Exemple #1
0
    public void UpgradeARackOfRigs(int rackSlot, Rack rackToUpgrade = null)
    {
        // TODO: figure out whether this actually does anything
        if (!rackToUpgrade)
        {
            foreach (Transform slot in rackSlots)
            {
                //Checking my rack ID to find the one we want to upgrade
                if (slot.GetComponent <RackSlot>().myOrderNumber == rackSlot)
                {
                    //Debug.Log("About to upgrade this rack!");
                    RigScript[] rigslotsInThisRackGroup;
                    // Collecting all the RIGSCRIPTS inside this RACKSLOT to the update them
                    rigslotsInThisRackGroup = slot.GetComponentsInChildren <RigScript>(true);

                    // Find out if we have enough money to upgrade all the rigs in this group
                    if (rigslotsInThisRackGroup[0].me.priceOfNextUpgradeLvl * rigslotsInThisRackGroup.Length < miningControllerInstance.myMiningController.currentBalance)
                    {
                        // Charge me the money for the upgrade of the 3 rigs in the group
                        miningControllerInstance.myMiningController.currentBalance -= rigslotsInThisRackGroup[0].me.priceOfNextUpgradeLvl * rigslotsInThisRackGroup.Length;
                        //Debug.Log("Charged you " + rigslotsInThisRackGroup[0].me.priceOfNextUpgradeLvl * rigslotsInThisRackGroup.Length + " for the upgrades on the rack");

                        // The actual rig upgrade process
                        foreach (RigScript rig in rigslotsInThisRackGroup)
                        {
                            //Debug.Log(rig.me);
                            //Debug.Log("My rig id is now " + rig.me.id);
                            rig.me = itemDatabase.rigTypes[rig.me.id + 1];
                            //Debug.Log("My rig id is now " + rig.me.id);
                            rig.RefreshIcon();
                        }
                        // Getting info from one of the rigs in the bunch
                        RigScript rigSample = rigslotsInThisRackGroup[0];
                        // APPLYING THE UPGRADE'S EFFECTS (this will be multiplied by 3, because there are 3 rigs in each rack
                        miningControllerInstance.IncreaseMinMaxMiningSpeed(rigSample.me.myEffectOnMining * 3);

                        //Send in the info to the UI so it can be udpated with the newly updated rig info for this rag
                        Debug.Log("Spawning a " + rigslotsInThisRackGroup[0].me);
                        mapDelegateHolder.upgradedRackActions(rigslotsInThisRackGroup[0].me, rackSlot);


                        return;
                    }
                    Debug.Log("Not enough money to upgrade all the rigs in this group!");
                    return;
                }
            }
        }
        else
        {
            Debug.Log("About to upgrade a specific rack!");
            RigScript[] rigslotsInThisRackGroup;
            // Collecting all the RIGSCRIPTS inside this RACKSLOT to the update them
            rigslotsInThisRackGroup = rackToUpgrade.GetComponentsInChildren <RigScript>(true);

            if (rigslotsInThisRackGroup[0].me.priceOfNextUpgradeLvl * rigslotsInThisRackGroup.Length < miningControllerInstance.myMiningController.currentBalance)
            {
                // Charge me the money for the upgrade
                miningControllerInstance.myMiningController.currentBalance -= rigslotsInThisRackGroup[0].me.priceOfNextUpgradeLvl * rigslotsInThisRackGroup.Length;
                //Debug.Log("Charged you " + rigslotsInThisRackGroup[0].me.priceOfNextUpgradeLvl * rigslotsInThisRackGroup.Length + " for the upgrades on the rack");

                foreach (RigScript rig in rigslotsInThisRackGroup)
                {
                    Debug.Log(rig.me);
                    //Debug.Log("My rig id is now " + rig.me.id);
                    rig.me = itemDatabase.rigTypes[rig.me.id + 1];
                    //Debug.Log("My rig id is now " + rig.me.id);
                    rig.RefreshIcon();

                    miningControllerInstance.IncreaseMinMaxMiningSpeed(rig.me.myEffectOnMining);
                }
                Debug.Log("Spawning a " + rigslotsInThisRackGroup[0].me);
                mapDelegateHolder.upgradedRackActions(rigslotsInThisRackGroup[0].me, rackSlot);

                //Debug.Log("I've upgraded all the rigs in this group!");
                return;
            }
            Debug.Log("Not enough money to upgrade all the rigs in this group!");
            return;
        }
    }