bool DealOrder(UnitInfo unit, FuelModifyType type, ref FuelComponent.Component fuel) { FuelComponent.Component?comp = null; if (TryGetComponent(unit.id, out comp) == false) { return(false); } var t_fuel = comp.Value; int num = 0; switch (type) { case FuelModifyType.Feed: num = Mathf.Clamp(t_fuel.EmptyCapacity(), 0, fuel.Fuel); fuel.Fuel -= num; break; case FuelModifyType.Absorb: num = Mathf.Clamp(fuel.EmptyCapacity(), 0, t_fuel.Fuel); fuel.Fuel += num; break; default: return(false); } var modify = new FuelModifier { Type = type, Amount = num, }; this.UpdateSystem.SendEvent(new FuelComponent.FuelModified.Event(modify), unit.id); return(true); }
void HandleRequest() { Entities.With(group).ForEach((Unity.Entities.Entity entity, ref FuelSupplyer.Component supply, ref FuelComponent.Component fuel, ref BaseUnitStatus.Component status, ref BaseUnitTarget.Component tgt, ref SpatialEntityId entityId) => { if (status.State != UnitState.Alive) { return; } if (status.Type != UnitType.Supply) { return; } if (supply.OrderFinished) { return; } var inter = supply.Interval; if (CheckTime(ref inter) == false) { return; } supply.Interval = inter; float range = supply.Range; var f_comp = fuel; var trans = EntityManager.GetComponentObject <Transform>(entity); var pos = trans.position; var id = supply.Order.Point.StrongholdId; var units = getAllyUnits(status.Side, pos, range, allowDead: false, GetSingleUnitTypes(UnitType.Stronghold)); foreach (var unit in units) { if (unit.id != id) { continue; } FuelModifyType type = FuelModifyType.None; switch (supply.Order.Type) { case SupplyOrderType.Deliver: type = FuelModifyType.Feed; break; case SupplyOrderType.Accept: type = FuelModifyType.Absorb; break; } bool tof = DealOrder(unit, type, ref f_comp); SendResult(tof, supply.ManagerId, entityId.EntityId, supply.Order); supply.OrderFinished = true; break; } if (fuel.Fuel != f_comp.Fuel) { fuel = f_comp; } }); }