BuildingManager.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. var BuildingModel = require('./BuildingModel');
  2. const bInfo = require('../data/roomInfo');
  3. const skillInfo = require('../data/skillInfo');
  4. const skillLevel = require('../data/skillLevel');
  5. const starInfo = require('../data/starInfo');
  6. const GameModule = require("./GameModule");
  7. const TapTapTool = require("./TapTapTool");
  8. export default class BuildingManager {
  9. static _instance;
  10. _allBuildData = {};
  11. _allSkillInfo = {};
  12. _allSkillLevel = {};
  13. networkRooms = [];
  14. constructor() {
  15. this._allBuildData = this.formatBuildingInfo();
  16. this.initSkill();
  17. let starInfBp = {}
  18. starInfo.forEach(n => {
  19. starInfBp[n.starId] = n;
  20. })
  21. this._allStarInfo = starInfBp;
  22. // console.log(this._allBuildData);
  23. };
  24. static get instance() {
  25. if (!BuildingManager._instance) {
  26. BuildingManager._instance = new BuildingManager();
  27. }
  28. return BuildingManager._instance;
  29. };
  30. initSkill() {
  31. let skiInfo = {};
  32. /// 得到数组 根据技能id获取对应技能的信息
  33. skillInfo.forEach(n => {
  34. skiInfo[n.skillId] = n;
  35. });
  36. this._allSkillInfo = skiInfo;
  37. this._allSkillLevel = skillLevel;
  38. }
  39. formatBuildingInfo() {
  40. let bInfoMap = {}
  41. bInfo.forEach(n => {
  42. bInfoMap[n.roomId] = n;
  43. })
  44. this._binfoMap = bInfoMap;
  45. }
  46. /**
  47. * 获取建筑的下一级信息
  48. * @param {int} roomId
  49. * @param {int} roomLevel
  50. */
  51. getBuildingInfo(roomId, roomLevel) {
  52. let roomInfo = this._binfoMap[roomId];
  53. let staticObj = {
  54. level: roomLevel
  55. };
  56. let nextObj = {
  57. nextUpGold:"0",
  58. hasNext: 0
  59. };
  60. if(roomLevel < roomInfo.maxLevel) {
  61. let gold3 = TapTapTool.goldStrToClass(roomInfo.gold3);
  62. let gold4 = TapTapTool.goldStrToClass(roomInfo.gold4);
  63. var goldMt = TapTapTool.toPower(roomLevel);
  64. var roomGold = TapTapTool.multiple(gold3,goldMt);
  65. if (gold4.n > 0 && roomLevel >= 27) {
  66. goldMt = TapTapTool.toPower((roomLevel - 27));
  67. roomGold = TapTapTool.multiple(gold4,goldMt);
  68. }
  69. nextObj = {
  70. nextUpGold: roomGold,
  71. hasNext: 1
  72. };
  73. staticObj['unlockScore'] = "0";
  74. }
  75. if (roomLevel == 0) {
  76. staticObj['unlockScore'] = roomInfo.gold3;
  77. }
  78. roomInfo = Object.assign(roomInfo, staticObj, nextObj);
  79. let buildModel = new BuildingModel(roomInfo);
  80. return buildModel;
  81. };
  82. /**
  83. * 获取对应建筑的最高等级
  84. * @param {*} roomId
  85. */
  86. getLevelCount(roomId) {
  87. // let building = this._allBuildData[roomId];
  88. let roomInfo = this._binfoMap[roomId];
  89. return roomInfo.maxLevel;
  90. };
  91. /// 根据roomId获取房间名字
  92. getRoomName(roomId) {
  93. let roomInfo = this._binfoMap[roomId];
  94. return roomInfo.name;
  95. }
  96. /// 获取某个技能的信息
  97. getSkillInfo(skillId) {
  98. let skill = this._allSkillInfo[skillId];
  99. return skill;
  100. }
  101. ///获取某个技能 某个level的信息
  102. getSkillLevelInfo(skillId, skillLevel) {
  103. if (skillLevel == 0) {
  104. return undefined;
  105. }
  106. let info = this._allSkillLevel[skillId].filter(n => n.level == skillLevel)[0];
  107. return info;
  108. }
  109. /// 获取某个明星的信息
  110. getStarInfo(starId) {
  111. return this._allStarInfo[starId];
  112. }
  113. /// 根据roomId获取是否已经解锁
  114. getRoomIsUnlocked(roomId) {
  115. for (let i = 0; i < GameModule.roomInfo.length; i ++) {
  116. let room = GameModule.roomInfo[i];
  117. if (roomId == room.roomId) {
  118. return room.isUnlocked;
  119. }
  120. }
  121. /// 返回没有解锁
  122. return 0;
  123. }
  124. /// 根据roomId获取当前等级
  125. getRoomLevel(roomId) {
  126. for (let i = 0; i < GameModule.roomInfo.length; i ++) {
  127. let room = GameModule.roomInfo[i];
  128. if (roomId == room.roomId) {
  129. return room.level;
  130. }
  131. }
  132. /// 返回没有解锁等级0
  133. return 0;
  134. }
  135. }