diff --git a/DungeonShooting_Godot/src/game/Cursor.cs b/DungeonShooting_Godot/src/game/Cursor.cs
index 01de4a2..7927549 100644
--- a/DungeonShooting_Godot/src/game/Cursor.cs
+++ b/DungeonShooting_Godot/src/game/Cursor.cs
@@ -37,7 +37,7 @@
{
if (!_isGuiMode)
{
- var targetGun = _mountRole?.Holster.ActiveItem;
+ var targetGun = _mountRole?.WeaponPack.ActiveItem;
if (targetGun != null)
{
SetScope(targetGun.CurrScatteringRange, targetGun);
diff --git a/DungeonShooting_Godot/src/game/activity/package/Package.cs b/DungeonShooting_Godot/src/game/activity/package/Package.cs
index 678b4e3..3541785 100644
--- a/DungeonShooting_Godot/src/game/activity/package/Package.cs
+++ b/DungeonShooting_Godot/src/game/activity/package/Package.cs
@@ -19,7 +19,7 @@
public int ActiveIndex { get; private set; } = 0;
///
- /// 物体袋容量
+ /// 物体背包容量
///
public int Capacity { get; private set; } = 0;
@@ -36,7 +36,7 @@
}
///
- /// 修改物体袋容量
+ /// 修改物体背包容量
///
public void SetCapacity(int capacity)
{
@@ -89,7 +89,7 @@
}
///
- /// 返回当前物体袋是否是空的
+ /// 返回当前物体背包是否是空的
///
public bool IsEmpty()
{
@@ -105,7 +105,7 @@
}
///
- /// 返回当前物体袋是否还有空位
+ /// 返回当前物体背包是否还有空位
///
public bool HasVacancy()
{
@@ -133,10 +133,10 @@
}
///
- /// 根据物体id查找物体袋中该物体所在的位置, 如果没有, 则返回 -1
+ /// 根据物体id查找物体背包中该物体所在的位置, 如果没有, 则返回 -1
///
/// 物体id
- public int FindItem(string id)
+ public int FindIndex(string id)
{
for (var i = 0; i < ItemSlot.Length; i++)
{
@@ -150,9 +150,9 @@
}
///
- /// 通过回调函数查询物体在物体袋中的位置, 如果没有, 则返回 -1
+ /// 通过回调函数查询物体在物体背包中的位置, 如果没有, 则返回 -1
///
- public int FindItem(Func handler)
+ public int FindIndex(Func handler)
{
for (var i = 0; i < ItemSlot.Length; i++)
{
@@ -181,7 +181,7 @@
}
///
- /// 从物体袋中移除所有物体, 并返回
+ /// 从物体背包中移除所有物体, 并返回
///
public T[] GetAndClearItem()
{
@@ -222,7 +222,7 @@
}
///
- /// 拾起物体, 存入物体袋中, 返回存放在物体袋的位置, 如果容不下这个物体, 则会返回 -1
+ /// 拾起物体, 存入物体背包中, 返回存放在物体背包的位置, 如果容不下这个物体, 则会返回 -1
///
/// 物体对象
/// 是否立即切换到该物体, 默认 true
@@ -256,7 +256,7 @@
///
/// 移除指定位置的物体, 并返回这个物体对象, 如果移除正在使用的这个物体, 则会自动切换到上一个物体
///
- /// 所在物体袋的位置索引
+ /// 所在物体背包的位置索引
public T RemoveItem(int index)
{
if (index < 0 || index >= ItemSlot.Length)
@@ -290,6 +290,14 @@
}
///
+ /// 移除指定位置的物体, 并返回这个物体对象, 如果移除正在使用的这个物体, 则会自动切换到上一个物体
+ ///
+ public T RemoveItem(T item)
+ {
+ return RemoveItem(IndexOf(item));
+ }
+
+ ///
/// 切换到上一个物体
///
public int ExchangePrev()
@@ -352,4 +360,47 @@
ActiveItem.OnActiveItem();
return true;
}
+
+ ///
+ /// 返回背包中是否有指定物体
+ ///
+ public bool Contains(T item)
+ {
+ if (ItemSlot == null)
+ {
+ return false;
+ }
+
+ foreach (var packageItem in ItemSlot)
+ {
+ if (packageItem == item)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ ///
+ /// 返回指定物体在当前背包中的索引, 如果不在背包中, 则返回 -1
+ ///
+ public int IndexOf(T item)
+ {
+ if (ItemSlot == null)
+ {
+ return -1;
+ }
+
+ for (var i = 0; i < ItemSlot.Length; i++)
+ {
+ var packageItem = ItemSlot[i];
+ if (packageItem == item)
+ {
+ return i;
+ }
+ }
+
+ return -1;
+ }
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/activity/role/Player.cs b/DungeonShooting_Godot/src/game/activity/role/Player.cs
index f556597..a627439 100644
--- a/DungeonShooting_Godot/src/game/activity/role/Player.cs
+++ b/DungeonShooting_Godot/src/game/activity/role/Player.cs
@@ -145,7 +145,7 @@
public override void ThrowWeapon()
{
//扔掉武器
- var weapon = Holster.ActiveItem;
+ var weapon = WeaponPack.ActiveItem;
base.ThrowWeapon();
EventManager.EmitEvent(EventEnum.OnPlayerRemoveWeapon, weapon);
}
@@ -153,7 +153,7 @@
public override void ThrowWeapon(int index)
{
//扔掉武器
- var weapon = Holster.GetItem(index);
+ var weapon = WeaponPack.GetItem(index);
base.ThrowWeapon(index);
EventManager.EmitEvent(EventEnum.OnPlayerRemoveWeapon, weapon);
}
diff --git a/DungeonShooting_Godot/src/game/activity/role/Role.cs b/DungeonShooting_Godot/src/game/activity/role/Role.cs
index 597e221..5a7878c 100644
--- a/DungeonShooting_Godot/src/game/activity/role/Role.cs
+++ b/DungeonShooting_Godot/src/game/activity/role/Role.cs
@@ -41,12 +41,12 @@
///
/// 携带的道具包裹
///
- public List PropsPack { get; } = new List();
+ public Package PropsPack { get; private set; }
///
- /// 角色携带的武器袋
+ /// 角色携带的武器背包
///
- public Package Holster { get; private set; }
+ public Package WeaponPack { get; private set; }
///
/// 武器挂载点
@@ -306,7 +306,8 @@
public override void OnInit()
{
- Holster = new Package(this);
+ PropsPack = new Package(this);
+ WeaponPack = new Package(this);
_startScale = Scale;
MountPoint.Master = this;
@@ -423,10 +424,13 @@
}
//道具调用更新
- var props = PropsPack.ToArray();
+ var props = (Prop[])PropsPack.ItemSlot.Clone();
foreach (var prop in props)
{
- prop.PackProcess(delta);
+ if (prop != null)
+ {
+ prop.PackProcess(delta);
+ }
}
}
@@ -461,7 +465,7 @@
protected override void OnAffiliationChange()
{
//身上的武器的所属区域也得跟着变
- Holster.ForEach((weapon, i) =>
+ WeaponPack.ForEach((weapon, i) =>
{
if (AffiliationArea != null)
{
@@ -519,7 +523,7 @@
///
public bool IsAllWeaponTotalAmmoEmpty()
{
- foreach (var weapon in Holster.ItemSlot)
+ foreach (var weapon in WeaponPack.ItemSlot)
{
if (weapon != null && !weapon.IsTotalAmmoEmpty())
{
@@ -537,7 +541,7 @@
/// 是否立即切换到该武器, 默认 true
public virtual bool PickUpWeapon(Weapon weapon, bool exchange = true)
{
- if (Holster.PickupItem(weapon, exchange) != -1)
+ if (WeaponPack.PickupItem(weapon, exchange) != -1)
{
//从可互动队列中移除
_interactiveItemList.Remove(weapon);
@@ -552,7 +556,7 @@
///
public virtual void ExchangeNext()
{
- Holster.ExchangeNext();
+ WeaponPack.ExchangeNext();
}
///
@@ -560,7 +564,7 @@
///
public virtual void ExchangePrev()
{
- Holster.ExchangePrev();
+ WeaponPack.ExchangePrev();
}
///
@@ -568,7 +572,7 @@
///
public virtual void ThrowWeapon()
{
- ThrowWeapon(Holster.ActiveIndex);
+ ThrowWeapon(WeaponPack.ActiveIndex);
}
///
@@ -577,7 +581,7 @@
/// 武器在武器袋中的位置
public virtual void ThrowWeapon(int index)
{
- var weapon = Holster.GetItem(index);
+ var weapon = WeaponPack.GetItem(index);
if (weapon == null)
{
return;
@@ -589,7 +593,7 @@
temp.Y = -temp.Y;
}
//var pos = GlobalPosition + temp.Rotated(weapon.GlobalRotation);
- Holster.RemoveItem(index);
+ WeaponPack.RemoveItem(index);
//播放抛出效果
weapon.ThrowWeapon(this, GlobalPosition);
}
@@ -622,9 +626,9 @@
///
public virtual void Reload()
{
- if (Holster.ActiveItem != null)
+ if (WeaponPack.ActiveItem != null)
{
- Holster.ActiveItem.Reload();
+ WeaponPack.ActiveItem.Reload();
}
}
@@ -633,9 +637,9 @@
///
public virtual void Attack()
{
- if (Holster.ActiveItem != null)
+ if (WeaponPack.ActiveItem != null)
{
- Holster.ActiveItem.Trigger();
+ WeaponPack.ActiveItem.Trigger();
}
}
@@ -789,12 +793,11 @@
///
public void PushProp(Prop prop)
{
- if (PropsPack.Contains(prop))
+ if (PropsPack.PickupItem(prop) == -1)
{
- GD.PrintErr("道具已经在包裹中了!");
+ GD.PrintErr("道具无法存入背包中!");
return;
}
- PropsPack.Add(prop);
OnPushProp(prop);
}
@@ -803,12 +806,12 @@
///
public bool RemoveProp(Prop prop)
{
- if (PropsPack.Remove(prop))
+ if (PropsPack.RemoveItem(prop) != null)
{
OnRemoveProp(prop);
return true;
}
- GD.PrintErr("当前道具不在角色包裹中!");
+ GD.PrintErr("当前道具不在角色背包中!");
return false;
}
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs b/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs
index fc6ecda..b7e3f48 100644
--- a/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs
+++ b/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs
@@ -111,7 +111,7 @@
protected override void OnDie()
{
//扔掉所有武器
- var weapons = Holster.GetAndClearItem();
+ var weapons = WeaponPack.GetAndClearItem();
for (var i = 0; i < weapons.Length; i++)
{
weapons[i].ThrowWeapon(this);
@@ -283,16 +283,16 @@
///
public void EnemyAttack(float delta)
{
- var weapon = Holster.ActiveItem;
+ var weapon = WeaponPack.ActiveItem;
if (weapon != null)
{
if (weapon.IsTotalAmmoEmpty()) //当前武器弹药打空
{
//切换到有子弹的武器
- var index = Holster.FindItem((we, i) => !we.IsTotalAmmoEmpty());
+ var index = WeaponPack.FindIndex((we, i) => !we.IsTotalAmmoEmpty());
if (index != -1)
{
- Holster.ExchangeByIndex(index);
+ WeaponPack.ExchangeByIndex(index);
}
else //所有子弹打光
{
@@ -338,9 +338,9 @@
/// 从最小到最大距离的过渡量, 0 - 1, 默认 0.5
public float GetWeaponRange(float weight = 0.5f)
{
- if (Holster.ActiveItem != null)
+ if (WeaponPack.ActiveItem != null)
{
- var attribute = Holster.ActiveItem.Attribute;
+ var attribute = WeaponPack.ActiveItem.Attribute;
return Mathf.Lerp(attribute.BulletMinDistance, attribute.BulletMaxDistance, weight);
}
@@ -415,7 +415,7 @@
//拾起地上的武器
if (InteractiveItem is Weapon weapon)
{
- if (Holster.ActiveItem == null) //手上没有武器, 无论如何也要拾起
+ if (WeaponPack.ActiveItem == null) //手上没有武器, 无论如何也要拾起
{
TriggerInteractive();
return;
@@ -427,10 +427,10 @@
return;
}
- var index = Holster.FindItem((we, i) => we.ItemConfig.Id == weapon.ItemConfig.Id);
+ var index = WeaponPack.FindIndex((we, i) => we.ItemConfig.Id == weapon.ItemConfig.Id);
if (index != -1) //与武器袋中武器类型相同, 补充子弹
{
- if (!Holster.GetItem(index).IsAmmoFull())
+ if (!WeaponPack.GetItem(index).IsAmmoFull())
{
TriggerInteractive();
}
@@ -440,7 +440,7 @@
// var index2 = Holster.FindWeapon((we, i) =>
// we.Attribute.WeightType == weapon.Attribute.WeightType && we.IsTotalAmmoEmpty());
- var index2 = Holster.FindItem((we, i) => we.IsTotalAmmoEmpty());
+ var index2 = WeaponPack.FindIndex((we, i) => we.IsTotalAmmoEmpty());
if (index2 != -1) //扔掉没子弹的武器
{
ThrowWeapon(index2);
diff --git a/DungeonShooting_Godot/src/game/activity/role/enemy/state/AiFollowUpState.cs b/DungeonShooting_Godot/src/game/activity/role/enemy/state/AiFollowUpState.cs
index 2200636..7bf1d93 100644
--- a/DungeonShooting_Godot/src/game/activity/role/enemy/state/AiFollowUpState.cs
+++ b/DungeonShooting_Godot/src/game/activity/role/enemy/state/AiFollowUpState.cs
@@ -64,7 +64,7 @@
//是否在攻击范围内
var inAttackRange = false;
- var weapon = Master.Holster.ActiveItem;
+ var weapon = Master.WeaponPack.ActiveItem;
if (weapon != null)
{
inAttackRange = masterPosition.DistanceSquaredTo(playerPos) <= Mathf.Pow(Master.GetWeaponRange(0.7f), 2);
diff --git a/DungeonShooting_Godot/src/game/activity/role/enemy/state/AiSurroundState.cs b/DungeonShooting_Godot/src/game/activity/role/enemy/state/AiSurroundState.cs
index c60e6ad..c4a9b39 100644
--- a/DungeonShooting_Godot/src/game/activity/role/enemy/state/AiSurroundState.cs
+++ b/DungeonShooting_Godot/src/game/activity/role/enemy/state/AiSurroundState.cs
@@ -53,7 +53,7 @@
}
var playerPos = Player.Current.GetCenterPosition();
- var weapon = Master.Holster.ActiveItem;
+ var weapon = Master.WeaponPack.ActiveItem;
//枪口指向玩家
Master.LookTargetPosition(playerPos);
@@ -160,7 +160,7 @@
private void RunOver(Vector2 targetPos)
{
- var weapon = Master.Holster.ActiveItem;
+ var weapon = Master.WeaponPack.ActiveItem;
var distance = (int)(weapon == null ? 150 : (weapon.Attribute.BulletMinDistance * 0.7f));
_nextPosition = new Vector2(
targetPos.X + Utils.RandomRangeInt(-distance, distance),
diff --git a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs
index ca7cd48..9a0d562 100644
--- a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs
+++ b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs
@@ -116,7 +116,7 @@
///
/// 返回是否真正使用该武器
///
- public bool IsActive => Master != null && Master.Holster.ActiveItem == this;
+ public bool IsActive => Master != null && Master.WeaponPack.ActiveItem == this;
///
/// 动画播放器
@@ -414,7 +414,7 @@
_noAttackTime += delta;
//这把武器被扔在地上, 或者当前武器没有被使用
- if (Master == null || Master.Holster.ActiveItem != this)
+ if (Master == null || Master.WeaponPack.ActiveItem != this)
{
//_triggerTimer
_triggerTimer = _triggerTimer > 0 ? _triggerTimer - delta : 0;
@@ -1439,14 +1439,14 @@
{
if (Master == null)
{
- var masterWeapon = roleMaster.Holster.ActiveItem;
+ var masterWeapon = roleMaster.WeaponPack.ActiveItem;
//查找是否有同类型武器
- var index = roleMaster.Holster.FindItem(ItemConfig.Id);
+ var index = roleMaster.WeaponPack.FindIndex(ItemConfig.Id);
if (index != -1) //如果有这个武器
{
if (CurrAmmo + ResidueAmmo != 0) //子弹不为空
{
- var targetWeapon = roleMaster.Holster.GetItem(index);
+ var targetWeapon = roleMaster.WeaponPack.GetItem(index);
if (!targetWeapon.IsAmmoFull()) //背包里面的武器子弹未满
{
//可以互动拾起弹药
@@ -1458,7 +1458,7 @@
}
else //没有武器
{
- if (roleMaster.Holster.CanPickupItem(this)) //能拾起武器
+ if (roleMaster.WeaponPack.CanPickupItem(this)) //能拾起武器
{
//可以互动, 拾起武器
result.CanInteractive = true;
@@ -1483,9 +1483,9 @@
{
if (master is Role roleMaster) //与role互动
{
- var holster = roleMaster.Holster;
+ var holster = roleMaster.WeaponPack;
//查找是否有同类型武器
- var index = holster.FindItem(ItemConfig.Id);
+ var index = holster.FindIndex(ItemConfig.Id);
if (index != -1) //如果有这个武器
{
if (CurrAmmo + ResidueAmmo == 0) //没有子弹了
diff --git a/DungeonShooting_Godot/src/game/ui/roomUI/ReloadBar.cs b/DungeonShooting_Godot/src/game/ui/roomUI/ReloadBar.cs
index b1b9e93..71f2327 100644
--- a/DungeonShooting_Godot/src/game/ui/roomUI/ReloadBar.cs
+++ b/DungeonShooting_Godot/src/game/ui/roomUI/ReloadBar.cs
@@ -56,9 +56,9 @@
public void OnCameraPositionUpdate(float delta)
{
var player = Player.Current;
- if (player.Holster.ActiveItem != null && player.Holster.ActiveItem.Reloading)
+ if (player.WeaponPack.ActiveItem != null && player.WeaponPack.ActiveItem.Reloading)
{
- ShowBar(player.GlobalPosition, player.Holster.ActiveItem.ReloadProgress);
+ ShowBar(player.GlobalPosition, player.WeaponPack.ActiveItem.ReloadProgress);
}
else
{
diff --git a/DungeonShooting_Godot/src/game/ui/roomUI/WeaponBar.cs b/DungeonShooting_Godot/src/game/ui/roomUI/WeaponBar.cs
index 3f3c062..33ef47f 100644
--- a/DungeonShooting_Godot/src/game/ui/roomUI/WeaponBar.cs
+++ b/DungeonShooting_Godot/src/game/ui/roomUI/WeaponBar.cs
@@ -25,7 +25,7 @@
public void Process(float delta)
{
- var weapon = Player.Current?.Holster.ActiveItem;
+ var weapon = Player.Current?.WeaponPack.ActiveItem;
if (weapon != null)
{
SetWeaponTexture(weapon.GetCurrentTexture());