コード例 #1
0
        void SetMonsters(IEnumerable <WEMonster> items)
        {
            if (items == null)
            {
                return;
            }
            // Clear First
            ClearMonster();


            foreach (WEMonster item in items)
            {
                // this item is a  area
                if (item.AreaSpwan)
                {
                    MonsterSpawnArea sa = new MonsterSpawnArea(item);
                    sa.CalcSpawns();

                    mMstAreas.Add(sa.ID, sa);
                }
                else
                {
                    MonsterSpawnPoint sp = new MonsterSpawnPoint(item);

                    mMsts.Add(sp.ID, sp);
                }
            }
        }
コード例 #2
0
 public void OnActivate()
 {
     if (entity == null && !mIsProcessing)
     {
         MonsterSpawnPoint mst = mstPoint;
         if ((mst == null || !mst.isDead) &&
             (spawnPoint.Enable || spawnPoint.EntityID != -1))
         {
             SceneMan.self.StartCoroutine(CreateEntity());
         }
     }
     else if (entity != null && !mIsProcessing)
     {
         if (entity.peTrans != null)
         {
             Vector3 pos = entity.peTrans.position;
             if (SceneAgentsContoller.CheckPos(out pos, pos, spawnPoint, spawnArea))
             {
                 entity.ExtSetPos(pos);
             }
             else
             {
                 Debug.LogWarning("The Entity id [" + entity.Id + "] position is wrong");
             }
         }
     }
 }
コード例 #3
0
 public SceneEntityAgent(MonsterSpawnPoint _point, bool is_saved = false, MonsterSpawnArea _area = null, MonsterSpawnPoint[]  _groupPoints = null)
 {
     mPoint      = _point;
     mIsSave     = is_saved;
     mArea       = _area;
     groupPoints = _groupPoints;
     mType       = EntityType.EntityType_Monster;
 }
コード例 #4
0
 public bool AddMonster(MonsterSpawnPoint msp)
 {
     if (!mMsts.ContainsKey(msp.ID))
     {
         mMsts.Add(msp.ID, msp);
         return(true);
     }
     return(false);
 }
