public void CreateHero(IpcCreateHeroMsg msg) { int len = msg.npclist.Length; for (int i = 0; i < len; i++) { CrtHero hero = msg.npclist[i]; ClientNPC npc = Npcloader.Load(hero.npcID, hero.uniqueId, (CAMP)hero.camp, WarPoint); if (npc == null) { ConsoleEx.DebugWarning("Create npc fail!!!!!!!!! id:: " + hero.npcID); continue; } warMgr.clientTeam.filterNpc(hero, npc); npc.transform.localPosition = new Vector3(hero.pos.x, hero.pos.y, hero.pos.z); npc.transform.localScale = Vector3.one; npc.transform.localEulerAngles = new Vector3(hero.rotation.x, hero.rotation.y, hero.rotation.z); } warMgr.SwitchHero(warMgr.clientTeam.activeNpc); warMgr.CreateHeroFinished(); }
public void CreateNpc() { Utils.Assert(curChapConfig == null, "Chapter Configdata is null."); if (reader.loadSceneConfig(curChapConfig.scene_config)) { NPCInSceneData[] npcInScene = reader.GetSceneEditorElementData <NPCInSceneData>(); if (npcInScene != null && npcInScene.Length > 0) { int len = npcInScene.Length; CrtHero[] toClient = new CrtHero[len]; for (int i = 0; i < len; i++) { NPCInSceneData sceneD = npcInScene [i]; ServerNPC npc = virNpcLoader.Load(sceneD.npcID, sceneD.camp, WarPoint); if (npc == null) { ConsoleEx.DebugWarning("Create npc fail!!!!!!!!! id:: " + sceneD.npcID); continue; } npc.transform.localPosition = new Vector3(sceneD.pos [0], sceneD.pos [1], sceneD.pos [2]); npc.transform.localScale = new Vector3(sceneD.scale [0], sceneD.scale [1], sceneD.scale [2]); npc.transform.localEulerAngles = new Vector3(sceneD.rotation [0], sceneD.rotation [1], sceneD.rotation [2]); npc.spawnPos = npc.transform.position; npc.spawnRot = npc.transform.rotation; npc.dataInScene = sceneD; npc.data.btData.way = sceneD.way; //初始化buff InitBuff(npc); //初始化AI InitAi(npc); toClient[i] = new CrtHero() { npcID = sceneD.npcID, uniqueId = npc.UniqueID, pos = VectorWrap.ToVector(npc.transform.position), rotation = VectorWrap.ToVector(npc.transform.eulerAngles), camp = (int)npc.Camp, }; } //send creating npc message to client IpcCreateNpcMsg msg = new IpcCreateNpcMsg() { npclist = toClient, }; WarSMgr.realServer.proxyCli.CtorNpc(msg); } } else { ConsoleEx.DebugWarning(curChapConfig.scene_config + " scene config is not find."); } }
public void filterNpc(CrtHero hero, ClientNPC npc) { if (hero.ClientID == DeviceInfo.GUID) { team[hero.index] = npc; if (hero.index == 0) { activeNpc = npc; } } }
public void CreateNpc(IpcCreateNpcMsg msg) { int len = msg.npclist.Length; for (int i = 0; i < len; i++) { CrtHero hero = msg.npclist[i]; ClientNPC npc = Npcloader.Load(hero.npcID, hero.uniqueId, (CAMP)hero.camp, WarPoint); // Debug.Log(fastJSON.JSON.Instance.ToJSON(msg)); if (npc == null) { ConsoleEx.DebugWarning("Create npc fail!!!!!!!!! id:: " + hero.npcID); continue; } npc.transform.localPosition = new Vector3(hero.pos.x, hero.pos.y, hero.pos.z); npc.transform.localScale = Vector3.one; npc.transform.localEulerAngles = new Vector3(hero.rotation.x, hero.rotation.y, hero.rotation.z); } }
void CreateOneSideHero(WarCamp wc, out List <ServerLifeNpc> NpcContainer, List <CrtHero> heroList) { NpcContainer = new List <ServerLifeNpc>(); List <RoomCharactor> OneSide = Charactors.get(wc); int count = OneSide.Count; for (int j = 0; j < count; ++j) { WrapperTeam wrapperTeam = (WrapperTeam)OneSide[j].team; List <NPCData> dataTeam = wrapperTeam.dataTeam; int cnt = dataTeam.Count; #if SINGLE_HERO cnt = 1; #endif if (dataTeam != null && cnt > 0) { //一方出生点 CAMP camp = WarCamp2Camp.toCamp(wc); List <ServerNPC> npcList = WarSMgr.npcMgr.GetNPCListByNum(NpcMgr <ServerNPC> .BORN_POINT, camp); for (int i = 0; i < cnt; i++) { ServerNPC npc = virNpcLoader.Load(dataTeam[i].configData.ID, camp, WarPoint); //设置出生点 npc.transform.position = npcList[i].transform.position; npc.spawnPos = npc.transform.position; npc.spawnRot = npc.transform.rotation; ServerLifeNpc hero = npc as ServerLifeNpc; NpcContainer.Add(hero); wrapperTeam.AddNpcMember(hero, i); BehaviorTree tree = hero.gameObject.AddComponent <BehaviorTree>(); tree.ExternalBehavior = AiLoader.load(AILoader.PATHFIND_ATK); tree.StartWhenEnabled = true; tree.RestartWhenComplete = true; hero.SwitchAutoBattle(true); hero.SwitchAutoBattle(false); CrtHero crt = new CrtHero(); crt.camp = (int)npc.Camp; crt.npcID = npc.data.configData.ID; crt.uniqueId = npc.UniqueID; crt.pos = VectorWrap.ToVector(npc.transform.position); crt.rotation = VectorWrap.ToVector(npc.transform.eulerAngles); crt.ClientID = OneSide[j].UID; crt.index = i; heroList.Add(crt); } } } }