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);
    }
    // New/Restore
    public void New()
    {
#if Have_ENTITY
        //if (EntityCreateMgr.DbgUseLegacyCode)
        //    return;

        NpcEntityCreator.Init();
        MonsterEntityCreator.Init();
        DoodadEntityCreator.Init();
        SceneEntityCreatorArchiver.Instance.New();
        if (PeGameMgr.IsStory || PeGameMgr.IsTutorial)
        {
            if (PeGameMgr.playerType == PeGameMgr.EPlayerType.Tutorial)
            {
                StartCoroutine(InitTutorialNpc());
            }
            else
            {
                DoodadEntityCreator.CreateStoryDoodads(true);
                StartCoroutine(InitStoryNpc());
            }
        }
        _bReadyToRefresh = true;
#endif
    }
Esempio n. 3
0
 IEnumerator RefreshAgents()
 {
     while (true)
     {
         if (PETools.PEUtil.SqrMagnitudeH(PeCreature.Instance.mainPlayer.position, Center) <= _playerRadius * _playerRadius)
         {
             int n = GetEntitiesCnt();
             if (n < _maxCntOfMonsters &&
                 _posOfMonsters != null && _posOfMonsters.Length > 0 &&
                 _protoIdsOfMonsters != null && _protoIdsOfMonsters.Length > 0)
             {
                 Vector3 pos     = GetSpawnPos();
                 int     protoId = GetProtoId();
                 if (PeGameMgr.IsAdventure)
                 {
                     SceneDoodadLodCmpt lod = GetComponentInParent <SceneDoodadLodCmpt> ();
                     if (lod != null && lod.Index >= 0)
                     {
                         int allyId    = VArtifactTownManager.Instance.GetTownByID(lod.Index).AllyId;
                         int playerId  = VATownGenerator.Instance.GetPlayerId(allyId);
                         int allyColor = VATownGenerator.Instance.GetAllyColor(allyId);
                         MonsterEntityCreator.CreateAdMonster(protoId, pos, allyColor, playerId);
                     }
                 }
                 else
                 {
                     MonsterEntityCreator.CreateMonster(protoId, pos);
                 }
                 //
             }
         }
         yield return(new WaitForSeconds(UnityEngine.Random.Range(_timeIntervalMinMax.x, _timeIntervalMinMax.y)));
     }
 }
    public void GenerateMonster(List <IdWeight> landMonsterId, List <IdWeight> waterMonsterId, int buff, System.Random rand, bool isTaskDungeon)
    {
//		if (RandomMonsterStrList.Count > 0)
//		{
//			List<IdWeight> idWeightList = new List<IdWeight>();
//			for (int i = 0; i < RandomMonsterStrList.Count; i++) {
//				idWeightList.Add(RandomDunGenUtil.GetChanceWeightFromStr(RandomMonsterStrList[i]));
//			}
//			int seed = (int)(System.DateTime.UtcNow.Ticks%Int32.MaxValue);
//			System.Random rand = new System.Random(seed);
//			List<int> pickedIdList = RandomDunGenUtil.PickIdFromWeightList(rand,idWeightList, 1);
//
//			PeEntity monster = MonsterEntityCreator.CreateMonster(pickedIdList[0], pos);
//			PESkEntity mp = monster.GetComponent<PESkEntity>();
//			mp.deathEvent+=RandomDungenMgr.Instance.OpenLockedDoor;
//			RandomDungenMgrData.AddMonster(monster);
//		}

        //--to do:check water
        List <IdWeight> monsterList = new List <IdWeight> ();

        if (VFVoxelWater.self != null)
        {
            if (VFVoxelWater.self.IsInWater(pos))
            {
                if (VFVoxelWater.self.IsInWater(pos + new Vector3(0, 1, 0)))
                {
                    if (VFVoxelWater.self.IsInWater(pos + new Vector3(0, 4, 0)))
                    {
                        monsterList = waterMonsterId;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    monsterList = landMonsterId;
                }
            }
            else
            {
                monsterList = landMonsterId;
            }
        }
        if (monsterList == null || monsterList.Count == 0)
        {
            return;
        }
        List <int> pickedIdList = RandomDunGenUtil.PickIdFromWeightList(rand, monsterList, 1);

        MonsterEntityCreator.CreateDungeonMonster(pickedIdList[0], pos, RandomDungenMgrData.DungeonId, buff);
    }
 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 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);
        }
    }
