Example #1
0
        public void OnPlayerTurnBegin(City c)
        {
            Player p = c.owner;

            if (state == States.InProgress)
            {
                turnsRemaining--;
                if (turnsRemaining == 0)
                {
                    App.Announce($"{name} has been built!");
                    c.currentlyBuilding = null;
                    state      = States.Builded;
                    c.Currpop += bonusProsperityFirstTurn;

                    if (name == "Granary")
                    {
                        // Add prosperity equal to number of resources connected to this city
                        int res = Game.game.Map.OfType <MapObject>().Where(x => x is Resource).Select(x => x as Resource).Where(x => x.cityOwner == c).Count();
                        c.Currpop += res;
                        App.Announce("Granary added " + res + " prosperity to one of your cities");
                    }
                }
            }
            else if (state == States.Builded)
            {
                p.resources += bonusOutputEachTurn;
                c.Currpop   += bonusProsperityEachTurn;
            }
        }
Example #2
0
 public void OnPlayerTurnBegin(Player player)
 {
     if (state == States.InProgress)
     {
         turnsRemaining--;
         if (turnsRemaining <= 0)
         {
             state = States.Researched;
             player.currentlyResearching = null;
             App.Announce($"{name} research completed! Go to research tab and choose another research.");
             if (player == Game.game.players[0])
             {
                 if (name == rssrch[(int)researches.Ironsmithing].name)
                 {
                     Achievement.achievements[(int)Achievement.eAchievs.Ironman].isSpecial = false;
                 }
                 if (name == rssrch[(int)researches.Gunpowder].name)
                 {
                     Achievement.achievements[(int)Achievement.eAchievs.PowerOfGunpowder].isSpecial = false;
                 }
                 Achievement.researchesResearched++;
                 Achievement.Check();
             }
         }
     }
 }
Example #3
0
        public bool StartBuilding(City c)
        {
            Player p = c.owner;

            bool everythingResearched = researchReq.Count() == 0;

            if (!everythingResearched)
            {
                foreach (int i in researchReq)
                {
                    if (p.researches[i].state == Research.States.Researched)
                    {
                        everythingResearched = true;
                    }
                    else
                    {
                        everythingResearched = false;
                        break;
                    }
                }
            }

            if (state == States.NotBuild && p.resources >= cost && c.currentlyBuilding == null && everythingResearched)
            {
                p.resources        -= cost;
                state               = States.InProgress;
                c.currentlyBuilding = this;
                App.Announce($"{name} is now building in one of your cities, it'll be done in {turnsRemaining} turns");
                return(true);
            }
            else
            {
                if (state == States.Builded)
                {
                    App.Announce("This building is already built");
                }
                else if (state == States.InProgress)
                {
                    App.Announce("You are already building this building");
                }
                else if (c.currentlyBuilding != null)
                {
                    App.Announce("You are already building something");
                }
                else if (!everythingResearched)
                {
                    App.Announce("There are some researches, you have to do before building " + name);
                }
                else if (p.resources < cost)
                {
                    App.Announce("You don't have enough resources");
                }
                else
                {
                    App.Announce("You cannot build this building");
                }
                return(false);
            }
        }
Example #4
0
        public Game(int length = 64, string save = "", int numberOfPlayers = 2, bool playAI = false, bool genMapIfNewGame = true)
        {
            if (save == "")
            {
                // New game
                this.length = length;
                rnd         = new Random();
                game        = this;
                for (int i = 0; i < numberOfPlayers; i++)
                {
                    Player p = new Player()
                    {
                        color = i, name = "Player " + (i + 1)
                    };
                    p.currAI = i != 0 && playAI ? new AIsoptik(p) : null;
                    players.Add(p);
                }

                if (genMapIfNewGame)
                {
                    Map = GenerateMap(length);
                }
            }
            else
            {
                try
                {
                    game = this;
                    SaveManager.Load(save);
                }
                catch (Exception ex)
                {
                    App.isAnnounceEnabled = true;
                    Bridge.Script.Call("console.log", ex);
                    App.Announce("Unable to load game, save is corrupted. Generating new game...");
                    Bridge.Html5.Window.LocalStorage["game_continue"] = "";

                    this.length = length;
                    rnd         = new Random();
                    game        = this;
                    for (int i = 0; i < numberOfPlayers; i++)
                    {
                        Player p = new Player()
                        {
                            color = i, name = "Player " + (i + 1)
                        };
                        p.currAI = i != 0 && playAI ? new AIsoptik(p) : null;
                        players.Add(p);
                    }
                    Map = GenerateMap(length);
                    //new Game(length, "", numberOfPlayers, playAI);
                }
            }
        }
