Beispiel #1
0
    public void ActivateButton()
    {
        InventoryItem item = activeList[selected];

        if (mode == "buying")
        {
            if (data.gold >= item.cost * 5)
            {
                data.AddToInventory(item.Copy());
                data.gold    -= item.cost * 5;
                goldText.text = data.gold.ToString();
                // Float cost text
                GameObject        text     = Instantiate(textFab, new Vector3(0, 0, 0), Quaternion.identity, gameObject.transform);
                DmgTextController textCont = text.GetComponent <DmgTextController>();
                textCont.Init(goldText.transform.position, "cost", "-" + (item.cost * 5).ToString());
            }
        }
        else if (mode == "selling")
        {
            data.gold     += item.cost;
            goldText.text  = data.gold.ToString();
            reselectNeeded = data.RemoveFromInventory(selected);
            // Float cost text
            GameObject        text     = Instantiate(textFab, new Vector3(0, 0, 0), Quaternion.identity, gameObject.transform);
            DmgTextController textCont = text.GetComponent <DmgTextController>();
            textCont.Init(goldText.transform.position, "gold", "+" + (item.cost).ToString());

            RefreshItems();
        }
    }
Beispiel #2
0
 // Actions on collisions
 public void NotableActions(string key)
 {
     if (key == "stairsUp")
     {
         data.depth--;
         data.floorDirection = "up";
         if (data.depth == 0)
         {
             data.entrance = 1;
             SceneManager.LoadScene("GreenVillage");
         }
         else
         {
             SceneManager.LoadScene("BasicDungeon");
         }
         return;
     }
     else if (key == "stairsDown")
     {
         data.depth++;
         data.floorDirection = "down";
         SceneManager.LoadScene("BasicDungeon");
         return;
     }
     else if (key.IndexOf("Loot") >= 0)
     {
         Vector3 pos = floorMap.CellToWorld(notableCells[key]);
         if (pos.z != 0)   // Account for floor z diff
         {
             pos.y += 0.75f;
             pos.z  = 0;
         }
         Vector3   diff;
         Transform target = null;
         foreach (Transform child in loot.transform)
         {
             diff = pos - child.position;
             if (diff.magnitude < 0.5)
             {
                 target = child;
                 break;
             }
         }
         if (target != null)
         {
             if (Weapon.IsWeapon(target.name))
             {
                 Weapon wep = new Weapon(target.name);
                 data.AddToInventory(wep);
                 player.saySomething = wep.displayName;
             }
             else if (Armor.IsArmor(target.name))
             {
                 Armor arm = new Armor(target.name);
                 data.AddToInventory(arm);
                 player.saySomething = arm.displayName;
             }
             else if (Potion.IsPotion(target.name))
             {
                 Potion pot = new Potion(target.name);
                 data.AddToInventory(pot);
                 player.saySomething = pot.displayName;
             }
             Destroy(target.gameObject);
             notableCells.Remove(key);
             dungeonController.UpdateNotables(notableCells);
         }
         return;
     }
     else if (key.IndexOf("Gold") >= 0)
     {
         Vector3 pos = floorMap.CellToWorld(notableCells[key]);
         if (pos.z != 0)   // Account for floor z diff
         {
             pos.y += 0.75f;
             pos.z  = 0;
         }
         Vector3   diff;
         Transform target = null;
         foreach (Transform child in loot.transform)
         {
             diff = pos - child.position;
             if (diff.magnitude < 0.5)
             {
                 target = child;
                 break;
             }
         }
         if (target != null)
         {
             data.gold          += goldLedger[key];
             player.saySomething = "+" + goldLedger[key] + " gold";
             goldLedger.Remove(key);
             Destroy(target.gameObject);
             notableCells.Remove(key);
             dungeonController.UpdateNotables(notableCells);
         }
         return;
     }
     else if (key.IndexOf("Chest") >= 0)
     {
         OpenChest(notableCells[key]);
         notableCells.Remove(key);
         dungeonController.UpdateNotables(notableCells);
         return;
     }
 }