public void Fill(int cntNpc, int cntMonster) { Vector3 center = RectIdxToCenterPos(_idx); bool bAvailable = false; SceneEntityPosAgent agent; System.Random rand = new System.Random(); for (int i = 0; i < cntNpc; i++) { Vector3 point = !PeGameMgr.randomMap ? GetEntityPoint(center, out bAvailable) : GetNpcPointInRndTer(center, out bAvailable); if (bAvailable) { if (VFDataRTGen.IsTownConnectionType(Mathf.RoundToInt(point.x), Mathf.RoundToInt(point.z))) { agent = NpcEntityCreator.CreateAgent(point); agent.spInfo = _rndNpcAgentInfo; _posRndNpcAgents.Add(agent); // npc entity would not be destroyed by scene } else { if (rand.NextDouble() < 0.25) { agent = NpcEntityCreator.CreateAgent(point); agent.spInfo = _rndNpcAgentInfo; _posRndNpcAgents.Add(agent); // npc entity would not be destroyed by scene } } } } for (int i = 0; i < cntMonster; i++) { Vector3 point = GetEntityPoint(center, out bAvailable); if (bAvailable && null == AIErodeMap.IsInErodeArea2D(point)) { _posRndMonsterAgents.Add(MonsterEntityCreator.CreateAgent(point)); } } SceneMan.AddSceneObjs(_posRndNpcAgents); SceneMan.AddSceneObjs(_posRndMonsterAgents); if (PeGameMgr.IsStory) { _posFixedMonsterIds = AISpawnPoint.Find(center.x - EntityCreationRadius, center.z - EntityCreationRadius, center.x + EntityCreationRadius, center.z + EntityCreationRadius); if (_posFixedMonsterIds.Count > 0) { SceneEntityCreatorArchiver.Instance.AddFixedSpawnPointToScene(_posFixedMonsterIds); } } else if (PeGameMgr.IsSingleAdventure) { SceneEntityPosRect.AddProcedualBossSpawnPointToScene(_idx); } }
public void AddFixedSpawnPointToScene(List <int> pointIds) { List <SceneEntityPosAgent> agents = new List <SceneEntityPosAgent>(); FixedSpawnPointInfo info = null; foreach (int id in pointIds) { if (_fixedSpawnPointInfos.TryGetValue(id, out info) && info._bActive) { if (PeGameMgr.IsMultiStory) { if (AISpawnPoint.s_spawnPointData[id].active == true) { continue; } } agents.Add(info._agent); } } SceneMan.AddSceneObjs(agents); }
public void AddImportedObj(string typeNameMask = null) { if (_dataToImport == null || _lstPosToSerialize == null || _lstTypeToSerialize == null) { return; } MemoryStream ms = new MemoryStream(_dataToImport); BinaryReader br = new BinaryReader(ms); int n = _lstTypeToSerialize.Count; List <ISceneSerializableObjAgent> lstObjToSerialize = new List <ISceneSerializableObjAgent>(n); for (int i = n - 1; i >= 0; i--) { string typeName = _lstTypeToSerialize[i]; long pos = _lstPosToSerialize[i]; if (typeNameMask != null && !typeName.Equals(typeNameMask)) { continue; } try { System.Type t = System.Type.GetType(typeName); //If necessary, we can use a hashset to optimize this. ISceneSerializableObjAgent obj = System.Activator.CreateInstance(t) as ISceneSerializableObjAgent; br.BaseStream.Seek(pos, SeekOrigin.Begin); obj.Deserialize(br); lstObjToSerialize.Add(obj); } catch (Exception e) { throw new System.Exception("[SceneMan]Wrong save data format: DataType " + typeName + "\nDetail:" + e); } _lstTypeToSerialize.RemoveAt(i); _lstPosToSerialize.RemoveAt(i); } SceneMan.AddSceneObjs(lstObjToSerialize); }
void LoadStaticAssetsFromDB() { List <ISceneObjAgent> objAgents = new List <ISceneObjAgent>(); _assets.Clear(); SqliteDataReader reader = LocalDatabase.Instance.ReadFullTable("sceneAssetList"); while (reader.Read()) { int id = Convert.ToInt32(reader.GetString(0)); int type = Convert.ToInt32(reader.GetString(1)); string prePathName = reader.GetString(2); string mainPathName = reader.GetString(3); string[] strPos = reader.GetString(4).Split(','); string[] strRot = reader.GetString(5).Split(','); string[] strScl = reader.GetString(6).Split(','); Vector3 pos = new Vector3( Convert.ToSingle(strPos[0]), Convert.ToSingle(strPos[1]), Convert.ToSingle(strPos[2])); Quaternion rot = new Quaternion( Convert.ToSingle(strRot[0]), Convert.ToSingle(strRot[1]), Convert.ToSingle(strRot[2]), Convert.ToSingle(strRot[3])); if (rot.w > 2) //Quaternion should be normalized { rot.eulerAngles = new Vector3(rot.x, rot.y, rot.z); } Vector3 scl = new Vector3( Convert.ToSingle(strScl[0]), Convert.ToSingle(strScl[1]), Convert.ToSingle(strScl[2])); if (prePathName != null && prePathName.Length <= 1) { prePathName = null; } switch (type) { case (int)SceneAssetType.StaticAsset: { SceneAssetDesc asset = new SceneAssetDesc(); asset._id = id; asset._agent = new SceneStaticAssetAgent(prePathName, mainPathName, pos, rot, scl); _assets.Add(asset); objAgents.Add(asset._agent); } break; case (int)SceneAssetType.OperatableItem: { // TODO : code for prePathName OperatableItemAgent agent = new OperatableItemAgent(id, pos, mainPathName); objAgents.Add(agent); } break; default: Debug.LogError("[SceneAssets]:Unrecognizable asset type:" + type); break; } } SceneMan.AddSceneObjs(objAgents); }