FormationData.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { DataSystem } from "../../core/data/DataSystem";
  2. import { MapData } from "../../core/data/MapData";
  3. import { Http } from "../../core/net/Http";
  4. import { ConfigData } from "../../data/ConfigData";
  5. /**
  6. * 阵位数据
  7. * @description 阵位编号为key,武将数据为value
  8. * @author 袁浩
  9. */
  10. export class FormationData extends MapData<number, number> {
  11. /**
  12. * 从服务端拉取数据
  13. * @param http
  14. */
  15. public async pull(http: Http) {
  16. let result = await http.send("/api/formation/GetFormation");
  17. if (result && result.data) {
  18. this.set(1, null);
  19. this.set(2, null);
  20. this.set(3, null);
  21. this.set(4, null);
  22. this.set(5, null);
  23. this.copy(result.data);
  24. }
  25. }
  26. /**
  27. * 根据武将编号获取阵位
  28. * @param heroID 武将编号
  29. * @returns 返回1就是1号位,返回0就是武将不在阵上
  30. */
  31. public getIDByHero(heroID: number) {
  32. let obj = this.object;
  33. for (let key in obj) {
  34. if (parseInt(obj[key]) == heroID) {
  35. return parseInt(key);
  36. }
  37. }
  38. return 0;
  39. }
  40. /**
  41. * 根据武将编号获取下一个武将
  42. * @param heroID
  43. */
  44. public nextHexo(heroID: number) {
  45. let id = this.getIDByHero(heroID);
  46. while (true) {
  47. id = id == 5 ? 1 : id + 1;
  48. if (this.get(id)) {
  49. return this.get(id);
  50. }
  51. }
  52. }
  53. /**
  54. * 根据武将编号获取上一个武将
  55. * @param heroID
  56. */
  57. public preHero(heroID: number) {
  58. let id = this.getIDByHero(heroID);
  59. while (true) {
  60. id = id == 1 ? 5 : id - 1;
  61. if (this.get(id)) {
  62. return this.get(id);
  63. }
  64. }
  65. }
  66. /**
  67. * 羁绊配置获取
  68. */
  69. public getFetter() {
  70. let campCount: any = {};
  71. let formationData = this.object;
  72. for (let key in formationData) {
  73. if (formationData[key]) {
  74. let heroConfig = DataSystem.getData(ConfigData).get("general")[formationData[key]];
  75. console.log("Config: ",heroConfig);
  76. campCount[heroConfig.camp] = campCount[heroConfig.camp] || 0;
  77. campCount[heroConfig.camp]++;
  78. }
  79. }
  80. let countList: { camp: number, count: number }[] = [];
  81. for (let key in campCount) {
  82. countList.push({ camp: parseInt(key), count: campCount[key] });
  83. }
  84. countList.sort((a: { camp: number, count: number }, b: { camp: number, count: number }) => {
  85. return b.count - a.count;
  86. });
  87. let fetterID = 0;
  88. let attackPer = 0;
  89. let cri = 0;
  90. let nationID = 0;
  91. if (countList.length) {
  92. let camp = 0;
  93. if (countList[0].count == 2) {
  94. fetterID = 1;
  95. camp = countList[0].camp;
  96. }
  97. else if (countList[0].count == 4) {
  98. fetterID = 4;
  99. camp = countList[0].camp;
  100. }
  101. else if (countList[0].count == 5) {
  102. fetterID = 5;
  103. camp = countList[0].camp;
  104. }
  105. else if (countList[0].count == 3 && countList[1] && countList[1].count == 2) {
  106. fetterID = 3;
  107. camp = countList[0].camp;
  108. }
  109. else if (countList[0].count == 3) {
  110. fetterID = 2;
  111. camp = countList[0].camp;
  112. }
  113. if (fetterID) {
  114. let fetterConfig = DataSystem.getData(ConfigData).get("fetter")[fetterID];
  115. let buffConfig = DataSystem.getData(ConfigData).get("buff");
  116. let buffList = fetterConfig.activeBuff.split(",");
  117. for (let i = 0; i < buffList.length; i++) {
  118. attackPer += (buffConfig[buffList[i]].attackPer || 0);
  119. cri += (buffConfig[buffList[i]].cri || 0);
  120. }
  121. if (fetterConfig.nation) {
  122. let nationBuff = buffConfig[fetterConfig.nation.split(",")[camp - 1]];
  123. nationID = nationBuff.id;
  124. }
  125. }
  126. }
  127. return { fetterID: fetterID, attackPer: attackPer, cri: cri, nationID: nationID };
  128. }
  129. }