RoleManager.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { Framework } from "../../framework/Framework";
  2. import { ItemEnum } from "../common/InterfaceAddEnum";
  3. import { LoginMgr } from "../common/LoginManager";
  4. import { FateattridConf } from "../config/FateattridConf";
  5. import { FateConf } from "../config/FateConf";
  6. import { RoleData } from "../data/RoleData";
  7. import { RoleConf } from "../ui/tower/conf/RoleConf";
  8. import { ObjectValueType } from "../ui/tower/data/BattleEnum";
  9. import { GoodsManager } from "./GoodsManager";
  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. //英雄升星
  20. static sendRoleAdvance(args: { hid: number }, callback) {
  21. LoginMgr.sendPost('role', 'grade_up', (data) => {
  22. console.log(data);
  23. let rData = RoleData.getRoleDataByID(args.hid);
  24. rData.grade = data.grade;
  25. RoleData.setRoleDataByID(args.hid, rData)
  26. if(data.awards){
  27. Framework.unionManager.parseServerAwards(data.awards);
  28. }
  29. callback();
  30. }, args)
  31. }
  32. static sendFateLevelUp(args: { id: number }, callback){
  33. LoginMgr.sendPost('role', 'fate_level_up', (data) => {
  34. console.log(data);
  35. this.setFateData(data.fate);
  36. if(data.awards){
  37. Framework.unionManager.parseServerAwards(data.awards);
  38. }
  39. callback();
  40. }, args)
  41. }
  42. static getRolesRaceGroup() {
  43. let roles = {};
  44. let roleConf = RoleConf.data
  45. for (const rId in roleConf) {
  46. if (Object.prototype.hasOwnProperty.call(roleConf, rId)) {
  47. const element = roleConf[rId];
  48. let rData = RoleData.getRoleDataByID(rId);
  49. if (roles[element.Race]) {
  50. if (rData) {
  51. roles[element.Race].push(rData);
  52. } else {
  53. roles[element.Race].push({ conf: element });
  54. }
  55. } else {
  56. roles[element.Race] = [];
  57. if (rData) {
  58. roles[element.Race].push(rData);
  59. } else {
  60. roles[element.Race].push({ conf: element });
  61. }
  62. }
  63. }
  64. }
  65. for (const key in roles) {
  66. if (Object.prototype.hasOwnProperty.call(roles, key)) {
  67. const element = roles[key];
  68. element.sort((a, b) => {
  69. return Number(a.conf.Id) < Number(b.conf.Id) ? -1 : 1;
  70. });
  71. }
  72. }
  73. return roles;
  74. }
  75. static getRoleById(rId: number) {
  76. let roleConf = RoleConf.data[rId]
  77. if (roleConf){
  78. let rData = RoleData.getRoleDataByID(rId);
  79. if (rData) {
  80. return rData;
  81. } else {
  82. return { conf: roleConf, type: ItemEnum.role};
  83. }
  84. }
  85. return null;
  86. }
  87. static setFateData(data: { [key: string]: number }) {
  88. let fateData = {};
  89. let conf = FateConf.data;
  90. let atteConf = FateattridConf.data;
  91. for (const key in conf) {
  92. if (Object.prototype.hasOwnProperty.call(conf, key)) {
  93. const element = conf[key];
  94. fateData[key] = {
  95. id:key,
  96. conf:element,
  97. level:0
  98. };
  99. if (data[key]) {
  100. fateData[key].level = data[key];
  101. }
  102. }
  103. }
  104. RoleData.fate = fateData;
  105. }
  106. /**
  107. * 获取单个英雄全属性
  108. * @param typeID 英雄ID
  109. * return {[key:ObjectValueType]:number}
  110. */
  111. static getRoleAttackAdd(typeID): {[key:number]:number} {
  112. let valueList:{[key:number]:number} = {}
  113. return valueList;
  114. }
  115. }