Пример #1
0
    IEnumerator CreateMapItemInBuilding(BuildingID buildingId, List <CreatItemInfo> itemInfoList, Vector3 root, int id, int rotation)
    {
        if (PeGameMgr.IsSingleAdventure)
        {
            for (int i = 0; i < itemInfoList.Count; i++)
            {
                //LogManager.Error(itemInfoList[i].mItemId, itemInfoList[i].mPos, itemInfoList[i].mRotation);
                DragArticleAgent.PutItemByProroId(itemInfoList[i].mItemId, itemInfoList[i].mPos, itemInfoList[i].mRotation);
                yield return(null);
            }

            mCreatedNpcBuildingID.Add(buildingId, 0);
        }
        else if (GameConfig.IsMultiMode)
        {
            while (true)
            {
                if (PeCreature.Instance.mainPlayer == null)
                {
                    yield return(null);
                }
                else
                {
                    break;
                }
            }
            //--to do: createBuildingWithItem
            //PlayerNetwork.MainPlayer.CreateBuildingWithItem(buildingId, itemInfoList, root, id, rotation);
            yield return(null);
        }

        yield return(null);
    }
Пример #2
0
    //[Obsolete]
    void RPC_S2C_PutItem(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        int        id    = stream.Read <int>();
        Vector3    pos   = stream.Read <Vector3>();
        Vector3    scale = stream.Read <Vector3>();
        Quaternion rot   = stream.Read <Quaternion>();

        ItemObject item = ItemMgr.Instance.Get(id);

        if (null == item)
        {
            return;
        }

        Drag drag = item.GetCmpt <Drag>();

        if (null == drag)
        {
            return;
        }

//         if (item.protoId == 1339)
//             KillNPC.ashBox_inScene++;


        /*DragArticleAgent dragItem = */ DragArticleAgent.Create(drag, pos, scale, rot, id);
    }
Пример #3
0
    protected override void OnPEDestroy()
    {
        StopAllCoroutines();

        DragArticleAgent.Destory(Id);

        if (null != _flagPos)
        {
            PeMap.LabelMgr.Instance.Remove(_flagPos);
            _flagPos = null;
        }

        int index = PeMap.MaskTile.Mgr.Instance.GetMapIndex(transform.position);

        PeMap.MaskTile mt = PeMap.MaskTile.Mgr.Instance.Get(index);
        if (null != mt)
        {
            mt.forceGroup = -1;
            PeMap.MaskTile.Mgr.Instance.Add(index, mt);
        }

        if (null == Runner)
        {
            return;
        }

        Destroy(Runner.gameObject);
    }
Пример #4
0
    void RPC_S2C_Plant_PutOut(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        Vector3    pos        = stream.Read <Vector3>();
        Quaternion rot        = stream.Read <Quaternion>();
        Vector3    scale      = stream.Read <Vector3>();
        int        instanceId = stream.Read <int>();

        ItemObject itemobj = ItemMgr.Instance.Get(instanceId);

        DragArticleAgent dragItem = DragArticleAgent.Create(itemobj.GetCmpt <Drag>(), pos, scale, rot, instanceId);

        FarmPlantLogic plant = dragItem.itemLogic as FarmPlantLogic;

        plant.InitInMultiMode();
        stream.Read <FarmPlantLogic>();
        plant.UpdateInMultiMode();

        //DragItem item = new DragItem(objID);

        //item.position = plantPos;
        //item.rotation = transform.rotation;
        //item.itemScript = null;
        ////item.DependType = dependType;
        //item.network = this;
        //DragItem.Mgr.Instance.Add(item);
    }
