public void PurchaseItem(Button purchaseButtonClicked)
    {
        merchantScript = MapSceneManager.currentLocation.GetComponent <ScriptableMapTileReader>().myMerchant;
        //int itemIndex = Array.FindIndex<Button>(purchaseButtons, purchaseButtons => purchaseButtonClicked);
        int itemIndex = 0;

//TOMAYBEDO This probably isn't very efficient (why not?). Try using System.Array or maybe even just a List<>
        for (int i = 0; i < purchaseButtons.Length; i++)
        {
            if (purchaseButtonClicked == purchaseButtons[i])
            {
                itemIndex = i;
            }
        }

        int itemCost = MapSceneManager.currentLocation.GetComponent <ScriptableMapTileReader>().myMerchant.itemPrices[itemIndex];

        EncounterMerchantScriptable.coinTypes myCoinType = MapSceneManager.currentLocation.GetComponent <ScriptableMapTileReader>().myMerchant.coinType[itemIndex];

        //Debug.Log(itemCost + myCoinType.ToString());

        AddObjectToInventory(merchantScript.itemScripts[itemIndex], merchantScript.objectQuantities[itemIndex], myCoinType, itemCost);

        currentMoneyText.text = "Current Money: \n" +
                                "Silver: " + InventoryManager.silverCarried + "\n" +
                                "Copper: " + InventoryManager.copperCarried;
    }
    public void UpdateLocationBG()
    {
        locationIndexText.GetComponentInChildren <Text>().text = ("Location: " + currentLocation.GetComponent <ScriptableMapTileReader>().myLocationID.ToString());
        locationText.text = currentLocation.GetComponent <ScriptableMapTileReader>().locationText[currentLocationTextIndex];

        locationTimeText.text = "Time: " + currentLocation.GetComponent <ScriptableMapTileReader>().timeTaken.ToString();
        CharacterManager.currentDayTimeTaken += currentLocation.GetComponent <ScriptableMapTileReader>().timeTaken;
        CharacterManager.totalTimeTaken      += currentLocation.GetComponent <ScriptableMapTileReader>().timeTaken;
        characterSheet.GetComponent <MapSceneCharacterSheetManager>().UpdateTimeText();
        print("Time Taken Today: " + CharacterManager.currentDayTimeTaken);

        CharacterManager.currentHealTimeElapsed += currentLocation.GetComponent <ScriptableMapTileReader>().timeTaken;
        print("Current Heal Time: " + CharacterManager.currentHealTimeElapsed + " / " + CharacterManager.healIncrementTime);
        if (CharacterManager.currentHealTimeElapsed >= CharacterManager.healIncrementTime)
        {
            //int timesHealed = CharacterManager.currentHealTimeElapsed /
            AlterDamage(-3, false);
            CharacterManager.currentHealTimeElapsed -= CharacterManager.healIncrementTime;
            if (CharacterManager.currentHealTimeElapsed < 0)
            {
                CharacterManager.currentHealTimeElapsed = 0;
            }
            CharacterManager.healIncrementTime = 60;

            overallActionText.text += "\nYou healed 3 endurance points over time.";
        }

        if (CharacterManager.statusDiseased)
        {
            diseaseIcon.gameObject.SetActive(true);
            CharacterManager.diseaseTimer += currentLocation.GetComponent <ScriptableMapTileReader>().timeTaken;
            if (CharacterManager.diseaseTimer >= 60)
            {
                //print("DiseaseDamageByDivision should be " + CharacterManager.diseaseTimer / 60);
                int diseaseDamageByDivision = CharacterManager.diseaseTimer / 60;
                CharacterManager.diseaseTimer -= diseaseDamageByDivision * 60;
                AlterDamage(diseaseDamageByDivision, false);
                print("You took " + diseaseDamageByDivision + "damage from your disease. Disease Timer: " + CharacterManager.diseaseTimer);
            }
        }

        locationXPText.text       = "Experience: " + currentLocation.GetComponent <ScriptableMapTileReader>().XPGained.ToString();
        CharacterManager.totalXP += currentLocation.GetComponent <ScriptableMapTileReader>().XPGained;
        characterSheet.GetComponent <MapSceneCharacterSheetManager>().UpdateXPText();

        if (currentEncounter != null)
        {
            //If movesTwoSpaces wasn't already false (most of the time it will be), do it now
            //currentEncounter.movesTwoSpaces = false;
        }

        if (currentLocationTextIndex >= currentLocation.GetComponent <ScriptableMapTileReader>().locationText.Length - 1)
        {
            progressLocationTextButton.SetActive(false);

            //If the current location has an ENCOUNTER
            if (currentLocation.GetComponent <ScriptableMapTileReader>().encounterOptionIndex1 == 0)
            {
                locationEncounterButton1.SetActive(false);
            }
            else
            {
                locationEncounterButton1.SetActive(true);
                locationEncounterButton1.GetComponentInChildren <Text>().text = currentLocation.GetComponent <ScriptableMapTileReader>().encounterOptionText1;
            }

            //If the current location has a SECOND ENCOUNTER
            if (currentLocation.GetComponent <ScriptableMapTileReader>().encounterOptionIndex2 == 0)
            {
                locationEncounterButton2.SetActive(false);
            }
            else
            {
                locationEncounterButton2.SetActive(true);
                locationEncounterButton2.GetComponentInChildren <Text>().text = currentLocation.GetComponent <ScriptableMapTileReader>().encounterOptionText2;
            }

            //If the current location has a THIRD ENCOUNTER
            if (currentLocation.GetComponent <ScriptableMapTileReader>().encounterOptionIndex3 == 0)
            {
                locationEncounterButton3.SetActive(false);
            }
            else
            {
                locationEncounterButton3.SetActive(true);
                locationEncounterButton3.GetComponentInChildren <Text>().text = currentLocation.GetComponent <ScriptableMapTileReader>().encounterOptionText3;
            }

            //If the current tile has a settlement and they have already been warned
            if (currentLocation.GetComponent <ScriptableMapTileReader>().mySettlementIndex != 0)
            {
                bool alreadyWarnedSettlement = false;

                switch (currentLocation.GetComponent <ScriptableMapTileReader>().mySettlementIndex)
                {
                case 1:                         //Bridgefields
                    if (CharacterManager.warnedBridgefields)
                    {
                        print("Already warned Bridgefields");
                        alreadyWarnedSettlement = true;
                    }
                    break;

                case 2:                         //Bywater
                    if (CharacterManager.warnedBywater)
                    {
                        alreadyWarnedSettlement = true;
                    }
                    break;

                case 3:                         //Frogmorton
                    if (CharacterManager.warnedFrogmorton)
                    {
                        alreadyWarnedSettlement = true;
                    }
                    break;

                case 4:                         //Hobbiton
                    if (CharacterManager.warnedHobbiton)
                    {
                        alreadyWarnedSettlement = true;
                    }
                    break;

                case 5:                         //Marish
                    if (CharacterManager.warnedMarish)
                    {
                        alreadyWarnedSettlement = true;
                    }
                    break;

                case 6:                         //Scary
                    if (CharacterManager.warnedScary)
                    {
                        alreadyWarnedSettlement = true;
                    }
                    break;

                case 7:                         //Stock
                    if (CharacterManager.warnedStock)
                    {
                        print("Already warned Stock");
                        alreadyWarnedSettlement = true;
                    }
                    break;

                case 8:                         //Tuckborough
                    if (CharacterManager.warnedTuckborough)
                    {
                        alreadyWarnedSettlement = true;
                    }
                    break;

                case 9:                         //Whitfurrows
                    if (CharacterManager.warnedWhitfurrows)
                    {
                        alreadyWarnedSettlement = true;
                    }
                    break;

                case 10:                         //Woodhall
                    if (CharacterManager.warnedWoodhall)
                    {
                        alreadyWarnedSettlement = true;
                    }
                    break;

                default:
                    Debug.Log("What settlement is this supposed to be?");
                    break;
                }

                if (alreadyWarnedSettlement)
                {
                    if (currentLocation.GetComponent <ScriptableMapTileReader>().myMerchant != null)
                    {
                        currentEncounter.myEncounterScriptable = GetComponent <EncounterManager>().encounterTextScriptables[464];
                        UpdateEncounterBG();
                        CloseLocationUI();
                        OpenEncounterUI();
                    }
                    else
                    {
                        print("Already warned this settlement, but it doesn't have a merchant");
                        currentEncounter.myEncounterScriptable = GetComponent <EncounterManager>().encounterTextScriptables[465];
                        UpdateEncounterBG();
                        CloseLocationUI();
                        OpenEncounterUI();
                    }
                }
            }

            //TOMAYBEDO Move this if-statement to a separate public function, to be used for the OnClick() for any "merchant encounter" buttons
            //If the current location has a MERCHANT
            if (currentLocation.GetComponent <ScriptableMapTileReader>().myTileScriptable.myMerchantScriptable != null)
            {
                EncounterMerchantScriptable myMerchant = currentLocation.GetComponent <ScriptableMapTileReader>().myMerchant;

                //Update MerchantBG display
                for (int i = 0; i < MerchantUI.GetComponent <MerchantUIManager>().itemNameTexts.Length; i++)
                {
                    MerchantUI.GetComponent <MerchantUIManager>().itemNameTexts[i].text = myMerchant.itemsForSale[i];
                    MerchantUI.GetComponent <MerchantUIManager>().itemCostTexts[i].text = myMerchant.itemPrices[i] + " " + myMerchant.coinType[i].ToString();
                }

                //Display the character's current funds on the MerchantBG
                MerchantUI.GetComponent <MerchantUIManager>().currentMoneyText.text = "Current Money: \n" +
                                                                                      "Silver: " + InventoryManager.silverCarried + "\n" +
                                                                                      "Copper: " + InventoryManager.copperCarried;

                //openMerchantUIButton.SetActive(true);
            }

            //If the current location has COMBAT

            //If the character can REST or MOVE ON from the current text
            if (CharacterManager.currentDayTimeTaken >= 780 && currentLocation.GetComponent <ScriptableMapTileReader>().canRestAtNight)
            {
                locationEncounterButton1.SetActive(false);
                locationEncounterButton2.SetActive(false);
                locationEncounterButton3.SetActive(false);

                EnableRestUI();
                moveOnButton.SetActive(false);
            }
            else if (currentLocation.GetComponent <ScriptableMapTileReader>().myTileScriptable.canMoveOn)
            {
                restUI.SetActive(false);
                moveOnButton.SetActive(true);
            }
            else
            {
                restUI.SetActive(false);
                moveOnButton.SetActive(false);
            }
        }
        else
        {
            progressLocationTextButton.SetActive(true);
            moveOnButton.SetActive(false);
        }

        CloseEncounterUI();
    }
