Remove the GetMeta method.

移除GetMeta方法。
This commit is contained in:
Cold-Mint 2024-08-05 22:52:20 +08:00
parent 4459b6a88b
commit cceda0bd1f
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
10 changed files with 55 additions and 58 deletions

View File

@ -26,8 +26,8 @@ animations = [{
collision_layer = 4 collision_layer = 4
collision_mask = 34 collision_mask = 34
script = ExtResource("1_1dlls") script = ExtResource("1_1dlls")
metadata/CampId = "Default" MaxHp = 32
metadata/MaxHp = 32 CampId = "Default"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CapsuleShape2D_bb8wt") shape = SubResource("CapsuleShape2D_bb8wt")

View File

@ -34,11 +34,10 @@ radius = 172.29
collision_layer = 64 collision_layer = 64
collision_mask = 38 collision_mask = 38
script = ExtResource("1_ubaid") script = ExtResource("1_ubaid")
InitWeaponRes = null CharacterName = "死灵法师"
MaxHp = 50
CampId = "Mazoku"
LootListId = "test" LootListId = "test"
metadata/CampId = "Mazoku"
metadata/MaxHp = 50
metadata/Name = "死灵法师"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 4) position = Vector2(0, 4)

View File

@ -14,9 +14,6 @@ collision_layer = 8
collision_mask = 38 collision_mask = 38
script = ExtResource("1_slakl") script = ExtResource("1_slakl")
NumberSlots = 30 NumberSlots = 30
BackpackAllowed = null
_minContactInjury = null
_maxContactInjury = null
[node name="DamageArea2D" type="Area2D" parent="."] [node name="DamageArea2D" type="Area2D" parent="."]
collision_layer = 8 collision_layer = 8

View File

@ -12,11 +12,13 @@ radius = 11.0
collision_layer = 0 collision_layer = 0
collision_mask = 0 collision_mask = 0
script = ExtResource("1_ib3qh") script = ExtResource("1_ib3qh")
metadata/Speed = 500.0 Life = 5000
metadata/Durability = 1.0 Durability = 1.0
metadata/DamageType = 2 MaxDamage = 3
metadata/Knockback = Vector2(2, -3) MinDamage = 10
metadata/Life = 5000 DamageType = 2
KnockbackForce = Vector2(2, -3)
Speed = 500.0
[node name="CurseOfTheUndead" type="Sprite2D" parent="."] [node name="CurseOfTheUndead" type="Sprite2D" parent="."]
texture = ExtResource("1_k8el6") texture = ExtResource("1_k8el6")

View File

@ -53,7 +53,7 @@ shape = SubResource("RectangleShape2D_7tsse")
[node name="Marker2D" type="Marker2D" parent="."] [node name="Marker2D" type="Marker2D" parent="."]
position = Vector2(260, 87) position = Vector2(260, 87)
script = ExtResource("2_wamhd") script = ExtResource("2_wamhd")
metadata/ResPath = "res://prefab/entitys/DelivererOfDarkMagic.tscn" ResPath = "res://prefab/entitys/DelivererOfDarkMagic.tscn"
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."] [node name="NavigationRegion2D" type="NavigationRegion2D" parent="."]
navigation_polygon = SubResource("NavigationPolygon_rh1gx") navigation_polygon = SubResource("NavigationPolygon_rh1gx")

View File

@ -9,7 +9,7 @@ namespace ColdMint.scripts.camp;
/// </summary> /// </summary>
public static class CampManager public static class CampManager
{ {
private static readonly Dictionary<string, Camp?> Camps = new Dictionary<string, Camp?>(); private static readonly Dictionary<string, Camp?> Camps = new();
/// <summary> /// <summary>
/// <para>The default camp is returned if no corresponding camp is obtained</para> /// <para>The default camp is returned if no corresponding camp is obtained</para>

View File

@ -75,7 +75,8 @@ public partial class CharacterTemplate : CharacterBody2D
public string? ReadOnlyCharacterName => CharacterName; public string? ReadOnlyCharacterName => CharacterName;
protected string? CharacterName; [Export]
public string? CharacterName;
protected IItemContainer? ProtectedItemContainer; protected IItemContainer? ProtectedItemContainer;
@ -156,15 +157,18 @@ public partial class CharacterTemplate : CharacterBody2D
//The initial health of the character after creation //The initial health of the character after creation
//角色创建后的初始血量 //角色创建后的初始血量
private int _initialHp; [Export]
public int InitialHp;
[Export]
public int MaxHp; public int MaxHp;
/// <summary> /// <summary>
/// <para>The camp ID of the role</para> /// <para>The camp ID of the role</para>
/// <para>角色的阵营ID</para> /// <para>角色的阵营ID</para>
/// </summary> /// </summary>
public string CampId = null!; [Export]
public string? CampId;
private DamageNumberNodeSpawn? _damageNumber; private DamageNumberNodeSpawn? _damageNumber;
@ -253,9 +257,6 @@ public partial class CharacterTemplate : CharacterBody2D
{ {
base._Ready(); base._Ready();
PickingRangeBodiesList = new List<Node>(); PickingRangeBodiesList = new List<Node>();
CharacterName = GetMeta("Name", Name).AsString();
CampId = GetMeta("CampId", Config.CampId.Default).AsString();
MaxHp = GetMeta("MaxHp", Config.DefaultMaxHp).AsInt32();
if (MaxHp <= 0) if (MaxHp <= 0)
{ {
@ -264,15 +265,14 @@ public partial class CharacterTemplate : CharacterBody2D
MaxHp = Config.DefaultMaxHp; MaxHp = Config.DefaultMaxHp;
} }
_initialHp = GetMeta("InitialHp", "0").AsInt32(); if (InitialHp <= 0 || InitialHp > MaxHp)
if (_initialHp <= 0 || _initialHp > MaxHp)
{ {
//If the initial health is less than or equal to 0 or greater than the maximum health, then set it to the maximum health //If the initial health is less than or equal to 0 or greater than the maximum health, then set it to the maximum health
//如果初始血量小于等于0或者大于最大血量那么将其设置为最大血量 //如果初始血量小于等于0或者大于最大血量那么将其设置为最大血量
_initialHp = MaxHp; InitialHp = MaxHp;
} }
CurrentHp = _initialHp; CurrentHp = InitialHp;
//The health bar of a creature may be null. //The health bar of a creature may be null.
//生物的健康条可能为null。 //生物的健康条可能为null。
_healthBar = GetNodeOrNull<HealthBar>("HealthBar"); _healthBar = GetNodeOrNull<HealthBar>("HealthBar");

View File

@ -12,14 +12,15 @@ namespace ColdMint.scripts.map;
public partial class AiCharacterSpawn : Marker2D public partial class AiCharacterSpawn : Marker2D
{ {
private PackedScene? _packedScene; private PackedScene? _packedScene;
[Export]
public string? ResPath;
public override void _Ready() public override void _Ready()
{ {
base._Ready(); base._Ready();
var resPath = GetMeta("ResPath", Name).AsString(); if (!string.IsNullOrEmpty(ResPath))
if (!string.IsNullOrEmpty(resPath))
{ {
_packedScene = GD.Load<PackedScene>(resPath); _packedScene = GD.Load<PackedScene>(ResPath);
} }
EventManager.AiCharacterGenerateEvent += OnAiCharacterGenerateEvent; EventManager.AiCharacterGenerateEvent += OnAiCharacterGenerateEvent;

View File

@ -16,17 +16,22 @@ namespace ColdMint.scripts.projectile;
/// </summary> /// </summary>
public partial class Projectile : CharacterBody2D public partial class Projectile : CharacterBody2D
{ {
private long _life; /// <summary>
/// <para>life(ms)</para>
/// <para>子弹的存在时间(毫秒)</para>
/// </summary>
[Export]
public long Life;
//The durability of the projectile //The durability of the projectile
//抛射体的耐久度 //抛射体的耐久度
//When the projectile hits the object, the durability will be reduced, and when the durability is less than or equal to 0, the projectile will be destroyed //When the projectile hits the object, the durability will be reduced, and when the durability is less than or equal to 0, the projectile will be destroyed
//当抛射体撞击到物体时会减少耐久度当耐久度小于等于0时销毁抛射体 //当抛射体撞击到物体时会减少耐久度当耐久度小于等于0时销毁抛射体
private double _durability; [Export] public double Durability;
private int _maxDamage; [Export] public int MaxDamage;
private int _minDamage; [Export] public int MinDamage;
private int _damageType; [Export] public int DamageType;
/// <summary> /// <summary>
/// <para>After this time destroy the projectile</para> /// <para>After this time destroy the projectile</para>
@ -49,9 +54,10 @@ public partial class Projectile : CharacterBody2D
///<para>How much force does it have when hitting the character? Unit: Number of cellsThe X direction of the force is inferred automatically.</para> ///<para>How much force does it have when hitting the character? Unit: Number of cellsThe X direction of the force is inferred automatically.</para>
///<para>当击中角色时带有多大的力单位格数力的X方向是自动推断的。</para> ///<para>当击中角色时带有多大的力单位格数力的X方向是自动推断的。</para>
/// </remarks> /// </remarks>
private Vector2 _knockbackForce; [Export]
public Vector2 KnockbackForce;
public float Speed => GetMeta("Speed", "15").AsSingle(); [Export] public float Speed;
private List<IProjectileDecorator>? _projectileDecorators; private List<IProjectileDecorator>? _projectileDecorators;
@ -70,22 +76,14 @@ public partial class Projectile : CharacterBody2D
_area2D.Monitoring = true; _area2D.Monitoring = true;
_area2D.BodyEntered += OnBodyEnter; _area2D.BodyEntered += OnBodyEnter;
_area2D.BodyExited += OnBodyExited; _area2D.BodyExited += OnBodyExited;
_durability = GetMeta("Durability", "1").AsDouble();
_maxDamage = GetMeta("MaxDamage", "7").AsInt32();
_minDamage = GetMeta("MinDamage", "5").AsInt32();
_damageType = GetMeta("DamageType", Config.DamageType.Physical).AsInt32();
_knockbackForce = GetMeta("Knockback", Vector2.Zero).AsVector2();
//life(ms)
//子弹的存在时间(毫秒)
_life = GetMeta("Life", "10000").AsInt64();
//If the existence time is less than or equal to 0, then it is set to exist for 10 seconds, and projectiles that exist indefinitely are prohibited //If the existence time is less than or equal to 0, then it is set to exist for 10 seconds, and projectiles that exist indefinitely are prohibited
//如果存在时间小于等于0那么设置为存在10秒禁止无限期存在的抛射体 //如果存在时间小于等于0那么设置为存在10秒禁止无限期存在的抛射体
if (_life <= 0) if (Life <= 0)
{ {
_life = 10000; Life = 10000;
} }
_destructionTime = DateTime.Now.AddMilliseconds(_life); _destructionTime = DateTime.Now.AddMilliseconds(Life);
} }
/// <summary> /// <summary>
@ -180,12 +178,12 @@ public partial class Projectile : CharacterBody2D
var damage = new Damage var damage = new Damage
{ {
Attacker = owner, Attacker = owner,
MaxDamage = _maxDamage, MaxDamage = MaxDamage,
MinDamage = _minDamage MinDamage = MinDamage
}; };
damage.CreateDamage(); damage.CreateDamage();
damage.MoveLeft = Velocity.X < 0; damage.MoveLeft = Velocity.X < 0;
damage.Type = _damageType; damage.Type = DamageType;
var dead = characterTemplate.Damage(damage); var dead = characterTemplate.Damage(damage);
if (dead) if (dead)
{ {
@ -194,12 +192,12 @@ public partial class Projectile : CharacterBody2D
InvokeDecorators(decorator => { decorator.OnKillCharacter(owner, characterTemplate); }); InvokeDecorators(decorator => { decorator.OnKillCharacter(owner, characterTemplate); });
} }
if (_knockbackForce != Vector2.Zero) if (KnockbackForce != Vector2.Zero)
{ {
//If we set the attack force, then apply the force to the object //If we set the attack force, then apply the force to the object
//如果我们设置了攻退力,那么将力应用到对象上 //如果我们设置了攻退力,那么将力应用到对象上
var force = new Vector2(); var force = new Vector2();
var forceX = Math.Abs(_knockbackForce.X); var forceX = Math.Abs(KnockbackForce.X);
if (Velocity.X < 0) if (Velocity.X < 0)
{ {
//Beat back to port //Beat back to port
@ -208,18 +206,18 @@ public partial class Projectile : CharacterBody2D
} }
force.X = forceX * Config.CellSize; force.X = forceX * Config.CellSize;
force.Y = _knockbackForce.Y * Config.CellSize; force.Y = KnockbackForce.Y * Config.CellSize;
characterTemplate.AddForce(force); characterTemplate.AddForce(force);
} }
} }
else if (target is PickAbleTemplate pickAbleTemplate) else if (target is PickAbleTemplate pickAbleTemplate)
{ {
if (_knockbackForce != Vector2.Zero) if (KnockbackForce != Vector2.Zero)
{ {
//If we set the attack force, then apply the force to the object //If we set the attack force, then apply the force to the object
//如果我们设置了攻退力,那么将力应用到对象上 //如果我们设置了攻退力,那么将力应用到对象上
var force = new Vector2(); var force = new Vector2();
var forceX = Math.Abs(_knockbackForce.X); var forceX = Math.Abs(KnockbackForce.X);
if (Velocity.X < 0) if (Velocity.X < 0)
{ {
//Beat back to port //Beat back to port
@ -228,7 +226,7 @@ public partial class Projectile : CharacterBody2D
} }
force.X = forceX * Config.CellSize; force.X = forceX * Config.CellSize;
force.Y = _knockbackForce.Y * Config.CellSize; force.Y = KnockbackForce.Y * Config.CellSize;
pickAbleTemplate.ApplyImpulse(force); pickAbleTemplate.ApplyImpulse(force);
} }
} }
@ -272,8 +270,8 @@ public partial class Projectile : CharacterBody2D
//请在Mask内配置子弹会和谁碰撞 //请在Mask内配置子弹会和谁碰撞
//When a bullet hits an object, its durability decreases //When a bullet hits an object, its durability decreases
//子弹撞击到物体时,耐久度减少 //子弹撞击到物体时,耐久度减少
_durability--; Durability--;
if (_durability <= 0) if (Durability <= 0)
{ {
//When the durability is less than or equal to 0, destroy the bullet //When the durability is less than or equal to 0, destroy the bullet
//当耐久度小于等于0时销毁子弹 //当耐久度小于等于0时销毁子弹

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB