Example #1
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);
    }
Example #2
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;
    }
Example #3
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);
        }
    }
Example #4
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);
        }
    }
Example #5
0
 /** 设置buff数据逻辑 */
 public void setBuffDataLogic(BuffDataLogic logic)
 {
     (buff = logic).setParent(this);
 }