private void CalculateShowForecast(TacticsMove attacker, TacticsMove defender)
    {
        bool         isDamage = (currentMode.value == ActionMode.ATTACK);
        BattleAction act1     = new BattleAction(true, isDamage, attacker, defender);

        if (isDamage)
        {
            BattleAction act2     = new BattleAction(false, true, defender, attacker);
            int          distance = MapCreator.DistanceTo(defender, walkTile.value);
            int          atk      = (attacker.GetWeapon().InRange(distance)) ? act1.GetDamage() : -1;
            int          def      = (defender.GetWeapon() != null && defender.GetWeapon().InRange(distance)) ? act2.GetDamage() : -1;
            int          spd      = attacker.stats.spd - defender.stats.spd;
            bool         atkWeak  = attacker.stats.IsWeakAgainst(defender.stats.GetWeapon());
            bool         defWeak  = defender.stats.IsWeakAgainst(attacker.stats.GetWeapon());
            ShowForecast(attacker, defender, atk, def, spd, act1.GetAdvantage(), atkWeak, defWeak);
        }
        else
        {
            ShowHealForecast(attacker, defender, act1.GetHeals());
        }
    }
Exemplo n.º 2
0
    private void CalculateShowForecast(TacticsMove attacker, MapTile target)
    {
        if (target.currentCharacter == null)
        {
            // BLOCK FIGHT
            TacticsMove       defender   = target.blockMove;
            BattleAction.Type battleMode = (currentMode.value == ActionMode.ATTACK) ? BattleAction.Type.DAMAGE : BattleAction.Type.HEAL;
            BattleAction      act1       = new BattleAction(AttackSide.LEFT, battleMode, attacker, defender);
            _attackerTactics = attacker;
            _defenderTactics = defender;
            act1.weaponAtk   = attacker.inventory.GetTuple(battleWeaponIndex.value);

            if (battleMode == BattleAction.Type.DAMAGE)
            {
                int  distance = BattleMap.DistanceTo(attacker, target);
                int  atk      = (act1.weaponAtk.InRange(distance)) ? act1.GetDamage() : -1;
                int  ret      = -1;
                int  spd      = 0;
                int  hit      = (atk != -1) ? act1.GetHitRate() : -1;
                int  hit2     = -1;
                int  crit     = -1;
                int  crit2    = -1;
                bool atkWeak  = false;
                bool defWeak  = false;
                UpdateHealthUI();
                ShowAttackerStats(attacker, act1.weaponAtk, atk, spd, hit, crit, atkWeak);
                ShowDefenderStats(defender, new InventoryTuple(null), ret, spd, hit2, crit2, defWeak);
                if (!inBattle)
                {
                    backgroundFight.SetActive(true);
                    backgroundHeal.SetActive(false);
                }
            }
        }
        else
        {
            TacticsMove       defender   = target.currentCharacter;
            BattleAction.Type battlemode = (currentMode.value == ActionMode.ATTACK) ? BattleAction.Type.DAMAGE : BattleAction.Type.HEAL;
            BattleAction      act1       = new BattleAction(AttackSide.LEFT, battlemode, attacker, defender);
            _attackerTactics = attacker;
            _defenderTactics = defender;
            act1.weaponAtk   = attacker.inventory.GetTuple(battleWeaponIndex.value);

            if (inBattle)
            {
                if (battlemode == BattleAction.Type.DAMAGE)
                {
                    attackerView.SetActive(true);
                    defenderView.SetActive(true);
                    healerView.SetActive(false);
                }
                else
                {
                    attackerView.SetActive(false);
                    defenderView.SetActive(false);
                    healerView.SetActive(true);
                }
            }

            if (battlemode == BattleAction.Type.DAMAGE)
            {
                BattleAction act2 = new BattleAction(AttackSide.RIGHT, BattleAction.Type.DAMAGE, defender, attacker);
                act2.weaponDef = attacker.inventory.GetTuple(battleWeaponIndex.value);
                int  distance = BattleMap.DistanceTo(defender, walkTile.value);
                int  atk      = (act1.weaponAtk.InRange(distance)) ? act1.GetDamage() : -1;
                int  ret      = (act1.DefenderInRange(distance)) ? act2.GetDamage() : -1;
                int  spd      = act1.GetSpeedDifference();
                int  hit      = (atk != -1) ? act1.GetHitRate() : -1;
                int  hit2     = (ret != -1) ? act2.GetHitRate() : -1;
                int  crit     = (atk != -1) ? act1.GetCritRate() : -1;
                int  crit2    = (ret != -1) ? act2.GetCritRate() : -1;
                bool atkWeak  = act1.CheckWeaponWeakness();
                bool defWeak  = act2.CheckWeaponWeakness();
                UpdateHealthUI();
                ShowAttackerStats(attacker, act1.weaponAtk, atk, spd, hit, crit, atkWeak);
                ShowDefenderStats(defender, act2.weaponAtk, ret, spd, hit2, crit2, defWeak);
                if (!inBattle)
                {
                    backgroundFight.SetActive(true);
                    backgroundHeal.SetActive(false);
                }
            }
            else
            {
                ShowHealForecast(attacker, defender, act1.staffAtk);
                if (!inBattle)
                {
                    backgroundFight.SetActive(false);
                    backgroundHeal.SetActive(true);
                }
            }
        }
    }
    private IEnumerator ActionLoop()
    {
        leftDamageObject.SetActive(false);
        rightDamageObject.SetActive(false);
        leftTransform.GetComponent <SpriteRenderer>().sprite  = actions[0].attacker.stats.battleSprite;
        rightTransform.GetComponent <SpriteRenderer>().sprite = actions[0].defender.stats.battleSprite;
        leftTransform.GetComponent <SpriteRenderer>().color   = Color.white;
        rightTransform.GetComponent <SpriteRenderer>().color  = Color.white;

        for (int i = 0; i < actions.Count; i++)
        {
            BattleAction act              = actions[i];
            Transform    attackTransform  = (!useBattleAnimations.value) ? act.attacker.transform : (act.leftSide) ? leftTransform : rightTransform;
            Transform    defenseTransform = (!useBattleAnimations.value) ? act.defender.transform : (act.leftSide) ? rightTransform : leftTransform;
            Vector3      startPos         = attackTransform.localPosition;
            Vector3      enemyPos         = defenseTransform.localPosition;
            enemyPos = startPos + (enemyPos - startPos).normalized;

            battleAnimationObject.SetActive(useBattleAnimations.value);
            if (useBattleAnimations.value)
            {
                leftHealth.fillAmount  = actions[0].attacker.GetHealthPercent();
                rightHealth.fillAmount = actions[0].defender.GetHealthPercent();
                yield return(new WaitForSeconds(1f));
            }

            //Move forward
            float f = 0;
            Debug.Log("Start moving");
            while (f < 0.5f)
            {
                f += Time.deltaTime * speed;
                attackTransform.localPosition = Vector3.Lerp(startPos, enemyPos, f);
                yield return(null);
            }
            // Deal damage
            if (act.isDamage)
            {
                int damage = act.GetDamage();
                if (act.attacker.SkillReady(SkillType.DAMAGE))
                {
                    damage = act.attacker.GetSkill().GenerateDamage(damage);
                    act.attacker.skillCharge = -1;
                    Debug.Log("Bonus damage!");
                }
                act.defender.TakeDamage(damage);
                StartCoroutine(DamageDisplay(act.leftSide, damage, true));

                Debug.Log(i + " Dealt damage :  " + damage);
                if (act.attacker.SkillReady(SkillType.HEAL))
                {
                    int health = act.attacker.GetSkill().GenerateHeal(damage);
                    act.attacker.skillCharge = -1;
                    act.attacker.TakeHeals(health);
                    rightDamageText.text = damage.ToString();
                    StartCoroutine(DamageDisplay(!act.leftSide, damage, false));
                    Debug.Log(i + " Healt damage :  " + health);
                }

                if (!act.defender.IsAlive())
                {
                    if (act.leftSide)
                    {
                        rightTransform.GetComponent <SpriteRenderer>().color = new Color(0.4f, 0.4f, 0.4f);
                    }
                    else
                    {
                        leftTransform.GetComponent <SpriteRenderer>().color = new Color(0.4f, 0.4f, 0.4f);
                    }
                }

                //Add skill charges
                act.attacker.IncreaseSkill();
                act.defender.IncreaseSkill();
            }
            else
            {
                if (act.attacker.GetSupport().supportType == SupportType.HEAL)
                {
                    int health = act.GetHeals();
                    act.defender.TakeHeals(health);
                    StartCoroutine(DamageDisplay(act.leftSide, health, false));
                    Debug.Log(i + " Healt damage :  " + health);
                    if (act.attacker.faction == Faction.PLAYER)
                    {
                        act.attacker.GainSP(1, true);
                    }
                }
                else if (act.attacker.GetSupport().supportType == SupportType.BUFF)
                {
                    act.defender.ReceiveBuff(act.attacker.GetSupport().boost, true, true);
                    Debug.Log("Boost them up!");
                }
            }
            //Update health
            leftHealth.fillAmount  = (act.leftSide) ? act.attacker.GetHealthPercent() : act.defender.GetHealthPercent();
            rightHealth.fillAmount = (act.leftSide) ? act.defender.GetHealthPercent() : act.attacker.GetHealthPercent();

            // Move back
            Debug.Log("Moving back");
            while (f > 0f)
            {
                f -= Time.deltaTime * speed;
                attackTransform.localPosition = Vector3.Lerp(startPos, enemyPos, f);
                yield return(null);
            }

            //Check Death
            Debug.Log("Check death");
            if (!act.defender.IsAlive())
            {
                if (act.attacker.faction == Faction.PLAYER)
                {
                    act.attacker.GainSP(3, true);
                }
                yield return(new WaitForSeconds(1f));

                break;
            }
        }

        //Handle exp
        yield return(StartCoroutine(ShowExpGain()));

        //Give debuffs
        if (actions[0].isDamage)
        {
            actions[0].attacker.ActivateSkills(Activation.POSTCOMBAT, actions[0].defender);
            actions[0].defender.ActivateSkills(Activation.POSTCOMBAT, actions[0].attacker);
        }

        //Check game finished
        battleFinishedEvent.Invoke();

        //Clean up
        battleAnimationObject.SetActive(false);
        leftDamageObject.SetActive(false);
        rightDamageObject.SetActive(false);
        actions[0].attacker.EndSkills(Activation.INITCOMBAT, actions[0].defender);
        actions[0].attacker.EndSkills(Activation.PRECOMBAT, actions[0].defender);
        actions[0].defender.EndSkills(Activation.PRECOMBAT, actions[0].attacker);
        actions.Clear();
        TurnController.busy = false;
        _currentCharacter.End();
        _currentCharacter = null;
    }