Пример #5
0
    void RPC_S2C_CLN_PlantPutOut(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        Vector3    pos   = stream.Read <Vector3>();
        Quaternion rot   = stream.Read <Quaternion>();
        int        objID = stream.Read <int>();

        /*byte type = */ stream.Read <byte>();

        //FarmPlantLogic mPlant = FarmManager.Instance.GetPlantByItemObjID (objID);
        //if(null == mPlant)
        //{
        //    mPlant = FarmManager.Instance.CreatePlant(objID, PlantInfo.GetPlantInfoByItemId(m_ItemID).mTypeID, pos);
        //    mPlant.mTerrianType = type;
        //    mPlant.UpdateGrowRate(0);
        //}
        //mPlant.mPos = pos;

        //DragArticleAgent item = DragArticleAgent.PutItemByProroId(objID, pos, transform.rotation);

        ItemObject itemobj = ItemMgr.Instance.Get(objID);

        DragArticleAgent dragItem = DragArticleAgent.Create(itemobj.GetCmpt <Drag>(), pos, Vector3.one, rot, objID);

        FarmPlantLogic plant = dragItem.itemLogic as FarmPlantLogic;

        plant.InitInMultiMode();
        stream.Read <FarmPlantLogic>();
        plant.UpdateInMultiMode();
    }
Пример #6
0
//	void RPC_S2C_CLN_SetGuardPos(uLink.BitStream stream, uLink.NetworkMessageInfo info)
//	{
//        //--to do: wait
//        Vector3 guardPos = stream.Read<Vector3>();
//        //int playID = stream.Read<int>();
//        //if (playID == PlayerFactory.mMainPlayer.OwnerView.viewID.id)
//        //{
//            CSCreator creator = CSMain.GetCreator(CSConst.ciDefMgCamp);
//            if (creator != null)
//            {
//                CSPersonnel[] personnels = creator.GetNpcs();
//                foreach (CSPersonnel csp in personnels)
//                {
//                    if (csp != null && csp.m_Npc != null)
//                    {
//                        if (Id == csp.m_Npc.Id)
//                        {
//                            csp.SetGuardAttr(guardPos);
//                        }
//                    }
//                }
//            }
//        //}
//	}

    void RPC_S2C_CLN_PlantGetBack(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        int objId = stream.Read <int> ();

        if (objId != -1)
        {
            FarmManager.Instance.RemovePlant(objId);
            DragArticleAgent.Destory(objId);
            ItemMgr.Instance.DestroyItem(objId);
        }
        else
        {
            FarmPlantLogic plant = stream.Read <FarmPlantLogic>();

            CSMgCreator creator = MultiColonyManager.GetCreator(TeamId);
            if (creator == null || creator.Assembly == null)
            {
                return;
            }
            CSFarm farm = creator.Assembly.Farm;
            if (farm == null)
            {
                return;
            }
            farm.RestoreWateringPlant(plant);
        }
    }
Пример #7
0
    void RPC_S2C_Plant_GetBack(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        int objId = stream.Read <int> ();

        FarmManager.Instance.RemovePlant(objId);
        DragArticleAgent.Destory(objId);
        //ItemMgr.Instance.DestroyItem(objId);
    }
Пример #8
0
    protected override void OnPEDestroy()
    {
        PlayerNetwork.OnTeamChangedEventHandler -= OnResetFlag;
        PlayerNetwork.OnLimitBoundsDel(Id);
        base.OnPEDestroy();

        DragArticleAgent.Destory(Id);

        RemoveFlag();
    }
Пример #9
0
    void RPC_S2C_Plant_Clear(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        int            objId = stream.Read <int> ();
        FarmPlantLogic plant = FarmManager.Instance.GetPlantByItemObjID(objId);

        if (plant != null)
        {
            FarmManager.Instance.RemovePlant(objId);
            DragArticleAgent.Destory(objId);
            //ItemMgr.Instance.DestroyItem(objId);
        }
    }
Пример #10
0
        void RemoveFromDragItemMgr(GameObject obj)
        {
            ItemScript script = obj.GetComponent <ItemScript>();

            if (null == script)
            {
                Debug.LogError("has no itemscript");
                return;
            }

            DragArticleAgent.Destory(script.id);
        }
Пример #11
0
    public static DragArticleAgent PutItemByProroId(int protoId, Vector3 pos, Vector3 scl, Quaternion rot, bool pickable = true, bool attackable = false)
    {
        ItemAsset.Drag drag = CreateItemDrag(protoId);

        if (null == drag)
        {
            Debug.LogError("item has no drag, protoId:" + protoId);
            return(null);
        }

        DragArticleAgent item = DragArticleAgent.Create(drag, pos, scl, rot);

        return(item);
    }
