RoleManager.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { Framework } from "../../framework/Framework";
  2. import { LoginMgr } from "../common/LoginManager";
  3. import { RoleData } from "../data/RoleData";
  4. import { RoleConf } from "../ui/tower/conf/RoleConf";
  5. import { GoodsManager } from "./GoodsManager";
  6. //角色管理器
  7. export class RoleManager {
  8. //抽一个英雄
  9. static getNewRole() {
  10. LoginMgr.sendPost('tavern', 'get', (data) => {
  11. console.log(data);
  12. }, {})
  13. return false;
  14. }
  15. //英雄升星
  16. static sendRoleAdvance(args: { hid: number }, callback) {
  17. LoginMgr.sendPost('role', 'grade_up', (data) => {
  18. console.log(data);
  19. let rData = RoleData.getRoleDataByID(args.hid);
  20. rData.grade = data.grade;
  21. RoleData.setRoleDataByID(args.hid, rData)
  22. if(data.awards){
  23. Framework.unionManager.parseServerAwards(data.awards);
  24. }
  25. callback();
  26. }, args)
  27. }
  28. static getRolesRaceGroup() {
  29. let roles = {};
  30. let roleConf = RoleConf.data
  31. for (const rId in roleConf) {
  32. if (Object.prototype.hasOwnProperty.call(roleConf, rId)) {
  33. const element = roleConf[rId];
  34. let rData = RoleData.getRoleDataByID(rId);
  35. if (roles[element.Race]) {
  36. if (rData) {
  37. roles[element.Race].push(rData);
  38. } else {
  39. roles[element.Race].push({ conf: element });
  40. }
  41. } else {
  42. roles[element.Race] = [];
  43. if (rData) {
  44. roles[element.Race].push(rData);
  45. } else {
  46. roles[element.Race].push({ conf: element });
  47. }
  48. }
  49. }
  50. }
  51. for (const key in roles) {
  52. if (Object.prototype.hasOwnProperty.call(roles, key)) {
  53. const element = roles[key];
  54. element.sort((a, b) => {
  55. return Number(a.conf.Id) < Number(b.conf.Id) ? -1 : 1;
  56. });
  57. }
  58. }
  59. return roles;
  60. }
  61. }