CommonActBoss.lua 10 KB

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