Пример #12
0
    protected override void OnPEDestroy()
    {
        StopAllCoroutines();

        PlayerNetwork.OnTeamChangedEventHandler -= InitMapInfo;
        RemoveMapInfo();

        DragArticleAgent.Destory(Id);

        if (null != Runner)
        {
            Runner.InitNetworkLayer(null);
            Destroy(Runner.gameObject);
        }
    }
Пример #13
0
    protected void PutDown(bool isCreation = false)
    {
        ItemAsset.Drag dragging = itemDragging;

        //some item stack count > 1, seed eg.
        if (itemDragging.itemObj.stackCount > 1)
        {
            ItemAsset.ItemObject itemobj = ItemAsset.ItemMgr.Instance.CreateItem(itemDragging.itemObj.protoId);
            dragging = itemobj.GetCmpt <ItemAsset.Drag>();
        }

        /*DragArticleAgent agent = */
        DragArticleAgent.Create(dragging, transform.position, transform.localScale, transform.rotation, SceneMan.InvalidID, null, isCreation);

        RemoveFromBag();
    }
Пример #14
0
    //[Obsolete]
    void RPC_S2C_Plant_FarmInfo(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        byte[] data = stream.Read <byte[]> ();
        List <FarmPlantInitData> initList = FarmManager.Instance.ImportPlantData(data);

        foreach (FarmPlantInitData plantData in initList)
        {
            ItemObject       itemObj  = ItemMgr.Instance.Get(plantData.mPlantInstanceId);
            DragArticleAgent dragItem = DragArticleAgent.Create(itemObj.GetCmpt <Drag>(), plantData.mPos, Vector3.one, plantData.mRot, plantData.mPlantInstanceId);

            FarmPlantLogic plant = dragItem.itemLogic as FarmPlantLogic;
            plant.InitDataFromPlant(plantData);
            FarmManager.Instance.AddPlant(plant);
            plant.UpdateInMultiMode();
        }
    }
Пример #15
0
    public static DragArticleAgent Create(ItemAsset.Drag drag, Vector3 pos, Vector3 scl, Quaternion rot, int id = SceneMan.InvalidID, NetworkInterface net = null, bool isCreation = false)
    {
        DragArticleAgent agent;

        if (isCreation)
        {
            agent = new DragCreationAgent(drag, pos, scl, rot, id, net);
        }
        else
        {
            agent = new DragArticleAgent(drag, pos, scl, rot, id, net);
        }

        agent.Create();
        SceneMan.AddSceneObj(agent);
        return(agent);
    }
Пример #16
0
    private FarmPlantLogic _plant(ItemObject io, Vector3 pos, int index)
    {
        //PlantInfo info = PlantInfo.GetPlantInfoByItemId(io.protoId);
//		Vector3 new_pos = new Vector3(pos.x, pos.y, pos.z)
        DragArticleAgent dragItem = DragArticleAgent.PutItemByProroId(io.protoId, pos, Quaternion.identity);

        //FarmManager.Instance.CreatePlant(dragItem.itemInstanceId, info.mTypeID, pos);
        io.DecreaseStackCount(1);
        if (io.GetCount() <= 0)
        {
            ItemMgr.Instance.DestroyItem(io.instanceId);

            SetPlantSeed(index, null);
        }

        // Event
        ExcuteEvent(CSConst.eetFarm_OnPlant, index);
        return(dragItem.itemLogic as FarmPlantLogic);
    }
Пример #17
0
    protected override void RPC_S2C_InitData(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        ItemObject item = stream.Read <ItemObject>();
        float      rotY = stream.Read <float>();

        rot = transform.rotation = Quaternion.Euler(0, rotY, 0);

        //InitData parameter member
        //and add data to creator
        _ColonyObj._RecordData.m_Position = transform.position;//network's position
        _ColonyObj._RecordData.ItemID     = ExternId;
        _ColonyObj._RecordData.ID         = Id;

        MultiColonyManager.Instance.AddDataToCreator(this, TeamId);
//        if(Application.isEditor)
//            Debug.Log("<color=red>Get colony InitData!</color>");

        if (null == item)
        {
            return;
        }

        Drag drag = item.GetCmpt <Drag>();

        if (null == drag)
        {
            return;
        }

        DragArticleAgent dragItem = DragArticleAgent.Create(drag, transform.position, transform.localScale, transform.rotation, Id, this);

        if (dragItem.itemLogic != null)
        {
            CSBuildingLogic csbl = dragItem.itemLogic as CSBuildingLogic;
            if (csbl != null)
            {
                csbl.InitInMultiMode(m_Entity, _ownerId);
                OnTeamChange();
                _entity = Pathea.EntityMgr.Instance.Get(Id);
                OnSpawned(csbl.gameObject);
            }
        }
    }
