Ejemplo n.º 1
0
        public override int takeDamage(int damageType, int damageValue, AttributeDataLogic targetAttribute, Unit target)
        {
            if (!_g12)
            {
                _m12 = instance.Type.GetMethod("takeDamage", 4);
                _g12 = true;
            }

            if (_m12 != null && !_b12)
            {
                _b12   = true;
                _p4[0] = damageType;
                _p4[1] = damageValue;
                _p4[2] = targetAttribute;
                _p4[3] = target;
                int re = (int)appdomain.Invoke(_m12, instance, _p4);
                _p4[0] = null;
                _p4[1] = null;
                _p4[2] = null;
                _p4[3] = null;
                _b12   = false;
                return(re);
            }
            else
            {
                return(base.takeDamage(damageType, damageValue, targetAttribute, target));
            }
        }
Ejemplo n.º 2
0
    /** 构造 */
    public virtual void construct()
    {
        _isDriveAll = !CommonSetting.isSceneServerDrive;

        (status = new StatusDataLogic()).setParent(this);
        (attribute = new AttributeDataLogic()).setParent(this);
        (cd = new CDDataLogic()).setParent(this);
        (buff = GameC.factory.createBuffDataLogic()).setParent(this);
        (avatar = new AvatarDataLogic()).setParent(this);
    }
Ejemplo n.º 3
0
    protected int takeRealDamage(int damageValue, AttributeDataLogic targetAttribute)
    {
        if (damageValue <= 0)
        {
            return(0);
        }

        int hp = targetAttribute.getAttribute(AttributeType.Hp);

        int re = damageValue > hp ? hp : damageValue;

        targetAttribute.subOneAttribute(AttributeType.Hp, damageValue);

        return(re);
    }
Ejemplo n.º 4
0
    /** 生效伤害 */
    public virtual int takeDamage(int damageType, int damageValue, AttributeDataLogic targetAttribute, Unit target)
    {
        switch (damageType)
        {
        case SkillDamageType.PhysicsDamage:
        case SkillDamageType.MagicDamage:
        {
            int shieldType = damageType == SkillDamageType.PhysicsDamage ? AttributeType.PhysicsShield : AttributeType.MagicShield;

            int shield = targetAttribute.getAttribute(shieldType);

            if (shield > 0)
            {
                if (shield >= damageValue)
                {
                    targetAttribute.subOneAttribute(shieldType, damageValue);
                    target.fight.getBuffLogic().onShieldDamage(shieldType, damageValue);
                    damageValue = 0;
                }
                else
                {
                    targetAttribute.subOneAttribute(shieldType, shield);
                    target.fight.getBuffLogic().onShieldDamage(shieldType, shield);

                    damageValue -= shield;
                }
            }

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

            return(takeRealDamage(damageValue, targetAttribute));
        }

        case SkillDamageType.HolyDamage:
        {
            return(takeRealDamage(damageValue, targetAttribute));
        }
        }

        return(0);
    }
Ejemplo n.º 5
0
    /** 析构 */
    public void dispose()
    {
        if (isWorking())
        {
            setIsWorking(false);
        }

        if (_equipTool != null)
        {
            _player.func.removeFuncTool(_equipTool);
            _equipTool.setMUnitLogic(null);
            _equipTool = null;
        }

        _fightLogic.setData(null, null);
        setPlayer(null);

        _data = null;

        _attributeLogic = null;
        _buffLogic      = null;
        index           = -1;
    }