Esempio n. 7
0
    IEnumerator Exec()
    {
        while (true)
        {
            switch (_step)
            {
            case Step.FadeIn:
                if (_tAirborne.position.y > _dstPos.y)
                {
                    _tAirborne.position -= _spdDown * Vector3.up;
                }
                else
                {
                    _lastTime = -1.0f;
                    _spdWave  = 0.0f;
                    _step     = Step.Running;
                }
                break;

            case Step.Running:
                float a = _coefWave * (transform.position.y + _endHeight - _tAirborne.position.y);                      // assume weight == 1
                _spdWave            += a;
                _tAirborne.position += _spdWave * Vector3.up;

                if (_agents.Count > 0 && Time.realtimeSinceStartup > _lastTime + _itvCreate)
                {
                    Transform tSpawn = _tAirborne.Find("CreatMonster");
                    _agents[0].Pos      = tSpawn != null ? tSpawn.position : _tAirborne.position;
                    _agents[0].protoId &= ~EntityProto.IdAirborneAllMask;
                    MonsterEntityCreator.CreateMonster(_agents[0]);
                    _agents.RemoveAt(0);
                    _lastTime = Time.realtimeSinceStartup;
                }
                break;

            case Step.FadeOut:
                if (_tAirborne.position.y < _dstPos.y)
                {
                    _tAirborne.position += _spdDown * Vector3.up;
                }
                else
                {
                    Destroy(gameObject);
                }
                break;
            }
            yield return(0);
        }
    }
 public void Restore()
 {
     NpcEntityCreator.Init();
     MonsterEntityCreator.Init();
     DoodadEntityCreator.Init();
     SceneEntityCreatorArchiver.Instance.Restore();
     if (PeGameMgr.IsStory)
     {
         if (PeGameMgr.playerType != PeGameMgr.EPlayerType.Tutorial)
         {
             DoodadEntityCreator.CreateStoryDoodads(false);
         }
     }
     _bReadyToRefresh = true;
 }
 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);
     }
 }
Esempio n. 10
0
        void UpdatePlayerUpperAir()
        {
            if (!PeGameMgr.IsMulti && Entity == PeCreature.Instance.mainPlayer)
            {
                if (carrier == null || !(carrier is HelicopterController))
                {
                    m_UpperAir = false;
                }
                else
                {
                    float baseHeight = PeMappingMgr.Instance.GetTerrainHeight(Entity.position);

                    bool isHeight  = Entity.position.y - baseHeight > 30.0f;
                    bool isRunning = carrier.rigidbody != null && carrier.rigidbody.velocity.sqrMagnitude > 1f * 1f;

                    m_UpperAir = isHeight && isRunning;
                }
            }

            if (!m_UpperAir)
            {
                m_UpperAirStartTime = 0.0f;
            }
            else
            {
                if (m_UpperAirStartTime < PETools.PEMath.Epsilon)
                {
                    m_UpperAirStartTime = Time.time;
                }
            }

            if (m_UpperAir && m_UpperAirStartTime > 0.0f)
            {
                if (Time.time - m_UpperAirStartTime > 10.0f)
                {
                    m_UpperAirStartTime = Time.time;

                    float randomValue = UnityEngine.Random.value;

                    if (randomValue < 0.015f)
                    {
                        Vector3 position = PETools.PEUtil.GetRandomPosition(Entity.position, 25.0f, 35.0f);
                        MonsterEntityCreator.CreateMonster(73, position);
                        Debug.Log("Spawn caelum rex in upper air : " + randomValue + " time : " + Time.time);
                    }
                }
            }
        }