Exemplo n.º 3
0
    void Awake()
    {
        if (myTileScriptable != null)
        {
            myLocationID      = myTileScriptable.locationID;
            mySettlementIndex = myTileScriptable.settlementIndex;

            locationText          = myTileScriptable.locationText;
            encounterOptionText1  = myTileScriptable.encounterText1;
            encounterOptionIndex1 = myTileScriptable.encounterIndex1;
            encounterOptionText2  = myTileScriptable.encounterText2;
            encounterOptionIndex2 = myTileScriptable.encounterIndex2;
            encounterOptionText3  = myTileScriptable.encounterText3;
            encounterOptionIndex3 = myTileScriptable.encounterIndex3;
            encounterOptionText4  = myTileScriptable.encounterText4;
            encounterOptionIndex4 = myTileScriptable.encounterIndex4;
            addSkillToAction      = myTileScriptable.actionAddsSkill;

            if (myTileScriptable.exploreHasMultipleRanges)
            {
                exploreHasMultipleRanges = myTileScriptable.exploreHasMultipleRanges;
                howManyRanges            = myTileScriptable.howManyRanges;

                if (howManyRanges > 0)
                {
                    exploreRange1      = new RangeInt(myTileScriptable.range1Min, myTileScriptable.range1Length);
                    range1FurtherIndex = myTileScriptable.range1FurtherIndex;
                }

                if (howManyRanges > 1)
                {
                    exploreRange2      = new RangeInt(myTileScriptable.range2Min, myTileScriptable.range2Length);
                    range2FurtherIndex = myTileScriptable.range2FurtherIndex;
                }

                if (howManyRanges > 2)
                {
                    exploreRange3      = new RangeInt(myTileScriptable.range3Min, myTileScriptable.range3Length);
                    range3FurtherIndex = myTileScriptable.range3FurtherIndex;
                }
                if (howManyRanges > 3)
                {
                    exploreRange4      = new RangeInt(myTileScriptable.range4Min, myTileScriptable.range4Length);
                    range4FurtherIndex = myTileScriptable.range4FurtherIndex;
                }

                rangeFailMeansMoveOn     = myTileScriptable.rangeFailMeansMoveOn;
                canGetLost               = myTileScriptable.canGetLost;
                randomDirectionChoiceMax = myTileScriptable.randomDirectionRangeMax;

                //rangeFailMeansDie = myTileScriptable.rangeFailMeansGameOver;
            }

            hasCombat = myTileScriptable.combatHere;

            if (myTileScriptable.merchantHere)
            {
                myMerchant = myTileScriptable.myMerchantScriptable;
            }

            canMoveOn = myTileScriptable.canMoveOn;

            timeTaken          = myTileScriptable.timeTaken;
            secondaryTimeTaken = myTileScriptable.timeTakenSecondary;
            canRestAtNight     = myTileScriptable.canRestAtNight;

            timeLocked    = myTileScriptable.timeLocked;
            daysLimit1    = myTileScriptable.daysLimit1;
            timeLimit1    = myTileScriptable.timeLimit1;
            limit1Index   = myTileScriptable.limit1Index;
            daysLimit2    = myTileScriptable.daysLimit2;
            timeLimit2    = myTileScriptable.timeLimit2;
            limit2Index   = myTileScriptable.limit2Index;
            overTimeIndex = myTileScriptable.overTimeIndex;

            XPGained = myTileScriptable.experience;

            changesPlayerLocation = myTileScriptable.changesPlayerLocation;
            changedLocationID     = myTileScriptable.changedLocationID;

            previousLocationsConsidered = myTileScriptable.previousLocationsConsidered;
            locationsConsidered         = myTileScriptable.locationsConsidered;
            locationBasedEncounter      = myTileScriptable.locationBasedEncounter;
            alternateLocationEncounter  = myTileScriptable.alternateLocationEncounter;

            downstreamSameSideTile1ID  = myTileScriptable.riverSameSideTile1ID;
            downstreamSameSideTile2ID  = myTileScriptable.riverSameSideTile2ID;
            downstreamOtherSideTile1ID = myTileScriptable.riverOtherSideTile1ID;
            downstreamOtherSideTile2ID = myTileScriptable.riverOtherSideTile2ID;
        }
    }