Пример #1
0
 //invoked repeatingly, will add 5 to existing stack of recruits if exists or will create new unit with army 1 if empty
 //we dont want more than 1 stack of recruits in a city (2 for capital), so dont regen if so
 //merge uneven troops in capital into one stack if possible: TODO
 public void RegainRecruits()
 {
     buttonText.TextSet();
     if (!isRaided)
     {
         if (townsArmylist.Count == 0 || townsArmylist.Count < 2 && isCapital)
         {
             townsArmylist.Add(new Unit(null, 5));
             buttonText.TextSet();
         }
         else if (townsArmylist.Count > 1 && !isCapital)
         {
             return;
         }
         else if (townsArmylist.Count > 0 && townsArmylist.Count < 3)
         {
             int recruitsToAdd = 5;
             foreach (Unit u in townsArmylist)
             {
                 if (u.currentSize < u.maxSize)
                 {
                     int difToMax = u.maxSize - u.currentSize;
                     if (difToMax >= recruitsToAdd)   //if there is more space than we are adding, just add all and return
                     {
                         u.SetCurrentSize(u.currentSize + recruitsToAdd);
                         return;
                     }
                     else     //this unit is at max after adding less than total recruits so add to max and contiune
                     {
                         recruitsToAdd -= difToMax;
                         u.SetCurrentSize(u.currentSize + recruitsToAdd);
                     }
                 }
             }
             buttonText.TextSet();
         }
     }
 }
Пример #2
0
    //rename to map interact
    public bool InteractionCheck()
    {
        //using mask to filter movement from objects
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        // Debug.Log("Location of player: " + player.location);
        //ignoring triggers around interactables
        if (Physics.Raycast(ray, out hit, 1000, -5, QueryTriggerInteraction.Ignore))
        {
            IInteractable i = hit.collider.GetComponent <IInteractable>();
            Challenger    c = hit.collider.GetComponent <Challenger>();
            //call i's method and update player position to equal this new interactable object
            //if statements in order of priority to handle
            if (c != null)
            {
                // Debug.Log("Click on Challenger recognized");
                //get distance to check if in range
                float distance = Vector3.Distance(playerGO.transform.position, c.transform.position);
                if (distance <= interactRadius)
                {
                    player.interactingWith = c;
                    menuManager.chalText.SetText(c);
                    menuManager.ShowChallengerUI();
                }
                else
                {
                    // Debug.Log("not in range of challenger !");
                }
                // player.CombatCalculation(c); //this works but might be better to show the GUI first
                return(true);
            }
            else if (i != null)
            {
                //Debug.Log("Location of player before: " + player.location);
                //sets the players location to the game object and updates which armyList to transfer to and from
                //Debug.Log("Hit interactable...");
                //get distance to check if in range
                float distance = Vector3.Distance(playerGO.transform.position, i.GetLocation().position);
                if (distance <= interactRadius)
                {
                    player.location = i.GetLocation();

                    //Debug.Log("Location of player after: " + player.location);
                    textButtons.TextSet(); //sets buttons on GUI to relevant location
                    textButtons.UpdateRecruitCount();
                    //player.ChangeOtherArmyList(i.GetArmyList()); not using army lists components in towns using Unit lists
                    i.OnClick();
                    i.GUIOnClick();
                }
                else
                {
                    // Debug.Log("not in range of interactabel! " + distance);
                }

                return(true);
            }
            //and for other interactable scripts
            return(false);
        }
        return(false);
    }