65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
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 
 | 
  local ipairs = ipairs
  local table = table
  local math = math
  local redisproxy = redisproxy
  local MsgPack = MsgPack
  
  local _M = {}
  
  function _M.getServerProcessRpc(agent, data)
  	local role = agent.role
  	local result = role:getSeaportServerProgress()
  
  	SendPacket(actionCodes.Seaport_getServerProcessRpc, MsgPack.pack(result))
  	return true
  end
  
  function _M.donateRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	
  	local phase = msg.phase or 0
  	local id = msg.id or 0
  	local itemId = msg.itemId or 0
  	local itemCount = msg.count or 0
  
  	if itemId == 0 or itemCount == 0 then return 0 end
  	if role:getItemCount(itemId) < itemCount then return 1 end
  	local DonateCsv = csvdb["seaport_purchaseCsv"]
 
 | 
5fb0ac5f
 
  liguanghui
 
海港贸易相关bug修复
 | 
29 
 | 
  	if not DonateCsv[phase] or not DonateCsv[phase][id] then return 2 end
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
30 
 | 
  
 
 | 
e820b3f3
 
  chenyueqi
 
海港贸易季bug修正
 | 
31
32 
 | 
  	local ddata = DonateCsv[phase][id]
  	local needs = ddata.need_item:toArray(true,"=")
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
33
34
35
36 
 | 
  	if itemId ~= needs[1] then return 3 end
  	if itemCount % needs[2] ~= 0 then return 4 end
  
  	local group = itemCount / needs[2]
 
 | 
e820b3f3
 
  chenyueqi
 
海港贸易季bug修正
 | 
37 
 | 
  	local rewards = ddata.award:toNumMap()
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
38
39
40
41
42 
 | 
  
  	for id, value in pairs(rewards) do
  		rewards[id] = value * group
  	end
  
 
 | 
e820b3f3
 
  chenyueqi
 
海港贸易季bug修正
 | 
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 
 | 
  	if phase == 1 then
  		local old = tonumber(redisproxy:hget(SEAPORT_TRADE_TASK_1,id)) or 0
  		local need = ddata.need_num - old
  		if need >= itemCount then
  			redisproxy:hincrby(SEAPORT_TRADE_TASK_1,id,itemCount)
  		else
  			redisproxy:hincrby(SEAPORT_TRADE_TASK_1,id,need)
  			for _, temp in pairs(DonateCsv[2]) do
  				local items = temp.need_item:toArray(true,"=")
  				if items[1] == itemId then
  					redisproxy:hincrby(SEAPORT_TRADE_TASK_2,temp.id,itemCount - need)
  					break
  				end
  			end
  		end
  	else
  		redisproxy:hincrby(SEAPORT_TRADE_TASK_2,id,itemCount)
  	end
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
61
62 
 | 
  
  	role:costItems({[itemId] = itemCount}, {log = {desc = "seaportDonate", int1 = phase, int2 = id}})
 
 | 
e820b3f3
 
  chenyueqi
 
海港贸易季bug修正
 | 
63 
 | 
  	local reward, change = role:award(rewards, {log = {desc = "seaportDonate", int1 = ddata.phase, int2 = ddata.id}})
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141 
 | 
  
  	role:mylog("role_action", {desc = "seaportDonate", int1 = itemId, int2 = itemCount})
  
  	SendPacket(actionCodes.Seaport_donateRpc, MsgPack.pack(role:packReward(reward, change)))
  	return true
  end
  
  function _M.donateRewardRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local id = msg.id
  	local dataCsv = csvdb["seaport_purchaseCsv"]
  	if not dataCsv[id] then return 0 end
  
  	local seaport = role:getProperty("seaport") or {}
  	local donate = seaport.donate or {}
  	if donate[id] then return 3 end
  
  	local data = dataCsv[id][1]
  
  	local result = role:getSeaportServerProgress()
  	if not result[id] then return 1 end
  
  	for _, tempData in ipairs(dataCsv[id]) do
  		if tempData.need_num > (result[id][tempData.id] or 0) then
  			return 2
  		end
  	end
  
  	donate[id] = 1
  	seaport.donate = donate
  
  	local reward, change = role:award(data.phase_award, {log = {desc = "seaportReward", int1 = data.phase, int2 = data.id}})
  
  	role:updateProperty({field = "seaport", value = seaport})
  	SendPacket(actionCodes.Seaport_donateRewardRpc, MsgPack.pack(role:packReward(reward, change)))
  	return true
  end
  
  -- 获取英雄大成功率
  local function getHeroCoef(hero, condition)
      -- 基础概率
      local rareMap = {[HeroQuality.N] = 10, [HeroQuality.R] = 10, [HeroQuality.SR] = 15, [HeroQuality.SSR] = 20}
      local rare = hero:getRare()
      local result = 0
      for _, it in ipairs(condition:toTableArray(true)) do
          local type = it[1]
          local value = it[2]
          local add = it[3]
          if type == 1 then   -- 种族加成
              if hero:getCamp() == value then
                  result = result + add
              end
          elseif type == 2 then   -- 定位加成
              if hero:getPosition() == value then
                  result = result + add
              end
          end
      end
  
      return result + (rareMap[rare] or 0)
  end
  
  function _M.taskRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local oper = msg.oper or 0
  	local team = msg.team or ""
  	local taskId = msg.id or 0
  	local level = msg.level or 0
  
  	if oper == 0 then return 0 end
  	local TaskCsv = csvdb["seaport_taskCsv"]
  	if not TaskCsv[taskId] or not TaskCsv[taskId][level] then return 1 end
  
  	local reward, change = {}, {}
 
 | 
