Exemplo n.º 1
0
        private void ProcessBored(InfanteryMind mind)
        {
            if (mind.SpottedUnitsBag.Any()) {
                mind.ChangeState(EMindState.Engaged);
                ProcessEngaged(mind);
            }
            else
            {

                if(mind.BlockedPositon != null)
                {
                    var upDown = random.Next(0, 100) > 50 ? true : false;
                    var leftRight = random.Next(0, 100) > 50 ? true : false;
                    var next = random.Next(0, 20);
                    var y = upDown ? next*-1 : next;
                    var x = leftRight ? next*-1 : next;
                    var wayPointStore = _pathfindingService.Provide(mind.Infantery.Position, new Vector2(mind.BlockedPositon.X + x, mind.BlockedPositon.X + y));
                    mind.WayPointStore = wayPointStore;
                    mind.BlockedPositon = null;
                }
                else
                {
                    var heatMapSectors = _heatMapService.Get();
                    var heatMapSector = heatMapSectors.OrderByDescending(x => x.HeatFactor).First();

                    var index = random.Next(0, heatMapSectors.Count - 1);
                    Debug.WriteLine("Random was: " + index);
                    var target = heatMapSector.HeatFactor <= 1 ? heatMapSectors[index].Center : heatMapSector.Center;
                    var wayPointStore = _pathfindingService.Provide(mind.Infantery.Position, target);
                    mind.WayPointStore = wayPointStore;

                }
                mind.ChangeState(EMindState.Scouting);
            }
        }
Exemplo n.º 2
0
        private void ProcessEngaged(InfanteryMind infanteryMind)
        {
            if(!infanteryMind.SpottedUnitsBag.Any())
            {
                infanteryMind.ChangeState(EMindState.Bored);
                return;

            }

            infanteryMind.EngagedProxy = new EngagedProxy(infanteryMind.SpottedUnitsBag.First().Id);
            var attackEvent = new UnitAttacksEvent(infanteryMind.Infantery.OwnerId, infanteryMind.Infantery.Id,
                                                   infanteryMind.EngagedProxy.TargetId);
            infanteryMind.EngagedProxy.AttackEventId = attackEvent.Id;

            _eventAgent.Enqueue(attackEvent);
        }
Exemplo n.º 3
0
        private void ProcessScouting(InfanteryMind infanteryMind)
        {
            if (infanteryMind.SpottedUnitsBag.Any())
            {
                infanteryMind.ChangeState(EMindState.Engaged);
                ProcessEngaged(infanteryMind);

            }
            else {

                var wayPoint = infanteryMind.WayPointStore.FirstOrDefault();
                if (wayPoint == null)
                    infanteryMind.ChangeState(EMindState.Bored);
                else {
                    wayPoint.Event = new MoveUnitEvent(infanteryMind.Infantery.OwnerId, infanteryMind.Infantery.Id,
                                                       wayPoint.Target.X, wayPoint.Target.Y);
                    _eventAgent.Enqueue(wayPoint.Event);
                }
            }
        }