Пример #1
0
        public NpcInfo CreateNpcByLinkId(int id, int linkId)
        {
            Data_Unit mapUnit = new Data_Unit();

            mapUnit.m_Id     = -1;
            mapUnit.m_LinkId = linkId;
            return(m_NpcMgr.AddNpc(id, mapUnit));
        }
Пример #2
0
        public NpcInfo DelayAddNpc(Data_Unit unit)
        {
            NpcInfo npc = NewNpcInfo();

            npc.SceneContext = m_SceneContext;
            npc.LoadData(unit);
            m_DelayAdd.Add(npc);
            return(npc);
        }
Пример #3
0
        private void LoadObjects()
        {
            m_SceneState = SceneState.Running;
            LogSys.Log(LOG_TYPE.DEBUG, "Scene {0} start Running.", m_SceneResId);
            // TODO: m_GameStartTime should be set when game of this scene
            // is really started
            m_GameTime.Start();
            m_SceneContext.StartTime = m_GameTime.StartTime;
            Room room = GetRoom();

            if (null != room && null != m_MapData)
            {
                MyDictionary <int, object> units = m_MapData.m_UnitMgr.GetData();
                foreach (Data_Unit unit in units.Values)
                {
                    if (null != unit && unit.m_IsEnable)
                    {
                        NpcInfo npc = m_NpcMgr.AddNpc(unit);
                        if (null != npc)
                        {
                            if (room.RoomUsers.Count() > 0)
                            {
                                npc.OwnerId = room.RoomUsers[0].RoleId;
                                LogSystem.Debug("User {0} is responsible for npc {1}", npc.OwnerId, npc.GetId());
                            }
                            else
                            {
                                LogSystem.Warn("No User is responsible for npc");
                            }
                        }
                    }
                }

                MyDictionary <int, object> slogics = m_MapData.m_SceneLogicMgr.GetData();
                foreach (SceneLogicConfig sc in slogics.Values)
                {
                    if (null != sc && sc.m_IsServer)
                    {
                        m_SceneLogicInfoMgr.AddSceneLogicInfo(sc.GetId(), sc);
                    }
                }

                foreach (User us in room.RoomUsers)
                {
                    UserInfo  info = us.Info;
                    Data_Unit unit = m_MapData.ExtractData(DataMap_Type.DT_Unit, info.GetUnitId()) as Data_Unit;
                    if (null != unit)
                    {
                        info.GetMovementStateInfo().SetPosition(unit.m_Pos);
                        info.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle);
                        info.RevivePoint = unit.m_Pos;
                    }
                }
            }
        }
Пример #4
0
        public NpcInfo CreateNpc(int id, int unitId)
        {
            NpcInfo   ret     = null;
            Data_Unit mapUnit = GetCurScene().StaticData.ExtractData(DataMap_Type.DT_Unit, unitId) as Data_Unit;

            if (null != mapUnit)
            {
                ret = m_NpcMgr.AddNpc(id, mapUnit);
            }
            return(ret);
        }
