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)));
     }
 }
    void Start()
    {
        if (PeGameMgr.IsAdventure)
        {
            SceneDoodadLodCmpt lod = GetComponentInParent <SceneDoodadLodCmpt> ();
            if (lod != null && lod.Index >= 0)
            {
//				int townid = lod.Index;
                List <Vector3> lstPos;
                VANativeCampXML.DynamicNative[] nativeIds = VArtifactUtil.GetAllDynamicNativePoint(lod.Index, out lstPos);
                if (nativeIds == null)
                {
                    return;
                }
                int cntNativeIds = nativeIds.Length;
                _posOfMonsters      = lstPos.ToArray();
                _protoIdsOfMonsters = new int[cntNativeIds];
                for (int i = 0; i < cntNativeIds; i++)
                {
                    _protoIdsOfMonsters[i] = nativeIds[i].type == 0 ? (nativeIds[i].did | EntityProto.IdGrpMask) : nativeIds[i].did;
                }
                _maxCntOfMonsters = 8;
            }
        }
        _radius = 256.0f;         //force 128
        StartCoroutine(RefreshAgents());
    }
Example #3
0
        bool _initDoodad(PeEntity entity, DoodadSpawnPoint sp)
        {
            if (entity == null)
            {
                Debug.LogError("The entity that given is null");
                return(false);
            }

            PeTrans view = entity.peTrans;

            if (null == view)
            {
                Debug.LogError("[SceneEntityCreator]No viewCmpt in doodad:" + sp.Prototype);
                return(false);
            }

            view.position = sp.spawnPos;
            view.rotation = sp.Rotation;
            view.scale    = sp.Scale;

            SceneDoodadLodCmpt lod = entity.GetCmpt <SceneDoodadLodCmpt> ();

            if (lod != null)
            {
                lod.IsShown     = sp.Visible;
                lod.IsDamagable = sp.IsTarget;
            }

            return(true);
        }
    // private
    static PeEntity CreateDoodad(bool bSerializable, AgentInfo spInfo, int protoId, Vector3 pos, Vector3 scl, Quaternion rot, int id = -1)
    {
        PeEntity entity = null;

        if (PeGameMgr.IsMulti && -1 != id)
        {
            entity = PeEntityCreator.Instance.CreateDoodad(id, protoId, pos, rot, scl);
        }
        else
        {
            entity = bSerializable
                                        ? PeCreature.Instance.CreateDoodad(Pathea.WorldInfoMgr.Instance.FetchRecordAutoId(), protoId, pos, rot, scl)
                                        : PeEntityCreator.Instance.CreateDoodad(Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId(), protoId, pos, rot, scl);
        }

        if (null == entity)
        {
            Debug.LogError("Failed to create doodad!");
            return(null);
        }
        if (spInfo != null)
        {
            SceneDoodadLodCmpt lod = entity.GetCmpt <SceneDoodadLodCmpt> ();
            if (lod != null)
            {
                lod.Index   = spInfo._id;
                lod.IsShown = spInfo._isShown;
                lod.SetDamagable(spInfo._campId, spInfo._damageId, spInfo._playerId);
            }
        }
        return(entity);
    }
    public static void OnDoodadDeath(SkEntity a, SkEntity b)
    {
        if (commonDeathEvent != null)
        {
            commonDeathEvent(a, b);
        }

        //--to do
        if (PeGameMgr.IsAdventure)
        {
            SceneDoodadLodCmpt lod = a.gameObject.GetComponent <SceneDoodadLodCmpt>();
            if (lod != null && lod.Index >= 0)
            {
                PeEntity entity = a.gameObject.GetComponent <PeEntity>();
                if (entity != null)
                {
                    bool isSignalTower = a.GetComponentInChildren <MonsterSummoner>() != null;
                    VArtifactTownManager.Instance.OnBuildingDeath(lod.Index, entity.Id, isSignalTower);
                }
            }
        }
    }