Ejemplo n.º 6
0
    /** 构建战斗逻辑(isRobot:是否是机器人) */
    public void init(MUnitUseData data, bool isClientDrive)
    {
        setData(data);

        MUnitFightDataLogic fightLogic = _fightLogic = GameC.factory.createMUnitFightDataLogic();

        fightLogic.construct();

        if (isClientDrive)
        {
            //开全控
            fightLogic.setIsDriveAll(true);
        }

        //绑定
        fightLogic.setUseLogic(this);
        //构造
        makeFightDataLogic(fightLogic);

        //标记index
        index = fightLogic.index = data.mIndex;

        fightLogic.setData(_data.fight, _data.avatar);

        _attributeLogic = fightLogic.attribute;
        _buffLogic      = fightLogic.buff;

        int fightUnitID = data.getFightUnitID();

        fightLogic.initByFightUnitConfig(fightUnitID);

        if (isClientDrive)
        {
            fightLogic.initByFightUnitLevelConfig(fightUnitID, data.level);
        }
    }
Ejemplo n.º 7
0
    public override void onRefreshHp()
    {
        AttributeDataLogic attributeDataLogic = _unit.fight.getAttributeLogic();

        _bloodImage.image.fillAmount = attributeDataLogic.getHpPercent();
    }
Ejemplo n.º 8
0
    /** 执行攻击数据 */
    private void toExecuteAttack(AttackData data)
    {
        Unit from = _scene.getFightUnit(data.fromInstanceID);

        if (from == null)
        {
            return;
        }

        Unit attacker = from.fight.getAttackerUnit();

        if (attacker == null)
        {
            return;
        }

        int attackerInstanceID = attacker.instanceID;

        SkillTargetData   tData       = data.targetData;
        AttackConfig      config      = data.config;
        AttackLevelConfig levelConfig = data.levelConfig;

        //主目标
        Unit mTarget = _scene.getFightUnit(tData.targetInstanceID);

        SList <Unit> tempTargets = new SList <Unit>();

        //构造目标组
        toMakeTargets(tempTargets, from, attacker, mTarget, tData, config, levelConfig);

        Unit target;

        //TODO:攻击前动作组

        //如果跳过伤害阶段
        if (config.passDamage)
        {
            for (int i = 0, len = tempTargets.size(); i < len; ++i)
            {
                target = tempTargets[i];

                //不可被攻击
                if (target.fight.getStatusLogic().cantBeAttackTarget())
                {
                    continue;
                }

                //添加buff
                if (levelConfig.addBuffProbID > 0)
                {
                    if (attacker.fight.randomProb(levelConfig.addBuffProbID))
                    {
                        int adderInstanceID = attackerInstanceID == target.instanceID ? -1 :attackerInstanceID;

                        foreach (DIntData v in levelConfig.addBuffs)
                        {
                            target.fight.getBuffLogic().addBuff(v.key, v.value, adderInstanceID);
                        }
                    }
                }

                //有子弹
                if (levelConfig.bullet.key > 0)
                {
                    from.fight.createAndExecuteBullet(levelConfig.bullet.key, levelConfig.bullet.value, tData);
                }
            }
        }
        else
        {
            doAttackMoment(AttackMomentType.AttackBeforeHit, @from, attacker, null, data, null);

            if (!tempTargets.isEmpty())
            {
                SList <Unit> tempKilledUnits = null;

                SList <DamageOneData> damageDataList = new SList <DamageOneData>();

                StatusDataLogic    attackerStatus    = attacker.fight.getStatusLogic();
                AttributeDataLogic attackerAttribute = attacker.fight.getAttributeLogic();
                BuffDataLogic      attackerBuffLogic = attacker.fight.getBuffLogic();
                StatusDataLogic    targetStatus;
                AttributeDataLogic targetAttribute;

                bool momentHitted = false;

                for (int i = 0, len = tempTargets.size(); i < len; ++i)
                {
                    target = tempTargets[i];

                    targetStatus    = target.fight.getStatusLogic();
                    targetAttribute = target.fight.getAttributeLogic();

                    //不可被攻击
                    if (targetStatus.cantBeAttackTarget())
                    {
                        continue;
                    }

                    //上次血量
                    int lastHp = targetAttribute.getHp();

                    DamageOneData damageOneData = new DamageOneData();
                    damageOneData.instanceID = target.instanceID;

                    damageDataList.add(damageOneData);

                    SList <DIntData> damageList = new SList <DIntData>();
                    damageOneData.damages = damageList;

                    damageOneData.isHit = toCountIsHit(data, attacker, target);

                    doAttackMoment(AttackMomentType.BeAttackBeforeHit, target, target, attacker, data, damageOneData);

                    int realDamage = 0;

                    if (damageOneData.isHit)
                    {
                        if (!momentHitted)
                        {
                            momentHitted = true;
                            doAttackMoment(AttackMomentType.AttackOnHitAnyTarget, @from, attacker, target, data, damageOneData);
                        }

                        if (target == mTarget)
                        {
                            doAttackMoment(AttackMomentType.AttackBeforeDamageMainTarget, @from, attacker, target, data, damageOneData);
                        }

                        doAttackMoment(AttackMomentType.AttackBeforeDamageEachTarget, @from, attacker, target, data, damageOneData);
                        doAttackMoment(AttackMomentType.BeAttackBeforeDamage, target, target, attacker, data, damageOneData);

                        //添加buff
                        if (levelConfig.addBuffProbID > 0)
                        {
                            if (attacker.fight.randomProb(levelConfig.addBuffProbID))
                            {
                                int adderInstanceID = attackerInstanceID == target.instanceID ? -1 :attackerInstanceID;

                                foreach (DIntData v in levelConfig.addBuffs)
                                {
                                    target.fight.getBuffLogic().addBuff(v.key, v.value, adderInstanceID);
                                }
                            }
                        }

                        //有子弹
                        DIntData levelConfigBullet;

                        if ((levelConfigBullet = levelConfig.bullet).key > 0)
                        {
                            from.fight.createAndExecuteBullet(levelConfigBullet.key, levelConfigBullet.value, tData);
                        }

                        bool isCrit = damageOneData.isCrit = toCountIsCrit(data, attacker, target);

                        SkillVarConfig varConfig;
                        int[]          damages;
                        int            damageType;
                        int            damageValue;
                        int            attackValue;
                        int            damageVarIndex = 0;

                        //伤害组
                        for (int j = 0, jLen = levelConfig.damages.Length; j < jLen; ++j)
                        {
                            varConfig  = levelConfig.varConfigT[j];
                            damages    = levelConfig.damages[j];
                            damageType = damages[0];

                            if (data.isRecorded)
                            {
                                attackValue     = BaseGameUtils.calculateSkillVarValueForSelf(varConfig, data.selfAttackValues, damageVarIndex, target.fight.getDataLogic());
                                damageVarIndex += varConfig.args.Length;
                            }
                            else
                            {
                                attackValue = BaseGameUtils.calculateSkillVarValueFull(varConfig, attacker.fight.getDataLogic(), target.fight.getDataLogic());
                            }

                            damageValue = toCalculateDamage(data, damageType, damages, attackValue, isCrit, attackerAttribute, targetAttribute, attacker, target);

                            if (damageValue > 0)
                            {
                                if (needDamageHurt(damageType))
                                {
                                    int rd = 0;

                                    if (!targetStatus.isDamageImmun())
                                    {
                                        rd = takeDamage(damageType, damageValue, targetAttribute, target);
                                    }

                                    if (Global.damageValueUseRealDamage)
                                    {
                                        damageValue = rd;
                                    }

                                    realDamage += rd;
                                }

                                //TODO:反伤类

                                damageList.add(DIntData.create(damageType, damageValue));
                            }
                        }

                        if (realDamage > 0)
                        {
                            _scene.method.onUnitTakeDamage(target, realDamage, attacker);
                        }

                        if (target == mTarget)
                        {
                            doAttackMoment(AttackMomentType.AttackAfterDamageMainTarget, @from, attacker, target, data, damageOneData);
                        }

                        doAttackMoment(AttackMomentType.AttackAfterDamageEachTarget, @from, attacker, target, data, damageOneData);
                        doAttackMoment(AttackMomentType.BeAttackAfterDamage, target, target, attacker, data, damageOneData);

                        //扣除buff次数
                        attackerBuffLogic.subBuffNumArr(BuffSubNumType.UseAttackFromGroup, config.groups);
                        attackerBuffLogic.subBuffNumArr(BuffSubNumType.MakeDamage, levelConfig.damageTypesT);
                        target.fight.getBuffLogic().subBuffNumArr(BuffSubNumType.BeDamage, levelConfig.damageTypesT);

                        //血减到0
                        if (lastHp > 0 && targetAttribute.getAttribute(AttributeType.Hp) <= 0 && targetStatus.isAlive())
                        {
                            if (tempKilledUnits == null)
                            {
                                tempKilledUnits = new SList <Unit>();
                            }

                            tempKilledUnits.add(target);
                        }
                    }

                    //受伤(客户端受伤即使realDamage为0也需要)
                    target.fight.onDamage(from, attacker, config, damageOneData);
                }

                onAttackDamage(from, config, tData);

                //处理击杀
                if (tempKilledUnits != null)
                {
                    for (int i = 0, len = tempKilledUnits.size(); i < len; ++i)
                    {
                        //活着
                        if ((target = tempKilledUnits[i]).fight.isAlive())
                        {
                            //被击杀时刻
                            doAttackMoment(AttackMomentType.BeforeBeKill, target, target, attacker, data, null);

                            //可被伤害击杀
                            if (!target.fight.getStatusLogic().cantBeKillByDamage())
                            {
                                target.fight.doDead(attacker, config.killType);
                            }

                            //击杀时刻
                            doAttackMoment(AttackMomentType.AfterKill, from, attacker, target, data, null);
                        }
                    }
                }
            }

            doAttackMoment(AttackMomentType.AttackAfterHit, from, attacker, null, data, null);
        }
    }