Пример #5
0
        internal static void Execute(object msg, User user)
        {
            Msg_CRC_Create enter_msg = msg as Msg_CRC_Create;

            if (enter_msg == null)
            {
                return;
            }
            LogSys.Log(LOG_TYPE.DEBUG, "user {0}({1}) enter.", user.RoleId, user.GetKey());
            user.UserControlState = (int)UserControlState.User;
            user.IsEntered        = true;

            Room room = user.OwnRoom;

            if (null != room)
            {
                Scene scene = room.GetActiveScene();
                if (null != scene)
                {
                    UserInfo userInfo = user.Info;
                    if (null != userInfo)
                    {
                        userInfo.GetXSoulInfo().GetAllXSoulPartData().Clear();
                        foreach (var pair in user.XSouls.GetAllXSoulPartData())
                        {
                            userInfo.GetXSoulInfo().SetXSoulPartData(pair.Key, pair.Value);
                        }
                        foreach (var pair in userInfo.GetXSoulInfo().GetAllXSoulPartData())
                        {
                            XSoulPartInfo part_info = pair.Value;
                            foreach (int impactid in part_info.GetActiveImpacts())
                            {
                                //LogSys.Log(LOG_TYPE.DEBUG, "---add xsoul impact to self: " + impactid);
                                ImpactSystem.Instance.SendImpactToCharacter(userInfo, impactid, userInfo.GetId(),
                                                                            -1, -1, userInfo.GetMovementStateInfo().GetPosition3D(),
                                                                            userInfo.GetMovementStateInfo().GetFaceDir());
                            }
                        }
                        if (scene.SceneState == SceneState.Running)
                        {
                            Data_Unit unit = scene.MapData.ExtractData(DataMap_Type.DT_Unit, userInfo.GetUnitId()) as Data_Unit;
                            if (null != unit)
                            {
                                userInfo.GetMovementStateInfo().SetPosition(unit.m_Pos);
                                userInfo.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle);
                                userInfo.RevivePoint = unit.m_Pos;
                            }
                            scene.SyncForNewUser(user);
                        }
                    }
                }
            }
        }
Пример #6
0
 public void LoadData(Data_Unit unit)
 {
     SetUnitId(unit.m_Id);
     SetCampId(unit.m_CampId);
     GetAiStateInfo().AiLogic = unit.m_AiLogic;
     for (int i = 0; i < Data_Unit.c_MaxAiParamNum; ++i)
     {
         GetAiStateInfo().AiParam[i] = unit.m_AiParam[i];
     }
     GetMovementStateInfo().SetPosition(unit.m_Pos);
     GetMovementStateInfo().SetFaceDir(unit.m_RotAngle);
     LoadData(unit.m_LinkId);
 }
Пример #7
0
        internal NpcInfo SummonNpc(int id, int owner_id, int owner_skillid, int npc_type_id, string modelPrefab, int skillid, int ailogicid, bool followsummonerdead,
                                   float x, float y, float z, string aiparamstr)
        {
            CharacterInfo charObj = SceneContext.GetCharacterInfoById(owner_id);

            if (charObj == null)
            {
                return(null);
            }
            NpcInfo   npc            = null;
            SkillInfo ownerSkillInfo = charObj.GetSkillStateInfo().GetSkillInfoById(owner_skillid);

            if (null != ownerSkillInfo)
            {
                if (null != ownerSkillInfo.m_EnableSummonNpcs && ownerSkillInfo.m_EnableSummonNpcs.Contains(npc_type_id))
                {
                    //ownerSkillInfo.m_EnableSummonNpcs.Remove(npc_type_id);

                    Data_Unit data = new Data_Unit();
                    data.m_Id       = -1;
                    data.m_LinkId   = npc_type_id;
                    data.m_CampId   = charObj.GetCampId();
                    data.m_IsEnable = true;
                    data.m_Pos      = new Vector3(x, y, z);
                    data.m_RotAngle = 0;
                    data.m_AiLogic  = ailogicid;
                    if (!string.IsNullOrEmpty(aiparamstr))
                    {
                        string[] strarry = aiparamstr.Split(new char[] { ',' }, 8);
                        int      i       = 0;
                        foreach (string str in strarry)
                        {
                            data.m_AiParam[i++] = str;
                        }
                    }
                    npc = NpcManager.AddNpc(data);
                    if (!string.IsNullOrEmpty(modelPrefab))
                    {
                        npc.SetModel(modelPrefab);
                    }
                    npc.FollowSummonerDead = followsummonerdead;
                    SkillInfo skillinfo = new SkillInfo(skillid);
                    npc.GetSkillStateInfo().AddSkill(skillinfo);
                    npc.GetMovementStateInfo().SetPosition(data.m_Pos);
                    npc.SummonOwnerId = charObj.GetId();
                    charObj.GetSkillStateInfo().AddSummonObject(npc);
                    AbstractNpcStateLogic.OnNpcSkill(npc, skillid);
                }
            }
            return(npc);
        }
