module (..., package.seeall)
local ShopM = {}
local SystemPrompt = require(__APP_PACKAGE_NAME__ .. ".scenes.common.SystemPrompt")
local Item = require("res.scripts.data.model.Item"); function ShopM:init()
-- 每个数据类都有一个对应的id
self.mid = getNextID();
self.refeshCountDown =
self.CurrentItem = {};
self.NowItem = nil;
-- 从配置表中获取配置数据,这里是以json的形式
self.shopprop = DB.getTable("shopprop")[]
self.shopitemprop = DB.getTable("shopitemprop")
if self.shopprop == nil then
printf("shopprop is nil");
end
if self.shopitemprop == nil then
printf("shopitemprop is nil");
end
-- 注册网络消息,用于接收服务器返回的数据,并对数据进行处理
NetController:registerMsg(MsgID.msgid_P_OPSHOP_ACK, self.mid, function ( dwSessionID, wMsgSID, wMsgID, pszMsg )
print("==============打开背包界面==============")
-- 将json数据转成表的格式
self.openNetData = CJson.decode(pszMsg);
if ~= self.openNetData.ErrCode then
SystemPrompt.new(Errdef.ERR_ALL[self.openNetData.ErrCode]);
SceneM.destroyNetLayer();
return
end
-- 处理数据
self:setData(self.openNetData);
-- 发送本地的事件消息
NotificationCenter:postEvent(MsgID.msgid_P_OPSHOP_ACK, {});
end, MAXPRIORITY); NetController:registerMsg(MsgID.msgid_P_BITEM_ACK, self.mid, function ( dwSessionID, wMsgSID, wMsgID, pszMsg )
print("==============购买道具==============")
self.openNetData = CJson.decode(pszMsg);
if ~= self.openNetData.ErrCode then
UISystemTips:SystemTips(self.openNetData.ErrCode);
return
end
self:setDataAfterBuy(self.openNetData);
NotificationCenter:postEvent(MsgID.msgid_P_BITEM_ACK, {});
end, MAXPRIORITY); NetController:registerMsg(MsgID.msgid_P_RITEM_ACK, self.mid, function ( dwSessionID, wMsgSID, wMsgID, pszMsg )
print("==============刷新道具==============")
self.openNetData = CJson.decode(pszMsg);
if ~= self.openNetData.ErrCode then
SystemPrompt.new(Errdef.ERR_ALL[self.openNetData.ErrCode]);
SceneM.destroyNetLayer();
return
end
self:setData(self.openNetData);
NotificationCenter:postEvent(MsgID.msgid_P_RITEM_ACK, {});
end, MAXPRIORITY); end function ShopM:cleanup( ) end function ShopM:setData( data )
self.itemList = {};
self.gridList = {};
local pos = ;
local itemInfo = data.ItemInfo
for i = , #itemInfo do
print("========ShopM:setData========" .. itemInfo[i].KindID);
local kindID = itemInfo[i].KindID
local num = itemInfo[i].Num
local itemType = math.modf(kindID/);
local itemData={ID=kindID, Idx=, Level=, Num=num}
self.itemList[pos] = Item.new(itemType, pos, itemData)
if kindID == then
self.itemList[pos].sell = -;
end
pos = pos+
end printf("ShopM:setData RCD:" .. data.RCD)
self.refeshCountDown = data.RCD
PlayerM:getBaseData().coin = data.CurCoin;
PlayerM:getBaseData().gold = data.CurGold;
end function ShopM:setDataAfterBuy( data )
printf(" before buy num:" .. #self.itemList)
if self.itemList[data.GridIdx] == nil then
printf(" item[" .. data.GridIdx .. "] is nil")
end
self.itemList[data.GridIdx].sell = -;
printf(" after buy num:" .. #self.itemList)
PlayerM:getBaseData().coin = data.CurCoin;
PlayerM:getBaseData().gold = data.CurGold;
end function ShopM:getItemLst( )
return self.itemList
end function ShopM:getShowGridNum( )
return -- todo
end function ShopM:getRefeshCountDown( )
return self.refeshCountDown
end function ShopM:getRefeshGold( )
if self.shopprop == nil then
return
end
return self.shopprop.NoCDGold
end
function ShopM:getRefeshCoin( )
printf("getRefeshCoin")
if self.shopprop == nil then
printf("getRefeshCoin2")
return
end
printf("getRefeshCoin3")
return self.shopprop.RefreshCoin
end function ShopM:getBuyGold( gridIdx )
printf("getBuyGold:" .. gridIdx)
if self.shopitemprop == nil then
printf("getBuyGold2")
return
end local gridProp = self.shopitemprop[gridIdx]
if gridProp == nil then
printf("getBuyGold3")
return
end
printf("======gridProp.BuyGold=======" .. gridProp.BuyGold);
return gridProp.BuyGold
end function ShopM:getBuyCoin( gridIdx )
if self.shopitemprop == nil then
return
end local gridProp = self.shopitemprop[gridIdx]
if gridProp == nil then
return
end
return gridProp.BuyCoin
end -- 这里要有一个return
return ShopM;

lua -- 商店的数据管理类的更多相关文章

  1. cocos进阶教程(1)Lua调用自定义C++类和函数的最佳实践

    第一层:纯C环境下,把C函数注册进Lua环境 a.lua 文件 )) a.c 文件 #include <lua.h> #include <lualib.h> #include ...

  2. Cocos2d-x下Lua调用自定义C++类和函数的最佳实践[转]

    Cocos2d-x下Lua调用C++这事之所以看起来这么复杂.网上所有的文档都没讲清楚,是因为存在5个层面的知识点: 1.在纯C环境下,把C函数注册进Lua环境,理解Lua和C之间可以互相调用的本质 ...

  3. 【转】Cocos2d-x下Lua调用自定义C++类和函数的最佳实践

    转自:http://segmentfault.com/blog/hongliang/1190000000631630 关于cocos2d-x下Lua调用C++的文档看了不少,但没有一篇真正把这事给讲明 ...

  4. Lua调用自定义C++类

    弄了一天终于会Lua调用自定义C++类.不容易啊. 我的电脑是64位的,装了64的Python不行,装了32位的就可以了,靠!下面是报错信息 python pyyaml Cheetah全都是装32位的 ...

  5. cocos2d-x 3.0 在lua中调用自定义类

    环境 windows8, cocos2d-x 3.0, 现在开始安装需要的一些其它包 1. 按README.mdown文档上面要求的, 下载在windows下要安装的东东, 主要就是python2.7 ...

  6. Cocos2d-x Lua中Sprite精灵类

    精灵类是Sprite,它的类图如下图所示. Sprite类图 Sprite类直接继承了Node类,具有Node基本特征.此外,我们还可以看到Sprite类的子类有:PhysicsSprite和Skin ...

  7. 【Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之四】使用绑定C++至Lua的自己定义类

    续[Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之三]动手绑定自己定义类至Lua 之后.我们已经完毕了自己定义类至Lua的绑定.在接下来的环节,我们将使用它. 首先,我们须要确定 ...

  8. ulua c#调用lua中模拟的类成员函数

    项目使用ulua,我神烦这个东西.lua单纯在lua环境使用还好,一旦要跟外界交互,各种月经不调就来了.要记住贼多的细节,你才能稍微处理好.一个破栈,pop来push去,位置一会在-1,一会在-3,2 ...

  9. lua的table元类

    Lua中提供的元表是用于帮助Lua数据变量完成某些非预定义功能的个性化行为,如两个table的相加.假设a和b都是table,通过元表可以定义如何计算表达式a+b.当Lua试图将两个table相加时, ...

