/// <summary> /// 创建npc缓存, 服务通知后创建缓存 /// </summary> public void CreateNpcCache() { List <NPCInSceneData> freshPtList = GetFreshPtList(); if (freshPtList != null && freshPtList.Count > 0) { FreshPoolModel poolModel = Core.Data.getIModelConfig <FreshPoolModel>(); FreshGroupModel gropModel = Core.Data.getIModelConfig <FreshGroupModel>(); for (int i = 0; i < freshPtList.Count; i++) { int poolId = freshPtList [i].freshParam.freshPoolID; NPCFreshPool pool = poolModel.GetNPCFreshPool(poolId); if (pool != null) { for (int j = 0; j < pool.freshPool.Count; j++) { NPCFreshGroup grop = gropModel.GetFreshGroup(pool.freshPool [j]); if (grop != null) { for (int m = 0; m < grop.freshGroup.Count; m++) { ClientNPC npcsript = Npcloader.Load(grop.freshGroup[m], -1, freshPtList[i].camp, WarPoint); npcsript.data.rtData.curHp = 0; npcsript.dataInScene = freshPtList[i]; npcsript.data.btData.way = freshPtList[i].way; npcsript.gameObject.SetActive(false); //加入缓存中 warMgr.npcMgr.SignDeadNpcCache(npcsript); } } } } } } }
public override TaskStatus OnUpdate() { curGroup = freshGroupModel.GetFreshGroup(curPool.freshPool[curGroupIndex.Value]); if (curGroup != null) { npcCnt.count.Value = curGroup.freshGroup.Count; } else { //空的一波怪 curIndex.Value = 0; curGroupIndex.Value++; curGroupCnt.Value++; //循环利用刷新池的数据 if (curGroupIndex.Value >= curPool.freshPool.Count) { curGroupIndex.Value = 0; } return(TaskStatus.Success); } if (curIndex.Value < curGroup.freshGroup.Count) { npcNum = curGroup.freshGroup [curIndex.Value]; } ServerNPC newNpc = WarServerManager.Instance.npcMgr.GetNpcFromCache(npcNum); if (newNpc != null) { WarServerManager.Instance.npcMgr.RemoveNpcFromCache(newNpc); } else { newNpc = loader.Load(npcNum, myHero.dataInScene.camp, mWarPoint); } GameObject go = newNpc.gameObject; go.SetActive(true); go.transform.localPosition = this.transform.localPosition; newNpc.data.rtData.curHp = newNpc.data.rtData.totalHp; newNpc.Camp = myHero.dataInScene.camp; newNpc.data.btData.way = myHero.dataInScene.way; newNpc.dataInScene = myHero.dataInScene; //发送消息通知客户端 SendCreateNpcMsg(newNpc); SendHpMsg(newNpc); InitAi(newNpc); InitBuff(newNpc); if (newNpc is ServerLifeNpc) { ServerLifeNpc life = newNpc as ServerLifeNpc; life.SwitchAutoBattle(true); } //同一拨,当前造兵索引++ curIndex.Value++; //同一拨,如果造了最后一个兵,当前造兵波数++ if (curIndex.Value >= curGroup.freshGroup.Count) { curIndex.Value = 0; curGroupIndex.Value++; curGroupCnt.Value++; //循环利用刷新池的数据 if (curGroupIndex.Value >= curPool.freshPool.Count) { curGroupIndex.Value = 0; } return(TaskStatus.Success); } return(TaskStatus.Success); }