Пример #8
0
        public void CreateNpcWithPos(int unitId, float x, float y, float z, float rotateAngle)
        {
            Data_Unit mapUnit = GetCurScene().StaticData.ExtractData(DataMap_Type.DT_Unit, unitId) as Data_Unit;

            if (null != mapUnit)
            {
                mapUnit.m_Pos      = new Vector3(x, y, z);
                mapUnit.m_RotAngle = rotateAngle;
                NpcInfo npc = m_NpcMgr.AddNpc(mapUnit);
                if (null != npc)
                {
                    EntityManager.Instance.CreateNpcView(npc.GetId());
                }
            }
        }
Пример #9
0
        public void Init(int resId)
        {
            m_SceneResId = resId;
            LoadSceneData(resId);
            WorldSystem.Instance.SceneContext.SceneResId = resId;
            m_IsWaitSceneLoad = true;

            Data_Unit unit = m_SceneStaticData.ExtractData(DataMap_Type.DT_Unit, GlobalVariables.GetUnitIdByCampId(NetworkSystem.Instance.CampId)) as Data_Unit;

            if (null != unit)
            {
                m_CameraLookAtHeight = unit.m_Pos.Y;
            }

            GfxSystem.GfxLog("SceneResource.Init {0}", resId);
        }
Пример #10
0
        public void StartGame()
        {
            UserInfo user = GetPlayerSelf();

            if (null != user)
            {
                EntityManager.Instance.DestroyUserView(user.GetId());
                DestroyCharacterById(user.GetId());
            }
            user = CreatePlayerSelf(1, NetworkSystem.Instance.HeroId);
            user.SetCampId(NetworkSystem.Instance.CampId);
            Data_Unit unit = m_CurScene.StaticData.ExtractData(DataMap_Type.DT_Unit, GlobalVariables.GetUnitIdByCampId(NetworkSystem.Instance.CampId)) as Data_Unit;

            if (null != unit)
            {
                user.GetMovementStateInfo().SetPosition(unit.m_Pos);
                user.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle);
                user.SetHp(Operate_Type.OT_Absolute, user.GetActualProperty().HpMax);
            }
            EntityManager.Instance.CreatePlayerSelfView(1);
            UserView view = EntityManager.Instance.GetUserViewById(1);

            if (null != view)
            {
                view.Visible = true;
            }

            foreach (Data_Unit npcUnit in m_CurScene.StaticData.m_UnitMgr.GetData().Values)
            {
                if (npcUnit.m_IsEnable)
                {
                    NpcInfo npc = m_NpcMgr.GetNpcInfoByUnitId(npcUnit.GetId());
                    if (null == npc)
                    {
                        npc = m_NpcMgr.AddNpc(npcUnit);
                    }
                    if (null != npc)
                    {
                        EntityManager.Instance.CreateNpcView(npc.GetId());
                    }
                }
            }
            GfxSystem.PublishGfxEvent("ge_on_game_start", "story");
            LogSystem.Debug("start game");
        }
Пример #11
0
        private void DropNpc(Vector3 pos, int money, string model, string particle)
        {
            //给每个玩家掉落一个
            Data_Unit unit = new Data_Unit();

            unit.m_Id       = -1;
            unit.m_LinkId   = 100001;
            unit.m_AiLogic  = (int)AiStateLogicId.DropOut_AutoPick;
            unit.m_RotAngle = 0;
            for (LinkedListNode <UserInfo> linkNode = UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                UserInfo userInfo = linkNode.Value;
                if (null != userInfo)
                {
                    float x = CrossEngineHelper.Random.NextFloat() * 4 - 2;
                    float z = CrossEngineHelper.Random.NextFloat() * 4 - 2;
                    pos.X += x;
                    pos.Z += z;

                    NpcInfo npcInfo = NpcManager.AddNpc(unit);
                    npcInfo.GetMovementStateInfo().SetPosition(pos);
                    npcInfo.GetMovementStateInfo().SetFaceDir(0);
                    npcInfo.GetMovementStateInfo().IsMoving = false;
                    npcInfo.SetAIEnable(true);
                    npcInfo.SetCampId((int)CampIdEnum.Friendly);
                    npcInfo.OwnerId   = userInfo.GetId();
                    npcInfo.DropMoney = money;

                    DropOutInfo dropInfo = new DropOutInfo();
                    dropInfo.DropType = DropOutType.GOLD;
                    dropInfo.Value    = money;
                    dropInfo.Model    = model;
                    dropInfo.Particle = particle;
                    npcInfo.GetAiStateInfo().AiDatas.AddData <DropOutInfo>(dropInfo);
                    npcInfo.SetModel(dropInfo.Model);

                    User us = userInfo.CustomData as User;
                    if (null != us)
                    {
                        Msg_RC_CreateNpc builder = DataSyncUtility.BuildCreateNpcMessage(npcInfo);
                        us.SendMessage(builder);
                    }
                }
            }
        }
