コード例 #1
0
ファイル: KNpc.cs プロジェクト: zuojiashun/src
    public int SetDisplayData(uint uID)
    {
        IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

        table.NpcDataBase npctable = GameTableManager.Instance.GetTableItem <table.NpcDataBase>(uID);
        if (npctable == null)
        {
            return(0);
        }

        GameCmd.t_MapNpcDataPos npcdata = new GameCmd.t_MapNpcDataPos();
        npcdata.mapnpcdata         = new GameCmd.t_MapNpcData();
        npcdata.mapnpcdata.npcdata = new GameCmd.t_NpcData();

        npcdata.mapnpcdata.npcdata.dwBaseID = uID;

        npcdata.mapnpcdata.npcdata.dwTempID  = this.m_dwID;
        npcdata.mapnpcdata.npcdata.movespeed = 600;

        EntityCreateData data = RoleUtil.BuildCreateEntityData(EntityType.EntityType_NPC, npcdata, 0);

        IEntity npc = es.CreateEntity(EntityType.EntityType_NPC, data, true) as INPC;

        //ISkillPart skillPart = npc.GetPart(EntityPart.Skill) as ISkillPart;
        //skillPart.ReqNpcUseSkill(208);

        m_pEntity = npc;

        return(1);
    }
コード例 #2
0
ファイル: HomeScene.cs プロジェクト: zuojiashun/src
    //-------------------------------------------------------------------------------------------------------

    /**
     * @brief 添加玩家(木偶)
     * @param strName 名称
     * @param nJob 职业
     * @param nSex 性别
     * @param propList 外观属性
     * @param bMainHost 是否是主角对象
     */
    public IPuppet AddPuppet(string strName, int nJob, int nSex, EntityViewProp[] propList, bool bMainHost = false)
    {
        EntityCreateData data = new EntityCreateData();

        data.ID      = ++m_uEntityID;
        data.strName = strName;

        int speed = 0;

        Client.IPlayer player = ClientGlobal.Instance().MainPlayer;
        if (player != null)
        {
            speed = player.GetProp((int)WorldObjProp.MoveSpeed);
        }


        data.PropList = new EntityAttr[(int)PuppetProp.End - (int)EntityProp.Begin];
        int index = 0;

        data.PropList[index++] = new EntityAttr((int)PuppetProp.Job, nJob);
        data.PropList[index++] = new EntityAttr((int)PuppetProp.Sex, nSex);
        data.PropList[index++] = new EntityAttr((int)EntityProp.BaseID, 0);
        data.PropList[index++] = new EntityAttr((int)WorldObjProp.MoveSpeed, speed);
        data.ViewList          = propList;

        IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

        if (es == null)
        {
            Engine.Utility.Log.Error("严重错误:EntitySystem is null!");
            return(null);
        }

        IPuppet entity = es.CreateEntity(EntityType.EntityType_Puppet, data) as IPuppet;

        if (entity == null)
        {
            Engine.Utility.Log.Error("AddEntity:创建家园对象失败!");
            return(null);
        }

        if (bMainHost)
        {
            IControllerSystem cs = ClientGlobal.Instance().GetControllerSystem();
            if (cs == null)
            {
                return(null);
            }

            cs.GetActiveCtrl().SetHost(entity);
            CameraFollow.Instance.target = entity;
        }

        m_dicPuppet.Add((int)entity.GetID(), entity);

        return(entity);
    }
コード例 #3
0
ファイル: EntityCreator.cs プロジェクト: zuojiashun/src
        private void CreateRobot(GameCmd.t_MapNpcDataPos npcdata, uint job)
        {
            Profiler.BeginSample("CreateRobot");
            IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

            if (es == null)
            {
                Engine.Utility.Log.Error("严重错误:EntitySystem is null!");
                return;
            }

            Vector3 pos = new Vector3(npcdata.cur_pos.x * 0.01f, 0, -npcdata.cur_pos.y * 0.01f); // 服务器到客户端坐标转换

            npcdata.mapnpcdata.npcdata.job = job;

            EntityCreateData data  = RoleUtil.BuildCreateEntityData(EntityType.EntityTYpe_Robot, npcdata, 0);
            IRobot           robot = es.FindRobot(npcdata.mapnpcdata.npcdata.dwTempID);

            if (robot != null)
            {
                robot.UpdateProp(data);
            }
            else
            {
                robot = es.CreateEntity(EntityType.EntityTYpe_Robot, data, !m_bDelayLoad) as IRobot;
                // 发送事件 CreateEntity
                if (robot != null)
                {
                    PlayAni anim_param = new PlayAni();
                    anim_param.strAcionName = EntityAction.Stand;
                    anim_param.fSpeed       = 1;
                    anim_param.nStartFrame  = 0;
                    anim_param.nLoop        = -1;
                    anim_param.fBlendTime   = 0.2f;
                    robot.SendMessage(EntityMessage.EntityCommand_PlayAni, anim_param);

                    if (!string.IsNullOrEmpty(npcdata.mapnpcdata.npcdata.name) && !Application.isEditor)
                    {
                        robot.SendMessage(EntityMessage.EntityCommond_SetName, npcdata.mapnpcdata.npcdata.name);
                    }
                    else
                    {
                        string strName = string.Format("{0}(AI)", npcdata.mapnpcdata.npcdata.name);
                        robot.SendMessage(EntityMessage.EntityCommond_SetName, npcdata.mapnpcdata.npcdata.name);
                    }
                }
            }

            Engine.Utility.Log.Info("创建机器人 {0} pos {1}", robot.GetID(), pos);

            robot.SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos);
            Vector3 rot = GameUtil.S2CDirection(npcdata.mapnpcdata.npcdata.byDirect);

            robot.SendMessage(EntityMessage.EntityCommand_SetRotate, (object)rot);
            Profiler.EndSample();
        }
