[Share] DragonSource Shop Packet Implementation

Results 1 to 7 of 7
  1. #1
    Alpha Member GlaphanKing is offline
    MemberRank
    Sep 2008 Join Date
    World of MorrowLocation
    2,594Posts

    [Share] DragonSource Shop Packet Implementation

    Ok. There are some things to understand before you start this.

    1. You must remove all of the code or comment it out that has to do with the isOldClient variable and functions. Its a deprecated function that was supposed to be cross client compatible but just ended up becoming a headache.

    2. You need to change the player.cpp to reflect this. Open the file and navigate to the switch for the packet headers and change the following:

    Code:
    // Player closed trade dialog with npc
                    case 0x00ff00b2: return false;
    Change it to:

    Code:
    // Player closed trade dialog with npc
                    case 0x00ff00b2: return true;
    This will ensure that no error comes about when using the packet.

    3.
    Add this or change it if you already have it : ShopPacket.cpp:

    Code:
    #include "Packets/NPCsPacket.h"
    #include "NPC.h"
    #include "ShopPacket.h"
    #include "Player.h"
    #include "Packets/PacketCreator.h"
    #include "ItemBank.h"
    #include "ItemBanks.h"
    #include "windows.h"
    #include <string>
    #include "tchar.h"
    #include <iostream>
    #include <fstream>
    #include <vector>
    
    
    void ShopPacket::showShop(NPC* npc, Player* player)
    {
        int count=0;
        string line;
        char* next_token;
        ifstream myfile;
        int i, j;
        int slots, linenum = 0;
        char* filename;
        vector<int> tab1;
        vector<int> tab2;
        vector<int> tab3;
        vector<int> tab4;
    
        printf("NPC id: %d\n", npc->id);
        switch(npc->id)
        {
            case 513:
                filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Lui.txt";
                myfile.open(filename);
                printf("Opening file %s\n", filename);
                break;
            case 514:
                filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Dior.txt";
                myfile.open(filename);
                printf("Opening file %s\n", filename);
                break;
            case 515:
                filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Is.txt";
                myfile.open(filename);
                printf("Opening file %s\n", filename);
                break;
            case 519:
                filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Boboku.txt";
                myfile.open(filename);
                printf("Opening file %s\n", filename);
                break;
            case 520:
                filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Boboko.txt";
                myfile.open(filename);
                printf("Opening file %s\n", filename);
                break;
            case 524:
                filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Luda.txt";
                myfile.open(filename);
                printf("Opening file %s\n", filename);
                break;
            case 554:
                filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Losha.txt";
                myfile.open(filename);
                printf("Opening file %s\n", filename);
                break;
            default:
                printf("No shop to open or id unknown %d please recheck the id and or filename", npc->id);
        }
        
        
        
    
        if (myfile.fail())
        {
            printf("%s couldn't be read\n",filename);
            //system("pause");
            //exit(1);
        }
        else
        {
            // If the file is open start parsing the text line by line.
            if (myfile.is_open())
            {
                i=0;
                linenum++;
                while(!myfile.eof()) 
                {
                    getline (myfile,line);
                    slots = atoi(strtok_s((char*)line.c_str(), " ", &next_token));
                    //strtok_s(NULL, " ", &next_token);
                    switch(linenum)
                    {
                    case 1: 
                        for(j = 0; j<slots;j++)
                        {
                            tab1.push_back(strval(strtok_s(NULL, " ", &next_token)));
                        }
                        linenum++;
                        break;
                    case 2: 
                        for(j = 0; j<slots;j++)
                        {
                            tab2.push_back(strval(strtok_s(NULL, " ", &next_token)));
                        }
                        linenum++;
                        break;
                    case 3: 
                        for(j = 0; j<slots;j++)
                        {
                            tab3.push_back(strval(strtok_s(NULL, " ", &next_token)));
                        }
                        linenum++;
                        break;
                    case 4: 
                        for(j = 0; j<slots;j++)
                        {
                            tab4.push_back(strval(strtok_s(NULL, " ", &next_token)));
                        }
                        break;
                    }
                }
                
            }
    
            myfile.close();
        }
    
        vector< vector<int> > shopTabs;
    
        shopTabs.push_back(tab1);
        shopTabs.push_back(tab2);
        shopTabs.push_back(tab3);
        shopTabs.push_back(tab4);
    
        Packet pak = Packet();
        pak.setPlayer(player);
        pak.addHeader(npc,0x14);
    
        //cycle through all four tabs
        for (int tab = 0; tab < 4; tab++)
        {
            for(i=0; i <100; i++)
                pak.addInt(i);
    
            pak.addByte(shopTabs[tab].size());
    
            for(unsigned int k=0; k < shopTabs[tab].size(); k++)
            {
                // process each tab
                if(shopTabs[tab].empty())
                    continue;
                
                ItemBank* shopItem = ItemBanks::getItemBankById(shopTabs[tab].at(k));
                pak.addByte(k);
                pak.addInt(k);
                pak.addInt(shopItem->id);
                pak.addInt(0);
                pak.addInt(0);
                pak.addShort(shopItem->maxItems);
                pak.addByte(0);
                if(shopItem->endurance == 0)
                {
                    pak.addInt(-1);
                }
                else 
                {
                    pak.addInt(shopItem->endurance);
                }
                pak.addInt(0);
                pak.addInt(0);
                pak.addInt(0);
                pak.addInt(0);
                pak.addInt(0);
                pak.addInt(0);
                pak.addInt(0);
                pak.addInt(0);
                pak.addInt(0);
                pak.addInt(0);
            }
            
            for(i=0; i <100; i++)
                pak.addInt(i);
        }
        
        pak.completePacket();
        pak.packetSend();
    
        shopTabs.clear();
        tab1.clear();
        tab2.clear();
        tab3.clear();
        tab4.clear();
    }
    As you can see, this is the code in its entiredy. I am going to give you ONE text file so you can get started. To make more use the file as a guide. The first one on each line is the amount items on each tab. Its IMPERITIVE that you keep this number consistant with the items on each line. failure to do so will crash the server. So here is an example of Luda's Shop.

    Code:
    7 21 23 25 81 27 61 83
    11 510 506 502 500 511 507 503 514 520 518 516
    5 2001 2003 2005 2007 2009
    Save this as MaFl_Luda.txt and place it in the databaseLoad/Shops folder. You can change the path name to your liking. I just kept it the default pathname.

    There should be no errors but if the errors arise, at least try and fix them before posting them here.

    Enjoy!


    oh, one more thing. YOU CANNOT BUY NOR SELL ITEMS AS OF THIS RELEASE! It will crash at this point.


  2. #2
    Account Upgraded | Title Enabled! divinepunition is offline
    MemberRank
    Dec 2008 Join Date
    FranceLocation
    621Posts

    Re: [Share] DragonSource Shop Packet Implementation

    Thank for your post Glaphan

    It will more easer to put item in shop in a .txt file ^_^

    I'm still learning c++ so i can't help but just a question...

    C:\\kims\\databaseLoad\\Shops\\mynpc.txt
    shouldn't we delete : C:\\kims\\ parts for all those line? and put :

    databaseLoad\\Shops\\mynpc.txt
    I think the answer is yes but i prefer to ask ^_^

    Another thing :

    Code:
     linenum++;
                while(!myfile.eof()) 
                {
    Shouldn't the iterator linenum++ be in the begining of the while lopp ? like this you don't have to write it for each case of the switch. And at the end of the 4 line, the while loop is end so it could work. I know it's not a GREAT modify that i suggest but...why not simplify the code ?
    like this :
    Code:
                while(!myfile.eof()) 
                {
                        linenum++;
    I suppose it's minor but less we have code more the program will be fast no ?

    EDIT :

    So if i understood...
    We need to go to NPCsPacket.ccp and delete items1[0] etc content but we need to load txt files content in there ?

    Problem, actually you put in the code npc id...
    Why not create a text file named npc.txt like this :
    Code:
    519
    520
    ...
    And then foreeach id read in this file => do what you have put in your post...
    Like this we could put an underterminate amount of shop and people can put whatever they're wanted...

    It's some suggest...
    Last edited by divinepunition; 13-02-09 at 06:14 AM.

  3. #3
    Valued Member blazingracer is offline
    MemberRank
    Sep 2008 Join Date
    USA, PA.Location
    130Posts

    Re: [Share] DragonSource Shop Packet Implementation

    hey there GlaphanKing I've tried this but I get this error:
    1>c:\users\administrator\desktop\dandy\gameserver\shoppacket.cpp(98) : error C3861: 'strval': identifier not found
    1>c:\users\administrator\desktop\dandy\gameserver\shoppacket.cpp(105) : error C3861: 'strval': identifier not found
    1>c:\users\administrator\desktop\dandy\gameserver\shoppacket.cpp(112) : error C3861: 'strval': identifier not found
    1>c:\users\administrator\desktop\dandy\gameserver\shoppacket.cpp(119) : error C3861: 'strval': identifier not found
    I'm guessing probably something to do with identifiers in shoppacket.h that are needed.
    Thanks for the relelase ^__^

  4. #4
    Alpha Member GlaphanKing is offline
    MemberRank
    Sep 2008 Join Date
    World of MorrowLocation
    2,594Posts

    Re: [Share] DragonSource Shop Packet Implementation

    Quote Originally Posted by divinepunition View Post
    Thank for your post Glaphan

    It will more easer to put item in shop in a .txt file ^_^

    I'm still learning c++ so i can't help but just a question...


    shouldn't we delete : C:\\kims\\ parts for all those line? and put :



    I think the answer is yes but i prefer to ask ^_^

    Another thing :

    Code:
     linenum++;
                while(!myfile.eof())
                {
    Shouldn't the iterator linenum++ be in the begining of the while lopp ? like this you don't have to write it for each case of the switch. And at the end of the 4 line, the while loop is end so it could work. I know it's not a GREAT modify that i suggest but...why not simplify the code ?
    like this :
    Code:
                while(!myfile.eof())
                {
                        linenum++;
    I suppose it's minor but less we have code more the program will be fast no ?

    EDIT :

    So if i understood...
    We need to go to NPCsPacket.ccp and delete items1[0] etc content but we need to load txt files content in there ?

    Problem, actually you put in the code npc id...
    Why not create a text file named npc.txt like this :
    Code:
    519
    520
    ...
    And then foreeach id read in this file => do what you have put in your post...
    Like this we could put an underterminate amount of shop and people can put whatever they're wanted...

    It's some suggest...
    1.yes you can delete the c:\\ path. I just made it absolute for debugging.

    2. if you have a more efficient way of doing it, then by all means, test it and share your results. Its only a quick way, and being open source its always nice to have more than one POV.

    3. I decided to separate the shopPacket by itself for my own reasons. you are more than welcome to put it elsewhere. just remember to put the header declarations in the new header.



    Quote Originally Posted by blazingracer View Post
    hey there GlaphanKing I've tried this but I get this error:

    I'm guessing probably something to do with identifiers in shoppacket.h that are needed.
    Thanks for the relelase ^__^
    Exactly. You can find these in the initializing.h.

    all it really does is implement the atoi function. google that and you can use it instead. I just put it into a quick function.

  5. #5
    Newbie kn95951135 is offline
    MemberRank
    Nov 2005 Join Date
    MalaysiaLocation
    388Posts

    Re: [Share] DragonSource Shop Packet Implementation

    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Lui.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Dior.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Is.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Boboku.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Boboko.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Luda.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Losha.txt";

    where can i find this file?

  6. #6
    Rhisis Developer Akitasha is offline
    MemberRank
    Jun 2005 Join Date
    NY, USALocation
    220Posts

    Re: [Share] DragonSource Shop Packet Implementation

    Quote Originally Posted by kn95951135 View Post
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Lui.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Dior.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Is.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Boboku.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Boboko.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Luda.txt";
    filename = "C:\\kims\\databaseLoad\\Shops\\MaFl_Losha.txt";

    where can i find this file?
    You're suppose to make your own files using the example he gave.
    Code:
    7 21 23 25 81 27 61 83
    11 510 506 502 500 511 507 503 514 520 518 516
    5 2001 2003 2005 2007 2009

  7. #7
    Newbie kn95951135 is offline
    MemberRank
    Nov 2005 Join Date
    MalaysiaLocation
    388Posts

    Re: [Share] DragonSource Shop Packet Implementation

    oh... but i cant understand what that code mean...>.<
    and i get this error
    2>.\ShopPacket.cpp(17) : error C2511: 'void ShopPacket::showShop(NPC *,Player *)' : overloaded member function not found in 'ShopPacket'
    2> h:\backup\administrator\Desktop\flyff\flyff_source_dev\server\flyff_source2\gameserver\ShopPacket.h(4) : see declaration of 'ShopPacket'



Advertisement