コード例 #1
0
        private void CombatHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            float rps = npc.GetActualProperty().Rps;

            if (rps > 0.001f && info.Time > 1000 / rps)
            {
                info.Time = 0;
                AiData_PveNpc_General data = GetAiData(npc);
                if (null != data)
                {
                    bool          goHome = false;
                    CharacterInfo target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(npc, info.Target);
                    if (null != target)
                    {
                        float dist       = (float)npc.GetActualProperty().AttackRange;
                        float distGoHome = (float)npc.GohomeRange;
                        ScriptRuntime.Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D();
                        ScriptRuntime.Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
                        float powDist       = Geometry.DistanceSquare(srcPos, targetPos);
                        float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                        if (powDist < dist * dist)
                        {
                            float dir = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                            npc.GetMovementStateInfo().SetFaceDir(dir);
                            npc.GetMovementStateInfo().SetMoveDir(dir);
                            if (npc.CanShoot() && !npc.GetSkillStateInfo().IsSkillActivated())
                            {
                                Data_NpcConfig npcConfig = NpcConfigProvider.Instance.GetNpcConfigById(npc.GetLinkId());
                                if (null == npcConfig)
                                {
                                    return;
                                }
                                if (npcConfig.m_SkillList.Count >= 1)
                                {
                                    ServerNpcSkill(npc, npcConfig.m_SkillList[0], target, targetPos, dir);
                                }
                            }
                        }
                        else if (powDistToHome < distGoHome * distGoHome)
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            info.Time = 0;
                            data.FoundPath.Clear();
                            ChangeToState(npc, (int)AiStateId.Pursuit);
                        }
                        else
                        {
                            goHome = true;
                        }
                    }
                    else
                    {
                        goHome = true;
                    }
                    if (goHome)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);
                        info.Time = 0;
                        ChangeToState(npc, (int)AiStateId.GoHome);
                    }
                }
            }
        }
コード例 #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_;
                    }
                }
            }
        }