BuildingManager.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. if (roomId == 0) {
  94. return null;
  95. }
  96. let roomInfo = this._binfoMap[roomId];
  97. return roomInfo.name;
  98. }
  99. /// 获取某个技能的信息
  100. getSkillInfo(skillId) {
  101. let skill = this._allSkillInfo[skillId];
  102. return skill;
  103. }
  104. ///获取某个技能 某个level的信息
  105. getSkillLevelInfo(skillId, skillLevel) {
  106. if (skillLevel == 0) {
  107. return undefined;
  108. }
  109. let info = this._allSkillLevel[skillId].filter(n => n.level == skillLevel)[0];
  110. return info;
  111. }
  112. /// 获取某个明星的信息
  113. getStarInfo(starId) {
  114. return this._allStarInfo[starId];
  115. }
  116. /// 根据roomId获取是否已经解锁
  117. getRoomIsUnlocked(roomId) {
  118. for (let i = 0; i < GameModule.roomInfo.length; i ++) {
  119. let room = GameModule.roomInfo[i];
  120. if (roomId == room.roomId) {
  121. return room.isUnlocked;
  122. }
  123. }
  124. /// 返回没有解锁
  125. return 0;
  126. }
  127. /// 根据roomId获取当前等级
  128. getRoomLevel(roomId) {
  129. for (let i = 0; i < GameModule.roomInfo.length; i ++) {
  130. let room = GameModule.roomInfo[i];
  131. if (roomId == room.roomId) {
  132. return room.level;
  133. }
  134. }
  135. /// 返回没有解锁等级0
  136. return 0;
  137. }
  138. }