コード例 #4
0
ファイル: EntityCreator.cs プロジェクト: zuojiashun/src
        public IBox AddBox(t_MapObjectData BoxData, uint nlefttime)
        {
            if (BoxData == null)
            {
                return(null);
            }
            //Engine.Utility.Log.Info("创建box{0}", BoxData.dwObjectID);
            IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

            if (es == null)
            {
                Engine.Utility.Log.Error("严重错误:EntitySystem is null!");
                return(null);
            }

//            if (es.FindBox(BoxData.qwThisID) == null)
            {
                //AddPetEntity(petdata);
                // 创建box
                //MapVector2 mapPos = MapVector2.FromCoordinate(BoxData.x, BoxData.y);
                Vector3 pos = new Vector3(BoxData.cur_pos.x * 0.01f, 0, -BoxData.cur_pos.y * 0.01f); // 服务器到客户端坐标转换

                EntityCreateData data = RoleUtil.BuildCreateEntityData(EntityType.EntityType_Box, BoxData);
                IBox             box  = es.FindBox(BoxData.qwThisID);
                if (box != null)
                {
                    box.UpdateProp(data);
                }
                else
                {
                    box = es.CreateEntity(EntityType.EntityType_Box, data, true) as IBox;
                }

                box.SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos);
                box.AddTrigger(new BoxOnTrigger());
                return(box);
            }
            return(null);
        }
コード例 #5
0
ファイル: EntityCreator.cs プロジェクト: zuojiashun/src
        IPet AddPetEntity(PetData petdata)
        {
            IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

            if (es == null)
            {
                Engine.Utility.Log.Error("严重错误:EntitySystem is null!");
                return(null);
            }
            EntityCreateData entityData = new EntityCreateData();

            entityData.ID       = petdata.id;
            entityData.PropList = new EntityAttr[(int)PetProp.End - (int)EntityProp.Begin];
            RoleUtil.BuildPetPropListByPetData(petdata, ref entityData.PropList);
            IPet pet = es.CreateEntity(EntityType.EntityType_Pet, entityData) as IPet;

            if (pet != null)
            {
                pet.SetExtraData(petdata);
                return(pet);
            }

            return(null);
        }
コード例 #6
0
ファイル: HomeScene.cs プロジェクト: zuojiashun/src
    //添加实体
    public IEntity AddEntity(string strName, EntityType type, uint nBaseID, int nState)
    {
        EntityCreateData data = BuildCreateEntityData(type, nBaseID, nState);

        if (data == null)
        {
            return(null);
        }

        data.strName = strName;

        IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

        if (es == null)
        {
            Engine.Utility.Log.Error("严重错误:EntitySystem is null!");
            return(null);
        }

        IEntity entity = es.CreateEntity(type, data);

        if (entity == null)
        {
            Engine.Utility.Log.Error("AddEntity:创建家园对象失败!");
            return(null);
        }

        if (entity.GetEntityType() == EntityType.EntityType_Animal)
        {
            m_AnimalManager.AddAnimal(entity as IAnimal);
        }

        m_dicEntity.Add((int)entity.GetID(), entity);

        return(entity);
    }
