From 4459b6a88bbd52958babf2809ffc7c929222fda2 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Sun, 4 Aug 2024 00:32:49 +0800 Subject: [PATCH] =?UTF-8?q?Added=20the=20game=20difficulty=20configuration?= =?UTF-8?q?=20class=20and=20added=20the=20ability=20to=20generate=20scenes?= =?UTF-8?q?=20after=20projectiles=20kill=20enemies.=20=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E9=9A=BE=E5=BA=A6=E7=9A=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E5=8A=A0=E5=85=A5=E6=8A=9B=E5=B0=84=E4=BD=93?= =?UTF-8?q?=E6=9D=80=E6=AD=BB=E6=95=8C=E4=BA=BA=E5=90=8E=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E7=9A=84=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ColdMint.Traveler.csproj | 2 +- data/itemRegs/weapons.yaml | 4 ++ prefab/packsacks/PortableBackpacks.tscn | 3 + prefab/weapons/StaffNecromancy.tscn | 3 + scripts/Config.cs | 23 ++++++++ scripts/loot/LootEntry.cs | 2 +- scripts/loot/LootRegister.cs | 2 +- scripts/projectile/Projectile.cs | 2 +- .../decorator/IProjectileDecorator.cs | 13 ++++- .../NodeSpawnOnKillCharacterDecorator.cs | 56 +++++++++++++++++++ scripts/utils/NodeUtils.cs | 6 ++ scripts/weapon/ProjectileWeapon.cs | 10 ++++ 12 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 scripts/projectile/decorator/NodeSpawnOnKillCharacterDecorator.cs diff --git a/ColdMint.Traveler.csproj b/ColdMint.Traveler.csproj index 34b43cd..d911b96 100644 --- a/ColdMint.Traveler.csproj +++ b/ColdMint.Traveler.csproj @@ -1,4 +1,4 @@ - + net6.0 net7.0 diff --git a/data/itemRegs/weapons.yaml b/data/itemRegs/weapons.yaml index 061fc51..a49d222 100644 --- a/data/itemRegs/weapons.yaml +++ b/data/itemRegs/weapons.yaml @@ -7,6 +7,10 @@ #staff_necromancy #死灵法杖 +# The Necromancy Staff will act differently on different difficulties. +#死灵法杖在不同的难度下会有不同的行为。 +#The probability of generating monsters is as follows:Hard mode 100%, Normal mode 75%, easy mode 5% +#以下是在击杀敌人后生成怪物的概率:困难模式100%,普通模式75%,简单模式5% - id: staff_necromancy scene_path: res://prefab/weapons/StaffNecromancy.tscn icon_path: res://sprites/weapon/StaffNecromancy_Icon.png diff --git a/prefab/packsacks/PortableBackpacks.tscn b/prefab/packsacks/PortableBackpacks.tscn index 3079339..1f936f2 100644 --- a/prefab/packsacks/PortableBackpacks.tscn +++ b/prefab/packsacks/PortableBackpacks.tscn @@ -14,6 +14,9 @@ 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/weapons/StaffNecromancy.tscn b/prefab/weapons/StaffNecromancy.tscn index 0243e8e..4684155 100644 --- a/prefab/weapons/StaffNecromancy.tscn +++ b/prefab/weapons/StaffNecromancy.tscn @@ -18,7 +18,10 @@ collision_mask = 34 script = ExtResource("1_w8hhv") ProjectileScenes = [ExtResource("2_34250")] FiringIntervalAsMillisecond = 300 +_recoil = null UniqueIcon = ExtResource("3_31iau") +_minContactInjury = null +_maxContactInjury = null [node name="DamageArea2D" type="Area2D" parent="."] collision_layer = 8 diff --git a/scripts/Config.cs b/scripts/Config.cs index 2086ce9..1895228 100644 --- a/scripts/Config.cs +++ b/scripts/Config.cs @@ -20,6 +20,29 @@ public static class Config /// public const string Test = "test"; } + + /// + /// Difficulty + /// 游戏难度 + /// + public static class Difficulty + { + /// + /// Simple mode + /// 简单模式 + /// + public const int Easy = 0; + /// + /// Normal mode + /// 正常模式 + /// + public const int Normal = 1; + /// + /// Hard mode + /// 困难模式 + /// + public const int Hard = 2; + } /// diff --git a/scripts/loot/LootEntry.cs b/scripts/loot/LootEntry.cs index d85ab7f..d367198 100644 --- a/scripts/loot/LootEntry.cs +++ b/scripts/loot/LootEntry.cs @@ -47,7 +47,7 @@ public readonly struct LootEntry(string itemId, int minQuantity = 1, int maxQuan ///Entries ///条目列表 /// -public readonly record struct LootGroup(double Chance, IEnumerable Entries) +public readonly record struct LootGroup(float Chance, IEnumerable Entries) { private int WeightSum { get; } = Entries.Sum(entry => entry.Weight); diff --git a/scripts/loot/LootRegister.cs b/scripts/loot/LootRegister.cs index 9372640..3ab5a63 100644 --- a/scripts/loot/LootRegister.cs +++ b/scripts/loot/LootRegister.cs @@ -16,7 +16,7 @@ public static class LootRegister { List lootGroups = [ - new LootGroup(0.8, + new LootGroup(0.8f, [ new LootEntry("staff_necromancy"), ]) diff --git a/scripts/projectile/Projectile.cs b/scripts/projectile/Projectile.cs index 7d93f6c..97432f0 100644 --- a/scripts/projectile/Projectile.cs +++ b/scripts/projectile/Projectile.cs @@ -191,7 +191,7 @@ public partial class Projectile : CharacterBody2D { //If the character is dead, then call OnKillCharacter //如果角色死亡了,那么调用OnKillCharacter - InvokeDecorators(decorator => { decorator.OnKillCharacter(); }); + InvokeDecorators(decorator => { decorator.OnKillCharacter(owner, characterTemplate); }); } if (_knockbackForce != Vector2.Zero) diff --git a/scripts/projectile/decorator/IProjectileDecorator.cs b/scripts/projectile/decorator/IProjectileDecorator.cs index e7de1b8..656209c 100644 --- a/scripts/projectile/decorator/IProjectileDecorator.cs +++ b/scripts/projectile/decorator/IProjectileDecorator.cs @@ -1,3 +1,6 @@ +using ColdMint.scripts.character; +using Godot; + namespace ColdMint.scripts.projectile.decorator; /// @@ -14,5 +17,13 @@ public interface IProjectileDecorator /// When the character is killed by this projectile /// 当角色被此抛射体击杀时 /// - void OnKillCharacter(); + /// + /// owner + /// 主人 + /// + /// + ///target + ///目标 + /// + void OnKillCharacter(Node2D? owner, CharacterTemplate target); } \ No newline at end of file diff --git a/scripts/projectile/decorator/NodeSpawnOnKillCharacterDecorator.cs b/scripts/projectile/decorator/NodeSpawnOnKillCharacterDecorator.cs new file mode 100644 index 0000000..ffde59b --- /dev/null +++ b/scripts/projectile/decorator/NodeSpawnOnKillCharacterDecorator.cs @@ -0,0 +1,56 @@ +using ColdMint.scripts.character; +using ColdMint.scripts.utils; +using Godot; + +namespace ColdMint.scripts.projectile.decorator; + +/// +/// NodeSpawnOnKillCharacterDecorator +/// 在击杀角色后生成节点 +/// +public class NodeSpawnOnKillCharacterDecorator : IProjectileDecorator +{ + /// + /// PackedScenePath + /// 要实例化的场景路径 + /// + public string? PackedScenePath { get; set; } + + /// + /// DefaultParentNode + /// 默认的父节点 + /// + public Node? DefaultParentNode { get; set; } + + /// + /// Chance + /// 生成概率 + /// + public float Chance { get; set; } = 1f; + + public void OnKillCharacter(Node2D? owner, CharacterTemplate target) + { + if (RandomUtils.Instance.NextSingle() > Chance) + { + //Not in probability, straight back. + //没有在概率内,直接返回。 + return; + } + + if (PackedScenePath == null || DefaultParentNode == null) + { + return; + } + + var packedScene = GD.Load(PackedScenePath); + var node2D = NodeUtils.InstantiatePackedScene(packedScene); + if (node2D == null) + { + return; + } + + var container = NodeUtils.FindContainerNode(node2D, DefaultParentNode); + node2D.GlobalPosition = target.GlobalPosition; + NodeUtils.CallDeferredAddChild(container, node2D); + } +} \ No newline at end of file diff --git a/scripts/utils/NodeUtils.cs b/scripts/utils/NodeUtils.cs index 039f265..1b1c39b 100644 --- a/scripts/utils/NodeUtils.cs +++ b/scripts/utils/NodeUtils.cs @@ -1,4 +1,5 @@ using System; +using ColdMint.scripts.character; using ColdMint.scripts.debug; using ColdMint.scripts.projectile; using Godot; @@ -224,6 +225,11 @@ public static class NodeUtils /// public static Node FindContainerNode(Node childNode, Node defaultParentNode) { + if (GameSceneNodeHolder.AiCharacterContainer!= null && childNode is AiCharacter) + { + return GameSceneNodeHolder.AiCharacterContainer; + } + if (GameSceneNodeHolder.ProjectileContainer != null && childNode is Projectile) { return GameSceneNodeHolder.ProjectileContainer; diff --git a/scripts/weapon/ProjectileWeapon.cs b/scripts/weapon/ProjectileWeapon.cs index d07e5fa..ef2365c 100644 --- a/scripts/weapon/ProjectileWeapon.cs +++ b/scripts/weapon/ProjectileWeapon.cs @@ -1,5 +1,6 @@ using ColdMint.scripts.debug; using ColdMint.scripts.projectile; +using ColdMint.scripts.projectile.decorator; using ColdMint.scripts.utils; using Godot; @@ -63,6 +64,15 @@ public partial class ProjectileWeapon : WeaponTemplate // var projectileScene = _projectileCache[_projectiles[0]]; var projectile = NodeUtils.InstantiatePackedScene(projectileScene); if (projectile == null) return; + if (Config.IsDebug()) + { + var nodeSpawnOnKillCharacterDecorator = new NodeSpawnOnKillCharacterDecorator + { + DefaultParentNode = this, + PackedScenePath = "res://prefab/entitys/DelivererOfDarkMagic.tscn" + }; + projectile.AddProjectileDecorator(nodeSpawnOnKillCharacterDecorator); + } NodeUtils.CallDeferredAddChild(GameSceneNodeHolder.ProjectileContainer, projectile); projectile.Owner = owner; projectile.Velocity = (enemyGlobalPosition - _marker2D.GlobalPosition).Normalized() * projectile.Speed;