public void OnStart()
        {
            if (GameConstants.ParticipantRace != Race.Zerg)
            {
                return;
            }
            _queenSquadId = _squadRepo.Create("Queens").Id;
            var hatcheries = _squadRepo.Create("Hatcheries");

            hatcheries.AddUnit(_intel.StructuresSelf().First(u => u.UnitType == BlizzardConstants.Unit.Hatchery));
            _hatcheriesId = hatcheries.Id;

            _intel.Handler.RegisterHandler(Case.UnitAddedSelf, u => {
                if (u.UnitType == BlizzardConstants.Unit.Queen)
                {
                    _squadRepo.Get().First(g => g.Name.Equals("Queens")).Units.Add(u);
                }
            });

            _intel.Handler.RegisterHandler(Case.StructureAddedSelf, u => {
                if (u.UnitType == BlizzardConstants.Unit.Hatchery || u.UnitType == BlizzardConstants.Unit.Lair || u.UnitType == BlizzardConstants.Unit.Hive)
                {
                    _squadRepo.Get().First(g => g.Name.Equals("Hatcheries")).Units.Add(u);
                }
            });
        }
        public void OnUnitDestroyed(IUnit unit)
        {
            if (unitToSquad.ContainsKey(unit.Tag))
            {
                var squad = squadRepo.Get(unitToSquad[unit.Tag]);
                squad.RemoveUnit(unit);
                if (squad.Units.Count == 0)
                {
                    squads.Remove(squad.Name);
                }

                unitToSquad.Remove(unit.Tag);
            }
        }
        public void Execute(CombatRequest request)
        {
            switch (request.CommandCase)
            {
            case CombatRequest.CommandOneofCase.MoveUnit:
                _manager.Move(request.MoveUnit.UnitTag, request.MoveUnit.Point, request.MoveUnit.Queue);
                break;

            case CombatRequest.CommandOneofCase.MoveSquad:
                _manager.Move(_repository.Get().First(s => s.Id.Equals(request.MoveSquad.Squad)),
                              request.MoveSquad.Point, request.MoveSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.AttackMoveUnit:
                _manager.AttackMove(request.AttackMoveUnit.UnitTag, request.AttackMoveUnit.Point,
                                    request.AttackMoveUnit.Queue);
                break;

            case CombatRequest.CommandOneofCase.AttackMoveSquad:
                _manager.AttackMove(_repository.Get().First(s => s.Id.Equals(request.AttackMoveSquad.Squad)),
                                    request.AttackMoveSquad.Point, request.AttackMoveSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.AttackUnit:
                _manager.Attack(request.AttackUnit.SourceUnit, request.AttackUnit.TargetUnit,
                                request.AttackUnit.Queue);
                break;

            case CombatRequest.CommandOneofCase.AttackSquad:
                _manager.Attack(_repository.Get().First(s => s.Id.Equals(request.AttackSquad.Squad)),
                                request.AttackSquad.TargetUnit, request.AttackSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.UseTargetedAbilityUnit:
                _manager.UseTargetedAbility(request.UseTargetedAbilityUnit.AbilityId,
                                            request.UseTargetedAbilityUnit.SourceUnit, request.UseTargetedAbilityUnit.TargetUnit,
                                            request.UseTargetedAbilityUnit.Queue);
                break;

            case CombatRequest.CommandOneofCase.UseTargetedAbilitySquad:
                _manager.UseTargetedAbility(request.UseTargetedAbilitySquad.AbilityId,
                                            _repository.Get().First(s => s.Id.Equals(request.UseTargetedAbilitySquad.Squad)),
                                            request.UseTargetedAbilitySquad.TargetUnit, request.UseTargetedAbilitySquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.UsePointCenteredAbilityUnit:
                _manager.UsePointCenteredAbility(request.UsePointCenteredAbilityUnit.AbilityId,
                                                 request.UsePointCenteredAbilityUnit.SourceUnit, request.UsePointCenteredAbilityUnit.Point);
                break;

            case CombatRequest.CommandOneofCase.UsePointCenteredAbilitySquad:
                _manager.UsePointCenteredAbility(request.UsePointCenteredAbilitySquad.AbilityId,
                                                 _repository.Get().First(s => s.Id.Equals(request.UsePointCenteredAbilitySquad.Squad)),
                                                 request.UsePointCenteredAbilitySquad.Point, request.UsePointCenteredAbilitySquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.UseTargetlessAbilityUnit:
                _manager.UseTargetlessAbility(request.UseTargetlessAbilityUnit.AbilityId,
                                              request.UseTargetlessAbilityUnit.SourceUnit, request.UseTargetlessAbilityUnit.Queue);
                break;

            case CombatRequest.CommandOneofCase.UseTargetlessAbilitySquad:
                _manager.UseTargetlessAbility(request.UseTargetedAbilitySquad.AbilityId,
                                              _repository.Get().First(s => s.Id.Equals(request.UseTargetedAbilitySquad.Squad)),
                                              request.UseTargetedAbilitySquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.SmartMoveUnit:
                if (_intel.TryGet(request.SmartMoveUnit.UnitTag, out IUnit unit))
                {
                    _manager.SmartMove(unit, request.SmartMoveUnit.Point, request.SmartMoveUnit.Queue);
                }
                break;

            case CombatRequest.CommandOneofCase.SmartMoveSquad:
                _manager.SmartMove(_repository.Get().First(s => s.Id.Equals(request.SmartMoveSquad.Squad)),
                                   request.SmartMoveSquad.Point, request.SmartMoveSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.SmartAttackMoveUnit:
                if (_intel.TryGet(request.SmartMoveUnit.UnitTag, out IUnit u))
                {
                    _manager.SmartAttackMove(u, request.SmartAttackMoveUnit.Point, request.SmartAttackMoveUnit.Queue);
                }
                break;

            case CombatRequest.CommandOneofCase.SmartAttackMoveSquad:
                _manager.SmartAttackMove(
                    _repository.Get().First(s => s.Id.Equals(request.SmartAttackMoveSquad.Squad)),
                    request.SmartAttackMoveSquad.Point, request.SmartAttackMoveSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.SmartAttackUnit:
                if (_intel.TryGet(request.SmartAttackUnit.SourceUnit, out IUnit un))
                {
                    _manager.SmartAttack(un, request.SmartAttackUnit.TargetUnit, request.SmartAttackUnit.Queue);
                }
                break;

            case CombatRequest.CommandOneofCase.SmartAttackSquad:
                _manager.SmartAttack(_repository.Get().First(s => s.Id.Equals(request.SmartAttackSquad.Squad)),
                                     request.SmartAttackSquad.TargetUnit, request.SmartAttackSquad.Queue);
                break;

            case CombatRequest.CommandOneofCase.SquadRequest:
                var addUnits    = request.SquadRequest.AddUnits;
                var removeUnits = request.SquadRequest.RemoveUnits;
                var createSquad = request.SquadRequest.CreateSquad;
                var removeSquad = request.SquadRequest.RemoveSquad;
                if (request.SquadRequest.AddUnits != null)
                {
                    foreach (var tag in addUnits.Tags)
                    {
                        if (_intel.TryGet(tag, out var addedUnit))
                        {
                            _repository.Get().First(s => s.Id.Equals(request.SquadRequest.AddUnits.SquadId))
                            .AddUnit(addedUnit);
                        }
                    }
                }
                if (removeUnits != null)
                {
                    foreach (var tag in removeUnits.Tags)
                    {
                        if (_intel.TryGet(tag, out var removedUnit))
                        {
                            _repository.Get().First(s => s.Id.Equals(request.SquadRequest.RemoveUnits.SquadId))
                            .RemoveUnit(removedUnit);
                        }
                    }
                }
                if (createSquad != null)
                {
                    _repository.Create(createSquad.Squad.Name, createSquad.Squad.SquadId);
                }
                if (removeSquad != null)
                {
                    _repository.Remove(removeSquad.SquadId);
                }
                break;

            default:
                throw new System.NotImplementedException();
            }
        }
Beispiel #4
0
        public IntelResponse BundleIntel(IntelRequest request)
        {
            AbathurMap map = null;

            if (request.Map)
            {
                map = new AbathurMap {
                }
            }
            ;
            Score score = null;

            if (request.Score)
            {
                score = _intel.CurrentScore;
            }
            PlayerCommon playerCommon = null;

            if (request.Common)
            {
                playerCommon = _intel.Common;
            }
            ICollection <UpgradeData> upgradeSelf = null;

            if (request.UpgradesSelf)
            {
                upgradeSelf = _intel.UpgradesSelf;
            }
            ICollection <IUnit> alliedBuilding = null;

            if (request.BuildingsSelf)
            {
                alliedBuilding = _intel.StructuresSelf().ToList();
            }
            ICollection <IUnit> alliedWorkers = null;

            if (request.WorkersSelf)
            {
                alliedWorkers = _intel.WorkersSelf().ToList();
            }
            ICollection <IUnit> alliedUnits = null;

            if (request.WorkersSelf)
            {
                alliedUnits = _intel.UnitsSelf().ToList();
            }
            ICollection <IUnit> structuresEnemy = null;

            if (request.StructuresEnemy)
            {
                structuresEnemy = _intel.WorkersEnemy().ToList();
            }
            ICollection <IUnit> unitsEnemy = null;

            if (request.UnitsEnemy)
            {
                unitsEnemy = _intel.WorkersEnemy().ToList();
            }
            ICollection <IUnit> workersEnemy = null;

            if (request.WorkersEnemy)
            {
                workersEnemy = _intel.WorkersEnemy().ToList();
            }
            IColony primaryColony = null;

            if (request.PrimaryColony)
            {
                primaryColony = _intel.PrimaryColony;
            }
            IEnumerable <IColony> colonies = null;

            if (request.Colonies)
            {
                colonies = _intel.Colonies;
            }
            ICollection <IUnit> mineralFields = null;

            if (request.MineralFields)
            {
                mineralFields = _intel.MineralFields.ToList();
            }
            ICollection <IUnit> vespeneGeysers = null;

            if (request.VespeneGeysers)
            {
                vespeneGeysers = _intel.VespeneGeysers.ToList();
            }
            ICollection <IUnit> destructibles = null;

            if (request.Destructibles)
            {
                destructibles = _intel.Destructibles().ToList();
            }
            ICollection <UnitTypeData> productionQueue = null;

            if (request.ProductionQueue)
            {
                productionQueue = _intel.ProductionQueue.ToList();
            }
            IEnumerable <Squad> squads = null;

            if (request.Squads)
            {
                squads = _squadRepo.Get();
            }
            uint gameloop = 0;

            if (request.GameLoop)
            {
                gameloop = _intel.GameLoop;
            }

            return(new IntelResponse {
                Map = map,
                Score = score,
                Common = playerCommon,
                UpgradesSelf = { upgradeSelf },
                BuildingsSelf = { Convert(alliedBuilding) },
                WorkersSelf = { Convert(alliedWorkers) },
                UnitsSelf = { Convert(alliedUnits) },
                StructuresEnemy = { Convert(structuresEnemy) },
                WorkersEnemy = { Convert(workersEnemy) },
                UnitsEnemy = { Convert(unitsEnemy) },
                PrimaryColony = Convert(primaryColony),
                Colonies = { Convert(colonies.ToList()) },
                MineralFields = { Convert(mineralFields) },
                VespeneGeysers = { Convert(vespeneGeysers) },
                Destructibles = { Convert(destructibles) },
                ProductionQueue = { productionQueue },
                Squads = { squads.Select(Convert) },
                GameLoop = gameloop
            });
        }