/// <summary> /// Checks to see if the specified item should drop to the loot bag based on current rules. /// </summary> /// <param name="item">item to drop</param> /// <returns>true if should drop, false otherwise</returns> protected bool ShouldDrop(CharacterItem item) { if (playerDB.CacheFilterLootItems.Count == 0) { return(true); } if (playerDB.lootBagItemFilterBehavior == LootBagFilterBehavior.Inclusive) { foreach (LootBagFilterItem fi in playerDB.CacheFilterLootItems) { if (item.GetItem().DataId == fi.item.DataId) { if (fi.dropRate >= 1 || Random.value < fi.dropRate) { return(true); } } } } else { bool inFilter = false; foreach (LootBagFilterItem fi in playerDB.CacheFilterLootItems) { if (item.GetItem().DataId == fi.item.DataId) { inFilter = true; break; } } return(!inFilter); } return(false); }
protected virtual void NetFuncSellItem(short index, short amount) { if (IsDead() || index >= nonEquipItems.Count) { return; } if (currentNpcDialog == null || currentNpcDialog.type != NpcDialogType.Shop) { return; } CharacterItem nonEquipItem = nonEquipItems[index]; if (!nonEquipItem.NotEmptySlot() || amount > nonEquipItem.amount) { return; } Item item = nonEquipItem.GetItem(); if (this.DecreaseItemsByIndex(index, amount)) { gameplayRule.IncreaseCurrenciesWhenSellItem(this, item, amount); } }
public bool CanAssignCharacterItem(CharacterItem characterItem) { if (characterItem == null) { return(false); } Item item = characterItem.GetItem(); if (item != null && characterItem.level > 0 && characterItem.amount > 0 && (item.IsPotion() || item.IsBuilding() || item.IsPet())) { return(true); } return(false); }
public void ReduceAmmo(CharacterItem weapon, bool isLeftHand, out Dictionary <DamageElement, MinMaxFloat> increaseDamges) { increaseDamges = null; // Avoid null data if (weapon == null) { return; } Item weaponItem = weapon.GetWeaponItem(); if (weaponItem.ammoCapacity <= 0) { // Ammo capacity is 0 so reduce ammo from inventory Dictionary <CharacterItem, short> decreaseAmmoItems; if (this.DecreaseAmmos(weaponItem.WeaponType.requireAmmoType, 1, out decreaseAmmoItems)) { KeyValuePair <CharacterItem, short> firstEntry = decreaseAmmoItems.FirstOrDefault(); CharacterItem ammoCharacterItem = firstEntry.Key; Item ammoItem = ammoCharacterItem.GetItem(); if (ammoItem != null && firstEntry.Value > 0) { // Ammo level always 1 and its bonus rate always 1 increaseDamges = ammoItem.GetIncreaseDamages(1, 1f); } } } else { // Ammo capacity more than 0 reduce loaded ammo if (weapon.ammo > 0) { weapon.ammo--; EquipWeapons equipWeapons = EquipWeapons; if (isLeftHand) { equipWeapons.leftHand = weapon; } else { equipWeapons.rightHand = weapon; } EquipWeapons = equipWeapons; } } }
public static bool IncreaseItems(IList <CharacterItem> itemList, CharacterItem addingItem) { // If item not valid if (!addingItem.NotEmptySlot()) { return(false); } Item itemData = addingItem.GetItem(); short amount = addingItem.amount; short maxStack = itemData.maxStack; Dictionary <int, CharacterItem> emptySlots = new Dictionary <int, CharacterItem>(); Dictionary <int, CharacterItem> changes = new Dictionary <int, CharacterItem>(); // Loop to all slots to add amount to any slots that item amount not max in stack CharacterItem tempNonEquipItem; for (int i = 0; i < itemList.Count; ++i) { tempNonEquipItem = itemList[i]; if (!tempNonEquipItem.NotEmptySlot()) { // If current entry is not valid, add it to empty list, going to replacing it later emptySlots[i] = tempNonEquipItem; } else if (tempNonEquipItem.dataId == addingItem.dataId) { // If same item id, increase its amount if (tempNonEquipItem.amount + amount <= maxStack) { tempNonEquipItem.amount += amount; changes[i] = tempNonEquipItem; amount = 0; break; } else if (maxStack - tempNonEquipItem.amount >= 0) { amount -= (short)(maxStack - tempNonEquipItem.amount); tempNonEquipItem.amount = maxStack; changes[i] = tempNonEquipItem; } } } // Adding item to new slots or empty slots if needed CharacterItem tempNewItem; if (changes.Count == 0 && emptySlots.Count > 0) { // If there are no changes and there are an empty entries, fill them foreach (int emptySlotIndex in emptySlots.Keys) { tempNewItem = addingItem.Clone(); short addAmount = 0; if (amount - maxStack >= 0) { addAmount = maxStack; amount -= maxStack; } else { addAmount = amount; amount = 0; } tempNewItem.amount = addAmount; changes[emptySlotIndex] = tempNewItem; if (amount == 0) { break; } } } // Apply all changes foreach (KeyValuePair <int, CharacterItem> change in changes) { itemList[change.Key] = change.Value; } // Add new items to new slots while (amount > 0) { tempNewItem = addingItem.Clone(); short addAmount = 0; if (amount - maxStack >= 0) { addAmount = maxStack; amount -= maxStack; } else { addAmount = amount; amount = 0; } tempNewItem.amount = addAmount; itemList.Add(tempNewItem); if (amount == 0) { break; } } return(true); }
public static bool NotEmptySlot(this CharacterItem data) { return(!data.IsEmpty() && data.GetItem() != null && data.amount > 0); }