/********************************************************************************************************************** 脚本使用导出C++对象说明 对于.pkg中导出的对象,脚本可以直接调用对象的方法,而不是使用原来的"名词空间"."函数方法" 的方式来调用。 例如:脚本已经保存了一个实体指针sysarg(Entity *),如果想获取实体句柄,调用方式为: Actor.getHandle(sysarg) 如果Entity类导出到lua脚本中,那么可以直接调用Entity的接口:sysarg:getHandle() !!! 注意:格式是"对象" + ":" + "方法" 。 是冒号,不是点!!! 下面写一个脚本创建宝箱掉落的脚本范例,以后对于导出到脚本的C++对象,都可以如法炮制。 步骤:假设有一个名称为"粽子"的宝箱掉落 (1) 查询游戏中当前是否已经创建了此宝箱掉落, local fileName = "data/config/item/scriptItemConfig/RollItemDrops/drops1.txt"" --爆率的配置位置 local dropName = "roll"..tostring(itemidx) --按名字索引的 local drop = System.getObjectVar(dropName) (2) 如果"粽子对象不存在",创建之(调用宝箱掉落管理器的接口创建) if (not drop) then boxdrop = CBoxDropMgr:getSingleton():createBoxDrop(dropName) -- 这里会返回一个宝箱掉落对象(CBoxDrop) if(boxdrop) then boxdrop:load(fileName) end end (3) 到此为止,宝箱掉落对象已经存在。调用其drop()方法执行掉落 local items = drop:drop() (4) 遍历掉落物品列表dropItemList --遍历掉落列表 if ( items.itemCount > 0) then for i=0, items.itemCount -1 do Actor.addItem(sysarg, items.itemList[i].wItemId, items.itemList[i].btQuality, items.itemList[i].btStrong, items.itemList[i].btCount,items.itemList[i].btBind,"activity",1) end end 总结:脚本使用C++导出对象,调用对象的成员方法使用的是冒号(:),访问对象成员遍历使用的是点(.) ***********************************************************************************************************************/ // C++导出脚本对象基类 class CBaseScriptExportObject { // 增加对象引用计数 int addRef(); // 减少对象引用计数。计数为0会删除对象 int release(); }; // 宝箱掉落对象 class CBoxDrop : public CBaseScriptExportObject { // 加载掉落配置数据(配置格式和怪物掉落配置格式一样,须单独文件形式) // drops={ // { id=375 ,count=1,strong =0,quality =2,propability=1, group=1}, // { id=380 ,count=1,strong =0,quality =2,propability=1, group=1}, // { id=382 ,count=1,strong =0,quality =2,propability=1, group=1}, // } void load(const char *pFile); // 执行一次掉落 DropItemList drop(void * pEntity =0); //按概率和执行掉落 DropItemList proabilityDrop(void * pEntity =0); }; // 宝箱掉落管理器 class CBoxDropMgr { // 获取宝箱掉落管理器对象 static CBoxDropMgr& getSingleton(); // 创建一个指定名称的宝箱对象 CBoxDrop* createBoxDrop(const char *pKey); }; // 掉落物品信息 class DropItemInfo { unsigned char btAwardType; // 奖励类型 unsigned short wItemId; // 物品id unsigned char btQuality; // 物品品质 unsigned char btStrong; // 物品强化等级 unsigned char btBind; // 物品绑定属性 int btCount; // 物品数量 unsigned char btAuxParam; // 辅助参数 unsigned int nTime; // 剩余存在时间,秒为单位 unsigned short nQualityDataIndex; //生成极品属性 }; // 掉落物品列表(包含多个掉落物品) class DropItemList { unsigned int moneyCount; // 金钱数目 unsigned int itemCount; // 物品数目 DropItemInfo itemList[MAX_DROP_ITEM_COUNT]; // 物品列表 };