示例#1
0
    protected IEnumerator performAttack()
    {
        if (meleeRangeFound)
        {
            StopCoroutine("getInMeleeRange");
        }
        else
        {
            if (getMarkedActors().Count == 1)
            {
                getTurnOwnerTarget().actor.transform.LookAt(getSingleTarget().actor.transform);
            }
            else
            {
                int halfPoint = Mathf.CeilToInt(getMarkedActors().Count / 2);
                getTurnOwnerTarget().actor.transform.LookAt(getMarkedActors()[halfPoint].actor.transform);
            }
        }

        bool multiTargetAttack = false;
        int  halfStare;

        if (getMarkedActors().Count != 1)
        {
            halfStare         = Mathf.FloorToInt(getMarkedActors().Count / 2);
            multiTargetAttack = true;
        }
        else
        {
            halfStare = 1;
        }

        BattleTarget myUser = getTurnOwnerTarget();

        if (multiTargetAttack)
        {
            if (isEnemy(myUser.actor))
            {
                myUser.actor.transform.LookAt(party[halfStare].actor.transform);
            }
            else
            {
                myUser.actor.transform.LookAt(enemies[halfStare].actor.transform);
            }
        }
        else
        {
            myUser.actor.transform.LookAt(getSingleTarget().actor.transform);
        }

        //Wait until cast animation complete
        //myUser.actor.GetComponent<Animator>().SetBool("casting", true);

        //yield new WaitForSeconds(animationClip.length);

        ActorBase myUserBase = myUser.actor.GetComponent <ActorBase>();

        //Calculate Damage and perform skill FX on enemies
        //FX works by instiating an prefab on target and having the FX script fade it into oblivion...
        //FX also includes the scrolling damage text included in newEffects list
        List <BattleTarget> tars = getMarkedActors();

        foreach (BattleTarget tar in tars)
        {
            float damage       = 0;
            float defendDamage = 0;
            int   finalDamage  = 0;

            ActorBase myBase = tar.actor.GetComponent <ActorBase>();

            Elements myEle    = myBase.myElement;
            Elements myOppEle = myBase.myOppElement;

            //Algorithms are modified algorithms based off Final Fantasy X
            //Reference: http://www.gamefaqs.com/ps2/197344-final-fantasy-x/faqs/31381

            if (executingSkill.effectType == EffectType.HEAL || executingSkill.effectType == EffectType.APPLY_EFF)
            {
                //Play cast animation
                if (myUser.actor.GetComponent <Actor>().hasAnimation("Cast"))
                {
                    myUser.actor.GetComponent <Actor>().playAnim("Cast");
                    yield return(new WaitForSeconds(1));
                }
            }
            else
            {
                //Play attack animation
                if (meleeRangeFound)
                {
                    if (myUser.actor.GetComponent <Actor>().hasAnimation("Attack"))
                    {
                        myUser.actor.GetComponent <Actor>().playAnim("Attack");
                        yield return(new WaitForSeconds(0.4f));

                        if (tar.actor.GetComponent <Actor>().hasAnimation("Hit"))
                        {
                            tar.actor.GetComponent <Actor>().playAnim("Hit");
                        }
                    }
                }
                else
                {
                    if (executingSkill.effectType == EffectType.PHYSICAL_DAMAGE)
                    {
                        if (myUser.actor.GetComponent <Actor>().hasAnimation("RAttack"))
                        {
                            myUser.actor.GetComponent <Actor>().playAnim("RAttack");
                            yield return(new WaitForSeconds(0.4f));

                            if (tar.actor.GetComponent <Actor>().hasAnimation("Hit"))
                            {
                                tar.actor.GetComponent <Actor>().playAnim("Hit");
                            }
                        }
                    }
                    else
                    {
                        if (myUser.actor.GetComponent <Actor>().hasAnimation("MAttack"))
                        {
                            myUser.actor.GetComponent <Actor>().playAnim("MAttack");
                            yield return(new WaitForSeconds(0.8f));

                            if (tar.actor.GetComponent <Actor>().hasAnimation("Hit"))
                            {
                                tar.actor.GetComponent <Actor>().playAnim("Hit");
                            }
                        }
                    }
                }
            }

            //do {
            //	yield return new WaitForSeconds(0.25f);
            //}while (myUser.actor.GetComponent<Actor>().myAnim.isPlaying && myUser.actor.GetComponent<Actor>().myAnim.clip.name.ToLower().Trim () != "idle");

            if (executingSkill.effectType == EffectType.PHYSICAL_DAMAGE)
            {
                //PHYSICAL DAMAGE
                damage       = (((Mathf.Pow(myUserBase.strength.value, 3) / 32) + myUserBase.curAttack) * executingSkill.magnitude) / 16;
                defendDamage = (Mathf.Pow(myUserBase.curDefense, 2) / 110) + 16;
                foreach (Effect eff in myUser.actor.GetComponent <Actor>().activeEffects)
                {
                    if (eff.myEffInfo == Effects.INC_STRENGTH)
                    {
                        damage *= eff.myValue;
                    }
                }
                foreach (Effect eff in tar.actor.GetComponent <Actor>().activeEffects)
                {
                    if (eff.myEffInfo == Effects.INC_DEFENSE)
                    {
                        defendDamage *= eff.myValue;
                    }
                }
                Debug.Log("Command did: " + damage + " but target blocked: " + defendDamage);
                finalDamage = Mathf.CeilToInt(damage - defendDamage);
                //finalDamage = 200;
                if (finalDamage < 0)
                {
                    Debug.LogWarning("Defended damage was greater than damage! Is math correct?");
                    finalDamage = finalDamage * -1;
                }
                else
                {
                    if (executingSkill.element == tar.actor.GetComponent <Actor>()._base.myOppElement)
                    {
                        finalDamage *= 2;
                    }
                    else if (executingSkill.element == tar.actor.GetComponent <Actor>()._base.myElement)
                    {
                        finalDamage *= -1;
                    }
                }
            }
            else if (executingSkill.effectType == EffectType.MAGIC_DAMAGE)
            {
                //MAGIC DAMAGE
                damage       = (executingSkill.magnitude * (Mathf.Pow(myUserBase.wisdom.value, 2) / 6) + myUserBase.wisdom.value) / 4;
                defendDamage = (Mathf.Pow(myUserBase.curMagicDefense, 2) / 110) + 16;
                foreach (Effect eff in myUser.actor.GetComponent <Actor>().activeEffects)
                {
                    if (eff.myEffInfo == Effects.INC_WISDOM)
                    {
                        damage *= eff.myValue;
                    }
                }
                foreach (Effect eff in tar.actor.GetComponent <Actor>().activeEffects)
                {
                    if (eff.myEffInfo == Effects.INC_MDEFENSE)
                    {
                        defendDamage *= eff.myValue;
                    }
                }
                finalDamage = Mathf.CeilToInt(damage - defendDamage);
                //finalDamage = 200;
                if (finalDamage < 0)
                {
                    Debug.LogWarning("Defended damage was greater than damage! Is math correct?");
                    finalDamage = finalDamage * -1;
                }
                else
                {
                    if (executingSkill.element == tar.actor.GetComponent <Actor>()._base.myOppElement)
                    {
                        finalDamage *= 2;
                    }
                    else if (executingSkill.element == tar.actor.GetComponent <Actor>()._base.myElement)
                    {
                        finalDamage *= -1;
                    }
                }
            }
            else
            {
                //HEAL
                damage = executingSkill.magnitude * ((myUserBase.wisdom.value + executingSkill.magnitude) / 2);
                foreach (Effect eff in myUser.actor.GetComponent <Actor>().activeEffects)
                {
                    if (eff.myEffInfo == Effects.INC_WISDOM)
                    {
                        damage *= eff.myValue;
                    }
                }
                if (executingSkill.element == tar.actor.GetComponent <Actor>()._base.myElement)
                {
                    damage *= 2;
                }
                else if (executingSkill.element == tar.actor.GetComponent <Actor>()._base.myOppElement)
                {
                    damage /= 2;
                }
            }

            foreach (BattleFXAnim bfa in _bm.fxAnims)
            {
                if (executingSkill.fxType == bfa.fxType)
                {
                    if (bfa.fxPrefab != null)
                    {
                        Vector3    spawnPos = new Vector3(tar.actor.transform.position.x, tar.actor.transform.position.y + 1, tar.actor.transform.position.z);
                        GameObject go       = (GameObject)Instantiate(bfa.fxPrefab, spawnPos, tar.actor.transform.rotation);
                        go.GetComponent <BattleFX>().run();
                    }
                    else
                    {
                        //Debug.Log ("Skill does not use FX!");
                    }
                }
            }

            if (executingSkill.effectType == EffectType.HEAL || executingSkill.effectType == EffectType.APPLY_EFF || executingSkill.element == tar.actor.GetComponent <Actor>()._base.myElement)
            {
                if (executingSkill.element != tar.actor.GetComponent <Actor>()._base.myElement)
                {
                    tar.actor.GetComponent <Actor>()._base.restoreHealth(Mathf.FloorToInt(finalDamage));
                    //Debug.Log ("Damage was of target's element! Damage is now healing!");
                    Debug.Log("Healing for: " + Mathf.FloorToInt(finalDamage));
                }
                else
                {
                    Debug.Log("Healing for: " + Mathf.FloorToInt(damage));
                    tar.actor.GetComponent <Actor>()._base.restoreHealth(Mathf.FloorToInt(damage));
                }
                GameObject txtObj = (GameObject)Instantiate(_bm.textObject);
                txtObj.transform.position             = new Vector3(tar.actor.transform.position.x, tar.actor.transform.position.y + 2.3f, tar.actor.transform.position.z);
                txtObj.GetComponent <TextMesh>().text = finalDamage.ToString();
                txtObj.GetComponent <BattleText>().StartCoroutine("fadeUpwards");
            }
            else if (executingSkill.element != tar.actor.GetComponent <Actor>()._base.myElement)
            {
                tar.actor.GetComponent <Actor>()._base.takeDamage(finalDamage);
                Debug.Log("Damage for command: " + finalDamage);
                GameObject txtObj = (GameObject)Instantiate(_bm.textObject);
                txtObj.transform.position             = new Vector3(tar.actor.transform.position.x, tar.actor.transform.position.y + 2.3f, tar.actor.transform.position.z);
                txtObj.GetComponent <TextMesh>().text = finalDamage.ToString();
                txtObj.GetComponent <BattleText>().StartCoroutine("fadeUpwards");
            }

            //Prepare for next turn in case turns are re-calculated
            if (tar.actor.GetComponent <Actor>()._base.dead == true)
            {
                //Set animation to dead
                Debug.Log(tar.actor.GetComponent <Actor>()._base.name + " has died!");
                tar.actor.GetComponent <Actor>().playAnim("Dead");
            }

            lastTurnOwner = turns.Dequeue();
            turns.Enqueue(lastTurnOwner);
            Debug.Log("Finishing turn for: " + lastTurnOwner.name);
            //Debug.Log ("Compare to next turn owner: " + turns.Peek ().name);

            _bm._gm._GUI.updatePartyValues();
            yield return(new WaitForSeconds(2));
        }

        executingSkill.advanceSkillStage(1);
        if (meleeRangeFound)
        {
            StartCoroutine("returnToStartPos");
        }
        else
        {
            finishSkill();
        }
    }
