public static SceneEntityPosAgent CreateAgent(Vector3 pos, int protoId = -1)
    {
        SceneEntityPosAgent agent = new SceneEntityPosAgent(pos, Vector3.one, Quaternion.identity, EntityType.EntityType_Monster, protoId);

        agent.spInfo = AgentInfo.s_defAgentInfo;
        return(agent);
    }
        IEnumerator DelayBossReborn(SceneEntityPosAgent agent)
        {
            SceneMan.RemoveSceneObj(agent);
            yield return(new WaitForSeconds(240));              // wait 4 min

            SceneMan.AddSceneObj(agent);
        }
    public static SceneEntityPosAgent CreateAgent(Vector3 pos, int protoId, Vector3 scl, Quaternion rot)
    {
        SceneEntityPosAgent agent = new SceneEntityPosAgent(pos, scl, rot, EntityType.EntityType_Monster, protoId);

        agent.spInfo = AgentInfo.s_defAgentInfo;
        return(agent);
    }
    public static PeEntity CreateMonster(int protoId, Vector3 pos, Vector3 scl, Quaternion rot)
    {
        SceneEntityPosAgent agent = CreateAgent(pos, protoId, scl, rot);

        CreateMonster(agent);
        return(agent.entity);
    }
Beispiel #5
0
    void OnMemberDestroy(PeEntity e)
    {
        // Check to destroy group
        foreach (ISceneObjAgent agent in _lstAgents)
        {
            SceneEntityPosAgent sepa = agent as SceneEntityPosAgent;
            if (sepa != null)
            {
                if (sepa.entity != null && sepa.entity != e)
                {
                    return;
                }
            }
            else
            {
//				PeCustom.AIAgent aiagent = agent as PeCustom.AIAgent;
//
//				if(aiagent.entity != null && aiagent.entity != e)
//				{
//					return;
//				}
                PeCustom.SceneEntityAgent sea = agent as PeCustom.SceneEntityAgent;
                if (sea.entity != null && sea.entity != e)
                {
                    return;
                }
            }
        }
        Destroy(gameObject);
    }
 public static PeEntity CreateDungeonMonster(int protoId, Vector3 pos, int dungeonId, int buffId = 0, int colorType = -1, int playerId = -1)
 {
     if (PeGameMgr.IsSingle)
     {
         PeEntity m = CreateAdMonster(protoId, pos, colorType, playerId, buffId, false);
         if (m != null)
         {
             m.SetAttribute(Pathea.AttribType.CampID, DungeonMonster.CAMP_ID);
             m.SetAttribute(Pathea.AttribType.DamageID, DungeonMonster.DAMAGE_ID);
         }
         else
         {
             Debug.LogError("createDungeonMonsterFailed!");
         }
         return(m);
     }
     else
     {
         SceneEntityPosAgent agent = CreateAdAgent(pos, protoId, colorType, playerId, buffId, false);
         agent.entity = null;
         // Compute agent.protoId
         EntityGrp           grp;
         EntityMonsterBeacon bcn;
         float exScale = -1.0f;
         if (!ParseAgentInfo(agent, out grp, out bcn, ref exScale, ref colorType, ref playerId, ref buffId))
         {
             return(agent.entity);
         }
         NetworkManager.WaitCoroutine(PlayerNetwork.RequestCreateAi(agent.protoId, agent.Pos, null == grp ? -1 : grp.Id, null == bcn ? -1 : bcn.Id, dungeonId, colorType, playerId, buffId));
         return(agent.entity);
     }
 }
