(client)feat:实现按武器释放技能

This commit is contained in:
m0_75251201
2025-08-27 19:08:27 +08:00
parent 63efa89ac1
commit 5315e29147
25 changed files with 1184 additions and 5106 deletions

View File

@ -68,33 +68,33 @@ namespace Entity
return remainingQuantity;
}
public override void TryAttack()
{
if (IsAttacking)
return;
if (!DefineManager.Instance.defines.TryGetValue(nameof(BulletDef), out var def))
return;
// 修正First() 可能会在一个空的 Values 集合上抛出异常。
// 更好的做法是使用 TryGetValue 或 FirstOrDefault 并检查结果。
// 这里假设至少有一个 BulletDef 存在,如果不是,需要更复杂的错误处理。
var bulletDefEntry = def.Values.FirstOrDefault();
if (bulletDefEntry == null)
{
Debug.LogError("No BulletDef found in DefineManager. Cannot attack.");
return;
}
var bulletDef = (BulletDef)bulletDefEntry;
Vector3 dir = MousePosition.GetWorldPosition();
EntityManage.Instance.GenerateBulletEntity(Program.Instance.FocusedDimensionId, bulletDef, Position,
dir - Position, this);
}
// public override void TryAttack()
// {
// if (IsAttacking)
// return;
// if (!DefineManager.Instance.defines.TryGetValue(nameof(BulletDef), out var def))
// return;
// // 修正First() 可能会在一个空的 Values 集合上抛出异常。
// // 更好的做法是使用 TryGetValue 或 FirstOrDefault 并检查结果。
// // 这里假设至少有一个 BulletDef 存在,如果不是,需要更复杂的错误处理。
// var bulletDefEntry = def.Values.FirstOrDefault();
// if (bulletDefEntry == null)
// {
// Debug.LogError("No BulletDef found in DefineManager. Cannot attack.");
// return;
// }
//
// var bulletDef = (BulletDef)bulletDefEntry;
//
// Vector3 dir = MousePosition.GetWorldPosition();
// EntityManage.Instance.GenerateBulletEntity(Program.Instance.FocusedDimensionId, bulletDef, Position,
// dir - Position, this);
// }
public override WeaponResource GetCurrentWeapon()
{
var currentSelectItem = Inventory.GetSlot(CurrentSelected);
return (WeaponResource)currentSelectItem.Item;
return (WeaponResource)currentSelectItem?.Item;
}
}
}