You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
3.4 KiB
123 lines
3.4 KiB
using Entitas;
|
|
using Sog;
|
|
|
|
namespace CoreGame.Render
|
|
{
|
|
public struct EquipData
|
|
{
|
|
public int slotId;
|
|
public int equipEid;
|
|
public int ownerId;
|
|
public int gunCfgId;
|
|
public Fixed64 holdDownTime;
|
|
public Fixed64 holdDownCD;
|
|
}
|
|
|
|
// 这组件理论上只有角色用吧
|
|
[Combat]
|
|
public class EquipsComponent : IComponent, IReset
|
|
{
|
|
public CombatEntity owner;
|
|
|
|
// 武器槽位应该不会太多, 规定第0个为主武器, 第1个为辅助武器
|
|
internal readonly EquipData[] slotDatas = new EquipData[2];
|
|
internal int usedSlot = -1;
|
|
internal int lastUsedSlot = -1; // 上一次使用的武器槽位, 用于切枪
|
|
|
|
// 获取当前使用的武器
|
|
public CombatEntity GetHoldGunEntity()
|
|
{
|
|
if (usedSlot < 0 || usedSlot >= slotDatas.Length)
|
|
return null;
|
|
if (slotDatas[usedSlot].equipEid == 0)
|
|
return null;
|
|
|
|
return Contexts.Combat.GetEntity(slotDatas[usedSlot].equipEid);
|
|
}
|
|
|
|
public CombatEntity GetMainGunEntity()
|
|
{
|
|
if (slotDatas[0].equipEid == 0)
|
|
return null;
|
|
|
|
return Contexts.Combat.GetEntity(slotDatas[0].equipEid);
|
|
}
|
|
|
|
public CombatEntity GetSupportGunEntity()
|
|
{
|
|
if (slotDatas[1].equipEid == 0)
|
|
return null;
|
|
|
|
return Contexts.Combat.GetEntity(slotDatas[1].equipEid);
|
|
}
|
|
|
|
|
|
// 获取指定槽位的武器
|
|
public CombatEntity GetSlotGunEntity(int slot)
|
|
{
|
|
if (slot < 0 || slot >= slotDatas.Length)
|
|
return null;
|
|
return Contexts.Combat.GetEntity(slotDatas[slot].equipEid);
|
|
}
|
|
|
|
public ref EquipData GetSlotData(int slot)
|
|
{
|
|
return ref slotDatas[slot];
|
|
}
|
|
|
|
public ref EquipData GetMainSlotData()
|
|
{
|
|
return ref slotDatas[0];
|
|
}
|
|
|
|
public ref EquipData GetSupportSlotData()
|
|
{
|
|
return ref slotDatas[1];
|
|
}
|
|
|
|
public ref EquipData GetHoldSlotData()
|
|
{
|
|
return ref slotDatas[usedSlot];
|
|
}
|
|
|
|
public ref EquipData GetNextSlotData()
|
|
{
|
|
return ref slotDatas[usedSlot + 1 >= slotDatas.Length ? 0 : usedSlot + 1];
|
|
}
|
|
|
|
public void AddGunToOwner(CombatEntity gun, int slotId)
|
|
{
|
|
if (gun == null)
|
|
{
|
|
return;
|
|
}
|
|
var gunDesc = WeaponDescMgr.Instance.GetConfig(gun.gunData.gunCfgId);
|
|
var cd = gunDesc.ReEnterCD * BattleConst.TenThousandReverse;
|
|
slotDatas[slotId] = new EquipData
|
|
{
|
|
slotId = slotId,
|
|
equipEid = gun.creationIndex,
|
|
ownerId = owner.creationIndex,
|
|
gunCfgId = gun.gunData.gunCfgId,
|
|
holdDownCD = cd,
|
|
//保证刚进入战斗场景时可以切枪
|
|
holdDownTime = GameTime.GetRenderTime() - cd
|
|
};
|
|
}
|
|
|
|
public void SwitchSlotNoCheck(int slot)
|
|
{
|
|
lastUsedSlot = usedSlot;
|
|
usedSlot = slot;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
for (var i = 0; i < slotDatas.Length; i++)
|
|
{
|
|
slotDatas[i] = default;
|
|
}
|
|
usedSlot = -1;
|
|
}
|
|
}
|
|
}
|