RoleManager.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 { GoodsManager } from "./GoodsManager";
  9. //角色管理器
  10. export class RoleManager {
  11. //抽一个英雄
  12. static getNewRole() {
  13. LoginMgr.sendPost('tavern', 'get', (data) => {
  14. console.log(data);
  15. }, {})
  16. return false;
  17. }
  18. //英雄升星
  19. static sendRoleAdvance(args: { hid: number }, callback) {
  20. LoginMgr.sendPost('role', 'grade_up', (data) => {
  21. console.log(data);
  22. let rData = RoleData.getRoleDataByID(args.hid);
  23. rData.grade = data.grade;
  24. RoleData.setRoleDataByID(args.hid, rData)
  25. if(data.awards){
  26. Framework.unionManager.parseServerAwards(data.awards);
  27. }
  28. callback();
  29. }, args)
  30. }
  31. static sendFateLevelUp(args: { id: number }, callback){
  32. LoginMgr.sendPost('role', 'fate_level_up', (data) => {
  33. console.log(data);
  34. this.setFateData(data.fate);
  35. if(data.awards){
  36. Framework.unionManager.parseServerAwards(data.awards);
  37. }
  38. callback();
  39. }, args)
  40. }
  41. static getRolesRaceGroup() {
  42. let roles = {};
  43. let roleConf = RoleConf.data
  44. for (const rId in roleConf) {
  45. if (Object.prototype.hasOwnProperty.call(roleConf, rId)) {
  46. const element = roleConf[rId];
  47. let rData = RoleData.getRoleDataByID(rId);
  48. if (roles[element.Race]) {
  49. if (rData) {
  50. roles[element.Race].push(rData);
  51. } else {
  52. roles[element.Race].push({ conf: element });
  53. }
  54. } else {
  55. roles[element.Race] = [];
  56. if (rData) {
  57. roles[element.Race].push(rData);
  58. } else {
  59. roles[element.Race].push({ conf: element });
  60. }
  61. }
  62. }
  63. }
  64. for (const key in roles) {
  65. if (Object.prototype.hasOwnProperty.call(roles, key)) {
  66. const element = roles[key];
  67. element.sort((a, b) => {
  68. return Number(a.conf.Id) < Number(b.conf.Id) ? -1 : 1;
  69. });
  70. }
  71. }
  72. return roles;
  73. }
  74. static getRoleById(rId: number) {
  75. let roleConf = RoleConf.data[rId]
  76. if (roleConf){
  77. let rData = RoleData.getRoleDataByID(rId);
  78. if (rData) {
  79. return rData;
  80. } else {
  81. return { conf: roleConf, type: ItemEnum.role};
  82. }
  83. }
  84. return null;
  85. }
  86. static setFateData(data: { [key: string]: number }) {
  87. let fateData = {};
  88. let conf = FateConf.data;
  89. let atteConf = FateattridConf.data;
  90. for (const key in conf) {
  91. if (Object.prototype.hasOwnProperty.call(conf, key)) {
  92. const element = conf[key];
  93. fateData[key] = {
  94. id:key,
  95. conf:element,
  96. level:0
  97. };
  98. if (data[key]) {
  99. fateData[key].level = data[key];
  100. }
  101. }
  102. }
  103. RoleData.fate = fateData;
  104. }
  105. }