18478207
 
  chenyueqi
 
贸易季委托要返回英雄的信赖值
 | 
142 
 | 
  	local heroFaithMap = {}
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
143
144
145 
 | 
  	local seaport = role:getProperty("seaport")
  
  	local data = TaskCsv[taskId][level]
 
 | 
0f2ede8d
 
  chenyueqi
 
海港贸易季委托任务奖励计算错误
 | 
146
147
148
149
150
151 
 | 
  	if data.phase == 2 then
  		local openTime = tonumber(redisproxy:hget("autoincrement_set", "seaportTime0")) or 0
  		local nowTime = skynet.timex()
  		if nowTime < (openTime + 86400) or nowTime > (openTime + 172800) then return 9 end
  	end
  
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
152
153 
 | 
  	if oper == 1 then -- 开始委托
  		if team == "" then return 3 end
 
 | 
b8788f58
 
  chenyueqi
 
海港贸易季委托增加魔导石加速完成
 | 
154 
 | 
  		local conditions = data.condition:toTableArray(true)
 
 | 
1dc5abc2
 
  chenyueqi
 
字符串分割错误遗漏
 | 
155
156 
 | 
  		local heros = team:toArray(true,"=")
  		if not next(heros) then return 8 end
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
157
158
159
160
161 
 | 
  		local UnitCsv = csvdb["unitCsv"]
  		for _, conds in pairs(conditions) do
  			local count = 0
  			for _, heroId in pairs(heros) do
  				local hero = role.heros[heroId]
 
 | 
1dc5abc2
 
  chenyueqi
 
字符串分割错误遗漏
 | 
