示例#1
0
    public void EngageCombat(List <Character> e)
    {
        StopAllCoroutines();
        if (e.Count > 0)
        {
            player = GameObject.FindGameObjectWithTag("Player").GetComponent <Character>();

            //DEBUG
            player.damage = 20;

            HealCount = 3;
            state     = combatState.START;
            enemies.Clear();
            enemies.AddRange(e);
            currentEnemy = e[0];

            BattleHUD.gameObject.SetActive(true);
            UpdateHUD();
            state = combatState.PLAYER;
            PlayerAttacks.SetActive(true);
        }
        else
        {
            Debug.LogError("Invalid enemy list. Unable to engage in combat");
        }
    }
示例#2
0
 public void charge()
 {
     if (state == combatState.NORMAL)
     {
         state = combatState.CHARGING;
     }
 }                                                                                                                   //needs work later.
示例#3
0
 public void playerAttack()
 {
     if (fightState == combatState.playerTurn)
     {
         int giveDamage = player.attack() + Random.Range(-1, 2);
         opponent.takeDamage(giveDamage);
         statusBarSay("You attack for " + giveDamage + " damage!");
         turnCount++;
         if (opponent.isDead())
         {
             GameObject.Destroy(opponent.gameObject);
             fightState = combatState.win;
             statusBarSay("You win!");
         }
         else if (player.isDead())
         {
             losePoint.transform.localPosition = new Vector3(0, 0, 5000);
             fightState = combatState.lose;
         }
         else
         {
             fightState = combatState.enemyTurn;
         }
     }
 }
示例#4
0
    IEnumerator PlayerWin()
    {
        dialogue.text = "You have defeated " + currentEnemy.characterName;

        yield return(new WaitForSeconds(2));

        if (enemies.Count > 1)
        {
            enemies.RemoveAt(0);
            currentEnemy.GetComponent <EnemyController>().Die();

            currentEnemy = enemies[0];
            state        = combatState.PLAYER;
        }
        else
        {
            enemies.RemoveAt(0);
            currentEnemy.InCombat = false;
            currentEnemy.GetComponent <EnemyController>().Die();
            currentEnemy = null;

            BattleHUD.gameObject.SetActive(false);
            GameObject.FindGameObjectWithTag("GameController").GetComponent <Game>().PlayerCaught = false;
            player.InCombat = false;
            state           = combatState.IDLE;
            turnTaken       = false;
            StopAllCoroutines();
        }
    }
示例#5
0
 public void trinket()
 {
     if (state == combatState.NORMAL)
     {
         state          = combatState.TRINKET;
         nextActionTime = Time.time + trinketLength;
     }
 }
示例#6
0
 public void runAway()
 {
     if (fightState == combatState.playerTurn)
     {
         fightState = combatState.deactivate;
         if (opponent != null)
         {
             GameObject.Destroy(opponent.gameObject);
         }
     }
 }
示例#7
0
    }                                                                                                                   //needs work later.

    public void attack()
    {
        if (state == combatState.CHARGING || state == combatState.NORMAL)                                                                       //only attack if idle or charging is over with
        {
            state          = combatState.ATTACK;                                                                                                //switch to attack state - MUST HAPPEN for attacks to register hits.
            nextActionTime = Time.time + normalAttackLength;                                                                                    //melee attack
            if (anim != null)
            {
                anim.SetBool("Attack", true);                                                                                                                                                   //tell animator to execute attack
            }
        }
    }
示例#8
0
    public void enemyAttack()
    {
        int giveDamage = opponent.attack() + Random.Range(-1, 2);

        player.takeDamage(giveDamage);
        statusBarSay("You take " + giveDamage + " damage!");
        if (player.isDead())
        {
            GameObject.Destroy(opponent.gameObject);
            losePoint.transform.localPosition = new Vector3(0, 0, 5000);
            fightState = combatState.lose;
        }
    }
示例#9
0
 public void parry()
 {
     if (state == combatState.NORMAL)
     {
         if (debugMode)
         {
             Debug.Log("PARRY!!");
         }
         state          = combatState.PARRY;
         nextActionTime = Time.time + parryLength;
         anim.SetBool("Parry", true);
     }
 }
