99Max综合娱乐网站(旧版)

 找回密码
 立即注册
查看: 1930|回复: 4

[教程] 自定义商店系统[第一期]

[复制链接]

升级   100%

发表于 2013-6-14 11:04:16 | 显示全部楼层 |阅读模式
本帖最后由 灵巧儿 于 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

加入
  1. struct s_item_vend{
  2.         int itemid;
  3.         int type;
  4.         char variable[20];
  5.         int vending_tax;
  6. };
  7. struct s_item_vend item_vend[MAX_INVENTORY];

  8. struct s_item_buyingstore{
  9.         int itemid;
  10.         int type;
  11.         char variable[20];
  12.         char variable2[20];
  13. };
  14. struct s_item_buyingstore item_buyingstore[MAX_INVENTORY];
复制代码
在打开itemdb.c
加入
  1. static bool itemdb_read_vending(char* fields[], int columns, int current)
  2. {
  3.         struct item_data* id;
  4.         int nameid,type,tax;

  5.         nameid = atoi(fields[0]);
  6.         type = atoi(fields[1]);
  7.         tax = atoi(fields[3]);


  8.         if( ( id = itemdb_exists(nameid) ) == NULL )
  9.         {
  10.                 ShowWarning("itemdb_read_vending: 无效的道具ID %d.\n", nameid);
  11.                 return false;
  12.         }

  13.         if( id->type == IT_ARMOR || id->type == IT_WEAPON )
  14.         {
  15.                 ShowWarning("itemdb_read_vending: 道具 %d 不能是装备或武器.\n", nameid);
  16.                 return false;
  17.         }

  18.         if ( type < 0 || type > 4 )
  19.         {       
  20.                 ShowWarning("itemdb_read_vending: 无效的type属性 %d \n",type);
  21.                 return false;
  22.         }

  23.         if ( tax < 0 )
  24.         {
  25.                 ShowWarning("itemdb_read_vending: 无效的vending_tax设定 %d \n",type);
  26.                 return false;               
  27.         }

  28.         safestrncpy(item_vend[current].variable,fields[2],sizeof(item_vend[current].variable));
  29.         item_vend[current].itemid = nameid;
  30.         item_vend[current].type = type;
  31.         item_vend[current].vending_tax = tax;

  32.         return true;
  33. }

  34. static bool itemdb_read_buying(char* fields[], int columns, int current)
  35. {
  36.         struct item_data* id;
  37.         int nameid,type;

  38.         nameid = atoi(fields[0]);
  39.         type = atoi(fields[1]);


  40.         if( ( id = itemdb_exists(nameid) ) == NULL )
  41.         {
  42.                 ShowWarning("itemdb_read_buyingstore: 无效的道具ID %d.\n", nameid);
  43.                 return false;
  44.         }

  45.         if( id->type == IT_ARMOR || id->type == IT_WEAPON )
  46.         {
  47.                 ShowWarning("itemdb_read_buyingstore: 道具 %d 不能是装备或武器.\n", nameid);
  48.                 return false;
  49.         }

  50.         if ( type < 0 || type > 4 )
  51.         {       
  52.                 ShowWarning("itemdb_read_buyingstore: 无效的type属性 %d \n",type);
  53.                 return false;
  54.         }

  55.         safestrncpy(item_buyingstore[current].variable,fields[2],sizeof(item_buyingstore[current].variable));
  56.         safestrncpy(item_buyingstore[current].variable2,fields[3],sizeof(item_buyingstore[current].variable2));
  57.         item_buyingstore[current].itemid = nameid;
  58.         item_buyingstore[current].type = type;

  59.         return true;
  60. }
复制代码
然后还是这个文件,找到
  1. sv_readdb(db_path, "item_avail.txt",                        ',', 2, 2, -1,                                &itemdb_read_itemavail        );
  2.         sv_readdb(db_path, "item_noequip.txt",                        ',', 2, 2, -1,                                &itemdb_read_noequip        );
  3.         sv_readdb(db_path, "item_trade.txt",                        ',', 3, 3, -1,                                &itemdb_read_itemtrade        );
  4.         sv_readdb(db_path, "item_delay.txt",                        ',', 2, 2, MAX_ITEMDELAYS,        &itemdb_read_itemdelay        );
  5.         sv_readdb(db_path, "item_buyingstore.txt",                ',', 1, 1, -1,                                &itemdb_read_buyingstore);
复制代码
在其后加入
  1. sv_readdb(db_path, "LeA/item_vending.txt",                ',', 4, 4, MAX_INVENTORY,        &itemdb_read_vending        );
  2.         sv_readdb(db_path, "LeA/item_buying.txt",                ',', 4, 4, MAX_INVENTORY,        &itemdb_read_buying                );
复制代码
以上我们就定义完成了DB的读取和设定

DB如下:
首先是:item_vending.txt
格式如下:
  1. // 自定义货币商店系统
  2. // 格式: 道具ID,Type,变量名,税率
  3. // Type = 1 为Zeny交易
  4. // Type = 2 为CashPoints
  5. // Type = 3 为自定义变量交易
  6. // Type = 4 为道具交易
  7. // 请对应在ITEMDB中加入道具ID
  8. // 道具交易无税率,请设置为0,否则会出错
  9. // type 1 2 4 变量名 请设置为0
  10. // 最大ID设置为 MAX_INVENTORY ( 默认 100 )
  11. 19996,1,0,200 // Zeny交易
  12. 19997,2,0,200 // CashPoints
  13. 19993,3,BOSSjf,200 //BOSS积分
  14. 19994,3,paodian,200 // 在线积分
  15. 19995,3,fzjifen,200 // 副职积分
复制代码
然后是:item_buying.txt
DB格式如下:
  1. // 自定义货币商店系统
  2. // 格式: 道具ID,Type,变量名,变量显示名
  3. // Type = 1 为Zeny交易
  4. // Type = 2 为CashPoints
  5. // Type = 3 为自定义变量交易
  6. // Type = 4 为道具交易
  7. // 请对应在ITEMDB中加入道具ID
  8. // type 1 2 4 变量名 请设置为0
  9. // 最大ID设置为 MAX_INVENTORY ( 默认 100 )
  10. 19996,1,0,0 // Zeny交易
  11. 19997,2,0,0 // CashPoints
  12. 19993,3,BOSSjf,BOSS积分
  13. 19994,3,paodian,在线积分
  14. 19995,3,fzjifen,副职积分
  15. 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 ,我们会及时删除。

升级   100%

发表于 2017-1-7 03:36:36 | 显示全部楼层
谢谢巧儿的教程!

升级   100%

发表于 2018-2-20 18:09:40 | 显示全部楼层
巧儿大大的帖子一定要顶.

升级   0%

群组: JRO日本客户端

发表于 2020-6-21 06:36:22 | 显示全部楼层
前来学习经验。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|99Max综合娱乐网站(旧版) ( 沪ICP备11024206号-1 )

GMT+8, 2024-5-2 21:31 , Processed in 0.060143 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表