- Code: Select all
public class GameDragonScaleMerchant : GameCountMerchant
{
public GameDragonScaleMerchant()
: base()
{
m_countText = "Dragonscales";
}
GameInventoryItem[] TheScales = new GameInventoryItem[6]
{
GameInventoryItem.CreateFromTemplate("ElderDragonScale"), //
GameInventoryItem.CreateFromTemplate("MoltedDragonScale"), //
GameInventoryItem.CreateFromTemplate("MoltedZhulrathuulScale"),
GameInventoryItem.CreateFromTemplate("MoltedXanxicarScale"),
GameInventoryItem.CreateFromTemplate("YoungDragonScale"),
GameInventoryItem.CreateFromTemplate("AdultDragonScale")
}; // array ends
public override void OnPlayerBuy(GamePlayer player, int item_slot, int number)
{
if (TheScales[0] == null || TheScales[0].Item == null)
return;
//Get the template
int pagenumber = item_slot / MerchantTradeItems.MAX_ITEM_IN_TRADEWINDOWS;
int slotnumber = item_slot % MerchantTradeItems.MAX_ITEM_IN_TRADEWINDOWS;
ItemTemplate template = this.TradeItems.GetItem(pagenumber, (eMerchantWindowSlot)slotnumber);
if (template == null) return;
//Calculate the amout of items
int amountToBuy = number;
if (template.PackSize > 0)
amountToBuy *= template.PackSize;
if (amountToBuy <= 0) return;
//Calculate the value of items
long totalValue = number * template.Value;
lock (player.Inventory)
{
int MasterAmount = 0;
for (int i = 0; i < TheScales.Length; i++)
{
MasterAmount += player.Inventory.CountItemTemplate(TheScales[i].Item.Id_nb, eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack);
}
if (MasterAmount < totalValue)
{
player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client, "GameMerchant.OnPlayerBuy.YouNeed2", totalValue, m_countText), eChatType.CT_System, eChatLoc.CL_SystemWindow);
return;
}
if (!player.Inventory.AddTemplate(template, amountToBuy, eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack))
{
player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client, "GameMerchant.OnPlayerBuy.NotInventorySpace"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
return;
}
//Generate the buy message
string message;
if (amountToBuy > 1)
message = LanguageMgr.GetTranslation(player.Client, "GameMerchant.OnPlayerBuy.BoughtPieces2", amountToBuy, template.GetName(1, false), totalValue, m_countText);
else
message = LanguageMgr.GetTranslation(player.Client, "GameMerchant.OnPlayerBuy.Bought2", template.GetName(1, false), totalValue, m_countText);
System.Collections.IList items = (System.Collections.IList)player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack);
int removed = 0;
foreach (InventoryItem item in items)
{
int check = 0;
for (int i = 0; i < TheScales.Length; i++)
{
if (item.Id_nb != TheScales[i].Item.Id_nb)
check += 1;
}
if (check == TheScales.Length)
continue;
int remFromStack = Math.Min(item.Count, (int)(totalValue - removed));
player.Inventory.RemoveCountFromStack(item, remFromStack);
removed += remFromStack;
if (removed == totalValue)
break;
}
player.Out.SendInventoryItemsUpdate(items);
player.Out.SendMessage(message, eChatType.CT_Merchant, eChatLoc.CL_SystemWindow);
}
}
public override bool Interact(GamePlayer player)
{
if (!base.Interact(player))
return false;
TurnTo(player, 10000);
string text = "Dragonscales";
player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client, "GameMerchant.GetExamineMessages.BuyItemsFor", this.Name, text), eChatType.CT_Say, eChatLoc.CL_ChatWindow);
return true;
}
}
Hi here is Dragonscale Merchant.. i think i added all the scales that he should take....
Please tell me if i could have done it better i want to learn more