示例#10
0
    public void playerDefend()
    {
        if (fightState == combatState.playerTurn)
        {
            //int giveDamage = player.attack() + Random.Range (-1, 2);
            //opponent.takeDamage (giveDamage);

            turnCount++;

            statusBarSay("You defended!");


            fightState = combatState.enemyTurn;
        }
    }
示例#11
0
 public void init(EntityStats nstats, Entity en, Animator nanim, FillScript nHealthBar)
 {
     stats = nstats;                                                                                         //entity stats container
     owner = en;                                                                                             //entity that this slice instance is attached to
     if (nanim != null)
     {
         anim = nanim;                                                                       //animator reference
     }
     if (nHealthBar != null)
     {
         healthBar = nHealthBar;                                             //UI health bar
     }
     state          = combatState.NORMAL;                                    //idle state
     nextActionTime = 0.0f;                                                  //no previous action has been performed, so zero the cooldown period
 }
示例#12
0
    public void menuLoop()
    {
        switch (fightState)
        {
        case combatState.fightStart:
            //Fill the Status bar with empty stuff
            populateStatusBar();

            winPoint.transform.localPosition  = new Vector3(0, 5000, 0);
            losePoint.transform.localPosition = new Vector3(-30, 5000, 0);


            opponent = (enemyClass)GameObject.Instantiate(enemyPool[Random.Range(0, enemyPool.Length)], enemySpawn.transform.position, enemySpawn.transform.rotation);
            opponent.transform.parent        = enemySpawn.transform;
            opponent.transform.localPosition = new Vector3(0, 0, 0);
            statusBarSay("An enemy " + opponent.name + " appeared!");
            fightState = combatState.playerTurn;
            break;

        case combatState.playerTurn:

            break;

        case combatState.enemyTurn:
            enemyAttack();
            if (player.isDead())
            {
                statusBarSay("You lose!");
                fightState = combatState.lose;
            }
            else
            {
                fightState = combatState.playerTurn;
            }
            break;

        case combatState.win:
            winPoint.transform.localPosition = new Vector3(0, 0, 0);
            break;

        case combatState.lose:
            losePoint.transform.localPosition = new Vector3(0, 0, 0);
            break;
        }
        updateStatusBar();
        healthbarUpdate();
    }
示例#13
0
    //update the state with respect to time
    void Update()
    {
        if (state == combatState.NORMAL)
        {
            return;                                                     //if no actions are in progress, don't process further.
        }
        else if (nextActionTime > Time.time)
        {
            return;                             //if an action isn't completed, don't continue.
        }

        //reset to normal after any primary action has timed out. timings controlled in attributes area up top.
        else if (state == combatState.ATTACK || state == combatState.PARRY || state == combatState.TRINKET || state == combatState.STUNNED || state == combatState.HIT)
        {
            state = combatState.NORMAL;
            if (anim != null)
            {
                anim.SetBool("Attack", false);
                anim.SetBool("Parry", false);
                anim.SetBool("Hit", false);
            }
        }
    }
示例#14
0
    //take damage. called via projectiles, player scripts, and whatnot. EStats p refs attacking player (for transfers)
    public void damage(float d, EntityStats p)
    {
        //damage value calculation
        float temp = d - stats.getDefense();

        if (temp < 1)
        {
            temp = 1;
        }

        //the pain train has arrived
        stats.health -= temp;
        if (stats.hud != null)
        {
            stats.hud.updateHealthbar();
        }

        //if (debugMode) Debug.Log("Damage done: " + temp + " to " + stats.health);

        if (stats.health <= 0)
        {
            death(p);
        }
        else
        {
            //we're hit, so cancel whatever action was going on
            state = combatState.HIT;
            if (anim != null)
            {
                anim.SetBool("Hit", true);
                anim.SetBool("Attack", false);
                anim.SetBool("Parry", false);
            }
            nextActionTime = Time.time + 0.2f;
        }
    }
示例#15
0
 public void setToInactive()
 {
     fightState = combatState.inactive;
 }
示例#16
0
 private void Start()
 {
     state = combatState.IDLE;
     BattleHUD.gameObject.SetActive(false);
 }