コード例 #5
0
        static bool CheckInWater(out Vector3 outPutPos, Vector3 curPos, SpawnPoint point, MonsterSpawnArea area)
        {
            outPutPos = curPos;

            if (PETools.PE.PointInWater(curPos) > 0.52f && PETools.PE.PointInTerrain(curPos) < 0.52f)
            {
                return(true);
            }

            MonsterSpawnPoint msp = point as MonsterSpawnPoint;

            if (msp == null || area == null)
            {
                int     ofs = 5;
                Vector3 pos = new Vector3(curPos.x, curPos.y - ofs, curPos.z);

                for (int i = 0; i < ofs * 2; i++)
                {
                    pos.y += 1;

                    if (PETools.PE.PointInWater(pos) > 0.52f && PETools.PE.PointInTerrain(pos) < 0.52f)
                    {
                        outPutPos = pos;
                        return(true);
                    }
                }
            }
            else
            {
                int xmin = Mathf.FloorToInt(msp.bound.center.x - msp.bound.extents.x);
                int xmax = Mathf.FloorToInt(msp.bound.center.x + msp.bound.extents.x);
                int ymin = Mathf.FloorToInt(msp.bound.center.y - msp.bound.extents.y);
                int ymax = Mathf.FloorToInt(msp.bound.center.y + msp.bound.extents.y);
                int zmin = Mathf.FloorToInt(msp.bound.center.z - msp.bound.extents.z);
                int zmax = Mathf.FloorToInt(msp.bound.center.z + msp.bound.extents.z);

                int cnt = 50;
                while (cnt > 0)
                {
                    cnt--;

                    Vector3 pos = new Vector3(Random.Range(xmin, xmax),
                                              Random.Range(ymin, ymax),
                                              Random.Range(zmin, zmax));

                    pos = area.spawnPos + area.Rotation * (pos - area.spawnPos);

                    if (PETools.PE.PointInWater(pos) > 0.52f)
                    {
                        outPutPos = pos;
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #6
0
        SceneEntityAgent _createMstAgent(MonsterSpawnPoint _point, bool is_saved, MonsterSpawnArea _area = null, MonsterSpawnPoint[] _groupPoints = null, bool save_to_scene = true)
        {
            SceneEntityAgent agent = new SceneEntityAgent(_point, is_saved, _area, _groupPoints);

            if (save_to_scene)
            {
                SceneMan.AddSceneObj(agent);
            }

            return(agent);
        }
コード例 #7
0
        PeEntity CreateMonster(MonsterSpawnPoint point, bool save)
        {
            PeEntity entity = null;

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

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

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

            return(entity);
        }
コード例 #8
0
        /// <summary>
        /// 在指定位置创建Object
        /// </summary>
        /// <param name="proto"> Object 的proto类型 </param>
        /// <param name="pos">创建位置 </param>
        /// <returns></returns>
        public static bool CreateObject(OBJECT proto, Vector3 pos)
        {
            if (!proto.isSpecificPrototype)
            {
                return(false);
            }

            if (proto.type == OBJECT.OBJECTTYPE.MonsterProto)
            {
                int id = PeCustomScene.Self.spawnData.GenerateId();
                MonsterSpawnPoint msp = new MonsterSpawnPoint();
                msp.ID              = id;
                msp.spawnPos        = pos;
                msp.Rotation        = Quaternion.identity;
                msp.Scale           = Vector3.one;
                msp.entityPos       = pos;
                msp.Prototype       = proto.Id;
                msp.IsTarget        = true;
                msp.Visible         = true;
                msp.isDead          = false;
                msp.MaxRespawnCount = 0;
                msp.RespawnTime     = 0;
                msp.bound           = new Bounds();

                PeCustomScene.Self.CreateAgent(msp);
            }
            else if (proto.type == OBJECT.OBJECTTYPE.ItemProto)
            {
                int            id  = PeCustomScene.Self.spawnData.GenerateId();
                ItemSpwanPoint isp = new ItemSpwanPoint();
                isp.ID        = id;
                isp.spawnPos  = pos;
                isp.Rotation  = Quaternion.identity;
                isp.Scale     = Vector3.one;
                isp.entityPos = pos;
                isp.Prototype = proto.Id;
                isp.IsTarget  = false;
                isp.Visible   = true;
                isp.isDead    = false;
                isp.CanPickup = true;

                PeCustomScene.Self.CreateAgent(isp);
            }


            return(true);
        }
コード例 #9
0
        public void AddMstDeadAgent(SceneEntityAgent agent)
        {
            MonsterSpawnPoint msp = agent.mstPoint;

            if (msp != null)
            {
                if (agent.spawnArea != null)
                {
                    if (agent.spawnArea.MaxRespawnCount != 0)
                    {
                        mMstDeadAgents.Add(agent);
                    }
                }
                else if (agent.mstPoint.MaxRespawnCount != 0)
                {
                    mMstDeadAgents.Add(agent);
                }
            }
        }
コード例 #10
0
        public void Update()
        {
            // Entity Dead
            for (int i = mMstDeadAgents.Count - 1; i >= 0; i--)
            {
                SceneEntityAgent  agent = mMstDeadAgents[i];
                MonsterSpawnPoint msp   = agent.mstPoint;
                if (msp.UpdateRespawnTime(Time.deltaTime))
                {
                    if (agent.spawnArea != null)
                    {
                        if (agent.spawnArea.MaxRespawnCount != 0)
                        {
                            agent.spawnArea.MaxRespawnCount--;
                        }
                        else
                        {
                            mMstDeadAgents.RemoveAt(i);
                            continue;
                        }
                    }
                    else
                    {
                        if (msp.MaxRespawnCount != 0)
                        {
                            msp.MaxRespawnCount--;
                        }
                        else
                        {
                            mMstDeadAgents.RemoveAt(i);
                            continue;
                        }
                    }

                    msp.isDead = false;
                    agent.Respawn();
                    Debug.Log("The Agent [" + agent.Id.ToString() + "] is respawned");
                    mMstDeadAgents.RemoveAt(i);
                }
            }
        }
コード例 #11
0
ファイル: SpawnPoint.cs プロジェクト: shrubba/planetexplorers
        public List <MonsterSpawnPoint> RandomPoints()
        {
            List <MonsterSpawnPoint> points = new List <MonsterSpawnPoint>();

            List <Bounds> bounds = new List <Bounds>(mInnerBounds);

            try
            {
                for (int i = 0; i < SpawnAmount; i++)
                {
                    if (bounds.Count == 0)
                    {
                        throw new System.Exception("error");
                    }
                    int index = Random.Range(0, bounds.Count - 1);

                    MonsterSpawnPoint sp     = new MonsterSpawnPoint(this);
                    Vector3           center = bounds[index].center;
                    Vector3           size   = bounds[index].size;

                    sp.spawnPos = new Vector3(center.x + (Random.value * 2 - 1) * size.x * 0.3f,
                                              center.y + (Random.value * 2 - 1) * size.y * 0.3f,
                                              center.z + (Random.value * 2 - 1) * size.z * 0.3f);
                    sp.spawnPos = center + Rotation * (sp.spawnPos - center);
                    sp.Rotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
                    sp.Scale    = Vector3.one;
                    sp.bound    = bounds[index];
                    points.Add(sp);

                    bounds.RemoveAt(index);
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.ToString());
            }


            return(points);
        }
コード例 #12
0
        EntityGrp CreateMonsterGroup(SpawnPoint grp_sp, MonsterSpawnPoint[] points, MonsterSpawnArea area)
        {
            int       noid = Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId();
            EntityGrp grp  = EntityMgr.Instance.Create(noid, sMonsterGroupPath, Vector3.zero, Quaternion.identity, Vector3.one) as EntityGrp;


            if (grp == null)
            {
                Debug.LogError("Load Prefab Error");
                return(null);
            }

            grp._protoId = grp_sp.Prototype;
            grp._cntMin  = area.AmountPerSocial;
            grp._cntMax  = area.AmountPerSocial;


            for (int i = 0; i < points.Length; i++)
            {
                MonsterSpawnPoint sp = points[i];

                Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId();
                SceneEntityAgent agent = new SceneEntityAgent(sp, false, area, null);
                agent.ScenarioId = area.ID;
                grp.scenarioId   = area.ID;
                agent.entityGp   = grp;
                sp.agent         = agent;

                AddMstDeadAgent(agent);

                if (!sp.isDead)
                {
                    SceneMan.AddSceneObj(agent);
                }
            }

            return(grp);
        }
コード例 #13
0
ファイル: SpawnPoint.cs プロジェクト: shrubba/planetexplorers
        public override void Deserialize(int version, BinaryReader br)
        {
            base.Deserialize(version, br);

            switch (version)
            {
            case 0x0000001:
            case 0x0000002:
            case 0x0000003:
            case 0x0000004:
            {
                SpawnAmount     = br.ReadInt32();
                AmountPerSocial = br.ReadInt32();
                IsSocial        = br.ReadBoolean();

                int count = br.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    SocialSpawns ss     = new SocialSpawns(br.ReadBoolean(), this);
                    int          subcnt = br.ReadInt32();
                    for (int j = 0; j < subcnt; j++)
                    {
                        MonsterSpawnPoint msp = new MonsterSpawnPoint();
                        msp.Deserialize(version, br);
                        ss.spawnPoints.Add(msp);
                    }

                    mSpawns.Add(ss);
                }
            }
            break;

            default:
                break;
            }
        }
コード例 #14
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;
                }
            }
        }