162 
 | 
  				if not hero then return 8 end
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193 
 | 
  
  				if conds[1] == 1 then
  					if hero:getProperty("level") >= conds[2] then
  						count = count + 1
  					end
  				elseif conds[1] == 2 then
  					if UnitCsv[hero:getProperty("type")].rare >= conds[2] then
  						count = count + 1
  					end
  				elseif conds[1] == 3 then
  					count = count + 1
  				end
  			end
  			if count < conds[#conds] then
  				return 4
  			end
  		end
  
  		local collect = seaport.collect or {}
  		collect[taskId] = {}
  		collect[taskId].time = skynet.timex()
  		collect[taskId].level = level
  		collect[taskId].team = team
  
  		seaport.collect = collect
  	elseif oper == 2 then -- 领取委托奖励
  		local collects = seaport.collect or {}
  		local collect = collects[taskId] or {}
  		if not next(collects) or not next(collect) then
  			return 5
  		end
 
 | 
b8788f58
 
  chenyueqi
 
海港贸易季委托增加魔导石加速完成
 | 
194 
 | 
  		local quick = msg.quick
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
195 
 | 
  		local endTime = data.time + collect.time
 
 | 
cee86c7b
 
  liguanghui
 
bug修复:海港贸易委托无法领取奖励
 | 
196 
 | 
  		local remainT = endTime - skynet.timex()
 
 | 
b8788f58
 
  chenyueqi
 
海港贸易季委托增加魔导石加速完成
 | 
197
198
199
200
201
202
203 
 | 
  		if not quick and remainT > 0 then return 6 end
  
  		if quick and remainT > 0 then
  			local cost = math.ceil(remainT / 3600) * globalCsv.seaport_task_quick
  			if not role:checkItemEnough({[ItemId.Diamond] = cost}) then return 8 end
  			role:costItems({[ItemId.Diamond] = cost}, {log = {desc = "seaportTask", int1 = taskId, int2 = level}})
  		end
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
204
205
206 
 | 
  
  		local carbonCsv = csvdb["idle_battleCsv"]
  		local expCarbonId = role:getProperty("hangInfo").expCarbonId
 
 | 
0f2ede8d
 
  chenyueqi
 
海港贸易季委托任务奖励计算错误
 | 
207 
 | 
  		if not carbonCsv[expCarbonId] then return 7 end
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
208
209 
 | 
  
  		local totalCoef = 0
 
 | 
9fc8b7f0
 
  chenyueqi
 
分割字符串错误
 | 
210 
 | 
  	    for _, heroId in ipairs(collect.team:toArray(true,"=")) do
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
211
212
213
214 
 | 
  	        local hero = role.heros[heroId]
  	        if hero then
  	            totalCoef = totalCoef + getHeroCoef(hero, data.success)
  	            hero:addHeroFaith(data.trust)
 
 | 
18478207
 
  chenyueqi
 
贸易季委托要返回英雄的信赖值
 | 
215 
 | 
  	            heroFaithMap[heroId] = hero:getProperty("faith")
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
216
217
218
219
220
221
222
223
224 
 | 
  	        end
      	end
  
  		local bigSuccess = false
  	    local result = math.randomInt(0, 100)
  	    if result < totalCoef then
  	        bigSuccess = true
  	    end
  
 
 | 
0f2ede8d
 
  chenyueqi
 
海港贸易季委托任务奖励计算错误
 | 
225
226 
 | 
  		local money = math.ceil(carbonCsv[expCarbonId].money / 5 * data.time * data.money_clear)
  		local exp = math.ceil(carbonCsv[expCarbonId].exp / 5 * data.time * data.exp_clear)
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245 
 | 
  		local itemReward = data.item_clear_special:toNumMap()
  		itemReward[ItemId.Gold] = (itemReward[ItemId.Gold] or 0) + money
      	itemReward[ItemId.Exp] = (itemReward[ItemId.Exp] or 0) + exp
      
  		if bigSuccess then
  	        for key, value in pairs(itemReward) do
  	            itemReward[key] = math.ceil(1.5 * value)
  	        end
  	    end
  
  	    reward, change = role:award(itemReward, {log = {desc = "seaportTask", int1 = taskId, int2 = level}})
  
  		seaport.collect[taskId] = nil
  	else
  		return 0
  	end
  
  	role:updateProperty({field = "seaport", value = seaport})
  
 
 | 
18478207
 
  chenyueqi
 
贸易季委托要返回英雄的信赖值
 | 
246
247
248
249 
 | 
  	local result = role:packReward(reward, change)
  	result["heroFaith"] = heroFaithMap
  
  	SendPacket(actionCodes.Seaport_taskRpc, MsgPack.pack(result))
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
250
251
252
253
254
255
256
257
258 
 | 
  	return true
  end
  
  function _M.shopRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id or 0
  	local count = msg.count or 1
  
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
259
260 
 | 
  	local shopCsv = {}
  	local dataSet = csvdb["shop_normalCsv"]
 
 | 
5fb0ac5f
 
  liguanghui
 
海港贸易相关bug修复
 | 
261
262
263 
 | 
  	for _, datat in pairs(dataSet) do
  		if datat.shop == 5 then
  			shopCsv[datat.id] = datat
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
264
265 
 | 
  		end
  	end
 
 | 
5fb0ac5f
 
  liguanghui
 
海港贸易相关bug修复
 | 
266
267
268 
 | 
  	local sdata = shopCsv[id]
  	
  	if not sdata then return 2 end
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
269 
 | 
  
 
 | 
5fb0ac5f
 
  liguanghui
 
海港贸易相关bug修复
 | 
270
271
272
273
274
275
276
277 
 | 
  	local seaport = role:getProperty("seaport")
  	local shop = seaport.shop or {}
  
  	if (shop[id] or 0) >= sdata.limit then return 1 end
  
  	
  
  	
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
278 
 | 
  
 
 | 
5fb0ac5f
 
  liguanghui
 
海港贸易相关bug修复
 | 
279 
 | 
  	if role:getItemCount(sdata.icon) < sdata.cost * count then return 3 end
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
280 
 | 
  
 
 | 
5fb0ac5f
 
  liguanghui
 
海港贸易相关bug修复
 | 
281 
 | 
  	role:costItems({[sdata.icon] = sdata.cost * count}, {log = {desc = "seaportShop", int1 = id, int2 = count}})
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
282 
 | 
  
 
 | 
5fb0ac5f
 
  liguanghui
 
海港贸易相关bug修复
 | 
283 
 | 
  	local itemReward = sdata.gift:toNumMap()
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
284
285
286
287
288
289 
 | 
  	for itemId, value in pairs(itemReward) do
  		itemReward[itemId] = value * count
  	end
  
  	local reward, change = role:award(itemReward, {log = {desc = "seaportShop", int1 = id, int2 = count}})
  
 
 | 
ac57fc89
 
  chenyueqi
 
贸易季兑换商店记录次数
 | 
290
291
292 
 | 
  	shop[id] = (shop[id] or 0) + count
  	seaport.shop = shop
  
 
 | 
65b551a7
 
  chenyueqi
 
海港贸易季初版
 | 
293
294
295
296
297
298
299
300
301
302
303
304
305
306 
 | 
  	role:updateProperty({field = "seaport", value = seaport})
  
  	SendPacket(actionCodes.Seaport_shopRpc, MsgPack.pack(role:packReward(reward, change)))
  	return true
  end
  
  function _M.resetRpc(agent, data)
  	local role = agent.role
  	role:checkSeaportTrade()
  	SendPacket(actionCodes.Seaport_resetRpc, MsgPack.pack(""))
  	return true
  end
  
  return _M
 
 |