• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

lua--商店的数据管理类

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
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 = 0
    self.CurrentItem = {};
    self.NowItem = nil;
    -- 从配置表中获取配置数据,这里是以json的形式
    self.shopprop = DB.getTable("shopprop")[1]
    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 0 ~= 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 0 ~= 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 0 ~= 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 = 1;
    local itemInfo = data.ItemInfo
    for i = 1, #itemInfo do
        print("========ShopM:setData========" .. itemInfo[i].KindID);
        local kindID = itemInfo[i].KindID
        local num = itemInfo[i].Num
        local itemType = math.modf(kindID/10000);
        local itemData={ID=kindID, Idx=0, Level=0, Num=num}
        self.itemList[pos] = Item.new(itemType, pos, itemData)    
        if kindID == 0 then
            self.itemList[pos].sell = -1;
        end    
        pos = pos+1
    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 = -1;
    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 12 -- todo
end

function ShopM:getRefeshCountDown( )
    return self.refeshCountDown
end

function ShopM:getRefeshGold(  )    
    if self.shopprop == nil then
        return 65535
    end
    return self.shopprop.NoCDGold
end
function ShopM:getRefeshCoin(  )
    printf("getRefeshCoin")
    if self.shopprop == nil then
        printf("getRefeshCoin2")
        return 65535
    end
    printf("getRefeshCoin3")
    return self.shopprop.RefreshCoin
end

function ShopM:getBuyGold( gridIdx )
    printf("getBuyGold:" .. gridIdx)
    if self.shopitemprop == nil then
        printf("getBuyGold2")
        return 65535
    end

    local gridProp = self.shopitemprop[gridIdx]
    if gridProp == nil then
        printf("getBuyGold3")
        return 65535
    end
    printf("======gridProp.BuyGold=======" .. gridProp.BuyGold);
    return gridProp.BuyGold
end

function ShopM:getBuyCoin( gridIdx )
    if self.shopitemprop == nil then
        return 65535
    end

    local gridProp = self.shopitemprop[gridIdx]
    if gridProp == nil then
        return 65535
    end
    return gridProp.BuyCoin
end

-- 这里要有一个return
return ShopM;

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
win7 VS2013 新建工程 编译lua5.2.0 静态库发布时间:2022-07-22
下一篇:
Lua及基本语法发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap