AGAndSD.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. -- 涉及到的相关属性在属性表配置
  2. AGAndSD = {}
  3. local this = AGAndSD;
  4. local filename = "AGAndSD";
  5. -- LuaMessageIdToClient.RES_AGANDSD_SENDSTATE = 90001034 --data [1]类型 0数据通知 l当前sd变化
  6. local curSDVar = "ZC_CurSDVar" -- 当前SD值
  7. local MaxSDVar = "ZC_MaxSDVar" -- 最大SD值
  8. local CurAGVar = "ZC_CurAGVar" -- 当前AG值
  9. local MaxAGVar = "ZC_MaxAGVar" -- 最大AG值
  10. local AGTimeVar = "AGTimeVar" -- ag倒计时
  11. local outFightTimeVar = "outFightTimeVar" -- 脱离战斗时间
  12. local maxOutFightTime = 3 -- 脱离战斗时间
  13. local Sd_TimeKey = "Sd_TimeKey" -- sd药水冷却时间
  14. local SDitems_CD = 4 -- sd药水冷却时间间隔
  15. -- SYS_AGANDSD_OFFLINE_PLAYERS = "R$agandsd_offline_players"
  16. AGAngSDConfig = {
  17. sdbilv_base = 9000, -- 护盾基础比率配置 万分比
  18. sd_huifu_time = 5, -- sd恢复时间间隔
  19. ag_huifu_time = 3, -- ag恢复时间间隔
  20. podun_buff = 100402301 -- 破盾buff添加
  21. };
  22. function APIGetTable(actor, varName, var_type)
  23. local val = nil
  24. if var_type == 0 then
  25. val = getplaydef(actor, "J$" .. varName)
  26. elseif var_type == 1 then
  27. val = getplaydef(actor, "@" .. varName)
  28. else
  29. val = getplaydef(actor, "T$" .. varName)
  30. end
  31. return val
  32. end
  33. ---设置玩家table变量 val类型必须是table var_type 0天变量 1缓存变量 其它正常保存数据库变量
  34. function APISetTable(actor, varName, val, var_type)
  35. if type(val) ~= "table" then
  36. return
  37. end
  38. if var_type == 0 then
  39. setplaydef(actor, "J$" .. varName, val)
  40. elseif var_type == 1 then
  41. setplaydef(actor, "@" .. varName, val)
  42. else
  43. setplaydef(actor, "T$" .. varName, val)
  44. -- info("记录成功",val,getplaydef(actor,"T$"..varName))
  45. end
  46. end
  47. function APIGetInt(actor, varName, var_type)
  48. local val = 0
  49. if var_type == 0 then
  50. val = getplaydef(actor, "J$" .. varName)
  51. elseif var_type == 1 then
  52. val = getplaydef(actor, "@" .. varName)
  53. else
  54. val = getplaydef(actor, "T$" .. varName)
  55. end
  56. return val or 0
  57. end
  58. ---设置玩家Int变量 val类型必须是number
  59. function APISetInt(actor, varName, val, var_type)
  60. if type(val) ~= "number" then
  61. return
  62. end
  63. if var_type == 0 then
  64. return setplaydef(actor, "J$" .. varName, val)
  65. elseif var_type == 1 then
  66. return setplaydef(actor, "@" .. varName, val)
  67. else
  68. return setplaydef(actor, "T$" .. varName, val)
  69. end
  70. end
  71. function APISendCenterMsg(actor, msg, color, log)
  72. if not color then
  73. tipinfo(actor, msg)
  74. else
  75. tipinfo(actor, "<color='" .. color .. "'>" .. msg .. "</color>")
  76. end
  77. if log then
  78. error(getbaseinfo(actor, "rolename"), msg)
  79. end
  80. end
  81. -- 伤害 excusefightdamage extra_result最后触发
  82. -- 此代码仅供参考
  83. --[[
  84. local extra_result = {};--额外的飘字拆分
  85. if targettype == MapObjectType.PLAYER then
  86. fightResult.targethurt = targethurt --受击者伤害
  87. --伤害后AG和SD操作执行
  88. AGAndSD.onAttackAGAndSD(paramMap,fightResult,extra_result)
  89. -- info("现伤害2",fightResult)
  90. targethurt = fightResult.targethurt
  91. hurttype = fightResult.hurttype
  92. end
  93. ]]
  94. -- 护盾扣除逻辑(伤害的90%,不足则全扣)
  95. function AGAndSD.onAttackSD(actor, paramMapList, fightResult)
  96. -- info("onAttackSD paramMapList ",paramMapList);
  97. -- info("onAttackSD fightResult ",fightResult);
  98. -- local castType = paramMapList["castertype"]
  99. local target = paramMapList[1]["target"] -- —— 受击对象
  100. local targethurt = fightResult["targethurt"] -- 攻击者伤害
  101. local actortype = getbaseinfo(actor, "mapobjecttype"); -- 攻击者
  102. local targettype = getbaseinfo(target, "mapobjecttype"); -- 受击者
  103. -- info("actortype ",actortype);
  104. -- APISetInt(target, outFightTimeVar, maxOutFightTime) -- 设置3秒脱战
  105. -- APISetInt(actor, outFightTimeVar, maxOutFightTime) -- 设置3秒脱战
  106. if actortype == 2 or targettype == 2 then
  107. return fightResult -- 怪物攻击时不做处理
  108. end
  109. if targethurt <= 0 then
  110. return fightResult
  111. end
  112. local curSD = APIGetInt(target, curSDVar);
  113. if curSD <= 0 then
  114. return fightResult
  115. end
  116. local maxSD = APIGetInt(target, MaxSDVar)
  117. local curAG = APIGetInt(target, CurAGVar)
  118. local maxAG = APIGetInt(target, MaxAGVar)
  119. if curSD >= 0 then
  120. local tmp = targethurt * 90 / 100
  121. if curSD >= tmp then
  122. curSD = curSD - tmp;
  123. targethurt = targethurt - tmp;
  124. else
  125. targethurt = targethurt - curSD;
  126. curSD = 0;
  127. end
  128. -- messagebox(actor,"伤害:"..casthurt.." 当前护盾:"..curSD.." 减少伤害:"..tmp)
  129. APISetInt(target, curSDVar, curSD)
  130. AGAndSD.SendMsg(target, {0, curSD, maxSD, curAG, maxAG})
  131. else
  132. APISetInt(target, curSDVar, 0)
  133. AGAndSD.SendMsg(target, {0, 0, maxSD, curAG, maxAG})
  134. end
  135. fightResult["targethurt"] = targethurt
  136. fightResult["targethurtshow"] = targethurt
  137. -- info("onAttackSD fightResult ",fightResult);
  138. return fightResult;
  139. end
  140. -- --护盾裆下的伤害用加血的方式处理
  141. -- function AddHealth(actor, healAmount)
  142. -- local currentHp = getbaseinfo(actor, "hp")
  143. -- local maxHp = getbaseinfo(actor, "maxhp")
  144. -- local newHp = math.min(maxHp, currentHp + healAmount)
  145. -- info("当前血量",currentHp,"最大血量",maxHp,"加血",healAmount,"新血量",newHp)
  146. -- sethp(actor, newHp)
  147. -- end
  148. -- 脱战后,每秒回复护盾值10点
  149. function AGAndSD.onSecCullSd(actor, fightResult)
  150. local time = APIGetInt(actor, AGTimeVar)
  151. if time == 0 then
  152. time = 2
  153. on3SecCullAg(actor, fightResult);
  154. else
  155. time = time - 1
  156. end
  157. APISetInt(actor, AGTimeVar, time)
  158. local outfighttime = APIGetInt(actor, outFightTimeVar)
  159. if outfighttime > 0 then
  160. outfighttime = outfighttime - 1
  161. APISetInt(actor, outFightTimeVar, outfighttime)
  162. return
  163. end
  164. -- messagebox(actor,"每秒回复护盾值10")
  165. local curSD = APIGetInt(actor, curSDVar)
  166. local maxSD = APIGetInt(actor, MaxSDVar)
  167. local curAG = APIGetInt(actor, CurAGVar)
  168. local maxAG = APIGetInt(actor, MaxAGVar)
  169. curSD = curSD + 10
  170. if curSD > maxSD then
  171. curSD = maxSD
  172. end
  173. APISetInt(actor, curSDVar, curSD)
  174. AGAndSD.SendMsg(actor, {0, curSD, maxSD, curAG, maxAG})
  175. end
  176. -- 技能消耗ag值的逻辑
  177. function AGAndSD.onAttackAG(actor, skillId)
  178. -- if true then
  179. -- return
  180. -- end
  181. -- APISetInt(actor, outFightTimeVar, maxOutFightTime) -- 设置3秒脱战
  182. local newConsumeAG = ConfigDataManager.getTableValue("cfg_skill_info", "newConsumeAG", "skillID", skillId)
  183. if newConsumeAG == nil then
  184. return
  185. end
  186. local castAG = tonumber(newConsumeAG) or 0
  187. local curSD = APIGetInt(actor, curSDVar)
  188. local maxSD = APIGetInt(actor, MaxSDVar)
  189. local curAG = APIGetInt(actor, CurAGVar)
  190. local maxAG = APIGetInt(actor, MaxAGVar)
  191. if curAG >= castAG then
  192. curAG = curAG - castAG
  193. APISetInt(actor, CurAGVar, curAG)
  194. AGAndSD.SendMsg(actor, {0, curSD, maxSD, curAG, maxAG})
  195. else
  196. APISetInt(actor, CurAGVar, 0)
  197. AGAndSD.SendMsg(actor, {0, curSD, maxSD, 0, maxAG})
  198. end
  199. end
  200. -- 每3秒触发回复技能伤害值
  201. function on3SecCullAg(actor, fightResult)
  202. local curSD = APIGetInt(actor, curSDVar)
  203. local maxSD = APIGetInt(actor, MaxSDVar)
  204. local curAG = APIGetInt(actor, CurAGVar)
  205. local maxAG = APIGetInt(actor, MaxAGVar)
  206. local tmp = maxAG * 3 / 100
  207. -- messagebox(actor,"三秒回复技能值="..tmp)
  208. curAG = curAG + tmp
  209. if curAG > maxAG then
  210. curAG = maxAG
  211. end
  212. APISetInt(actor, CurAGVar, curAG)
  213. AGAndSD.SendMsg(actor, {0, curSD, maxSD, curAG, maxAG})
  214. -- APISendCenterMsg(actor,"当前技能值="..curAG,0,true)
  215. end
  216. function AGAndSD.onAttackAGAndSD(paramMap, fightResult, extra_result)
  217. local actor = paramMap.caster -- —— 攻击对象
  218. local target = paramMap.target -- —— 受击对象
  219. local targethurt = fightResult.targethurt -- 受击者伤害
  220. local casthurt = fightResult.casthurt -- 攻击者伤害
  221. local castershield = fightResult.castershield -- 攻击者者扣除护盾
  222. local targetshield = fightResult.targetshield -- 受击者扣除护盾
  223. local nowsec = getbaseinfo(actor, "nowsec")
  224. local playerName = getbaseinfo(actor, "rolename")
  225. local attackRid = actor:toString()
  226. APISetInt(actor, "ZC_SDTime", nowsec, 1)
  227. APISetInt(target, "ZC_SDTime", nowsec, 1)
  228. local curSD = APIGetInt(target, curSDVar);
  229. if curSD <= 0 then
  230. AGAndSD.SendMsg(target, {1, curSD, playerName, attackRid})
  231. return
  232. end
  233. -- info("原伤害",targethurt,casthurt)
  234. local c_SDwushiRate = getattrinfo(actor, "SDwushiRate") -- 攻击者sd的无视概率
  235. local t_dikangwushiSd = getattrinfo(actor, "dikangwushiSd") -- 受击者的抵抗无视概率
  236. -- 判定是否可无视
  237. if c_SDwushiRate > t_dikangwushiSd then
  238. local randomValue = math.random(10000);
  239. -- 无视成功
  240. if randomValue < c_SDwushiRate - t_dikangwushiSd then
  241. return
  242. end
  243. end
  244. local c_SDwushiRate = getattrinfo(actor, "adbilvRate") -- 攻击者SD减少率
  245. local t_dikangwushiSd = getattrinfo(actor, "SDsubRate") -- 受击者SD比率
  246. local bilv = (AGAngSDConfig.sdbilv_base / 10000 + c_SDwushiRate - t_dikangwushiSd) -- 最终比率
  247. local sd_hurt = targethurt * bilv -- 减少伤害
  248. if sd_hurt > targethurt then
  249. sd_hurt = targethurt;
  250. end
  251. -- 破盾
  252. if sd_hurt >= curSD then
  253. -- APISendCenterMsg(target,"破盾了")
  254. sd_hurt = curSD
  255. curSD = 0;
  256. addbuff(target, AGAngSDConfig.podun_buff)
  257. else
  258. sd_hurt = math.floor(sd_hurt)
  259. curSD = curSD - sd_hurt;
  260. end
  261. fightResult.targethurt = targethurt - sd_hurt
  262. -- fightResult.targetshield = targetshield + sd_hurt
  263. local extar_fight = table.copy(fightResult)
  264. extar_fight.hurttype = 203
  265. extar_fight.targethurt = 0;
  266. extar_fight.targethurtshow = sd_hurt;
  267. extar_fight.fightLog = {"SD护盾显示飘字" .. extar_fight.targethurtshow}
  268. -- info(extar_fight)
  269. table.insert(extra_result, extar_fight)
  270. APISetInt(target, curSDVar, curSD)
  271. AGAndSD.SendMsg(target, {1, curSD, playerName, attackRid})
  272. end
  273. function AGAndSD.onReflexDamage(paramMap, fightResult, extra_result, casthurt)
  274. local actor = paramMap.caster -- —— 攻击对象
  275. local nowsec = getbaseinfo(actor, "nowsec")
  276. APISetInt(actor, "ZC_SDTime", nowsec, 1)
  277. local curSD = APIGetInt(actor, curSDVar);
  278. if curSD <= 0 then
  279. return casthurt
  280. end
  281. local bilv = (AGAngSDConfig.sdbilv_base / 10000)
  282. local sd_hurt = casthurt * bilv -- 减少伤害
  283. if sd_hurt > casthurt then
  284. sd_hurt = casthurt;
  285. end
  286. -- 破盾
  287. if sd_hurt >= curSD then
  288. -- APISendCenterMsg(target,"破盾了")
  289. sd_hurt = curSD
  290. curSD = 0;
  291. addbuff(actor, AGAngSDConfig.podun_buff)
  292. else
  293. sd_hurt = math.floor(sd_hurt)
  294. curSD = curSD - sd_hurt;
  295. end
  296. -- fightResult.targetshield = targetshield + sd_hurt
  297. local extar_fight = table.copy(fightResult)
  298. extar_fight.target = actor
  299. extar_fight.hurttype = 203
  300. extar_fight.targethurt = 0;
  301. extar_fight.targethurtshow = sd_hurt;
  302. extar_fight.fightLog = {"SD护盾显示飘字" .. extar_fight.targethurtshow}
  303. -- info(extar_fight)
  304. table.insert(extra_result, extar_fight)
  305. APISetInt(actor, curSDVar, curSD)
  306. AGAndSD.SendMsg(actor, {1, curSD})
  307. return casthurt - sd_hurt
  308. end
  309. -- 每秒心跳 rolesecondheart调用
  310. function AGAndSD.onRoleseCond(actor)
  311. -- local playerinfo = getplayermaininfo(actor)
  312. -- info('获取玩家所有的属性点信息', playerinfo)
  313. -- jprint(playerinfo)
  314. local maxSD = APIGetInt(actor, MaxSDVar)
  315. local hudunValue = getattrinfo(actor, "hudunValue")
  316. local curSD = APIGetInt(actor, curSDVar)
  317. local is_change = false;
  318. -- if maxSD <= 0 and curSD > 0 then
  319. -- maxSD = curSD
  320. -- APISetInt(actor, MaxSDVar, maxSD)
  321. -- end
  322. if hudunValue > maxSD or curSD > maxSD then
  323. maxSD = hudunValue;
  324. curSD = math.max(0, curSD)
  325. curSD = math.min(maxSD, curSD)
  326. is_change = true;
  327. -- info("上限增加",curSD,maxSD)
  328. end
  329. -- SDyewaihuivValue SDyewaihuivRate 属性表注册
  330. local SDyewaihuivValue = getattrinfo(actor, "SDyewaihuivValue")
  331. local SDyewaihuivRate = getattrinfo(actor, "SDyewaihuivRate")
  332. -- info("恢复1",curSD,maxSD,SDyewaihuivValue,SDyewaihuivRate,curSD < maxSD and (SDyewaihuivValue > 0 or SDyewaihuivRate > 0))
  333. if curSD < maxSD and (SDyewaihuivValue > 0 or SDyewaihuivRate > 0) then
  334. local nowsec = getbaseinfo(actor, "nowsec")
  335. local fightstate = getfightstate(actor)
  336. -- if fightstate == 0 then
  337. local last_huifu_time = APIGetInt(actor, "ZC_SDTime", 1)
  338. -- info("恢复", last_huifu_time, last_huifu_time >= nowsec + AGAngSDConfig.sd_huifu_time)
  339. if last_huifu_time + AGAngSDConfig.sd_huifu_time <= nowsec then
  340. APISetInt(actor, "ZC_SDTime", nowsec, 1)
  341. local huifu_count = SDyewaihuivValue + math.ceil(maxSD * SDyewaihuivRate)
  342. curSD = curSD + huifu_count
  343. -- info("当前护盾值恢复",curSD,maxSD)
  344. if curSD > maxSD then
  345. curSD = maxSD
  346. end
  347. is_change = true
  348. end
  349. -- else
  350. -- APISetInt(actor, "ZC_SDTime", nowsec, 1)
  351. -- end
  352. end
  353. -- AG
  354. local curAG = APIGetInt(actor, CurAGVar);
  355. local maxAG = APIGetInt(actor, MaxAGVar);
  356. local agValue = getattrinfo(actor, "agValue")
  357. if agValue > maxAG then
  358. curAG = curAG + agValue - maxAG
  359. maxAG = agValue;
  360. is_change = true;
  361. end
  362. local agZiDongHuifu = getattrinfo(actor, "agZiDongHuifu")
  363. local AGZiDongHuiFuBili = getattrinfo(actor, "AGZiDongHuiFuBili") -- 0.0 , 0.08
  364. -- agZiDongHuifu = tonumber(agZiDongHuifu) or 0
  365. -- AGZiDongHuiFuBili = tonumber(AGZiDongHuiFuBili) or 0
  366. if curAG < maxAG and (agZiDongHuifu > 0 or AGZiDongHuiFuBili > 0) then
  367. local nowsec = getbaseinfo(actor, "nowsec")
  368. -- if getfightstate(actor) == 0 then
  369. local last_huifu_time = APIGetInt(actor, "ZC_AGTime", 1)
  370. if last_huifu_time + AGAngSDConfig.ag_huifu_time <= nowsec then
  371. APISetInt(actor, "ZC_AGTime", nowsec, 1)
  372. local huifu_count = agZiDongHuifu + math.ceil(maxAG * AGZiDongHuiFuBili)
  373. curAG = curAG + huifu_count
  374. if curAG > maxAG then
  375. curAG = maxAG
  376. end
  377. is_change = true
  378. end
  379. -- else
  380. -- APISetInt(actor, "ZC_AGTime", nowsec, 1)
  381. -- end
  382. end
  383. -- info(string.format("MS -> AGAndSD.onRoleseCond, 8.结束心跳 actor: %s, curAG: %d, maxAG: %d", actor, curAG, maxAG))
  384. if is_change then
  385. APISetInt(actor, MaxSDVar, maxSD)
  386. APISetInt(actor, curSDVar, curSD)
  387. APISetInt(actor, CurAGVar, curAG)
  388. APISetInt(actor, MaxAGVar, maxAG)
  389. AGAndSD.SendMsg(actor, {0, curSD, maxSD, curAG, maxAG})
  390. end
  391. -- info("数据同步") 测试期间, 先不检测是否改变
  392. end
  393. -- 玩家登录 login调用
  394. function AGAndSD.onLoginEnd(actor)
  395. local curSD = APIGetInt(actor, curSDVar);
  396. local maxSD = APIGetInt(actor, MaxSDVar);
  397. local curAG = APIGetInt(actor, CurAGVar);
  398. local maxAG = APIGetInt(actor, MaxAGVar);
  399. local curMaxSD = getattrinfo(actor, "hudunValue")
  400. local agValue = getattrinfo(actor, "agValue")
  401. -- messagebox("curMaxSD", curMaxSD, "agValue", agValue, "curSD", curSD, "maxSD", maxSD, "curAG", curAG, "maxAG", maxAG)
  402. if maxSD ~= curMaxSD then
  403. maxSD = curMaxSD
  404. APISetInt(actor, MaxSDVar, maxSD)
  405. end
  406. if maxAG ~= agValue then
  407. maxAG = agValue
  408. APISetInt(actor, MaxAGVar, maxAG)
  409. end
  410. if curAG > maxAG then
  411. curAG = maxAG
  412. APISetInt(actor, CurAGVar, curAG)
  413. end
  414. AGAndSD.SendMsg(actor, {0, curSD, maxSD, curAG, maxAG})
  415. end
  416. function AGAndSD.onLogout(actor)
  417. end
  418. -- 怪物死亡 killmon 调用
  419. function AGAndSD.onKillMon(actor, monsterId, monsterCfgId, monsterName, pointX, pointY, activityId, monsterLevel,
  420. mongenCfgId)
  421. local shaguaihuiSDValue = getattrinfo(actor, "shaguaihuiSDValue")
  422. local shaguaihuiSDRate = getattrinfo(actor, "shaguaihuiSDRate")
  423. if shaguaihuiSDValue > 0 or shaguaihuiSDRate > 0 then
  424. local maxSD = APIGetInt(actor, MaxSDVar)
  425. local curSD = APIGetInt(actor, curSDVar)
  426. if curSD < maxSD then
  427. local huifu_count = shaguaihuiSDValue + math.ceil(maxSD * shaguaihuiSDRate)
  428. curSD = curSD + huifu_count
  429. AGAndSD.SetCurSD(actor, curSD)
  430. end
  431. end
  432. end
  433. -- 设置当前sd 并同步客户端
  434. function AGAndSD.SetCurSD(actor, SD)
  435. local maxSD = APIGetInt(actor, MaxSDVar)
  436. if SD > maxSD then
  437. SD = maxSD
  438. end
  439. APISetInt(actor, curSDVar, SD)
  440. -- info("数据同步")
  441. AGAndSD.SendMsg(actor, {1, SD})
  442. end
  443. -- 获取当前sd以及最大sd
  444. function AGAndSD.GetSD(actor)
  445. return APIGetInt(actor, curSDVar), APIGetInt(actor, MaxSDVar)
  446. end
  447. -- 设置当前AG 并同步客户端
  448. function AGAndSD.SetCurAG(actor, AG)
  449. local maxSD = APIGetInt(actor, MaxAGVar)
  450. if AG > maxSD then
  451. AG = maxSD
  452. end
  453. APISetInt(actor, CurAGVar, AG)
  454. -- info("数据同步",AG)
  455. AGAndSD.SendMsg(actor, {2, AG})
  456. end
  457. -- 获取当前AG以及最大AG
  458. function AGAndSD.GetAG(actor)
  459. return APIGetInt(actor, CurAGVar), APIGetInt(actor, MaxAGVar)
  460. end
  461. -- releaseskill 调用 newConsumeAG在cfg_skill_info添加配置
  462. --[[ 代码参考
  463. function releaseskill(actor, skillid, skilllevel, targetlist)
  464. if not AGAndSD.CanRelease(actor,skillid,skilllevel) then
  465. return false
  466. end
  467. end
  468. ]]
  469. function AGAndSD.CanRelease(actor, skillid, skilllevel)
  470. local curAG = APIGetInt(actor, CurAGVar);
  471. local consumeAG = ConfigDataManager.getTableValue("cfg_skill_info", "newConsumeAG", "skillID", skillid,
  472. "skillLevel", skilllevel)
  473. -- info("consumeAG1",type(consumeAG),consumeAG)
  474. consumeAG = tonumber(consumeAG)
  475. -- info("consumeAG",type(consumeAG),consumeAG)
  476. if consumeAG then
  477. local agConsumeJianShao = getattrinfo(actor, "agConsumeJianShao")
  478. local agConsumeJianShaoBiLi = getattrinfo(actor, "agConsumeJianShaoBiLi")
  479. if agConsumeJianShao > 0 or agConsumeJianShaoBiLi > 0 then
  480. -- info("ag减少",agConsumeJianShao - consumeAG*agConsumeJianShaoBiLi)
  481. consumeAG = consumeAG - agConsumeJianShao - math.floor(consumeAG * agConsumeJianShaoBiLi)
  482. end
  483. if consumeAG > 0 then
  484. if consumeAG > curAG then
  485. APISendCenterMsg(actor, "AG值不足")
  486. return false
  487. else
  488. AGAndSD.SetCurAG(actor, curAG - consumeAG)
  489. end
  490. end
  491. end
  492. return true
  493. end
  494. function AGAndSD.SendMsg(actor, data)
  495. local msg = {
  496. rid = actor:toString(),
  497. data = data
  498. }
  499. sendluamsg(actor, LuaMessageIdToClient.RES_AGANDSD_SENDSTATE, msg)
  500. end
  501. function AGAndSD.useItem(actor, itemId, itemCount, type)
  502. if itemId ~= 50020021 then
  503. return false
  504. end
  505. local config = ConfigDataManager.getById("cfg_item", itemId)
  506. if table.isEmpty(config) then
  507. return false
  508. end
  509. -- local type = tonumber(config['type'])
  510. -- local subType = tonumber(config['subtype'])
  511. -- if type ~= 3 or subType ~= 94 then
  512. -- return
  513. -- end
  514. local useParam = tonumber(config['useparam']) or 0
  515. if useParam == 0 then
  516. return false
  517. end
  518. if type == 1 then
  519. local nowsec = getbaseinfo(actor, "nowsec")
  520. local cdVal = APIGetInt(actor, Sd_TimeKey, 1)
  521. if cdVal > 0 and nowsec - cdVal <= SDitems_CD then
  522. messagebox(actor, "冷却中,请稍后再使用!")
  523. -- noticeTip.noticeinfo(actor, "冷却中,请稍后再使用!")
  524. return false
  525. end
  526. APISetInt(actor, Sd_TimeKey, nowsec, 1)
  527. return true
  528. end
  529. local maxSD = APIGetInt(actor, MaxSDVar)
  530. local curSD = APIGetInt(actor, curSDVar)
  531. if curSD < maxSD then
  532. local huifu_count = math.ceil(maxSD * useParam / 100)
  533. curSD = curSD + huifu_count
  534. AGAndSD.SetCurSD(actor, curSD)
  535. end
  536. end
  537. function AGAndSD.playerRelive(actor)
  538. local maxSD = APIGetInt(actor, MaxSDVar);
  539. local maxAG = APIGetInt(actor, MaxAGVar);
  540. AGAndSD.SetCurSD(actor, maxSD)
  541. AGAndSD.SetCurAG(actor, maxAG)
  542. end