Blame view

src/actions/StoreAction.lua 2.79 KB
cccc9c70   zhouhaihai   商城
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  local _M = {}
  
  function _M.rechargeRpc(agent , data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
  	local dataSet = csvdb["shop_rechargeCsv"][id]
  	if not dataSet then return end
  	local diamondCount
  	if dataSet.type == 0 then -- 钻石
  		local rechargeF = role:getProperty("rechargeF")
  		diamondCount = dataSet.diamond + dataSet.diamondExtra
  		if not rechargeF[id] then
  			diamondCount = diamondCount + dataSet.diamondFirst
  			rechargeF[id] = 1
  			role:updateProperty({field = "rechargeF", value = rechargeF})
  		end
  		role:gainDiamond({count = diamondCount, isRecharge = true})
  	elseif dataSet.type == 1 then  --月卡
  		return
  	elseif dataSet.type == 2 then  -- 赛季通行证
  		return
  	else
  		return
  	end
  
  	-- 累充
  	local rmb = dataSet.rmb
  	role:updateProperty({field = "rmbC", delta = rmb})
  	
  	SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({diamond = diamondCount}))
  	return true
  end
  
  
  function _M.dailyBuyRpc(agent , data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
  	local count = msg.count or 1
  
  	local dataSet = csvdb["shop_diamondCsv"][id]
  	if not dataSet then return 1 end
  
  	local dailySDC = role.dailyData:getProperty("dailySDC")
  
  	if math.illegalNum(count, 1, (dataSet.limit == 0 and math.huge or dataSet.limit - (dailySDC[id] or 0))) then return 1 end
  
  	local cost = dataSet.cost
  	if dataSet.type == 0 then
  		local dailySDD = role.dailyData:getProperty("dailySDD")
  		if dailySDD[id] then -- 折扣
  			cost = math.ceil(cost * (1 - dataSet.disount / 100))
  		end
  	elseif dataSet.type == 1 then
  	else
  		return 3 
  	end
  
  	if not role:costDiamond({count = cost * count}) then
  		return 4 
  	end
  
  	if dataSet.limit ~= 0 then
  		dailySDC[id] = (dailySDC[id] or 0) + count
  		role.dailyData:updateProperty({field = "dailySDC", value = dailySDC})
  	end
  	local reward = role:award(dataSet.gift)
  
  	SendPacket(actionCodes.Store_dailyBuyRpc, MsgPack.pack({reward = reward}))
  	return true
  end
  
  
  function _M.dinerBuyRpc(agent , data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
  	local count = msg.count or 1
  
  	local dataSet = csvdb["shop_dinerCsv"][id]
  	if not dataSet then return end
  
  	local dinerS = role:getProperty("dinerS")
  	if math.illegalNum(count, 1, (dataSet.limit == 0 and math.huge or dataSet.limit - (dinerS[id] or 0))) then return 1 end
  
  	local cost = {[ItemId.DinerCoin] = dataSet.cost}
  	if not role:checkItemEnough(cost) then return end
  
  	if dataSet.limit ~= 0 then
  		dinerS[id] = (dinerS[id] or 0) + count
  		role:updateProperty({field = "dinerS", value = dinerS})
  	end
  
  	role:costItems(cost)
  
  	local gift = {}
  	for _id, _count in pairs(dataSet.gift:toNumMap()) do
  		gift[_id] = _count * count
  	end
  	local reward = role:award(gift)
  
  	SendPacket(actionCodes.Store_dinerBuyRpc, MsgPack.pack({reward = reward}))
  	return true
  end
  
  return _M