예제 #1
0
    //adds a new stack to the army list and removes it from the town as player has no recruits refillable
    private void HireNewRecruits(Challenger chall)
    {
        Debug.Log("hire recruits in town method called");
        playerArmy      = chall.GetArmy();
        playersArmyList = chall.armyScrollList;
        List <int> iToRemove = new List <int>(); //complains about removing from list while iterating through
        int        counter   = 0;

        foreach (Unit u in townsArmylist)
        {
            //if player can afford the whole stack, add it
            int cost = u.hireCost * u.currentSize;
            if (chall.gold >= cost)  //if can afford whole stack
            {
                int oldPos = u.positionInList;
                u.positionInList = playerArmy.Count;
                // playersArmyList.GetUnit(u); //adds unit to players army from town not working for enemy AI whyyy??
                playerArmy.Add(u);
                iToRemove.Add(counter);
                chall.gold -= cost;
                counter++;
                //playersArmyList.RefreshDisplay();
            }
            else   //dont need to delete stack, only need to add stack to chall
            {
                Debug.Log("You cant afford the whole recruit stack, attempting to add new partial stack ");
                counter++;
                int amount    = Mathf.RoundToInt((float)player.gold / (float)u.hireCost);
                int newAmount = u.currentSize - amount;
                if (newAmount >= 0 && newAmount <= u.maxSize)
                {
                    u.currentSize    = amount;
                    u.positionInList = playerArmy.Count;
                    playerArmy.Add(u);
                    u.currentSize = newAmount;
                    // playersArmyList.RefreshDisplay();
                }
                else
                {
                    Debug.Log("adding new stack failed, shouldnt hit this ??");
                }
                break;
            }
        }
        try {
            if (townsArmylist.Count > 0)
            {
                foreach (int i in iToRemove)
                {
                    townsArmylist.RemoveAt(i);
                }
            }
        } catch {
            Debug.Log("catchededed");
        }
        //update player army GUI buttons
        playersArmyList.RefreshDisplay();
        //refresh town text
        //playersArmyList.RefreshDisplay();
    }
예제 #2
0
 private void RemoveUnit(Unit unitToRemove, ArmyScrollList list)
 {
     for (int i = list.unitList.Count - 1; i >= 0; i--)
     {
         if (list.unitList[i] == unitToRemove)
         {
             list.unitList.RemoveAt(i);
         }
     }
 }
예제 #3
0
 public void Setup(Unit currentUnit, int unitIndex, ArmyScrollList currentScrollList)
 {
     unit             = currentUnit;
     unitName.text    = currentUnit.name;
     iconImage.sprite = unit.icon;
     // priceText.text = unit.price.ToString();
     scrollList     = currentScrollList;
     powerText.text = "" + unit.power;
     levelText.text = "" + unit.level;
     this.unitIndex = unitIndex;
 }
예제 #4
0
 void AfterSetup()
 {
     //menuUI = GameObject.Find("City Menu").GetComponent<Canvas>();
     menuManager = GameObject.Find("Menu Manager").GetComponent <MenuManager>(); // trying to mae this work
     buttonText  = menuManager.GetComponent <MapBuildingText>();                 // :/
     playerGO    = GameObject.FindWithTag("Player");
     playerArmy  = playerGO.GetComponent <Challenger>().GetArmy();
     //GUI:
     townsArmylist   = new List <Unit>();
     playersArmyList = playerGO.GetComponent <ArmyScrollList>();
     player          = playerGO.GetComponent <Challenger>();
     if (isCapital)
     {
         buildingType = BuildingType.Capital;
     }
     // citiesUnit = new Unit(unitsSprite);
     setup = true;
     InvokeRepeating("RegainRecruits", 40f, recruitRegainCD);
     //buttonText.TextSet(); too soon?
 }
예제 #5
0
    //currently only will work with closest town
    // Use this for initialization
    void Start()
    {
        //add buttons
        AddButtons();

        // initialise other list, if this is attached to any object other than a 'challenger', we set
        //transfer list to be the players army.  //set unit list to unit list in attached challenger script
        challReference = this.GetComponent <Challenger>();
        if (challReference)
        {
            // do something specific ... (?) TODO think
            //set to current interactable object
            // otherList = challReference.location.GetArmyList();
            unitList = challReference.GetArmy();
        }
        else     //must be attached a town or interactable etc, so we set other list to players list for transfers
        {
            otherList = GameObject.FindWithTag("Player").GetComponent <ArmyScrollList>();
        }
    }
예제 #6
0
 // changing army scroll list to different town
 public void ChangeOtherArmyList(ArmyScrollList newList)
 {
     gameObject.GetComponent <ArmyScrollList>().otherList = newList;
 }
예제 #7
0
    // players armies are not fully refilled and so dont need to add buttons to the army GUI, just increment current size of recruits in player army

    /*this doesnt terminate ever when trying to add new unit to AI army.. occasionally infinite looped, replaced with below
     * private void RefillPlayerRecruits1(Challenger chall) {
     *
     * Debug.Log("Attempting to a unit from...: " + buildingType);
     *  //fancy gui: troop count is the list, dont need an int check.
     *  //refilling players recruits
     *  playerArmy = chall.GetArmy();
     *  playersArmyList = chall.armyScrollList;
     *  int failsafe = 0;
     *  if (townsArmylist.unitList.Count > 0 && chall.gold >= townsArmylist.unitList[0].hirePrice && playerArmy.Count > 0) {
     *          foreach (Unit playerU in playerArmy) {
     *              foreach (Unit u in townsArmylist.unitList) {
     *                                                                              // changed from playerU, fixed??,
     *                  while (playerU.currentSize < playerU.maxSize && chall.gold >= u.hirePrice && u.currentSize > 0) {
     *                      failsafe++;
     *                      u.currentSize -= 1;
     *                      playerU.currentSize += 1;
     *                      chall.gold -= u.hirePrice;
     *                      if (failsafe > 10000 || playerU.currentSize >= playerU.maxSize)
     *                          break;
     *                 // Debug.Log("looping still");
     *                  }
     *              }
     *
     *          }
     *       }
     * } */

    private void RefillPlayerRecruits(Challenger chall)
    {
        // Debug.Log("Refill player rec called");
        //fancy gui: troop count is the list, dont need an int check.
        //refilling players recruits
        playerArmy      = chall.GetArmy();
        playersArmyList = chall.armyScrollList; //can uncomment out thses later
        var townsArmy = townsArmylist;

        foreach (Unit p in playerArmy)
        {
            int recruits = (p.maxSize - p.currentSize); //amount needed to hire
            Debug.Log(recruits + " recruits needed for full refill");
            foreach (Unit t in townsArmy)               // line below should assure all units are recruits
            {
                if (recruits <= 0)
                {
                    break;                        //skip to next unit
                }
                int townRecruits = t.currentSize; //amount hireable
                Debug.Log(townRecruits + " recruits in town");
                if (townRecruits > 0)
                {
                    //this unit for the player is now full, so add all recruits
                    int cost = recruits * p.hireCost;
                    //case 1, player unit will be filled to max and can afford
                    if (recruits <= t.currentSize && chall.gold >= cost)
                    {
                        Debug.Log("case 1");
                        chall.gold   -= cost;
                        recruits      = 0;
                        p.currentSize = p.maxSize;
                        if (t.currentSize - recruits >= 0)
                        {
                            t.currentSize -= recruits;
                            // playersArmyList.RefreshDisplay();
                        }
                        else   //should never hit this
                        {
                            t.currentSize = 0;
                            //playersArmyList.RefreshDisplay();
                        }
                        break; // go to next player unit
                    }
                    //case 2, town unit emptied before player unit to max and can afford
                    else if (recruits > t.currentSize && chall.gold >= cost)
                    {
                        Debug.Log("case 2");
                        chall.gold    -= (t.currentSize * t.hireCost);
                        p.currentSize += t.currentSize;
                        recruits      -= t.currentSize;
                        t.currentSize  = 0;
                        // playersArmyList.RefreshDisplay();
                    }
                    //case 3, town unit emptied before player unit to max but cant afford
                    else if (t.currentSize - recruits < 0 && chall.gold < cost)
                    {
                        Debug.Log("case 3");
                        int maxHireable = Mathf.RoundToInt((float)chall.gold / (float)t.hireCost);
                        Debug.Log(maxHireable + " max hirable,,");
                        chall.gold    -= (maxHireable * t.hireCost);
                        p.currentSize += maxHireable;
                        t.currentSize -= maxHireable;
                        // playersArmyList.RefreshDisplay();
                        return; //player is out of gold so break out
                    }
                    //case 4, player unit would be filled to max but cant afford, acting as default fallthrough case as same as case 3
                    else if (recruits - t.currentSize <= 0 && chall.gold < cost)
                    {
                        Debug.Log("case 4");
                        int maxHireable = Mathf.RoundToInt((float)chall.gold / (float)t.hireCost);
                        chall.gold    -= (maxHireable * t.hireCost);
                        p.currentSize += maxHireable;
                        t.currentSize -= maxHireable;
                        //playersArmyList.RefreshDisplay();
                        return;//player is out of gold so break out
                    }
                }
                else
                {
                    Debug.Log("town is empty??");
                    return;
                }
            }
        }
    }
예제 #8
0
 // Use this for initialization
 void Start()
 {
     player      = manager.player;
     playersList = player.armyScrollList;
     playerArmy  = player.GetArmy();
 }
예제 #9
0
 private void AddUnit(Unit unitToAdd, ArmyScrollList list)
 {
     list.unitList.Add(unitToAdd);
 }