コード例 #1
0
    public void Send_Armies()                                                                           // Send armies button
    {
        GameObject button       = EventSystem.current.currentSelectedGameObject;                        // The button that was clicked
        CityStats  buttonParent = button.transform.parent.parent.gameObject.GetComponent <CityStats>(); // Gets the parent from the button that was clicked, aka a City

        if (buttonParent.armySize > 0)                                                                  // Makes a new army object
        {
            // Make a new army
            GameObject newArmy = Instantiate(army, buttonParent.transform.position, Quaternion.identity);
            StaticLibrary.DeselectAll();                                      // All others all deselected

            newArmy.transform.parent = GameObject.Find("_Dynamic").transform; // Becomes a dynamic object
            newArmy.GetComponent <ArmyStats>().armySize     = buttonParent.armySize;
            newArmy.GetComponent <ArmyStats>().isSelected   = true;           // The city spawned is selected
            newArmy.GetComponent <ArmyStats>().spawnNumber  = StaticLibrary.spawnArmyCounter;
            newArmy.GetComponent <ArmyStats>().playerNumber = buttonParent.playerNumber;

            buttonParent.armySize = 0; // The city where the army spawned from now has 0 armies

            StaticLibrary.spawnArmyCounter++;

            Transform[] parameters = new Transform[2] {
                newArmy.transform, buttonParent.transform
            };
            StopCoroutine("DeleteArmy");
            StartCoroutine("DeleteArmy", parameters);
        }
    }
コード例 #2
0
    public void Send_Armies()                                                                           // Send armies button
    {
        GameObject button       = EventSystem.current.currentSelectedGameObject;                        // The button that was clicked
        CityStats  buttonParent = button.transform.parent.parent.gameObject.GetComponent <CityStats>(); // Gets the parent from the button that was clicked, aka a City

        if (buttonParent.armySize > 0)                                                                  // Makes a new army object
        {
            StopCoroutine("InstantiateArmy");
            StartCoroutine("InstantiateArmy", buttonParent);
        }
    }
コード例 #3
0
 public async Task OnGetAsync(string city, string date)
 {
     if (!string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(date))
     {
         Details = await _db.GetMeasurementsForCityAndDateAsync(city, date);
     }
     else if (!string.IsNullOrEmpty(city))
     {
         Stats = await _db.GetCityStatsAsync(city);
     }
 }
コード例 #4
0
    /* De 2 collision gameobjects kunnen hier niet, want dan als een 3e partij collide dan worden ze geupdate hier en klopt het gevecht niet meer.
     *
     */

    void OnTriggerEnter(Collider collision)

    // When an other prefab army is hit they collide, based on wether it is an enemy or ally it responds accordingly.
    {
        if (collision.gameObject.CompareTag("Town"))
        {
            ArmyStats myArmyStats = transform.GetComponent <ArmyStats>();
            CityStats cityStats   = collision.GetComponent <CityStats>();

            if (myArmyStats.playerNumber == cityStats.playerNumber && !myArmyStats.justSpawned) // Own city collision
            {
                cityStats.armySize += myArmyStats.armySize;
                cityStats.Update_Citystats();
                Destroy(myArmyStats.gameObject);
            }
            else // TODO enemy city collision
            {
            }
        }
        else if (collision.gameObject.CompareTag("Army")) // Collision between armies
        {
            ArmyStats myArmyStats    = transform.GetComponent <ArmyStats>();
            ArmyStats enemyArmyStats = collision.GetComponent <ArmyStats>();

            if (enemyArmyStats.playerNumber == myArmyStats.playerNumber) // Own Team collision
            {
                // spawnNumber < spawnNumber is so that the collision only gets done once, because this method is being invoked on both objects
                if (enemyArmyStats.spawnNumber < myArmyStats.spawnNumber && !myArmyStats.inBattle && !enemyArmyStats.inBattle)
                {
                    OwnTeamCollision(collision);
                }

                else if (!enemyArmyStats.inBattle && myArmyStats.inBattle) // If one of the 2 is in battle
                {
                    myArmyStats.armySize += enemyArmyStats.armySize;
                    Destroy(enemyArmyStats.gameObject);
                }
            }
            else // Enemy Team collision
            {
                if (enemyArmyStats.spawnNumber < myArmyStats.spawnNumber && !myArmyStats.inBattle && !enemyArmyStats.inBattle)
                {
                    EnemyTeamCollision(collision);
                }

                else if (!enemyArmyStats.inBattle && myArmyStats.inBattle)
                {
                    myArmyStats.inBattleWith.GetComponent <ArmyStats>().armySize += enemyArmyStats.armySize;
                    Destroy(enemyArmyStats.gameObject);
                }
            }
        }
    }
