/// <summary> /// sell packet /// </summary> /// <param name="sellPacket"></param> public void SellShop(SellPacket sellPacket) { if (Session.Character.InExchangeOrTrade) { //TODO log return; } if (sellPacket.Amount.HasValue && sellPacket.Slot.HasValue) { PocketType type = (PocketType)sellPacket.Data; var inv = Session.Character.Inventory.LoadBySlotAndType <IItemInstance>(sellPacket.Slot.Value, type); if (inv == null || sellPacket.Amount.Value > inv.Amount) { //TODO log return; } if (!inv.Item.IsSoldable) { Session.SendPacket(new SMemoPacket { Type = SMemoType.Error, Message = Language.Instance.GetMessageFromKey(LanguageKey.ITEM_NOT_SOLDABLE, Session.Account.Language) }); return; } long price = inv.Item.ItemType == ItemType.Sell ? inv.Item.Price : inv.Item.Price / 20; if (Session.Character.Gold + price * sellPacket.Amount.Value > _worldConfiguration.MaxGoldAmount) { Session.SendPacket(new MsgPacket { Message = Language.Instance.GetMessageFromKey(LanguageKey.MAX_GOLD, Session.Account.Language), Type = 0 }); return; } Session.Character.Gold += price * sellPacket.Amount.Value; Session.SendPacket(new SMemoPacket { Type = SMemoType.Success, Message = string.Format( Language.Instance.GetMessageFromKey(LanguageKey.SELL_ITEM_VALIDE, Session.Account.Language), inv.Item.Name, sellPacket.Amount.Value ) }); Session.Character.Inventory.RemoveItemAmountFromInventory(sellPacket.Amount.Value, inv.Id); Session.SendPacket(Session.Character.GenerateGold()); } else { //TODO sell skill } }
/// <summary> /// sell packet /// </summary> /// <param name="sellPacket"></param> public void SellShop(SellPacket sellPacket) { Logger.Debug(Session.Character.GenerateIdentity(), sellPacket.ToString()); if (Session.Character.ExchangeInfo != null && Session.Character.ExchangeInfo.ExchangeList.Any() || Session.Character.IsShopping) { return; } if (sellPacket.Amount.HasValue && sellPacket.Slot.HasValue) { InventoryType type = (InventoryType)sellPacket.Data; byte amount = sellPacket.Amount.Value, slot = sellPacket.Slot.Value; if (type == InventoryType.Bazaar) { return; } ItemInstance inv = Session.Character.Inventory.LoadBySlotAndType(slot, type); if (inv == null || amount > inv.Amount) { return; } if (Session.Character.MinilandObjects.Any(s => s.ItemInstanceId == inv.Id)) { return; } if (!inv.Item.IsSoldable) { Session.SendPacket(UserInterfaceHelper.Instance.GenerateShopMemo(2, string.Format(Language.Instance.GetMessageFromKey("ITEM_NOT_SOLDABLE")))); return; } long price = inv.Item.ItemType == ItemType.Sell ? inv.Item.Price : inv.Item.Price / 20; if (Session.Character.Gold + price * amount > ServerManager.Instance.MaxGold) { string message = UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("MAX_GOLD"), 0); Session.SendPacket(message); return; } Session.Character.Gold += price * amount; Session.SendPacket(UserInterfaceHelper.Instance.GenerateShopMemo(1, string.Format(Language.Instance.GetMessageFromKey("SELL_ITEM_VALIDE"), inv.Item.Name, amount))); Session.Character.Inventory.RemoveItemAmountFromInventory(amount, inv.Id); Session.SendPacket(Session.Character.GenerateGold()); } else { short vnum = sellPacket.Data; CharacterSkill skill = Session.Character.Skills[vnum]; if (skill == null || vnum == 200 + 20 * (byte)Session.Character.Class || vnum == 201 + 20 * (byte)Session.Character.Class) { return; } Session.Character.Gold -= skill.Skill.Price; Session.SendPacket(Session.Character.GenerateGold()); foreach (CharacterSkill loadedSkill in Session.Character.Skills.GetAllItems()) { if (skill.Skill.SkillVNum == loadedSkill.Skill.UpgradeSkill) { Session.Character.Skills.Remove(loadedSkill.SkillVNum); } } Session.Character.Skills.Remove(skill.SkillVNum); Session.SendPacket(Session.Character.GenerateSki()); Session.SendPackets(Session.Character.GenerateQuicklist()); Session.SendPacket(Session.Character.GenerateLev()); } }