Ejemplo n.º 9
0
    /** 计算对单个单位的伤害(范围伤害值) */
    public int toCalculateDamage(AttackData data, int damageType, int[] damages, int attackValue, bool isCrit, AttributeDataLogic attackerAttribute, AttributeDataLogic targetAttribute, Unit attacker, Unit target)
    {
        int damageValue;

        switch (damageType)
        {
        case SkillDamageType.PhysicsDamage:
        case SkillDamageType.MagicDamage:
        case SkillDamageType.HolyDamage:
        {
            damageValue = calculateDamage(damages, attackValue, isCrit, attackerAttribute, targetAttribute, attacker, target, data);
        }
        break;

        case SkillDamageType.HpAdd:
        {
            damageValue = attackValue;

            if (!target.fight.getStatusLogic().cantBeHeal())
            {
                int healV = targetAttribute.getAddRatioResult(AttributeType.HealAddPercent, damageValue);
                targetAttribute.addOneAttribute(AttributeType.Hp, healV);
            }
        }
        break;

        case SkillDamageType.MpAdd:
        {
            damageValue = attackValue;
            targetAttribute.addOneAttribute(AttributeType.Mp, damageValue);
        }
        break;

        case SkillDamageType.MpSub:
        {
            damageValue = attackValue;
            targetAttribute.subOneAttribute(AttributeType.Mp, damageValue);
        }
        break;

        default:
        {
            damageValue = calculateDamage(damages, attackValue, isCrit, attackerAttribute, targetAttribute, attacker, target, data);
        }
        break;
        }

        return(damageValue);
    }
