From cceda0bd1f8387b15586f82f32958e7d866f7080 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Mon, 5 Aug 2024 22:52:20 +0800 Subject: [PATCH] =?UTF-8?q?Remove=20the=20GetMeta=20method.=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4GetMeta=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prefab/entitys/Character.tscn | 4 +- prefab/entitys/DelivererOfDarkMagic.tscn | 7 +-- prefab/packsacks/PortableBackpacks.tscn | 3 - prefab/projectile/curseOfTheUndead.tscn | 12 ++-- .../dungeon/horizontalCorridor.tscn | 2 +- scripts/camp/CampManager.cs | 2 +- scripts/character/CharacterTemplate.cs | 20 +++---- scripts/map/AiCharacterSpawn.cs | 7 ++- scripts/projectile/Projectile.cs | 56 +++++++++--------- sprites/Player.png | Bin 1769 -> 2398 bytes 10 files changed, 55 insertions(+), 58 deletions(-) diff --git a/prefab/entitys/Character.tscn b/prefab/entitys/Character.tscn index d015d78..60c295b 100644 --- a/prefab/entitys/Character.tscn +++ b/prefab/entitys/Character.tscn @@ -26,8 +26,8 @@ animations = [{ collision_layer = 4 collision_mask = 34 script = ExtResource("1_1dlls") -metadata/CampId = "Default" -metadata/MaxHp = 32 +MaxHp = 32 +CampId = "Default" [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource("CapsuleShape2D_bb8wt") diff --git a/prefab/entitys/DelivererOfDarkMagic.tscn b/prefab/entitys/DelivererOfDarkMagic.tscn index 1362234..4c90b56 100644 --- a/prefab/entitys/DelivererOfDarkMagic.tscn +++ b/prefab/entitys/DelivererOfDarkMagic.tscn @@ -34,11 +34,10 @@ radius = 172.29 collision_layer = 64 collision_mask = 38 script = ExtResource("1_ubaid") -InitWeaponRes = null +CharacterName = "死灵法师" +MaxHp = 50 +CampId = "Mazoku" LootListId = "test" -metadata/CampId = "Mazoku" -metadata/MaxHp = 50 -metadata/Name = "死灵法师" [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, 4) diff --git a/prefab/packsacks/PortableBackpacks.tscn b/prefab/packsacks/PortableBackpacks.tscn index 1f936f2..3079339 100644 --- a/prefab/packsacks/PortableBackpacks.tscn +++ b/prefab/packsacks/PortableBackpacks.tscn @@ -14,9 +14,6 @@ collision_layer = 8 collision_mask = 38 script = ExtResource("1_slakl") NumberSlots = 30 -BackpackAllowed = null -_minContactInjury = null -_maxContactInjury = null [node name="DamageArea2D" type="Area2D" parent="."] collision_layer = 8 diff --git a/prefab/projectile/curseOfTheUndead.tscn b/prefab/projectile/curseOfTheUndead.tscn index 3f34eb5..36c5bbb 100644 --- a/prefab/projectile/curseOfTheUndead.tscn +++ b/prefab/projectile/curseOfTheUndead.tscn @@ -12,11 +12,13 @@ radius = 11.0 collision_layer = 0 collision_mask = 0 script = ExtResource("1_ib3qh") -metadata/Speed = 500.0 -metadata/Durability = 1.0 -metadata/DamageType = 2 -metadata/Knockback = Vector2(2, -3) -metadata/Life = 5000 +Life = 5000 +Durability = 1.0 +MaxDamage = 3 +MinDamage = 10 +DamageType = 2 +KnockbackForce = Vector2(2, -3) +Speed = 500.0 [node name="CurseOfTheUndead" type="Sprite2D" parent="."] texture = ExtResource("1_k8el6") diff --git a/prefab/roomTemplates/dungeon/horizontalCorridor.tscn b/prefab/roomTemplates/dungeon/horizontalCorridor.tscn index b619abc..40c2b67 100644 --- a/prefab/roomTemplates/dungeon/horizontalCorridor.tscn +++ b/prefab/roomTemplates/dungeon/horizontalCorridor.tscn @@ -53,7 +53,7 @@ shape = SubResource("RectangleShape2D_7tsse") [node name="Marker2D" type="Marker2D" parent="."] position = Vector2(260, 87) script = ExtResource("2_wamhd") -metadata/ResPath = "res://prefab/entitys/DelivererOfDarkMagic.tscn" +ResPath = "res://prefab/entitys/DelivererOfDarkMagic.tscn" [node name="NavigationRegion2D" type="NavigationRegion2D" parent="."] navigation_polygon = SubResource("NavigationPolygon_rh1gx") diff --git a/scripts/camp/CampManager.cs b/scripts/camp/CampManager.cs index 3ee99c3..6d5bbe8 100644 --- a/scripts/camp/CampManager.cs +++ b/scripts/camp/CampManager.cs @@ -9,7 +9,7 @@ namespace ColdMint.scripts.camp; /// public static class CampManager { - private static readonly Dictionary Camps = new Dictionary(); + private static readonly Dictionary Camps = new(); /// /// The default camp is returned if no corresponding camp is obtained diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs index 225aea6..d6d8642 100644 --- a/scripts/character/CharacterTemplate.cs +++ b/scripts/character/CharacterTemplate.cs @@ -75,7 +75,8 @@ public partial class CharacterTemplate : CharacterBody2D public string? ReadOnlyCharacterName => CharacterName; - protected string? CharacterName; + [Export] + public string? CharacterName; protected IItemContainer? ProtectedItemContainer; @@ -156,15 +157,18 @@ public partial class CharacterTemplate : CharacterBody2D //The initial health of the character after creation //角色创建后的初始血量 - private int _initialHp; + [Export] + public int InitialHp; + [Export] public int MaxHp; /// /// The camp ID of the role /// 角色的阵营ID /// - public string CampId = null!; + [Export] + public string? CampId; private DamageNumberNodeSpawn? _damageNumber; @@ -253,9 +257,6 @@ public partial class CharacterTemplate : CharacterBody2D { base._Ready(); PickingRangeBodiesList = new List(); - CharacterName = GetMeta("Name", Name).AsString(); - CampId = GetMeta("CampId", Config.CampId.Default).AsString(); - MaxHp = GetMeta("MaxHp", Config.DefaultMaxHp).AsInt32(); if (MaxHp <= 0) { @@ -264,15 +265,14 @@ public partial class CharacterTemplate : CharacterBody2D 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 //如果初始血量小于等于0或者大于最大血量,那么将其设置为最大血量 - _initialHp = MaxHp; + InitialHp = MaxHp; } - CurrentHp = _initialHp; + CurrentHp = InitialHp; //The health bar of a creature may be null. //生物的健康条,可能为null。 _healthBar = GetNodeOrNull("HealthBar"); diff --git a/scripts/map/AiCharacterSpawn.cs b/scripts/map/AiCharacterSpawn.cs index 03d598a..5032544 100644 --- a/scripts/map/AiCharacterSpawn.cs +++ b/scripts/map/AiCharacterSpawn.cs @@ -12,14 +12,15 @@ namespace ColdMint.scripts.map; public partial class AiCharacterSpawn : Marker2D { private PackedScene? _packedScene; + [Export] + public string? ResPath; public override void _Ready() { base._Ready(); - var resPath = GetMeta("ResPath", Name).AsString(); - if (!string.IsNullOrEmpty(resPath)) + if (!string.IsNullOrEmpty(ResPath)) { - _packedScene = GD.Load(resPath); + _packedScene = GD.Load(ResPath); } EventManager.AiCharacterGenerateEvent += OnAiCharacterGenerateEvent; diff --git a/scripts/projectile/Projectile.cs b/scripts/projectile/Projectile.cs index 97432f0..18c707d 100644 --- a/scripts/projectile/Projectile.cs +++ b/scripts/projectile/Projectile.cs @@ -16,17 +16,22 @@ namespace ColdMint.scripts.projectile; /// public partial class Projectile : CharacterBody2D { - private long _life; + /// + /// life(ms) + /// 子弹的存在时间(毫秒) + /// + [Export] + public long Life; //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 //当抛射体撞击到物体时,会减少耐久度,当耐久度小于等于0时,销毁抛射体 - private double _durability; + [Export] public double Durability; - private int _maxDamage; - private int _minDamage; - private int _damageType; + [Export] public int MaxDamage; + [Export] public int MinDamage; + [Export] public int DamageType; /// /// After this time destroy the projectile @@ -49,9 +54,10 @@ public partial class Projectile : CharacterBody2D ///How much force does it have when hitting the character? Unit: Number of cells,The X direction of the force is inferred automatically. ///当击中角色时带有多大的力?单位:格数,力的X方向是自动推断的。 /// - private Vector2 _knockbackForce; + [Export] + public Vector2 KnockbackForce; - public float Speed => GetMeta("Speed", "15").AsSingle(); + [Export] public float Speed; private List? _projectileDecorators; @@ -70,22 +76,14 @@ public partial class Projectile : CharacterBody2D _area2D.Monitoring = true; _area2D.BodyEntered += OnBodyEnter; _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 //如果存在时间小于等于0,那么设置为存在10秒,禁止无限期存在的抛射体 - if (_life <= 0) + if (Life <= 0) { - _life = 10000; + Life = 10000; } - _destructionTime = DateTime.Now.AddMilliseconds(_life); + _destructionTime = DateTime.Now.AddMilliseconds(Life); } /// @@ -180,12 +178,12 @@ public partial class Projectile : CharacterBody2D var damage = new Damage { Attacker = owner, - MaxDamage = _maxDamage, - MinDamage = _minDamage + MaxDamage = MaxDamage, + MinDamage = MinDamage }; damage.CreateDamage(); damage.MoveLeft = Velocity.X < 0; - damage.Type = _damageType; + damage.Type = DamageType; var dead = characterTemplate.Damage(damage); if (dead) { @@ -194,12 +192,12 @@ public partial class Projectile : CharacterBody2D 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 //如果我们设置了攻退力,那么将力应用到对象上 var force = new Vector2(); - var forceX = Math.Abs(_knockbackForce.X); + var forceX = Math.Abs(KnockbackForce.X); if (Velocity.X < 0) { //Beat back to port @@ -208,18 +206,18 @@ public partial class Projectile : CharacterBody2D } force.X = forceX * Config.CellSize; - force.Y = _knockbackForce.Y * Config.CellSize; + force.Y = KnockbackForce.Y * Config.CellSize; characterTemplate.AddForce(force); } } 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 //如果我们设置了攻退力,那么将力应用到对象上 var force = new Vector2(); - var forceX = Math.Abs(_knockbackForce.X); + var forceX = Math.Abs(KnockbackForce.X); if (Velocity.X < 0) { //Beat back to port @@ -228,7 +226,7 @@ public partial class Projectile : CharacterBody2D } force.X = forceX * Config.CellSize; - force.Y = _knockbackForce.Y * Config.CellSize; + force.Y = KnockbackForce.Y * Config.CellSize; pickAbleTemplate.ApplyImpulse(force); } } @@ -272,8 +270,8 @@ public partial class Projectile : CharacterBody2D //请在Mask内配置子弹会和谁碰撞 //When a bullet hits an object, its durability decreases //子弹撞击到物体时,耐久度减少 - _durability--; - if (_durability <= 0) + Durability--; + if (Durability <= 0) { //When the durability is less than or equal to 0, destroy the bullet //当耐久度小于等于0时,销毁子弹 diff --git a/sprites/Player.png b/sprites/Player.png index 957abcad1289f392bd3b10b09a42541a867cd8bf..94c898c0dbd61bfdf168b7b77b8ac20151f22a78 100644 GIT binary patch delta 2388 zcmV-a39I($4c-!vBYz1cNkl^j+jJFrcI;uR6dqBD4xp zbi~Mv7@`ngNYoe~Ga2oGVMLuDlL?cInK8`7(ddxihy)Cjh)}c&NJNlWUnrC!ZE0zt zx3%=?o%5}8*Kyx-_c`~R+eZI%CHL&T*IsMwZ$0)t`?N$uG=CI7VRRsR| z(D2N3W1L2- z9$o`}__62LC0PQR4#2N@@(IlhQOUF!TE33yI|C|sM5}LXuFkG258zkacQ?!Q_x4$` z;rvmQnmv-s5>9x@WqEh1Z=^Hl+u@lblf^2%UA^1}^RlSrOe6J-2vFc$j0(%> z9tk;s(h2CSMR>>psJE+|rcA#&!Zn*&zr4l*A2neNkcHlEhHO@-Q>5$*CzU?v@2l$0)#;ELkLLTdll&c7JSnBMQ7FpmYFEoKe^@JjnF*^qIeI zbAzk$_P!?vP&)SV5b)>f8>pkbJqn0K-@aI)(wMSFjJ)kQc0guQ7ywe*M zfccJND=XCz)mc>*GROo7rF8tr$K1C+;${HRS4qH2Z|f%M`XF2 zTz^W*brU;9A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