Пример #12
0
 private void CreateNpcByStory(int unitIdFrom, int unitIdTo)
 {
     LogSystem.Debug("start = {0}, to = {1}", unitIdFrom, unitIdTo);
     for (int i = unitIdFrom; i <= unitIdTo; i++)
     {
         Data_Unit mapUnit = GetCurScene().StaticData.ExtractData(DataMap_Type.DT_Unit, i) as Data_Unit;
         if (null == mapUnit)
         {
             LogSystem.Debug("i = {0}", i);
         }
         if (null != mapUnit)
         {
             NpcInfo npc = m_NpcMgr.AddNpc(mapUnit);
             if (null != npc)
             {
                 EntityManager.Instance.CreateNpcView(npc.GetId());
             }
         }
     }
 }
Пример #13
0
        /**
         * @brief 克隆函数
         *
         * @return
         */
        public object Clone()
        {
            Data_Unit data = new Data_Unit();

            data.m_Id       = m_Id;
            data.m_LinkId   = m_LinkId;
            data.m_CampId   = m_CampId;
            data.m_Pos      = new ScriptRuntime.Vector3(m_Pos.X, m_Pos.Y, m_Pos.Z);
            data.m_RotAngle = m_RotAngle;

            data.m_IsEnable = m_IsEnable;
            data.m_AiLogic  = m_AiLogic;

            for (int i = 0; i < c_MaxAiParamNum; ++i)
            {
                data.m_AiParam[i] = m_AiParam[i];
            }

            return(data);
        }
Пример #14
0
        public NpcInfo AddNpc(int id, Data_Unit unit)
        {
            NpcInfo npc = NewNpcInfo(id);

            npc.SceneContext = m_SceneContext;
            npc.LoadData(unit);
            npc.IsBorning = true;
            npc.SetAIEnable(false);
            npc.SetStateFlag(Operate_Type.OT_AddBit, CharacterState_Type.CST_Invincible);
            npc.BornTime = TimeUtility.GetServerMilliseconds();
            m_Npcs.Add(npc.GetId(), npc);
            if (null != m_SceneContext && null != m_SceneContext.SpatialSystem)
            {
                m_SceneContext.SpatialSystem.AddObj(npc.SpaceObject);
            }
            if (null != m_SceneContext && null != m_SceneContext.SightManager)
            {
                m_SceneContext.SightManager.AddObject(npc);
            }
            return(npc);
        }
Пример #15
0
        internal void OnSummonNpc(Msg_CRC_SummonNpc msg)
        {
            CharacterInfo char_Info = SceneContext.GetCharacterInfoById(msg.summon_owner_id);

            if (null == char_Info)
            {
                return;
            }
            Data_Unit data = new Data_Unit();

            data.m_IsEnable = true;
            NpcInfo npc = SummonNpc(msg.npc_id, msg.summon_owner_id, msg.owner_skillid,
                                    msg.link_id, msg.model_prefab, msg.skill_id, msg.ai_id, msg.follow_dead,
                                    msg.pos_x, msg.pos_y, msg.pos_z, msg.ai_params);

            if (npc != null)
            {
                npc.OwnerId  = char_Info.OwnerId;
                msg.npc_id   = npc.GetId();
                msg.owner_id = char_Info.OwnerId;
                NotifyAllUser(msg);
            }
        }