示例#2
0
    //Assumption: PARTY is always 3 people
    public void calculateTurns(BattleTarget tar = null)
    {
        if (tar != null)
        {
            Debug.Log("One actor has been removed. Updating current list.");
            Queue <GameObject> tempQueue = new Queue <GameObject>();

            foreach (GameObject go in turns)
            {
                if (go != tar.actor)
                {
                    tempQueue.Enqueue(go);
                }
                else
                {
                    Debug.Log("Removed actor: " + tar.actor.GetComponent <Actor>()._base.name + " from turns list!");
                }
            }

            turns = new Queue <GameObject>();
            foreach (GameObject go in tempQueue)
            {
                turns.Enqueue(go);
            }
            for (int i = 0; i < turns.Count; i++)
            {
                GameObject reQ = turns.Dequeue();
                turns.Enqueue(reQ);
            }
        }
        else
        {
            Debug.Log("Calculating starting turns list.");
            turns = new Queue <GameObject>();
            List <BattleTarget> actors = new List <BattleTarget>();
            if (party[0].actor.GetComponent <Actor>()._base.dead != true)
            {
                actors.Add(party[0]);
            }
            if (party[1].actor.GetComponent <Actor>()._base.dead != true)
            {
                actors.Add(party[1]);
            }
            if (party[2].actor.GetComponent <Actor>()._base.dead != true)
            {
                actors.Add(party[2]);
            }

            foreach (BattleTarget bt in enemies)
            {
                if (bt.actor != null)
                {
                    if (bt.actor.GetComponent <Actor>()._base.dead != true)
                    {
                        actors.Add(bt);
                    }
                }
            }

            //adds actors with highest speed first into queue
            int maxActors = actors.Count;

            //loop until each actor is given an
            while (turns.Count != maxActors)
            {
                BattleTarget highestSpeedActor = null;

                //Get current highest speed actor
                foreach (BattleTarget bt in actors)
                {
                    if (highestSpeedActor == null)
                    {
                        highestSpeedActor = bt;
                    }
                    else if (bt.actor.GetComponent <ActorBase>().speed.value > highestSpeedActor.actor.GetComponent <ActorBase>().speed.value)
                    {
                        highestSpeedActor = bt;
                    }
                }

                //add current highest speed actor to queue
                //Debug.Log (turns.Count + " : " + highestSpeedActor.actor.name);
                turns.Enqueue(highestSpeedActor.actor);
                actors.Remove(highestSpeedActor);
            }
        }
    }