コード例 #7
0
ファイル: EntityCreator.cs プロジェクト: zuojiashun/src
        //------------------------------------------------------------------------------------------------

        private void CreateNPC(GameCmd.t_MapNpcDataPos npcdata, uint master_id)
        {
            Profiler.BeginSample("CreateNPC");
            IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

            if (es == null)
            {
                Engine.Utility.Log.Error("严重错误:EntitySystem is null!");
                return;
            }

            //MapVector2 mapPos = MapVector2.FromCoordinate(npcdata.cur_pos.x * 0.01f, npcdata.cur_pos*0.01f);
            Vector3 pos = new Vector3(npcdata.cur_pos.x * 0.01f, 0, -npcdata.cur_pos.y * 0.01f); // 服务器到客户端坐标转换


            EntityCreateData data = RoleUtil.BuildCreateEntityData(EntityType.EntityType_NPC, npcdata, master_id);
            INPC             npc  = es.FindNPC(npcdata.mapnpcdata.npcdata.dwTempID);

            if (npc != null)
            {
                npc.UpdateProp(data);
                NpcAscription.Instance.UpdateBelong(npc, npcdata.mapnpcdata.npcdata.owernuserid, npcdata.mapnpcdata.npcdata.owernteamid, npcdata.mapnpcdata.npcdata.owernclanid, npcdata.mapnpcdata.npcdata.ownername);
            }
            else
            {
                npc = es.CreateEntity(EntityType.EntityType_NPC, data, !m_bDelayLoad) as INPC;
                // 发送事件 CreateEntity
                if (npc != null)
                {
                    NpcAscription.Instance.UpdateBelong(npc, npcdata.mapnpcdata.npcdata.owernuserid, npcdata.mapnpcdata.npcdata.owernteamid, npcdata.mapnpcdata.npcdata.owernclanid, npcdata.mapnpcdata.npcdata.ownername);
                    table.NpcDataBase npctable = GameTableManager.Instance.GetTableItem <table.NpcDataBase>((uint)npcdata.mapnpcdata.npcdata.dwBaseID);
                    if (npctable != null)
                    {
                        //Debug.LogError("********** npctable.dwID = " + npctable.dwID);
                        if (npcdata.mapnpcdata.npcdata.arenanpctype == ArenaNpcType.ArenaNpcType_Player)//离线的真实玩家名字,用服务器的
                        {
                            npc.SendMessage(EntityMessage.EntityCommond_SetName, npcdata.mapnpcdata.npcdata.name);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(npcdata.mapnpcdata.npcdata.name))
                            {
                                npc.SendMessage(EntityMessage.EntityCommond_SetName, npctable.strName);
                            }
                        }
                        if (npctable.dwType == (uint)GameCmd.enumNpcType.NPC_TYPE_TRANSFER)//传送阵
                        {
                            EntityOnTrigger callback = new EntityOnTrigger();
                            npc.SetCallback(callback);
                        }
                    }
                    if (npc != null)
                    {
                        PlayAni anim_param = new PlayAni();
                        anim_param.strAcionName = EntityAction.Stand;
                        anim_param.fSpeed       = 1;
                        anim_param.nStartFrame  = 0;
                        anim_param.nLoop        = -1;
                        anim_param.fBlendTime   = 0.2f;
                        npc.SendMessage(EntityMessage.EntityCommand_PlayAni, anim_param);
                    }
                }
            }
            if (npc != null)
            {
                npc.SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos);
                Vector3 rot = GameUtil.S2CDirection(npcdata.mapnpcdata.npcdata.byDirect);
                npc.SendMessage(EntityMessage.EntityCommand_SetRotate, (object)rot);
                IBuffPart buffpart = npc.GetPart(EntityPart.Buff) as IBuffPart;
                if (buffpart != null)
                {
                    buffpart.ReceiveBuffList(npcdata.mapnpcdata.statelist.data);
                }
            }

            Profiler.EndSample();
        }
