public GameObject CreateRandomPoolItem() { GameObject item = GameObject.Instantiate(prefabs[Random.Range(0, prefabs.Count)], poolParent); item.AddComponent <PoolChild>().Pool = this; item.SetActive(false); ItemPool.Add(item); return(item); }
/// <summary> /// will fill the item pool with default /// </summary> /// <returns></returns> public bool fillItemPool() { ItemModel temp = new ItemModel(); List <ItemModel> item = Services.DefaultData.LoadData(temp); foreach (ItemModel i in item) { ItemPool.Add(i); } return(true); }
/// <summary> /// Monster experience a critical miss. /// Since monsters don't equip items, critical miss is slightly different than characters. /// After rolling a critical miss. Roll a 10 sided dice. The following things can happen. /// Roll Value /// 1-6, Monster drops an item from one of its pockets. /// If it has no items in any pockets, it drops a random item. /// The dropped item is added to the item pool. /// 7-10, Nothing bad happens, luck was with the attacker /// </summary> /// <param name="monster"></param> /// <returns></returns> public bool MonsterCriticalMiss(MonsterModel monster) { // roll dice to determine event var d10 = DiceHelper.RollDice(1, 10); // Drop an item if (d10 <= 6) { // randomly check a monster's item pocket var d3 = DiceHelper.RollDice(1, 3); if (d3 == 1) { var item = ItemIndexViewModel.Instance.GetItem(monster.ItemPocket1); monster.ItemPocket1 = string.Empty; if (item == null) { item = ItemIndexViewModel.Instance.GetRandomItem(); } ItemPool.Add(item); BattleMessages.CriticalMissMessage = "Critical miss! " + monster.Name + " dropped " + item.Name + " in item pool!"; } if (d3 == 2) { var item = ItemIndexViewModel.Instance.GetItem(monster.ItemPocket2); monster.ItemPocket2 = string.Empty; if (item == null) { item = ItemIndexViewModel.Instance.GetRandomItem(); } ItemPool.Add(item); BattleMessages.CriticalMissMessage = "Critical miss! " + monster.Name + " dropped " + item.Name + " in item pool!"; } if (d3 == 3) { var item = ItemIndexViewModel.Instance.GetItem(monster.ItemPocket3); monster.ItemPocket3 = string.Empty; if (item == null) { item = ItemIndexViewModel.Instance.GetRandomItem(); } ItemPool.Add(item); BattleMessages.CriticalMissMessage = "Critical miss! " + monster.Name + " dropped " + item.Name + " in item pool!"; } } return(true); }
private async Task <T> FindOrCreateLoader() { T firstFound; switch (BalancingMethod) { case BalancingMethods.Random: if (_loadingRandom == null) { _loadingRandom = new Random(); } CurrentIndex = _loadingRandom.Next(0, ItemPool.Count()); break; case BalancingMethods.MaxCount: int maxedCount = 0; for (var i = 0; i < ItemPool.Count(); i++) { var openItem = ItemPool.ElementAt(i); if (openItem.ActiveCount >= openItem.MaxCount) { maxedCount++; } else { CurrentIndex = i; break; } } if (maxedCount == ItemPool.Count()) { var newItem = new T(); ItemPool.Add(newItem); CurrentIndex = ItemPool.Count() - 1; } break; default: if (CurrentIndex >= ItemPool.Count()) { CurrentIndex = 0; } break; } firstFound = ItemPool.ElementAt(CurrentIndex); CurrentIndex++; return(await Task.FromResult(firstFound)); }
/// <summary> /// Adds an item to the item pool. /// </summary> /// <param name="item">Item to add.</param> public static void AddItem(Item item) { if (item == null) { return; } Item _item = LookUpItem(item.ID); if (_item != null) { return; } ItemPool.Add(item); AssignCorrectIDS(); }
/// <summary> /// Monster Drop Item /// </summary> /// <param name="Target"></param> /// <returns></returns> public int MonsterDropItem(EntityInfoModel Target) { // Monster will only drop unique Item // The unique item will drop based on droprate var DroppedMessage = "\nItems Dropped : \n"; if (string.IsNullOrEmpty(Target.UniqueItemId)) { var data = GetRandomMonsterItemDrops(); BattleScore.ItemsDroppedList += data.FormatOutput() + "\n"; DroppedMessage += data.Name + "\n"; ItemPool.Add(data); BattleMessageModel.DroppedMessage = DroppedMessage; BattleScore.ItemModelDropList.Add(data); return(1); } if (!IsUniqueDrop(Target)) { DroppedMessage = " Nothing dropped. "; BattleMessageModel.DroppedMessage = DroppedMessage; return(0); } var ItemModel = ItemIndexViewModel.Instance.GetItem(Target.UniqueItemId); BattleScore.ItemsDroppedList += ItemModel.FormatOutput() + "\n"; DroppedMessage += ItemModel.Name + "\n"; ItemPool.Add(ItemModel); BattleMessageModel.DroppedMessage = DroppedMessage; BattleScore.ItemModelDropList.Add(ItemModel); return(1); }
/// <summary> /// Swap the Item the character has for one from the pool /// /// Drop the current item back into the Pool /// /// </summary> /// <param name="character"></param> /// <param name="setLocation"></param> /// <param name="PoolItem"></param> /// <returns></returns> public ItemModel SwapCharacterItem(PlayerInfoModel character, ItemLocationEnum setLocation, ItemModel PoolItem) { // Put on the new ItemModel, which drops the one back to the pool var droppedItem = character.AddItem(setLocation, PoolItem.Id); // Add the PoolItem to the list of selected items BattleScore.ItemModelSelectList.Add(PoolItem); // Remove the ItemModel just put on from the pool ItemPool.Remove(PoolItem); if (droppedItem != null) { // Add the dropped ItemModel to the pool ItemPool.Add(droppedItem); } return(droppedItem); }
/// <summary> /// Swap the Item the character has for one from the pool /// /// Drop the current item back into the Pool /// /// </summary> /// <param name="character"></param> /// <param name="setLocation"></param> /// <param name="PoolItem"></param> /// <returns></returns> private ItemModel SwapCharacterItem(CharacterModel character, ItemLocationEnum setLocation, ItemModel PoolItem) { // Put on the new ItemModel, which drops the one back to the pool var droppedItem = character.AddItem(setLocation, PoolItem); // Update BattleMessage BattleMessages.AddItemEquipped(character.Name, PoolItem.Name); // Remove the ItemModel just put on from the pool ItemPool.Remove(PoolItem); if (droppedItem != null) { // Add the dropped ItemModel to the pool ItemPool.Add(droppedItem); } return(droppedItem); }
// Replaces an item assigned to character if there is a better item avaliable. public void GetItemFromPoolIfBetter(Character character, ItemLocationEnum setLocation) { // Get the highest value item by location var myList = ItemPool.Where(a => a.Location == setLocation) .OrderByDescending(a => a.Value) .ToList(); // If no items in the list, return... if (!myList.Any()) { return; } // Get the item that is on the character in that location var currentItem = character.GetItemByLocation(setLocation); // If no item in that location, add the item if (currentItem == null) { // If no item in the slot then put on the first in the list character.AddItem(setLocation, myList.FirstOrDefault().Id); return; } foreach (var item in myList) { if (item.Value > currentItem.Value) { // Put on the new item, which drops the one back to the pool var droppedItem = character.AddItem(setLocation, item.Id); // Remove the item just put on from the pool ItemPool.Remove(item); // Add the item to the pool if there is one if (droppedItem != null) { // Add the dropped item to the pool ItemPool.Add(droppedItem); } } } }
/// <summary> /// Swap out the item if it is better /// /// Uses Value to determine /// </summary> /// <param name="character"></param> /// <param name="setLocation"></param> public bool GetItemFromPoolIfBetter(PlayerInfoModel character, ItemLocationEnum setLocation) { var myList = ItemPool.Where(a => a.Location == setLocation) .OrderByDescending(a => a.Value) .ToList(); // If no items in the list, return... if (!myList.Any()) { return(false); } var CharacterItem = character.GetItemByLocation(setLocation); if (CharacterItem == null) { // If no ItemModel in the slot then put on the first in the list character.AddItem(setLocation, myList.FirstOrDefault().Id); return(true); } foreach (var PoolItem in myList) { if (PoolItem.Value > CharacterItem.Value) { // Put on the new ItemModel, which drops the one back to the pool var droppedItem = character.AddItem(setLocation, PoolItem.Id); // Remove the ItemModel just put on from the pool ItemPool.Remove(PoolItem); if (droppedItem != null) { // Add the dropped ItemModel to the pool ItemPool.Add(droppedItem); } } } return(true); }
/// <summary> /// Character experience a critical miss. /// After rolling a critical miss. Roll a 10 sided dice. The following things can happen. /// Roll Value /// 1, Primary Hand Item breaks, and is lost forever /// 2-4, Character Drops the Primary Hand Item back into the item pool /// 5-6, Character drops a random equipped item back into the item pool /// 7-10, Nothing bad happens, luck was with the attacker /// </summary> /// <param name="character"></param> /// <returns></returns> public bool CharacterCriticalMiss(CharacterModel character) { // roll dice to determine event var d10 = DiceHelper.RollDice(1, 10); // Primary Hand Item breaks if (d10 == 1) { character.RemoveItem(ItemLocationEnum.PrimaryHand); BattleMessages.CriticalMissMessage = "Critical miss! Item in primary hand broke!"; return(true); } // Character Drops the Primary Hand Item back into the item pool if (d10 >= 2 && d10 <= 4) { var item = character.RemoveItem(ItemLocationEnum.PrimaryHand); if (item != null) { BattleMessages.CriticalMissMessage = "Critical miss! " + character.Name + " dropped " + item.Name + " in item pool!"; ItemPool.Add(item); return(true); } } // Character drops a random equipped item back into the item pool if (d10 >= 5 && d10 <= 6) { // check where character has items equipped var equipped = new List <ItemLocationEnum>(); var item = character.GetItemByLocation(ItemLocationEnum.Head); if (item != null) { equipped.Add(ItemLocationEnum.Head); } item = character.GetItemByLocation(ItemLocationEnum.Necklass); if (item != null) { equipped.Add(ItemLocationEnum.Necklass); } item = character.GetItemByLocation(ItemLocationEnum.Feet); if (item != null) { equipped.Add(ItemLocationEnum.Feet); } item = character.GetItemByLocation(ItemLocationEnum.PrimaryHand); if (item != null) { equipped.Add(ItemLocationEnum.PrimaryHand); } item = character.GetItemByLocation(ItemLocationEnum.OffHand); if (item != null) { equipped.Add(ItemLocationEnum.OffHand); } item = character.GetItemByLocation(ItemLocationEnum.RightFinger); if (item != null) { equipped.Add(ItemLocationEnum.RightFinger); } item = character.GetItemByLocation(ItemLocationEnum.LeftFinger); if (item != null) { equipped.Add(ItemLocationEnum.LeftFinger); } // no items equipped if (equipped.Count() <= 0) { return(true); } var unequip = DiceHelper.RollDice(1, equipped.Count()) - 1; // check that dice roll was valid (in case forced rolls are being used) if (unequip < 0 || unequip >= equipped.Count()) { return(false); // did not remove an item } item = character.RemoveItem(equipped.ElementAt(unequip)); ItemPool.Add(item); BattleMessages.CriticalMissMessage = "Critical miss! " + character.Name + " dropped " + item.Name + " in item pool!"; } return(true); }