示例#17
0
    IEnumerator PlayerAttack(attackType attack)
    {
        turnTaken = true;
        bool enemyDead = false;

        switch (attack)
        {
        case attackType.MELEE:
            enemyDead = currentEnemy.TakeDamage(player.damage);
            break;

        case attackType.MAGIC:
            enemyDead = currentEnemy.TakeDamage(player.damage);
            break;

        case attackType.HEAL:
            player.Restore(0, 25);
            break;

        case attackType.POTION:
            player.Restore(0, 50);
            player.Restore(1, 25);
            player.Restore(2, 25);
            break;

        case attackType.BLOCK:
            player.Restore(0, 5);
            break;

        case attackType.COWER:
            int successChance = Random.Range(0, 4);
            if (successChance == 3)
            {
                dialogue.text = "You cower successfully and the gods take pity on you. You find your resolve for battle is fortified.";
                int stat = Random.Range(0, 3);
                player.Restore(stat, 50);
            }
            else
            {
                dialogue.text = "You cower unsuccessfully, the gods have forsaken you. You find your resolve for battle falters.";
                int stat = Random.Range(0, 3);
                player.Restore(stat, 5);
            }
            break;
        }

        UpdateHUD();

        yield return(new WaitForSeconds(2));

        //Check if enemy is dead
        if (enemyDead)
        {
            state = combatState.WIN;
            StopAllCoroutines();
            StartCoroutine(PlayerWin());
        }
        else
        {
            PlayerAttacks.SetActive(false);
            dialogue.text = "Your oponent prepares to attack...";
            state         = combatState.ENEMY;
            yield return(new WaitForSeconds(1));

            StartCoroutine(EnemyTurn());
        }
    }
示例#18
0
    IEnumerator EnemyTurn()
    {
        bool playerDead = false;

        if (state == combatState.ENEMY)
        {
            //Can be modified to include a priority system here so more likely to heal when low on health etc.
            attackType attack = (attackType)Random.Range(0, 6);

            switch (attack)
            {
            case attackType.MELEE:
                if (currentEnemy.Consume(2, 15))
                {
                    playerDead    = player.TakeDamage(currentEnemy.damage);
                    dialogue.text = currentEnemy.characterName + " performs a melee attack at you.";
                }
                else
                {
                    dialogue.text = currentEnemy.characterName + " cowers.";
                }
                break;

            case attackType.MAGIC:
                if (currentEnemy.Consume(1, 15))
                {
                    playerDead    = player.TakeDamage(currentEnemy.damage);
                    dialogue.text = currentEnemy.characterName + " performs a magic attack at you.";
                }
                break;

            case attackType.HEAL:
                if (currentEnemy.Consume(1, 15 + (5 * (3 - HealCount))))
                {
                    currentEnemy.Restore(0, 5 * HealCount);
                    dialogue.text = currentEnemy.characterName + " casts healing on themself.";
                    HealCount--;
                }
                break;

            case attackType.POTION:
                currentEnemy.Restore(1, 25);
                currentEnemy.Restore(2, 25);
                dialogue.text = currentEnemy.characterName + " restores their abilities.";
                break;

            case attackType.BLOCK:
                if (currentEnemy.Consume(2, 5))
                {
                    currentEnemy.Restore(0, 5);
                    dialogue.text = currentEnemy.characterName + " prepares to block your next attack.";
                }
                break;

            case attackType.COWER:
                dialogue.text = currentEnemy.characterName + " cowers.";
                break;
            }
        }

        UpdateHUD();

        yield return(new WaitForSeconds(2));

        if (playerDead)
        {
            state = combatState.LOSE;
            StopAllCoroutines();
        }
        else
        {
            dialogue.text = "You prepare your next move...";
            state         = combatState.PLAYER;
            PlayerAttacks.SetActive(true);
        }
        turnTaken = false;
    }
示例#19
0
 public void lose()
 {
     fightState = combatState.deactivate;
 }
示例#20
0
 public void win()
 {
     fightState = combatState.deactivate;
 }
示例#21
0
 //called whenever you need to get parried.
 public void stun()
 {
     state          = combatState.STUNNED;
     nextActionTime = Time.time + stunLength;
 }
示例#22
0
 public void parried()
 {
     nextActionTime = Time.time + stunLength;
     state          = combatState.STUNNED;
 }
示例#23
0
 public void activate()
 {
     fightState = combatState.fightStart;
 }