Example #5
0
 private void CheckAchiev()
 {
     if (!isSpecial && !isDone)
     {
         if (enemiesKilled >= reqEnemiesKilled && unitsLost >= reqUnitsLost && finishedGames >= reqFinishedGames && citiesCaptured >= reqCitiesCaptured &&
             resourcesRebuilt >= reqResourcesRebuilt && unitsRecruited >= reqUnitsRecruited && researchesResearched >= reqResearchesResearched &&
             recruitTentsBuilt >= reqRecruitTentsBuilt && recruitTentsDestroyed >= reqRecruitTentsDestroyed)
         {
             isDone = true;
             App.Announce("Achieved new achievement: " + name);
         }
     }
 }
Example #6
0
        public override void NextTurn()
        {
            if (Game.game.Map[x, y, 2] != null && (Game.game.Map[x, y, 2] as Unit).owner != owner)
            {
                if (!readyToCapture)
                {
                    readyToCapture = true;
                }

                int pState = Game.game.playerState;

                if (readyToCapture && (Game.game.Map[x, y, 2] as Unit).owner == Game.game.players[pState == 0 ? Game.game.players.Count - 1 : pState - 1])
                {
                    App.Announce("There is a city ready to capture!");
                }

                if (readyToCapture && (Game.game.Map[x, y, 2] as Unit).owner != owner && owner == Game.game.players[pState == 0 ? Game.game.players.Count - 1 : pState - 1])
                {
                    App.Announce("One of your cities is under siege!");
                }
            }
            else if (readyToCapture)
            {
                readyToCapture = false;
            }

            if (owner != null && Game.game.players[Game.game.playerState] == owner)
            {
                owner.resources += Production;
            }

            if (Game.game.Map[x, y, 2] != null && (Game.game.Map[x, y, 2] as Unit).owner == owner && Game.game.players[Game.game.playerState] == owner)
            {
                (Game.game.Map[x, y, 2] as Unit).hp += 2;
                if ((Game.game.Map[x, y, 2] as Unit).hp > (Game.game.Map[x, y, 2] as Unit).maxhp)
                {
                    (Game.game.Map[x, y, 2] as Unit).hp = (Game.game.Map[x, y, 2] as Unit).maxhp;
                }
            }
        }
Example #7
0
        public bool StartResearch(Player player)
        {
            bool everythingResearched = reqResearch.Count() == 0;

            if (!everythingResearched)
            {
                foreach (int i in reqResearch)
                {
                    if (player.researches[i].state == States.Researched)
                    {
                        everythingResearched = true;
                    }
                    else
                    {
                        everythingResearched = false;
                        break;
                    }
                }
            }
            if (everythingResearched && state == States.NotResearched && cost <= player.resources && player.currentlyResearching == null && reqScienceLevel <= player.researchMultiplier)
            {
                player.resources           -= cost;
                state                       = States.InProgress;
                player.currentlyResearching = this;

                /*
                 * int minusDueToSciencePoints = 0;
                 * if(reqScienceLevel + 1 < player.researchMultiplier)
                 * {
                 *  int percent = (int)(10 * (reqScienceLevel - player.researchMultiplier));
                 *  minusDueToSciencePoints = maximumTurnsRemaining * percent / 100;
                 * }
                 * turnsRemaining -= minusDueToSciencePoints;
                 * maximumTurnsRemaining -= minusDueToSciencePoints;*/

                App.Announce($"Research {name} started! It'll be finished in {turnsRemaining} turns.");
                return(true);
            }
            else
            {
                if (!everythingResearched)
                {
                    App.Announce("You need to research another researches before researching this");
                }
                else if (state != States.NotResearched)
                {
                    if (state == States.InProgress)
                    {
                        App.Announce("You are already researching this research");
                    }
                    else
                    {
                        App.Announce("You have already researched this research");
                    }
                }
                else if (player.currentlyResearching != null)
                {
                    App.Announce("You are already researching something");
                }
                else if (reqScienceLevel > player.researchMultiplier)
                {
                    App.Announce("Your science level isn't big enough. Build more science buildings.");
                }
                else
                {
                    App.Announce("You don't have enough resources to start research");
                }
                return(false);
            }
        }