Beispiel #7
0
    public static PeEntity CreateNpc(int protoId, Vector3 pos)
    {
        SceneEntityPosAgent agent = CreateAgent(pos, protoId);

        CreateNpc(agent);
        return(agent.entity);
    }
    public static PeEntity CreateAdMonster(int protoId, Vector3 pos, int colorType, int playerId, int buffId = 0, bool bride = true)
    {
        SceneEntityPosAgent agent = CreateAdAgent(pos, protoId, colorType, playerId, buffId, bride);

        CreateMonster(agent);
        return(agent.entity);
    }
    public static void CreateStoryDoodads(bool bNew)
    {
        if (PeGameMgr.IsMulti)
        {
            return;
        }
        foreach (KeyValuePair <int, SceneDoodadDesc> iter in StoryDoodadMap.s_dicDoodadData)
        {
            bool bSerializable = iter.Value._type > 0;
            if (!bNew && bSerializable)
            {
                // serializable doodad would be created from savedata loading
                continue;
            }

            AgentInfo spInfo = new AgentInfo(iter.Value._id, iter.Value._isShown, iter.Value._campId, iter.Value._damageId);
            if (!bSerializable)                 // Add to scene
            {
                SceneEntityPosAgent agent = CreateAgent(iter.Value._pos, iter.Value._protoId, iter.Value._scl, iter.Value._rot);
                agent.spInfo = spInfo;
                SceneMan.AddSceneObj(agent);
                continue;
            }

            // bNew and serializable
            CreateDoodad(true, spInfo, iter.Value._protoId, iter.Value._pos, iter.Value._scl, iter.Value._rot);
        }
    }
 private void ReqReborn(SceneEntityPosAgent agent)
 {
     if (agent.IsIdle)
     {
         if (agent.entity == null || agent.entity.IsDead())
         {
             agent.entity  = null;
             agent.canRide = false;
             SceneMan.RemoveSceneObj(agent);
             SceneMan.AddSceneObj(agent);
         }
         else if (agent.entity != null && agent.entity.monstermountCtrl != null &&
                  agent.entity.monstermountCtrl.ctrlType == ECtrlType.Mount) //Lw2017.2.14:怪物已经被驯服,重新生成
         {
             agent.entity  = null;
             agent.canRide = false;
             //SceneMan.RemoveSceneObj(agent);
             SceneMan.AddSceneObj(agent);
         }
         else
         {
             agent.canRide = false;
             MonsterCmpt mc = agent.Go.GetComponent <MonsterCmpt>();
             if (mc != null)
             {
                 mc.Req_MoveToPosition(agent.Pos, 1, true, SpeedState.Run);
             }
         }
     }
 }
Beispiel #11
0
    void OnEntitySpawned(SceneEntityPosAgent agent)
    {
        m_MaxCount++;

        if (!EntityMonsterBeacon.IsBcnMonsterProtoId(agent.protoId))            // not encoded, unexpected agent
        {
            return;
        }

        int spType, lvl, spawnType;

        EntityMonsterBeacon.DecodeBcnMonsterProtoId(agent.protoId, out spType, out lvl, out spawnType);

        int areaType = PeGameMgr.IsStory
            ? PeMappingMgr.Instance.GetAiSpawnMapId(new Vector2(agent.Pos.x, agent.Pos.z))
            : AiUtil.GetMapID(agent.Pos);

        AISpawnTDWavesData.TDMonsterSpData data = AISpawnTDWavesData.GetMonsterSpData(false, spType, lvl, spawnType, areaType);

        float rhp = data != null ? data._rhp : 200.0f;
        float dps = data != null ? data._dps : 50.0f;

        SiegeAgent siegeAgent = new SiegeAgent(this, agent, rhp, dps);

        agent.spInfo = new SiegeAgent.AgentInfo(m_Beacon, siegeAgent);
        m_Agents.Add(siegeAgent);
    }
    static bool ParseAgentInfo(SceneEntityPosAgent agent, out EntityGrp grp, out EntityMonsterBeacon bcn, ref float exScale, ref int colorType, ref int playerId, ref int buffId)       // bValidAgent
    {
        AgentInfo info = agent.spInfo as AgentInfo;

        grp       = info != null ? info._grp : null;
        bcn       = info != null ? info._bcn : null;
        colorType = info != null?info._colorType:-1;
        playerId  = info != null?info._playerId:-1;
        buffId    = info != null?info._buffId:0;
        if (bcn != null)
        {
            agent.protoId = MonsterEntityCreator.GetMonsterProtoIDForBeacon(agent.protoId, agent.Pos, ref exScale);
            if ((agent.protoId & EntityProto.IdAirborneAllMask) != 0)
            {
                bcn.AddAirborneReq(agent);
                return(false);
            }
        }
        if (0 > agent.protoId)
        {
            agent.protoId = (info == null || info._bsRate < 0)
                                ? GetMonsterProtoID(agent.Pos, ref exScale)
                                : GetBossMonsterProtoID(agent.Pos, info._bsRate, ref exScale);
        }
        return(agent.protoId >= 0);
    }
    public static SceneEntityPosAgent CreateAdAgent(Vector3 pos, int protoId, int colorType, int playerId, int buffId = 0, bool bride = true)
    {
        SceneEntityPosAgent agent = new SceneEntityPosAgent(pos, Vector3.one, Quaternion.identity, EntityType.EntityType_Monster, protoId);

        agent.spInfo  = new MonsterEntityCreator.AgentInfo(colorType, playerId, buffId);
        agent.canRide = bride;
        return(agent);
    }
        public virtual void OnSuceededToCreate(SceneEntityPosAgent agent)
        {
            // Default behavior:
            LodCmpt entityLodCmpt = agent.entity.lodCmpt;

            if (entityLodCmpt != null)
            {
                entityLodCmpt.onDestruct += (e) => { agent.DestroyEntity(); };
            }
        }
 public void GenEnemyNpc(List <BuildingNpc> bNpcs, int townId, int allyId)
 {
     foreach (BuildingNpc bnpc in bNpcs)
     {
         int enemyNpcId            = GetEnemyNpcId(bnpc.templateId);
         int allyColor             = VATownGenerator.Instance.GetAllyColor(allyId);
         int playerId              = VATownGenerator.Instance.GetPlayerId(allyId);
         SceneEntityPosAgent agent = MonsterEntityCreator.CreateAdAgent(bnpc.pos, enemyNpcId, allyColor, playerId);
         SceneMan.AddSceneObj(agent);
         VArtifactTownManager.Instance.AddMonsterPointAgent(townId, agent);
     }
 }
 public override void OnSuceededToCreate(SceneEntityPosAgent agent)
 {
     base.OnSuceededToCreate(agent);
     if (_fixedId != -1)
     {
         //SceneEntityCreatorArchiver.Instance.SetFixedSpawnPointActive(fixedId, false);
         PeEntity mon = SceneEntityCreatorArchiver.Instance.GetEntityByFixedSpId(_fixedId);
         if (mon != null && mon.aliveEntity != null)                     // now no code for grp
         {
             mon.aliveEntity.deathEvent += AliveEntityDeathEvent;
         }
     }
 }
