public void InteractButton() { if (isSelling && cartItems.Count != 0) { inventoryManager.AddGold(totalAmount); cartItems.ForEach((t) => { inventoryManager.RemoveItem(t); }); npc.PlaySoundEffect(buysellAudioClip); } else if (!isSelling && totalAmount <= inventoryManager.playerGold) { if (inventoryItems.Count + cartItems.Count > inventoryManager.inventorySize) { return; } cartItems.ForEach((t) => { inventoryManager.AddItem(t, t.amount); }); inventoryManager.AddGold(-totalAmount); npc.PlaySoundEffect(buysellAudioClip); } cartItems.Clear(); foreach (var playerInventorySlot in playerInventorySlots) { playerInventorySlot.isItemInCart = false; } UpdateUI(); }
// Destroys the building and reset the Tile ID for the grid space void DestroyBuilding() { Debug.Log("--- Destroying Building at: (" + iTileX.ToString() + ", " + iTileY.ToString() + ")"); // Reset the Tile ID foreach (Vector2 tilePos in av2CoveredTiles) { WorldManager.aiTileIDArray[(int)tilePos.y, (int)tilePos.x] = 0; } // Save the world tileSave.SaveData(); // Remove the building and give the player the value in gold WorldManager.lBuildingList.Remove(this); InventoryManager.AddGold(ResourceTypeData.aResourceTypes[iObjectID].iValue / 2); // Save the new building data buildingSave.SaveData(); Debug.Log("Building Removed"); Debug.Log("Destruction saved"); // Destroy the game object Destroy(this.gameObject); }
public void CompleteQuest(int questID) { for (int i = 0; i < currentQuestList.Count; i++) { if (currentQuestList [i].id == questID && currentQuestList [i].progess == Quest.QuestProgress.COMPLETE) { currentQuestList [i].progess = Quest.QuestProgress.DONE; inventory.AddGold(currentQuestList [i].goldReward); currentQuestList.Remove(currentQuestList [i]); } } }
protected override void WindowFunction(int windowID) { // Window Area Vector2 windowArea = new Vector2(v2Size.x * Screen.width, v2Size.y * Screen.height); GUIStyle style = new GUIStyle(); style.fontSize = 14; style.alignment = TextAnchor.MiddleLeft; style.normal.textColor = Color.white; // If the Close Button is clicked then close the window if (GUI.Button(new Rect(windowArea.x - 30, 5, 20, 20), "X")) { EnableControls(); BuyButtonGUI.bButtonPressed = false; } GUI.Label(new Rect(windowArea.x * 0.2f, windowArea.y * 0.3f, windowArea.x * 0.4f, windowArea.y * 0.15f), "Buy 10 Credits (£7.99)", style); if (GUI.Button(new Rect(windowArea.x * 0.7f, windowArea.y * 0.325f, windowArea.x * 0.1f, windowArea.y * 0.1f), "Buy")) { InventoryManager.AddCredits(10); } GUI.Label(new Rect(windowArea.x * 0.2f, windowArea.y * 0.5f, windowArea.x * 0.4f, windowArea.y * 0.15f), "Buy 1000 Gold (3x Credits)", style); if (GUI.Button(new Rect(windowArea.x * 0.7f, windowArea.y * 0.525f, windowArea.x * 0.1f, windowArea.y * 0.1f), "Buy")) { if (InventoryManager.TakeCredits(3)) { InventoryManager.AddGold(1000); } } GUI.Label(new Rect(windowArea.x * 0.2f, windowArea.y * 0.7f, windowArea.x * 0.4f, windowArea.y * 0.15f), "Buy 10000 Gold: (10x Credits)", style); if (GUI.Button(new Rect(windowArea.x * 0.7f, windowArea.y * 0.725f, windowArea.x * 0.1f, windowArea.y * 0.1f), "Buy")) { if (InventoryManager.TakeCredits(10)) { InventoryManager.AddGold(10000); } } }
// Check Quest Progress void CheckQuestProgress() { // If there are active quests if (liActiveQuests.Count > 0) { print(liActiveQuests.Count); // Loop through each quest for (int i = 0; i < liActiveQuests.Count; i++) { QuestProgressData currentQuest = aQuestProgress[liActiveQuests[i]]; // Number of complete conditions int conditionsComplete = 0; // Loop through each condition for (int j = 0; j < currentQuest.abConditionsComplete.Length; j++) { // If the condition is complete then increment conditionsComplete if (currentQuest.abConditionsComplete[j]) { conditionsComplete++; } } // If the number of complete conditions matches the number of conditions // then set the quest to complete and remove it from the active quests list if (conditionsComplete == QuestTypeData.aQuests[currentQuest.iID].iNoOfConditions) { aQuestProgress[liActiveQuests[i]].bQuestComplete = true; InventoryManager.AddGold(QuestTypeData.aQuests[currentQuest.iID].iGoldReward); LevelManager.iAddXP(QuestTypeData.aQuests[currentQuest.iID].iXPReward); liActiveQuests.RemoveAt(i); QuestCompleteWindow.iQuestID = liActiveQuests[i]; QuestCompleteWindow.bWindowActive = true; questSave.SaveData(); } } } }
// Level Up void LevelUp() { // Advance the level iLevel++; InventoryManager.AddGold(XPLevelData.aiGoldRewards[iLevel]); InventoryManager.AddCredits(XPLevelData.aiCreditRewards[iLevel]); LevelUpWindow.bWindowActive = true; WindowGUI.DisableControls(); levelSave.SaveData(); // Checks if muted if (SoundManager.bMute == false) { // Plays sound clip audio.volume = SoundManager.fVolume; audio.clip = levelUpSound; audio.Play(); } }
// Window Function protected override void WindowFunction(int windowID) { // Window Area Vector2 windowArea = new Vector2(v2Size.x * Screen.width, v2Size.y * Screen.height); // Area of the window used for the Scroll View Rect scrollArea = new Rect(windowArea.x * 0.05f, windowArea.y * 0.25f, windowArea.x * 0.85f, windowArea.y * 0.70f); // Scrollable Area Rect scrollViewArea = new Rect(0, 0, scrollArea.width - 100, scrollArea.height * 3.5f); // Label GUI Style GUIStyle style = GUI.skin.GetStyle("Label"); style.alignment = TextAnchor.MiddleCenter; // If the Close Button is clicked then close the window if (GUI.Button(new Rect(windowArea.x - 30, 5, 20, 20), "X")) { EnableControls(); InventoryButtonGUI.bButtonPressed = false; } // Create the Scroll View and Update the Scroll Bar Position v2ScrollPosition = GUI.BeginScrollView(scrollArea, v2ScrollPosition, scrollViewArea, false, true); // Space out and display each resource for (int i = 0; i < ResourceTypeData.iNoOfTypes; i++) { // Grid Position int positionX = (i % 3) * (int)windowArea.x / 3; int positionY = (i / 3) * 200; // Draw the Resource Icon GUI.DrawTexture(new Rect(positionX + 30, positionY + 50, 80, 80), resourceIcons[i]); // Draw the Resource Name GUI.Label(new Rect(positionX + 15, positionY + 130, 120, 25), ResourceTypeData.aResourceTypes[i].sName + " - " + InventoryManager.GetResource(i).ToString(), style); // Draws Sell Button on the inventory if (GUI.Button(new Rect(positionX, positionY + 160, 140, 30), "Sell" + " - " + ResourceTypeData.aResourceTypes[i].iValue * aiSellAmount[i])) { // Takes resources with amount specified and sell amount by value of resource InventoryManager.TakeResource(i, aiSellAmount[i]); InventoryManager.AddGold(aiSellAmount[i] * ResourceTypeData.aResourceTypes[i].iValue); aiSellAmount[i] = 0; // Checks if muted if (SoundManager.bMute == false) { // Plays sound clip audio.volume = SoundManager.fVolume; audio.clip = SellButtonSound; audio.Play(); } } // Draws box that displays aiCraftAmount GUI.Box(new Rect(positionX + 40, positionY + 195, 60, 25), aiSellAmount[i].ToString()); // Draws - button if (GUI.Button(new Rect(positionX, positionY + 195, 35, 25), "-")) { // Checks amount in aiSellAmount in inventory to stay on 0 and above if (aiSellAmount[i] > 0) { aiSellAmount[i]--; } } // Draws + button if (GUI.Button(new Rect(positionX + 105, positionY + 195, 35, 25), "+")) { // Checks amount in aiSellAmount to max in inventory if (aiSellAmount[i] < InventoryManager.GetResource(i)) { aiSellAmount[i]++; } } } GUI.EndScrollView(); }