/// <inheritdoc /> public void OnKilled(ILivingEntity killerEntity) { _monster.Timers.DespawnTime = Time.TimeInSeconds() + 5; // TODO: Configure this timer on world configuration // Drop items int itemCount = 0; foreach (DropItemData dropItem in _monster.Data.DropItems) { if (itemCount >= _monster.Data.MaxDropItem) { break; } long dropChance = RandomHelper.LongRandom(0, DropSystem.MaxDropChance); if (dropItem.Probability * _worldConfiguration.Rates.Drop >= dropChance) { var item = new Item(dropItem.ItemId, 1, -1, -1, -1, (byte)RandomHelper.Random(0, dropItem.ItemMaxRefine)); _dropSystem.DropItem(_monster, item, killerEntity); itemCount++; } } // Drop item kinds foreach (DropItemKindData dropItemKind in _monster.Data.DropItemsKind) { var itemsDataByItemKind = _gameResources.Items.Values.Where(x => x.ItemKind3 == dropItemKind.ItemKind && x.Rare >= dropItemKind.UniqueMin && x.Rare <= dropItemKind.UniqueMax); if (!itemsDataByItemKind.Any()) { continue; } var itemData = itemsDataByItemKind.ElementAt(RandomHelper.Random(0, itemsDataByItemKind.Count() - 1)); int itemRefine = RandomHelper.Random(0, 10); for (int i = itemRefine; i >= 0; i--) { long itemDropProbability = (long)(_gameResources.ExpTables.GetDropLuck(itemData.Level > 120 ? 119 : itemData.Level, itemRefine) * (_monster.Data.CorrectionValue / 100f)); long dropChance = RandomHelper.LongRandom(0, DropSystem.MaxDropChance); if (dropChance < itemDropProbability * _worldConfiguration.Rates.Drop) { var item = new Item(itemData.Id, 1, -1, -1, -1, (byte)itemRefine); _dropSystem.DropItem(_monster, item, killerEntity); break; } } } // Drop gold int goldDropped = RandomHelper.Random(_monster.Data.DropGoldMin, _monster.Data.DropGoldMax); _dropSystem.DropGold(_monster, goldDropped, killerEntity); }
/// <inhertidoc /> public void DropItem(IPlayerEntity player, int itemUniqueId, int quantity) { Item itemToDrop = player.Inventory.GetItemAtIndex(itemUniqueId); if (itemToDrop == null) { throw new ArgumentNullException(nameof(itemToDrop), $"Cannot find item with unique id: '{itemUniqueId}' in {player.Object.Name} inventory."); } if (itemToDrop.Slot >= EquipOffset) { throw new InvalidOperationException($"Cannot drop an equiped item."); } int quantityToDrop = Math.Min(quantity, itemToDrop.Quantity); if (quantityToDrop <= 0) { throw new InvalidOperationException("Cannot drop a zero or negative quantit."); } _dropSystem.DropItem(player, itemToDrop, owner: null, quantity: quantityToDrop); DeleteItem(player, itemUniqueId, quantityToDrop); }