Beispiel #17
0
        public override void OnSuceededToCreate(SceneEntityPosAgent agent)
        {
            //base.OnSuceededToCreate(agent);

            LodCmpt entityLodCmpt = agent.entity.lodCmpt;

            if (entityLodCmpt != null)
            {
                entityLodCmpt.onDestruct += (e) => { agent.DestroyEntity(); };
            }

            _agent.OnSuceededToCreate();
        }
Beispiel #18
0
    public SiegeAgent(MonsterSiege siege, SceneEntityPosAgent agent, float hp, float atk)
    {
        _siege = siege;
        _agent = agent;

        _hpMax  = hp;
        _atkMax = atk;

        _hp = _hpMax;

        siege.StartCoroutine(Move());
        siege.StartCoroutine(Attack());

        //Debug.LogError("Spawn PosAgent at position : " + _agent.Pos);
    }
 public static void AddProcedualBossSpawnPointToScene(IntVector2 idxPosRect)
 {
             #if false
     // (256*2)*(256*2) one
     int           idxX        = idxPosRect.x >> 1;
     int           idxY        = idxPosRect.y >> 1;
     int           idx         = ((idxPosRect.y - (idxY << 1)) << 1) + (idxPosRect.y - (idxY << 1));
     int           idxMax      = 4;
     int           seed        = RandomMapConfig.RandSeed + idxX * 722 + idxY; // Magic code
     System.Random rnd4BossGen = new System.Random(seed);
     int           idx0        = rnd4BossGen.Next(idxMax);
     if (idx != idx0)
     {
         return;
     }
             #else
     // (256*4)*(256*4) one
     int           idxX        = idxPosRect.x >> 2;
     int           idxY        = idxPosRect.y >> 2;
     int           idx         = ((idxPosRect.y - (idxY << 2)) << 2) + (idxPosRect.x - (idxX << 2));
     int           idxMax      = 16;
     int           seed        = RandomMapConfig.RandSeed + idxY * 722 + idxX; // Magic code
     System.Random rnd4BossGen = new System.Random(seed);
     int           idx0        = rnd4BossGen.Next(idxMax);
     int           idx1        = rnd4BossGen.Next(idxMax);
     while (idx1 == idx0)
     {
         idx1 = rnd4BossGen.Next(idxMax);
     }
     if (idx != idx0 && idx != idx1)
     {
         return;
     }
             #endif
     rnd4BossGen = new System.Random(seed + idx);
     float   dx  = (float)rnd4BossGen.NextDouble();
     float   dy  = (float)rnd4BossGen.NextDouble();
     Vector3 pos = new Vector3((dx + idxPosRect.x) * 2 * SceneEntityPosRect.EntityCreationRadius,
                               SceneEntityPosAgent.PosYTBD,
                               (dy + idxPosRect.y) * 2 * SceneEntityPosRect.EntityCreationRadius);
     if (null == AIErodeMap.IsInScaledErodeArea2D(pos, 1.2f))
     {
         SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(pos);
         agent.spInfo = new MonsterEntityCreator.AgentInfo((float)rnd4BossGen.NextDouble());
         SceneMan.AddSceneObj(agent);
         Debug.Log("<color=red>Boss Spawn Point</color>" + pos);
     }
 }
    void MonEscape(SceneEntityPosAgent agent, Vector3 center)
    {
        if (agent.entity == null)
        {
            return;
        }
        Vector3 dir = agent.entity.position - center;

        dir.Normalize();
        if (agent.entity.monster != null)
        {
            //RequestCmpt rc = entity.GetCmpt<RequestCmpt>();
            Request moveTo = agent.entity.monster.Req_MoveToPosition(agent.entity.position + (dir * 50), 1, true, SpeedState.Run);
            moveTo.AddRelation(EReqType.Attack, EReqRelation.Block);
        }
        PeLogicGlobal.Instance.DestroyEntity(agent.entity.aliveEntity, 10);
    }
 public void AddAirborneReq(SceneEntityPosAgent agent)
 {
     if (_airborne == null)
     {
         RaycastHit hinfo;
         Vector3    pos   = _position;               // target pos
         int        layer = 1 << Pathea.Layer.VFVoxelTerrain
                     | 1 << Pathea.Layer.Building
                     | 1 << Pathea.Layer.SceneStatic
                     | 1 << Pathea.Layer.Unwalkable;
         if (Physics.Raycast(pos + 500.0f * Vector3.up, Vector3.down, out hinfo, 1000.0f, layer))
         {
             pos = hinfo.point;
         }
         MonsterAirborne.Type type = ((agent.protoId & Pathea.EntityProto.IdAirbornePujaMask) != 0) ? MonsterAirborne.Type.Puja : MonsterAirborne.Type.Paja;
         _airborne = MonsterAirborne.CreateAirborne(pos, type);
     }
     _airborne.AddAirborneReq(agent);
 }
