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.
60 lines
2.1 KiB
60 lines
2.1 KiB
using CoreGame;
|
|
using Entitas;
|
|
using xFrame;
|
|
|
|
namespace CoreGame.Render
|
|
{
|
|
/// <summary>
|
|
/// 装弹系统
|
|
/// </summary>
|
|
public class GunReloadSystem : IExecuteSystem
|
|
{
|
|
readonly IGroup<CombatEntity> m_Group;
|
|
|
|
public GunReloadSystem(Contexts contexts)
|
|
{
|
|
m_Group = contexts.combat.GetGroup(MatcherExt.s_GunReloadMatcher);
|
|
}
|
|
|
|
public void Execute(float dt)
|
|
{
|
|
m_Group.GetEntities(Contexts.s_CacheEntities);
|
|
if (Contexts.s_CacheEntities.Count == 0)
|
|
return;
|
|
|
|
var entities = Contexts.s_CacheEntities;
|
|
for (int i = 0; i < entities.Count; i++)
|
|
{
|
|
var entity = entities[i];
|
|
var owner = entity.parentRecorder.ParentEntity;
|
|
var reload = entity.reload;
|
|
if (owner.equips.GetHoldGunEntity().creationIndex != entity.creationIndex)
|
|
continue;
|
|
|
|
reload.cdAcc += dt;
|
|
if (reload.cdAcc <= reload.cdTotal)
|
|
continue;
|
|
|
|
// 装弹, 并且移除装弹组件
|
|
var gc = entity.gunData;
|
|
var prop = entity.property;
|
|
var tbGun = WeaponDescMgr.Instance.GetConfig(gc.gunCfgId);
|
|
// 装弹也要通知UI
|
|
|
|
var ammo = (int)(ExpressionEvaluator.CalcVal_WithProp(tbGun.Capacity, owner.property.container, 1) +
|
|
PropertyContainer.Epsilon);
|
|
prop.SetProperty(PropertyDef.AmmoMax, ammo, true);
|
|
prop.AddValue(PropertyDef.Ammo, ammo);
|
|
if (owner.isLocalPlayer)
|
|
{
|
|
CoreUIBridge.CoreGamePushGunReload(gc.slotId, false);
|
|
CoreUIBridge.CoreGamePushSlotBulletChanged(gc.slotId, (int)prop.GetProperty(PropertyDef.Ammo),
|
|
ammo);
|
|
}
|
|
GunSrv.PushAmmoBarData(owner, 1f, 0f, 0f, true);
|
|
owner.DispatchEvent(ClientEvent.OnGunReloadEnd, null);
|
|
entity.RemoveReload();
|
|
}
|
|
}
|
|
}
|
|
}
|