private void KilledBy(GameObject source) { InventoryNPC myInv = GetComponent <InventoryNPC>(); if (WeaponSlot.transform.childCount > 0) { InvItem weapon = WeaponSlot.transform.GetChild(0).GetComponent <InvItem>(); if (weapon) { myInv.GiveItem(weapon); } } if (ArmorSlot.transform.childCount > 0) { InvItem armor = ArmorSlot.transform.GetChild(0).GetComponent <InvItem>(); if (armor) { myInv.GiveItem(armor); } } LootCrate.SpawnLootcrateOn(transform); Destroy(gameObject); }
new private void Start() { InventoryNPC inv = GetComponent <InventoryNPC>(); inv.WoodGot.AddListener(HandleWoodGot); inv.StoneGot.AddListener(HandleStoneGot); inv.FoodGot.AddListener(HandleFoodGot); inv.GoldGot.AddListener(HandleGoldGot); }
public void HandleNPCInteract(GuildMemberController NPC) { Transform npcTransform = NPC.transform; if ((npcTransform.position - transform.position).sqrMagnitude <= NPCRange) { InventoryNPC npcInv = NPC.GetComponent <InventoryNPC>(); bool isEmpty; int amtCanGive = CheckCanGive(AmtHarvestAtOnce, out isEmpty); npcInv.AddResource(HarvestableType, amtCanGive); AmtResources -= amtCanGive; if (isEmpty) { Destroy(gameObject); } else if (_soundEffect) { _soundEffect.Stop(); _soundEffect.Play(); } } }
void PressedUICancelWithMenuOpen() { // close things depending on where in the menu we are switch (_whichMenuActive) { case MenuType.Main: // close things and give control back to the player _isMenuOpen = false; MainMenu.SetActive(_isMenuOpen); GameManager.Instance.PlayerAvatar.GetComponent <PlayerController>().AcceptsInput = true; break; case MenuType.Name: NewNameMenu.SetActive(false); MainMenu.SetActive(true); _whichMenuActive = MenuType.Main; break; case MenuType.Quest: QuestMenu.SetActive(false); MainMenu.SetActive(true); _whichMenuActive = MenuType.Main; break; case MenuType.GiveQuests: // give the quests back to the player QuestHolder playerQuests = null; GameObject player = NPCsGuild.GuildLeader; if (player) { playerQuests = player.GetComponent <QuestHolder>(); } // get all the quests back out of the wrapper and give them back to the player if (playerQuests) { Transform pQuestParent = playerQuests.QuestsHolder.transform; // Transform thisQuestParent = PlayerQuestsHolder.transform; int test = PlayerQuestsHolder.transform.childCount; while (test > 0) { GameObject pQuestWrapper = PlayerQuestsHolder.transform.GetChild(test - 1).gameObject; pQuestWrapper.GetComponent <PlayerQuestWrapper>().GiveMyQuestTo(player.GetComponent <QuestHolder>()); --test; } } // set menus GiveQuestsMenu.SetActive(false); QuestMenu.SetActive(true); _whichMenuActive = MenuType.Quest; break; case MenuType.Inventory: InventoryNPC inv = GetComponent <InventoryNPC>(); if (inv) { if (inv.GiveItemsMenuUp) // the inv handles this itself { break; } } InventoryMenu.SetActive(false); MainMenu.SetActive(true); _whichMenuActive = MenuType.Main; break; case MenuType.Status: ChangeStatusMenu.SetActive(false); MainMenu.SetActive(true); _whichMenuActive = MenuType.Main; break; case MenuType.Gear: // remove all listeners for (int i = 0; i < NPCItemHolder.transform.GetChild(0).childCount; ++i) { NPCItemHolder.transform.GetChild(0).GetChild(i).GetComponent <InvItem>().PlayerClicked.RemoveAllListeners(); } for (int i = 0; i < PlayerItemHolder.transform.GetChild(0).childCount; ++i) { PlayerItemHolder.transform.GetChild(0).GetChild(i).GetComponent <InvItem>().PlayerClicked.RemoveAllListeners(); } // give back the items NPCItemHolder.transform.GetChild(0).SetParent(_originalNPCItemParent); NPCItemHolder.GetComponent <ScrollRect>().content = null; _originalNPCItemParent.GetComponent <ScrollRect>().content = _originalNPCItemParent.GetChild(0).GetComponent <Image>().rectTransform; _originalNPCItemParent.GetChild(0).localPosition = new Vector3(0, 0, 0); _originalNPCItemParent.GetChild(0).localScale = new Vector3(1, 1, 1); _originalNPCItemParent.GetChild(0).localRotation = new Quaternion(0, 0, 0, 0); GearMenu.SetActive(false); MainMenu.SetActive(true); _whichMenuActive = MenuType.Main; break; case MenuType.EnemyStrategy: EnemyStrategyMenu.SetActive(false); MainMenu.SetActive(true); _whichMenuActive = MenuType.Main; break; case MenuType.PickVillageToDefend: VillageToDefendMenu.SetActive(false); EnemyStrategyMenu.SetActive(true); _whichMenuActive = MenuType.EnemyStrategy; break; } }