Пример #16
0
        internal void DropNpc(int ownerId, int fromNpcId, DropOutType dropType, string model, string particle, int num)
        {
            if (ownerId > 0)
            {
                UserInfo user = UserManager.GetUserInfo(ownerId);
                if (null == user)
                {
                    NpcInfo npc = NpcManager.GetNpcInfo(ownerId);
                    while (null != npc)
                    {
                        user = UserManager.GetUserInfo(npc.OwnerId);
                        if (null != user)
                        {
                            break;
                        }
                        else
                        {
                            npc = NpcManager.GetNpcInfo(npc.OwnerId);
                        }
                    }
                }
                if (null != user)
                {
                    Data_Unit unit = new Data_Unit();
                    unit.m_Id = -1;
                    switch (dropType)
                    {
                    case DropOutType.GOLD:
                        unit.m_LinkId = (int)DropNpcTypeEnum.GOLD;
                        break;

                    case DropOutType.HP:
                        unit.m_LinkId = (int)DropNpcTypeEnum.HP;
                        break;

                    case DropOutType.MP:
                        unit.m_LinkId = (int)DropNpcTypeEnum.MP;
                        break;

                    case DropOutType.MULT_GOLD:
                        unit.m_LinkId = (int)DropNpcTypeEnum.MUTI_GOLD;
                        break;
                    }
                    unit.m_RotAngle = 0;

                    NpcInfo npcInfo = NpcManager.AddNpc(unit);
                    npcInfo.GetMovementStateInfo().SetFaceDir(0);
                    npcInfo.GetMovementStateInfo().IsMoving = false;
                    npcInfo.SetAIEnable(true);
                    npcInfo.SetCampId(user.GetCampId());
                    npcInfo.OwnerId = user.GetId();

                    DropOutInfo dropInfo = new DropOutInfo();
                    dropInfo.DropType = dropType;
                    dropInfo.Value    = num;
                    dropInfo.Model    = model;
                    dropInfo.Particle = particle;

                    npcInfo.GetAiStateInfo().AiDatas.AddData <DropOutInfo>(dropInfo);
                    npcInfo.SetModel(dropInfo.Model);

                    User us = user.CustomData as User;
                    if (null != us)
                    {
                        Msg_RC_DropNpc builder = DataSyncUtility.BuildDropNpcMessage(npcInfo, fromNpcId, (int)dropType, num, model);
                        us.SendMessage(builder);
                    }
                }
            }
            else
            {
                int      ct   = UserManager.Users.Count;
                int      rd   = CrossEngineHelper.Random.Next(0, ct);
                UserInfo user = null;
                if (UserManager.Users.TryGetValue(rd, out user))
                {
                    Data_Unit unit = new Data_Unit();
                    unit.m_Id = -1;
                    switch (dropType)
                    {
                    case DropOutType.GOLD:
                        unit.m_LinkId = (int)DropNpcTypeEnum.GOLD;
                        break;

                    case DropOutType.HP:
                        unit.m_LinkId = (int)DropNpcTypeEnum.HP;
                        break;

                    case DropOutType.MP:
                        unit.m_LinkId = (int)DropNpcTypeEnum.MP;
                        break;

                    case DropOutType.MULT_GOLD:
                        unit.m_LinkId = (int)DropNpcTypeEnum.MUTI_GOLD;
                        break;
                    }
                    unit.m_RotAngle = 0;

                    NpcInfo npcInfo = NpcManager.AddNpc(unit);
                    npcInfo.GetMovementStateInfo().SetFaceDir(0);
                    npcInfo.GetMovementStateInfo().IsMoving = false;
                    npcInfo.SetAIEnable(true);
                    npcInfo.SetCampId(user.GetCampId());
                    npcInfo.OwnerId = user.GetId();

                    DropOutInfo dropInfo = new DropOutInfo();
                    dropInfo.DropType = dropType;
                    dropInfo.Value    = num;
                    dropInfo.Model    = model;
                    dropInfo.Particle = particle;

                    npcInfo.GetAiStateInfo().AiDatas.AddData <DropOutInfo>(dropInfo);
                    npcInfo.SetModel(dropInfo.Model);

                    User us = user.CustomData as User;
                    if (null != us)
                    {
                        Msg_RC_DropNpc builder = DataSyncUtility.BuildDropNpcMessage(npcInfo, fromNpcId, (int)dropType, num, model);
                        us.SendMessage(builder);
                    }
                }
            }
        }
