CommonActBoss.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. local Msg = require("core.Msg")
  2. local Grid = require("bag.Grid")
  3. local BagLogic = require("bag.BagLogic")
  4. local AbsActLogic = require("absAct.AbsActLogic")
  5. local Broadcast = require("broadcast.Broadcast")
  6. local Lang = require("common.Lang")
  7. local Config = require("excel.commonact").ectype
  8. local CommonDefine = require("common.CommonDefine")
  9. local Util = require("common.Util")
  10. local CombatDefine = require("combat.CombatDefine")
  11. local CombatLogic = require("combat.CombatLogic")
  12. local YunYingLogic = require("yunying.YunYingLogic")
  13. local AbsActExcel = require("excel.absAct")
  14. local COMMONACTBOSSABSID = 7501
  15. local COMMONACTFREENUM = 3 -- 免费挑战次数
  16. local COMMONACTDAYID = 99
  17. local COMMONACTBOOSPRIZE = 1 -- BOSS奖励类型
  18. local COMMONACTFIGHTPRIZE = 2 -- 战斗奖励类型
  19. local CommonAct_BossID = nil
  20. local CommonAct_MapID = nil
  21. local function ComActBoss_CreateDB(human)
  22. if not human.db.absAct[COMMONACTBOSSABSID] then
  23. human.db.absAct[COMMONACTBOSSABSID] = {}
  24. end
  25. human.db.absAct[COMMONACTBOSSABSID].tBossInfo = {
  26. nFreeNum = COMMONACTFREENUM,
  27. nFreeTime = os.time(),
  28. nDamage = 0,
  29. tPrizeInfo = {}
  30. }
  31. for nID, v in pairs(Config) do
  32. if nID ~= COMMONACTDAYID then
  33. human.db.absAct[COMMONACTBOSSABSID].tBossInfo.tPrizeInfo[nID] = CommonDefine.COMMON_PRIZE_STATE_NOGET
  34. end
  35. end
  36. end
  37. -- 检测并创建DB数据
  38. local function ComActBoss_CheckAndCreateDB(human)
  39. if not human.db.absAct[COMMONACTBOSSABSID] or not human.db.absAct[COMMONACTBOSSABSID].tBossInfo then
  40. ComActBoss_CreateDB(human)
  41. end
  42. end
  43. -- 获取奖励数据
  44. local function CommonActBoss_GetPrizeData(human)
  45. return human.db.absAct[COMMONACTBOSSABSID].tBossInfo.tPrizeInfo
  46. end
  47. -- 获取奖励状态
  48. local function CommonActBoss_GetPrizeStatus(human, nID)
  49. local tPrizeInfo = CommonActBoss_GetPrizeData(human)
  50. return tPrizeInfo[nID]
  51. end
  52. -- 设置奖励状态
  53. local function CommonActBoss_SetPrizeStatus(human, nID, nValue)
  54. local tPrizeInfo = CommonActBoss_GetPrizeData(human)
  55. tPrizeInfo[nID] = nValue
  56. end
  57. -- 获取总伤害
  58. local function CommonActBoss_GetDamage(human)
  59. return human.db.absAct[COMMONACTBOSSABSID].tBossInfo.nDamage
  60. end
  61. -- 增加总伤害
  62. local function CommonActBoss_AddDamage(human, nNum)
  63. human.db.absAct[COMMONACTBOSSABSID].tBossInfo.nDamage = human.db.absAct[COMMONACTBOSSABSID].tBossInfo.nDamage + nNum
  64. end
  65. -- 获取免费次数
  66. local function CommonActBoss_GetFreeNum(human)
  67. return human.db.absAct[COMMONACTBOSSABSID].tBossInfo.nFreeNum
  68. end
  69. -- 设置免费次数
  70. local function CommonActBoss_SetFreeNum(human, nNum)
  71. human.db.absAct[COMMONACTBOSSABSID].tBossInfo.nFreeNum = nNum
  72. end
  73. -- 获取免费刷新时间
  74. local function CommonActBoss_GetFreeTime(human)
  75. return human.db.absAct[COMMONACTBOSSABSID].tBossInfo.nFreeTime
  76. end
  77. -- 设置免费刷新时间
  78. local function CommonActBoss_SetFreeTime(human, nTime)
  79. human.db.absAct[COMMONACTBOSSABSID].tBossInfo.nFreeTime = nTime
  80. end
  81. local function CommonActBoss_IsPrizeRed(human)
  82. for nID, v in pairs(Config) do
  83. if nID ~= COMMONACTDAYID then
  84. local nState = CommonActBoss_GetPrizeStatus(human, nID)
  85. if nState == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  86. return true
  87. end
  88. end
  89. end
  90. return false
  91. end
  92. function isRed(human)
  93. local state, nEndTime, nOpenTime = AbsActLogic.isStarted(human, COMMONACTBOSSABSID)
  94. if not state then
  95. return false
  96. end
  97. ComActBoss_CheckAndCreateDB(human)
  98. local nFreeNum = CommonActBoss_GetFreeNum(human)
  99. if nFreeNum > 0 then
  100. return true
  101. end
  102. return CommonActBoss_IsPrizeRed(human)
  103. end
  104. function isOpen(human, YYInfo, funcConfig)
  105. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig and funcConfig.funcID or COMMONACTBOSSABSID)
  106. if not state then
  107. print("[CommonActBoss_isOpen] 当前活动未开启")
  108. return
  109. end
  110. -- print("[CommonActBoss_isOpen] 进入判断 endTime = "..endTime.." startTime = "..startTime)
  111. return true, endTime, startTime
  112. end
  113. function isActive(human, YYInfo, funcConfig)
  114. return not isOpen(human, YYInfo, funcConfig)
  115. end
  116. function onZero(human, funcID)
  117. local state, nEndTime, nOpenTime = AbsActLogic.isStarted(human, COMMONACTBOSSABSID)
  118. if not state then
  119. return
  120. end
  121. CommonActBoss_SetFreeNum(human, COMMONACTFREENUM)
  122. CommonActBoss_SetFreeTime(human, os.time())
  123. end
  124. function onLogin(human, funcID)
  125. local state, nEndTime, nOpenTime = AbsActLogic.isStarted(human, COMMONACTBOSSABSID)
  126. if not state then
  127. return
  128. end
  129. ComActBoss_CheckAndCreateDB(human)
  130. local nFreeRefreshTime = CommonActBoss_GetFreeTime(human)
  131. if true ~= Util.isSameDayByTimes(nFreeRefreshTime, os.time()) then
  132. CommonActBoss_SetFreeNum(human, COMMONACTFREENUM)
  133. CommonActBoss_SetFreeTime(human, os.time())
  134. end
  135. end
  136. ------------------------------------ 客户端请求处理开始 ---------------------------------
  137. function CommonActBoss_Query(human)
  138. local state = AbsActLogic.isStarted(human, COMMONACTBOSSABSID)
  139. if not state then
  140. print("[CommonActBoss_Query] 当前活动未开启")
  141. return
  142. end
  143. ComActBoss_CheckAndCreateDB(human)
  144. local tMsgData = Msg.gc.GC_ABS_FESTIVAL_BOSS_QUERY
  145. tMsgData.nNum = CommonActBoss_GetFreeNum(human)
  146. tMsgData.nMaxNum = COMMONACTFREENUM
  147. tMsgData.nHarm = CommonActBoss_GetDamage(human)
  148. tMsgData.bRedPrize = CommonActBoss_IsPrizeRed(human) == true and 1 or 0
  149. Msg.send(tMsgData, human.fd)
  150. end
  151. function CommonActBoss_QueryPrize(human)
  152. local tMsgData = Msg.gc.GC_ABS_FESTIVAL_BOSS_REWARD
  153. tMsgData.tPrize[0] = 0
  154. for nID, v in pairs(Config) do
  155. if v.nType == COMMONACTBOOSPRIZE then
  156. tMsgData.tPrize[0] = tMsgData.tPrize[0] + 1
  157. local tData = tMsgData.tPrize[tMsgData.tPrize[0]]
  158. tData.nID = nID
  159. tData.nHarm = v.hurt
  160. tData.nState = CommonActBoss_GetPrizeStatus(human, nID)
  161. tData.tPrize[0] = #v.tPrize
  162. for i, value in ipairs(v.tPrize) do
  163. Grid.makeItem(tData.tPrize[i], value[1], value[2])
  164. end
  165. end
  166. end
  167. Msg.send(tMsgData, human.fd)
  168. end
  169. function CommonActBoss_GetPrize(human)
  170. local tItem = {}
  171. for nID, v in pairs(Config) do
  172. if v.nType == COMMONACTBOOSPRIZE then
  173. local nState = CommonActBoss_GetPrizeStatus(human, nID)
  174. if CommonDefine.COMMON_PRIZE_STATE_CANGET == nState then
  175. CommonActBoss_SetPrizeStatus(human, nID, CommonDefine.COMMON_PRIZE_STATE_GET)
  176. for i, value in ipairs(v.tPrize) do
  177. if not tItem[value[1]] then
  178. tItem[value[1]] = 0
  179. end
  180. tItem[value[1]] = tItem[value[1]] + value[2]
  181. end
  182. end
  183. end
  184. end
  185. if nil ~= _G.next(tItem) then
  186. local tGoods = {}
  187. for nID, nNum in pairs(tItem) do
  188. table.insert(tGoods, {nID, nNum})
  189. end
  190. BagLogic.addItemList(human, tGoods, "CommonActBoss")
  191. CommonActBoss_Query(human)
  192. CommonActBoss_QueryPrize(human)
  193. YunYingLogic.sendBanner(human)
  194. local config = AbsActExcel.absActivity[COMMONACTBOSSABSID]
  195. YunYingLogic.sendGroupUpdate(YYInfo[COMMONACTBOSSABSID], human, config.panelID)
  196. end
  197. end
  198. ------------------------------------ 战斗处理开始 ---------------------------------
  199. -- 调用开始战斗
  200. function fight(human, args, combatType)
  201. if CombatDefine.COMBAT_TYPE34 ~= combatType then
  202. print("[CommonActBoss_fight] 战斗类型不正确 combatType = "..combatType)
  203. return
  204. end
  205. local nMapID = getMapID(human, nil)
  206. -- print("[CommonActBoss_fight] 11111 combatType = "..combatType)
  207. local nNowFreeNum = CommonActBoss_GetFreeNum(human)
  208. if 0 >= nNowFreeNum then
  209. return
  210. end
  211. nNowFreeNum = nNowFreeNum - 1
  212. CommonActBoss_SetFreeNum(human, nNowFreeNum)
  213. CombatLogic.combatBegin(human, nMapID, args, CombatDefine.COMBAT_TYPE34)
  214. -- print("[CommonActBoss_fight] 2222 combatType = "..combatType)
  215. end
  216. -- 获取人物对战列表
  217. function getCombatObjList(human, side, args)
  218. if not human then
  219. print("[getCombatObjList] 获取进攻方,但是不存在对应的human")
  220. return
  221. end
  222. if side ~= CombatDefine.ATTACK_SIDE then
  223. return
  224. end
  225. -- print("[getCombatObjList] 进攻方 获取人物对战列表")
  226. local objList, helpList, rolebase, formation,jiban, elfList = CombatLogic.getHumanObjList(human, CombatDefine.COMBAT_TYPE34)
  227. if not objList or nil == _G.next(objList) then
  228. print("[getCombatObjList] 没有获取到对应的进攻方防守阵容,取默认对战阵容")
  229. objList, helpList, rolebase, formation,jiban, elfList = CombatLogic.getHumanObjList(human, CombatDefine.COMBAT_TYPE1)
  230. end
  231. return objList, helpList, rolebase, formation,jiban, elfList
  232. end
  233. -- 获取机器人对应战斗ID
  234. function getCombatMonsterOutID(human, side, args)
  235. if side ~= CombatDefine.DEFEND_SIDE then
  236. return
  237. end
  238. if not CommonAct_BOSSID then
  239. for key, v in pairs(Config) do
  240. if v.nMonsterOutID and v.nType == COMMONACTFIGHTPRIZE then
  241. CommonAct_BOSSID = v.nMonsterOutID
  242. break
  243. end
  244. end
  245. end
  246. -- print("[getCombatMonsterOutID] 获取到的战斗ID CommonAct_BOSSID = "..CommonAct_BOSSID)
  247. return CommonAct_BOSSID
  248. end
  249. function getMapID(human, param)
  250. if not CommonAct_MapID then
  251. for key, v in pairs(Config) do
  252. if v.mapID and v.nType == COMMONACTFIGHTPRIZE then
  253. CommonAct_MapID = v.mapID
  254. break
  255. end
  256. end
  257. end
  258. return CommonAct_MapID
  259. end
  260. function onFightEnd(human, result, combatType, defUuid, combatInfo)
  261. local atkHurt = 0
  262. for pos = 1, CombatDefine.COMBAT_HERO_CNT do
  263. local obj = combatInfo.objList and combatInfo.objList[pos]
  264. if obj then
  265. atkHurt = atkHurt + obj.result[1]
  266. end
  267. end
  268. -- 魔兽 造成伤害
  269. for _,pos in ipairs(CombatDefine.SIDE2HELPPOS[CombatDefine.ATTACK_SIDE]) do
  270. local pet = combatInfo.helpList and combatInfo.helpList[pos]
  271. if pet and pet.isPet then
  272. atkHurt = atkHurt + pet.result[1]
  273. end
  274. end
  275. -- 精灵 造成伤害
  276. for _,pos in ipairs(CombatDefine.SIDE2ELFPOS[CombatDefine.ATTACK_SIDE]) do
  277. local elf = combatInfo.elfList and combatInfo.elfList[pos]
  278. if elf then
  279. atkHurt = atkHurt + elf.result[1]
  280. end
  281. end
  282. local nNowDamage = CommonActBoss_GetDamage(human)
  283. nNowDamage = nNowDamage + atkHurt
  284. local bChange = false
  285. local tPrize = nil
  286. for nID, v in pairs(Config) do
  287. if v.nType == COMMONACTBOOSPRIZE then
  288. if nNowDamage >= v.hurt then
  289. local nState = CommonActBoss_GetPrizeStatus(human, nID)
  290. if CommonDefine.COMMON_PRIZE_STATE_NOGET == nState then
  291. CommonActBoss_SetPrizeStatus(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
  292. bChange = true
  293. end
  294. else
  295. bChange = true
  296. end
  297. else
  298. tPrize = v.tPrize
  299. end
  300. end
  301. if true == bChange then
  302. YunYingLogic.sendBanner(human)
  303. local config = AbsActExcel.absActivity[COMMONACTBOSSABSID]
  304. YunYingLogic.sendGroupUpdate(YYInfo[COMMONACTBOSSABSID], human, config.panelID)
  305. CommonActBoss_AddDamage(human, atkHurt)
  306. CommonActBoss_Query(human)
  307. end
  308. BagLogic.addItemList(human, tPrize, "CommonActBoss")
  309. end