UID7297
阅读权限120
威望 点
积分2017
注册时间2010-11-7
最后登录1970-1-1
听众
收听
 
 
 
升级 
    100%
 
 
 | 
 
 本帖最后由 灵巧儿 于 2013-6-14 11:05 编辑  
 
自定义商店系统,其作用是: 
 
根据DB设置玩家可以使用多种货币进行贩卖或者购买 
货币形式可以是Zeny,CASHPOINT,自定义的变量(积分等等),可叠加的物品(不能使用装备) 
 
此源码比较庞大,复杂,涉及的文件比较多,我会分开进行讲解 
 
此源码主要涉及的文件: 
itemdb.h 
itemdb.c 
clif.c 
skill.c 
pc.h 
vending.c 
 
其核心代码主要位于 vending.c 玩家交易的函数全部在这个文件中. 
 
好,我新开始DB的定义. 
我们打开 itemdb.h 
 
加入- struct s_item_vend{
 
 -         int itemid;
 
 -         int type;
 
 -         char variable[20];
 
 -         int vending_tax;
 
 - };
 
 - struct s_item_vend item_vend[MAX_INVENTORY];
 
  
- struct s_item_buyingstore{
 
 -         int itemid;
 
 -         int type;
 
 -         char variable[20];
 
 -         char variable2[20];
 
 - };
 
 - struct s_item_buyingstore item_buyingstore[MAX_INVENTORY];
 
  复制代码 在打开itemdb.c 
加入- static bool itemdb_read_vending(char* fields[], int columns, int current)
 
 - {
 
 -         struct item_data* id;
 
 -         int nameid,type,tax;
 
 -  
 
 -         nameid = atoi(fields[0]);
 
 -         type = atoi(fields[1]);
 
 -         tax = atoi(fields[3]);
 
  
 
-         if( ( id = itemdb_exists(nameid) ) == NULL )
 
 -         {
 
 -                 ShowWarning("itemdb_read_vending: 无效的道具ID %d.\n", nameid);
 
 -                 return false;
 
 -         }
 
  
-         if( id->type == IT_ARMOR || id->type == IT_WEAPON )
 
 -         {
 
 -                 ShowWarning("itemdb_read_vending: 道具 %d 不能是装备或武器.\n", nameid);
 
 -                 return false;
 
 -         }
 
  
-         if ( type < 0 || type > 4 )
 
 -         {        
 
 -                 ShowWarning("itemdb_read_vending: 无效的type属性 %d \n",type);
 
 -                 return false;
 
 -         }
 
  
-         if ( tax < 0 )
 
 -         {
 
 -                 ShowWarning("itemdb_read_vending: 无效的vending_tax设定 %d \n",type);
 
 -                 return false;                
 
 -         }
 
  
-         safestrncpy(item_vend[current].variable,fields[2],sizeof(item_vend[current].variable));
 
 -         item_vend[current].itemid = nameid;
 
 -         item_vend[current].type = type;
 
 -         item_vend[current].vending_tax = tax;
 
  
-         return true;
 
 - }
 
  
