Add melee weapons.

加入近战武器。
This commit is contained in:
Cold-Mint 2024-10-07 15:17:04 +08:00
parent f313240400
commit 25ad117d6f
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
8 changed files with 194 additions and 4 deletions

View File

@ -15,3 +15,7 @@
scene_path: res://prefab/weapons/StaffNecromancy.tscn scene_path: res://prefab/weapons/StaffNecromancy.tscn
icon_path: res://sprites/weapon/StaffNecromancy_Icon.png icon_path: res://sprites/weapon/StaffNecromancy_Icon.png
max_stack_value: 1 max_stack_value: 1
- id: iron_axe
scene_path: res://prefab/weapons/IronAxe.tscn
icon_path: res://sprites/weapon/StaffNecromancy_Icon.png
max_stack_value: 1

View File

@ -9,3 +9,5 @@ item_x3,三重射击法术,Triple shot spell,三重射撃術です
item_x3_desc,使发射器一次射出三颗弹丸。,Make the launcher shoot three pellets at a time.,発射機から一度に三つの弾丸を発射させます。 item_x3_desc,使发射器一次射出三颗弹丸。,Make the launcher shoot three pellets at a time.,発射機から一度に三つの弾丸を発射させます。
item_resignation_certificate,离职证明,Resignation certificate,退職証明書です item_resignation_certificate,离职证明,Resignation certificate,退職証明書です
item_resignation_certificate_desc,冷薄荷,感谢您在职时为公司做出的贡献。,"Cold Mint, thank you for your service to the company.",コールドミント、現役時代のご貢献ありがとうございました。 item_resignation_certificate_desc,冷薄荷,感谢您在职时为公司做出的贡献。,"Cold Mint, thank you for your service to the company.",コールドミント、現役時代のご貢献ありがとうございました。
item_iron_axe,铁斧子,Iron axe,鉄の斧です
item_iron_axe_desc,铁斧子,Iron axe,鉄の斧です
1 id zh en ja
9 item_x3_desc 使发射器一次射出三颗弹丸。 Make the launcher shoot three pellets at a time. 発射機から一度に三つの弾丸を発射させます。
10 item_resignation_certificate 离职证明 Resignation certificate 退職証明書です
11 item_resignation_certificate_desc 冷薄荷,感谢您在职时为公司做出的贡献。 Cold Mint, thank you for your service to the company. コールドミント、現役時代のご貢献ありがとうございました。
12 item_iron_axe 铁斧子 Iron axe 鉄の斧です
13 item_iron_axe_desc 铁斧子 Iron axe 鉄の斧です

View File

@ -62,7 +62,7 @@ ItemId = "necromancy"
[node name="ItemMarker2D5" type="Marker2D" parent="."] [node name="ItemMarker2D5" type="Marker2D" parent="."]
position = Vector2(381, 136) position = Vector2(381, 136)
script = ExtResource("3_v1tlc") script = ExtResource("3_v1tlc")
ItemId = "resignation_certificate" ItemId = "iron_axe"
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."] [node name="NavigationRegion2D" type="NavigationRegion2D" parent="."]
navigation_polygon = SubResource("NavigationPolygon_064c7") navigation_polygon = SubResource("NavigationPolygon_064c7")

View File

@ -0,0 +1,57 @@
[gd_scene load_steps=7 format=3 uid="uid://g1jrthe4ojdd"]
[ext_resource type="Script" path="res://scripts/weapon/MeleeWeapon.cs" id="1_snmy1"]
[ext_resource type="Texture2D" uid="uid://wt50kx6bup51" path="res://sprites/weapon/StaffNecromancy.png" id="3_cm7e6"]
[ext_resource type="AudioStream" uid="uid://cak6chjjsu7wo" path="res://sounds/fire.wav" id="4_qimud"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_obcq2"]
size = Vector2(49, 5)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_14m1g"]
size = Vector2(49, 5.25)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2u0n7"]
size = Vector2(102, 94)
[node name="IronAxe" type="RigidBody2D"]
collision_layer = 8
collision_mask = 34
angular_damp = -1.0
script = ExtResource("1_snmy1")
[node name="DamageArea2D" type="Area2D" parent="."]
collision_layer = 8
collision_mask = 102
[node name="CollisionShape2D" type="CollisionShape2D" parent="DamageArea2D"]
position = Vector2(25.5, 0.5)
shape = SubResource("RectangleShape2D_obcq2")
[node name="StaffOfTheUndead2" type="Sprite2D" parent="."]
position = Vector2(30, 0)
texture = ExtResource("3_cm7e6")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(25.5, 0.375)
shape = SubResource("RectangleShape2D_14m1g")
[node name="Marker2D" type="Marker2D" parent="."]
position = Vector2(65, 0)
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="Marker2D"]
stream = ExtResource("4_qimud")
bus = &"SoundEffect"
[node name="TipLabel" type="Label" parent="."]
offset_left = 6.0
offset_top = 48.0
offset_right = 46.0
offset_bottom = 73.0
[node name="WeaponDamageArea" type="Area2D" parent="."]
collision_layer = 512
collision_mask = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="WeaponDamageArea"]
position = Vector2(127, 1)
shape = SubResource("RectangleShape2D_2u0n7")

