Exemple #1
0
        public Army CreateArmy(Player owner, int charactersCount, CharacterDefinition charactersType = null)
        {
            var army = new Army();

            army.Owner = owner;

            if (army.Owner != null)
            {
                var armyId = Armies.Count(a => a.Owner == army.Owner) + 1;

                if (army.Owner.IsUserControlled)
                {
                    army.Name = "Legion " + armyId;
                }
                else if (army.Owner.IsChaosControlled)
                {
                    army.Name          = "Wojownicy Chaosu";
                    army.DaysToGetInfo = 30;
                }
                else
                {
                    var postfix = army.Owner.Name.StartsWith("I") ? "ego" : "a";
                    army.Name          = armyId + " Legion " + army.Owner.Name + postfix;
                    army.DaysToGetInfo = 30;
                    //army.Aggression = 150 + Rand.Next(50) + dataManager.Power;
                }
            }

            army.Food = GlobalUtils.Rand(200);

            for (var i = 0; i < charactersCount; i++)
            {
                var type = charactersType;
                if (type == null)
                {
                    type = _definitionsRepository.Races[GlobalUtils.Rand(_definitionsRepository.Races.Count - 1)];
                }
                var character = _charactersRepository.CreateCharacter(type);
                army.Characters.Add(character);
            }

            Armies.Add(army);

            return(army);
        }
        public ActionResult <CharacterDTO> CreateCharacter(CreateCharacterDTO createCharacterDTO)
        {
            Character character = new Character
            {
                Id   = Guid.NewGuid(),
                Name = createCharacterDTO.Name
            };

            repository.CreateCharacter(character);

            return(character.AsDTO());
        }
Exemple #3
0
        public void Riot(City city)
        {
            var userArmy = _armiesHelper.FindUserArmyInCity(city);

            if (userArmy == null)
            {
                city.Owner  = null;
                city.Morale = 30;
                //TODO: //CENTER[MIASTA(M, 0, M_X), MIASTA(M, 0, M_Y), 1]
                var riotMessage = new Message();
                riotMessage.Type       = MessageType.RiotInTheCity;
                riotMessage.MapObjects = new List <MapObject> {
                    city
                };
                _messagesService.ShowMessage(riotMessage);
                return;
            }

            //TODO: CENTER[MIASTA(M, 0, M_X), MIASTA(M, 0, M_Y), 1]

            // there is user army in city and can fight with rebels
            var villagersCount = 2 + GlobalUtils.Rand(2);
            var count          = (city.Population / 70) + 1;

            if (count > 10)
            {
                count = 10;
            }
            count -= villagersCount;

            var rebelArmy = _armiesRepository.CreateTempArmy(count);

            //'wieśniacy wśród buntowników
            for (var i = 0; i <= villagersCount; i++)
            {
                // TODO: check if 9 is villager
                var villager = _charactersRepository.CreateCharacter(_definitionsRepository.Races.Find(c => c.Name == "villager"));
                rebelArmy.Characters.Add(villager);
            }

            //TODO: BITWA[_ATAK,40,1,1,0,1,1,1,TEREN,M]
            var battleContext = new TerrainActionContext();

            battleContext.UserArmy    = userArmy;
            battleContext.EnemyArmy   = rebelArmy;
            battleContext.Type        = TerrainActionType.Battle;
            battleContext.ActionAfter = () =>
            {
                city.Population -= city.Population / 4;

                if (rebelArmy.IsKilled)
                {
                    city.Morale    = 50;
                    city.Craziness = GlobalUtils.Rand(3) + 5;
                }
                else
                {
                    var successMessage = new Message();
                    successMessage.Type       = MessageType.RiotInTheCitySuccess;
                    successMessage.MapObjects = new List <MapObject> {
                        city
                    };
                    _messagesService.ShowMessage(successMessage);
                }
            };

            var defenceMessage = new Message();

            defenceMessage.Type       = MessageType.RiotInTheCityWithDefence;
            defenceMessage.MapObjects = new List <MapObject> {
                city, userArmy
            };
            defenceMessage.OnClose = () =>
            {
                _viewSwitcher.OpenTerrain(battleContext);
            };
            _messagesService.ShowMessage(defenceMessage);
        }