private void TickPreloading()
        {
            long curTime = TimeUtility.GetServerMilliseconds();

            if (m_LastPreloadingTickTime + c_PreloadingTickInterval < curTime)
            {
                m_LastPreloadingTickTime = curTime;

                bool canStart = true;
                foreach (User us in m_Room.RoomUsers)
                {
                    if (!us.IsEntered && !us.IsTimeout())
                    {
                        canStart = false;
                    }
                }

                if (canStart)
                {
                    LoadObjects();
                    CalculateDropOut();
                    m_StorySystem.StartStory(1);
                    for (LinkedListNode <UserInfo> linkNode = UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next)
                    {
                        UserInfo user = linkNode.Value;
                        UserAttrCalculator.Calc(user);
                        user.LevelChanged = false;
                        user.SetHp(Operate_Type.OT_Absolute, user.GetActualProperty().HpMax);
                        user.SetEnergy(Operate_Type.OT_Absolute, user.GetActualProperty().EnergyMax);
                    }
                    //先让各客户端创建自己与场景相关信息
                    foreach (User us in m_Room.RoomUsers)
                    {
                        if (us.IsEntered)
                        {
                            SyncUserToSelf(us);
                            SyncSceneObjectsToUser(us);
                        }
                    }
                    //再通知其他客户端看见自己
                    foreach (User us in m_Room.RoomUsers)
                    {
                        if (us.IsEntered)
                        {
                            SyncUserToOthers(us);
                        }
                    }
                    //给观察者发初始玩家与场景对象信息
                    foreach (Observer observer in m_Room.RoomObservers)
                    {
                        if (null != observer && !observer.IsIdle && observer.IsEntered)
                        {
                            SyncForNewObserver(observer);
                        }
                    }
                }
            }
        }
        internal void OnUserRevive(Msg_LR_UserReLive msg)
        {
            User user = m_Room.GetUserByGuid(msg.UserGuid);

            if (null != user)
            {
                UserInfo info = user.Info;
                info.SetHp(Operate_Type.OT_Absolute, info.GetActualProperty().HpMax);
                info.SetEnergy(Operate_Type.OT_Absolute, info.GetActualProperty().EnergyMax);
                info.DeadTime = 0;
                DataSyncUtility.SyncUserPropertyToCaredUsers(info);
                DataSyncUtility.SyncUserReliveToCaredUsers(info);
            }
        }
Beispiel #3
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");
        }
        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);
                    }
                }
            }
        }
        private void TickRecover()
        {
            float            hp_coefficient = 1.0f;
            float            mp_coefficient = 1.0f;
            Data_SceneConfig scene_data     = SceneConfigProvider.Instance.GetSceneConfigById(m_SceneResId);

            if (null != scene_data)
            {
                hp_coefficient = scene_data.m_RecoverHpCoefficient;
                mp_coefficient = scene_data.m_RecoverMpCoefficient;
            }
            for (LinkedListNode <UserInfo> linkNode = UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                UserInfo info = linkNode.Value;
                if (!info.IsDead())
                {
                    float hpRecover = info.GetActualProperty().HpRecover *hp_coefficient;
                    float epRecover = info.GetActualProperty().EnergyRecover *mp_coefficient;
                    if (hpRecover > 0.0001)
                    {
                        if (info.Hp + (int)hpRecover >= info.GetActualProperty().HpMax)
                        {
                            info.SetHp(Operate_Type.OT_Absolute, (int)info.GetActualProperty().HpMax);
                        }
                        else
                        {
                            info.SetHp(Operate_Type.OT_Relative, (int)hpRecover);
                        }
                    }
                    if (epRecover > 0.0001)
                    {
                        if (info.Energy + (int)epRecover >= info.GetActualProperty().EnergyMax)
                        {
                            info.SetEnergy(Operate_Type.OT_Absolute, (int)info.GetActualProperty().EnergyMax);
                        }
                        else
                        {
                            info.SetEnergy(Operate_Type.OT_Relative, (int)epRecover);
                        }
                    }
                    if (hpRecover > 0.0001 || epRecover > 0.0001)
                    {
                        Msg_RC_SyncProperty builder = DataSyncUtility.BuildSyncPropertyMessage(info);
                        NotifyAreaUser(info, builder, false);
                    }
                }
            }
            for (LinkedListNode <NpcInfo> linkNode = NpcManager.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                NpcInfo info = linkNode.Value;
                if (!info.IsDead())
                {
                    float hpRecover = info.GetActualProperty().HpRecover;
                    float npRecover = info.GetActualProperty().EnergyRecover;
                    if (hpRecover > 0.0001)
                    {
                        if (info.Hp + (int)hpRecover >= info.GetActualProperty().HpMax)
                        {
                            info.SetHp(Operate_Type.OT_Absolute, (int)info.GetActualProperty().HpMax);
                        }
                        else
                        {
                            info.SetHp(Operate_Type.OT_Relative, (int)hpRecover);
                        }
                    }
                    if (npRecover > 0.0001)
                    {
                        if (info.Energy + (int)npRecover >= info.GetActualProperty().EnergyMax)
                        {
                            info.SetEnergy(Operate_Type.OT_Absolute, (int)info.GetActualProperty().EnergyMax);
                        }
                        else
                        {
                            info.SetEnergy(Operate_Type.OT_Relative, (int)npRecover);
                        }
                    }
                    if (hpRecover > 0.0001 || npRecover > 0.0001)
                    {
                        Msg_RC_SyncProperty builder = DataSyncUtility.BuildSyncPropertyMessage(info);
                        NotifyAreaUser(info, builder, false);
                    }
                }
            }
        }