コード例 #5
0
    public City(string _name, int pop, int x, int width, int height, Vector3 _connectorPos)
    {
        name       = _name;
        population = pop;
        worldX     = x;

        gridHeight = height;
        gridWidth  = width;

        connectorPosition = _connectorPos;

        // Right now we are using the name of the city to generate its random starting stats
        cityStats = new CityStats(name, worldX);
    }
コード例 #6
0
    public void ClickBuildingButton()
    {
        GameObject button       = EventSystem.current.currentSelectedGameObject; // The button that was clicked
        GameObject city         = button.transform.parent.parent.parent.gameObject;
        CityStats  buttonParent = city.GetComponent <CityStats>();               // Gets the parent from the button that was clicked, aka a City

        string buildingname = "";

        for (int i = 0; i < button.name.Length; i++) // Removes "Button" from the string, leaving the name of the building. Eg, FarmButton becomes Farm.
        {
            buildingname = buildingname + button.name[i];
            if (button.name[i + 1].Equals('B'))
            {
                break;
            }
        }
        if (!levelsTown.ContainsKey(city.name))
        {
            levelsTown.Add(city.name, new Dictionary <string, int>());
        }

        if (!levelsTown[city.name].ContainsKey(buildingname)) // If the key is not yet in the dictionary it will be added.
        {
            levelsTown[city.name].Add(buildingname, 0);
        }


        if (buildingname == "Townhall")
        {
            buttonParent.popMax = 1200 * Mathf.Pow(levelsTown[city.name]["Townhall"] + 1, 2) + 5000;
        }

        if (Config.buildingconfig[buildingname]["Balance"].Count > levelsTown[city.name][buildingname] && BalanceController.balance >= (int)Config.buildingconfig[buildingname]["Balance"][levelsTown[city.name][buildingname]]) // There needs to be a level for the specific building and enough money.
        {
            // Update balance, buildingmod and popgrowth based on the buildingname config.
            Stats_update((int)Config.buildingconfig[buildingname]["Balance"][levelsTown[city.name][buildingname]],
                         Config.buildingconfig[buildingname]["Buildingmod"][0],
                         Config.buildingconfig[buildingname]["Popgrowth"][0], 0, buttonParent);
            if (Config.buildingconfig[buildingname]["Balance"].Count > (levelsTown[city.name][buildingname]) + 1)                       // Update to the price of the next level, if there is one.
            {
                button.GetComponentInChildren <Text>().text = buildingname + " " + (levelsTown[city.name][buildingname] + 2).ToString() // Takes the buttons children text and updates the price
                                                              + ": " + (int)Config.buildingconfig[buildingname]["Balance"][levelsTown[city.name][buildingname] + 1];
            }
            else
            {
                button.GetComponentInChildren <Text>().text = buildingname + " Max";
            }
            levelsTown[city.name][buildingname]++;
        }
    }