示例#3
0
    //gets the next target for a single target skill
    public BattleTarget getNextTarget(bool ascending = true, bool allowDeadTargets = false)
    {
        BattleTarget bt = getSingleTarget();

        int  index             = -1;
        bool isParty           = true;
        bool requiresOtherSide = false;

        for (int i = 0; i < party.Length; i++)
        {
            if (party[i] == bt)
            {
                index   = i;
                isParty = true;
            }
        }
        for (int i = 0; i < enemies.Length - 1; i++)
        {
            if (enemies[i] == bt)
            {
                index   = i;
                isParty = false;
            }
        }

        if (index != -1)
        {
            if (isParty)
            {
                //PARTY
                //Debug.Log ("Starting at: " + index);
                if (ascending)
                {
                    if (allowDeadTargets)
                    {
                        Debug.LogWarning("Dead targets not yet implemented!");
                        return(getNextTarget(ascending));
                    }
                    else
                    {
                        //Debug.Log ("Finding: " + (index + 1));
                        if (index == 2)
                        {
                            return(getLivingActor());
                        }
                        else if (index == 1)
                        {
                            if (party[2].actor.GetComponent <Actor>()._base.curHealth > 0)
                            {
                                return(party[2]);
                            }
                            else
                            {
                                if (party[0].actor.GetComponent <Actor>()._base.curHealth > 0)
                                {
                                    return(party[0]);
                                }
                                else
                                {
                                    Debug.LogWarning("All other party members are KO'd");
                                    return(bt);
                                }
                            }
                        }
                        else if (index == 0)
                        {
                            if (party[1].actor.GetComponent <Actor>()._base.curHealth > 0)
                            {
                                return(party[1]);
                            }
                            else
                            {
                                if (party[2].actor.GetComponent <Actor>()._base.curHealth > 0)
                                {
                                    return(party[2]);
                                }
                                else
                                {
                                    Debug.LogWarning("All other party members are KO'd");
                                    return(bt);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (allowDeadTargets)
                    {
                        Debug.LogWarning("Dead targets not yet implemented!");
                        return(getNextTarget(ascending));
                    }
                    else
                    {
                        //Debug.Log ("Finding: " + (index - 1));
                        if (index == 0)
                        {
                            //If cur target is first party, check last then mid
                            if (party[party.Length - 1].actor.GetComponent <Actor>()._base.curHealth > 0)
                            {
                                return(party[party.Length - 1]);
                            }
                            else
                            {
                                if (party[party.Length - 2].actor.GetComponent <Actor>()._base.curHealth > 0)
                                {
                                    return(party[party.Length - 2]);
                                }
                                else
                                {
                                    Debug.LogWarning("All other party members are KO'd");
                                    return(bt);
                                }
                            }
                        }
                        else if (index > 0)
                        {
                            //If cur target is mid or last / check first or check mid then first
                            if (index + 1 == party.Length - 1)
                            {
                                //Mid
                                if (party[0].actor.GetComponent <Actor>()._base.curHealth > 0)
                                {
                                    return(party[0]);
                                }
                                else
                                {
                                    if (party[2].actor.GetComponent <Actor>()._base.curHealth > 0)
                                    {
                                        return(party[2]);
                                    }
                                    else
                                    {
                                        Debug.LogWarning("All other party members are KO'd");
                                        return(bt);
                                    }
                                }
                            }
                            else if (index == party.Length - 1)
                            {
                                //Last
                                if (party[1].actor.GetComponent <Actor>()._base.curHealth > 0)
                                {
                                    return(party[1]);
                                }
                                else
                                {
                                    if (party[0].actor.GetComponent <Actor>()._base.curHealth > 0)
                                    {
                                        return(party[0]);
                                    }
                                    else
                                    {
                                        Debug.LogWarning("All other party members are KO'd");
                                        return(bt);
                                    }
                                }
                            }
                            else
                            {
                                Debug.Log("Other two members are KO'd");
                                return(bt);
                            }
                        }
                    }
                }
            }
            else
            {
                //ENEMY
                if (ascending)
                {
                    if (index == enemyCount - 1)
                    {
                        //Last enemy
                        return(getLivingActor(false));
                    }
                    else if (index < enemyCount - 1)
                    {
                        int cnt = index + 1;
                        //If first, check mid and last / If mid, check last / In case error get first living
                        while (cnt != index)
                        {
                            if (cnt > enemyCount - 1)
                            {
                                cnt = 0;
                            }
                            else
                            {
                                if (enemies[cnt].actor.GetComponent <Actor>()._base.curHealth > 0)
                                {
                                    return(enemies[cnt]);
                                }
                                else
                                {
                                    cnt++;
                                    if (cnt == enemyCount)
                                    {
                                        cnt = 0;
                                    }
                                }
                            }
                        }
                        Debug.LogWarning("No other enemies!");
                        return(bt);
                    }
                }
                else
                {
                    if (index == 0)
                    {
                        int cnt = enemyCount - 1;
                        //Loop through each enemy except current target
                        while (cnt > 0)
                        {
                            if (enemies[cnt].actor.GetComponent <Actor>()._base.curHealth > 0)
                            {
                                return(enemies[cnt]);
                            }
                            else
                            {
                                cnt--;
                            }
                        }
                        Debug.LogWarning("No other enemies!");
                        return(bt);
                    }
                    else if (index > 0)
                    {
                        int cnt = index - 1;
                        //Loop through each enemy except current target
                        while (cnt != index)
                        {
                            if (enemies[cnt].actor.GetComponent <Actor>()._base.curHealth > 0)
                            {
                                return(enemies[cnt]);
                            }
                            else
                            {
                                cnt--;
                                if (cnt == -1)
                                {
                                    cnt = enemyCount - 1;
                                }
                            }
                        }
                        Debug.LogWarning("No other enemies!");
                        return(bt);
                    }
                }
            }
        }
        else
        {
            Debug.LogError("Could not find next target for " + bt.actor.name);
            return(bt);
        }

        Debug.LogError("Could not find marked target from list!");
        return(null);
    }
示例#4
0
 public void ActivateSelector(BattleTarget target, bool targetEnemiesFirst = false)
 {
     switch (target)
     {
         case BattleTarget.Self:
             SelectSelf();
             break;
         case BattleTarget.Combatant:
             SelectCombatant(targetEnemiesFirst ? BattleTargetGroup.Enemies : BattleTargetGroup.Allies);
             break;
         case BattleTarget.Ally:
             SelectAlly();
             break;
         case BattleTarget.Enemy:
             BattleState.Screen.SelectEnemy();
             break;
         case BattleTarget.Group:
         case BattleTarget.GroupRandom:
             BattleState.Screen.SelectEitherGroup(targetEnemiesFirst ? BattleTargetGroup.Enemies : BattleTargetGroup.Allies);
             break;
         case BattleTarget.Allies:
         case BattleTarget.AlliesRandom:
             BattleState.Screen.SelectAllies();
             break;
         case BattleTarget.Enemies:
         case BattleTarget.EnemiesRandom:
             BattleState.Screen.SelectEnemies();
             break;
         case BattleTarget.Area:
         case BattleTarget.AreaRandom:
             BattleState.Screen.SelectArea();
             break;
     }
 }
示例#5
0
 /// <summary> use the action choosed </summary>
 /// <param name="target"></param>
 public override void useAction(BattleTarget target)
 {
     animateMovement(actionInUse, target, _battleStateManager.getBattleSpawn(choosedActor));
 }
示例#6
0
 public BattleThreat(BattleTarget tar)
 {
     target = tar;
     threat = 0;
 }
示例#7
0
    public void takeTurnAI()
    {
        //code for enemy AI to determine action
        List <BattleBehaviour> plausbile = new List <BattleBehaviour>();

        foreach (BattleBehaviour bb in behaviours)
        {
            bool test = testCondition(bb);
            if (test)
            {
                plausbile.Add(bb);
            }

            /*
             * if (bb.condition == BattleCondition.TURN_NUMBER) {
             *      if (bf.turnCount == bb.value) {
             *              highestPriority = bb;
             *              break;
             *      }
             * }else{
             *      if (bb.condition == BattleCondition.TURN_EVEN || bb.condition == BattleCondition.TURN_ODD) {
             *              highestPriority = bb;
             *      }else{
             *              if (bb.condition == BattleCondition.ANY_TURN) {
             *
             *              }
             *      }
             * }
             */
        }

        List <BattleBehaviour> highestPrioritys = new List <BattleBehaviour>();
        int topPriority = 0;

        foreach (BattleBehaviour bb in plausbile)
        {
            if (bb.priority > topPriority)
            {
                highestPrioritys.Clear();
                topPriority = bb.priority;
                highestPrioritys.Add(bb);
            }
            else if (bb.priority == topPriority)
            {
                highestPrioritys.Add(bb);
            }
        }

        BattleBehaviour finalChoice = null;

        if (highestPrioritys.Count > 1)
        {
            finalChoice = highestPrioritys[Mathf.FloorToInt(Random.Range(0, highestPrioritys.Count - 1))];
        }
        else if (highestPrioritys.Count == 1)
        {
            finalChoice = highestPrioritys[0];
        }
        else if (highestPrioritys.Count < 1)
        {
            Debug.Log("No skills were found for enemy to use!");
        }

        if (finalChoice != null)
        {
            Skill skillUsing = getOwnedSkill(finalChoice.skillName);
            if (skillUsing != null)
            {
                if (skillUsing.targetType == TargetType.ALL_TARGET)
                {
                    bf.targetEntireParty();
                }
                else if (skillUsing.targetType == TargetType.TARGET)
                {
                    BattleTarget myTar = getHighestThreat().target;
                    while (myTar.actor.GetComponent <Actor>()._base.curHealth < 0)
                    {
                        myTar = targets[Mathf.FloorToInt(Random.Range(0, targets.Count - 1))].target;
                    }
                    bf.targetSingle(myTar);
                }
                else if (skillUsing.targetType == TargetType.SELF)
                {
                    bf.targetSelf();
                }
                else if (skillUsing.targetType == TargetType.ALL_PARTY)
                {
                    bf.targetEntireEnemies();
                }
                else if (skillUsing.targetType == TargetType.PARTY_MEMBER)
                {
                }
                bf.curSkill = skillUsing;
                bf.executeSkill();
            }
            else
            {
                Debug.LogError("Skill was not found in actor's owned skills list!");
            }
        }
        else
        {
            Debug.LogError(_base.name + " was unable to find a command!");
        }
    }
示例#8
0
 public abstract void useAction(BattleTarget target);