Beispiel #1
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);
        }
Beispiel #2
0
        public bool AddDoodad(DoodadSpawnPoint dsp)
        {
            if (!mDoodads.ContainsKey(dsp.ID))
            {
                mDoodads.Add(dsp.ID, dsp);
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        void SetDoodads(IEnumerable <WEDoodad> items)
        {
            if (items == null)
            {
                return;
            }
            ClearDoodad();

            foreach (WEDoodad item in items)
            {
                DoodadSpawnPoint sp = new DoodadSpawnPoint(item);

                mDoodads.Add(sp.ID, sp);
            }
        }
Beispiel #4
0
        PeEntity CreadteDoodad(DoodadSpawnPoint point, bool is_save)
        {
            PeEntity entity = null;

            if (is_save)
            {
                if (point.EntityID == -1)
                {
                    int id = Pathea.WorldInfoMgr.Instance.FetchRecordAutoId();
                    entity         = CreatureMgr.Instance.CreateDoodad(CustomGameData.Mgr.Instance.curGameData.WorldIndex, id, point.Prototype);
                    point.EntityID = entity.Id;

                    _initDoodad(entity, point);
                }
                else
                {
                    //PeEntity ent = EntityMgr.Instance.Get(point.EntityID);
                    entity = CreatureMgr.Instance.CreateDoodad(CustomGameData.Mgr.Instance.curGameData.WorldIndex, point.EntityID, point.Prototype);
                    if (entity == null)
                    {
                        Debug.LogError("Cant Find the Entity [ID " + point.EntityID.ToString() + "]");
                    }
                }
            }
            else
            {
                Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId();
                entity         = PeEntityCreator.Instance.CreateDoodad(Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId(), point.Prototype, Vector3.zero, Quaternion.identity, Vector3.one);
                point.EntityID = entity.Id;

                _initDoodad(entity, point);
            }

            if (entity != null)
            {
                entity.scenarioId = point.ID;
                PeScenarioEntity pse = entity.gameObject.GetComponent <PeScenarioEntity>();
                if (pse == null)
                {
                    pse = entity.gameObject.AddComponent <PeScenarioEntity>();
                }
                pse.spawnPoint = point;
            }

            return(entity);
        }
        /// <summary>
        /// Accept the notification for Views.
        /// </summary>
        /// <param name="msg_type">Msg_type.</param>
        /// <param name="data">Data.</param>
        public void OnNotification(ESceneNoification msg_type, params object[] data)
        {
            SpawnDataSource ds = mBinder.Get <SpawnDataSource>();

            switch (msg_type)
            {
            case ESceneNoification.SceneBegin:
                if (PeGameMgr.IsSingle)
                {
                    CreateAgents(ds);
                }
                break;

            case ESceneNoification.CreateAgent:
            {
                if (data.Length == 0)
                {
                    Debug.LogError("Create Agent notification parameters error");
                    break;
                }

                SpawnPoint sp = data[0] as SpawnPoint;

                CreateAgent(ds, sp);
            }
            break;

                #region SPAWNPOINT_CASE
            case ESceneNoification.RemoveSpawnPoint:
            {
                if (data.Length == 0)
                {
                    Debug.LogError("Remove SpawnPoint notification parameters error");
                    break;
                }

                SpawnPoint sp = data[0] as SpawnPoint;
                // Monster
                if (sp as MonsterSpawnPoint != null)
                {
                    MonsterSpawnPoint msp = sp as MonsterSpawnPoint;

                    // Destroy Entity First
                    if (msp.EntityID != -1)
                    {
                        CreatureMgr.Instance.Destory(sp.EntityID);
                    }

                    // Remove Agent
                    if (msp.agent != null)
                    {
                        SceneMan.RemoveSceneObj(msp.agent);
                    }

                    // Remove Spawn Point
                    ds.RemoveMonster(msp.ID);
                }
                // Npc
                else if (sp as NPCSpawnPoint != null)
                {
                    NPCSpawnPoint nsp = sp as NPCSpawnPoint;

                    // Destroy Entity First
                    if (nsp.EntityID != -1)
                    {
                        CreatureMgr.Instance.Destory(sp.EntityID);
                    }

                    if (nsp.agent != null)
                    {
                        SceneMan.RemoveSceneObj(nsp.agent);
                    }

                    ds.RemoveMonster(nsp.ID);
                }
                // Doodad
                else if (sp as DoodadSpawnPoint != null)
                {
                    DoodadSpawnPoint dsp = sp as DoodadSpawnPoint;

                    if (dsp.EntityID != -1)
                    {
                        CreatureMgr.Instance.Destory(sp.EntityID);
                    }

                    if (dsp.agent != null)
                    {
                        SceneMan.RemoveSceneObj(dsp.agent);
                    }

                    ds.RemoveMonster(dsp.ID);
                }
                // Item
                else if (sp as ItemSpwanPoint != null)
                {
                    ItemSpwanPoint isp = sp as ItemSpwanPoint;

                    List <ISceneObjAgent> agents = SceneMan.GetSceneObjs <DragArticleAgent>();
                    for (int i = 0; i < agents.Count; i++)
                    {
                        DragArticleAgent drag_agent = agents[i] as DragArticleAgent;
                        if (drag_agent != null && drag_agent.itemDrag.itemObj.instanceId == isp.ItemObjId)
                        {
                            ItemAsset.ItemMgr.Instance.DestroyItem(isp.ItemObjId);
                            SceneMan.RemoveSceneObj(drag_agent);
                            break;
                        }
                    }
                }
            }
            break;

            case ESceneNoification.EnableSpawnPoint:
            {
                if (data.Length < 1)
                {
                    Debug.LogError("Enable SpawnPoint notification parameters error");
                    break;
                }

                SpawnPoint sp     = data[0] as SpawnPoint;
                bool       enable = (bool)data[1];

                if (sp as MonsterSpawnArea != null)
                {
                    MonsterSpawnArea area = sp as MonsterSpawnArea;
                    for (int i = 0; i < area.Spawns.Count; i++)
                    {
                        for (int j = 0; j < area.Spawns[i].spawnPoints.Count; j++)
                        {
                            area.Spawns[i].spawnPoints[j].Enable = enable;
                        }
                    }
                }
                sp.Enable = enable;
            }
            break;
                #endregion

                #region CREATE_CASE
            case ESceneNoification.CreateMonster:
            {
                if (data.Length < 2)
                {
                    Debug.LogError("The [CreateMonster] notification parameter is wrong");
                    break;
                }

                SceneEntityAgent agent = data[0] as SceneEntityAgent;
                bool             save  = (bool)data[1];

                bool need_check = true;
                if (data.Length > 2)
                {
                    need_check = (bool)data[2];
                }

                Vector3 pos = agent.spawnPoint.spawnPos;
                if (!need_check || CheckPos(out pos, pos, agent.spawnPoint, agent.spawnArea))
                {
                    agent.spawnPoint.spawnPos = pos;

                    // Is Group Root?
                    if (agent.groupPoints != null)
                    {
                        agent.entityGp          = CreateMonsterGroup(agent.spawnPoint, agent.groupPoints, agent.spawnArea);
                        agent.entity            = agent.entityGp;
                        agent.entity.scenarioId = agent.ScenarioId;

                        break;
                    }

                    agent.entity            = CreateMonster(agent.mstPoint, save);
                    agent.entity.scenarioId = agent.ScenarioId;

                    if (agent.entityGp != null)
                    {
                        agent.entity.transform.parent = agent.entityGp.transform;
                    }

                    Debug.Log("Create the Monster ");
                }
            } break;

            case ESceneNoification.CreateNpc:
            {
                if (data.Length == 0)
                {
                    Debug.LogError("The [CreateNpc] notification parameters are wrong");
                    break;
                }

                SceneEntityAgent agent = data[0] as SceneEntityAgent;

                bool need_check = true;
                if (data.Length > 1)
                {
                    need_check = (bool)data[1];
                }

                Vector3 pos = agent.spawnPoint.spawnPos;
                if (!need_check || CheckPos(out pos, pos, agent.spawnPoint, agent.spawnArea))
                {
                    agent.spawnPoint.spawnPos = pos;
                    agent.entity = CreateNpc(agent.spawnPoint as NPCSpawnPoint);

                    if (agent.entity == null)
                    {
                        agent.entity.scenarioId = agent.ScenarioId;
                        Debug.LogError("[SceneEntityCreator]Failed to create npc:" + agent.protoId);
                    }
                    else
                    {
                        Debug.Log("Create the Npc [" + agent.entity.Id.ToString() + "]");
                    }
                }
            } break;

            case ESceneNoification.CreateDoodad:
            {
                if (data.Length < 2)
                {
                    Debug.LogError("The [CreateNpc] notification parameters are wrong");
                    break;
                }

                SceneStaticAgent agent = data[0] as SceneStaticAgent;
                //bool is_save = (bool)data[1];

                agent.entity            = CreadteDoodad(agent.spawnPoint as DoodadSpawnPoint, agent.IsSave);
                agent.entity.scenarioId = agent.ScenarioId;
            }
            break;
                #endregion


                #region DEAD_CASE
            case ESceneNoification.MonsterDead:
            {
                if (data.Length == 0)
                {
                    Debug.LogError("The [MonsterDead] notification parameters are wrong ");
                    break;
                }

                SceneEntityAgent agent = data[0] as SceneEntityAgent;

                MonsterSpawnPoint msp = agent.mstPoint;
                if (msp == null)
                {
                    Debug.LogError("he [MonsterDead] notification : the point is not a MonsterSpawnPoint");
                    break;
                }


                msp.isDead   = true;
                msp.EntityID = -1;

                Debug.Log("The monster [" + agent.entity.Id.ToString() + "] is Dead");
                agent.entity = null;

                if (agent.spawnArea != null)
                {
                    if (agent.spawnArea.MaxRespawnCount != 0)
                    {
                        AddMstDeadAgent(agent);
                    }
                }
                else if (msp.MaxRespawnCount != 0)
                {
                    AddMstDeadAgent(agent);
                }
            } break;

            case ESceneNoification.DoodadDead:
            {
                if (data.Length == 0)
                {
                    Debug.LogError("The [DoodadDead] notification parameters are wrong ");
                    break;
                }

                SceneStaticAgent agent = data[0] as SceneStaticAgent;

                DoodadSpawnPoint dsp = agent.spawnPoint as DoodadSpawnPoint;
                if (dsp == null)
                {
                    Debug.LogError("he [DoodadDead] notification : the point is not a DoodadSpawnPoint");
                    break;
                }

                dsp.isDead   = true;
                dsp.EntityID = -1;
            }
            break;

                #endregion
            case ESceneNoification.EntityDestroy:
            {
                if (data.Length < 2)
                {
                    Debug.LogError("The [EntityDestroy] notification parameters are wrong ");
                    break;
                }

                SpawnPoint sp     = data[0] as SpawnPoint;
                PeEntity   entity = data[1] as PeEntity;

                bool remove_data = false;
                if (data.Length > 2)
                {
                    remove_data = (bool)data[2];
                }

                if (remove_data)
                {
                    entity.Export();
                    CreatureMgr.Instance.Destory(sp.EntityID);
                    sp.EntityID = -1;
                }
                else
                {
                    CreatureMgr.Instance.DestroyAndDontRemove(sp.EntityID);
                }
            } break;
            }
        }
Beispiel #6
0
        /// <summary>
        /// 根据 OBJECT 找到相应的 GameObject
        /// </summary>
        /// <returns>The GameObject.</returns>
        /// <param name="obj">OBJECT 结构,来自statement的自定义参数.</param>
        public static GameObject GetGameObject(OBJECT obj)
        {
            if (obj.isCurrentPlayer)
            {
                return(PeCreature.Instance.mainPlayer.gameObject);
            }

            if (!obj.isSpecificEntity)
            {
                return(null);
            }

            if (obj.isPlayerId)
            {
                if (CustomGameData.Mgr.Instance != null &&
                    CustomGameData.Mgr.Instance.curGameData != null)
                {
                    if (CustomGameData.Mgr.Instance.curGameData.curPlayer.ID == obj.Id)
                    {
                        if (PeCreature.Instance.mainPlayer != null)
                        {
                            return(PeCreature.Instance.mainPlayer.gameObject);
                        }
                    }
                }
            }
            else if (obj.isNpoId)
            {
                if (CustomGameData.Mgr.Instance != null &&
                    CustomGameData.Mgr.Instance.curGameData != null)
                {
                    if (CustomGameData.Mgr.Instance.curGameData.WorldIndex == obj.Group)
                    {
                        if (PeGameMgr.IsSingle)
                        {
                            SpawnDataSource sds = PeCustomScene.Self.spawnData;
                            // Monster ?
                            if (sds.ContainMonster(obj.Id))
                            {
                                MonsterSpawnPoint msp = sds.GetMonster(obj.Id);
                                if (msp.agent != null)
                                {
                                    if (msp.agent.entity != null)
                                    {
                                        return(msp.agent.entity.gameObject);
                                    }
                                    else
                                    {
                                        if (msp.agent.ForceCreateEntity())
                                        {
                                            return(msp.agent.entity.gameObject);
                                        }
                                        else
                                        {
                                            Debug.Log("Create Entity Faild");
                                        }
                                    }
                                }
                            }
                            // Npc ?
                            else if (sds.ContainNpc(obj.Id))
                            {
                                NPCSpawnPoint nsp = sds.GetNpc(obj.Id);
                                if (nsp.agent != null)
                                {
                                    if (nsp.agent.entity != null)
                                    {
                                        return(nsp.agent.entity.gameObject);
                                    }
                                    else
                                    {
                                        if (nsp.agent.ForceCreateEntity())
                                        {
                                            return(nsp.agent.entity.gameObject);
                                        }
                                        else
                                        {
                                            Debug.Log("Create Entity Faild");
                                        }
                                    }
                                }
                            }
                            // Doodad ?
                            else if (sds.ContainDoodad(obj.Id))
                            {
                                DoodadSpawnPoint dsp = sds.GetDoodad(obj.Id);
                                if (dsp.agent != null)
                                {
                                    if (dsp.agent.entity != null)
                                    {
                                        return(dsp.agent.entity.gameObject);
                                    }
                                    else
                                    {
                                        if (dsp.agent.ForceCreateEntity())
                                        {
                                            return(dsp.agent.entity.gameObject);
                                        }
                                        else
                                        {
                                            Debug.Log("Create Entity faild");
                                        }
                                    }
                                }
                            }
                            // Item ?
                            else if (sds.ContainItem(obj.Id))
                            {
                                //ItemAsset.Drag drag = null;
                                ItemSpwanPoint        isp       = sds.GetItem(obj.Id);
                                List <ISceneObjAgent> agents    = SceneMan.GetSceneObjs <DragArticleAgent>();
                                DragArticleAgent      tar_agent = null;
                                for (int i = 0; i < agents.Count; i++)
                                {
                                    DragArticleAgent _tar = agents[i] as DragArticleAgent;
                                    if (_tar != null && _tar.itemDrag.itemObj.instanceId == isp.ItemObjId)
                                    {
                                        tar_agent = _tar;
                                        break;
                                    }
                                }

                                if (tar_agent != null)
                                {
                                    if (tar_agent.itemLogic != null || tar_agent.itemScript != null)
                                    {
                                        if (tar_agent.itemLogic != null)
                                        {
                                            return(tar_agent.itemLogic.gameObject);
                                        }
                                        else
                                        {
                                            return(tar_agent.itemScript.gameObject);
                                        }
                                    }
                                    else
                                    {
                                        //TODO: 当前item并没有创建gameobj,强制创建?
                                        //tar_agent.TryForceCreateGO();
                                        //if (tar_agent.itemScript != null)
                                        //    return tar_agent.itemScript.gameObject;
                                    }
                                }
                            }
                        }
                        else
                        {
                            PeEntity entity = EntityMgr.Instance.GetByScenarioId(obj.Id);
                            if (null != entity)
                            {
                                return(entity.gameObject);
                            }
                        }
                    }
                }
            }


            return(null);
        }
Beispiel #7
0
 public DoodadSpawnPoint(DoodadSpawnPoint sp)
     : base(sp)
 {
 }
Beispiel #8
0
 public SceneStaticAgent(DoodadSpawnPoint sp, bool is_saved)
 {
     mPoint = sp;
     IsSave = is_saved;
 }
Beispiel #9
0
        /// <summary>
        /// Create a agent for a spawn point and add sp to the spawn data source
        /// </summary>
        void CreateAgent(SpawnDataSource ds, SpawnPoint sp)
        {
            // Create Monster Agent
            if (sp as MonsterSpawnPoint != null)
            {
                MonsterSpawnPoint msp = sp as MonsterSpawnPoint;

                if (ds.AddMonster(msp))
                {
                    SceneEntityAgent agent = _createMstAgent(msp, true, null, null, !msp.isDead);
                    msp.agent        = agent;
                    agent.ScenarioId = sp.ID;
                    AddMstDeadAgent(agent);
                }
                else
                {
                    Debug.LogError("Add Monster spawn point error");
                }
            }
            // Create Npc Agent
            else if (sp as NPCSpawnPoint != null)
            {
                NPCSpawnPoint nsp = sp as NPCSpawnPoint;
                if (ds.AddNpc(nsp))
                {
                    SceneEntityAgent agent = new SceneEntityAgent(nsp);
                    nsp.agent        = agent;
                    agent.ScenarioId = sp.ID;
                    SceneMan.AddSceneObj(agent);
                }
                else
                {
                    Debug.LogError("Add npc spawn point error");
                }
            }
            // Create Doodad Agent
            else if (sp as DoodadSpawnPoint != null)
            {
                DoodadSpawnPoint dsp = sp as DoodadSpawnPoint;
                if (ds.AddDoodad(dsp))
                {
                    SceneStaticAgent agent = new SceneStaticAgent(dsp, true);
                    dsp.agent        = agent;
                    agent.ScenarioId = sp.ID;
                    SceneMan.AddSceneObj(agent);
                }
                else
                {
                    Debug.LogError("Add doodad spawn point error");
                }
            }
            // Create Item
            else if (sp as ItemSpwanPoint != null)
            {
                ItemSpwanPoint isp = sp as ItemSpwanPoint;
                if (ds.AddItem(isp))
                {
                    DragArticleAgent agent = DragArticleAgent.PutItemByProroId(isp.Prototype
                                                                               , isp.spawnPos
                                                                               , isp.Scale
                                                                               , isp.Rotation
                                                                               , isp.CanPickup
                                                                               , isp.IsTarget);
                    if (agent != null)
                    {
                        isp.isNew        = false;
                        isp.ItemObjId    = agent.itemDrag.itemObj.instanceId;
                        agent.ScenarioId = sp.ID;
                    }
                }
                else
                {
                    Debug.LogError("Add item spawn point error");
                }
            }
            // Create Effect
            else if (sp as EffectSpwanPoint != null)
            {
            }
        }
Beispiel #10
0
        void SetData(byte[] data)
        {
            using (MemoryStream ms_iso = new MemoryStream(data))
            {
                BinaryReader r = new BinaryReader(ms_iso);

                int version = r.ReadInt32();

                switch (version)
                {
                case 0x0000001:
                case 0x0000002:
                case 0x0000003:
                {
                    int count = r.ReadInt32();

                    for (int i = 0; i < count; i++)
                    {
                        MonsterSpawnPoint sp = new MonsterSpawnPoint();
                        sp.Deserialize(version, r);
                        mMsts.Add(sp.ID, sp);
                    }

                    //-- Area Spawn point list
                    count = r.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        MonsterSpawnArea sa = new MonsterSpawnArea();
                        sa.Deserialize(version, r);
                        mMstAreas.Add(sa.ID, sa);
                    }

                    // -- NPC
                    count = r.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        NPCSpawnPoint sp = new NPCSpawnPoint();
                        sp.Deserialize(version, r);
                        mNpcs.Add(sp.ID, sp);
                    }

                    // Doodad
                    count = r.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        DoodadSpawnPoint sp = new DoodadSpawnPoint();
                        sp.Deserialize(version, r);
                        mDoodads.Add(sp.ID, sp);
                    }

                    // Item
                    count = r.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        ItemSpwanPoint sp = new ItemSpwanPoint();
                        sp.Deserialize(version, r);
                        mItems.Add(sp.ID, sp);
                    }
                }
                break;

                case 0x0000004:
                {
                    mMaxSpawnPointId = r.ReadInt32();
                    int count = r.ReadInt32();


                    for (int i = 0; i < count; i++)
                    {
                        MonsterSpawnPoint sp = new MonsterSpawnPoint();
                        sp.Deserialize(version, r);
                        mMsts.Add(sp.ID, sp);
                    }

                    //-- Area Spawn point list
                    count = r.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        MonsterSpawnArea sa = new MonsterSpawnArea();
                        sa.Deserialize(version, r);
                        mMstAreas.Add(sa.ID, sa);
                    }

                    // -- NPC
                    count = r.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        NPCSpawnPoint sp = new NPCSpawnPoint();
                        sp.Deserialize(version, r);
                        mNpcs.Add(sp.ID, sp);
                    }

                    // Doodad
                    count = r.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        DoodadSpawnPoint sp = new DoodadSpawnPoint();
                        sp.Deserialize(version, r);
                        mDoodads.Add(sp.ID, sp);
                    }

                    // Item
                    count = r.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        ItemSpwanPoint sp = new ItemSpwanPoint();
                        sp.Deserialize(version, r);
                        mItems.Add(sp.ID, sp);
                    }
                }
                break;

                default: break;
                }
            }
        }