FightData.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. import Main from "../Main";
  2. import AdM from "../manager/AdM";
  3. import GameM from "../manager/GameM";
  4. import HttpM from "../manager/HttpM";
  5. import UiM from "../manager/UiM";
  6. import { PlayerPrefs } from "../tools/MyExtends";
  7. import EffectNode from "../ui/EffectNode";
  8. import UIMng, { PanelType } from "../uiFrames/UIMng";
  9. import LogUtil from "../utils/LogUtil";
  10. import Random from "../utils/Random";
  11. import { HTTP_TYPE } from "./CommonData";
  12. import { MateData } from "./MateData";
  13. export class FightData {
  14. //战斗模块数据管理类
  15. private static _ins: FightData = null;
  16. public static get Ins(): FightData {
  17. if (this._ins == null) {
  18. this._ins = new FightData();
  19. }
  20. return this._ins;
  21. }
  22. /**触发已解锁武将战斗 武将的最低等级*/
  23. triggerFightRoleMinLv: number = 7;
  24. fightTriggerTimes: number = 3;
  25. curFightTime: number = 0;
  26. isTriggerFight: boolean = false;
  27. /**破绽点击次数*/
  28. flawTimes: number = 3;
  29. /**破绽生命时长*/
  30. flawDuration: number = 3;
  31. /**破绽触发概率*/
  32. flawRate: number = 10;
  33. /**破绽同时存在的数量*/
  34. flawNum: number = 1;
  35. /**破绽当前存在的数量*/
  36. flawCurNum: number = 0;
  37. /**今日剩余奖励次数 战斗2*/
  38. rewardTimes: number = 0;
  39. //存到服务器
  40. /**第一次合成需要战斗的武将 武将id 存到服务器*/
  41. composeFightRoles: any[] = [];
  42. /*
  43. [
  44. {code: "5", battleStatus: 0, battleResult: 0},
  45. {code: "6", battleStatus: 0, battleResult: 0}
  46. ]
  47. */
  48. /**需要战斗的武将的星级 存到服务器*/
  49. fightRolesStars: number[] = [];
  50. /**触发2 战斗触发概率*/
  51. triggerFightRates: number[] = [10, 20, 30, 40, 40];
  52. fightWordsCfg: any = null;
  53. private isInit: boolean = false;
  54. constructor() {
  55. this.composeFightRoles = PlayerPrefs.GetObject("fightRoles", []);
  56. //this.triggerFightRoleMinLv=GameM.commonData.fightCfg.unlock_lv;
  57. console.log("ComposeFightRoles:", this.composeFightRoles);
  58. }
  59. //战斗模块 战斗触发机制
  60. //1 首次合成的怪物 且该怪物配置的是 需要战斗的
  61. //2 非首次合成的怪物 合成的怪物等级 往下5级内怪物 概率触发与该怪物战斗
  62. //战斗 有奖励:
  63. /*
  64. 1星宝箱 2件物品 少量天赋点
  65. 2星宝箱 3件物品 中量天赋点
  66. 3星宝箱 4件物品 大量天赋点
  67. */
  68. Init() {
  69. //服务器获取数据
  70. this.isInit = true;
  71. }
  72. /**是否触发第一次合成战斗
  73. */
  74. CheckComposeFight() {
  75. //三国战戟 战斗弃用
  76. return;
  77. let maxLv = GameM.commonData.maxCarLevel;
  78. if (GameM.commonData.fightRoleServerCfg[maxLv.toString()].is_fight == 1) {
  79. //this.EnterFight();
  80. //console.log("--->FightCfg:",GameM.commonData.fightRoleServerCfg);
  81. //console.log("--->FightCfg lv:",GameM.commonData.fightRoleServerCfg[maxLv.toString()]);
  82. let cfg = GameM.commonData.fightRoleCfg[maxLv.toString()];
  83. this.flawTimes = cfg.flawclicktimes;
  84. this.flawDuration = cfg.flawduration;
  85. this.flawRate = cfg.flawrate;
  86. this.flawNum = cfg.flawnum;
  87. let serCfg = GameM.commonData.fightRoleServerCfg[maxLv.toString()];
  88. let fightrole = new FightRole();
  89. fightrole.arrayIndex = -1;
  90. fightrole.blood = serCfg.bloods;
  91. fightrole.buffId = 1; //无效 在战斗时生效
  92. fightrole.fightTime = serCfg.times;
  93. fightrole.fightType = 1;
  94. fightrole.lv = maxLv;
  95. fightrole.name = serCfg.name;
  96. fightrole.star = 1; //弃用
  97. fightrole.rewardId = 1//弃用;
  98. console.log("Trigger Fight 1");
  99. UIMng.Ins.AsyncGetPanel(PanelType.FightRoleBPanel, (panel) => {
  100. panel.OnEnter(fightrole);
  101. });
  102. //UIMng.Ins.GetPanel(PanelType.FightRoleBPanel).OnEnter(fightrole);
  103. }
  104. }
  105. /**
  106. * 检查是否概率触发已解锁武将的战斗
  107. */
  108. CheckTriggerFight(rolelv: number) {
  109. //弃用 奇遇 老武将战斗功能取消
  110. return;
  111. if (this.isTriggerFight) {
  112. this.curFightTime++;
  113. if (this.curFightTime <= this.fightTriggerTimes) return;
  114. this.curFightTime = 0;
  115. this.isTriggerFight = false;
  116. }
  117. let deltaNum = GameM.commonData.maxCarLevel - rolelv;
  118. //this.triggerFightRoleMinLv = 7; //TEST
  119. //console.log("----Max: " + GameM.commonData.maxCarLevel + " Min: " + this.triggerFightRoleMinLv + " delta: " + deltaNum);
  120. if (GameM.commonData.maxCarLevel >= this.triggerFightRoleMinLv && deltaNum >= 0 && deltaNum <= 4) {
  121. //let fightCfg = GameM.commonData.fightCfg;
  122. let cfg = GameM.commonData.fightRoleCfg[rolelv.toString()];
  123. //战斗触发触发概率 fightRoleCfg---id---fight_rate
  124. let rate = Random.Range(0, 100);
  125. //console.log("--->rate: " + rate + " targetRate:" + this.triggerFightRates[deltaNum]);
  126. LogUtil.logV("-->Tri Rate:", rate)
  127. LogUtil.logV("-->Tri Rate2:", this.triggerFightRates[deltaNum])
  128. //console.log("----->Trigger Rate:" + rate + " T:" + this.triggerFightRates[deltaNum]);
  129. if (rate < this.triggerFightRates[deltaNum]) {
  130. this.isTriggerFight = true;
  131. let cfg = GameM.commonData.fightRoleCfg[rolelv.toString()];
  132. this.flawTimes = cfg.flawclicktimes;
  133. this.flawDuration = cfg.flawduration;
  134. this.flawRate = cfg.flawrate;
  135. this.flawNum = cfg.flawnum;
  136. //使用服务端角色配置基础属性
  137. let serCfg = GameM.commonData.fightRoleServerCfg[rolelv.toString()];
  138. let fightrole = new FightRole();
  139. let star = Random.Range(1, 4);
  140. fightrole.arrayIndex = -1;
  141. fightrole.blood = serCfg.bloods;
  142. fightrole.buffId = 1; //无效 在战斗时生效
  143. fightrole.fightTime = serCfg.times;
  144. fightrole.fightType = 2;
  145. fightrole.lv = rolelv;
  146. fightrole.name = serCfg.name;
  147. fightrole.star = star;
  148. fightrole.rewardId = cfg.fight_box[star - 1];
  149. console.log("Trigger Fight 2");
  150. UIMng.Ins.AsyncGetPanel(PanelType.FightRoleBPanel, (panel) => {
  151. panel.OnEnter(fightrole);
  152. });
  153. //UIMng.Ins.GetPanel(PanelType.FightRoleBPanel).OnEnter(fightrole);
  154. // AdM.onSendEvent(`fight_old_open`, `旧怪触发战斗`, 'fight_old_open');
  155. //AdM.onSendEvent(`guide_${this.curGuideId}`, `引导${this.curGuideId}`, 'guide');
  156. }
  157. }
  158. }
  159. /**
  160. * 检查是否触发大富翁BOSS战
  161. * @param rolelv 武将等级
  162. */
  163. CheckRichFight(rolelv: number) {
  164. //if (GameM.commonData.fightRoleServerCfg[rolelv.toString()].is_fight == 1) {
  165. let cfg = GameM.commonData.fightRoleCfg[rolelv.toString()];
  166. this.flawTimes = cfg.flawclicktimes;
  167. this.flawDuration = cfg.flawduration;
  168. this.flawRate = cfg.flawrate;
  169. this.flawNum = cfg.flawnum;
  170. let serCfg = GameM.commonData.fightRoleServerCfg[rolelv.toString()];
  171. let fightrole = new FightRole();
  172. fightrole.arrayIndex = -1;
  173. fightrole.blood = serCfg.bloods;
  174. fightrole.buffId = 1; //无效 在战斗时生效
  175. fightrole.fightTime = serCfg.times;
  176. fightrole.fightType = 3;
  177. fightrole.lv = rolelv;
  178. fightrole.name = serCfg.name;
  179. fightrole.star = 1; //弃用
  180. fightrole.rewardId = 1//弃用;
  181. console.log("Trigger Fight 3", fightrole);
  182. UIMng.Ins.AsyncGetPanel(PanelType.FightRoleBPanel, (panel) => {
  183. panel.OnEnter(fightrole);
  184. });
  185. //UIMng.Ins.GetPanel(PanelType.FightRoleBPanel).OnEnter(fightrole);
  186. //}
  187. }
  188. EnterFight() {
  189. //console.log("EnterFight:", this.composeFightRoles);
  190. HttpM.Instance.SendData(HTTP_TYPE.getMyBossRecords, { version: GameM.commonData.version }, (res) => {
  191. LogUtil.logV("-->get boss:", res);
  192. //console.log("-->res getboss:", res);
  193. if (res.data != null) {
  194. if (res.data.length > 0) {
  195. this.composeFightRoles = res.data;
  196. console.log("select role panel");
  197. UIMng.Ins.AsyncGetPanel(PanelType.FightRolePanel, (panel) => {
  198. panel.OnEnter();
  199. });
  200. //UIMng.Ins.GetPanel(PanelType.FightRolePanel).OnEnter();
  201. } else {
  202. console.log("no master");
  203. EffectNode.instance.PlayTip(`达到指定等级可招来武将`);
  204. }
  205. }
  206. }, null, null, true);
  207. }
  208. /**获取 更新武将的星级 服务器获取*/
  209. GetFightRoleStars(callback: Function) {
  210. this.fightRolesStars = [];
  211. //第一次解锁的武将都是3星
  212. for (let i = 0; i < this.composeFightRoles.length; i++) {
  213. //this.fightRolesStars[i]=Random.Range(1,4);
  214. this.fightRolesStars[i] = 3;
  215. console.log("Star:" + this.fightRolesStars[i]);
  216. }
  217. callback();
  218. //HttpM.Instance.SendData();
  219. }
  220. /**解锁伙伴
  221. * @param mateid 伙伴id
  222. * @param name 图片id
  223. */
  224. UnlockMate(mateid: number, name: number) {
  225. MateData.Ins.UnlockMate(mateid);
  226. // UIMng.Ins.GetPanel(PanelType.MateUnlockPanel).OnEnter({ lv: name });
  227. //主界面 师徒5人坐标更新
  228. UiM.Instance.hallNode.getComponent(Main).DisplayMate();
  229. }
  230. /**
  231. * 三国战戟 解锁伙伴
  232. * @param data 解锁的伙伴数据
  233. */
  234. UnLockMateSanGuo(data: any) {
  235. for (let i = 0; i < data.length; i++) {
  236. MateData.Ins.UnlockMate(data[i]);
  237. }
  238. //主界面 师徒5人坐标更新
  239. UiM.Instance.hallNode.getComponent(Main).DisplayMate();
  240. }
  241. /**更新触发2 战斗概率数据*/
  242. UpdateTriggerFightRate() {
  243. let cfg = GameM.commonData.fightCfg;
  244. this.triggerFightRoleMinLv = cfg.unlock_lv;
  245. this.fightTriggerTimes = cfg.fight_trigger_times;
  246. //"unlock_lv":14,
  247. //this.triggerFightRoleMinLv = 7;
  248. //max 40 40 39 38 37 36 百分制
  249. this.triggerFightRates[0] = Number((GameM.commonData.maxCarLevel - cfg.nor_lv) / cfg.delta_lv) * cfg.rate_add_delta * 0.01 + cfg.nor_rate;
  250. this.triggerFightRates[1] = this.triggerFightRates[0] * cfg.rates[1] * 0.01;
  251. this.triggerFightRates[2] = this.triggerFightRates[0] * cfg.rates[2] * 0.01;
  252. this.triggerFightRates[3] = this.triggerFightRates[0] * cfg.rates[3] * 0.01;
  253. this.triggerFightRates[4] = this.triggerFightRates[0] * cfg.rates[4] * 0.01;
  254. //this.triggerFightRates[0] = 80;
  255. //this.triggerFightRates[1] = 80;
  256. //this.triggerFightRates[2] = 80;
  257. //this.triggerFightRates[3] = 80;
  258. //this.triggerFightRates[4] = 80;
  259. // console.log("-->UpdateRate:", this.triggerFightRates);
  260. }
  261. /**获取武将遗言
  262. * @param type 类型 1 words1 2 words2
  263. */
  264. GetWords(type: number) {
  265. if (this.fightWordsCfg == null) {
  266. this.fightWordsCfg = cc.loader.getRes("configs/fightWordsCfg").json;
  267. }
  268. if (type == 1) {
  269. return this.fightWordsCfg.words1[Random.Range(0, this.fightWordsCfg.words1.length)];
  270. } else {
  271. return this.fightWordsCfg.words2[Random.Range(0, this.fightWordsCfg.words2.length)];
  272. }
  273. }
  274. }
  275. /**战斗武将*/
  276. export class FightRole {
  277. /**战斗id 该战斗存在的唯一标志*/
  278. fightId: string = null;
  279. /**战斗类型 1 第一次合成解锁战斗 2 合成已解锁的武将战斗 3 大富翁BOSS战*/
  280. fightType: number = 1;
  281. /**战斗类型为1 时 在武将队列中的索引 -1 表示没有*/
  282. arrayIndex: number = 0;
  283. /**武将名称*/
  284. name: string = null;
  285. /**武将等级*/
  286. lv: number = 1;
  287. /**武将星级*/
  288. star: number = 1;
  289. /**武将血量*/
  290. blood: number = 10;
  291. /**击败需要的时间*/
  292. fightTime: number = 30;
  293. /**buff id 弃用 buff改用 武将血量减少时获取 并 生效*/
  294. buffId: number = 1;
  295. /**奖励宝箱id*/
  296. rewardId: number = 1001;
  297. }
  298. /**战斗结果*/
  299. export class FightResult {
  300. /**战斗id 该战斗存在的唯一标志*/
  301. fightId: string = null;
  302. /**战斗结果 1 战斗胜利 其他 战斗失败*/
  303. result: number = 1;
  304. /**战斗类型 1 第一次合成解锁战斗 2 合成已解锁的武将战斗 3 大富翁BOSS战*/
  305. fightType: number = 1;
  306. /**武将等级*/
  307. lv: number = 1;
  308. /**武将星级*/
  309. star: number = 1;
  310. /**奖励 等*/
  311. rewards: any[] = null;
  312. /**奖励 天赋石*/
  313. talent: number = 0;
  314. /**解锁的伙伴id*/
  315. unlock_mateid: string = null;
  316. /**今日剩余奖励次数 只用于战斗触发2*/
  317. reward_times: number = 0;
  318. }