- static bool itemdb_read_buying(char* fields[], int columns, int current)
 
 - {
 
 -         struct item_data* id;
 
 -         int nameid,type;
 
 -  
 
 -         nameid = atoi(fields[0]);
 
 -         type = atoi(fields[1]);
 
  
 
-         if( ( id = itemdb_exists(nameid) ) == NULL )
 
 -         {
 
 -                 ShowWarning("itemdb_read_buyingstore: 无效的道具ID %d.\n", nameid);
 
 -                 return false;
 
 -         }
 
  
-         if( id->type == IT_ARMOR || id->type == IT_WEAPON )
 
 -         {
 
 -                 ShowWarning("itemdb_read_buyingstore: 道具 %d 不能是装备或武器.\n", nameid);
 
 -                 return false;
 
 -         }
 
  
-         if ( type < 0 || type > 4 )
 
 -         {        
 
 -                 ShowWarning("itemdb_read_buyingstore: 无效的type属性 %d \n",type);
 
 -                 return false;
 
 -         }
 
  
-         safestrncpy(item_buyingstore[current].variable,fields[2],sizeof(item_buyingstore[current].variable));
 
 -         safestrncpy(item_buyingstore[current].variable2,fields[3],sizeof(item_buyingstore[current].variable2));
 
 -         item_buyingstore[current].itemid = nameid;
 
 -         item_buyingstore[current].type = type;
 
  
-         return true;
 
 - }
 
 
  复制代码 然后还是这个文件,找到-  sv_readdb(db_path, "item_avail.txt",                        ',', 2, 2, -1,                                &itemdb_read_itemavail        );
 
 -         sv_readdb(db_path, "item_noequip.txt",                        ',', 2, 2, -1,                                &itemdb_read_noequip        );
 
 -         sv_readdb(db_path, "item_trade.txt",                        ',', 3, 3, -1,                                &itemdb_read_itemtrade        );
 
 -         sv_readdb(db_path, "item_delay.txt",                        ',', 2, 2, MAX_ITEMDELAYS,        &itemdb_read_itemdelay        );
 
 -         sv_readdb(db_path, "item_buyingstore.txt",                ',', 1, 1, -1,                                &itemdb_read_buyingstore);
 
  复制代码 在其后加入-  sv_readdb(db_path, "LeA/item_vending.txt",                ',', 4, 4, MAX_INVENTORY,        &itemdb_read_vending        );
 
 -         sv_readdb(db_path, "LeA/item_buying.txt",                ',', 4, 4, MAX_INVENTORY,        &itemdb_read_buying                );
 
  复制代码 以上我们就定义完成了DB的读取和设定 
 
DB如下: 
首先是:item_vending.txt 
格式如下:- // 自定义货币商店系统
 
 - // 格式: 道具ID,Type,变量名,税率
 
 - // Type = 1 为Zeny交易
 
 - // Type = 2 为CashPoints
 
 - // Type = 3 为自定义变量交易
 
 - // Type = 4 为道具交易
 
 - // 请对应在ITEMDB中加入道具ID
 
 - // 道具交易无税率,请设置为0,否则会出错
 
 - // type 1 2 4 变量名 请设置为0
 
 - // 最大ID设置为 MAX_INVENTORY ( 默认 100 )
 
 - 19996,1,0,200 // Zeny交易
 
 - 19997,2,0,200 // CashPoints
 
 - 19993,3,BOSSjf,200 //BOSS积分
 
 - 19994,3,paodian,200 // 在线积分
 
 - 19995,3,fzjifen,200 // 副职积分
 
  复制代码 然后是:item_buying.txt 
DB格式如下:- // 自定义货币商店系统
 
 - // 格式: 道具ID,Type,变量名,变量显示名
 
 - // Type = 1 为Zeny交易
 
 - // Type = 2 为CashPoints
 
 - // Type = 3 为自定义变量交易
 
 - // Type = 4 为道具交易
 
 - // 请对应在ITEMDB中加入道具ID
 
 - // type 1 2 4 变量名 请设置为0
 
 - // 最大ID设置为 MAX_INVENTORY ( 默认 100 )
 
 - 19996,1,0,0 // Zeny交易
 
 - 19997,2,0,0 // CashPoints
 
 - 19993,3,BOSSjf,BOSS积分
 
 - 19994,3,paodian,在线积分
 
 - 19995,3,fzjifen,副职积分
 
 - 674,4,0,0
 
  复制代码 2个DB的格式是一样的, 
item_vending.txt 定义的是贩卖商店货币的定义 
item_buying.txt 定义的是收购商店货币的定义 
 
以上不明白的可以跟帖提问. 
第二期我将对玩家技能 MC_VENDING 的相关修改 
 |   
 
 温馨提示:
1. 本站模拟器源于网络,经 99Max.mE 二次开发,仅供个人学习娱乐使用,切勿用于商业用途,否则后果自负! 
2. 如需更好体验游戏内容,请前往官方游戏!不具备合法的运营模式,都是强盗,请勿擅自搭建私服! 
3. 如本站内容有侵犯您的权益,请发送信息至QQ:372607220 或 EMAIL:372607220@qq.com ,我们会及时删除。 
 
 
 |