Example #1
0
    private void ShowRangeOnHover()
    {
        TroopPlaceholder temp = inventory.GetHighlightedUnit();

        if (temp != null)
        {
            Vector3      mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit      = Physics2D.Raycast(new Vector2(mousePos.x, mousePos.y), Vector2.zero, 0, TowerLayers);
            if (hit)
            {
                Vector3 center = hit.collider.gameObject.transform.position - new Vector3(0, 0.1f, 0);
                Debug.Log(center);
                ringObject.GetComponent <Renderer>().enabled = true;
                ringObject.transform.localScale = new Vector3(temp.Range * 2, temp.Range * 2, 0);
                ringObject.transform.position   = center;
                Debug.Log(temp.Range);
            }
            else
            {
                ringObject.GetComponent <Renderer>().enabled = false;
            }
        }
        else
        {
            ringObject.GetComponent <Renderer>().enabled = false;
        }
    }
Example #2
0
    /// <summary>
    /// Takes in a troop to be added to the inventory
    /// </summary>
    /// <param name="troop">The troop that is sent to the inventory</param>
    /// <returns>if the troop could be added to the inventory</returns>
    public bool AddTroop(TroopPlaceholder troop)
    {
        if (IsInventoryFull())
        {
            return(false);
        }

        // Find the next available slot in the inventory
        int newSlot = GetAvailableSlot();

        if (newSlot == -1)
        {
            return(false);
        }

        // Add it to Inventory Grid
        GameObject newInventoryItemGO = GameObject.Instantiate(inventoryGridUnit, buttonParent.transform);

        newInventoryItemGO.SetActive(true);
        buttons[newSlot] = newInventoryItemGO;
        InventoryUIUnit newInventoryUnit = newInventoryItemGO.GetComponent <InventoryUIUnit>();

        newInventoryUnit.index = newSlot;
        newInventoryUnit.troop = troop;
        newInventoryUnit.UpdateUI();

        InfoWindow.ClearStatic();


        inventory[newSlot] = troop;
        itemCount++;
        return(true);
    }
Example #3
0
    // Will try to purchase a unit from the shop at the index given
    public void BuyTower(int index)
    {
        if (GameStats.Instance.GetCursorState() == CursorState.BuyingTower)
        {
            return;
        }

        if (currentShop[index] == TowerType.None)
        {
            return;// false;
        }
        if (!unitAssignment.IsInventoryFull())
        {
            if (GameStats.Instance.PurchaseItemOfType(currentShop[index]))
            {
                // * add it to the inventory *
                TroopPlaceholder newTroop = new TroopPlaceholder(GameStats.Instance.TroopBaseData[currentShop[index]]);
                unitAssignment.AddTroop(newTroop);

                currentShop[index] = TowerType.None;
                uiManager.towerButtons[index].SetActive(false);
                //return true;
            }
        }
    }
Example #4
0
 public TroopPlaceholder GetHighlightedUnit()
 {
     if (highlightedIndex != -1)
     {
         TroopPlaceholder toReturn = inventory[highlightedIndex];
         return(toReturn);
     }
     return(null);
 }
Example #5
0
 public void AssignUnit(TroopPlaceholder troop)
 {
     if (isUnitAssigned)
     {
         return;
     }
     isUnitAssigned      = true;
     this.troop          = troop;
     selfRenderer.sprite = troop.BattlefieldSprite;
 }
Example #6
0
    /// <summary>
    /// Takes in a troop to be added to the inventory
    /// </summary>
    /// <param name="troop">The troop that is sent to the inventory</param>
    /// <returns>if the troop could be added to the inventory</returns>
    public bool AddTroop(TroopPlaceholder troop)
    {
        if (itemCount + 1 > maxInventorySize)
        {
            return(false);
        }

        inventory[itemCount] = troop;
        itemCount++;
        return(true);
    }
Example #7
0
 void Start()
 {
     emptyInvItem     = new TroopPlaceholder(EmptyInvItem);
     highlightedIndex = -1;
     buttons          = buttonParent.GetComponentsInChildren <Button>();
     //maxInventorySize = buttons.Length;
     for (int i = 0; i < buttons.Length; i++)
     {
         inventory.Add(emptyInvItem);
     }
 }
Example #8
0
 public void UpdateInfo(TroopPlaceholder troop)
 {
     gameObject.SetActive(true);
     portrait.sprite      = troop.InventorySprite;
     nameText.text        = troop.TroopName;
     descriptionText.text = troop.Description;
     tierText.text        = troop.tier.ToString();
     rangeValueText.text  = troop.Range.ToString();
     damageValueText.text = troop.Damage.ToString();
     asValueText.text     = troop.AttackSpeed.ToString();
 }
Example #9
0
    /// <summary>
    /// Removes and returns a troop at the given index
    /// </summary>
    /// <returns>the troop at the given index</returns>
    public TroopPlaceholder RemoveAtIndex(int index)
    {
        TroopPlaceholder toReturn = inventory[index];

        inventory[index] = null;
        GameObject.Destroy(buttons[index]);
        buttons[index] = null;
        // Just clear the highlighted unit, just to be safe
        SetHighlightedUnit(-1);
        itemCount--;
        return(toReturn);
    }
Example #10
0
    public TroopPlaceholder RemoveUnit()
    {
        if (!isUnitAssigned)
        {
            return(null);
        }
        isUnitAssigned = false;
        TroopPlaceholder temp = troop;

        troop = null;
        selfRenderer.sprite = emptyTower;
        return(temp);
    }
Example #11
0
    /// <summary>
    /// pops the highlighted troop out
    /// </summary>
    /// <returns>the troop highlighted, if no troop is highlighted returns null</returns>
    public TroopPlaceholder PopHighlightedTroop()
    {
        if (highlightedIndex != -1)
        {
            TroopPlaceholder temp = inventory[highlightedIndex];
            inventory.RemoveAt(highlightedIndex);
            inventory.Add(emptyInvItem);
            itemCount       -= 1;
            outputLabel.text = "";
            highlightedIndex = -1;
            return(temp);
        }

        return(null);
    }
Example #12
0
    public void CombineTroops()
    {
        if (highlightedIndex == -1)
        {
            return;
        }

        TroopPlaceholder temp = PopHighlightedTroop();

        if (temp.tier < temp.MaxTier)
        {
            List <int> sameTypeIndex = new List <int>();
            for (int i = 0; i < inventory.Length; i++)
            {
                if (inventory[i] == null)
                {
                    continue;
                }

                if (inventory[i].data.TowerType == temp.data.TowerType && inventory[i].tier == temp.tier)
                {
                    sameTypeIndex.Add(i);
                }
            }

            if (sameTypeIndex.Count > 1)
            {
                for (int i = 0; i < 2; i++)
                {
                    RemoveAtIndex(sameTypeIndex[i]);
                }
                temp.TierUp();
            }
        }
        AddTroop(temp);
    }
Example #13
0
    //public Color highlightedColor;

    public void SetTroop(TroopPlaceholder troop)
    {
        this.troop = troop;
    }
Example #14
0
 public static void UpdateInfoStatic(TroopPlaceholder troop)
 {
     instance.UpdateInfo(troop);
 }