/// <summary> /// The Player is buying an Item from the merchant /// </summary> /// <param name="player"></param> /// <param name="playerInventory"></param> /// <param name="fromSlot"></param> /// <param name="toSlot"></param> public void OnPlayerBuy(GamePlayer player, IGameInventory playerInventory, eInventorySlot fromSlot, eInventorySlot toSlot, bool byMarketExplorer) { IDictionary<int, InventoryItem> inventory = ConInventory; if ((int)fromSlot >= (int)eInventorySlot.Consignment_First) { fromSlot = (eInventorySlot)(RecalculateSlot((int)fromSlot)); } InventoryItem fromItem = inventory[(int)fromSlot]; if (fromItem == null) return; int totalValue = fromItem.SellPrice; int orgValue = totalValue; if (byMarketExplorer) { int additionalfee = (totalValue * 20) / 100; totalValue += additionalfee; } lock (player.Inventory) { if (totalValue == 0) { player.Out.SendMessage("This Item can not be bought.", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } if (ConsignmentMoney.UseBP) { if (player.BountyPoints < totalValue) { ChatUtil.SendSystemMessage(player, "GameMerchant.OnPlayerBuy.YouNeedBP", totalValue); return; } } else { if (player.GetCurrentMoney() < totalValue) { ChatUtil.SendSystemMessage(player, "GameMerchant.OnPlayerBuy.YouNeed", Money.GetString(totalValue)); return; } } if (player.Inventory.FindFirstEmptySlot(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack) == eInventorySlot.Invalid) { ChatUtil.SendSystemMessage(player, "GameMerchant.OnPlayerBuy.NotInventorySpace", null); return; } if (ConsignmentMoney.UseBP) // we buy with Bountypoints { ChatUtil.SendMerchantMessage(player, "GameMerchant.OnPlayerBuy.BoughtBP", fromItem.GetName(1, false), totalValue); player.BountyPoints -= totalValue; player.Out.SendUpdatePoints(); } else //we buy with money { if (player.RemoveMoney(totalValue)) { InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, totalValue); ChatUtil.SendMerchantMessage(player, "GameMerchant.OnPlayerBuy.Bought", fromItem.GetName(1, false), Money.GetString(totalValue)); } } TotalMoney += orgValue; NotifyObservers(MoveItemFromMerchant(player, playerInventory, fromSlot, toSlot)); } }
/// <summary> /// Move an Item from the merchant /// </summary> /// <param name="playerInventory"></param> /// <param name="fromSlot"></param> /// <param name="toSlot"></param> /// <returns></returns> protected IDictionary<int, InventoryItem> MoveItemFromMerchant(GamePlayer player, IGameInventory playerInventory, eInventorySlot fromSlot, eInventorySlot toSlot) { // We will only allow moving to the backpack. if (toSlot < eInventorySlot.FirstBackpack || toSlot > eInventorySlot.LastBackpack) return null; IDictionary<int, InventoryItem> inventory = ConInventory; if ((int)fromSlot >= (int)eInventorySlot.Consignment_First) { fromSlot = (eInventorySlot)(RecalculateSlot((int)fromSlot)); } if (!inventory.ContainsKey((int)fromSlot)) return null; IDictionary<int, InventoryItem> updateItems = new Dictionary<int, InventoryItem>(1); InventoryItem fromItem = inventory[(int)fromSlot]; InventoryItem toItem = playerInventory.GetItem(toSlot); if (toItem != null) { playerInventory.RemoveItem(toItem); InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, toItem.Template, toItem.Count); toItem.SlotPosition = fromItem.SlotPosition; GameServer.Database.AddObject(toItem); } GameServer.Database.DeleteObject(fromItem); if (fromItem.OwnerID != player.DBCharacter.ObjectId) { fromItem.OwnerID = player.DBCharacter.ObjectId; } if (fromItem.SellPrice != 0) { fromItem.SellPrice = 0; } fromItem.OwnerLot = 0; if (playerInventory.AddItem(toSlot, fromItem)) InventoryLogging.LogInventoryAction(this, player, eInventoryActionType.Merchant, fromItem.Template, fromItem.Count); updateItems.Add((int)fromSlot, toItem); return updateItems; }
/// <summary> /// Move an item to the merchant /// </summary> /// <param name="playerInventory"></param> /// <param name="fromSlot"></param> /// <param name="toSlot"></param> /// <returns></returns> protected IDictionary<int, InventoryItem> MoveItemToMerchant(GamePlayer player, IGameInventory playerInventory, eInventorySlot fromSlot, eInventorySlot toSlot) { // We will only allow moving from the backpack. if (fromSlot < eInventorySlot.FirstBackpack || fromSlot > eInventorySlot.LastBackpack) return null; InventoryItem fromItem = playerInventory.GetItem(fromSlot); if (fromItem == null) return null; if (fromItem is InventoryArtifact) return null; IDictionary<int, InventoryItem> inventory = ConInventory; IDictionary<int, InventoryItem> updateItems = new Dictionary<int, InventoryItem>(1); playerInventory.RemoveItem(fromItem); InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, fromItem.Template, fromItem.Count); if (inventory.ContainsKey((int)toSlot)) { InventoryItem toItem = inventory[(int)toSlot]; GameServer.Database.DeleteObject(toItem); if (playerInventory.AddItem(fromSlot, toItem)) InventoryLogging.LogInventoryAction(this, player, eInventoryActionType.Other, toItem.Template, toItem.Count); } House house = HouseMgr.GetHouse(HouseNumber); fromItem.SlotPosition = (int)(toSlot); var price = player.TempProperties.getProperty<int>(PlayerSetMarketPriceHandler.NEW_PRICE); player.TempProperties.removeProperty(PlayerSetMarketPriceHandler.NEW_PRICE); if (fromItem.OwnerID != house.OwnerID) { fromItem.OwnerID = house.OwnerID; } fromItem.SellPrice = price; fromItem.OwnerLot = (ushort)HouseNumber; // used to mark the lot for market explorer GameServer.Database.AddObject(fromItem); if ((int)toSlot >= (int)eInventorySlot.Consignment_First) { toSlot = (eInventorySlot)(RecalculateSlot((int)toSlot)); } updateItems.Add((int)toSlot, fromItem); return updateItems; }
/// <summary> /// Move an item from, to or inside a consignment merchants inventory. /// </summary> /// <param name="playerInventory"></param> /// <param name="fromSlot"></param> /// <param name="toSlot"></param> /// <returns></returns> public void MoveItem(GamePlayer player, IGameInventory playerInventory, eInventorySlot fromSlot, eInventorySlot toSlot) { if (fromSlot == toSlot) return; House house = HouseMgr.GetHouse(HouseNumber); if (house == null) return; lock (m_vaultSync) { if (fromSlot == toSlot) { NotifyObservers(null); } else if (fromSlot >= eInventorySlot.Consignment_First && fromSlot <= eInventorySlot.Consignment_Last) { if (toSlot >= eInventorySlot.Consignment_First && toSlot <= eInventorySlot.Consignment_Last) { NotifyObservers(MoveItemInsideMerchant(fromSlot, toSlot)); } else if (!house.HasOwnerPermissions(player)) { OnPlayerBuy(player, playerInventory, fromSlot, toSlot, false); } else { NotifyObservers(MoveItemFromMerchant(player, playerInventory, fromSlot, toSlot)); } } else if (toSlot >= eInventorySlot.Consignment_First && toSlot <= eInventorySlot.Consignment_Last) { NotifyObservers(MoveItemToMerchant(player, playerInventory, fromSlot, toSlot)); } } }