From 16a2d405019fefed4e160cfccdbbe188657ace57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=A7=E9=9B=A8=E7=83=A8?= Date: Thu, 13 Jun 2024 01:51:51 +0800 Subject: [PATCH] It's done. --- locals/Log.en.translation | Bin 1946 -> 1946 bytes locals/Log.ja.translation | Bin 2825 -> 2825 bytes locals/Log.zh.translation | Bin 2197 -> 2197 bytes locals/Slogan.ja.translation | Bin 765 -> 765 bytes locals/slogan.en.translation | Bin 666 -> 666 bytes locals/slogan.zh.translation | Bin 713 -> 713 bytes scripts/character/CharacterTemplate.cs | 54 ++++++++++++++++------- scripts/inventory/ItemSlotNode.cs | 2 + scripts/item/SingleItemStack.cs | 4 +- scripts/item/weapon/WeaponTemplate.cs | 7 ++- scripts/projectile/ProjectileTemplate.cs | 26 ++++++----- scripts/utils/NodeUtils.cs | 2 +- 12 files changed, 64 insertions(+), 31 deletions(-) diff --git a/locals/Log.en.translation b/locals/Log.en.translation index 3b2867b042ae128471bbb4d3e8be889a6f882294..26a2d18cd01ee755eba438f7287fd40f3fd7467c 100644 GIT binary patch delta 18 ZcmbQmKZ}2ZG$U)CQF2M~W(CG7HUKrK1!4dI delta 18 ZcmbQmKZ}2ZG$U(CURh4wW(CG7HUKz61*!l5 diff --git a/locals/Log.ja.translation b/locals/Log.ja.translation index ae0f9249ff9cc3df2d93fc552d2558b1e280e8b6..bcce44b179ae100f45cc89df2a5d6125119f52b9 100644 GIT binary patch delta 18 ZcmeAa>lE7{&B&UVZ;@-dS%L8-Cjc|e1%Lnm delta 18 ZcmeAa>lE7{&B$6=UQ(L9S%L8-CjdBM1{weW diff --git a/locals/Log.zh.translation b/locals/Log.zh.translation index a879ff0126fe830b1da85e9b55abdf106bba6b8a..b618fc91b966e5a60c0d12853c9e80bbe3277004 100644 GIT binary patch delta 18 ZcmbO#I8|_iG$U(Dfk|c3W(CGlb^tX*1yKM1 delta 18 ZcmbO#I8|_iG$U(qWofG6W(CGlb^tbk1!VvL diff --git a/locals/Slogan.ja.translation b/locals/Slogan.ja.translation index e44c84c9eaa7fd4576956a3f74e9a6dc87e8dc85..db766f6e265c289e9a8cac10d6cb05b37e3865d6 100644 GIT binary patch delta 35 rcmey%`j>TrEr;KlmkHBU7l}^{RG65+GqG?LYk{$8cIsvY#=DFF2e%EI delta 35 rcmey%`j>TrEr;)lcMN|kqBtf7Dojk^nOL}rHOC;+$aJ#;<6TAo2C)rd diff --git a/locals/slogan.en.translation b/locals/slogan.en.translation index afca76212737fdd2ebf6a5dc5db4c21d2ba12ea9..77ebe612cb8c3192f0892dd0521191b2abfbd24d 100644 GIT binary patch delta 35 rcmbQmI*WCJEysk4i1_-k delta 35 rcmbQmI*WCJEl2znBN5B=1>O?_6(%O|Oe|c*YLZr2X|`E`v5FA@+R+Qy diff --git a/locals/slogan.zh.translation b/locals/slogan.zh.translation index 357757f11e93c472f909446519db091dd54945d3..04ff43419af368263662db24f056efcd3f80688a 100644 GIT binary patch delta 35 rcmX@fdXja5Er*7a)`q$3ax^9eDojk^nOL}rwJh1tz<9F)<4Q&V=RXWE delta 35 rcmX@fdXja5Eyw%W27wn^=4nj~RG65+GqG?LYe`B@M)_t1#+8f!2rmul diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs index aff45c9..75e2fb0 100644 --- a/scripts/character/CharacterTemplate.cs +++ b/scripts/character/CharacterTemplate.cs @@ -485,8 +485,8 @@ public partial class CharacterTemplate : CharacterBody2D /// /// public void GenerateLootObjects(Node parentNode, - LootData[] lootDataArray, - Vector2 position) + LootData[] lootDataArray, + Vector2 position) { LootListManager.GenerateLootObjects(parentNode, lootDataArray, position); } @@ -617,8 +617,8 @@ public partial class CharacterTemplate : CharacterBody2D /// 抛出物品 /// /// - ///Item slot subscript in item container - ///物品容器内的物品槽下标 + ///Item slot index in item container + ///物品容器内的物品槽位置 /// /// /// How many to throw @@ -633,8 +633,41 @@ public partial class CharacterTemplate : CharacterBody2D protected void ThrowItem(int index, int number, Vector2 velocity) { var itemSlotNode = ItemContainer?.GetItemSlotNode(index); + if (itemSlotNode is null) return; - var item = itemSlotNode?.GetItem(); + if (number < 0) + { + while (!itemSlotNode.IsEmpty()) + { + ThrowOneItem(itemSlotNode, velocity); + } + } + else + { + for (int i = 0; i < number && !itemSlotNode.IsEmpty(); i++) + { + ThrowOneItem(itemSlotNode, velocity); + } + } + } + + /// + /// Throw item + /// 抛出物品 + /// + /// + ///Item slot index in item container + ///物品容器内的物品槽位置 + /// + /// + ///The speed to be applied to the item + ///要施加到物品上的速度 + /// + protected void ThrowOneItem(ItemSlotNode itemSlotNode, Vector2 velocity) + { + //Pick an item from the item container + //从物品容器内取出一个物品 + var item = itemSlotNode?.PickItem(); if (item is not Node2D node2D) { @@ -685,17 +718,6 @@ public partial class CharacterTemplate : CharacterBody2D rigidBody2D.LinearVelocity = velocity; break; } - - //Remove items from the item container - //在物品容器内移除物品 - if (number < 0) - { - itemSlotNode!.RemoveItem(item.Quantity); - } - else - { - itemSlotNode!.RemoveItem(number); - } } /// diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs index b129e1c..9208cd5 100644 --- a/scripts/inventory/ItemSlotNode.cs +++ b/scripts/inventory/ItemSlotNode.cs @@ -37,6 +37,8 @@ public partial class ItemSlotNode : MarginContainer public TextureRect? BackgroundTextureRect => _backgroundTextureRect; + public bool IsEmpty() => _itemStack == null; + /// /// Get the item stack in the item slot /// 获取物品槽内的物品堆 diff --git a/scripts/item/SingleItemStack.cs b/scripts/item/SingleItemStack.cs index 86850bf..839066e 100644 --- a/scripts/item/SingleItemStack.cs +++ b/scripts/item/SingleItemStack.cs @@ -27,8 +27,8 @@ public class SingleItemStack(IItem_New item) : IItemStack public int CanTakeFrom(IItemStack itemStack) => 0; - public int TakeFrom(IItemStack itemStack) => 0; - + public bool TakeFrom(IItemStack itemStack) => false; + public IItem_New? GetItem() { throw new NotImplementedException(); diff --git a/scripts/item/weapon/WeaponTemplate.cs b/scripts/item/weapon/WeaponTemplate.cs index 851cca1..6b5d314 100644 --- a/scripts/item/weapon/WeaponTemplate.cs +++ b/scripts/item/weapon/WeaponTemplate.cs @@ -35,6 +35,11 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem_New Fire(owner, targetGlobalPosition); } + public virtual void Destroy() + { + QueueFree(); + } + /// /// Whether the weapon is currently picked up @@ -168,7 +173,7 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem_New //Determine if your side can cause damage //判断所属的阵营是否可以造成伤害 - var canCauseHarm = CampManager.CanCauseHarm(CampManager.GetCamp(ownerCharacterTemplate.CampId), + var canCauseHarm = CampManager.CanCauseHarm(CampManager.GetCamp(ownerCharacterTemplate.CampId), CampManager.GetCamp(characterTemplate.CampId)); if (!canCauseHarm) { diff --git a/scripts/projectile/ProjectileTemplate.cs b/scripts/projectile/ProjectileTemplate.cs index 8d8b4f5..3079f72 100644 --- a/scripts/projectile/ProjectileTemplate.cs +++ b/scripts/projectile/ProjectileTemplate.cs @@ -1,8 +1,11 @@ using System; + using ColdMint.scripts.camp; using ColdMint.scripts.character; using ColdMint.scripts.damage; -using ColdMint.scripts.weapon; +using ColdMint.scripts.item; +using ColdMint.scripts.item.weapon; + using Godot; namespace ColdMint.scripts.projectile; @@ -64,10 +67,10 @@ public partial class ProjectileTemplate : 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(); + 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) //子弹的存在时间(毫秒) @@ -111,7 +114,9 @@ public partial class ProjectileTemplate : CharacterBody2D return true; } - if (target is WeaponTemplate) + //Match any item now + //现在使它识别任何物品 + if (target is IItem_New) { //Bullets are allowed to strike objects. //允许子弹撞击物品。 @@ -126,7 +131,7 @@ public partial class ProjectileTemplate : CharacterBody2D //First get the owner's camp and compare it with the target camp //先获取主人的阵营与目标阵营进行比较 var canCauseHarm = CampManager.CanCauseHarm(CampManager.GetCamp(ownerCharacterTemplate.CampId), - CampManager.GetCamp(characterTemplate.CampId)); + CampManager.GetCamp(characterTemplate.CampId)); return canCauseHarm; } @@ -169,7 +174,8 @@ public partial class ProjectileTemplate : CharacterBody2D force.Y = KnockbackForce.Y * Config.CellSize; characterTemplate.AddForce(force); } - }else if (target is WeaponTemplate weaponTemplate) + } + else if (target is WeaponTemplate weaponTemplate) { if (KnockbackForce != Vector2.Zero) { @@ -225,9 +231,7 @@ public partial class ProjectileTemplate : CharacterBody2D /// 当子弹离开节点时 /// /// - protected virtual void OnBodyExited(Node2D node) - { - } + protected virtual void OnBodyExited(Node2D node) { } /// diff --git a/scripts/utils/NodeUtils.cs b/scripts/utils/NodeUtils.cs index 5714db6..44ac247 100644 --- a/scripts/utils/NodeUtils.cs +++ b/scripts/utils/NodeUtils.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using ColdMint.scripts.debug; -using ColdMint.scripts.weapon; +using ColdMint.scripts.item.weapon; using Godot; namespace ColdMint.scripts.utils;