Esempio n. 11
0
    public void GenBoss(List <IdWeight> landMonsterId, List <IdWeight> waterMonsterId, int buff, System.Random rand, bool isTaskDungeon)
    {
        List <IdWeight> monsterList = new List <IdWeight> ();

        if (VFVoxelWater.self != null)
        {
            if (VFVoxelWater.self.IsInWater(pos))
            {
                if (VFVoxelWater.self.IsInWater(pos + new Vector3(0, 1, 0)))
                {
                    if (VFVoxelWater.self.IsInWater(pos + new Vector3(0, 4, 0)))
                    {
                        monsterList = waterMonsterId;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    monsterList = landMonsterId;
                }
            }
            else
            {
                monsterList = landMonsterId;
            }
        }
        if (monsterList == null || monsterList.Count == 0)
        {
            return;
        }
        List <int> pickedIdList = RandomDunGenUtil.PickIdFromWeightList(rand, monsterList, 1);

        MonsterEntityCreator.CreateDungeonMonster(pickedIdList[0], pos, RandomDungenMgrData.DungeonId, buff);

//		if(PeGameMgr.IsSingle&&monster!=null){
//			PESkEntity mp = monster.GetComponent<PESkEntity>();
//			mp.deathEvent+=RandomDungenMgr.Instance.OpenLockedDoor;
//			RandomDungenMgrData.AddMonster(monster);
//			//--to do add monsterBuff
//			if(buff!=0)
//				SkillSystem.SkEntity.MountBuff(monster.skEntity, buff, new List<int>(), new List<float>());
//		}
    }
 private void Init4FixedSpawnPoint()
 {
     foreach (KeyValuePair <int, AISpawnPoint> pair in AISpawnPoint.s_spawnPointData)
     {
         AISpawnPoint pt      = pair.Value;
         int          protoId = pt.resId;
         if (pt.isGroup)
         {
             protoId |= EntityProto.IdGrpMask;
         }
         FixedSpawnPointInfo info = new FixedSpawnPointInfo();
         info._bActive      = pt.active;
         info._needCD       = pt.refreshtime;
         info._agent        = MonsterEntityCreator.CreateAgent(pt.Position, protoId, Vector3.one, Quaternion.Euler(pt.euler));
         info._agent.spInfo = new AgentInfo(pair.Key);
         info._agent.FixPos = pt.fixPosition;
         _fixedSpawnPointInfos[pair.Key] = info;
     }
 }
Esempio n. 13
0
    public void GenBoss(List <IdWeight> landMonsterId, List <IdWeight> waterMonsterId, int buff, System.Random rand, bool isTaskDungeon)
    {
        List <IdWeight> monsterList = new List <IdWeight> ();

        if (VFVoxelWater.self != null)
        {
            if (VFVoxelWater.self.IsInWater(pos))
            {
                if (VFVoxelWater.self.IsInWater(pos + new Vector3(0, 1, 0)))
                {
                    if (VFVoxelWater.self.IsInWater(pos + new Vector3(0, 4, 0)))
                    {
                        monsterList = waterMonsterId;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    monsterList = landMonsterId;
                }
            }
            else
            {
                monsterList = landMonsterId;
            }
        }
        if (monsterList == null || monsterList.Count == 0)
        {
            return;
        }
        List <int> pickedIdList = RandomDunGenUtil.PickIdFromWeightList(rand, monsterList, 1);

        MonsterEntityCreator.CreateDungeonMonster(pickedIdList[0], pos, RandomDungenMgrData.DungeonId, buff);
//		if(PeGameMgr.IsSingle&&monster!=null&&buff!=0)
//			SkillSystem.SkEntity.MountBuff(monster.skEntity, buff, new List<int>(), new List<float>());
    }
    IEnumerator TryCreateEntityUnstatic()
    {
        _step = EStep.InCreating;

        int n = 0;

        while (n++ < MaxTimes)
        {
            if (CheckSetAvailablePos())
            {
                switch (_type)
                {
                case EntityType.EntityType_Npc:                 NpcEntityCreator.CreateNpc(this); break;

                case EntityType.EntityType_Monster:     MonsterEntityCreator.CreateMonster(this); break;
                }

                if (entity != null)
                {
                    spInfo.OnSuceededToCreate(this);
                }
                else
                {
                    //if(protoId >= 0){	// Airborne monster would go here to remove its agent
                    //	Debug.LogWarning("[EntityPosAgent]:Failed to create entity "+_type.ToString()+protoId);
                    //}
                    spInfo.OnFailedToCreate(this);
                }
                break;
            }
            yield return(new WaitForSeconds(OneWait));
        }
        if (n >= MaxTimes)
        {
            Debug.LogWarning("[EntityPosAgent]:Failed to create entity " + _type.ToString() + protoId + " during " + n * OneWait);
        }

        _step = EStep.Created;
    }
Esempio n. 15
0
    void Start()
    {
        //PeEntity entity = null;

        if (protoType == ProtoType.Doodad)
        {
            DoodadEntityCreator.CreateDoodad(protoID, transform.position);
        }
        else if (protoType == ProtoType.NpcRandom)
        {
            NpcEntityCreator.CreateNpc(protoID, transform.position);
        }
        else if (protoType == ProtoType.NpcLine)
        {
            NpcEntityCreator.CreateStoryLineNpcFromID(protoID, transform.position);
        }
        else
        {
            MonsterEntityCreator.CreateAdMonster(protoID, transform.position, colorId, -1);
        }

        Destroy(gameObject);
    }
    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);
//		}
    }
Esempio n. 17
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 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);
    }
Esempio n. 19
0
    //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;
            }
        }
        ;
    }