Пример #17
0
        internal void SummonPartner(Msg_CR_SummonPartner msg)
        {
            UserInfo userInfo = UserManager.GetUserInfo(msg.obj_id);

            if (null != userInfo)
            {
                // summonpartner
                PartnerInfo partnerInfo = userInfo.GetPartnerInfo();
                if (null != partnerInfo && (TimeUtility.GetServerMilliseconds() - userInfo.LastSummonPartnerTime > partnerInfo.CoolDown || userInfo.LastSummonPartnerTime == 0))
                {
                    Data_Unit data = new Data_Unit();
                    data.m_Id         = -1;
                    data.m_LinkId     = partnerInfo.LinkId;
                    data.m_CampId     = userInfo.GetCampId();
                    data.m_Pos        = userInfo.GetMovementStateInfo().GetPosition3D();
                    data.m_RotAngle   = 0;
                    data.m_AiLogic    = partnerInfo.GetAiLogic();
                    data.m_AiParam[0] = "";
                    data.m_AiParam[1] = "";
                    data.m_AiParam[2] = partnerInfo.GetAiParam().ToString();
                    data.m_IsEnable   = true;
                    NpcInfo npc = NpcManager.AddNpc(data);
                    if (null != npc)
                    {
                        AppendAttributeConfig aac       = AppendAttributeConfigProvider.Instance.GetDataById(partnerInfo.GetAppendAttrConfigId());
                        float inheritAttackAttrPercent  = partnerInfo.GetInheritAttackAttrPercent();
                        float inheritDefenceAttrPercent = partnerInfo.GetInheritDefenceAttrPercent();
                        if (null != aac)
                        {
                            // attack
                            npc.GetBaseProperty().SetAttackBase(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().AttackBase *inheritAttackAttrPercent));
                            npc.GetBaseProperty().SetFireDamage(Operate_Type.OT_Absolute, userInfo.GetActualProperty().FireDamage *inheritAttackAttrPercent);
                            npc.GetBaseProperty().SetIceDamage(Operate_Type.OT_Absolute, userInfo.GetActualProperty().IceDamage *inheritAttackAttrPercent);
                            npc.GetBaseProperty().SetPoisonDamage(Operate_Type.OT_Absolute, userInfo.GetActualProperty().PoisonDamage *inheritAttackAttrPercent);
                            // defence
                            npc.GetBaseProperty().SetHpMax(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().HpMax *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetEnergyMax(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().EnergyMax *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetADefenceBase(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().ADefenceBase *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetMDefenceBase(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().MDefenceBase *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetFireERD(Operate_Type.OT_Absolute, userInfo.GetActualProperty().FireERD *inheritDefenceAttrPercent);
                            npc.GetBaseProperty().SetIceERD(Operate_Type.OT_Absolute, userInfo.GetActualProperty().IceERD *inheritDefenceAttrPercent);
                            npc.GetBaseProperty().SetPoisonERD(Operate_Type.OT_Absolute, userInfo.GetActualProperty().PoisonERD *inheritDefenceAttrPercent);
                            // reset hp & energy
                            npc.SetHp(Operate_Type.OT_Absolute, npc.GetBaseProperty().HpMax);
                            npc.SetEnergy(Operate_Type.OT_Absolute, npc.GetBaseProperty().EnergyMax);
                        }
                        npc.SetAIEnable(true);
                        npc.GetSkillStateInfo().RemoveAllSkill();
                        npc.BornTime = TimeUtility.GetServerMilliseconds();
                        List <int> skillList = partnerInfo.GetSkillList();
                        if (null != skillList)
                        {
                            for (int i = 0; i < skillList.Count; ++i)
                            {
                                SkillInfo skillInfo = new SkillInfo(skillList[i]);
                                npc.GetSkillStateInfo().AddSkill(skillInfo);
                            }
                        }
                        userInfo.LastSummonPartnerTime = TimeUtility.GetServerMilliseconds();
                        npc.OwnerId        = userInfo.GetId();
                        userInfo.PartnerId = npc.GetId();
                        if (partnerInfo.BornSkill > 0)
                        {
                            SkillInfo skillInfo = new SkillInfo(partnerInfo.BornSkill);
                            npc.GetSkillStateInfo().AddSkill(skillInfo);
                        }
                        ArkCrossEngineMessage.Msg_RC_CreateNpc builder = DataSyncUtility.BuildCreateNpcMessage(npc);
                        NotifyAllUser(builder);
                    }
                }
            }
        }
Пример #18
0
        internal bool AddNewUser(User newUser)
        {
            foreach (User us in room_users_)
            {
                if (us != null && us.Guid == newUser.Guid)
                {
                    //当前玩家已在游戏房间内
                    LogSys.Log(LOG_TYPE.DEBUG, "Add user success: User already in the room! RoomID:{0}, Guid:{1}, OldUser[{2}]({3}) NewUser[{4}]({5}) ",
                               cur_room_id_, us.Guid, us.LocalID, us.GetKey(), newUser.LocalID, newUser.GetKey());
                    LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for {1} {2}, [Room.AddNewUser]", newUser.LocalID, newUser.Guid, newUser.GetKey());
                    user_pool_.FreeUser(newUser.LocalID);
                    return(true);
                }
            }
            can_close_time_       = 0;
            newUser.EnterRoomTime = TimeUtility.GetServerMilliseconds();
            newUser.OwnRoom       = this;
            newUser.RegisterObservers(room_observers_);
            newUser.Info = m_UserMgr.AddUser(newUser.HeroId);
            newUser.Info.SetUnitId(GlobalVariables.GetUnitIdByCampId(newUser.CampId));
            newUser.Info.SetCampId(newUser.CampId);
            newUser.Info.SetLevel(newUser.Level);
            if ((int)UserControlState.Ai == newUser.UserControlState)
            {
                newUser.Info.GetAiStateInfo().AiLogic = (int)AiStateLogicId.PvpUser_General;
                newUser.IsEntered = true;
            }
            if (m_ActiveScene >= 0 && m_Scenes.Count > m_ActiveScene)
            {
                Scene scene = m_Scenes[m_ActiveScene];
                scene.EnterScene(newUser.Info);
                if ((int)UserControlState.Ai == newUser.UserControlState)
                {
                    Data_Unit unit = scene.MapData.ExtractData(DataMap_Type.DT_Unit, newUser.Info.GetUnitId()) as Data_Unit;
                    if (null != unit)
                    {
                        newUser.Info.GetMovementStateInfo().SetPosition(unit.m_Pos);
                        newUser.Info.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle);
                    }
                }
            }
            foreach (User otheruser in room_users_)
            {
                if (otheruser != null)
                {
                    otheruser.AddSameRoomUser(newUser);
                    newUser.AddSameRoomUser(otheruser);
                }
            }
            room_users_.Add(newUser);
            LogSys.Log(LOG_TYPE.DEBUG, "Add user success ! RoomID:{0} , UserGuid:{1}({2})",
                       cur_room_id_, newUser.Guid, newUser.GetKey());

            if (null != newUser.Skill && 4 == newUser.Skill.Count)
            {
                newUser.Info.GetSkillStateInfo().RemoveAllSkill();
                newUser.Info.ResetSkill();
                for (int index = 0; index < newUser.Skill.Count; index++)
                {
                    if (newUser.Skill[index].SkillId > 0)
                    {
                        SkillInfo info = new SkillInfo(newUser.Skill[index].SkillId);
                        info.SkillLevel = newUser.Skill[index].SkillLevel;
                        info.Postions.SetCurSkillSlotPos(newUser.PresetIndex, (SlotPosition)(index + 1));
                        SkillCategory cur_skill_pos = SkillCategory.kNone;
                        if ((index + 1) == (int)SlotPosition.SP_A)
                        {
                            cur_skill_pos = SkillCategory.kSkillA;
                        }
                        else if ((index + 1) == (int)SlotPosition.SP_B)
                        {
                            cur_skill_pos = SkillCategory.kSkillB;
                        }
                        else if ((index + 1) == (int)SlotPosition.SP_C)
                        {
                            cur_skill_pos = SkillCategory.kSkillC;
                        }
                        else if ((index + 1) == (int)SlotPosition.SP_D)
                        {
                            cur_skill_pos = SkillCategory.kSkillD;
                        }
                        info.ConfigData.Category = cur_skill_pos;
                        newUser.Info.GetSkillStateInfo().AddSkill(info);
                        newUser.Info.ResetSkill();
                        ///
                        AddSubSkill(newUser, info.SkillId, cur_skill_pos, info.SkillLevel);
                    }
                }
                Data_PlayerConfig playerData = PlayerConfigProvider.Instance.GetPlayerConfigById(newUser.HeroId);
                if (null != playerData && null != playerData.m_FixedSkillList &&
                    playerData.m_FixedSkillList.Count > 0)
                {
                    foreach (int skill_id in playerData.m_FixedSkillList)
                    {
                        if (null == newUser.Info.GetSkillStateInfo().GetSkillInfoById(skill_id))
                        {
                            SkillInfo info = new SkillInfo(skill_id, 1);
                            newUser.Info.GetSkillStateInfo().AddSkill(info);
                            newUser.Info.ResetSkill();
                        }
                    }
                }
            }
            if (null != newUser.Equip && newUser.Equip.Count > 0)
            {
                newUser.Info.GetEquipmentStateInfo().Reset();
                for (int index = 0; index < newUser.Equip.Count; index++)
                {
                    if (newUser.Equip[index].ItemId > 0)
                    {
                        ItemDataInfo info = new ItemDataInfo(newUser.Equip[index].ItemRandomProperty);
                        info.ItemId         = newUser.Equip[index].ItemId;
                        info.Level          = newUser.Equip[index].ItemLevel;
                        info.RandomProperty = newUser.Equip[index].ItemRandomProperty;
                        info.ItemConfig     = ItemConfigProvider.Instance.GetDataById(info.ItemId);
                        newUser.Info.GetEquipmentStateInfo().SetEquipmentData(index, info);
                    }
                }
            }
            if (null != newUser.Legacy && newUser.Legacy.Count > 0)
            {
                newUser.Info.GetLegacyStateInfo().Reset();
                for (int index = 0; index < newUser.Legacy.Count; index++)
                {
                    if (null != newUser.Legacy[index] && newUser.Legacy[index].ItemId > 0 &&
                        newUser.Legacy[index].IsUnlock)
                    {
                        ItemDataInfo info = new ItemDataInfo(newUser.Legacy[index].ItemRandomProperty);
                        info.ItemId         = newUser.Legacy[index].ItemId;
                        info.Level          = newUser.Legacy[index].ItemLevel;
                        info.RandomProperty = newUser.Legacy[index].ItemRandomProperty;
                        info.IsUnlock       = newUser.Legacy[index].IsUnlock;
                        info.ItemConfig     = ItemConfigProvider.Instance.GetDataById(info.ItemId);
                        newUser.Info.GetLegacyStateInfo().SetLegacyData(index, info);
                    }
                }
                newUser.Info.GetLegacyStateInfo().UpdateLegacyComplexAttr();
            }
            if (null != newUser.Partner)
            {
                newUser.Info.SetPartnerInfo(newUser.Partner);
            }
            return(true);
        }