コード例 #15
0
        /// <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;
            }
        }
コード例 #16
0
        /// <summary>
        /// 删除指定范围内Object
        /// </summary>
        /// <param name="proto">Object类型</param>
        /// <param name="range">删除范围</param>
        /// <returns></returns>
        public static bool RemoveObjects(OBJECT proto, RANGE range)
        {
            if (!proto.isPrototype)
            {
                return(false);
            }

            if (proto.isAnyPrototype)
            {
                SpawnDataSource data = PeCustomScene.Self.spawnData;

                if (proto.type == OBJECT.OBJECTTYPE.MonsterProto)
                {
                    // Monster point
                    _tempSPList.Clear();
                    foreach (var kvp in data.monsters)
                    {
                        if (range.Contains(kvp.Value.entityPos))
                        {
                            _tempSPList.Add(kvp.Value);
                        }
                    }

                    for (int i = 0; i < _tempSPList.Count; i++)
                    {
                        PeCustomScene.Self.RemoveSpawnPoint(_tempSPList[i]);
                    }
                    _tempSPList.Clear();

                    // Monster area
                    foreach (var kvp in data.areas)
                    {
                        for (int i = 0; i < kvp.Value.Spawns.Count; i++)
                        {
                            for (int j = 0; j < kvp.Value.Spawns[i].spawnPoints.Count; j++)
                            {
                                MonsterSpawnPoint msp = kvp.Value.Spawns[i].spawnPoints[j];
                                if (range.Contains(msp.entityPos))
                                {
                                    if (msp.EntityID != -1)
                                    {
                                        CreatureMgr.Instance.Destory(msp.EntityID);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (proto.type == OBJECT.OBJECTTYPE.ItemProto)
                {
                    List <ISceneObjAgent> agents = SceneMan.GetSceneObjs <DragItemAgent>();
                    for (int i = 0; i < agents.Count; i++)
                    {
                        DragItemAgent drag_agent = agents[i] as DragItemAgent;
                        if (range.Contains(drag_agent.position))
                        {
                            DragItemAgent.Destory(drag_agent);
                        }
                    }
                }
            }
            else
            {
                SpawnDataSource data = PeCustomScene.Self.spawnData;
                if (proto.type == OBJECT.OBJECTTYPE.MonsterProto)
                {
                    // Monster point
                    _tempSPList.Clear();
                    foreach (var kvp in data.monsters)
                    {
                        if (kvp.Value.Prototype == proto.Id && range.Contains(kvp.Value.entityPos))
                        {
                            _tempSPList.Add(kvp.Value);
                        }
                    }

                    for (int i = 0; i < _tempSPList.Count; i++)
                    {
                        PeCustomScene.Self.RemoveSpawnPoint(_tempSPList[i]);
                    }
                    _tempSPList.Clear();

                    // Monster area
                    foreach (var kvp in data.areas)
                    {
                        for (int i = 0; i < kvp.Value.Spawns.Count; i++)
                        {
                            for (int j = 0; j < kvp.Value.Spawns[i].spawnPoints.Count; j++)
                            {
                                MonsterSpawnPoint msp = kvp.Value.Spawns[i].spawnPoints[j];
                                if (kvp.Value.Prototype == proto.Id && range.Contains(msp.entityPos))
                                {
                                    if (msp.EntityID != -1)
                                    {
                                        CreatureMgr.Instance.Destory(msp.EntityID);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (proto.type == OBJECT.OBJECTTYPE.ItemProto)
                {
                    List <ISceneObjAgent> agents = SceneMan.GetSceneObjs <DragArticleAgent>();
                    for (int i = 0; i < agents.Count; i++)
                    {
                        DragArticleAgent drag_agent = agents[i] as DragArticleAgent;
                        if (drag_agent.itemDrag.itemObj.protoId == proto.Id && range.Contains(drag_agent.position))
                        {
                            DragItemAgent.Destory(drag_agent);
                        }
                    }
                }
            }

            return(true);
        }
コード例 #17
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);
        }
コード例 #18
0
ファイル: SpawnPoint.cs プロジェクト: shrubba/planetexplorers
        public List <SocialSpawns> RandomPointsForSocials()
        {
            List <SocialSpawns> list   = new List <SocialSpawns>();
            List <Bounds>       bounds = new List <Bounds>(mInnerBounds);

            int curCount = SpawnAmount;

            while (curCount > 0)
            {
                // is Group
                if (curCount >= AmountPerSocial)
                {
                    SocialSpawns ss = new SocialSpawns(true, this);
                    for (int i = 0; i < AmountPerSocial; i++)
                    {
                        int index = Random.Range(0, bounds.Count - 1);

                        MonsterSpawnPoint sp     = new MonsterSpawnPoint(this);
                        Vector3           center = bounds[index].center;
                        Vector3           size   = bounds[index].size;

                        sp.spawnPos = new Vector3(center.x + (Random.value * 2 - 1) * size.x * 0.3f,
                                                  center.y + (Random.value * 2 - 1) * size.y * 0.3f,
                                                  center.z + (Random.value * 2 - 1) * size.z * 0.3f);

                        sp.spawnPos = spawnPos + Rotation * (sp.spawnPos - spawnPos);
                        sp.Rotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
                        sp.Scale    = Vector3.one;
                        sp.bound    = bounds[index];

                        ss.spawnPoints.Add(sp);
                        bounds.RemoveAt(index);
                    }

                    list.Add(ss);
                }
                else
                {
                    SocialSpawns ss = new SocialSpawns(false, null);
                    for (int i = 0; i < curCount; i++)
                    {
                        int index                = Random.Range(0, bounds.Count - 1);
                        MonsterSpawnPoint sp     = new MonsterSpawnPoint(this);
                        Vector3           center = bounds[index].center;
                        Vector3           size   = bounds[index].size;

                        sp.spawnPos = new Vector3(center.x + (Random.value * 2 - 1) * size.x * 0.3f,
                                                  center.y + (Random.value * 2 - 1) * size.y * 0.3f,
                                                  center.z + (Random.value * 2 - 1) * size.z * 0.3f);
                        sp.spawnPos = spawnPos + Rotation * (sp.spawnPos - spawnPos);
                        sp.Rotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
                        sp.Scale    = Vector3.one;
                        sp.bound    = bounds[index];

                        ss.spawnPoints.Add(sp);
                        bounds.RemoveAt(index);
                    }

                    list.Add(ss);
                }

                curCount -= AmountPerSocial;
            }

            return(list);
        }
コード例 #19
0
        /// <summary>
        /// Creates all the agents from data source
        /// </summary>
        void CreateAgents(SpawnDataSource ds)
        {
            foreach (KeyValuePair <int, MonsterSpawnPoint> kvp in ds.monsters)
            {
                SceneEntityAgent agent = _createMstAgent(kvp.Value, true, null, null, !kvp.Value.isDead);
                agent.ScenarioId = kvp.Value.ID;
                kvp.Value.agent  = agent;

                AddMstDeadAgent(agent);
            }


            foreach (KeyValuePair <int, MonsterSpawnArea> kvp in ds.areas)
            {
                for (int i = 0; i < kvp.Value.Spawns.Count; i++)
                {
                    MonsterSpawnArea.SocialSpawns mss = kvp.Value.Spawns[i];

                    if (!mss.isSocial)
                    {
                        for (int j = 0; j < mss.spawnPoints.Count; j++)
                        {
                            MonsterSpawnPoint sp    = mss.spawnPoints[j];
                            SceneEntityAgent  agent = _createMstAgent(sp, true, kvp.Value, null, !sp.isDead);
                            agent.ScenarioId = kvp.Value.ID;
                            sp.agent         = agent;

                            AddMstDeadAgent(agent);
                        }
                    }
                    else
                    {
                        _createMstAgent(mss.centerSP, false, kvp.Value, mss.spawnPoints.ToArray());
                    }
                }
            }

            CreateNpcAgents(ds.npcs);
            CreateDoodadAgents(ds.doodads);


            foreach (KeyValuePair <int, EffectSpwanPoint> kvp in ds.effects)
            {
                SceneStaticEffectAgent agent = SceneStaticEffectAgent.Create(kvp.Value.Prototype, kvp.Value.spawnPos, kvp.Value.Rotation, kvp.Value.Scale);
                agent.ScenarioId = kvp.Value.ID;
                SceneMan.AddSceneObj(agent);
            }

            foreach (KeyValuePair <int, ItemSpwanPoint> kvp in ds.items)
            {
                if (kvp.Value.isNew)
                {
                    DragArticleAgent agent = DragArticleAgent.PutItemByProroId(kvp.Value.Prototype
                                                                               , kvp.Value.spawnPos
                                                                               , kvp.Value.Scale
                                                                               , kvp.Value.Rotation
                                                                               , kvp.Value.CanPickup
                                                                               , kvp.Value.IsTarget);
                    if (agent != null)
                    {
                        agent.ScenarioId    = kvp.Value.ID;
                        kvp.Value.isNew     = false;
                        kvp.Value.ItemObjId = agent.itemDrag.itemObj.instanceId;
                    }
                }
            }
        }
コード例 #20
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)
            {
            }
        }
コード例 #21
0
 public void MonsterDeadEvent(SceneEntityAgent agent, MonsterSpawnPoint msp)
 {
 }
コード例 #22
0
        static bool CheckOnLand(out Vector3 outPutPos, Vector3 curPos, SpawnPoint point, MonsterSpawnArea area)
        {
            outPutPos = curPos;

            MonsterSpawnPoint msp = point as MonsterSpawnPoint;

            if (msp == null || area == null)
            {
                int          h    = 1000;
                RaycastHit[] rchs = Physics.RaycastAll(new Vector3(curPos.x, curPos.y + h, curPos.z), Vector3.down, h * 2, SceneMan.DependenceLayer);

                if (rchs != null && rchs.Length != 0)
                {
                    float      dis = (curPos - rchs[0].point).sqrMagnitude;
                    RaycastHit rch = rchs[0];
                    for (int i = 1; i < rchs.Length; i++)
                    {
                        float _dis = (curPos - rchs[i].point).sqrMagnitude;

                        if (dis > _dis)
                        {
                            rch = rchs[i];
                            //dis = dis;
                        }
                    }


                    outPutPos    = rch.point;
                    outPutPos.y += 1;


                    return(true);
                }
            }
            else
            {
                Vector3[] area_bounds_v = new Vector3[8];
                area_bounds_v[0] = area.spawnPos + area.Rotation * new Vector3(area.Scale.x, area.Scale.y, area.Scale.z) * 0.5f;
                area_bounds_v[1] = area.spawnPos + area.Rotation * new Vector3(-area.Scale.x, area.Scale.y, area.Scale.z) * 0.5f;
                area_bounds_v[2] = area.spawnPos + area.Rotation * new Vector3(area.Scale.x, -area.Scale.y, area.Scale.z) * 0.5f;
                area_bounds_v[3] = area.spawnPos + area.Rotation * new Vector3(-area.Scale.x, -area.Scale.y, area.Scale.z) * 0.5f;
                area_bounds_v[4] = area.spawnPos + area.Rotation * new Vector3(area.Scale.x, area.Scale.y, -area.Scale.z) * 0.5f;
                area_bounds_v[5] = area.spawnPos + area.Rotation * new Vector3(-area.Scale.x, area.Scale.y, -area.Scale.z) * 0.5f;
                area_bounds_v[6] = area.spawnPos + area.Rotation * new Vector3(area.Scale.x, -area.Scale.y, -area.Scale.z) * 0.5f;
                area_bounds_v[7] = area.spawnPos + area.Rotation * new Vector3(-area.Scale.x, -area.Scale.y, -area.Scale.z) * 0.5f;

                float[] area_y = new float[8];
                for (int i = 0; i < 8; i++)
                {
                    area_y[i] = area_bounds_v[i].y;
                }

                float area_y_min = Mathf.Min(area_y) - 4;
                float area_y_max = Mathf.Max(area_y) + 4;

                RaycastHit[] rchs = Physics.RaycastAll(new Vector3(curPos.x, area_y_max, curPos.z), Vector3.down, area_y_max - area_y_min, SceneMan.DependenceLayer);

                if (rchs != null && rchs.Length != 0)
                {
                    float dis = 100000;
                    for (int i = 0; i < rchs.Length; i++)
                    {
                        if (dis > rchs[i].distance)
                        {
                            Vector3 _pos = area.spawnPos + Quaternion.Inverse(area.Rotation) * (rchs[i].point - area.spawnPos);

                            if (msp.bound.Contains(_pos))
                            {
                                outPutPos = rchs[i].point;
                                dis       = rchs[i].distance;
                            }
                            else
                            {
                                if (outPutPos.y > rchs[i].point.y)
                                {
                                    outPutPos.y = rchs[i].point.y + 0.5f;
                                }
                                dis = rchs[i].distance;
                            }
                        }
                    }


                    return(true);
                }
            }

            return(false);
        }
コード例 #23
0
ファイル: SpawnPoint.cs プロジェクト: shrubba/planetexplorers
 public MonsterSpawnPoint(MonsterSpawnPoint sp)
     : base(sp)
 {
     MaxRespawnCount = sp.MaxRespawnCount;
     RespawnTime     = sp.RespawnTime;
 }
コード例 #24
0
        static bool CheckOnSky(out Vector3 outPutPos, Vector3 curPos, SpawnPoint point, MonsterSpawnArea area)
        {
            outPutPos = curPos;

            if (PETools.PE.PointInTerrain(outPutPos) < 0.52f && PETools.PE.PointInWater(outPutPos) < 0.52f)
            {
                return(true);
            }

            MonsterSpawnPoint msp = point as MonsterSpawnPoint;

            if (msp == null || area == null)
            {
                int     ofs = 5;
                Vector3 pos = new Vector3(curPos.x, curPos.y + ofs, curPos.z);

                for (int i = 0; i < ofs * 2; i++)
                {
                    pos.y -= 1;

                    if (PETools.PE.PointInTerrain(pos) < 0.52f && PETools.PE.PointInWater(outPutPos) < 0.52f)
                    {
                        outPutPos = pos;
                        return(true);
                    }
                }
            }
            else
            {
                Vector3[] v      = new Vector3[8];
                Vector3   center = msp.bound.center;
                Vector3   ext    = msp.bound.size;
                v[0] = area.spawnPos + area.Rotation * (area.spawnPos - (center + new Vector3(ext.x, ext.y, ext.z)));
                v[1] = area.spawnPos + area.Rotation * (area.spawnPos - (center + new Vector3(-ext.x, ext.y, ext.z)));
                v[2] = area.spawnPos + area.Rotation * (area.spawnPos - (center + new Vector3(ext.x, -ext.y, ext.z)));
                v[3] = area.spawnPos + area.Rotation * (area.spawnPos - (center + new Vector3(-ext.x, -ext.y, ext.z)));
                v[4] = area.spawnPos + area.Rotation * (area.spawnPos - (center + new Vector3(ext.x, ext.y, -ext.z)));
                v[5] = area.spawnPos + area.Rotation * (area.spawnPos - (center + new Vector3(-ext.x, ext.y, -ext.z)));
                v[6] = area.spawnPos + area.Rotation * (area.spawnPos - (center + new Vector3(ext.x, -ext.y, -ext.z)));
                v[7] = area.spawnPos + area.Rotation * (area.spawnPos - (center + new Vector3(-ext.x, -ext.y, -ext.z)));

                float[] yArr = new float[8];
                for (int i = 0; i < 8; i++)
                {
                    yArr[i] = v[i].y;
                }

                float yMin = Mathf.Min(yArr);
                float yMax = Mathf.Max(yArr);

                //RaycastHit rch;

                int step = 2;
                for (float h = yMax; h > yMin - 1; h -= step)
                {
                    Vector3 pos = new Vector3(outPutPos.x, h, outPutPos.z);
                    if (PETools.PE.PointInTerrain(pos) < 0.52f &&
                        PETools.PE.PointInWater(pos) < 0.52f &&
                        area.PointIn(pos))
                    {
                        outPutPos = pos;
                        return(true);
                    }
                }
            }



            return(false);
        }
コード例 #25
0
ファイル: SpawnPoint.cs プロジェクト: shrubba/planetexplorers
 public SocialSpawns(bool social, MonsterSpawnArea center)
 {
     isSocial    = social;
     spawnPoints = new List <MonsterSpawnPoint>(10);
     centerSP    = center;
 }