Ejemplo n.º 10
0
    /** 计算伤害 */
    public int calculateDamage(int[] damages, int attackValue, bool isCrit, AttributeDataLogic attackerAttribute, AttributeDataLogic targetAttribute, Unit attacker, Unit target, AttackData data)
    {
        int   damageType;
        float damage = 0f;

        switch ((damageType = damages[0]))
        {
        case SkillDamageType.PhysicsDamage:
        case SkillDamageType.MagicDamage:
        {
            int defence;
            int addPercent;
            int deratePercent;

            if (damageType == SkillDamageType.PhysicsDamage)
            {
                defence       = targetAttribute.getAttribute(AttributeType.PhysicsDefence);
                addPercent    = attackerAttribute.getAttribute(AttributeType.PhysicsDamageAddPercent);
                deratePercent = targetAttribute.getAttribute(AttributeType.PhysicsDamageDeratePercent);
            }
            else
            {
                defence       = targetAttribute.getAttribute(AttributeType.MagicDefence);
                addPercent    = attackerAttribute.getAttribute(AttributeType.MagicDamageAddPercent);
                deratePercent = targetAttribute.getAttribute(AttributeType.MagicDamageDeratePercent);
            }

            damage = toCalculateBaseDamage(damages, attackValue, defence);

            if (isCrit)
            {
                damage = damageCrit(damage, attackerAttribute.getAttribute(AttributeType.CritDamagePercentAdd));
            }

            damage = damageRandom(damage, attackerAttribute.getAttribute(AttributeType.DamageRandomRatio));

            //伤害增加
            if (addPercent != 0)
            {
                float percent = (1 + addPercent / 1000f);

                if (percent > 0f)
                {
                    damage *= percent;
                }
                else
                {
                    damage = 0f;
                }
            }

            //伤害减少
            if (deratePercent != 0)
            {
                float percent = (1 - deratePercent / 1000f);

                if (percent > 0f)
                {
                    damage *= percent;
                }
                else
                {
                    damage = 0f;
                }
            }
        }
        break;

        case SkillDamageType.HolyDamage:
        {
            damage = toCalculateBaseDamage(damages, attackValue, 0);

            if (isCrit)
            {
                damage = damageCrit(damage, attackerAttribute.getAttribute(AttributeType.CritDamagePercentAdd));
            }

            damage = damageRandom(damage, attackerAttribute.getAttribute(AttributeType.DamageRandomRatio));
        }
        break;
        }

        int allDeratePercent = targetAttribute.getAttribute(AttributeType.AllDemageDeratePercent);

        if (allDeratePercent != 0)
        {
            float percent = (1 - allDeratePercent / 1000f);

            if (percent > 0f)
            {
                damage *= percent;
            }
            else
            {
                damage = 0f;
            }
        }

        return((int)damage);
    }