View File

@ -168,6 +168,7 @@ locale/translations=PackedStringArray("res://locals/DeathInfo.en.translation", "
2d_physics/layer_7="Mob" 2d_physics/layer_7="Mob"
2d_physics/layer_8="Wall" 2d_physics/layer_8="Wall"
2d_physics/layer_9="Furniture" 2d_physics/layer_9="Furniture"
2d_physics/layer_10="WeaponDamageArea"
[physics] [physics]

View File

@ -578,6 +578,11 @@ public static class Config
/// <para>家具</para> /// <para>家具</para>
/// </summary> /// </summary>
public const int Furniture = 9; public const int Furniture = 9;
/// <summary>
/// <para>WeaponDamageArea</para>
/// <para>武器伤害区域</para>
/// </summary>
public const int WeaponDamageArea = 10;
} }
/// <summary> /// <summary>

View File

@ -94,6 +94,12 @@ public static class LogCat
/// <para>物品生成器</para> /// <para>物品生成器</para>
/// </summary> /// </summary>
public const string ItemSpawn = "ItemSpawn"; public const string ItemSpawn = "ItemSpawn";
/// <summary>
/// <para>MeleeWeapon</para>
/// <para>近战武器</para>
/// </summary>
public const string MeleeWeapon = "MeleeWeapon";
} }

View File

@ -0,0 +1,115 @@
using System.Collections.Generic;
using ColdMint.scripts.character;
using ColdMint.scripts.damage;
using ColdMint.scripts.debug;
using Godot;
namespace ColdMint.scripts.weapon;
/// <summary>
/// <para>MeleeWeapon</para>
/// <para>近战武器</para>
/// </summary>
public partial class MeleeWeapon : WeaponTemplate
{
/// <summary>
/// <para>The damage area of the weapon</para>
/// <para>武器的伤害区域</para>
/// </summary>
private Area2D? _weaponDamageArea;
[Export]
private int _maxDamage = 1;
[Export]
private int _minDamage = 1;
private DamageTemplate? _damageTemplate;
private readonly List<CharacterTemplate> _characterTemplates =
[
];
public override void _Ready()
{
base._Ready();
LogCat.Log("ready", LogCat.LogLabel.MeleeWeapon);
_weaponDamageArea = GetNode<Area2D>("WeaponDamageArea");
_weaponDamageArea.InputPickable = false;
_weaponDamageArea.SetCollisionMaskValue(Config.LayerNumber.Player, true);
_weaponDamageArea.SetCollisionMaskValue(Config.LayerNumber.Mob, true);
_weaponDamageArea.Monitoring = true;
_weaponDamageArea.BodyEntered += OnBodyEntered;
_weaponDamageArea.BodyExited += OnBodyExited;
_weaponDamageArea.AreaEntered += AreaEntered;
_weaponDamageArea.AreaExited += AreaExited;
_damageTemplate = new Damage();
_damageTemplate.MaxDamage = _maxDamage;
_damageTemplate.MinDamage = _minDamage;
_damageTemplate.Type = Config.DamageType.Physical;
LogCat.Log("success", LogCat.LogLabel.MeleeWeapon);
}
private void AreaExited(Node2D node2D)
{
LogCat.Log("AreaExited" + node2D.Name, LogCat.LogLabel.MeleeWeapon);
}
private void AreaEntered(Node2D node2D)
{
LogCat.Log("AreaEntered" + node2D.Name, LogCat.LogLabel.MeleeWeapon);
}
/// <summary>
/// <para>OnBodyEntered</para>
/// <para>当敌人进入攻击范围</para>
/// </summary>
private void OnBodyEntered(Node2D node2D)
{
LogCat.Log("OnBodyEntered" + node2D.Name, LogCat.LogLabel.MeleeWeapon);
if (node2D is CharacterTemplate characterTemplate)
{
_characterTemplates.Add(characterTemplate);
}
}
/// <summary>
/// <para>When the enemy is out of range</para>
/// <para>当敌人离开攻击范围</para>
/// </summary>
/// <param name="node"></param>
private void OnBodyExited(Node node)
{
LogCat.Log("OnBodyExited" + node.Name, LogCat.LogLabel.MeleeWeapon);
if (node is CharacterTemplate characterTemplate)
{
_characterTemplates.Remove(characterTemplate);
}
}
protected override bool DoFire(Node2D? owner, Vector2 enemyGlobalPosition)
{
if (_weaponDamageArea == null)
{
return false;
}
if (_damageTemplate == null)
{
return false;
}
if (owner == null)
{
LogCat.LogError("owner_is_null", LogCat.LogLabel.MeleeWeapon);
return false;
}
if (_characterTemplates.Count == 0)
{
return false;
}
foreach (var characterTemplate in _characterTemplates)
{
characterTemplate.Damage(_damageTemplate);
}
return true;
}
}