//Gives the reward for completing a quest public void GiveItem() { //Gives a weapon if (currentQuest.giveWeapon == true) { GameObject questDrop = Instantiate(Resources.Load("Loot Drop"), player.transform.position, Quaternion.identity) as GameObject; LootDropMonitor questDropMonitor = questDrop.GetComponent <LootDropMonitor>(); questDropMonitor.type = 0; questDropMonitor.itemStats = LootManager.GenerateSpecificWeapon(currentQuest.weaponType, currentQuest.weaponValue); } //Give an Item if (currentQuest.giveItem == true) { GameObject questDrop = Instantiate(Resources.Load("Loot Drop"), player.transform.position, Quaternion.identity) as GameObject; LootDropMonitor questDropMonitor = questDrop.GetComponent <LootDropMonitor>(); questDropMonitor.type = 2; questDropMonitor.item = currentQuest.itemName; } //Gives Xp for quest PersistantGameManager.Instance.playerStats.playerExperience += currentQuest.questExperience; //Removes item from inventory if (!currentQuest.instantComplete && currentQuest.returnItem) { PersistantGameManager.Instance.itemInventory[currentQuest.questItemName]--; } //Tells PGM to move onto the next quest PersistantGameManager.Instance.characterQuests[nameOfNpc]++; //Removes quest from PGM PersistantGameManager.Instance.activeQuests.Remove(currentQuest.questKey); PersistantGameManager.Instance.possibleQuests.Remove(currentQuest.questKey); PersistantGameManager.Instance.completedQuests.Add(currentQuest.questKey); //Tells player they have completed the quest TextMeshProUGUI text = GameObject.FindGameObjectWithTag("Updates").GetComponent <TextMeshProUGUI>(); if (!currentQuest.instantComplete) { text.text = "Completed " + currentQuest.questName; } hasTalkedBefore = false; currentQuest = null; EndDialogue(); //If instant complete then loop to next dialogue if (mGiveItem) { StartCoroutine(CreateDialogueBox()); mGiveItem = false; } }
//Runs through each sentence moving onto the next one when the player clicks //Some will start a co-routine that waits for the player to complete a certian task before conintuing public void ContinueDialogue() { if (canContinueDialogue) { if (stageOfConvo == 0) { if (currentSentenceIndex == 0) { StopAllCoroutines(); StartCoroutine(AddChars("Let me get you up to speed, you look new here after all./d", canvasMainText)); currentSentenceIndex = 1; } else if (currentSentenceIndex == 1) { StopAllCoroutines(); StartCoroutine(AddChars("Using ‘A’ and ‘D’ you can move left and right,\n/wTry that now...", canvasMainText)); canvasContinueButton.gameObject.SetActive(false); canContinueDialogue = false; StartCoroutine(WaitForPlayerMove()); currentSentenceIndex = 2; } else if (currentSentenceIndex == 2) { StopAllCoroutines(); StartCoroutine(AddChars("Now try a jump, and then a double jump with the space bar...", canvasMainText)); canvasContinueButton.gameObject.SetActive(false); canContinueDialogue = false; StartCoroutine(WaitForPlayerJump()); currentSentenceIndex = 3; } else if (currentSentenceIndex == 3) { StopAllCoroutines(); StartCoroutine(AddChars("Head to your right and grab that item on the topmost platform, \nUse ‘E’ to interact with items...", canvasMainText)); canvasContinueButton.gameObject.SetActive(false); canContinueDialogue = false; StartCoroutine(WaitForPlayerPickup()); currentSentenceIndex = 4; } else if (currentSentenceIndex == 4) { StopAllCoroutines(); StartCoroutine(AddChars("Now lets have a look at the items you hold, Click 'tab' to open the menu, And click the [items] button to view your inventory...", canvasMainText)); canvasContinueButton.gameObject.SetActive(false); canContinueDialogue = false; StartCoroutine(WaitForPlayerToOpenMenu()); currentSentenceIndex = 5; } else if (currentSentenceIndex == 5) { StopAllCoroutines(); StartCoroutine(AddChars("In the menu you can also see your weapons and active quests.../d", canvasMainText)); canContinueDialogue = false; currentSentenceIndex = 6; } else if (currentSentenceIndex == 6) { StopAllCoroutines(); StartCoroutine(AddChars("You can look deeper into a quest by clicking on it in the [quests] menu, Give it a go...", canvasMainText)); canvasContinueButton.gameObject.SetActive(false); canContinueDialogue = false; StartCoroutine(WaitForPlayerToOpenQuestDesc()); currentSentenceIndex = 7; } else if (currentSentenceIndex == 7) { StopAllCoroutines(); StartCoroutine(AddChars("Good job! When you are ready come chat to me.../d", canvasMainText)); currentSentenceIndex = 8; } else if (currentSentenceIndex == 8) { dialogueCanvas.SetActive(false); stageOfConvo = 1; currentSentenceIndex = 0; } } if (stageOfConvo == 1) { if (currentSentenceIndex == 1) { dialogueCanvas.SetActive(true); StopAllCoroutines(); StartCoroutine(AddChars("If you find others around, this is how you'll greet them. They will give you quests and rewards should you choose to help them./d", canvasMainText)); canContinueDialogue = false; currentSentenceIndex = 2; } else if (currentSentenceIndex == 2) { canContinueDialogue = false; StopAllCoroutines(); StartCoroutine(AddChars("If you're struggling to find your way around, you can use your minimap by pressing 'P'./d", canvasMainText)); currentSentenceIndex = 3; } else if (currentSentenceIndex == 3) { canContinueDialogue = false; StopAllCoroutines(); StartCoroutine(AddChars("It seems like you don't have any weapons. You're going to need one in here./d", canvasMainText)); currentSentenceIndex = 4; } else if (currentSentenceIndex == 4) { canContinueDialogue = false; StopAllCoroutines(); StartCoroutine(AddChars("You'll find a few different types of weapons around, some more effective than others./d", canvasMainText)); currentSentenceIndex = 5; } else if (currentSentenceIndex == 5) { canContinueDialogue = false; StopAllCoroutines(); //Drops jasons dagger GameObject questDrop = Instantiate(Resources.Load("Loot Drop"), player.transform.position, Quaternion.identity) as GameObject; LootDropMonitor questDropMonitor = questDrop.GetComponent <LootDropMonitor>(); questDropMonitor.type = 0; questDropMonitor.itemStats = new Weapon("Dagger", "Jason's ", "", "", 5, 0.5f, 0.5f, 1, 1.5f); StartCoroutine(AddChars("Here's my dagger, I don't use it much anyway, Use 'e' to pick up a weapon. Pressing 1, 2 or 3 will change the slot you are comparing and switching into.../d", canvasMainText)); currentSentenceIndex = 6; } else if (currentSentenceIndex == 6) { bool hasPickedItUp = false; foreach (Weapon weapon in PersistantGameManager.Instance.playerWeaponInventory) { if (weapon.itemPrefix == "Jason's ") { hasPickedItUp = true; break; } } if (hasPickedItUp) { currentSentenceIndex = 7; ContinueDialogue(); } else { StopAllCoroutines(); canContinueDialogue = false; canvasContinueButton.gameObject.SetActive(false); StartCoroutine(AddChars("Pick up my dagger, use 'e' and click the [Take] button or 'L' to take the weapon. Pressing the [Keep] button or 'K' will keep your current weapon and leave the new one./d", canvasMainText)); StartCoroutine(WaitForPlayerToPickupWeapon()); currentSentenceIndex = 7; } } else if (currentSentenceIndex == 7) { canContinueDialogue = false; StopAllCoroutines(); Instantiate(Resources.Load("Tutorial Enemy")); canvasContinueButton.gameObject.SetActive(false); StartCoroutine(AddChars("You can see the equipped weapon slot in the bottom left of the screen. Pressing 1, 2, or 3 will change the weapon you are using. " + "\nAn enemy has appeared on the right. Use 'W' to attack, but try not to touch it...", canvasMainText)); StartCoroutine(WaitForPlayerToKillEnemy()); currentSentenceIndex = 8; } else if (currentSentenceIndex == 8) { canContinueDialogue = false; StopAllCoroutines(); if (player.currentHealth > player.totalHealth - 0.01f) { StartCoroutine(AddChars("Wow, I'm impressed you did that without taking any damage!.../d", canvasMainText)); currentSentenceIndex = 9; } else { canvasContinueButton.gameObject.SetActive(false); StartCoroutine(AddChars("Oosh, you took some hard hits, Just wait a few seconds without taking damage or attacking and your health will soon come back...", canvasMainText)); StartCoroutine(WaitForPlayerFullHealth()); currentSentenceIndex = 10; } } else if (currentSentenceIndex == 9) { canContinueDialogue = false; StopAllCoroutines(); StartCoroutine(AddChars("But if you do take damage your health regenerates after a few seconds of no combat.../d", canvasMainText)); currentSentenceIndex = 10; } else if (currentSentenceIndex == 10) { canContinueDialogue = false; StopAllCoroutines(); StartCoroutine(AddChars("This enemy dropped a weapon, as do others. Taking a weapon on the ground will switch it with your old weapon, so whatever you used to have will be on the ground should you change your mind./d ", canvasMainText)); currentSentenceIndex = 11; } else if (currentSentenceIndex == 11) { canContinueDialogue = false; StopAllCoroutines(); StartCoroutine(AddChars("He also gave you some xp, You need a certain amount of xp to level up\nAnd you seem to have leveled up.../d", canvasMainText)); currentSentenceIndex = 13; } /*Obselete * else if (currentSentenceIndex == 12) * { * canContinueDialogue = false; * StopAllCoroutines(); * StartCoroutine(AddChars("Click 'u' to open the player canvas, Then from there click 'k' to open the skills panel, to unlock a skill you must spend a skill point.../d", canvasMainText)); * currentSentenceIndex = 13; * } */ else if (currentSentenceIndex == 13) { if (PersistantGameManager.Instance.playerStats.playerSkillPoints == 0) { currentSentenceIndex = 14; ContinueDialogue(); } if (PersistantGameManager.Instance.playerStats.playerSkillPoints > 0) { canvasContinueButton.gameObject.SetActive(false); canContinueDialogue = false; StopAllCoroutines(); StartCoroutine(AddChars("Press 'U' to open the character menu and find the [Skills] button. in that screen can spend skill points to unlock skills. You earned one from levelling up, try spending it now...", canvasMainText)); StartCoroutine(WaitForPlayerToUnlockSkill()); currentSentenceIndex = 14; } } else if (currentSentenceIndex == 14) { StopAllCoroutines(); canContinueDialogue = false; StartCoroutine(AddChars("Every time you level up you get a skill point, you will use these to unlock skills, remember to use them.../d", canvasMainText)); currentSentenceIndex = 15; } else if (currentSentenceIndex == 15) { StopAllCoroutines(); canContinueDialogue = false; StartCoroutine(AddChars("Just to make sure you remember.../d", canvasMainText)); currentSentenceIndex = 16; } else if (currentSentenceIndex == 16) { StopAllCoroutines(); canContinueDialogue = false; StartCoroutine(AddChars("You hold 3 weapons, and can switch them with 1, 2, and 3, the order can be arranged in your weapons menu. If you need to save your game or load an old one, click the button in the menu./d", canvasMainText)); currentSentenceIndex = 17; } else if (currentSentenceIndex == 17) { StopAllCoroutines(); canContinueDialogue = false; StartCoroutine(AddChars("As you explore and complete quests, the world will change around you. Be sure to check for areas you may have not been able to reach before, and to click on strange looking terrain./d", canvasMainText)); currentSentenceIndex = 18; } else if (currentSentenceIndex == 18) { StopAllCoroutines(); canContinueDialogue = false; canvasContinueButton.gameObject.SetActive(false); StartCoroutine(AddChars("I've taught you all I can. Use [enter] to go through doors. Goodbye", canvasMainText)); PersistantGameManager.Instance.activeQuests.Remove("Tutorial"); PersistantGameManager.Instance.possibleQuests.Remove("Tutorial"); PersistantGameManager.Instance.tutorialComplete = true; } } } }
private void Update() { if (type == 2) { if (PersistantGameManager.Instance.itemInventory.ContainsKey(item)) { if (PersistantGameManager.Instance.itemInventory[item] > 0 || PersistantGameManager.Instance.completedQuests.Contains(quest)) { Destroy(gameObject); } } } //Gets the distance to the player distanceToPlayer = Vector2.Distance(player.transform.position, transform.position); //If the player is close enough to the loot drop and "E" is pressed if (distanceToPlayer < 2f && Input.GetKeyDown(KeyCode.E) && Time.timeScale != 0) { //makes an array of all current loot drops LootDropMonitor[] lootDrops = FindObjectsOfType <LootDropMonitor>(); //Sets the closest loot drop info as this LootDropMonitor closestLootDrop = this; float closestDistance = distanceToPlayer; //repeats for each loot drop foreach (LootDropMonitor lootDrop in lootDrops) { //if a loot drop is closer than any previous once sets that loot drop as the closest loot drop if (lootDrop.distanceToPlayer <= closestDistance) { closestDistance = lootDrop.distanceToPlayer; closestLootDrop = lootDrop; } } //If the compare Screen is not currently open, the compare canvas wont close on a "E" press and this is the closest loot drop if (!PersistantGameManager.Instance.compareScreenOpen && closestLootDrop == this && type == 0) { asyncTriggers.OpenCompareCanvas(itemStats); //Tells the script that is needs to wait for the comapre screen to close waitingForChange = true; } else if (!PersistantGameManager.Instance.compareScreenOpen && closestLootDrop == this && type == 1) { //Sets the weapon to compare as the weapon this is storing Destroy(gameObject); } else if (!PersistantGameManager.Instance.compareScreenOpen && closestLootDrop == this && type == 2) { if (!PersistantGameManager.Instance.itemInventory.ContainsKey(item)) { PersistantGameManager.Instance.itemInventory.Add(item, 0); print("added"); } PersistantGameManager.Instance.itemInventory[item] += 1; TextMeshProUGUI text = GameObject.FindGameObjectWithTag("Updates").GetComponent <TextMeshProUGUI>(); text.text = item + " added to inventory"; Destroy(gameObject); } } //Calls when the compare screen closes if (waitingForChange && !PersistantGameManager.Instance.compareScreenOpen) { //stores the disregarded weapon itemStats = PersistantGameManager.Instance.comparingWeapon; //tells the script it doesnt need to wait for the compare screen to close waitingForChange = false; } }
//The Death method, drops a loot item, gives xp and then destorys the enemy will eventully play death animation public void EnemyDeath() { if (PersistantGameManager.Instance.currentEnemyKills.ContainsKey(enemyStats.enemyName)) { PersistantGameManager.Instance.currentEnemyKills[enemyStats.enemyName]++; } else { PersistantGameManager.Instance.currentEnemyKills.Add(enemyStats.enemyName, 1); } if (questTarget == true && PersistantGameManager.Instance.activeQuests.Contains(questKey)) { GameObject questDrop = Instantiate(Resources.Load(lootDropPreFabName), transform.position + new Vector3(0.6f, 0, 0), Quaternion.identity) as GameObject; LootDropMonitor questDropMonitor = questDrop.GetComponent <LootDropMonitor>(); questDropMonitor.type = 2; //questDropMonitor.item = PersistantGameManager.Instance.questTargets[nPCMonitor.currentQuest.questKey]; questDropMonitor.item = questReward; droppedQuestItem = true; } // Sets most recent killed enemy's level to the enemy level for loot to level based on enemy stats rather than the player. PersistantGameManager.Instance.lastEnemyLevel = enemyStats.enemyLevel; //Gets the new weapon based off the drop chance and the value of weapon, if a weapon is not going to be droped it returns null LootItem newItem = LootManager.DropItem(itemChance, weaponValue); int chance = random.Next(0, 3); if (chance > 0 && enemyStats.enemyName != "Evil Door") { newItem = null; } //runs if there is a weapon stored in new weapon if (newItem != null) { //Instatiates the loot drop prefab at the poition of the enemy takes a local "Gameobject copy" GameObject lootDropInstance = Instantiate(Resources.Load(lootDropPreFabName), transform.position, Quaternion.identity) as GameObject; //gets the LootDropMonitor from the newly created Loot Drop LootDropMonitor lootDropInstanceMonitor = lootDropInstance.GetComponent <LootDropMonitor>(); if (newItem.type == 0) { lootDropInstanceMonitor.type = 0; lootDropInstanceMonitor.itemStats = newItem.newWeapon; } if (droppedQuestItem == true) { Vector2 lootPosition = lootDropInstance.transform.position; lootDropInstance.transform.position = new Vector2(lootDropInstance.transform.position.x - 1 / 2, lootPosition.y); } //Tells the Loot Drop what weapon it should store } //Gives the player XP GiveExp(enemyStats.enemyTier, enemyStats.enemyLevel); //Kills the enemy if (transform.parent != null) { Destroy(transform.parent.gameObject); } else { Destroy(transform.gameObject); } }