RoleManager.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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.CalcRoleAttr(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(rId){
  39. let role = RoleData.getRoleDataByID(rId);
  40. return role.attr;
  41. }
  42. static CalcRoleAttr(role:RoleServer) {
  43. let attrs:AttrBaseData = {
  44. [AttrEnum.attack]: 0,
  45. [AttrEnum.defence]: 0,
  46. [AttrEnum.hp]: 0,
  47. [AttrEnum.speed]: 0,
  48. [AttrEnum.broken]: 0,
  49. [AttrEnum.power]: 0,
  50. [AttrEnum.hp_p]: 0,
  51. [AttrEnum.attack_p]: 0,
  52. [AttrEnum.defence_p]: 0,
  53. [AttrEnum.hit]: 0,
  54. [AttrEnum.miss]: 0,
  55. [AttrEnum.crite]: 0,
  56. [AttrEnum.decrite]: 0,
  57. [AttrEnum.critedamage]: 0,
  58. [AttrEnum.adddamage]: 0,
  59. [AttrEnum.dedamage]: 0,
  60. [AttrEnum.suck]: 0,
  61. [AttrEnum.thorns]: 0,
  62. [AttrEnum.block]: 0
  63. };
  64. //星级
  65. let gradeConf = RolegradeConf.data[String(role['grade'])];
  66. let roleConf = RoleConf.data[String(role['id'])]
  67. let atkNum = roleConf['Damage'];
  68. atkNum = atkNum * gradeConf[`LvAttrMod${roleConf['Quality']}`];
  69. attrs[AttrEnum.attack] += Number(atkNum);
  70. //装备
  71. let equipData = EquipManager.getEquipWearRaceGroup()[roleConf['Race']];
  72. for (const key in equipData) {
  73. if (Object.prototype.hasOwnProperty.call(equipData, key)) {
  74. const element = equipData[key];
  75. if (element) {
  76. for (let index = 1; index <= 2; index++) {
  77. let Stat = element.conf['Stat' + index];
  78. if (Stat != 0) {
  79. let str = Stat.split(':');
  80. attrs[str[0]] += Number(str[1]);
  81. }
  82. }
  83. }
  84. }
  85. }
  86. //羁绊
  87. return attrs;
  88. }
  89. //英雄升星
  90. static sendRoleAdvance(args: { hid: number }, callback) {
  91. LoginMgr.sendPost('role', 'grade_up', (data) => {
  92. console.log(data);
  93. let rData = RoleData.getRoleDataByID(args.hid);
  94. rData.grade = data.grade;
  95. RoleData.setRoleDataByID(args.hid, rData)
  96. if (data.awards) {
  97. Framework.unionManager.parseServerAwards(data.awards);
  98. Framework.unionManager.UpdateRoleAttr([args.hid]);
  99. }
  100. callback();
  101. }, args)
  102. }
  103. static sendFateLevelUp(args: { id: number }, callback) {
  104. LoginMgr.sendPost('role', 'fate_level_up', (data) => {
  105. console.log(data);
  106. this.setFateData(data.fate);
  107. if (data.awards) {
  108. Framework.unionManager.parseServerAwards(data.awards);
  109. }
  110. callback();
  111. }, args)
  112. }
  113. static getRolesRaceGroup() {
  114. let roles = {};
  115. let roleConf = RoleConf.data
  116. for (const rId in roleConf) {
  117. if (Object.prototype.hasOwnProperty.call(roleConf, rId)) {
  118. const element = roleConf[rId];
  119. let rData = RoleData.getRoleDataByID(rId);
  120. if (roles[element.Race]) {
  121. if (rData) {
  122. roles[element.Race].push(rData);
  123. } else {
  124. roles[element.Race].push({ conf: element });
  125. }
  126. } else {
  127. roles[element.Race] = [];
  128. if (rData) {
  129. roles[element.Race].push(rData);
  130. } else {
  131. roles[element.Race].push({ conf: element });
  132. }
  133. }
  134. }
  135. }
  136. for (const key in roles) {
  137. if (Object.prototype.hasOwnProperty.call(roles, key)) {
  138. const element = roles[key];
  139. element.sort((a, b) => {
  140. return Number(a.conf.Id) < Number(b.conf.Id) ? -1 : 1;
  141. });
  142. }
  143. }
  144. return roles;
  145. }
  146. static getRoleById(rId: number) {
  147. let roleConf = RoleConf.data[rId]
  148. if (roleConf) {
  149. let rData = RoleData.getRoleDataByID(rId);
  150. if (rData) {
  151. return rData;
  152. } else {
  153. return { conf: roleConf, type: ItemEnum.role };
  154. }
  155. }
  156. return null;
  157. }
  158. static setFateData(data: { [key: string]: number }) {
  159. let fateData = {};
  160. let conf = FateConf.data;
  161. let atteConf = FateattridConf.data;
  162. for (const key in conf) {
  163. if (Object.prototype.hasOwnProperty.call(conf, key)) {
  164. const element = conf[key];
  165. fateData[key] = {
  166. id: key,
  167. conf: element,
  168. level: 0
  169. };
  170. if (data[key]) {
  171. fateData[key].level = data[key];
  172. }
  173. }
  174. }
  175. RoleData.fate = fateData;
  176. }
  177. }