Beispiel #22
0
    public PeEntity GetClosestEntity(SceneEntityPosAgent agent)
    {
        PeEntity result = null;
        float    minDis = Mathf.Infinity;

        for (int i = 0; i < m_Entities.Count; i++)
        {
            if (m_Entities[i] != null && !m_Entities[i].IsDeath())
            {
                float tmpDis = PETools.PEUtil.Magnitude(m_Entities[i].position, agent.Pos);
                if (tmpDis < minDis)
                {
                    minDis = tmpDis;
                    result = m_Entities[i];
                }
            }
        }

        return(result);
    }
        public override void OnSuceededToCreate(SceneEntityPosAgent agent)
        {
            LodCmpt entityLodCmpt = agent.entity.lodCmpt;

            if (entityLodCmpt != null)
            {
                entityLodCmpt.onDestruct += (e) => { agent.DestroyEntity(); };
            }
            if (_bsRate >= 0)
            {
                if (agent.entity.aliveEntity != null)
                {
                    agent.entity.aliveEntity.deathEvent += (a, b) => {
                        SceneMan.self.StartCoroutine(DelayBossReborn(agent));
                    };
                }
            }
            if (_bcn != null)
            {
                SceneMan.RemoveSceneObj(agent);
            }
        }
    public void RenderNative(NativePointInfo nativePointInfo)
    {
        int     id  = nativePointInfo.ID;
        Vector3 pos = nativePointInfo.position;
//        int townId = nativePointInfo.townId;
        //if (Pathea.PeGameMgr.IsSingleAdventure)
        //{
        //    Debug.Log("SPPoint.InstantiateSPPoint<SPPoint>: " + pos);
        //    SPPoint point = SPPoint.InstantiateSPPoint<SPPoint>(pos,
        //                                                        Quaternion.identity,
        //                                                        IntVector4.Zero,
        //                                                        SPTerrainEvent.instance.transform,
        //                                                        0,
        //                                                        id,
        //                                                        true,
        //                                                        true,
        //                                                        false,
        //                                                        false);

        //    SPTerrainEvent.instance.RegisterSPPoint(point, true);
        //}
        //else if (GameConfig.IsMultiMode)
        //{
        //    SPTerrainEvent.instance.CreateMultiNativeStatic(pos, id, townId);
        //}

//		if(Pathea.PeGameMgr.IsSingleAdventure)
//		{
        int allyId                = VArtifactTownManager.Instance.GetTownByID(nativePointInfo.townId).AllyId;
        int playerId              = VATownGenerator.Instance.GetPlayerId(allyId);
        int allyColor             = VATownGenerator.Instance.GetAllyColor(allyId);
        SceneEntityPosAgent agent = MonsterEntityCreator.CreateAdAgent(pos, id, allyColor, playerId);

        SceneMan.AddSceneObj(agent);
        VArtifactTownManager.Instance.AddMonsterPointAgent(nativePointInfo.townId, agent);
//		}
    }
