Dragonscale Merchant

A place to submit .patch fixes for the DOL SVN

Moderator: Developer Team

Dragonscale Merchant

Postby geshi » Sat Jan 16, 2010 5:03 pm

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 :P
geshi
Contributor
 
Posts: 1823
Joined: Tue Oct 21, 2008 9:16 pm

Re: Dragonscale Merchant

Postby Graveen » Sat Jan 16, 2010 10:17 pm

interesting geshi, ty.
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12070
Joined: Fri Oct 19, 2007 9:22 pm
Location: France

Re: Dragonscale Merchant

Postby stephenxpimentel » Sat Jan 16, 2010 10:37 pm

this will not work i don't think. and the reason for this is because if you have more than 1 stack with more than enough in it, it will take from them all, or if u have 1 stack with 1 in it (on top) then 1 with more than enough below, it will only remove the 1 stack on top.. look at ur inventory like this.


1 Super Dragonscale
99 Mediocre Dragonscales


then you buy something for say 23 scales, your inventory will look like this.

99 Mediocre Dragonscales

This is my thoughts anyways, i had this problem with the Casino manager i was working on with you, and i fixed it but the fix can't apply to this. Test it and let me know =]
Lets have some fun.
stephenxpimentel
Contributor
 
Posts: 1298
Joined: Wed Sep 19, 2007 5:09 pm

Re: Dragonscale Merchant

Postby geshi » Sat Jan 16, 2010 11:36 pm

Me & Stephen just tested it more and it works fine :D
geshi
Contributor
 
Posts: 1823
Joined: Tue Oct 21, 2008 9:16 pm

Re: Dragonscale Merchant

Postby Graveen » Sun Apr 11, 2010 4:13 pm

Thank you. This NPC is livelike ?
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12070
Joined: Fri Oct 19, 2007 9:22 pm
Location: France

Re: Dragonscale Merchant

Postby geshi » Sun Apr 11, 2010 4:59 pm

yes, but this script need editing, I will in 2 months :( PC is broken and in 2 months i get new :D
geshi
Contributor
 
Posts: 1823
Joined: Tue Oct 21, 2008 9:16 pm

Re: Dragonscale Merchant

Postby Graveen » Sun Apr 11, 2010 5:03 pm

Ok, i wait you could rewrite it ! If it is livelike, no troubles to have it in svn ;)
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12070
Joined: Fri Oct 19, 2007 9:22 pm
Location: France

Re: Dragonscale Merchant

Postby Aredhel » Sun Apr 11, 2010 5:22 pm

geshi wrote:yes, but this script need editing, I will in 2 months :( PC is broken and in 2 months i get new :D


Two months without a PC.. I think I'd die if that happened to me :shock:
User avatar
Aredhel
Inactive Staff Member
 
Posts: 1024
Joined: Sat Apr 14, 2007 1:49 pm
Location: Germany

Re: Dragonscale Merchant

Postby geshi » Sun Apr 11, 2010 5:26 pm

Aredhel wrote:
Two months without a PC.. I think I'd die if that happened to me :shock:

hehe i have laptop but it can just about run firefox :roll:

Graveen wrote:Ok, i wait you could rewrite it ! If it is livelike, no troubles to have it in svn ;)


It's npc from live that takes several currency for Dragon Items (Fine Steel Longsword etc) not with merchantlist though..
geshi
Contributor
 
Posts: 1823
Joined: Tue Oct 21, 2008 9:16 pm

Re: Dragonscale Merchant

Postby Dinberg » Mon Apr 12, 2010 10:07 am

Whats the use of this bit in the code btw?

Code: Select all
            if (TheScales[0] == null || TheScales[0].Item == null)
                return;
One day, I will finish The Marvellous Contraption, in all its custom glory.
Decatur wrote:Ah neato stephen! I see I still have much to learn :)
User avatar
Dinberg
Inactive Staff Member
 
Posts: 4567
Joined: Sat Mar 10, 2007 9:47 am
Location: Houses of Parliament

Re: Dragonscale Merchant

Postby geshi » Mon Apr 12, 2010 11:10 am

Code: Select all
              GameInventoryItem.CreateFromTemplate("ElderDragonScale"),   // 


If ElderDragonScale does not exist then the npc won't do anything, this is a bad fix and it really should check for all the scales and not just one type.

The script looks so bad now :(
geshi
Contributor
 
Posts: 1823
Joined: Tue Oct 21, 2008 9:16 pm

Re: Dragonscale Merchant

Postby stephenxpimentel » Fri Apr 16, 2010 9:45 pm

do an i variable imo :)
Lets have some fun.
stephenxpimentel
Contributor
 
Posts: 1298
Joined: Wed Sep 19, 2007 5:09 pm

Re: Dragonscale Merchant

Postby geshi » Fri Apr 16, 2010 11:20 pm

stephenxpimentel wrote:do an i variable imo :)

why i ? i like to giev my variables names so I remember what they are for :cry: or what do you mean? :s
geshi
Contributor
 
Posts: 1823
Joined: Tue Oct 21, 2008 9:16 pm

Re: Dragonscale Merchant

Postby stephenxpimentel » Sat Apr 17, 2010 3:37 am

geshi wrote:
stephenxpimentel wrote:do an i variable imo :)

why i ? i like to giev my variables names so I remember what they are for :cry: or what do you mean? :s


is exactly what i meant hehe

for (int i ) etc.

tbh i like to give them names too, but in this case what would u do?

Code: Select all
for (int scaleType = 0; scaleType < TheScales.Length; i++)
{
if (TheScales[scaleType] == null || TheScales[scaleType].Item == null)
return;
}


seems a little funky but its fine, your variables ur names!! =]
Lets have some fun.
stephenxpimentel
Contributor
 
Posts: 1298
Joined: Wed Sep 19, 2007 5:09 pm

Re: Dragonscale Merchant

Postby Aredhel » Sat Apr 17, 2010 8:25 am

Only use capitalized names for classes, methods and properties - is TheScales an indexed property or a mere variable/class member?
User avatar
Aredhel
Inactive Staff Member
 
Posts: 1024
Joined: Sat Apr 14, 2007 1:49 pm
Location: Germany

Next

Return to DOL Code Contributions

Who is online

Users browsing this forum: Ephemeral and 1 guest