MarshalSkillSystem.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import { Component, _decorator } from "cc";
  2. import { DataSystem } from "../core/data/DataSystem";
  3. import { Http } from "../core/net/Http";
  4. import { WindowOpenMode } from "../core/ui/window/WindowOpenMode";
  5. import { WindowSystem } from "../core/ui/window/WindowSystem";
  6. import { Hero_Client, UserHeroData } from "../hero/UserHeroData";
  7. import { MarshalData, Skill } from "./MarshalData";
  8. const { ccclass } = _decorator;
  9. /**
  10. * 统帅技能数据处理
  11. * @description 统帅技能数据更新 提示弹窗等操作
  12. * @author 郑聂华
  13. */
  14. @ccclass('MarshalSkillSystem')
  15. export class MarshalSkillSystem extends Component {
  16. private static thisObject: MarshalSkillSystem;
  17. private marshalData: MarshalData;
  18. private get MarshalData(): MarshalData {
  19. if (!this.marshalData) this.marshalData = DataSystem.getData(MarshalData);
  20. return this.marshalData;
  21. }
  22. private set MarshalData(value: MarshalData) {
  23. this.marshalData = value;
  24. }
  25. start() {
  26. MarshalSkillSystem.thisObject = this;
  27. }
  28. onDestroy() {
  29. MarshalSkillSystem.thisObject = null;
  30. }
  31. /**更新统帅技能和通知队列数据*/
  32. private updateNoticeQueue() {
  33. let starNum = 0;
  34. let userHeroData = DataSystem.getData(UserHeroData);
  35. for (let id of userHeroData.haveHeros) {
  36. let tempHero = userHeroData.get(id);
  37. starNum += tempHero.server.star;
  38. }
  39. let tempKeys = this.MarshalData.marshalSkillData.lvNeedStarsMap.keys();
  40. for (let id of tempKeys) {
  41. let tempStarAry = this.MarshalData.marshalSkillData.lvNeedStarsMap.get(id);
  42. for (let i = 0; i < tempStarAry.length; i++) {
  43. if (tempStarAry[i] <= starNum) {
  44. let curLv = this.MarshalData.marshalSkillData.lvMarshalSkill.get(id);
  45. if (curLv < i + 1) {
  46. let param = { type: curLv <= 0 ? 1 : 2, id: id, lv: i + 1, lastLv: curLv };
  47. this.MarshalData.skillNoticeQueue.push(param);
  48. this.MarshalData.skillUnlockLvUpQueue.push(param);
  49. this.MarshalData.marshalSkillData.lvMarshalSkill.set(id, i + 1);
  50. }
  51. }
  52. }
  53. }
  54. }
  55. /**
  56. * 更新统帅技能等级数据
  57. */
  58. private async updateSkillLvData(http: Http) {
  59. let numStar = 0;
  60. let userHeroData = DataSystem.getData(UserHeroData);
  61. //await userHeroData.pull(http);
  62. for (let id of userHeroData.haveHeros) {
  63. let tempHero = userHeroData.get(id);
  64. numStar += tempHero.server.star;
  65. }
  66. let tempKeys = this.MarshalData.marshalSkillData.lvNeedStarsMap.keys();
  67. for (let id of tempKeys) {
  68. let tempStarAry = this.MarshalData.marshalSkillData.lvNeedStarsMap.get(id);
  69. for (let i = 0; i < tempStarAry.length; i++) {
  70. if (numStar >= tempStarAry[i])
  71. this.MarshalData.marshalSkillData.lvMarshalSkill.set(id, i + 1);
  72. }
  73. }
  74. }
  75. /**打开统帅技能通知小弹窗*/
  76. private openMarshalSkillNotice() {
  77. if (this.MarshalData.skillNoticeQueue && this.MarshalData.skillNoticeQueue.length > 0) {
  78. let param = this.MarshalData.skillNoticeQueue[0];
  79. WindowSystem.open("prefabs/ui/marshalStage/marshalSkillNotice", WindowOpenMode.NotCloseAndCover, [param]);
  80. }
  81. }
  82. /**打开统帅技能信息通知弹窗*/
  83. private openMarshalSkillUnlockLv() {
  84. if (this.MarshalData.skillUnlockLvUpQueue && this.MarshalData.skillUnlockLvUpQueue.length > 0) {
  85. let param = this.MarshalData.skillUnlockLvUpQueue[0];
  86. WindowSystem.open("prefabs/ui/marshalStage/marshalSkillLvUp", WindowOpenMode.NotCloseAndCover, [param]);
  87. }
  88. }
  89. /**获取技能效果值
  90. * @param skill 技能对象
  91. * @param lv 技能等级
  92. */
  93. private getSkillValue(skill: Skill, lv: number) {
  94. switch (skill.attType) {
  95. case 1:
  96. return;
  97. case 2:
  98. return;
  99. case 3:
  100. return (skill.skillValue[lv - 1]) / 10000;
  101. case 4:
  102. return;
  103. case 5:
  104. return skill.skillValue[lv - 1];
  105. }
  106. }
  107. /**获取技能效果值字符串
  108. * @param skill 技能对象
  109. * @param lv 技能等级
  110. */
  111. private getSkillValueStr(skill: Skill, lv: number) {
  112. switch (skill.attType) {
  113. case 1:
  114. return;
  115. case 2:
  116. return;
  117. case 3:
  118. return ((skill.skillValue[lv - 1]) / 10000 * 100).toFixed(1) + "%";
  119. case 4:
  120. return;
  121. case 5:
  122. return skill.skillValue[lv - 1] + "秒";
  123. }
  124. }
  125. /**
  126. * 获取技能统帅加成值
  127. * @param hero 统帅
  128. */
  129. private getSkillAddValue(hero: Hero_Client) {
  130. return Math.pow(hero.commander / 100, 1.9);
  131. }
  132. /**
  133. * 获取技能统帅加成值字符串
  134. * @param skill 技能
  135. * @param lv 技能等级
  136. * @param hero 武将
  137. */
  138. private getSkillAddValueStr(skill: Skill, lv: number, hero: Hero_Client) {
  139. let addcommander = Math.pow(hero.commander / 100, 1.9);
  140. switch (skill.attType) {
  141. case 1:
  142. return;
  143. case 2:
  144. return;
  145. case 3:
  146. return (addcommander * skill.skillValue[lv - 1] / 10000 * 100).toFixed(1) + "%";
  147. case 4:
  148. return;
  149. case 5:
  150. return (addcommander * skill.skillValue[lv - 1]).toFixed(1) + "秒";
  151. }
  152. }
  153. /**更新统帅技能信息并检测打开通知弹窗
  154. * @param id 武将id
  155. */
  156. public static updateMarshalSkillInfo(id?: number) {
  157. this.thisObject.updateNoticeQueue();
  158. this.thisObject.openMarshalSkillNotice();
  159. }
  160. /**打开统帅技能通知小弹窗*/
  161. public static openMarshalSkillNotice() {
  162. this.thisObject.openMarshalSkillNotice();
  163. }
  164. /**打开统帅技能信息通知弹窗*/
  165. public static openMarshalSkillUnlockLv() {
  166. this.thisObject.openMarshalSkillUnlockLv();
  167. }
  168. /**更新统帅技能和通知队列数据*/
  169. public static updateNoticeQueue() {
  170. this.thisObject.updateNoticeQueue();
  171. }
  172. /** 更新统帅技能等级数据*/
  173. public static updateSkillLvData(http: Http) {
  174. this.thisObject.updateSkillLvData(http);
  175. }
  176. /**获取技能效果值
  177. * @param skill 技能对象
  178. * @param lv 技能等级
  179. */
  180. public static getSkillValue(skill: Skill, lv: number) {
  181. return this.thisObject.getSkillValue(skill, lv);
  182. }
  183. /**获取技能效果值字符串
  184. * @param skill 技能对象
  185. * @param lv 技能等级
  186. */
  187. public static getSkillValueStr(skill: Skill, lv: number) {
  188. return this.thisObject.getSkillValueStr(skill, lv);
  189. }
  190. /**
  191. * 获取技能统帅加成值
  192. * @param hero 统帅
  193. */
  194. public static getSkillAddValue(hero: Hero_Client) {
  195. return this.thisObject.getSkillAddValue(hero);
  196. }
  197. /**
  198. * 获取技能统帅加成值字符串
  199. * @param skill 技能
  200. * @param lv 技能等级
  201. * @param hero 武将
  202. */
  203. public static getSkillAddValueStr(skill: Skill, lv: number, hero: Hero_Client) {
  204. return this.thisObject.getSkillAddValueStr(skill, lv, hero);
  205. }
  206. }