Beispiel #1
0
        private void TickNpcs()
        {
            List <NpcInfo> deletes = new List <NpcInfo>();

            for (LinkedListNode <NpcInfo> linkNode = m_NpcMgr.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                NpcInfo info = linkNode.Value;
                if (info.LevelChanged || info.GetShootStateInfo().WeaponChanged || info.GetSkillStateInfo().BuffChanged || info.GetEquipmentStateInfo().EquipmentChanged)
                {
                    NpcAttrCalculator.Calc(info);
                    info.LevelChanged = false;
                    info.GetShootStateInfo().WeaponChanged        = false;
                    info.GetSkillStateInfo().BuffChanged          = false;
                    info.GetEquipmentStateInfo().EquipmentChanged = false;
                }

                // 约定npc的高度低于140时,直接判定npc死亡。
                if (140.0f > info.GetMovementStateInfo().GetPosition3D().Y)
                {
                    info.SetHp(Operate_Type.OT_Absolute, 0);
                }
                if (info.NeedDelete)
                {
                    deletes.Add(info);
                }
                else if (info.Hp <= 0)
                {
                    if (!info.LogicDead)
                    {
                        GfxSystem.PublishGfxEvent("ge_on_npc_dead", "story", info.GetUnitId());
                        info.LogicDead = true;
                    }
                    if (info.DeadTime <= 0)
                    {
                    }
                    else if (TimeUtility.GetServerMilliseconds() - info.DeadTime > info.ReleaseTime)
                    {
                        deletes.Add(info);
                    }
                }
                if (info.IsBorning && IsNpcBornOver(info))
                {
                    info.IsBorning = false;
                    info.SetAIEnable(true);
                    info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible);
                }
            }
            if (deletes.Count > 0)
            {
                foreach (NpcInfo ni in deletes)
                {
                    CharacterView view = EntityManager.Instance.GetCharacterViewById(ni.GetId());
                    if (null != view)
                    {
                        GfxSystem.SendMessage(view.Actor, "OnDead", null);
                    }
                    EntityManager.Instance.DestroyNpcView(ni.GetId());
                    WorldSystem.Instance.DestroyCharacterById(ni.GetId());
                    return;
                }
            }
        }
