Exemplo n.º 1
0
        public override CombatStep CalcBattle(Combat combat, CombatVariable atkVal, CombatVariable defVal)
        {
            CombatUnit atker = combat.GetCombatUnit(0);
            CombatUnit defer = combat.GetCombatUnit(1);

            // 防守者是否可反击
            bool canDeferAtk = false;

            if (defer.Role.EquipedWeapon != null)
            {
                Vector3Int       offset  = defer.MapClass.CellPosition - atker.MapClass.CellPosition;
                int              dist    = Mathf.Abs(offset.x) + Mathf.Abs(offset.y);
                WeaponUniqueInfo defInfo = defer.Role.EquipedWeapon.UniqueInfo;

                //if (defInfo.weaponType != WeaponType.Staff)
                {
                    // 如果在反击范围内
                    canDeferAtk |= dist >= defInfo.minRange && dist <= defInfo.maxRange;
                }
            }

            // 根据速度初始化攻击者与防守者
            if (canDeferAtk)
            {
                if (atker.Speed < defer.Speed)
                {
                    CombatUnit tmp = atker;
                    atker = defer;
                    defer = tmp;
                }
            }

            // 更新信息
            Message = "战斗开始";

            atkVal = new CombatVariable(atker.Position, atker.Hp, true, atker.Durability, CombatAnimaType.Prepare);
            defVal = new CombatVariable(defer.Position, defer.Hp, canDeferAtk, defer.Durability, CombatAnimaType.Prepare);

            // 准备阶段
            CombatStep firstStep = new CombatStep(atkVal, defVal);

            return(firstStep);
        }
Exemplo n.º 2
0
        public override CombatStep CalcBattle(Combat combat, CombatVariable atkVal, CombatVariable defVal)
        {
            CombatUnit atker = combat.GetCombatUnit(atkVal.position);
            CombatUnit defer = combat.GetCombatUnit(defVal.position);

            atkVal.animaType = CombatAnimaType.Attack;

            // 真实命中率 = 攻击者命中 - 防守者回避
            int realHit = atker.Hit - defer.Avoidance;

            // 概率是否击中
            int  hitRate = Random.Range(0, 100);
            bool isHit   = hitRate <= realHit;

            if (isHit)
            {
                bool crit    = false; // TODO 是否暴击
                int  realAtk = atker.Atk;

                ///////////////////
                // TODO 触发伤害技能
                //////////////////

                if (crit)
                {
                    realAtk *= 3; // 假定暴击造成三倍伤害
                }

                // 掉血 = 攻击者攻击力 - 防守者防御力
                // 最少不掉血
                int damageHp = Mathf.Max(0, realAtk - defer.Def);
                if (damageHp > defVal.hp)
                {
                    damageHp = defVal.hp;
                }
                defVal.hp -= damageHp;

                atkVal.crit      = crit;
                defVal.animaType = CombatAnimaType.Damage;

                // 更新此次攻击信息
                this.Message = string.Format(
                    "{0} 对 {1} 的攻击造成了 {2} 点伤害{3}。",
                    atker.Role.Character.Info.name,
                    defer.Role.Character.Info.name,
                    damageHp,
                    crit ? "(暴击)" : string.Empty);

                if (defVal.IsDead)
                {
                    Message += string.Format(" {0}被击败了。", defer.Role.Character.Info.name);
                }
            }
            else
            {
                defVal.animaType = CombatAnimaType.Evade;

                // 更新此次躲闪信息
                Message = string.Format(
                    "{1} 躲闪了 {0} 的攻击。",
                    atker.Role.Character.Info.name,
                    defer.Role.Character.Info.name);
            }

            // 只有玩家才会减低耐久度
            if (atker.Role.AttitudeTowards == AttitudeTowards.Player)
            {
                // 攻击者武器耐久度 -1
                atkVal.durability = Mathf.Max(0, atkVal.durability - 1);
            }

            // 攻击者行动过了
            atkVal.action = true;

            CombatStep step = new CombatStep(atkVal, defVal);

            return(step);
        }