Пример #18
0
    void RPC_SO_InitData(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        ItemAsset.ItemObject itemObj = stream.Read <ItemAsset.ItemObject>();
        transform.position = stream.Read <Vector3>();
        transform.rotation = stream.Read <Quaternion>();

        if (null == itemObj)
        {
            return;
        }

        ItemAsset.Drag drag = itemObj.GetCmpt <ItemAsset.Drag>();
        if (null == drag)
        {
            return;
        }

        DragArticleAgent item = DragArticleAgent.Create(drag, transform.position, transform.localScale, transform.rotation, Id, this);

        if (item.itemLogic != null)
        {
            DragItemLogicFlag flag = item.itemLogic as DragItemLogicFlag;
            if (flag != null)
            {
                _entity = Pathea.EntityMgr.Instance.Get(Id);
                OnSpawned(flag.gameObject);
            }
        }

        if (null == _flagPos)
        {
            _flagPos            = new PeMap.StaticPoint();
            _flagPos.icon       = PeMap.MapIcon.FlagIcon;
            _flagPos.fastTravel = true;
            _flagPos.text       = "Flag_" + Id;
            //_flagPos.campId = TeamId;
            _flagPos.position = transform.position;

            PeMap.LabelMgr.Instance.Add(_flagPos);
        }

        StartCoroutine(RefreshFlag());
    }
    public void OnClear()
    {
        if (!GameConfig.IsMultiMode)
        {
            FarmManager.Instance.RemovePlant(itemObjectId);

            //ItemMgr.Instance.DestroyItem(mItemObj.instanceId);
            DragArticleAgent.Destory(id);
        }
        else
        {
            if (null != PlayerNetwork.mainPlayer)
            {
                PlayerNetwork.mainPlayer.RPCServer(EPacketType.PT_InGame_Plant_Clear, plant.mPlantInstanceId);
            }
        }
        HideItemOpGui();
        //UpdateCmdList();
    }
Пример #20
0
    void RPC_SO_InitData(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        ItemAsset.ItemObject itemObj = stream.Read <ItemAsset.ItemObject>();
        _pos = transform.position = stream.Read <Vector3>();
        rot  = transform.rotation = stream.Read <Quaternion>();

        if (null == itemObj)
        {
            return;
        }

        ItemAsset.Drag drag = itemObj.GetCmpt <ItemAsset.Drag>();
        if (null == drag)
        {
            return;
        }

        DragArticleAgent item = DragArticleAgent.Create(drag, _pos, transform.localScale, rot, Id, this);

        if (item.itemLogic != null)
        {
            DragItemLogicFlag flag = item.itemLogic as DragItemLogicFlag;
            if (flag != null)
            {
                OnSpawned(flag.gameObject);

                Pathea.PeEntity FlagEntity = flag.gameObject.GetComponent <Pathea.PeEntity>();
                if (null != FlagEntity)
                {
                    Pathea.NetCmpt net = FlagEntity.GetCmpt <Pathea.NetCmpt>();
                    if (null == net)
                    {
                        net = FlagEntity.Add <Pathea.NetCmpt>();
                    }

                    net.network = this;
                }
            }
        }

        OnResetFlag();
    }
