RoleManager.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { Framework } from "../../framework/Framework";
  2. import { AttrBaseData, AttrConf, AttrEnum, ItemEnum, Role, RoleServer } from "../common/InterfaceAddEnum";
  3. import { LoginMgr } from "../common/LoginManager";
  4. import { FateattridConf } from "../config/FateattridConf";
  5. import { FateConf } from "../config/FateConf";
  6. import { RolegradeConf } from "../config/RolegradeConf";
  7. import { RoleData } from "../data/RoleData";
  8. import { RoleConf } from "../ui/tower/conf/RoleConf";
  9. import { EquipManager } from "./EquipManager";
  10. //角色管理器
  11. export class RoleManager {
  12. //抽一个英雄
  13. static getNewRole() {
  14. LoginMgr.sendPost('tavern', 'get', (data) => {
  15. console.log(data);
  16. }, {})
  17. return false;
  18. }
  19. static setData(data: { [id: string]: RoleServer }): void {
  20. let roles = {}
  21. let rConf = RoleConf.data;
  22. if (data) {
  23. for (const id in data) {
  24. if (data.hasOwnProperty(id)) {
  25. if (rConf[id]) {
  26. let role: Role = <Role>data[id];
  27. role.conf = rConf[id];
  28. role.type = ItemEnum.role;
  29. role.attr = this.getRoleAttr(data[id]);
  30. roles[data[id].id] = role;
  31. // console.log(`ID: ${id}, Name: ${role.name}, Level: ${role.level}`);
  32. }
  33. }
  34. }
  35. }
  36. RoleData.setData(roles);
  37. }
  38. static getRoleAttr(role): AttrBaseData {
  39. let attrs:AttrBaseData = {
  40. [AttrEnum.attack]: 0,
  41. [AttrEnum.defence]: 0,
  42. [AttrEnum.hp]: 0,
  43. [AttrEnum.speed]: 0,
  44. [AttrEnum.broken]: 0,
  45. [AttrEnum.power]: 0,
  46. [AttrEnum.hp_p]: 0,
  47. [AttrEnum.attack_p]: 0,
  48. [AttrEnum.defence_p]: 0,
  49. [AttrEnum.hit]: 0,
  50. [AttrEnum.miss]: 0,
  51. [AttrEnum.crite]: 0,
  52. [AttrEnum.decrite]: 0,
  53. [AttrEnum.critedamage]: 0,
  54. [AttrEnum.adddamage]: 0,
  55. [AttrEnum.dedamage]: 0,
  56. [AttrEnum.suck]: 0,
  57. [AttrEnum.thorns]: 0,
  58. [AttrEnum.block]: 0
  59. };
  60. //星级
  61. let gradeConf = RolegradeConf.data[String(role['grade'])];
  62. let roleConf = RoleConf.data[String(role['id'])]
  63. let atkNum = roleConf['Damage'];
  64. atkNum = atkNum * gradeConf[`LvAttrMod${roleConf['Quality']}`];
  65. attrs[AttrEnum.attack] += Number(atkNum);
  66. //装备
  67. let equipData = EquipManager.getEquipWearRaceGroup()[roleConf['Race']];
  68. for (const key in equipData) {
  69. if (Object.prototype.hasOwnProperty.call(equipData, key)) {
  70. const element = equipData[key];
  71. if (element) {
  72. for (let index = 1; index <= 2; index++) {
  73. let Stat = element.conf['Stat' + index];
  74. if (Stat != 0) {
  75. let str = Stat.split(':');
  76. attrs[str[0]] += Number(str[1]);
  77. }
  78. }
  79. }
  80. }
  81. }
  82. //羁绊
  83. return attrs;
  84. }
  85. //英雄升星
  86. static sendRoleAdvance(args: { hid: number }, callback) {
  87. LoginMgr.sendPost('role', 'grade_up', (data) => {
  88. console.log(data);
  89. let rData = RoleData.getRoleDataByID(args.hid);
  90. rData.grade = data.grade;
  91. RoleData.setRoleDataByID(args.hid, rData)
  92. if (data.awards) {
  93. Framework.unionManager.parseServerAwards(data.awards);
  94. }
  95. callback();
  96. }, args)
  97. }
  98. static sendFateLevelUp(args: { id: number }, callback) {
  99. LoginMgr.sendPost('role', 'fate_level_up', (data) => {
  100. console.log(data);
  101. this.setFateData(data.fate);
  102. if (data.awards) {
  103. Framework.unionManager.parseServerAwards(data.awards);
  104. }
  105. callback();
  106. }, args)
  107. }
  108. static getRolesRaceGroup() {
  109. let roles = {};
  110. let roleConf = RoleConf.data
  111. for (const rId in roleConf) {
  112. if (Object.prototype.hasOwnProperty.call(roleConf, rId)) {
  113. const element = roleConf[rId];
  114. let rData = RoleData.getRoleDataByID(rId);
  115. if (roles[element.Race]) {
  116. if (rData) {
  117. roles[element.Race].push(rData);
  118. } else {
  119. roles[element.Race].push({ conf: element });
  120. }
  121. } else {
  122. roles[element.Race] = [];
  123. if (rData) {
  124. roles[element.Race].push(rData);
  125. } else {
  126. roles[element.Race].push({ conf: element });
  127. }
  128. }
  129. }
  130. }
  131. for (const key in roles) {
  132. if (Object.prototype.hasOwnProperty.call(roles, key)) {
  133. const element = roles[key];
  134. element.sort((a, b) => {
  135. return Number(a.conf.Id) < Number(b.conf.Id) ? -1 : 1;
  136. });
  137. }
  138. }
  139. return roles;
  140. }
  141. static getRoleById(rId: number) {
  142. let roleConf = RoleConf.data[rId]
  143. if (roleConf) {
  144. let rData = RoleData.getRoleDataByID(rId);
  145. if (rData) {
  146. return rData;
  147. } else {
  148. return { conf: roleConf, type: ItemEnum.role };
  149. }
  150. }
  151. return null;
  152. }
  153. static setFateData(data: { [key: string]: number }) {
  154. let fateData = {};
  155. let conf = FateConf.data;
  156. let atteConf = FateattridConf.data;
  157. for (const key in conf) {
  158. if (Object.prototype.hasOwnProperty.call(conf, key)) {
  159. const element = conf[key];
  160. fateData[key] = {
  161. id: key,
  162. conf: element,
  163. level: 0
  164. };
  165. if (data[key]) {
  166. fateData[key].level = data[key];
  167. }
  168. }
  169. }
  170. RoleData.fate = fateData;
  171. }
  172. }