コード例 #7
0
    IEnumerator InstantiateArmy(CityStats buttonParent) // Instantiates an army
    {
        bool    playerClicked       = false;            // Only instantiate when a player clickes to move it immediately
        Vector3 playerClickedTarget = Vector3.zero;
        float   armysize            = buttonParent.armySize;

        buttonParent.armySize = 0; // The city where the army spawned from now has 0 armies
        buttonParent.Update_Citystats();

        while (!playerClicked) // Waits untill the player clicks before instantiating unit
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                if (Input.GetMouseButtonDown(1))
                {
                    playerClicked       = true;
                    playerClickedTarget = new Vector3(hit.point.x, 0f, hit.point.z);
                }
            }
            yield return(null);
        }
        // Make a new army
        GameObject newArmy = Instantiate(army, buttonParent.transform.position, Quaternion.identity);

        ArmyStats newArmyStats = newArmy.GetComponent <ArmyStats>();

        newArmyStats.justSpawned  = true;                                  // So that it doesnt collide with the town immediately, used in Collide armies to not collide with a town
        newArmy.transform.parent  = GameObject.Find("_Dynamic").transform; // Becomes a dynamic object
        newArmyStats.armySize     = armysize;
        newArmyStats.isSelected   = true;                                  // The army spawned is selected
        newArmyStats.spawnNumber  = StaticLibrary.spawnArmyCounter;
        newArmyStats.playerNumber = buttonParent.playerNumber;

        newArmy.GetComponent <MoveArmies>().target = playerClickedTarget;
        newArmy.GetComponent <MoveArmies>().StartRoutine();

        StaticLibrary.DeselectTown();
        StaticLibrary.spawnArmyCounter++;

        playerClicked = false;
        yield return(new WaitForSeconds(0.5f)); // So that it doesnt collide with the town immediately

        newArmyStats.justSpawned = false;
    }
コード例 #8
0
    public void ClickLegionsButton()
    {
        GameObject button       = EventSystem.current.currentSelectedGameObject;                               // The button that was clicked
        CityStats  buttonParent = button.transform.parent.parent.parent.gameObject.GetComponent <CityStats>(); // Gets the parent from the button that was clicked, aka a City

        string legionname = "";

        for (int i = 0; i < button.name.Length; i++) // Removes "Button" from the string, leaving the name of the building. Eg, FarmButton becomes Farm.
        {
            legionname = legionname + button.name[i];
            if (button.name[i + 1].Equals('B'))
            {
                break;
            }
        }
        if (Config.legionsConfig[legionname] <= BalanceController.balance && buttonParent.population > 20)
        {
            Stats_update(Config.legionsConfig[legionname], 0, 0, 1, buttonParent);
        }
    }
コード例 #9
0
        public async Task <CityStats> GetCityStatsAsync(string city)
        {
            CityStats stats      = null;
            var       cityValues = await _weatherCollection.Find(c => c.City == city).ToListAsync();

            if (cityValues == null || !cityValues.Any())
            {
                return(stats);
            }
            cityValues = cityValues.OrderBy(d => d.Date).ToList();
            stats      = new()
            {
                AverageTemp      = Math.Round(cityValues.Average(v => v.DailyValues.AvgDailyTemp), 1),
                MinTemp          = Math.Round(cityValues.Min(v => v.DailyValues.MinTemp), 1),
                MaxTemp          = Math.Round(cityValues.Max(v => v.DailyValues.MaxTemp), 1),
                MeasurementCount = cityValues.Count(),
                CityName         = city,
                SpringDate       = FindSpring(cityValues),
                SummerDate       = FindSummer(cityValues),
                Source           = cityValues
            };
            return(stats);
        }
コード例 #10
0
 private void Stats_update(int Balance, double buildingmod, double popgrowth, int army, CityStats buttonParent) // Updating popgrowth, buildingmod and balance based on button clicked.
 {
     if (buttonParent.building_modifier < 100)                                                                  // To be sure
     {
         buttonParent.building_modifier += (float)buildingmod;
     }
     buttonParent.population_growth += (float)popgrowth;
     BalanceController.balance      += -Balance;
     buttonParent.armySize          += army;
     buttonParent.Update_Citystats();
 }
コード例 #11
0
 public void AddCityStat(CityStats newStats)
 {
     all_CityStats.Add(newStats);
 }