RoleManager.ts 6.4 KB

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