随机推荐

  1. JUC-线程池调度-ScheduledThreadPool

    线程调度使用类:ScheduledExecutorService 创建线程池调度类对象: ScheduledExecutorService pool = Executors.newScheduledT ...

  2. Vivaldi浏览器媲美Chrome

    Vivaldi跨平台的浏览器,很好的兼容性...基本上跟Chrome一个层次的... 好的东西,用一次就明白!好酒,酒香巷子深... Download: https://vivaldi.com/dow ...

  3. DPDK无法分出连续大页面(contiguous hugepages)的几个解决方法

    在使用DPDK或者SPDK的时候,需要在进程刚启动的时候使用rte_eal_init初始化Environment Abstract Layer,应用进程会通过这个函数告诉EAL为它映射多大的hugep ...

  4. Indy Changed from Indy10

    Indy Changed from Indy10 http://stackoverflow.com/questions/16339656/delphi-xe4-indy-compatibility-i ...

  5. 有关于malloc申请内存和free内存释放

    malloc工作机制: malloc函数的实质体现在,它有一个将可用的内存块连接为一个长长的列表的所谓空闲链表(堆内存).调用malloc函数时,它沿连接表寻找一个大到足以满足用户请求所需要的内存块. ...

  6. magento登陆

    magento判断用户登录 Magento 登陆之后返回登录之前的页面 magento 在登陆后一般会自动跳转到 My Account 页面 但是经常会有需求 就是登陆自动跳转到 之前的页面里面 工具 ...

  7. 【Servlet】深入浅出JavaServlet重定向和请求转发

    import java.text.*; import java.util.*; import java.io.*; import javax.servlet.http.*; import javax. ...

  8. 新建MVC3 编译出现 System.Web.Mvc.ModelClientValidationRule

    我在vs2010 新建一个Mvc3项目,编译报一下错误: 错误 1 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\A ...

  9. [Warning] TIMESTAMP with implicit DEFAULT value is deprecated

    启动mysql时,报如下警告信息: [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explic ...

  10. appium简明教程(5)——appium client方法一览

    appium client扩展了原生的webdriver client方法 下面以java代码为例,简单过一下appium client提供的适合移动端使用的新方法 resetApp() getApp ...