BuildingManager.js 4.6 KB

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