using CoreGame; using Entitas; using xFrame; namespace CoreGame.Render { /// /// 装弹系统 /// public class GunReloadSystem : IExecuteSystem { readonly IGroup 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(); } } } }