116 lines
3.2 KiB
C#
116 lines
3.2 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
public class CardPointsController : MonoBehaviour
|
|
{
|
|
public static CardPointsController instance;
|
|
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
public CardPlacePoint[] playerCardPoints, enemyCardPoints;
|
|
|
|
public float timeBetweenAttacks = 0.25f;
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public void PlayerAttack()
|
|
{
|
|
StartCoroutine(PlayerAttackCo());
|
|
}
|
|
|
|
IEnumerator PlayerAttackCo()
|
|
{
|
|
yield return new WaitForSeconds(timeBetweenAttacks);
|
|
|
|
for(int i = 0; i < playerCardPoints.Length; i++)
|
|
{
|
|
if(playerCardPoints[i].activeCard != null)
|
|
{
|
|
if (enemyCardPoints[i].activeCard != null)
|
|
{
|
|
//attack the enemy's card
|
|
enemyCardPoints[i].activeCard.DamageCard(playerCardPoints[i].activeCard.attackPower);
|
|
}
|
|
else
|
|
{
|
|
//attack enemy's overall health
|
|
BattleController.instance.DamageEnemy(playerCardPoints[i].activeCard.attackPower);
|
|
}
|
|
playerCardPoints[i].activeCard.anim.SetTrigger("Attack");
|
|
yield return new WaitForSeconds(timeBetweenAttacks);
|
|
}
|
|
}
|
|
CheckAssignedCards();
|
|
BattleController.instance.AdvanceTurn();
|
|
}
|
|
|
|
public void EnemyAttack()
|
|
{
|
|
StartCoroutine(EnemyAttackCo());
|
|
}
|
|
|
|
IEnumerator EnemyAttackCo()
|
|
{
|
|
yield return new WaitForSeconds(timeBetweenAttacks);
|
|
|
|
for (int i = 0; i < enemyCardPoints.Length; i++)
|
|
{
|
|
if (enemyCardPoints[i].activeCard != null)
|
|
{
|
|
if (playerCardPoints[i].activeCard != null)
|
|
{
|
|
//attack the player's card
|
|
playerCardPoints[i].activeCard.DamageCard(enemyCardPoints[i].activeCard.attackPower);
|
|
}
|
|
else
|
|
{
|
|
//attack player's overall health
|
|
BattleController.instance.DamagePlayer(enemyCardPoints[i].activeCard.attackPower);
|
|
}
|
|
enemyCardPoints[i].activeCard.anim.SetTrigger("Attack");
|
|
yield return new WaitForSeconds(timeBetweenAttacks);
|
|
}
|
|
}
|
|
CheckAssignedCards();
|
|
BattleController.instance.AdvanceTurn();
|
|
}
|
|
|
|
public void CheckAssignedCards()
|
|
{
|
|
foreach(CardPlacePoint point in enemyCardPoints)
|
|
{
|
|
if (point.activeCard != null)
|
|
{
|
|
if(point.activeCard.currentHealth <= 0)
|
|
{
|
|
point.activeCard = null;
|
|
}
|
|
}
|
|
}
|
|
foreach (CardPlacePoint point in playerCardPoints)
|
|
{
|
|
if (point.activeCard != null)
|
|
{
|
|
if (point.activeCard.currentHealth <= 0)
|
|
{
|
|
point.activeCard = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|