private void FacilityQuery(Entity entity, ref HexFacility.Component facility, ref BaseUnitStatus.Component status, ref SpatialEntityId entityId) { var hexIndex = facility.HexIndex; var side = status.Side; if (HexDic.ContainsKey(hexIndex) == false) { return; } var hex = HexDic[hexIndex]; if (hex.Side == status.Side) { return; } changedCount++; hex.Side = status.Side; this.UpdateSystem.SendEvent(new HexBase.SideChanged.Event(new SideChangedEvent(side)), hex.EntityId.EntityId); //Debug.LogFormat("Updated Index:{0} Side:{1}", hexIndex, side); }
void FactoryQuery(Unity.Entities.Entity entity, ref UnitFactory.Component factory, ref BaseUnitStatus.Component status, ref StrongholdSight.Component sight, ref HexFacility.Component hex) { if (status.State != UnitState.Alive) { return; } if (UnitUtils.IsBuilding(status.Type) == false) { return; } if (status.Side == UnitSide.None) { return; } UnityEngine.Profiling.Profiler.BeginSample("HandleFactoryRequests:CheckAlive"); var trans = EntityManager.GetComponentObject <Transform>(entity); CheckAlive(trans.position, status.Side, uint.MaxValue, HexDictionary.HexEdgeLength * 2, teamsDic); UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("HandleFactoryRequests:MakeOrders"); // number check if (factory.TeamOrders.Count == 0 && sight.StrategyVector.Side != UnitSide.None) { var teamOrders = factory.TeamOrders; makeOrders(status.Side, status.Rank, PostureUtils.RotFoward(sight.StrategyVector.Vector.ToUnityVector()), status.Order, hex.HexIndex, sight.FrontLineCorners, sight.TargetHexes, teamsDic, teamOrders); factory.TeamOrders = teamOrders; } UnityEngine.Profiling.Profiler.EndSample(); #if false if (factory.TurretOrders.Count == 0) { var turretOrders = factory.TurretOrders; makeOrders(trans.position, status.Side, status.Rank, turretOrders); factory.TurretOrders = turretOrders; } #endif }
private void Query(Entity entity, ref StrongholdSight.Component sight, ref BaseUnitStatus.Component status, ref HexFacility.Component hex, ref SpatialEntityId entityId) { if (status.State != UnitState.Alive) { return; } if (UnitUtils.IsBuilding(status.Type) == false) { return; } if (status.Side == UnitSide.None) { return; } var inter = sight.Interval; if (CheckTime(ref inter) == false) { return; } sight.Interval = inter; var trans = EntityManager.GetComponentObject <Transform>(entity); var targets = sight.TargetStrongholds; var enemySide = sight.StrategyVector.Side; var vector = sight.StrategyVector.Vector.ToUnityVector(); var corners = sight.FrontLineCorners; var hexes = sight.TargetHexes; var order = GetTarget(trans.position, hex.HexIndex, this.FrontHexes, this.HexIndexes, status.Side, enemySide, hexes, corners); sight.TargetStrongholds = targets; sight.FrontLineCorners = corners; sight.TargetHexes = hexes; status.Order = order; }
void OrderQuery(Unity.Entities.Entity entity, ref BaseUnitStatus.Component status, ref StrongholdSight.Component sight, ref HexFacility.Component hex) { if (status.State != UnitState.Alive) { return; } if (UnitUtils.IsBuilding(status.Type) == false) { return; } if (status.Side == UnitSide.None) { return; } var trans = EntityManager.GetComponentObject <Transform>(entity); CheckAlive(trans.position, status.Side, hex.HexIndex, HexDictionary.HexEdgeLength, teamsDic); sendIds.Clear(); // order check // Not Set Strongholds UnityEngine.Profiling.Profiler.BeginSample("CheckOrder:Strongholds"); CheckOrder(hex.HexIndex, status.Order, sight.TargetStrongholds, sight.StrategyVector.Vector.ToUnityVector(), teamsDic, sendIds); UnityEngine.Profiling.Profiler.EndSample(); // FrontLineCorners UnityEngine.Profiling.Profiler.BeginSample("CheckOrder:FrontLineCorners"); CheckOrder(hex.HexIndex, status.Order, status.Side, sight.FrontLineCorners, sight.StrategyVector.Vector.ToUnityVector(), teamsDic, sendIds); UnityEngine.Profiling.Profiler.EndSample(); // Hex UnityEngine.Profiling.Profiler.BeginSample("CheckOrder:TargetHexes"); CheckOrder(hex.HexIndex, status.Order, sight.TargetHexes, sight.StrategyVector.Vector.ToUnityVector(), teamsDic, sendIds); UnityEngine.Profiling.Profiler.EndSample(); }
private void Query(Transform trans, ref TurretHub.Component turret, ref BaseUnitStatus.Component status, ref HexFacility.Component hex, ref SpatialEntityId entityId) { if (status.State != UnitState.Alive) { return; } if (UnitUtils.IsBuilding(status.Type) == false) { return; } var datas = turret.TurretsDatas; if (IsNeedRenewTurrets(datas) == false) { return; } var units = getAllUnits(trans.position, HexDictionary.HexEdgeLength, allowDead: true, GetSingleUnitTypes(UnitType.Turret)); removeKeys.Clear(); foreach (var k in datas.Keys) { removeKeys.Add(k); } bool changed = false; var hexIndex = hex.HexIndex; foreach (var u in units) { if (hexIndex != uint.MaxValue && HexUtils.IsInsideHex(this.Origin, hexIndex, u.pos, HexDictionary.HexEdgeLength) == false) { continue; } if (TryGetComponent <TurretComponent.Component>(u.id, out var comp) == false) { continue; } int masterId = comp.Value.MasterId; if (datas.ContainsKey(u.id)) { var val = datas[u.id]; if (CheckDiffTurretInfo(ref val, u.side, masterId, u.id)) { datas[u.id] = val; changed = true; } removeKeys.Remove(u.id); } else { datas[u.id] = new TurretInfo(u.side, masterId, u.id); changed = true; } } if (removeKeys.Count == 0 && changed == false) { return; } foreach (var k in removeKeys) { datas.Remove(k); } turret.TurretsDatas = datas; }