示例#1
0
    public void ActionHandle(BuffHandlerVar buffHandlerVar)
    {
        Buff_DamageByNumeric buff = (Buff_DamageByNumeric)buffHandlerVar.data;

        if (!buffHandlerVar.GetBufferValue(out BufferValue_TargetUnits targetUnits))
        {
            return;
        }
        NumericComponent numericComponent = buffHandlerVar.source.GetComponent <NumericComponent>();

        GameCalNumericTool.DamageData damageData = new GameCalNumericTool.DamageData();



        damageData.damageType = buff.damageType;

        damageData.damageValue = Mathf.RoundToInt(numericComponent.GetAsInt(buff.numericType) * buff.baseCoff);
        if (buffHandlerVar.bufferValues.TryGetValue(typeof(BufferValue_DamageAddPct), out var damageAddPct))
        {
            damageData.damageValue = Mathf.RoundToInt((1 + ((BufferValue_DamageAddPct)damageAddPct).damageAddPct) * damageData.damageValue);
        }
        damageData.isCritical = false;
        SkillEffectComponent skillEffectComponent = buffHandlerVar.source.GetComponent <SkillEffectComponent>();
        var effectData = skillEffectComponent.GetEffectData(buffHandlerVar.skillId);

        if (effectData != null)
        {
            damageData.damageValue = Mathf.RoundToInt((1 + effectData.coefficientAddPct) * damageData.damageValue);
            damageData.isCritical  = effectData.critical;
        }

        if (!SkillHelper.tempData.ContainsKey((buffHandlerVar.source, buff.buffSignal)))
        {
            SkillHelper.tempData[(buffHandlerVar.source, buff.buffSignal)] = new Dictionary <Type, IBufferValue>();
示例#2
0
        public static int GetBattleRoleCount(DUnit tower)
        {
            NumericComponent numeric = tower.GetComponent <NumericComponent>();
            int halfHpAdd            = (numeric.GetAsInt(NumericType.Hp) - numeric.GetAsInt(NumericType.HpBase)) / 2;

            if (halfHpAdd <= 0)
            {
                return(0);
            }

            int         RoleId     = tower.GetComponent <UTowerConfigComponent>().TowerConfig.RoleId;
            URoleConfig RoleConfig = URoleConfigCategory.Instance.Get(RoleId);

            if (RoleConfig == null)
            {
                return(0);
            }

            return(halfHpAdd / RoleConfig.HP);
        }
示例#3
0
        public static void SummonRoles(DUnit tower, long gamerid, int count, long targetid)
        {
            // 自身血量检测
            NumericComponent numeric = tower.GetComponent <NumericComponent>();
            int hpAdd = (numeric.GetAsInt(NumericType.Hp) - numeric.GetAsInt(NumericType.HpBase));

            if (hpAdd <= 0)
            {
                return;
            }

            // 召唤数量检测
            int roleConfigId = tower.GetComponent <UTowerConfigComponent>().TowerConfig.RoleId;
            int roleHp       = URoleConfigCategory.Instance.Get(roleConfigId).HP;

            if (roleHp * count > hpAdd)
            {
                count = hpAdd / roleHp;
            }

            // 包装召唤ROLE
            DUnitInfo roleinfo = new DUnitInfo();

            roleinfo.GamerId       = gamerid;
            roleinfo.UnitId        = IdGenerater.Instance.GenerateUnitId(0);
            roleinfo.ConfigId      = roleConfigId;
            roleinfo.Camp          = (int)(tower.GetComponent <CampComponent>().Camp);
            roleinfo.PX            = tower.Position.x;
            roleinfo.PY            = tower.Position.y;
            roleinfo.PZ            = tower.Position.z;
            roleinfo.RX            = tower.Rotation.x;
            roleinfo.RY            = tower.Rotation.y;
            roleinfo.RZ            = tower.Rotation.z;
            roleinfo.RW            = tower.Rotation.w;
            roleinfo.Count         = count;
            roleinfo.TargetId      = targetid;
            roleinfo.OperationerId = gamerid;

            RoleFactory.Create(tower.Domain, roleinfo);
        }
    public static void GiveExp(Unit unit, int num, out float preProgress, out float currProgress, out bool lvUp)
    {
        NumericComponent numericComponent = unit.GetComponent <NumericComponent>();

        if (numericComponent.GetAsInt(NumericType.Level) == numericComponent.GetAsInt(NumericType.LevelMax))
        {
            preProgress  = 1;
            currProgress = 1;
            lvUp         = false;
            return;
        }
        Debug.LogFormat("单位{0}获得经验 {1}", unit.Id, num);
        int expMax = numericComponent.GetAsInt(NumericType.ExpMax);
        int preExp = numericComponent.GetAsInt(NumericType.Exp);

        preProgress = preExp / ((float)expMax);
        int currExp = preExp + num;

        lvUp = false;
        if (currExp >= expMax)
        {
            numericComponent.Set(NumericType.Level, numericComponent.GetAsInt(NumericType.Level) + 1);
            lvUp = true;
            Game.EventSystem.Run(EventIdType.UnitLvUp, unit.Id, numericComponent.GetAsInt(NumericType.Level));
            if (numericComponent.GetAsInt(NumericType.Level) == numericComponent.GetAsInt(NumericType.LevelMax))
            {
                currProgress = 1;
                return;
            }
            currExp -= expMax;
            ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>();
            //ExpForLevelUp expConfig = configComponent.Get(typeof(ExpForLevelUp), numericComponent.GetAsInt(NumericType.等级)) as ExpForLevelUp;
            //expMax = expConfig.Exp;
            //numericComponent.Set(NumericType.经验Max, expMax);
        }
        currProgress = Mathf.Clamp01(currExp / ((float)expMax));
        numericComponent.Set(NumericType.Exp, currExp);
    }
    public static bool CalFinalDamage(long sourceUnitId, long destUnitId, DamageData skillDamageValue)
    {
        try
        {
            CharacterStateComponent unitState = UnitComponent.Instance.Get(destUnitId).GetComponent <CharacterStateComponent>();
            if (unitState.Get(SpecialStateType.Die))
            {
                return(false);
            }

            if (unitState.Get(SpecialStateType.Invincible))
            {
                //TODO: 提示无敌状态
                return(false);
            }
            NumericComponent sourceUnitNumericCom = UnitComponent.Instance.Get(sourceUnitId).GetComponent <NumericComponent>();
            NumericComponent destUnitNumericCom   = UnitComponent.Instance.Get(destUnitId).GetComponent <NumericComponent>();
            int rateCharge = 0;
            //命中判定
            float hitRate = sourceUnitNumericCom.GetAsFloat(NumericType.HitRate) - destUnitNumericCom.GetAsFloat(NumericType.DodgeRate);
            rateCharge = RandomHelper.RandomNumber(0, 100);
            if (rateCharge / 100.0f > hitRate)
            {
                Game.EventSystem.Run(EventIdType.AttackMissing, destUnitId);
                Log.Debug("Miss!  命中率 " + hitRate);
                return(false);
            }

            //暴击判定
            //可能有技能提升效果
            if (!skillDamageValue.isCritical)
            {
                float criticalRate = sourceUnitNumericCom.GetAsFloat(NumericType.CritRate);
                rateCharge = RandomHelper.RandomNumber(0, 100);
                if (rateCharge / 100.0f <= criticalRate)
                {
                    //暴击判定通过
                    skillDamageValue.isCritical = true;
                }
            }
            if (skillDamageValue.isCritical)
            {
                skillDamageValue.damageValue = Mathf.RoundToInt(skillDamageValue.damageValue * sourceUnitNumericCom.GetAsFloat(NumericType.CritDamagePct));
            }



            NumericType resistType = NumericType.ArmorResist;

            if (skillDamageValue.damageType != DamageType.Physic)
            {
                resistType = NumericType.MagicResist;
            }
            skillDamageValue.damageValue = Mathf.RoundToInt(skillDamageValue.damageValue * (100.0f / (destUnitNumericCom.GetAsInt(resistType) + 100.0f)));

            //预防可能要考虑什么白字红字,黑字粉字等乱七八糟的情况,所以专门用一个List
            DamageData[] array = new DamageData[1];
            array[0] = skillDamageValue;

            //计算最终伤害加成,减免

            for (int i = 0; i < array.Length; i++)
            {
                var damage = array[i];

                float finalDamagePct = 1 + sourceUnitNumericCom.GetAsFloat(NumericType.FinalDamage_AddPct) - destUnitNumericCom.GetAsFloat(NumericType.FinalDamage_ReducePct);

                damage.damageValue = Mathf.RoundToInt(array[i].damageValue * finalDamagePct);
                //限定最小伤害0
                damage.damageValue = Mathf.Clamp(array[i].damageValue, 0, int.MaxValue);
                array[i]           = damage;
            }


            //给予伤害
            Game.EventSystem.Run(EventIdType.GiveDamage, destUnitId, array);

            //给予吸血,吸法
            float xiQu = sourceUnitNumericCom.GetAsFloat(NumericType.HP_LeechRate);
            if (xiQu > 0)
            {
                Game.EventSystem.Run(EventIdType.GiveHealth, sourceUnitId, Mathf.RoundToInt(skillDamageValue.damageValue * xiQu));
            }
            xiQu = sourceUnitNumericCom.GetAsFloat(NumericType.MP_LeechRate);
            if (xiQu > 0)
            {
                Game.EventSystem.Run(EventIdType.GiveMp, sourceUnitId, Mathf.RoundToInt(skillDamageValue.damageValue * xiQu));
            }
            return(true);
        }
        catch (Exception e)
        {
            Debug.LogError(e.ToString());
            return(false);
        }
    }
        // protected override void Run(Tank entity, C2B_AttackTankRequest message)
        // {
        //     if (entity.Id != message.SourceTankId)
        //     {
        //         Log.Debug("客户端发送炮弹有误");
        //         return;
        //     }
        //
        //     B2C_AttackTankResponse sc = new B2C_AttackTankResponse();
        //
        //     Tank tank = Game.Scene.GetComponent<TankComponent>().Get(message.TargetTankId);
        //
        //     tank.GetComponent<NumericComponent>().Change(NumericType.HpBase, -message.Damage);
        //
        //     sc.SourceTankId = entity.Id;
        //
        //     sc.TargetTankId = message.TargetTankId;
        //
        //     sc.Damage = message.Damage;
        //
        //     entity.BroadcastExceptSelf(sc);
        // }

        protected override async ETTask Run(Tank entity, C2B_AttackTankRequest message, Action <B2C_AttackTankResponse> reply)
        {
            try
            {
                if (entity.Id != message.SourceTankId)
                {
                    Log.Debug("客户端发送炮弹有误");
                    return;
                }

                Tank targetTank = entity.Battle.Get(message.TargetTankId);

                if (entity.TankCamp == targetTank.TankCamp)
                {
                    return;
                }

                if (targetTank.Died)
                {
                    return;
                }

                B2C_AttackTankResponse response = new B2C_AttackTankResponse();

                NumericComponent sourceNumeric = entity.GetComponent <NumericComponent>();

                NumericComponent targetNumeric = targetTank.GetComponent <NumericComponent>();

                int damage = targetNumeric[NumericType.HpBase] < message.Damage ? targetNumeric[NumericType.HpBase] : message.Damage;

                sourceNumeric.Change(NumericType.DamageBase, damage);

                targetNumeric.Change(NumericType.TakeDamageBase, damage);

                int curtHp = targetNumeric.Change(NumericType.HpBase, -damage);

                if (damage != 0 && curtHp == 0)
                {
                    sourceNumeric.Change(NumericType.KillsBase, sourceNumeric.GetAsInt(NumericType.Kills) + 1);

                    targetNumeric.Change(NumericType.DeathsBase, sourceNumeric.GetAsInt(NumericType.Deaths) + 1);
                }

                response.SourceTankId = entity.Id;

                response.TargetTankId = message.TargetTankId;

                response.CurrentHp = curtHp;

                reply(response);

                await ETTask.CompletedTask;

                Send_B2CAttackTank(entity, response.SourceTankId, response.TargetTankId, response.CurrentHp);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            //entity.BroadcastExceptSelf(response);
        }