private void Alert(Enemy obj) { if (obj.OwnerId.Equals(HeadQuarter.OwnerId)) return; CallToHotSpot(obj, HeadQuarter.Position.X, HeadQuarter.Position.X); foreach (var barrack in _barrack) CallToHotSpot(obj, barrack.Position.X, barrack.Position.Y); if (obj.IsBuilding && !targets.Any(x => x.Id!=null && x.Id.Equals(obj.Id))) { targets.Add(new Target { X = obj.X, Y = obj.Y, Id = obj.Id }); var randomDivision = GetRandomDivision(); randomDivision.TargetX = obj.X; randomDivision.TargetY = obj.Y; } var spotter = _soldiers.FirstOrDefault(x => x.Id.Equals(obj.ExplorerId)); var devision = divisions.FirstOrDefault(x => x.Units.Any(y => y.Id.Equals(obj.ExplorerId))); if (devision != null) { devision.TargetX = obj.X; devision.TargetY = obj.Y; devision.Units.Where(x=>x.IsInAttackRange(new Vector2(obj.X, obj.Y))).ToList().ForEach(x => Agent.Enqueue(new UnitAttacksEvent(HeadQuarter.OwnerId, x.Id, obj.Id)) ); } else if (spotter!=null) { spotter.Attack(obj.Id); } Move(); }
private void CallToHotSpot(Enemy obj, float criticalPositionX, float criticalY) { if (obj.X - 30 < criticalPositionX && criticalPositionX < obj.X + 30 && obj.Y - 30 < criticalY && criticalY < obj.Y + 30) { var randomDivision = GetRandomDivision(); randomDivision.TargetX = obj.X; randomDivision.TargetY = obj.Y; Move(); } }