Beispiel #2
0
        public void LoadData(int resId)
        {
            SetLinkId(resId);
            m_LevelupConfig = NpcConfigProvider.Instance.GetNpcLevelupConfigById(resId);
            Data_NpcConfig npcCfg = NpcConfigProvider.Instance.GetNpcConfigById(resId);

            if (null != npcCfg)
            {
                m_NpcType = npcCfg.m_NpcType;
                switch (m_NpcType)
                {
                case (int)NpcTypeEnum.Mecha:
                    m_IsMecha = true;
                    break;

                case (int)NpcTypeEnum.Horse:
                    m_IsHorse = true;
                    break;

                case (int)NpcTypeEnum.Task:
                    m_IsTask = true;
                    break;

                case (int)NpcTypeEnum.PvpTower:
                    m_IsPvpTower = true;
                    break;
                }
                m_IsRangeNpc        = npcCfg.m_IsRange;
                m_IsShine           = npcCfg.m_IsShine;
                m_CanMove           = npcCfg.m_CanMove;
                m_CanRotate         = npcCfg.m_CanRotate;
                m_DeadType          = (NpcDeadType)npcCfg.m_DeadType;
                m_DropCount         = npcCfg.m_DropCount;
                m_DropExp           = npcCfg.m_DropExp;
                m_DropMoney         = npcCfg.m_DropMoney;
                m_DropProbabilities = npcCfg.m_DropProbabilities;
                m_DropNpcs          = npcCfg.m_DropNpcs;
                m_Scale             = npcCfg.m_Scale;

                m_IsHurtComa        = npcCfg.m_IsHurtComa;
                m_isBlaze           = npcCfg.m_isBlaze;
                m_BornAnimTimeMs    = npcCfg.m_BornTimeMs;
                m_BornEffect        = npcCfg.m_BornEffect;
                m_IsAttachControler = npcCfg.m_IsAttachControler;
                m_AttachNodeName    = npcCfg.m_AttachNodeName;
                m_MuzzlePos         = npcCfg.m_GunEndRelativePos;
                m_SecondMuzzlePos   = npcCfg.m_GunEndRelativePos;
                m_SecondMuzzlePos.X = -npcCfg.m_GunEndRelativePos.X;

                SetName(npcCfg.m_Name);
                SetLevel(npcCfg.m_Level);
                SetModel(npcCfg.m_Model);
                DeathModel  = npcCfg.m_DeathModel;
                DeathEffect = npcCfg.m_DeathEffect;
                DeathSound  = npcCfg.m_DeathSound;
                SetActionList(npcCfg.m_ActionList);
                SetBarrageId(npcCfg.m_Barrage);

                AvoidanceRadius = npcCfg.m_AvoidanceRadius;
                if (null != npcCfg.m_Shape)
                {
                    Shape = (Shape)npcCfg.m_Shape.Clone();
                }
                else
                {
                    Shape = new Circle(new Vector3(0, 0, 0), 1);
                }

                ViewRange   = npcCfg.m_ViewRange;
                GohomeRange = npcCfg.m_GohomeRange;
                ReleaseTime = npcCfg.m_ReleaseTime;
                HeadUiPos   = npcCfg.m_HeadUiPos;

                int   hp                = (int)npcCfg.m_AttrData.GetAddHpMax(0, npcCfg.m_Level);
                int   energy            = (int)npcCfg.m_AttrData.GetAddNpMax(0, npcCfg.m_Level);
                float moveSpeed         = npcCfg.m_AttrData.GetAddSpd(0, npcCfg.m_Level);
                int   hpMax             = (int)npcCfg.m_AttrData.GetAddHpMax(0, npcCfg.m_Level);
                int   energyMax         = (int)npcCfg.m_AttrData.GetAddNpMax(0, npcCfg.m_Level);
                int   energyCoreMax     = (int)npcCfg.m_AttrData.GetAddEpMax(0, npcCfg.m_Level);
                int   crgMax            = (int)npcCfg.m_AttrData.GetAddCrgMax(0, npcCfg.m_Level);
                float hpRecover         = npcCfg.m_AttrData.GetAddHpRecover(0, npcCfg.m_Level);
                float energyRecover     = npcCfg.m_AttrData.GetAddNpRecover(0, npcCfg.m_Level);
                float energyCoreRecover = npcCfg.m_AttrData.GetAddEpRecover(0, npcCfg.m_Level);
                int   attackBase        = (int)npcCfg.m_AttrData.GetAddAd(0, npcCfg.m_Level);
                int   defenceBase       = (int)npcCfg.m_AttrData.GetAddDp(0, npcCfg.m_Level);
                float critical          = npcCfg.m_AttrData.GetAddCri(0, npcCfg.m_Level);
                float criticalPow       = npcCfg.m_AttrData.GetAddPow(0, npcCfg.m_Level);
                float armorPenetration  = npcCfg.m_AttrData.GetAddAndp(0, npcCfg.m_Level);
                float energyIntensity   = npcCfg.m_AttrData.GetAddAp(0, npcCfg.m_Level);
                float energyArmor       = npcCfg.m_AttrData.GetAddTay(0, npcCfg.m_Level);
                float attackRange       = npcCfg.m_AttrData.GetAddRange(0, npcCfg.m_Level);
                float aRps              = npcCfg.m_AttrData.GetAddRps(0, npcCfg.m_Level);
                int   aCrg              = (int)npcCfg.m_AttrData.GetAddCrg(0, npcCfg.m_Level);
                float aCht              = npcCfg.m_AttrData.GetAddCht(0, npcCfg.m_Level);
                float aWdps             = npcCfg.m_AttrData.GetAddDps(0, npcCfg.m_Level);
                float aDamRandom        = npcCfg.m_AttrData.GetAddDamRange(0, npcCfg.m_Level);

                GetBaseProperty().SetMoveSpeed(Operate_Type.OT_Absolute, moveSpeed);
                GetBaseProperty().SetHpMax(Operate_Type.OT_Absolute, hpMax);
                GetBaseProperty().SetEnergyMax(Operate_Type.OT_Absolute, energyMax);
                GetBaseProperty().SetEnergyCoreMax(Operate_Type.OT_Absolute, energyCoreMax);
                GetBaseProperty().SetCrgMax(Operate_Type.OT_Absolute, crgMax);
                GetBaseProperty().SetHpRecover(Operate_Type.OT_Absolute, hpRecover);
                GetBaseProperty().SetEnergyRecover(Operate_Type.OT_Absolute, energyRecover);
                GetBaseProperty().SetEnergyCoreRecover(Operate_Type.OT_Absolute, energyCoreRecover);
                GetBaseProperty().SetAttackBase(Operate_Type.OT_Absolute, attackBase);
                GetBaseProperty().SetDefenceBase(Operate_Type.OT_Absolute, defenceBase);
                GetBaseProperty().SetCritical(Operate_Type.OT_Absolute, critical);
                GetBaseProperty().SetCriticalPow(Operate_Type.OT_Absolute, criticalPow);
                GetBaseProperty().SetArmorPenetration(Operate_Type.OT_Absolute, armorPenetration);
                GetBaseProperty().SetEnergyIntensity(Operate_Type.OT_Absolute, energyIntensity);
                GetBaseProperty().SetEnergyArmor(Operate_Type.OT_Absolute, energyArmor);
                GetBaseProperty().SetAttackRange(Operate_Type.OT_Absolute, attackRange);
                GetBaseProperty().SetRps(Operate_Type.OT_Absolute, aRps);
                GetBaseProperty().SetCrg(Operate_Type.OT_Absolute, aCrg);
                GetBaseProperty().SetCht(Operate_Type.OT_Absolute, aCht);
                GetBaseProperty().SetWdps(Operate_Type.OT_Absolute, aWdps);
                GetBaseProperty().SetDamRange(Operate_Type.OT_Absolute, aDamRandom);

                // 技能数据
                for (int i = 0; i < npcCfg.m_SkillList.Count; i++)
                {
                    SkillInfo skillInfo = new SkillInfo(npcCfg.m_SkillList[i]);
                    GetSkillStateInfo().AddSkill(skillInfo);
                }

                for (int i = 0; i < npcCfg.m_WeaponList.Count; ++i)
                {
                    WeaponInfo      weaponInfo = new WeaponInfo(npcCfg.m_WeaponList[i]);
                    WeaponLogicData weaponData = weaponInfo.ConfigData;
                    if (null != weaponData)
                    {
                        GetShootStateInfo().AddWeapon(0, weaponInfo);
                        if (null == GetShootStateInfo().GetCurWeaponInfo())
                        {
                            GetShootStateInfo().SetCurWeaponInfo(weaponInfo.WeaponId);
                            GetShootStateInfo().CurrentWeaponIndex = i;
                        }
                        //todo:先按武器表里的武器配置上,后续需要从db里读取升级数据并初始化升级配置数据
                        EquipmentDataInfo equipDataInfo = new EquipmentDataInfo();
                        equipDataInfo.EquipmentConfig = EquipmentConfigProvider.Instance.GetEquipmentConfigById(weaponData.m_EquipmentId);
                        GetEquipmentStateInfo().EquipmentInfo.Weapons[i] = equipDataInfo;
                    }
                }

                NpcAttrCalculator.Calc(this);
                CalcValidDropNumAndTotalDropProbability();
                SetHp(Operate_Type.OT_Absolute, GetActualProperty().HpMax);
                SetEnergy(Operate_Type.OT_Absolute, GetActualProperty().EnergyMax);
                for (int i = 0; i < npcCfg.m_WeaponList.Count; ++i)
                {
                    WeaponInfo      weaponInfo = GetShootStateInfo().GetWeaponInfoById(npcCfg.m_WeaponList[i]);
                    WeaponLogicData weaponData = weaponInfo.ConfigData;
                    if (null != weaponData)
                    {
                        //暴击数值
                        float CRIRATE_   = (float)(GetActualProperty().Critical / 480.0);
                        float CRIRATE_C_ = CriticalConfigProvider.Instance.GetC(CRIRATE_);
                        weaponInfo.CurCritical = CRIRATE_C_;
                    }
                }
            }
        }
        private void TickNpcs()
        {
            List <NpcInfo> deletes        = new List <NpcInfo>();
            List <NpcInfo> deletes2       = new List <NpcInfo>();
            Msg_RC_NpcDead npcDeadBuilder = new Msg_RC_NpcDead();

            for (LinkedListNode <NpcInfo> linkNode = NpcManager.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                NpcInfo info = linkNode.Value;
                if (info.LevelChanged || info.GetSkillStateInfo().BuffChanged || info.GetEquipmentStateInfo().EquipmentChanged || info.GetLegacyStateInfo().LegacyChanged)
                {
                    NpcAttrCalculator.Calc(info);
                    info.LevelChanged = false;
                    info.GetSkillStateInfo().BuffChanged          = false;
                    info.GetEquipmentStateInfo().EquipmentChanged = false;
                    info.GetLegacyStateInfo().LegacyChanged       = false;
                }
                // 伙伴自动掉血
                if ((int)NpcTypeEnum.Partner == info.NpcType)
                {
                    UserInfo owner = UserManager.GetUserInfo(info.OwnerId);
                    if (null != owner)
                    {
                        PartnerInfo pi = owner.GetPartnerInfo();
                        if (null != pi && TimeUtility.GetServerMilliseconds() - pi.LastTickTime > pi.TickInterval)
                        {
                            info.SetHp(Operate_Type.OT_Relative, (int)pi.GetHpCostPerTick(info.GetActualProperty().HpMax));
                            pi.LastTickTime = TimeUtility.GetServerMilliseconds();
                        }
                    }
                }
                if (info.NeedDelete)
                {
                    deletes2.Add(info);
                }
                else if (info.IsDead())
                {
                    if (info.DeadTime <= 0)
                    {
                        info.DeadTime = TimeUtility.GetServerMilliseconds();
                        //击杀收益计算
                        CalcKillIncome(info);
                        //解除控制
                        ReleaseControl(info);
                        //发送npc死亡消息
                        npcDeadBuilder.npc_id = info.GetId();
                        NotifyAllUser(npcDeadBuilder);

                        if (info.IsCombatNpc())
                        {
                            m_StorySystem.SendMessage("objkilled", info.GetId(), GetBattleNpcCount());
                            m_StorySystem.SendMessage(string.Format("npckilled:{0}", info.GetUnitId()), info.GetId(), GetBattleNpcCount());
                            if (info.GetUnitId() > 0)
                            {
                                if (m_IsAttemptScene)
                                {
                                    if ((int)NpcTypeEnum.BigBoss == info.NpcType)
                                    {
                                        TryFireAllNpcKilled();
                                    }
                                }
                                else
                                {
                                    TryFireAllNpcKilled();
                                }
                            }
                        }
                    }
                    else if (TimeUtility.GetServerMilliseconds() - info.DeadTime > info.ReleaseTime && info.GfxDead)
                    {
                        deletes.Add(info);
                    }
                }
                if (info.IsBorning && IsNpcBornOver(info))
                {
                    info.IsBorning = false;
                    info.SetAIEnable(true);
                    info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible);
                }
                CheckNpcOwnerId(info);
            }
            if (deletes.Count > 0)
            {
                Msg_RC_DestroyNpc destroyNpcBuilder = new Msg_RC_DestroyNpc();
                foreach (NpcInfo ni in deletes)
                {
                    //发送npc消失消息
                    destroyNpcBuilder.npc_id           = ni.GetId();
                    destroyNpcBuilder.need_play_effect = true;
                    NotifyAllUser(destroyNpcBuilder);
                    //删除npc
                    NpcManager.RemoveNpc(ni.GetId());
                    LogSystem.Debug("Npc {0}  name {1} is deleted.", ni.GetId(), ni.GetName());
                }
            }
            if (deletes2.Count > 0)
            {
                Msg_RC_DestroyNpc destroyNpcBuilder = new Msg_RC_DestroyNpc();
                foreach (NpcInfo ni in deletes2)
                {
                    //发送npc消失消息
                    destroyNpcBuilder.npc_id           = ni.GetId();
                    destroyNpcBuilder.need_play_effect = false;
                    NotifyAllUser(destroyNpcBuilder);
                    //删除npc
                    NpcManager.RemoveNpc(ni.GetId());
                    LogSystem.Debug("Npc {0}  name {1} is deleted.", ni.GetId(), ni.GetName());
                }
            }
            NpcManager.ExecuteDelayAdd();
        }