Beispiel #1
0
 // Adds an InvItem, given an InvName, quantity, and whether it is to persist at zero
 public virtual void AddInvItem(InvNames name, int quantity, bool persist = false)
 {
     // If the item isn't already there, create a new item and add it to the inventory
     if (!names.Contains(name))
     {
         contents.Add(InvData.MakeNewInvItem(name, persist));
         contents[contents.Count - 1].Quantity = quantity;
         names.Add(name);
         SortInventory();
     }
     else
     {
         // If the Inventory already contains this items, just increase the quantity
         // If a quantity of -1 is passed, the quantity "increases" to "Unlimited"
         if (quantity < 0)
         {
             contents[names.IndexOf(name)].Quantity = -1; // -1 for "Unlimited"
         }
         else
         {
             // If quantity is already -1, leave it at -1, but add quantity if >= 0
             if (contents[names.IndexOf(name)].Quantity >= 0)
             {
                 contents[names.IndexOf(name)].Quantity += quantity;
             }
         }
     }
 }
Beispiel #2
0
 public RootObject(UserData userData, InvData invData)
 {
     UserData = userData;
     Stats    = new StatData();
     ModData  = new ModData();
     Activity = new CountData();
 }
Beispiel #3
0
 // Runs the Initializer() method in each static script. The call is ignored if
 // a class has already been initialized.
 public static void Run()
 {
     //AudioManager initialized by GameAudioSource object
     InvData.Initialize();
     BattleEnemyData.Initialize();
     HeroSpriteData.Initialize();
     BattleAbilityData.Initialize();
     BattleLoader.Initialize();
     Shop.Initialize();
     TalkData.Initialize();
 }
    // For BuyButton On_Click(). Makes the proposed purchase, adjusting gold and Inventorys
    public void Click_BuyButton()
    {
        AudioManager.PlaySound(AudioClipName.ShopPurchase); // ka-ching

        // Calculate gold
        if (remainingAmount >= 0)
        {
            partyGold = remainingAmount;
            BattleLoader.Party.Gold = partyGold;
            remainingAmount         = partyGold;

            // Clear the proposed purchase display
            totalPurchaseAmount = 0;
            RefreshPurchase();
        }

        // Make a dictionary to store the quantity of each item in the purchase
        Dictionary <InvNames, int> purchaseLog = new Dictionary <InvNames, int>();

        // Tells all the shopPanels to put their quantity and itemName info into the log
        makePurchaseEvent.Invoke(purchaseLog);

        // For everything in the log with a quantity > 0
        foreach (KeyValuePair <InvNames, int> pair in purchaseLog)
        {
            // Retrieve the InvItem from the Shop.Stock
            InvItem shopItem = Shop.Stock.GetItem(pair.Key);

            // Deduct quantity from Shop.Stock, but
            // don't deduct from shopInventory if quantity is -1, aka unlimited
            if (shopItem.Quantity > 0)
            {
                Shop.Stock.RemoveInvItem(shopItem.Name, pair.Value);
            }

            // Make a new copy of the item and add some of it to the party inventory
            InvItem partyItem = InvData.MakeNewInvItem(pair.Key);
            BattleLoader.Party.Inventory.AddInvItem(partyItem.Name, pair.Value);
        }
    }