Esempio n. 1
0
    public IEnumerator ResolveTurn(Attack attack, Fighter[] targets)
    {
        combat3DUI.ClearSkills();
        currentAttack = attack;

        AudioManager.instance.PlayAttack(attack.attackSound);

        currentFighter.Get3D().TriggerAttackAnimation();
        if (attack.attackPrefab != null)
        {
            EffectGenerator.instance.SpawnEffect(attack.attackPrefab,
                                                 currentFighter.Get3D().transform);
        }

        if (!attack.specialBehaviour)
        {
            yield return(StartCoroutine(currentFighter.ChangeMana(-attack._cost)));

            yield return(new WaitForSeconds(FastMode.instance.GetAttackDelay()));

            //Damage calculation
            float totalDmg = 0;
            if (attack.damage > 0)
            {
                float relicMultiplier = 1.0f;
                if (RelicManager.instance != null && FighterBelongsToTeamA(currentFighter))
                {
                    yield return(StartCoroutine(RelicManager.instance.PlayerAttack()));

                    relicMultiplier = RelicManager.instance.multiplier;
                }

                for (int i = 0; i < targets.Length; i++)
                {
                    currentFighter.Get3D().TriggerDamageAnimation();
                    if (attack.attackTakePrefab != null)
                    {
                        EffectGenerator.instance.SpawnEffect(attack.attackTakePrefab,
                                                             targets[i].Get3D().transform);
                    }

                    //Critic chance
                    float dmg    = attack.damage;
                    bool  critic = false;

                    if (!attack.noCritic && !targets[i].criticInmune)
                    {
                        var random = UnityEngine.Random.Range(0f, 1f);
                        if (random <= currentFighter._critChance)
                        {
                            critic = true;
                            dmg   += currentFighter._criticBonus * attack.damage;
                        }
                    }


                    StartCoroutine(targets[i].TakeDamage(dmg * relicMultiplier, currentFighter.GetStr(), critic));
                    while (targets[i].calculatingTotalDmg)
                    {
                        yield return(0);
                    }
                    totalDmg += targets[i].damageToReceive;
                }

                while (damageTakingCalulations > 0)
                {
                    yield return(0);
                }

                // ------- Events ------ //
                EventManager.CombatEvent eventParam = new EventManager.CombatEvent();
                eventParam.caster   = currentFighter;
                eventParam.totalDmg = totalDmg;
                EventManager.TriggerEvent(EventManager.combatEvents.fullDamageCalculation, eventParam);
                while (runningEvents > 0)
                {
                    yield return(0);
                }
                // --------------------- //
            }
            //Healing calculation
            float totalHealing = 0f;
            if (attack.health != 0)
            {
                for (int i = 0; i < targets.Length; i++)
                {
                    if (targets[i].defeated)
                    {
                        continue;
                    }
                    //Critic chance
                    float hl     = attack.health;
                    bool  critic = false;
                    var   random = UnityEngine.Random.Range(0f, 1f);
                    if (random <= currentFighter._critChance)
                    {
                        critic = true;
                        hl    += currentFighter._criticBonus * attack.health;
                    }

                    // Wait for last coroutine to finish
                    StartCoroutine(targets[i].Heal(hl, critic));
                    totalHealing += targets[i].healingToReceive;
                }

                while (damageTakingCalulations > 0)
                {
                    yield return(0);
                }

                // ------- Events ------ //
                EventManager.CombatEvent eventParam = new EventManager.CombatEvent();
                eventParam.caster       = currentFighter;
                eventParam.totalHealing = totalHealing;
                EventManager.TriggerEvent(EventManager.combatEvents.fullHealingCalculation, eventParam);
                while (runningEvents > 0)
                {
                    yield return(0);
                }
                // --------------------- //
            }
        }
        else
        {
            yield return(StartCoroutine(attack.ResolveAttack(currentFighter, targets)));
        }

        for (int i = 0; i < attack.hotDot.Length; i++)
        {
            for (int j = 0; j < targets.Length; j++)
            {
                if (targets[j].defeated)
                {
                    continue;
                }

                var hotdot = new HotDot.HotDotInstance(attack.hotDot[i], attack.hotDot[i].uniqueApplied?
                                                       attack.hotDot[i].hotdotID :
                                                       attack.hotDot[i].hotdotID + attack.attackName + currentFighter.fighterName, currentFighter);


                yield return(StartCoroutine(targets[j].GetDotManager().AddNewHotDot(hotdot)));
            }
        }

        yield return(StartCoroutine(EndTurn()));
    }
Esempio n. 2
0
    public IEnumerator InitializeCombat(Fighter[] teamA, Fighter[] teamB, List <GlobalBuffs.GlobalHotDot> globalHotDots, Climate climate)
    {
        StopAllCoroutines();

        this.teamA = RelicManager.instance.CombatStart(teamA);

        this.teamB     = teamB;
        ended          = false;
        currentFighter = null;
        this.climate   = climate;

        if (climate != null)
        {
            climate.Setup();
        }

        //combatUI.InitializeCombat(teamA, teamB);
        combat3Dcontroller.Setup(this.teamA, teamB);
        combat3DUI.InitializeUI(this.teamA, teamB);

        foreach (Fighter f in GetAllFighters())
        {
            f.OnDeath.AddListener(CheckDeath);
        }

        if (ExperienceManager.instance != null)
        {
            ExperienceManager.instance.CalculatePotentialExperience(this);
        }

        StoreAllFightersInSpeedList();
        SortSpeedList();
        CombatSpeedElementManager.instance.SetupPanel(speedList);


        // ------- Events ------ //
        EventManager.CombatEvent eventParam = new EventManager.CombatEvent();
        EventManager.TriggerEvent(EventManager.combatEvents.combatStart, eventParam);

        // --------------------- //

        foreach (GlobalBuffs.GlobalHotDot globalHotDot in globalHotDots)
        {
            if (globalHotDot.combatsLeft > 0)
            {
                if (globalHotDot.affectsAllies)
                {
                    for (int i = 0; i < this.teamA.Length; i++)
                    {
                        var hotdot = new HotDot.HotDotInstance(globalHotDot.hotdot, globalHotDot.hotdot.hotdotID + this.teamA[i].fighterName, null);
                        yield return(StartCoroutine(this.teamA[i].GetDotManager().AddNewHotDot(hotdot)));
                    }
                }
                if (globalHotDot.affectsEnemies)
                {
                    for (int i = 0; i < teamB.Length; i++)
                    {
                        var hotdot = new HotDot.HotDotInstance(globalHotDot.hotdot, globalHotDot.hotdot.hotdotID + teamB[i].fighterName, null);
                        yield return(StartCoroutine(teamB[i].GetDotManager().AddNewHotDot(hotdot)));
                    }
                }
            }
        }

        if (RelicManager.instance != null)
        {
            RelicManager.instance.InitializeAll();
        }

        StartCoroutine(NextTurn());
    }