public void Spawn_Item(ItemName item_name, Vector3 position) { #if TESTING_WHATAMISPAWNING Debug.Log("Spawning a " + item_name.ToString()); #endif ItemClass instance = new ItemClass(); switch ((int)item_name) { case (int)ItemName.Health_Potion: { instance.GenerateInstance(ItemName.Health_Potion); this.m_SpriteToBeUsed = this.m_HealthPotionSprite; break; } case (int)ItemName.Mana_Potion: { instance.GenerateInstance(ItemName.Mana_Potion); this.m_SpriteToBeUsed = this.m_ManaPotionSprite; break; } default: { //impossible break; } } //end switch GameObject obj = GameObject.Instantiate(this.m_DefaultItemPickupPrefab); obj.GetComponent <ItemPickup> ().SetItem(instance); //Set the sprite obj.transform.GetComponentInChildren <SpriteRenderer> ().sprite = this.m_SpriteToBeUsed; obj.transform.position = position; }
private QuestGiver GenerateQuestGiver(Vector3 position, ItemName[] itemRewards, SpellName[] spellRewards) { QuestGiver qg = Instantiate(m_QuestGiver_Generic).GetComponent <QuestGiver>(); qg.m_QuestManager = this; qg.m_PlayerInventory = this.m_Player.GetComponent <PlayerInventory>(); qg.transform.position = position; if (itemRewards != null) { foreach (ItemName reward in itemRewards) { ItemClass thisReward = new ItemClass(); thisReward.GenerateInstance(reward); qg.m_RewardItem = thisReward; } } if (spellRewards != null) { foreach (var reward in spellRewards) { SpellClass thisReward = new SpellClass(); thisReward = thisReward.GenerateInstance(reward); print(reward); print(thisReward.ReturnSpellInstanceInfo()); qg.m_RewardSpell = thisReward; } } return(qg); }
void Start() { SpellClass spell_class_instance = new SpellClass(); #if START_WITH_FIREBALL this.AddSpell(spell_class_instance.GenerateInstance(SpellName.Fireball)); this.AssignDefaultActiveSpell(); #endif #if START_WITH_ICEBALL this.AddSpell(spell_class_instance.GenerateInstance(SpellName.Iceball)); this.AssignDefaultActiveSpell(); #endif #if START_WITH_SHIELD this.AddSpell(spell_class_instance.GenerateInstance(SpellName.Shield)); this.AssignDefaultActiveSpell(); #endif #if START_WITH_THUNDERBALL this.AddSpell(spell_class_instance.GenerateInstance(SpellName.Thunderball)); this.AssignDefaultActiveSpell(); #endif #if START_WITH_THUNDERSTORM this.AddSpell(spell_class_instance.GenerateInstance(SpellName.Thunderstorm)); this.AssignDefaultActiveSpell(); #endif #if START_WITH_HEAL this.AddSpell(spell_class_instance.GenerateInstance(SpellName.Heal)); this.AssignDefaultActiveSpell(); #endif #if START_WITH_TORNADO this.AddSpell(spell_class_instance.GenerateInstance(SpellName.Tornado)); this.AssignDefaultActiveSpell(); #endif #if START_WITH_WATERBUBBLE this.AddSpell(spell_class_instance.GenerateInstance(SpellName.WaterBubble)); this.AssignDefaultActiveSpell(); #endif #if START_WITH_HEALTH_POTION ItemClass health_potion = new ItemClass(); health_potion.GenerateInstance(ItemName.Health_Potion); this.AddItem(health_potion); #endif #if START_WITH_MANA_POTION ItemClass mana_potion = new ItemClass(); mana_potion.GenerateInstance(ItemName.Mana_Potion); this.AddItem(mana_potion); #endif //In case we're loading in the scene if (this.m_ActiveSpellClass != null) { this.m_ActiveSpellIcon.UpdateActiveSpellSprite(this.m_ActiveSpellClass.m_SpellName); } else { this.m_ActiveSpellIcon.gameObject.transform.parent.gameObject.SetActive(false); } } //end f'n void Start()
/**A function to load in our list of hotkeyed items, and the proper quantities. * Assumes the player inventory has been reset by now.*/ public void SetCurrentHotkeyedItems(GameObject player) { PlayerInventory player_inventory = player.GetComponent <PlayerInventory> (); string message = "Load start"; if (player_inventory.m_ItemDictionary.Count > 0) { //for each hotkey for (int hotkey_index = 0; hotkey_index < this.m_HotkeyedItems.Count; hotkey_index++) { //if the hotkey contains an item... if (-1 < this.m_HotkeyedItems [hotkey_index]) { ItemClass item = new ItemClass(); foreach (ItemName item_name_enum in System.Enum.GetValues(typeof(ItemName))) { //...if there's an item that has the same name int value as the one we want in our hotkey... if ((int)item_name_enum == this.m_HotkeyedItems [hotkey_index]) { item.GenerateInstance(item_name_enum); } } //end foreach int item_quantity = 0; for (int item_index = 0; item_index < this.m_ItemNames.Count; item_index++) { if (this.m_ItemNames [item_index] == item.m_ItemName.ToString()) { item_quantity = this.m_ItemQuantities [item_index]; break; } } //end for UnityEngine.UI.Button button = player_inventory.m_HotKeyList [hotkey_index]; HotKeys hotkey = button.GetComponentInChildren <HotKeys> (); hotkey.setHotKeys(item, item_quantity); message += "Set item " + item.m_ItemName.ToString() + " to hotkey " + hotkey_index + " with quantity " + item_quantity; } } } // Debug.Log(message); }
} //end f'n void ParseItemDictionary(Dictionary<Item, int>) /**A function to set the contents of the player inventory item dictionary. * Clears player item dictionary before adding anything.*/ public void SetItemDictionary(GameObject player) { PlayerInventory player_inventory = player.GetComponent <PlayerInventory> (); for (int index = 0; index < this.m_ItemNames.Count; index++) { ItemClass item_to_add = new ItemClass(); //for every item name... foreach (ItemName name in System.Enum.GetValues(typeof(ItemName))) { //...if the name in the enum matches that of the list... if (this.m_ItemNames [index] == name.ToString()) { //...then create the item and add it with its respective quantity item_to_add.GenerateInstance(name); player_inventory.m_ItemDictionary.Add(item_to_add, this.m_ItemQuantities [index]); } //end if } //end foreach } //end for } //end f'n void SetItemDictionary(GameObject)