BattleManager.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { Framework } from "../../framework/Framework";
  2. import { LoginMgr } from "../common/LoginManager";
  3. import { BattleData, BattleLayoutData, BattleLayoutPos, BattleLayoutScale, BattleOptsBase, BattleOptsKill, BattleOptsMerge, BattleOptsMove, BattleOptsNew, BattleOptsRemove, BattleOptsType } from "../data/BattleData";
  4. import { GameEvent } from "../data/GameEvent";
  5. import { RoleData } from "../data/RoleData";
  6. import { UserData } from "../data/UserData";
  7. import { BattlesConf } from "../ui/tower/conf/BattlesConf";
  8. import { GoodsManager } from "./GoodsManager";
  9. //战斗消息管理
  10. export class BattleManager {
  11. /**
  12. * 发送战斗结束消息
  13. * @param id 新关卡id,
  14. * @param win 战斗结果(1-胜利,0-失败),
  15. * @param layout 布局信息, [key:BattleLayoutPos]:number
  16. * @param opts 操作指令顺序数组
  17. * @param callback
  18. */
  19. static sendBattleDuplicateMsg(id:number,win:boolean,layout:{[key:string]:number},opts:Array<BattleOptsBase>, callback,errorFun) {
  20. let args = {
  21. id:id, //新关卡id,
  22. win:win?1:0, // 战斗结果(1-胜利,0-失败),
  23. layout:layout, //布局信息,
  24. opts:[], //操作指令顺序数组
  25. }
  26. for(let item of opts) {
  27. switch(item.type) {
  28. case BattleOptsType.New:{
  29. let item_new = item as BattleOptsNew;
  30. args.opts.push([item_new.type, item_new.pos,item_new.raceID,item_new.level]);
  31. break;
  32. }
  33. case BattleOptsType.Move:{
  34. let item_move = item as BattleOptsMove;
  35. args.opts.push([item_move.type, item_move.srcPos,item_move.targetPos]);
  36. break;
  37. }
  38. case BattleOptsType.Merge:{
  39. let item_merge = item as BattleOptsMerge;
  40. args.opts.push([item_merge.type, item_merge.srcPos,item_merge.targetPos]);
  41. break;
  42. }
  43. case BattleOptsType.Remove:{
  44. let item_remove = item as BattleOptsRemove;
  45. args.opts.push([item_remove.type, item_remove.pos]);
  46. break;
  47. }
  48. case BattleOptsType.Kill:{
  49. let item_kill = item as BattleOptsKill;
  50. args.opts.push([item_kill.type, item_kill.typeID, item_kill.count]);
  51. break;
  52. }
  53. }
  54. }
  55. LoginMgr.sendPost('battle', 'duplicate', (data) => {
  56. console.log(data);
  57. if(data.duplicate){
  58. BattleData.duplicate = data.duplicate;
  59. }
  60. if(data.layout){
  61. BattleData.layout = data.layout;
  62. }
  63. if(data.awards){
  64. let awards = Framework.unionManager.parseServerAwards(data.awards);
  65. Framework.unionManager.fireEventWithItem(awards)
  66. Framework.unionManager.showItemTips(awards);
  67. }
  68. UserData.food_timer = data.food_timer;
  69. UserData.status.food = data.food;
  70. callback&&callback();
  71. }, args,errorFun)
  72. }
  73. // 重置新章节
  74. static sendBattleDuplicateResetMsg(mapID:number) {
  75. let args = {
  76. id:mapID, //章节id,
  77. }
  78. LoginMgr.sendPost('battle', 'duplicate_reset', (data) => {
  79. if(data.duplicate){
  80. BattleData.duplicate = data.duplicate;
  81. }
  82. if(data.layout){
  83. BattleData.layout = data.layout;
  84. }
  85. if(data.awards){
  86. let awards = Framework.unionManager.parseServerAwards(data.awards);
  87. Framework.unionManager.fireEventWithItem(awards)
  88. Framework.unionManager.showItemTips(awards);
  89. }
  90. Framework.event.fireEvent(GameEvent.BattleDuplicateReset,data);
  91. }, args)
  92. }
  93. //领取章节奖励
  94. static sendBattleDuplicateRewardMsg(mapID:number) {
  95. let args = {
  96. id:mapID, //章节id
  97. }
  98. LoginMgr.sendPost('battle', 'duplicate_reward', (data) => {
  99. console.log(data);
  100. if(data.duplicate_reward){
  101. BattleData.duplicateReward = data.duplicate_reward;
  102. }
  103. if(data.awards){
  104. let awards = Framework.unionManager.parseServerAwards(data.awards);
  105. Framework.unionManager.fireEventWithItem(awards)
  106. Framework.unionManager.showItemTips(awards);
  107. }
  108. Framework.event.fireEvent(GameEvent.BattleDuplicateReward,data);
  109. }, args)
  110. }
  111. //切换同种族角色
  112. static sendBattleDuplicateFightRoleMsg(typeID:number, callback) {
  113. let args = {
  114. rid:typeID, //角色id
  115. }
  116. LoginMgr.sendPost('battle', 'set_fight_role', (data) => {
  117. RoleData.fightRole = data.fight_role
  118. callback&&callback();
  119. }, args)
  120. }
  121. //根据布局数据获取类型ID
  122. static getDataWithLayoutValue(value:number):BattleLayoutData{
  123. let fightRole = RoleData.fightRole;
  124. let level = value%BattleLayoutScale;
  125. let raceID = (value-level)/BattleLayoutScale;
  126. let typeID = fightRole[raceID-1];
  127. return {typeID: typeID,raceID: raceID,level: level}
  128. }
  129. //获取可领奖的最大章节
  130. static getRewardChapter(){
  131. let chapter = BattleData.duplicate.chapter-1;
  132. let curProcess = BattleData.duplicate.max_process
  133. let battlesConf = BattlesConf.data[curProcess];
  134. if(battlesConf){
  135. if(curProcess == battlesConf.BossProcess){
  136. chapter++;
  137. }
  138. }
  139. return chapter;
  140. }
  141. }