Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
TriggerFix
Fix Triggers
  • Loading branch information
aps16104 committed Mar 24, 2020
1 parent 93a2262 commit 9405204
Show file tree
Hide file tree
Showing 221 changed files with 15,838 additions and 335 deletions.
382 changes: 382 additions & 0 deletions RPG/Assets/BattleSystem3.cs
@@ -0,0 +1,382 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public enum BattleState3 { START, PLAYERTURN, ENEMYTURN, WON, LOST }
public class BattleSystem3 : MonoBehaviour
{

public GameObject playerPrefab;
public GameObject enemyPrefab;

public Transform playerBattleStation;
public Transform enemyBattleStation;

Unit playerUnit;
Unit enemyUnit;

public float speed = 5f;

public Animator animator;
public Animator Eanimator;

public Text dialogueText;

public BattleHUD playerHUD;
public BattleHUD enemyHUD;

public BattleState state;

void Start()
{
state = BattleState.START;
StartCoroutine(SetupBattle());
}

IEnumerator SetupBattle()
{
playerPrefab.SetActive(false);
GameObject playerGO = playerPrefab;
playerPrefab.SetActive(true);
playerUnit = playerGO.GetComponent<Unit>();

enemyPrefab.SetActive(false);
GameObject enemyGO = enemyPrefab;
enemyPrefab.SetActive(true);
enemyUnit = enemyGO.GetComponent<Unit>();

dialogueText.text = "A hostile " + enemyUnit.unitName + " approaches...";

playerHUD.SetHUD(playerUnit);
enemyHUD.SetHUD(enemyUnit);

yield return new WaitForSeconds(.5f);

state = BattleState.PLAYERTURN;
StartCoroutine(PlayerTurn());
}



IEnumerator EnemyTurn()
{
dialogueText.text = enemyUnit.unitName + "'s turn";
yield return new WaitForSeconds(1.5f);
float i = Random.Range(0f, 10f);
if (i <= 8)
{
dialogueText.text = enemyUnit.unitName + " attacks!";
//Animation wait time
yield return new WaitForSeconds(.5f);
enemyPrefab.transform.Translate(speed * 1, 0, 0);
Eanimator.SetBool("E_Attack", true);
bool isDead = playerUnit.TakeDamage(enemyUnit.damage);
playerHUD.SetHP(playerUnit.currentHP);
animator.SetBool("Hurt", true);
yield return new WaitForSeconds(1.2f);
animator.SetBool("Hurt", false);
Eanimator.SetBool("E_Attack", false);
enemyPrefab.transform.Translate(-speed, 0, 0);





if (isDead)
{
animator.SetBool("Dead", true);
yield return new WaitForSeconds(2.1f);
state = BattleState.LOST;
EndBattle();
}
else
{
state = BattleState.PLAYERTURN;
StartCoroutine(PlayerTurn());
}
}

//Healing
else
{
animator.SetBool("E_Heals", true);
yield return new WaitForSeconds(1.5f);
animator.SetBool("E_Heals", false);
dialogueText.text = enemyUnit.unitName + " heals!";
enemyUnit.Heal(15);
enemyHUD.SetHP(enemyUnit.currentHP);
yield return new WaitForSeconds(1.5f);
animator.SetBool("E_Heals", false);

state = BattleState.PLAYERTURN;
StartCoroutine(PlayerTurn());
}
}




IEnumerator PlayerTurn()
{

dialogueText.text = "Choose an action:";
yield return new WaitForSeconds(1f);
}



//Player Options
public void OnAttackButton()
{
if (state != BattleState.PLAYERTURN)
return;
StartCoroutine(PlayerAttack());
}



IEnumerator PlayerAttack() //QuickAttack
{

//Run to enemy
playerPrefab.transform.Translate(speed * 1, 0, 0);
dialogueText.text = "quick attack!";
animator.SetBool("QuickAttack", true);
yield return new WaitForSeconds(.50f);

//Tackle Enemy
bool isDead = enemyUnit.TakeDamage(playerUnit.damage);
dialogueText.text = "The quick attack is successful!";
enemyHUD.SetHP(enemyUnit.currentHP);
Eanimator.SetBool("E_Hurt", true);
yield return new WaitForSeconds(.51f);
Eanimator.SetBool("E_Hurt", false);

//return
animator.SetBool("QuickAttack", false);
playerPrefab.transform.Translate(-speed, 0, 0);
yield return new WaitForSeconds(1f);

//check if enemy dead
if (isDead)
{
Eanimator.SetBool("E_Dead", true);
yield return new WaitForSeconds(1.5f);

state = BattleState.WON;
EndBattle();
}

else
{
state = BattleState.ENEMYTURN;
StartCoroutine(EnemyTurn());
}

}

public void OnAttack2Button()
{
if (state != BattleState.PLAYERTURN)
return;

StartCoroutine(PlayerAttack2());
}

IEnumerator PlayerAttack2() //Tackle
{
//Run to Enemy
playerPrefab.transform.Translate(speed * 1, 0, 0);
dialogueText.text = "Tackle!";
//swing


animator.SetBool("Tackle", true);



yield return new WaitForSeconds(1.5f);
Eanimator.SetBool("E_Hurt", true);
yield return new WaitForSeconds(.51f);

Eanimator.SetBool("E_Hurt", false);
animator.SetBool("Tackle", false);
//Stop Swinging and reuturn
playerPrefab.transform.Translate(-speed, 0, 0);




//see if hit or miss
float i = Random.Range(0, 10);
if (i <= 8)

{
//Damage enemy
bool isDead = enemyUnit.TakeDamage(playerUnit.damage2);
enemyHUD.SetHP(enemyUnit.currentHP);
dialogueText.text = "The Tackle is successful!";
yield return new WaitForSeconds(1f);

//check if enemy dead
if (isDead)
{
Eanimator.SetBool("E_Dead", true);
yield return new WaitForSeconds(1.5f);
state = BattleState.WON;
EndBattle();
}

else
{
state = BattleState.ENEMYTURN;
StartCoroutine(EnemyTurn());
}
}

else
{
bool isDead = enemyUnit.TakeDamage(playerUnit.damage0);
yield return new WaitForSeconds(.10f);
dialogueText.text = "The Tackle did no damage";
yield return new WaitForSeconds(1f);

//check if enemy dead
if (isDead)
{
Eanimator.SetBool("E_Dead", true);
yield return new WaitForSeconds(1.5f);
state = BattleState.WON;
EndBattle();
}

else
{
state = BattleState.ENEMYTURN;
StartCoroutine(EnemyTurn());
}
}


}

public void OnAttack3Button()
{
if (state != BattleState.PLAYERTURN)
return;

StartCoroutine(PlayerAttack3());
}

IEnumerator PlayerAttack3() //Fury Swipe
{
//Damage enemy
//Run to Enemy
playerPrefab.transform.Translate(speed * 1, 0, 0);
dialogueText.text = "Fury Swipes!";
yield return new WaitForSeconds(.50f);
animator.SetBool("FurySwipe", true);

//animate here

//1
Eanimator.SetBool("E_Hurt", true);
yield return new WaitForSeconds(.50f);
Eanimator.SetBool("E_Hurt", false);

yield return new WaitForSeconds(.50f);

//2
Eanimator.SetBool("E_Hurt", true);
yield return new WaitForSeconds(.50f);
Eanimator.SetBool("E_Hurt", false);

yield return new WaitForSeconds(.50f);

//3
Eanimator.SetBool("E_Hurt", true);
yield return new WaitForSeconds(.50f);
Eanimator.SetBool("E_Hurt", false);

yield return new WaitForSeconds(.50f);

//4
Eanimator.SetBool("E_Hurt", true);
yield return new WaitForSeconds(.50f);
Eanimator.SetBool("E_Hurt", false);





yield return new WaitForSeconds(1f);


dialogueText.text = "The attack was successful!";
bool isDead = enemyUnit.TakeDamage(Random.Range(5, 15));
enemyHUD.SetHP(enemyUnit.currentHP);
animator.SetBool("FurySwipe", false);
playerPrefab.transform.Translate(-speed, 0, 0);


yield return new WaitForSeconds(1f);

//check if enemy dead
if (isDead)
{
Eanimator.SetBool("E_Dead", true);
yield return new WaitForSeconds(1.5f);
state = BattleState.WON;
EndBattle();
}

else
{
state = BattleState.ENEMYTURN;
StartCoroutine(EnemyTurn());
}

}

public void OnHealButton()
{
if (state != BattleState.PLAYERTURN)
return;
StartCoroutine(PlayerHeal());
}

IEnumerator PlayerHeal() //Heal
{
yield return new WaitForSeconds(.5f);
playerUnit.Heal(15);
playerHUD.SetHP(playerUnit.currentHP);
animator.SetBool("Heal", true);
yield return new WaitForSeconds(1.75f);
dialogueText.text = "You feel renewed strength!";
animator.SetBool("Heal", false);
state = BattleState.ENEMYTURN;
yield return new WaitForSeconds(1f);
StartCoroutine(EnemyTurn());

}


void EndBattle()
{
//change state
if (state == BattleState.WON)
{
dialogueText.text = "Victory!";
SceneManager.LoadScene("2D_3B");
}

else if (state == BattleState.LOST)
{
dialogueText.text = "You lost!";
SceneManager.LoadScene("GameOver");
}

}
}
11 changes: 11 additions & 0 deletions RPG/Assets/BattleSystem3.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9405204

Please sign in to comment.