RoleManager.ts 2.1 KB

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