Ejemplo n.º 11
0
    /** 每秒十次 */
    public void onPiece(int delay)
    {
        if (!_buffDatas.isEmpty())
        {
            //是客户端驱动
            if (_parent.isSelfDriveAttackHapen())
            {
                //先触发间隔
                if (!_intervalActions.isEmpty())
                {
                    AttributeDataLogic attributeLogic = _parent.attribute;

                    foreach (BuffIntervalActionData v in _intervalActions)
                    {
                        v.timePass += delay;

                        if (v.timePass >= v.delay)
                        {
                            v.timePass -= v.delay;

                            switch (v.type)
                            {
                            case BuffIntervalActionType.Attack:
                            {
                                //触发一次
                                _parent.doBuffIntervalAttack(v);
                            }
                            break;

                            case BuffIntervalActionType.AddAttribute:
                            {
                                if (!_parent.isDriveAll())
                                {
                                    return;
                                }

                                attributeLogic.addOneAttribute(v.key, v.value);
                            }
                            break;

                            case BuffIntervalActionType.AddAttributeVar:
                            {
                                if (!_parent.isDriveAll())
                                {
                                    return;
                                }

                                attributeLogic.addOneAttribute(v.key, _parent.getSkillVarValueT(v.value, v.adderInstanceID));
                            }
                            break;
                            }
                        }
                    }
                }
            }

            foreach (BuffData data in _buffDatas)
            {
                //有持续时间
                if (data.lastTime > 0)
                {
                    if ((data.lastTime -= delay) <= 0)
                    {
                        data.lastTime = 0;

                        //本端驱动才移除
                        if (_parent.isDriveAll())
                        {
                            buffOver(data);
                        }
                    }
                }
            }
        }
    }