public static async Task MoveItem(this InventoryComponent inv, ItemInstanceDto source, InventoryMoveEvent args) { ItemInstanceDto[] subInv = inv.GetSubInvFromItemInstance(source); subInv[args.DestinationSlot] = source; subInv[args.SourceSlot] = null; source.Slot = args.DestinationSlot; if (!(inv.Entity is IPlayerEntity player)) { return; } await player.SendPacketAsync(player.GenerateEmptyIvnPacket(args.InventoryType, args.SourceSlot)); await player.SendPacketAsync(source.GenerateIvnPacket()); }
public static async Task MoveItems(this InventoryComponent inv, ItemInstanceDto source, ItemInstanceDto dest) { ItemInstanceDto[] subInv = inv.GetSubInvFromItemInstance(source); subInv[dest.Slot] = source; subInv[source.Slot] = dest; short tmp = dest.Slot; dest.Slot = source.Slot; source.Slot = tmp; if (!(inv.Entity is IPlayerEntity player)) { return; } await player.SendPacketAsync(source.GenerateIvnPacket()); await player.SendPacketAsync(dest.GenerateIvnPacket()); }
private async Task EquipItem(InventoryComponent inventory, IInventoriedEntity entity, ItemInstanceDto itemToEquip) { // check if slot already claimed ItemInstanceDto alreadyEquipped = inventory.GetWeared(itemToEquip.Item.EquipmentSlot); var player = entity as IPlayerEntity; if (alreadyEquipped != null) { // todo refacto to "MoveSlot" method inventory.Equipment[itemToEquip.Slot] = alreadyEquipped; alreadyEquipped.Slot = itemToEquip.Slot; alreadyEquipped.Type = InventoryType.Equipment; } else { inventory.Equipment[itemToEquip.Slot] = null; } if (!(player is null)) { await player.SendPacketAsync(player.GenerateEmptyIvnPacket(itemToEquip.Type, itemToEquip.Slot)); } inventory.Wear[(int)itemToEquip.Item.EquipmentSlot] = itemToEquip; itemToEquip.Slot = (short)itemToEquip.Item.EquipmentSlot; itemToEquip.Type = InventoryType.Wear; if (alreadyEquipped == null) { return; } if (!(player is null)) { await player?.SendPacketAsync(alreadyEquipped.GenerateIvnPacket()); } }
protected override async Task Handle(RarifyEvent e, CancellationToken cancellation) { if (!(e.Sender is IPlayerEntity player)) { return; } double rnd; double[] rare = { _configuration.RarifyChances.Raren2, _configuration.RarifyChances.Raren1, _configuration.RarifyChances.Rare0, _configuration.RarifyChances.Rare1, _configuration.RarifyChances.Rare2, _configuration.RarifyChances.Rare3, _configuration.RarifyChances.Rare4, _configuration.RarifyChances.Rare5, _configuration.RarifyChances.Rare6, _configuration.RarifyChances.Rare7, _configuration.RarifyChances.Rare8 }; sbyte[] rareitem = { -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8 }; if (e.Mode != RarifyMode.Drop || e.Item.Item.ItemType == ItemType.Shell) { rare[0] = 0; rare[1] = 0; rare[2] = 0; rnd = _randomGenerator.Next(0, 80); } else { rnd = _randomGenerator.Next(0, 1000) / 10D; } if (e.Protection == RarifyProtection.RedAmulet || e.Protection == RarifyProtection.HeroicAmulet || e.Protection == RarifyProtection.RandomHeroicAmulet) { for (byte i = 0; i < rare.Length; i++) { rare[i] = (byte)(rare[i] * _configuration.RarifyChances.ReducedChanceFactor); } } ItemInstanceDto amulet = player.Inventory.GetWeared(EquipmentType.Amulet); switch (e.Mode) { case RarifyMode.Free: break; case RarifyMode.Reduce: if (amulet == null) { return; } if (e.Item.Rarity < 8 || !e.Item.Item.IsHeroic) { await player.SendChatMessageAsync("NOT_MAX_RARITY", SayColorType.Yellow); return; } e.Item.Rarity -= (sbyte)_randomGenerator.Next(0, 7); e.Item.SetRarityPoint(); e.Item.GenerateHeroicShell(e.Protection); // session.Character.DeleteItemByItemInstanceId(amulet.Id); // await session.SendPacketAsync(session.Character.GenerateEquipment()); await player.SendPacketAsync(player.GenerateInfoBubble("AMULET_DESTROYED")); await player.NotifyRarifyResult(e.Item.Rarity); await player.SendPacketAsync(e.Item?.GenerateIvnPacket()); return; case RarifyMode.Success: if (e.Item.Item.IsHeroic && e.Item.Rarity >= 8 || !e.Item.Item.IsHeroic && e.Item.Rarity <= 7) { await player.SendChatMessageAsync("ALREADY_MAX_RARE", SayColorType.Yellow); return; } e.Item.Rarity += 1; e.Item.SetRarityPoint(); if (e.Item.Item.IsHeroic) { e.Item.GenerateHeroicShell(RarifyProtection.RandomHeroicAmulet); } ItemInstanceDto inventory = e.Item; if (inventory != null) { await player.SendPacketAsync(e.Item?.GenerateIvnPacket()); } return; case RarifyMode.Normal: // TODO: Normal Item Amount if (player.Character.Gold < _configuration.RarifyChances.GoldPrice) { return; } if (player.Inventory.GetItemQuantityById(_configuration.RarifyChances.RarifyItemNeededVnum) < _configuration.RarifyChances.RarifyItemNeededQuantity) { // not enough quantity ! return; } if (e.Protection == RarifyProtection.Scroll && !e.IsCommand && !player.Inventory.HasItem(_configuration.RarifyChances.ScrollVnum)) { return; } if ((e.Protection == RarifyProtection.Scroll || e.Protection == RarifyProtection.BlueAmulet || e.Protection == RarifyProtection.RedAmulet) && !e.IsCommand && e.Item.Item.IsHeroic) { await player.SendTopscreenMessage("ITEM_IS_HEROIC", MsgPacketType.Whisper); return; } if ((e.Protection == RarifyProtection.HeroicAmulet || e.Protection == RarifyProtection.RandomHeroicAmulet) && !e.Item.Item.IsHeroic) { await player.SendTopscreenMessage("ITEM_NOT_HEROIC", MsgPacketType.Whisper); return; } if (e.Item.Item.IsHeroic && e.Item.Rarity == 8) { await player.SendTopscreenMessage("ALREADY_MAX_RARE", MsgPacketType.Whisper); return; } if (e.Protection == RarifyProtection.Scroll && !e.IsCommand) { // remove item ScrollVnum await player.SendPacketAsync(player.GenerateShopEndPacket(player.Inventory.HasItem(_configuration.RarifyChances.ScrollVnum) ? ShopEndPacketType.CloseSubWindow : ShopEndPacketType.CloseWindow)); } await player.GoldLess(_configuration.RarifyChances.GoldPrice); /*session.Character.Inventory.RemoveItemAmount(cellaVnum, cella);*/ break; case RarifyMode.Drop: break; default: return; } if (e.Item.Item.IsHeroic && e.Protection != RarifyProtection.None) { if (rnd < rare[10]) { if (e.Mode != RarifyMode.Drop) { await player.NotifyRarifyResult(8); } e.Item.Rarity = 8; ItemInstanceDto inventory = e.Item; if (inventory != null) { await player.SendPacketAsync(inventory.GenerateIvnPacket()); } e.Item.GenerateHeroicShell(e.Protection); e.Item.SetRarityPoint(); return; } } bool sayfail = false; for (byte y = 9; y != 0; y--) { if (!(rnd < rare[y]) || e.Protection == RarifyProtection.Scroll && e.Item.Rarity >= rareitem[y]) { continue; } await e.RarifyAsync(player, rareitem[y]); sayfail = true; break; } if (!sayfail) { await e.FailAsync(player); } if (e.Mode == RarifyMode.Drop) { return; } ItemInstanceDto inventoryb = e.Item; if (inventoryb != null) { await player.SendPacketAsync(inventoryb.GenerateIvnPacket()); } }
protected override async Task Handle(UpgradeSpecialistEvent e, CancellationToken cancellation) { if (!(e.Sender is IPlayerEntity player)) { return; } if (player.Inventory.GetItemQuantityById(_configuration.UpgradeSp.FullmoonVnum) < _configuration.UpgradeSp.FullMoon[e.Item.Upgrade]) { await player.SendChatMessageAsync("NOT_ENOUGH_ITEMS", SayColorType.Yellow); return; } if (player.Inventory.GetItemQuantityById(_configuration.UpgradeSp.FeatherVnum) < _configuration.UpgradeSp.Feather[e.Item.Upgrade]) { await player.SendChatMessageAsync("NOT_ENOUGH_ITEMS", SayColorType.Yellow); return; } if (player.Character.Gold < _configuration.UpgradeSp.GoldPrice[e.Item.Upgrade]) { await player.SendChatMessageAsync("NOT_ENOUGH_MONEY", SayColorType.Yellow); return; } if (e.Item.Upgrade < 5 ? e.Item.Level < 20 : e.Item.Upgrade < 10 ? e.Item.Level < 40 : e.Item.Level < 50) { await player.SendChatMessageAsync("LVL_REQUIRED", SayColorType.Purple); return; } if (player.Inventory.GetItemQuantityById(e.Item.Upgrade < 5 ? (e.Item.Item.Morph <= 16 ? _configuration.UpgradeSp.GreenSoulVnum : _configuration.UpgradeSp.DragonSkinVnum) : e.Item.Upgrade < 10 ? (e.Item.Item.Morph <= 16 ? _configuration.UpgradeSp.RedScrollVnum : _configuration.UpgradeSp.DragonBloodVnum) : (e.Item.Item.Morph <= 16 ? _configuration.UpgradeSp.BlueSoulVnum : _configuration.UpgradeSp.DragonHeartVnum)) < _configuration.UpgradeSp.Soul[e.Item.Upgrade]) { await player.SendChatMessageAsync("NOT_ENOUGH_ITEMS", SayColorType.Yellow); return; } if (e.Protection == UpgradeProtection.Protected) { if (player.Inventory.GetItemQuantityById(e.Item.Upgrade < 15 ? _configuration.UpgradeSp.BlueScrollVnum : _configuration.UpgradeSp.RedScrollVnum) < 1) { await player.SendChatMessageAsync("NOT_ENOUGH_ITEMS", SayColorType.Yellow); return; } // remove Item Blue/red scroll x 1 await player.SendPacketAsync(player.GenerateShopEndPacket(player.Inventory.HasItem(e.Item.Upgrade < 15 ? _configuration.UpgradeSp.BlueScrollVnum : _configuration.UpgradeSp.RedScrollVnum) ? ShopEndPacketType.CloseSubWindow : ShopEndPacketType.CloseWindow)); } await player.GoldLess(_configuration.UpgradeSp.GoldPrice[e.Item.Upgrade]); //CharacterSession.Character.Inventory.RemoveItemAmount(featherVnum, feather[Upgrade]); //CharacterSession.Character.Inventory.RemoveItemAmount(fullmoonVnum, fullmoon[Upgrade]); ItemInstanceDto wearable = e.Item; double rnd = _random.Next(); if (rnd < _configuration.UpgradeSp.Destroy[e.Item.Upgrade]) { if (e.Protection == UpgradeProtection.Protected) { await player.SendPacketAsync(player.GenerateEffectPacket(3004)); await player.SendChatMessageAsync("UPGRADESP_FAILED_SAVED", SayColorType.Purple); await player.SendTopscreenMessage("UPGRADESP_FAILED_SAVED", MsgPacketType.Whisper); } else { wearable.Rarity = -2; await player.SendChatMessageAsync("UPGRADESP_DESTROYED", SayColorType.Purple); await player.SendTopscreenMessage("UPGRADESP_DESTROYED", MsgPacketType.Whisper); await player.SendPacketAsync(wearable.GenerateIvnPacket()); } } else if (rnd < _configuration.UpgradeSp.UpFail[e.Item.Upgrade]) { if (e.Protection == UpgradeProtection.Protected) { await player.SendPacketAsync(player.GenerateEffectPacket(3004)); } await player.SendChatMessageAsync("UPGRADESP_FAILED", SayColorType.Purple); await player.SendTopscreenMessage("UPGRADESP_FAILED", MsgPacketType.Whisper); } else { if (e.Protection == UpgradeProtection.Protected) { await player.SendPacketAsync(player.GenerateEffectPacket(3004)); } await player.SendPacketAsync(player.GenerateEffectPacket(3005)); await player.SendChatMessageAsync("UPGRADESP_SUCCESS", SayColorType.Purple); await player.SendTopscreenMessage("UPGRADESP_SUCCESS", MsgPacketType.Whisper); /* if (Upgrade < 5) * { * CharacterSession.Character.Inventory.RemoveItemAmount( * Item.Morph <= 16 ? greenSoulVnum : dragonSkinVnum, soul[Upgrade]); * } * else if (Upgrade < 10) * { * CharacterSession.Character.Inventory.RemoveItemAmount( * Item.Morph <= 16 ? redSoulVnum : dragonBloodVnum, soul[Upgrade]); * } * else if (Upgrade < 15) * { * CharacterSession.Character.Inventory.RemoveItemAmount( * Item.Morph <= 16 ? blueSoulVnum : dragonHeartVnum, soul[Upgrade]); * }*/ wearable.Upgrade++; if (wearable.Upgrade > 8) { // CharacterSession.Character.Family?.InsertFamilyLog(FamilyLogType.ItemUpgraded, // CharacterSession.Character.Name, itemVNum: wearable.ItemVNum, upgrade: wearable.Upgrade); } await player.SendPacketAsync(wearable.GenerateIvnPacket()); } await player.SendPacketAsync(player.GenerateShopEndPacket(ShopEndPacketType.CloseSubWindow)); }
/// <summary> /// Actualizes the given player inventory slot /// </summary> /// <param name="player"></param> /// <param name="type"></param> /// <param name="slot"></param> public static Task ActualizeUiInventorySlot(this IPlayerEntity player, InventoryType type, short slot) { ItemInstanceDto tmp = player.Inventory.GetItemFromSlotAndType(slot, type); return(player.SendPacketAsync(tmp == null ? player.GenerateEmptyIvnPacket(type, slot) : tmp.GenerateIvnPacket())); }