public void StartRevolution()
    {
        int numOfCitiesToRevolt = 2;

        if (numOfCitiesToRevolt <= 0)
        {
            return;
        }
        if (currentlySelectedKingdom.cities.Count < 4)
        {
            Debug.LogWarning("The kingdom only has " + currentlySelectedKingdom.cities.Count.ToString() + " cities.");
        }
        else
        {
            if (numOfCitiesToRevolt == currentlySelectedKingdom.cities.Count)
            {
                //Replace Lord
                if (currentlySelectedKingdom.royaltyList.successionRoyalties.Count <= 0)
                {
                    currentlySelectedKingdom.AssignNewLord(null);
                }
                else
                {
                    currentlySelectedKingdom.AssignNewLord(currentlySelectedKingdom.royaltyList.successionRoyalties[0]);
                }

                Debug.Log("Revolution! Lord of: " + currentlySelectedKingdom.kingdomName + " was replaced");
            }
            else
            {
                List <CityTileTest> citiesForNewKingdom = new List <CityTileTest> ();
                CityTileTest        mainCity            = currentlySelectedKingdom.cities [UnityEngine.Random.Range(0, currentlySelectedKingdom.cities.Count)];
                citiesForNewKingdom.Add(mainCity);
                for (int i = 0; i < mainCity.cityAttributes.connectedCities.Count; i++)
                {
                    if (mainCity.cityAttributes.connectedCities [i].cityAttributes.kingdomTile.kingdom.id == currentlySelectedKingdom.id)
                    {
                        citiesForNewKingdom.Add(mainCity.cityAttributes.connectedCities [i]);
                        break;
                    }
                }

                currentlySelectedKingdom.RemoveCitiesFromKingdom(citiesForNewKingdom);
                KingdomTest newKingdom = PoliticsPrototypeManager.Instance.CreateNewKingdom(citiesForNewKingdom, UnityEngine.Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f));
                newKingdom.CreateInitialRelationshipsToKingdoms();
                PoliticsPrototypeManager.Instance.AddRelationshipToOtherKingdoms(newKingdom);
                Debug.Log("Revolution! New kingdom: " + newKingdom.kingdomName + " was created");
                PoliticsPrototypeManager.Instance.GenerateConnections();
                LoadKingdoms();
            }

            ShowKingdomInfo(currentlySelectedKingdom);
        }
    }
Exemplo n.º 2
0
    internal void CheckForWars()
    {
        if (this.cities.Count <= 0)
        {
            PoliticsPrototypeManager.Instance.turnEnded -= CheckForWars;
            PoliticsPrototypeManager.Instance.MakeKingdomDead(this);
        }
        if (this.kingdomsAtWarWith.Count <= 0)
        {
            return;
        }
        for (int i = 0; i < this.cities.Count; i++)
        {
            for (int j = 0; j < this.cities[i].cityAttributes.connectedCities.Count; j++)
            {
                CityTest connectedCity = this.cities[i].cityAttributes.connectedCities[j].cityAttributes;
                if (connectedCity.kingdomTile.kingdom.id != this.id &&
                    SearchRelationshipKingdomsById(connectedCity.kingdomTile.kingdom.id).isAtWar)
                {
                    KingdomTest kingdomAtWarWith = connectedCity.kingdomTile.kingdom;
                    int         chanceOfWar      = Random.Range(0, 100);
//					Debug.LogError(this.kingdomName + " is attempting to invade city " + connectedCity.cityName + " of kingdom " + connectedCity.kingdomTile.kingdom.kingdomName);
                    if (chanceOfWar < 5)
                    {
                        //Invade City
                        Debug.LogError(this.kingdomName + " has invaded city " + connectedCity.cityName + " of kingdom " + connectedCity.kingdomTile.kingdom.kingdomName);
                        this.AddCityToKingdom(connectedCity.hexTile.GetCityTileTest());
                        kingdomAtWarWith.RemoveCitiesFromKingdom(new List <CityTileTest>()
                        {
                            connectedCity.hexTile.GetCityTileTest()
                        });
                        int chanceOfPeace = Random.Range(0, 100);
                        if (chanceOfPeace < 15)
                        {
                            Debug.LogError(this.kingdomName + " has declared peace with " + connectedCity.kingdomTile.kingdom.kingdomName);
                            this.SearchRelationshipKingdomsById(kingdomAtWarWith.id).isAtWar = false;
                            kingdomAtWarWith.SearchRelationshipKingdomsById(this.id).isAtWar = false;
                        }
                        break;
                    }
                }
            }
        }
    }