(client)feat:实现按武器释放技能
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user