Beispiel #25
0
 void OnNewEntity(SceneEntityPosAgent agent)
 {
     totalCount++;
 }
Beispiel #26
0
    public static EntityGrp CreateMonsterGroup(int grpProtoId, Vector3 center, int colorType, int playerId, int entityId = -1, int buffId = 0)
    {
        int noid = -1 == entityId?Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId() : entityId;

#if DbgMonsterGroup
        MonsterGroupProtoDb.Item item = new MonsterGroupProtoDb.Item();
        item.protoID    = 3;
        item.cntMinMax  = new int[] { 3, 5 };
        item.radiusDesc = new float[] { 15f, 1.5f };
        item.subProtoID = new int[0];
#else
        MonsterGroupProtoDb.Item item = MonsterGroupProtoDb.Get(grpProtoId);
        if (item == null)
        {
            return(null);
        }
#endif
        int       cnt = 0;
        EntityGrp grp = EntityMgr.Instance.Create(noid, PeEntityCreator.GroupPrefabPath, center, Quaternion.identity, Vector3.one) as EntityGrp;
        if (grp == null)
        {
            return(null);
        }

        grp._grpProtoId = grpProtoId;
        // Random part
        grp._protoId         = item.protoID;
        grp._cntMin          = item.cntMinMax [0];
        grp._cntMax          = item.cntMinMax [1];
        grp._atkMin          = item.atkMinMax [0];
        grp._atkMax          = item.atkMinMax [1];
        grp._radius          = item.radiusDesc [0];
        grp._sqrRejectRadius = item.radiusDesc.Length > 1 ? (item.radiusDesc [1] * item.radiusDesc [1]) : 1;
        cnt = UnityEngine.Random.Range(grp._cntMin, grp._cntMax);
        if (grp._protoId > 0)
        {
            Vector3 pos = Vector3.zero;
            for (int i = 0; i < cnt; i++)
            {
                if (grp.GetRandPos(center, ref pos, 5))
                {
                    SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(pos, grp._protoId);
                    agent.ScenarioId = grp.scenarioId;
                    agent.spInfo     = new MonsterEntityCreator.AgentInfo(grp, colorType, playerId, buffId);
                    grp._lstAgents.Add(agent);
                }
            }
        }
        // Layout part
        cnt = item.subProtoID != null ? item.subProtoID.Length : 0;
        for (int i = 0; i < cnt; i++)
        {
            if (item.subProtoID[i] > 0)
            {
                SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(item.subPos[i] + center, item.subProtoID[i], item.subScl[i], Quaternion.Euler(item.subRot[i]));
                agent.ScenarioId = grp.scenarioId;
                agent.spInfo     = new MonsterEntityCreator.AgentInfo(grp, colorType, playerId, buffId);
                grp._lstAgents.Add(agent);
            }
        }
        grp.StartCoroutine(grp.AddMemberAgents());           //postpond member creation to avoid performance spike
        //SceneMan.AddSceneObjs (grp._lstAgents);
        return(grp);
    }
    //public void CreateNpcReady(IntVector4 nodePosLod)
    //{
    //    //return;
    //    IntVector3 chunkCenter = new Vector3(nodePosLod.x, nodePosLod.y, nodePosLod.z);
    //    //LogManager.Error("createNpcReady", chunkCenter);
    //    for (int i = chunkCenter.x; i < chunkCenter.x + VoxelTerrainConstants._numVoxelsPerAxis; i++)
    //    {
    //        for (int j = chunkCenter.z; j < chunkCenter.z + VoxelTerrainConstants._numVoxelsPerAxis; j++)
    //        {
    //            IntVector2 posXZ = new IntVector2(i, j);
    //            if (!npcInfoMap.ContainsKey(posXZ))
    //            {
    //                continue;
    //            }
    //            VATownNpcInfo townNpcInfo = npcInfoMap[posXZ];
    //            if (!nodePosLod.ContainInTerrainNode(townNpcInfo.getPos()))
    //            {
    //                LogManager.Error("!nodePosLod.ContainInTerrainNode");
    //                continue;
    //            }
    //            if (townNpcInfo.PosY == -1)
    //            {
    //                continue;
    //            }
    //            int Id = townNpcInfo.getId();
    //            if (!NpcMissionDataRepository.m_AdRandMisNpcData.ContainsKey(Id))
    //            {
    //                continue;
    //            }
    //            //LogManager.Error("TownNPC: ID="+townNpcInfo.getId()+" pos="+townNpcInfo.getPos());
    //            if (Pathea.PeGameMgr.IsSingleAdventure)
    //            {
    //                AdNpcData adNpcData = NpcMissionDataRepository.m_AdRandMisNpcData[Id];
    //                int RNpcId = adNpcData.mRnpc_ID;
    //                int Qid = adNpcData.mQC_ID;

    //                //int npcid = NpcManager.Instance.RequestRandomNpc(RNpcId, townNpcInfo.getPos(), StroyManager.Instance.OnRandomNpcCreated1, adNpcData);
    //                //createdNpcIdList.Add(npcid);

    //                //NpcRandom nr = NpcManager.Instance.CreateRandomNpc(RNpcId, townNpcInfo.getPos());
    //                //StroyManager.Instance.NpcTakeMission(RNpcId, Qid, townNpcInfo.getPos(), nr, adNpcData.m_CSRecruitMissionList);
    //                //LogManager.Error("npc Created!Pos: " + townNpcInfo.getPos() + " id: " + RNpcId);
    //                //createdNpcIdList.Add(nr.mNpcId);
    //                createdPosList.Add(posXZ);
    //                npcInfoMap.Remove(posXZ);

    //            }
    //            else if (GameConfig.IsMultiMode)
    //            {
    //                SPTerrainEvent.instance.CreateAdNpcByIndex(townNpcInfo.getPos(), Id);
    //                npcInfoMap.Remove(posXZ);
    //            }
    //        }
    //    }
    //}

    //public void RenderTownNPC(IntVector2 posXZ)
    //{
    //    if (!npcInfoMap.ContainsKey(posXZ))
    //    {
    //        return;
    //    }
    //    VATownNpcInfo townNpcInfo = npcInfoMap[posXZ];
    //    if (townNpcInfo.PosY == -1)
    //    {
    //        return;
    //    }

    //    RenderTownNPC(townNpcInfo);
    //}

    public void RenderTownNPC(VATownNpcInfo townNpcInfo)
    {
        IntVector2 posXZ = townNpcInfo.Index;

        if (!npcInfoMap.ContainsKey(posXZ))
        {
            return;
        }
        int Id = townNpcInfo.getId();

        //if (!NpcMissionDataRepository.m_AdRandMisNpcData.ContainsKey(Id))
        //{
        //    return;
        //}
        if (Pathea.PeGameMgr.IsSingleAdventure)
        {
            //AdNpcData adNpcData = NpcMissionDataRepository.m_AdRandMisNpcData[Id];
            //int RNpcId = adNpcData.mRnpc_ID;
            //int Qid = adNpcData.mQC_ID;

            int enemyNpcId = GetEnemyNpcId(Id);
            int allyId     = VArtifactTownManager.Instance.GetTownByID(townNpcInfo.townId).AllyId;
            int allyColor  = VATownGenerator.Instance.GetAllyColor(allyId);
            int playerId   = VATownGenerator.Instance.GetPlayerId(allyId);
            if (allyId != TownGenData.PlayerAlly)
            {
                SceneEntityPosAgent agent = MonsterEntityCreator.CreateAdAgent(townNpcInfo.getPos(), enemyNpcId, allyColor, playerId);
                SceneMan.AddSceneObj(agent);
                VArtifactTownManager.Instance.AddMonsterPointAgent(townNpcInfo.townId, agent);
            }
            else
            {
                PeEntity npc = NpcEntityCreator.CreateNpc(Id, townNpcInfo.getPos(), Vector3.one, Quaternion.Euler(0, 180, 0));
                if (npc == null)
                {
                    Debug.LogError("npc id error: templateId = " + Id);
                    return;
                }
                //Debug.Log("created town npc:"+ npc.name+"_"+npc.position);
                VArtifactUtil.SetNpcStandRot(npc, 180, false);              //test
                if (Id == VArtifactTownManager.Instance.missionStartNpcID)
                {
                    VArtifactTownManager.Instance.missionStartNpcEntityId = npc.Id;
                }
                createdPosList.Add(posXZ);
            }

            //Debug.Log("Id: " + Id + " npcPos:" + townNpcInfo.getPos());

            //int npcid = NpcManager.Instance.RequestRandomNpc(RNpcId, townNpcInfo.getPos(), StroyManager.Instance.OnRandomNpcCreated1, adNpcData);
            //createdNpcIdList.Add(Id);

            //NpcRandom nr = NpcManager.Instance.CreateRandomNpc(RNpcId, townNpcInfo.getPos());
            //StroyManager.Instance.NpcTakeMission(RNpcId, Qid, townNpcInfo.getPos(), nr, adNpcData.m_CSRecruitMissionList);
            //LogManager.Error("npc Created!Pos: " + townNpcInfo.getPos() + " id: " + RNpcId);
            //createdNpcIdList.Add(nr.mNpcId);
            npcInfoMap.Remove(posXZ);
        }
        else if (GameConfig.IsMultiMode)
        {
            int enemyNpcId = GetEnemyNpcId(Id);
            int allyId     = VArtifactTownManager.Instance.GetTownByID(townNpcInfo.townId).AllyId;
            int allyColor  = VATownGenerator.Instance.GetAllyColor(allyId);
            int playerId   = VATownGenerator.Instance.GetPlayerId(allyId);
            if (allyId != TownGenData.PlayerAlly)
            {
                SceneEntityPosAgent agent = MonsterEntityCreator.CreateAdAgent(townNpcInfo.getPos(), enemyNpcId, allyColor, playerId);
                SceneMan.AddSceneObj(agent);
                VArtifactTownManager.Instance.AddMonsterPointAgent(townNpcInfo.townId, agent);
            }
            else
            {
                StartCoroutine(RenderOneNpc(townNpcInfo.getPos(), Id));
            }
            npcInfoMap.Remove(posXZ);
        }
    }
    IEnumerator RefreshTowerMission()
    {
        _idxWave = 0;
        _uiData.CurWavesRemaining = _spData._waveDatas.Count;
        _uiData.TotalWaves        = _spData._waveDatas.Count;
        while (_idxWave < _spData._waveDatas.Count)
        {
            while (PreTime > 0)
            {
                yield return(new WaitForSeconds(TimeStep));

                PreTime -= TimeStep;
            }
            PreTime = 0;
            Vector3 dir    = _forward;
            Vector3 center = _position;
            int     m      = _idxWave;
            AISpawnTDWavesData.TDWaveData wd = _spData._waveDatas[m];
            if (Pathea.PeGameMgr.IsStory)
            {
                StroyManager.Instance.PushStoryList(wd._plotID);
            }
            int nMonsterTypes = wd._monsterTypes.Count;
            for (int n = 0; n < nMonsterTypes; n++)
            {
                int spType   = wd._monsterTypes[n];
                int minAngle = wd._minDegs[n];
                int maxAngle = wd._maxDegs[n];
                int spCount  = UnityEngine.Random.Range(wd._minNums[n], wd._maxNums[n]);

                for (int i = 0; i < spCount; i++)
                {
                    Vector3 pos;
                    if (spType == 520 || spType == 521)                         //Special code for airborne monsters
                    {
                        pos = center;
                    }
                    else
                    {
                        if (isSweep)
                        {
                            pos = AiUtil.GetRandomPosition(center, 80, 100, dir, minAngle, maxAngle);
                            transform.position = center + ((center - pos) * 1000);
                        }
                        else
                        {
                            pos = AiUtil.GetRandomPosition(center, 20, 80, dir, minAngle, maxAngle);
                        }
                        pos.y = SceneEntityPosAgent.PosYTBD;                            // let posagent to set y
                    }
                    SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(pos, EncodeBcnMonsterProtoId(spType, _spData._dif, _spData._spawnType));
                    agent.spInfo  = new MonsterEntityCreator.AgentInfo(this);
                    agent.canRide = false;

                    if (handerNewEntity != null)
                    {
                        handerNewEntity(agent);
                    }

                    _agents.Add(agent);
                    SceneMan.AddSceneObj(agent);
                }
            }
            if (handlerNewWave != null)
            {
                handlerNewWave(_spData, _idxWave);
            }

            _uiData.CurWavesRemaining--;

            _idxWave++;
            if (_idxWave < _spData._waveDatas.Count)
            {
                int cdTime = _spData._timeToCool;
                while (cdTime > 0)
                {
                    yield return(new WaitForSeconds(1));

                    cdTime--;
                }
                PreTime = (float)_spData._waveDatas[_idxWave]._delayTime;
            }
        }
        ;
    }
 public virtual void OnFailedToCreate(SceneEntityPosAgent agent)
 {
     SceneMan.RemoveSceneObj(agent);
 }
    public bool Start()
    {
        MissionCommonData data = MissionManager.GetMissionCommonData(MissionId);

        for (int i = 0; i < data.m_TargetIDList.Count; i++)
        {
            if (data.m_TargetIDList[i] == TargetId)
            {
                _idxTarId = i;
                break;
            }
        }
        if (_idxTarId == -1)
        {
            return(false);
        }
        _data = MissionManager.GetTypeMonsterData(TargetId);
        if (_data == null)
        {
            return(false);
        }
        Vector3 referToPos;

        switch (_data.m_mr.refertoType)
        {
        case ReferToType.None:
            referToPos = PeCreature.Instance.mainPlayer.position;
            break;

        case ReferToType.Player:
            referToPos = PeCreature.Instance.mainPlayer.position;
            break;

        case ReferToType.Town:
            VArtifactUtil.GetTownPos(_data.m_mr.referToID, out referToPos);
            break;

        case ReferToType.Npc:
            referToPos = EntityMgr.Instance.Get(MissionManager.Instance.m_PlayerMission.adId_entityId[_data.m_mr.referToID]).position;
            break;

        default:
            referToPos = PeCreature.Instance.mainPlayer.position;
            break;
        }
        if (referToPos == Vector3.zero)
        {
            return(false);
        }
        if (PeGameMgr.IsSingle || PeGameMgr.IsTutorial)
        {
            if (_data.type == 2)
            {
                DoodadEntityCreator.commonDeathEvent += OnMonsterDeath;
            }
            else
            {
                MonsterEntityCreator.commonDeathEvent += OnMonsterDeath;
            }
        }

        GenMonsterInMission = !PeGameMgr.IsStory;
        if (GenMonsterInMission)
        {
#if  DbgNearGen
            Vector2 v2 = Vector2.zero;
#else
            Vector2 v2 = UnityEngine.Random.insideUnitCircle.normalized * _data.m_mr.radius1;
#endif
            Vector3 center = referToPos + new Vector3(v2.x, 0.0f, v2.y);
            //for (int i = 0; i < _data.m_MonsterList.Count; i++) {
            //	int num = _data.m_MonsterList[i].type;
            //             int protoId = _data.m_MonsterList[i].npcs[UnityEngine.Random.Range(0, _data.m_MonsterList[i].npcs.Count)];
            //	for (int j = 0; j < num; j++) {
            //		Vector3 pos = AiUtil.GetRandomPosition (center, 0, _data.m_mr.radius2);
            //		pos.y = SceneEntityPosAgent.PosYTBD;	// let posagent to set y
            //		SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(pos, protoId);
            //		agent.spInfo = new MonsterEntityCreator.AgentInfo(EntityMonsterBeacon.GetSpBeacon4MonsterKillTask());
            //		_agents.Add (agent);
            //		SceneMan.AddSceneObj (agent);
            //	}
            //}

            for (int i = 0; i < _data.m_CreMonList.Count; i++)
            {
                for (int j = 0; j < _data.m_CreMonList[i].monNum; j++)
                {
                    Vector3 pos = AiUtil.GetRandomPosition(center, 0, _data.m_mr.radius2);
                    pos.y = SceneEntityPosAgent.PosYTBD;    // let posagent to set y
                    int protoId = _data.m_CreMonList[i].monID;
                    if (_data.m_CreMonList[i].type == 1)
                    {
                        protoId |= EntityProto.IdGrpMask;
                    }
                    SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(pos, protoId);
                    agent.spInfo  = new MonsterEntityCreator.AgentInfo(EntityMonsterBeacon.GetSpBeacon4MonsterKillTask());
                    agent.canRide = false;
                    _agents.Add(agent);
                    SceneMan.AddSceneObj(agent);
                }
            }
        }
        return(true);
    }