diff --git a/DungeonShooting_Godot/src/game/item/package/Holster.cs b/DungeonShooting_Godot/src/game/item/package/Holster.cs index a971b08..a34e5e8 100644 --- a/DungeonShooting_Godot/src/game/item/package/Holster.cs +++ b/DungeonShooting_Godot/src/game/item/package/Holster.cs @@ -8,31 +8,10 @@ public class Holster { /// - /// 插槽类 - /// - public class WeaponSlot - { - /// - /// 是否启用 - /// - public bool Enable = false; - /// - /// 当前插槽存放的武器类型 - /// - public WeaponWeightType Type = WeaponWeightType.MainWeapon; - /// - /// 插槽存放的武器 - /// - public Weapon Weapon; - } - - /// /// 归属者 /// public Role Master { get; } - - //public Weapon HandheldWeapon { get; private set; } - + /// /// 当前使用的武器对象 /// @@ -44,30 +23,69 @@ public int ActiveIndex { get; private set; } = 0; /// + /// 武器袋容量 + /// + public int Capacity { get; private set; } = 0; + + /// /// 武器插槽 /// - public WeaponSlot[] SlotList { get; } = new WeaponSlot[4]; + public Weapon[] Weapons { get; private set; } public Holster(Role master) { Master = master; + //默认容量4 + SetCapacity(4); + } - //创建武器的插槽, 默认前两个都是启用的 - WeaponSlot slot1 = new WeaponSlot(); - slot1.Enable = true; - SlotList[0] = slot1; + /// + /// 修改武器袋容量 + /// + public void SetCapacity(int capacity) + { + if (capacity < 0) + { + capacity = 0; + } - WeaponSlot slot2 = new WeaponSlot(); - slot2.Enable = true; - slot2.Type = WeaponWeightType.DeputyWeapon; - SlotList[1] = slot2; + if (capacity == Capacity) + { + return; + } - WeaponSlot slot3 = new WeaponSlot(); - SlotList[2] = slot3; + if (Weapons == null) + { + Weapons = new Weapon[capacity]; + } + else if (Weapons.Length > capacity) //删减格子 + { + var newArray = new Weapon[capacity]; + for (var i = 0; i < Weapons.Length; i++) + { + if (i < capacity) + { + newArray[i] = Weapons[i]; + } + else + { + Master.ThrowWeapon(i); + } + } - WeaponSlot slot4 = new WeaponSlot(); - slot4.Type = WeaponWeightType.DeputyWeapon; - SlotList[3] = slot4; + Weapons = newArray; + } + else //添加格子 + { + var newArray = new Weapon[capacity]; + for (var i = 0; i < Weapons.Length; i++) + { + newArray[i] = Weapons[i]; + } + Weapons = newArray; + } + Capacity = capacity; + } /// @@ -75,9 +93,9 @@ /// public bool IsEmpty() { - for (int i = 0; i < SlotList.Length; i++) + for (var i = 0; i < Weapons.Length; i++) { - if (SlotList[i].Weapon != null) + if (Weapons[i] != null) { return false; } @@ -91,10 +109,9 @@ /// public bool HasVacancy() { - for (int i = 0; i < SlotList.Length; i++) + for (var i = 0; i < Weapons.Length; i++) { - var item = SlotList[i]; - if (item.Enable && item.Weapon == null) + if (Weapons[i] == null) { return true; } @@ -108,11 +125,11 @@ /// public Weapon GetWeapon(int index) { - if (index < 0 || index >= SlotList.Length) + if (index < 0 || index >= Weapons.Length) { return null; } - return SlotList[index].Weapon; + return Weapons[index]; } /// @@ -121,10 +138,10 @@ /// 武器id public int FindWeapon(string id) { - for (int i = 0; i < SlotList.Length; i++) + for (var i = 0; i < Weapons.Length; i++) { - var item = SlotList[i]; - if (item.Weapon != null && item.Weapon.ItemId == id) + var item = Weapons[i]; + if (item != null && item.ItemId == id) { return i; } @@ -137,10 +154,10 @@ /// public int FindWeapon(Func handler) { - for (int i = 0; i < SlotList.Length; i++) + for (var i = 0; i < Weapons.Length; i++) { - var item = SlotList[i]; - if (item.Weapon != null && handler(item.Weapon, i)) + var item = Weapons[i]; + if (item != null && handler(item, i)) { return i; } @@ -153,12 +170,12 @@ /// public void ForEach(Action handler) { - for (int i = 0; i < SlotList.Length; i++) + for (var i = 0; i < Weapons.Length; i++) { - var item = SlotList[i]; - if (item.Weapon != null) + var item = Weapons[i]; + if (item != null) { - handler(item.Weapon, i); + handler(item, i); } } } @@ -168,17 +185,16 @@ /// public Weapon[] GetAndClearWeapon() { - List weapons = new List(); - for (int i = 0; i < SlotList.Length; i++) + var weapons = new List(); + for (var i = 0; i < Weapons.Length; i++) { - var slot = SlotList[i]; - var weapon = slot.Weapon; + var weapon = Weapons[i]; if (weapon != null) { weapon.GetParent().RemoveChild(weapon); weapon.RemoveAt(); weapons.Add(weapon); - slot.Weapon = null; + Weapons[i] = null; } } @@ -191,10 +207,10 @@ /// 武器对象 public bool CanPickupWeapon(Weapon weapon) { - for (int i = 0; i < SlotList.Length; i++) + for (var i = 0; i < Weapons.Length; i++) { - var item = SlotList[i]; - if (item.Enable && weapon.Attribute.WeightType == item.Type && item.Weapon == null) + var item = Weapons[i]; + if (item == null) { return true; } @@ -214,13 +230,13 @@ { return -1; } - for (int i = 0; i < SlotList.Length; i++) + for (var i = 0; i < Weapons.Length; i++) { - var item = SlotList[i]; - if (item.Enable && weapon.Attribute.WeightType == item.Type && item.Weapon == null) + var item = Weapons[i]; + if (item == null) { weapon.Pickup(); - item.Weapon = weapon; + Weapons[i] = weapon; weapon.PickUpWeapon(Master); if (exchange) { @@ -239,18 +255,17 @@ /// 所在武器袋的位置索引 public Weapon RemoveWeapon(int index) { - if (index < 0 || index >= SlotList.Length) + if (index < 0 || index >= Weapons.Length) { return null; } - var slot = SlotList[index]; - if (slot.Weapon == null) + var weapon = Weapons[index]; + if (weapon == null) { return null; } - var weapon = slot.Weapon; weapon.GetParent().RemoveChild(weapon); - slot.Weapon = null; + Weapons[index] = null; //如果是当前手持的武器, 就需要调用切换武器操作 if (index == ActiveIndex) @@ -276,7 +291,7 @@ { if (index < 0) { - index = SlotList.Length - 1; + index = Weapons.Length - 1; } if (ExchangeByIndex(index)) { @@ -294,7 +309,7 @@ var index = ActiveIndex + 1; do { - if (index >= SlotList.Length) + if (index >= Weapons.Length) { index = 0; } @@ -313,9 +328,9 @@ public bool ExchangeByIndex(int index) { if (index == ActiveIndex && ActiveWeapon != null) return true; - if (index < 0 || index > SlotList.Length) return false; - var slot = SlotList[index]; - if (slot == null || slot.Weapon == null) return false; + if (index < 0 || index > Weapons.Length) return false; + var weapon = Weapons[index]; + if (weapon == null) return false; //将上一把武器放到背后 if (ActiveWeapon != null) @@ -354,21 +369,21 @@ } //更改父节点 - var parent = slot.Weapon.GetParentOrNull(); + var parent = weapon.GetParentOrNull(); if (parent == null) { - Master.MountPoint.AddChild(slot.Weapon); + Master.MountPoint.AddChild(weapon); } else if (parent != Master.MountPoint) { - parent.RemoveChild(slot.Weapon); - Master.MountPoint.AddChild(slot.Weapon); + parent.RemoveChild(weapon); + Master.MountPoint.AddChild(weapon); } - slot.Weapon.Position = Vector2.Zero; - slot.Weapon.Scale = Vector2.One; - slot.Weapon.RotationDegrees = 0; - ActiveWeapon = slot.Weapon; + weapon.Position = Vector2.Zero; + weapon.Scale = Vector2.One; + weapon.RotationDegrees = 0; + ActiveWeapon = weapon; ActiveIndex = index; ActiveWeapon.Active(); return true; diff --git a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs index 3affc00..6c270ce 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs @@ -949,12 +949,8 @@ if (holster.PickupWeapon(this) == -1) { //替换武器 - var slot = holster.SlotList[holster.ActiveIndex]; - if (slot.Type == Attribute.WeightType) - { - roleMaster.ThrowWeapon(); - roleMaster.PickUpWeapon(this); - } + roleMaster.ThrowWeapon(); + roleMaster.PickUpWeapon(this); } } } @@ -1077,7 +1073,7 @@ HideShadowSprite(); OnConceal(); } - + //-------------------------------- Ai相关 ----------------------------- /// diff --git a/DungeonShooting_Godot/src/game/role/Player.cs b/DungeonShooting_Godot/src/game/role/Player.cs index 8ef27b9..ae777c2 100644 --- a/DungeonShooting_Godot/src/game/role/Player.cs +++ b/DungeonShooting_Godot/src/game/role/Player.cs @@ -29,9 +29,7 @@ AttackLayer = PhysicsLayer.Wall | PhysicsLayer.Props | PhysicsLayer.Enemy; Camp = CampEnum.Camp1; - - Holster.SlotList[2].Enable = true; - Holster.SlotList[3].Enable = true; + //让相机跟随玩家 // var remoteTransform = new RemoteTransform2D(); // AddChild(remoteTransform); diff --git a/DungeonShooting_Godot/src/game/role/Role.cs b/DungeonShooting_Godot/src/game/role/Role.cs index e619cf6..8cbc731 100644 --- a/DungeonShooting_Godot/src/game/role/Role.cs +++ b/DungeonShooting_Godot/src/game/role/Role.cs @@ -351,9 +351,9 @@ /// public bool IsAllWeaponTotalAmmoEmpty() { - foreach (var weaponSlot in Holster.SlotList) + foreach (var weapon in Holster.Weapons) { - if (weaponSlot.Weapon != null && !weaponSlot.Weapon.IsTotalAmmoEmpty()) + if (weapon != null && !weapon.IsTotalAmmoEmpty()) { return false; } diff --git a/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs b/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs index e26025b..92edf4e 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs @@ -91,9 +91,6 @@ MoveSpeed = 20; - Holster.SlotList[2].Enable = true; - Holster.SlotList[3].Enable = true; - MaxHp = 20; Hp = 20;