123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- var BuildingModel = require('./BuildingModel');
- const bInfo = require('../data/roomInfo');
- const skillInfo = require('../data/skillInfo');
- const skillLevel = require('../data/skillLevel');
- const starInfo = require('../data/starInfo');
- const GameModule = require("./GameModule");
- const TapTapTool = require("./TapTapTool");
- export default class BuildingManager {
-
- static _instance;
- _allBuildData = {};
- _allSkillInfo = {};
- _allSkillLevel = {};
- networkRooms = [];
- constructor() {
- this._allBuildData = this.formatBuildingInfo();
- this.initSkill();
- let starInfBp = {}
- starInfo.forEach(n => {
- starInfBp[n.starId] = n;
- })
- this._allStarInfo = starInfBp;
- // console.log(this._allBuildData);
- };
- static get instance() {
- if (!BuildingManager._instance) {
- BuildingManager._instance = new BuildingManager();
- }
- return BuildingManager._instance;
- };
- initSkill() {
- let skiInfo = {};
- /// 得到数组 根据技能id获取对应技能的信息
- skillInfo.forEach(n => {
- skiInfo[n.skillId] = n;
- });
- this._allSkillInfo = skiInfo;
- this._allSkillLevel = skillLevel;
- }
- formatBuildingInfo() {
- let bInfoMap = {}
- bInfo.forEach(n => {
- bInfoMap[n.roomId] = n;
- })
- this._binfoMap = bInfoMap;
- }
- /**
- * 获取建筑的下一级信息
- * @param {int} roomId
- * @param {int} roomLevel
- */
- getBuildingInfo(roomId, roomLevel) {
- let roomInfo = this._binfoMap[roomId];
- let staticObj = {
- level: roomLevel
- };
- let nextObj = {
- nextUpGold:"0",
- hasNext: 0
- };
- if(roomLevel < roomInfo.maxLevel) {
- let gold3 = TapTapTool.goldStrToClass(roomInfo.gold3);
- let gold4 = TapTapTool.goldStrToClass(roomInfo.gold4);
- var goldMt = TapTapTool.toPower(roomLevel);
- var roomGold = TapTapTool.multiple(gold3,goldMt);
- if (gold4.n > 0 && roomLevel >= 27) {
- goldMt = TapTapTool.toPower((roomLevel - 27));
- roomGold = TapTapTool.multiple(gold4,goldMt);
- }
- nextObj = {
- nextUpGold: roomGold,
- hasNext: 1
- };
- staticObj['unlockScore'] = "0";
- }
- if (roomLevel == 0) {
- staticObj['unlockScore'] = roomInfo.gold3;
- }
- roomInfo = Object.assign(roomInfo, staticObj, nextObj);
- let buildModel = new BuildingModel(roomInfo);
- return buildModel;
- };
- /**
- * 获取对应建筑的最高等级
- * @param {*} roomId
- */
- getLevelCount(roomId) {
- // let building = this._allBuildData[roomId];
- let roomInfo = this._binfoMap[roomId];
- return roomInfo.maxLevel;
- };
- /// 根据roomId获取房间名字
- getRoomName(roomId) {
- let roomInfo = this._binfoMap[roomId];
- return roomInfo.name;
- }
- /// 获取某个技能的信息
- getSkillInfo(skillId) {
- let skill = this._allSkillInfo[skillId];
- return skill;
- }
- ///获取某个技能 某个level的信息
- getSkillLevelInfo(skillId, skillLevel) {
- if (skillLevel == 0) {
- return undefined;
- }
- let info = this._allSkillLevel[skillId].filter(n => n.level == skillLevel)[0];
- return info;
- }
- /// 获取某个明星的信息
- getStarInfo(starId) {
- return this._allStarInfo[starId];
- }
- /// 根据roomId获取是否已经解锁
- getRoomIsUnlocked(roomId) {
- for (let i = 0; i < GameModule.roomInfo.length; i ++) {
- let room = GameModule.roomInfo[i];
- if (roomId == room.roomId) {
- return room.isUnlocked;
- }
- }
- /// 返回没有解锁
- return 0;
- }
- /// 根据roomId获取当前等级
- getRoomLevel(roomId) {
- for (let i = 0; i < GameModule.roomInfo.length; i ++) {
- let room = GameModule.roomInfo[i];
- if (roomId == room.roomId) {
- return room.level;
- }
- }
- /// 返回没有解锁等级0
- return 0;
- }
- }
|