Exemplo n.º 1
0
        public void AddUnit(Players playerId, Vector2 position, UnitTypes name, float rot = 0f, int health = 0)
        {
            IUnit unit;

            switch (name)
            {
            case UnitTypes.Arrow:
                unit = new Arrow(playerId, position, rot, mGridSize, position);
                break;

            case UnitTypes.Swordsman:
                unit = new Swordsman(playerId, position, rot, mGridSize);
                break;

            case UnitTypes.Cavalry:
                unit = new Cavalry(playerId, position, rot, mGridSize);
                break;

            case UnitTypes.Hero:
                var hero = new Hero(playerId, position, rot, mGridSize, mContent);
                unit = hero;
                HeroesByPlayer[playerId] = hero;
                break;

            case UnitTypes.Bowman:
                unit = new Bowman(playerId, position, rot, mGridSize);
                break;

            case UnitTypes.BatteringRam:
                unit = new BatteringRam(playerId, position, rot, mGridSize);
                break;

            default:
                return;
            }

            if (unit is IDamageableUnit damageableUnit && health != 0)
            {
                damageableUnit.Health = health;
            }

            if (!UnitsByPlayer.ContainsKey(playerId))
            {
                UnitsByPlayer.Add(playerId, new List <IUnit>());
            }

            UnitsByPlayer[playerId].Add(unit);
            if (unit.UnitType == UnitTypes.Hero || unit.UnitType == UnitTypes.Swordsman || unit.UnitType == UnitTypes.Cavalry ||
                unit.UnitType == UnitTypes.BatteringRam || unit.UnitType == UnitTypes.Bowman)
            {
                StatisticsByPlayer[playerId]["CreateTroops"] += 1;
            }
            if (!UnitsByModel.ContainsKey(unit.ModelType))
            {
                UnitsByModel.Add(unit.ModelType, new List <IUnit>());
            }

            UnitsByModel[unit.ModelType].Add(unit);
        }
Exemplo n.º 2
0
        public void SignalModelUpdate(ModelManager.Model oldModel, IUnit unit)
        {
            UnitsByModel[oldModel].Remove(unit);
            if (!UnitsByModel.ContainsKey(unit.ModelType))
            {
                UnitsByModel[unit.ModelType] = new List <IUnit>();
            }

            UnitsByModel[unit.ModelType].Add(unit);
        }
Exemplo n.º 3
0
        private void AddQueuedUnits()
        {
            while (mUnitsToAddNextTick.Count != 0)
            {
                var unit = mUnitsToAddNextTick.Dequeue();
                UnitsByPlayer[unit.Owner].Add(unit);
                if (!UnitsByModel.ContainsKey(unit.ModelType))
                {
                    UnitsByModel[unit.ModelType] = new List <IUnit>();
                }

                UnitsByModel[unit.ModelType].Add(unit);
            }
        }
Exemplo n.º 4
0
        public void AddHero(Players playerId, Vector2 pos, float rot, int mana, int health, LevelManager levelManager, SkillManager skillManager)
        {
            var hero = new Hero(playerId, pos, rot, mGridSize, mana, health, levelManager, skillManager, mContent);

            HeroesByPlayer[playerId] = hero;
            if (!UnitsByPlayer.ContainsKey(playerId))
            {
                UnitsByPlayer.Add(playerId, new List <IUnit>());
            }

            UnitsByPlayer[playerId].Add(hero);
            StatisticsByPlayer[playerId]["CreateTroops"] += 1;
            if (!UnitsByModel.ContainsKey(hero.ModelType))
            {
                UnitsByModel.Add(hero.ModelType, new List <IUnit>());
            }

            UnitsByModel[hero.ModelType].Add(hero);
        }
Exemplo n.º 5
0
        public bool AddBuilding(Players playerId, Vector2 position, UnitTypes name, float rotation = 0f, int health = 0)
        {
            ABuilding unit;

            switch (name)
            {
            case UnitTypes.Gate:
                unit = new Gate(playerId, position, rotation, mGridSize);
                break;

            case UnitTypes.Wall:
                unit = new Wall(playerId, position, rotation, mGridSize);
                break;

            case UnitTypes.SacredStar:
                unit = new SacredStar(playerId, position, mGridSize);
                break;

            case UnitTypes.Village:
                unit = new Village(playerId, position, rotation, mGridSize);
                VillagePos.Add(playerId, position);
                VillagesByPlayer.Add(playerId, (Village)unit);
                break;

            case UnitTypes.GoldMine:
                unit = new Mine(playerId, position, rotation, true, mGridSize, Resources);
                break;

            case UnitTypes.Quarry:
                unit = new Mine(playerId, position, rotation, false, mGridSize, Resources);
                break;

            case UnitTypes.Rock:
                unit = new Rock(position, mGridSize, rotation);
                break;

            default:
                return(false);
            }

            if (unit is IDamageableUnit damageableUnit && health != 0)
            {
                damageableUnit.Health = health;
            }

            var blockedFields  = unit.BlockedFields();
            var passableFields = unit.PassableFields();

            if (AreFieldsOccupied(blockedFields, passableFields))
            {
                return(false);
            }

            ChangeFieldState(TileStates.Blocked, blockedFields);
            ChangeFieldState(TileStates.Passable, passableFields);

            if (!BuildingsByPlayer.ContainsKey(playerId))
            {
                BuildingsByPlayer.Add(playerId, new List <IUnit>());
            }

            if ((unit.UnitType == UnitTypes.GoldMine || unit.UnitType == UnitTypes.Quarry ||
                 unit.UnitType == UnitTypes.SacredStar) && !BuildingsByPlayer[Players.Global].Contains(unit))
            {
                BuildingsByPlayer[Players.Global].Add(unit);
            }
            BuildingsByPlayer[playerId].Add(unit);
            if (!UnitsByModel.ContainsKey(unit.ModelType))
            {
                UnitsByModel.Add(unit.ModelType, new List <IUnit>());
            }

            UnitsByModel[unit.ModelType].Add(unit);

            return(true);
        }