import GameUtil from "../core/GameUtil"; import NpcMgr from "../core/NpcMgr"; import NpcConfigMgr from "../core/NpcConfigMgr"; import PlayerMgr from "./PlayerMgr"; import DWorldMonster from "./DWorldMonster"; export default class MagicWorldMonsterMgr{ mapName:any; vecMonster:any[]; vecMstPos:any[]; constructor() { this.mapName = { 4004: '上古战场' }; this.vecMonster = []; this.vecMstPos = []; this.Init(); } Init() { let mapLiveCnt:any = { 82022: 0 }; for (var it in mapLiveCnt) { this.vecMonster.push(new DWorldMonster(it, mapLiveCnt[it])); } this.vecMstPos = [ { map: 1010, x: 150, y: 63 }, { map: 1010, x: 143, y: 29 }, { map: 1010, x: 125, y: 123 }, ]; } GetRemainPos() { let vecTmp = this.vecMstPos.slice(0); for (let it in this.vecMonster) { let pMonster:any = this.vecMonster[it]; if (pMonster.nOnlyID == 0) continue; vecTmp.splice(pMonster.nInPos, 0); } return vecTmp; } FindMonster(nConfigID:any):any{ for (let it in this.vecMonster) { if (this.vecMonster[it].nNpc == nConfigID) return this.vecMonster[it]; } return null; } FindDeadMonster(nKind:any):any{ let vecTmp = []; for (let it in this.vecMonster) { if (this.vecMonster[it].nOnlyID > 0) continue; vecTmp.push(it); } if (vecTmp.length <= 0) return null; let nRand = GameUtil.random(0, vecTmp.length - 1); let nIndex = vecTmp[nRand]; return this.vecMonster[Number(nIndex)]; } GetMapName(nID:any):any{ if (this.mapName.hasOwnProperty(nID)) return this.mapName[nID]; return ''; } ReliveWorldMonster(roleId:any, nKind:any) { let pPlayer = PlayerMgr.shared.getPlayerByRoleId(roleId); if (null == pPlayer) return; let pMst = this.FindDeadMonster(nKind); if (null == pMst) return; let vecTmp = this.GetRemainPos(); if (vecTmp.length <= 0) return; let nRand = GameUtil.random(0, vecTmp.length - 1); let stPos = vecTmp[nRand]; pMst.nOnlyID = NpcMgr.shared.CreateNpc(pMst.nNpc, stPos.map, stPos.x, stPos.y, { nKind: 0, nID: 0 }, 0); pMst.nInPos = nRand; pMst.nCnt = pMst.nKind == 1 ? 10 : 1; let pConfigInfo = NpcConfigMgr.shared.getConfig(pMst.nNpc); let strMapName = this.GetMapName(stPos.map); let strRichText = ` ${pConfigInfo.name} ${strMapName}, ${stPos.x}, ${stPos.y} 出现了,快去击杀吧。`; PlayerMgr.shared.broadcast('s2c_screen_msg', { strRichText: strRichText, bInsertFront: 1 }); } CheckWorldMonsterDead(nOnlyID:any) { for (let it in this.vecMonster) { let pMonster = this.vecMonster[it]; if (pMonster.nOnlyID != nOnlyID) continue; pMonster.nCnt -= 1; if (pMonster.nCnt > 0) break; pMonster.nOnlyID = 0; NpcMgr.shared.DeleteNpc(nOnlyID); break; } } }