コード例 #8
0
ファイル: EntityCreator.cs プロジェクト: zuojiashun/src
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
        private Client.IPlayer CreatePlayer(GameCmd.t_MapUserData userData)
        {
            IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

            if (es == null)
            {
                Engine.Utility.Log.Error("严重错误:EntitySystem is null!");
                return(null);
            }

            EntityCreateData data   = RoleUtil.BuildCreateEntityData(EntityType.EntityType_Player, userData);
            IPlayer          player = es.FindPlayer(userData.userdata.dwUserID);

            if (player != null)
            {
                uint clanIdLow  = (uint)player.GetProp((int)CreatureProp.ClanIdLow);
                uint clanIdHigh = (uint)player.GetProp((int)CreatureProp.ClanIdHigh);
                uint clanid     = (clanIdHigh << 16) | clanIdLow;

                //
                //uint clanid = (uint)player.GetProp((int)CreatureProp.ClanId);


                //玩家死亡 服务器会通过这里刷新 所以这里更新下玩家血条
                if (userData.userdata.curhp <= 0)
                {
                    stPropUpdate prop = new stPropUpdate();
                    prop.uid        = player.GetUID();
                    prop.nPropIndex = (int)CreatureProp.Hp;
                    prop.oldValue   = player.GetProp((int)CreatureProp.Hp);

                    player.UpdateProp(data);

                    prop.newValue = player.GetProp((int)CreatureProp.Hp);

                    Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.ENTITYSYSTEM_HPUPDATE, prop);
                }
                else
                {
                    stPropUpdate prop = new stPropUpdate();
                    prop.uid        = player.GetUID();
                    prop.nPropIndex = (int)CreatureProp.Hp;
                    prop.oldValue   = player.GetProp((int)CreatureProp.Hp);

                    player.UpdateProp(data);

                    prop.newValue = player.GetProp((int)CreatureProp.Hp);
                    if (prop.oldValue < prop.newValue)
                    {
                        Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.ENTITYSYSTEM_HPUPDATE, prop);
                    }
                }

                if (userData.userdata.clan_id != clanid)
                {
                    Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.CLANREFRESHID,
                                                                        new Client.stClanUpdate()
                    {
                        uid = player.GetUID(), clanId = userData.userdata.clan_id
                    });
                }
            }
            else
            {
                if (UserData.IsMainRoleID(userData.userdata.dwUserID))
                {
                    data.nLayer      = LayerMask.NameToLayer("MainPlayer");
                    data.bMainPlayer = true; // 设置主角标识
                    player           = es.CreateEntity(EntityType.EntityType_Player, data, true) as IPlayer;
                    if (player == null)
                    {
                        Engine.Utility.Log.Error("CreatePlayer:创建角色失败!");
                        return(null);
                    }
                    Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.ENTITYSYSTEM_MAINPLAYERCREATE,
                                                                        new Client.stCreateEntity()
                    {
                        uid = userData.userdata.dwUserID
                    });

                    // 设置控制对象
                    Client.IControllerSystem cs = ClientGlobal.Instance().GetControllerSystem();
                    if (cs != null)
                    {
                        cs.GetActiveCtrl().SetHost(player);
                    }

                    // 补丁 服务器没有金钱没有放在角色属性上
                    {
                        player.SetProp((int)PlayerProp.Money, (int)UserData.Money);
                        player.SetProp((int)PlayerProp.Coupon, (int)UserData.Coupon);
                        player.SetProp((int)PlayerProp.Cold, (int)UserData.Cold);
                        player.SetProp((int)PlayerProp.Reputation, (int)UserData.Reputation);
                        player.SetProp((int)PlayerProp.Score, (int)UserData.Score);
                        player.SetProp((int)PlayerProp.CampCoin, (int)UserData.CampCoin);
                        player.SetProp((int)PlayerProp.AchievePoint, (int)UserData.AchievePoint);
                        player.SetProp((int)PlayerProp.ShouLieScore, (int)UserData.ShouLieScore);
                        player.SetProp((int)PlayerProp.FishingMoney, (int)UserData.FishingMoney);
                        player.SetProp((int)PlayerProp.YinLiang, (int)UserData.YinLiang);
                    }

                    // 设置主像机参数
                    SetupMainCamera(player);

                    //玩家成功登陆回调
                    Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.PLAYER_LOGIN_SUCCESS, null);

                    //Client.stCreateEntity createEntity = new Client.stCreateEntity();
                    //createEntity.uid = player.GetUID();
                    //Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.ENTITYSYSTEM_CREATEENTITY, createEntity);
                    //set hp
                    DataManager.Manager <UIPanelManager>().SendMsg(PanelID.MainPanel, UIMsgID.eSetRoleProperty, player);

                    //预加载资源
                    //  PreLoadResource(player.GetProp((int)PlayerProp.Job));
                }
                else
                {
                    //Profiler.BeginSample("CreatePlayer");
                    player = es.CreateEntity(EntityType.EntityType_Player, data, !m_bDelayLoad) as IPlayer;
                    //Profiler.EndSample();
                    Protocol.Instance.RequestName(userData.userdata.dwUserID);
                }

                if (player != null)
                {
                    PlayAni anim_param = new PlayAni();
                    anim_param.strAcionName = EntityAction.Stand;
                    anim_param.fSpeed       = 1;
                    anim_param.nStartFrame  = 0;
                    anim_param.nLoop        = -1;
                    anim_param.fBlendTime   = 0.2f;
                    player.SendMessage(EntityMessage.EntityCommand_PlayAni, anim_param);
                }
            }
            IBuffPart buffpart = player.GetPart(EntityPart.Buff) as IBuffPart;

            if (buffpart != null)
            {
                buffpart.ReceiveBuffList(userData.statelist.data);
            }
            return(player);
        }