Blame view

src/actions/RadioAction.lua 8.65 KB
782ee57d   liuzujun   多编队功能
1
2
  local _M = {}
  
16634605   liuzujun   多队挂机,天赋道具合成
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  -- 获取英雄大成功率
  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
782ee57d   liuzujun   多编队功能
23
  
16634605   liuzujun   多队挂机,天赋道具合成
24
      return result + (rareMap[rare] or 0)
782ee57d   liuzujun   多编队功能
25
26
  end
  
16634605   liuzujun   多队挂机,天赋道具合成
27
28
29
30
31
32
33
34
35
  local function getQuestMax(role)
      local count = 0
      for _, carbonId in ipairs(globalCsv.crusade_team_unlock or {}) do
          if role:checkHangPass(carbonId) then
              count = count + 1
          end
      end
  
      return count + (globalCsv.cursade_team_count_initial or 0)
782ee57d   liuzujun   多编队功能
36
37
  end
  
eab5a2d4   zhangqijia   feat: 讨伐电台终止派遣改为消...
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
108
109
110
  local function getCrusadeReward(role, id)
      local radioTask = role:getProperty("radioTask")
      local task = radioTask[id]
      if not task then return 1 end
      --  check id
      local config = csvdb["crusadeCsv"][id]
      if not config then return 2 end
      local carbonData = csvdb["idle_battleCsv"][config.unlock]
      if not carbonData then return 3 end
      --  get heros
      local totalCoef = 0
      local exp = config.time / 60
      local heroFaithMap = {}
      for _, heroId in ipairs(task.heros) do
          local hero = role.heros[heroId]
          if hero then
              totalCoef = totalCoef + getHeroCoef(hero, config.success)
              -- 增加英雄信赖
              hero:addHeroFaith(exp)
              heroFaithMap[heroId] = hero:getProperty("faith")
          end
      end
      -- send award
      local bigSuccess = false
      local result = math.randomInt(0, 100)
      if result < totalCoef then
          bigSuccess = true
      end
      local money = math.ceil(carbonData.money / 5) * config.time * config.money_clear
      local exp = math.ceil(carbonData.exp / 5) * config.time * config.exp_clear
      local itemReward = config.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
  
      local r, change = role:award(itemReward, {log = {desc = "radioQuest", int1 = id}})
  
      radioTask[id] = nil
      role:updateProperty({field="radioTask", value=radioTask, notNotify = true})
  
      local msg = role:packReward(r, change)
      msg["big"] = bigSuccess
      msg["id"] = id
      msg["heroFaith"] = heroFaithMap
  
      role:checkTaskEnter("RadioTaskStart", {heroCnt = #task.heros})
  
      local herolist = {}
      for _, heroId in ipairs(task.heros) do
          local hero = role.heros[heroId]
          if hero then
              table.insert(herolist, hero:getProperty("type"))
          end
      end
  
      --  讨伐行动
      role:log("punitive_action", {
          mission_id	= id, --关卡ID
          mission_herolist = herolist, -- 英雄ID,排序以玩家出战设置为准,示例:[111, 222, 333, 444, 555]
          mission_success_rate = totalCoef, -- 大成功几率
          mission_reward = r, -- 获得奖励,建议使用json格式记录。示例:{ itemid1: 1,  itemid2: 3,  itemid3: 5}
          mission_result = 1, -- 战斗结果(0-无效,1-胜利,2-失败)
          mission_roundtime = config.time, -- 完成耗时(秒)
          mission_cleartype = 2,  -- 1-开始; 2-完成(领取奖励时)
      })
      role:mylog("role_action", {desc = "radioTask", int1 = id, short1 = bigSuccess and 1 or 0})
      return msg
  end
  
782ee57d   liuzujun   多编队功能
111
112
113
114
115
  function _M.startQuestRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
  	local heros = msg.heros
c5fe43c2   zhangqijia   fix: 活动派遣不占用正常讨伐电...
116
  
782ee57d   liuzujun   多编队功能
117
      --  check id
16634605   liuzujun   多队挂机,天赋道具合成
118
      local config = csvdb["crusadeCsv"][id]
c5fe43c2   zhangqijia   fix: 活动派遣不占用正常讨伐电...
119
120
121
122
      if not config then return 1 end
  
      local radioTask = role:getProperty("radioTask")
  
21c09fa2   zhangqijia   fix: 活动派遣 同时只能有一个存在
123
124
      local getActIDs = function ()
          local actids = {}
c5fe43c2   zhangqijia   fix: 活动派遣不占用正常讨伐电...
125
          for _, v in pairs(radioTask or {}) do
21c09fa2   zhangqijia   fix: 活动派遣 同时只能有一个存在
126
              actids[v.actid] = (actids[v.actid] or 0) + 1
c5fe43c2   zhangqijia   fix: 活动派遣不占用正常讨伐电...
127
          end
21c09fa2   zhangqijia   fix: 活动派遣 同时只能有一个存在
128
          return actids
c5fe43c2   zhangqijia   fix: 活动派遣不占用正常讨伐电...
129
130
      end
  
21c09fa2   zhangqijia   fix: 活动派遣 同时只能有一个存在
131
      local actids = getActIDs()
c5fe43c2   zhangqijia   fix: 活动派遣不占用正常讨伐电...
132
      if config.activity_ctrl_id == 0 then
21c09fa2   zhangqijia   fix: 活动派遣 同时只能有一个存在
133
134
          --非活动 判断数量
          if (actids[config.activity_ctrl_id] or 0) >= getQuestMax(role) then
c5fe43c2   zhangqijia   fix: 活动派遣不占用正常讨伐电...
135
136
              return 2
          end
21c09fa2   zhangqijia   fix: 活动派遣 同时只能有一个存在
137
138
139
140
141
142
  
      else
          --活动 同时只能有一个存在
          if actids[config.activity_ctrl_id] >= 1 then
              return 5
          end
c5fe43c2   zhangqijia   fix: 活动派遣不占用正常讨伐电...
143
144
      end
  
16634605   liuzujun   多队挂机,天赋道具合成
145
146
      if not role:checkHangPass(config.unlock) then return 3 end
      if radioTask[id] then return 4 end
782ee57d   liuzujun   多编队功能
147
      --  check hero
16634605   liuzujun   多队挂机,天赋道具合成
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
      --1=指定等级=人数
      --2=指定稀有度=人数 
      --3=人数
      local needHeroCnt = 0
      local lvlMap = {}
      local rareMap = {}
      for _, it in ipairs(config.condition:toTableArray(true)) do
          local type = it[1]
          if type == 1 then
              lvlMap[1] = it[2]
              lvlMap[2] = it[3]
          elseif type == 2 then
              rareMap[1] = it[2]
              rareMap[2] = it[3]
          elseif type == 3 then
              needHeroCnt = it[2]
          end
      end
cf1d48e8   liuzujun   多队挂机70005报错 Bug
166
      for _, heroId in pairs(heros) do
16634605   liuzujun   多队挂机,天赋道具合成
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
          local hero = role.heros[heroId]
          if hero then
              needHeroCnt = needHeroCnt - 1
              if next(lvlMap) then
                  if hero:getProperty("level") >= lvlMap[1] then
                      lvlMap[2] = lvlMap[2] - 1
                      if lvlMap[2] <= 0 then
                          lvlMap = {}
                      end
                  end
              end
              if next(rareMap) then
                  if hero:getRare() >= rareMap[1] then
                      rareMap[2] = rareMap[2] - 1
                  end
                      if rareMap[2] <= 0 then
                          rareMap = {}
                      end
              end
          end
      end
      if needHeroCnt > 0 or next(rareMap) or next(lvlMap) then
          return 5
      end
782ee57d   liuzujun   多编队功能
191
      -- start quest, set finish time
40b19300   chenyueqi   电波塔激活加成效果后对各个系统的加成
192
      local timeSub = role:getBnousCrusade(config.time)
16634605   liuzujun   多队挂机,天赋道具合成
193
      local taskData = {}
40b19300   chenyueqi   电波塔激活加成效果后对各个系统的加成
194
      taskData["time"] = skynet.timex() + config.time + timeSub
16634605   liuzujun   多队挂机,天赋道具合成
195
      taskData["heros"] = heros
c5fe43c2   zhangqijia   fix: 活动派遣不占用正常讨伐电...
196
      taskData["actid"] = config.activity_ctrl_id
16634605   liuzujun   多队挂机,天赋道具合成
197
198
      radioTask[id] = taskData
      role:updateProperty({field="radioTask", value=radioTask, notNotify=true})
782ee57d   liuzujun   多编队功能
199
  
f76d63e1   liuzujun   联动任务活动
200
      SendPacket(actionCodes.Radio_startQuestRpc, MsgPack.pack({id=id, task=taskData}))
5b4db3a3   liuzujun   增加电台任务日志完成类型
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
  
      local herolist = {}
      for _, heroId in ipairs(heros) do
          local hero = role.heros[heroId]
          if hero then
              table.insert(herolist, hero:getProperty("type"))
          end
      end
  
  	--  讨伐行动 
  	role:log("punitive_action", {
  		mission_id	= id, --关卡ID
  		mission_herolist = herolist, -- 英雄ID,排序以玩家出战设置为准,示例:[111, 222, 333, 444, 555]
  		mission_success_rate = 0, -- 大成功几率
  		mission_reward = {}, -- 获得奖励,建议使用json格式记录。示例:{ itemid1: 1,  itemid2: 3,  itemid3: 5}
  		mission_result = 0, -- 战斗结果(0-无效,1-胜利,2-失败)
          mission_roundtime = 0, -- 完成耗时(秒)
          mission_cleartype = 1,  -- 1-开始; 2-完成(领取奖励时)
  	})
782ee57d   liuzujun   多编队功能
220
221
222
223
224
225
226
  	return true
  end
  
  function _M.finishQuestRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
782ee57d   liuzujun   多编队功能
227
      -- check finish time
16634605   liuzujun   多队挂机,天赋道具合成
228
229
      local radioTask = role:getProperty("radioTask")
      local task = radioTask[id]
eab5a2d4   zhangqijia   feat: 讨伐电台终止派遣改为消...
230
231
232
233
234
235
236
237
      if not task then return 4 end
      if skynet.timex() < task.time then return 5 end
  
      local reward = getCrusadeReward(role, id)
      if type(reward) == "number" then
          return reward
      else
          SendPacket(actionCodes.Radio_finishQuestRpc, MsgPack.pack(reward))
6a2b449c   liuzujun   扭蛋机奖励不合并显示, 新增多队挂...
238
      end
782ee57d   liuzujun   多编队功能
239
240
241
  	return true
  end
  
4f7cffe5   liuzujun   多队挂机任务取消功能,累充奖励
242
243
244
245
246
247
248
  function _M.cancelQuestRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
      -- check finish time
      local radioTask = role:getProperty("radioTask")
      local task = radioTask[id]
eab5a2d4   zhangqijia   feat: 讨伐电台终止派遣改为消...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
      if not task then return 4 end
      if skynet.timex() > task.time then return 5 end
  
      local remainT = task.time - skynet.timex()
      if remainT > 0 then
          local cost = math.ceil(remainT / 3600) * globalCsv.crusade_quicken
          if not role:checkItemEnough({[ItemId.Jade] = cost}) then return 6 end
          role:costItems({[ItemId.Jade] = cost}, {log = {desc = "radioQuest", int1 = id}})
          local reward = getCrusadeReward(role, id)
          if type(reward) == "number" then
              return reward
          else
              SendPacket(actionCodes.Radio_cancelQuestRpc, MsgPack.pack(reward))
          end
      else
          SendPacket(actionCodes.Radio_cancelQuestRpc, MsgPack.pack({id = id}))
      end
4f7cffe5   liuzujun   多队挂机任务取消功能,累充奖励
266
267
268
      return true
  end
  
782ee57d   liuzujun   多编队功能
269
  return _M