Пример #21
0
    private void RPC_S2C_InitData(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        ItemAsset.ItemObject item = stream.Read <ItemAsset.ItemObject>();
        _pos     = transform.position = stream.Read <Vector3>();
        rot      = transform.rotation = stream.Read <Quaternion>();
        HP       = stream.Read <float>();
        MaxHP    = stream.Read <float>();
        Fuel     = stream.Read <float>();
        MaxFuel  = stream.Read <float>();
        authId   = stream.Read <int>();
        _ownerId = stream.Read <int>();

        if (null == item)
        {
            Debug.LogWarning("CreationNetwork RPC_S2C_InitData null item.");
            return;
        }

        DragArticleAgent agent = DragArticleAgent.Create(DragArticleAgent.CreateItemDrag(item.protoId), _pos, Vector3.one, rot, _id, this, true);

        if (agent != null && null != agent.itemLogic && null != agent.itemLogic.gameObject)
        {
            OnSpawned(agent.itemLogic.gameObject);
            _entity = agent.itemLogic.gameObject.GetComponent <WhiteCat.CreationSkEntity>();
            if (_entity != null)
            {
                NetCmpt net = _entity.GetComponent <NetCmpt>();
                if (null == net)
                {
                    net = _entity.gameObject.AddComponent <NetCmpt>();
                }
                net.network = this;
            }
        }
        else
        {
            Debug.LogWarningFormat("CreationNetwork RPC_S2C_InitData invalide agent:{0}", item.protoId);
        }

        OnSkAttrInitEvent += SendBaseAttr;
        StartCoroutine(SyncMove());
    }
Пример #22
0
    protected override void OnPEDestroy()
    {
        StopAllCoroutines();

        switch (ExternId)
        {
        case ColonyIDInfo.COLONY_ASSEMBLY:
        {
            PlayerNetwork.OnTeamChangedEventHandler -= OnTeamChange;
            PlayerNetwork.OnLimitBoundsDel(Id);
        }
        break;
        }

        DragArticleAgent.Destory(Id);

        if (null != Runner)
        {
            Destroy(Runner.gameObject);
        }
    }
Пример #23
0
    // Destory itsself
    public virtual void DestroySelf()
    {
        Debug.Log("Delete " + Name + "successfully");
        m_MgCreator.RemoveLogic(ID);
        DragArticleAgent.Destory(logicId);
        EntityMgr.Instance.Remove(PeEntityId);

        if (m_CSRepair != null)
        {
            GameObject.Destroy(m_CSRepair);
        }
        if (m_CSDelete != null)
        {
            GameObject.Destroy(m_CSDelete);
        }

        if (m_Object != null)
        {
            GameObject.Destroy(m_Object);
        }
        ExcuteEvent(CSConst.eetDestroy);
    }
Пример #24
0
    void OnDeleteBtn()
    {
        if (m_Plant == null)
        {
            return;
        }

        if (FarmManager.Instance != null)
        {
            FarmManager.Instance.RemovePlant(m_Plant.mPlantInstanceId);
        }

        DragArticleAgent.Destory(m_Plant.mPlantInstanceId);

        //ItemMgr.Instance.DestroyItem(m_Plant.mInstanceId);

        //GameObject.Destroy(gameObject);

        if (OnDestroySelf != null)
        {
            OnDestroySelf(this);
        }
    }
Пример #25
0
    IEnumerator WaitForMainPlayer()
    {
        while (null == PlayerNetwork.mainPlayer)
        {
            yield return(null);
        }

        if (hasOwnerAuth)
        {
            if (-1 == _missionId && -1 == _targetId)
            {
                ItemAsset.ItemObject item = ItemAsset.ItemMgr.Instance.Get(Id);
                if (null == item)
                {
                    yield break;
                }

                ItemAsset.Drag drag = item.GetCmpt <ItemAsset.Drag>();
                if (null == drag)
                {
                    yield break;
                }

                DragArticleAgent.Create(drag, _pos, Vector3.one, Quaternion.identity, Id, this);
                StartCoroutine(WaitForActivate());
            }
            else
            {
                SceneEntityCreator.self.AddMissionPoint(_missionId, _targetId, Id);
                StartCoroutine(WaitForActivate());
            }
        }
        else
        {
            RPCServer(EPacketType.PT_InGame_TDInitData);
        }
    }
Пример #26
0
 void TowerDestroy()
 {
     ItemAsset.ItemMgr.Instance.DestroyItem(itemObjectId);
     DragArticleAgent.Destory(id);
 }
        /// <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;
            }
        }
Пример #28
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);
        }
Пример #29
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);
        }
Пример #30
0
 public void DestroySelf()
 {
     DragArticleAgent.Destory(id);
 }