Developing AI behaviour scripts

This commit is contained in:
SHOUTING_PIRATE
2025-04-28 12:01:01 +01:00
parent 6a34653ec6
commit 11297a3078
4514 changed files with 140858 additions and 139160 deletions

View File

@@ -10,7 +10,7 @@ public class BattleController : MonoBehaviour
}
public int startingMana = 4, maxMana = 12;
public int playerMana;
public int playerMana, enemyMana;
public int startingCardsAmount = 5;
public int cardsToDrawPerTurn = 2;
@@ -23,13 +23,15 @@ public class BattleController : MonoBehaviour
public int playerHealth;
public int enemyHealth;
private int currentPlayerMaxMana;
private int currentPlayerMaxMana, currentEnemyMaxMana;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
currentPlayerMaxMana = startingMana;
FillPlayerMana();
currentEnemyMaxMana = startingMana;
FillEnemyMana();
DeckController.instance.DrawMultipleCards(startingCardsAmount);
UIController.instance.SetPlayerHealthText(playerHealth);
@@ -41,7 +43,7 @@ public class BattleController : MonoBehaviour
{
if(Input.GetKeyDown(KeyCode.T))
{
AdvanceTurn();
//AdvanceTurn();
}
}
@@ -56,6 +58,17 @@ public class BattleController : MonoBehaviour
UIController.instance.SetPlayerManaText(playerMana);
}
public void SpendEnemyMana (int amountToSpend)
{
enemyMana = enemyMana - amountToSpend;
if(enemyMana < 0)
{
enemyMana = 0;
}
//UIController.instance.SetPlayerManaText(playerMana);
}
public void FillPlayerMana()
{
//playerMana = startingMana;
@@ -63,6 +76,13 @@ public class BattleController : MonoBehaviour
UIController.instance.SetPlayerManaText(playerMana);
}
public void FillEnemyMana()
{
//playerMana = startingMana;
enemyMana = currentEnemyMaxMana;
//UIController.instance.SetPlayerManaText(playerMana);
}
public void AdvanceTurn()
{
currentPhase++;
@@ -88,8 +108,14 @@ public class BattleController : MonoBehaviour
CardPointsController.instance.PlayerAttack();
break;
case TurnOrder.enemyActive:
Debug.Log("Skipping enemy actions");
AdvanceTurn();
//Debug.Log("Skipping enemy actions");
//AdvanceTurn();
if(currentEnemyMaxMana < maxMana)
{
currentEnemyMaxMana++;
}
FillEnemyMana();
EnemyController.instance.StartAction();
break;
case TurnOrder.enemyCardAttacks:
//Debug.Log("Skipping enemy card attacks");

View File

@@ -1,11 +1,43 @@
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using System;
using Random = UnityEngine.Random;
using System.IO.Compression;
public class EnemyController : MonoBehaviour
{
public static EnemyController instance;
// Awake is called when the script instance is being loaded
void Awake()
{
{
instance = this;
}
}
public List<CardScriptableObject> deckToUse = new List<CardScriptableObject>();
public Card cardToSpawn;
public Transform cardSpawnPoint;
public enum AIType { placeFromDeck, handRandomPlace, handDefensive, handAttacking };
public AIType enemyAIType;
public int startHandSize;
private List<CardScriptableObject> activeCards = new List<CardScriptableObject>();
private List<CardScriptableObject> cardsInHand = new List<CardScriptableObject>();
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
SetUpDeck();
if(enemyAIType != AIType.placeFromDeck)
{
SetupHand();
}
}
// Update is called once per frame
@@ -13,4 +45,114 @@ public class EnemyController : MonoBehaviour
{
}
public void SetUpDeck()
{
activeCards.Clear();
int interations = 0;
List<CardScriptableObject> tempDeck = new List<CardScriptableObject>();
tempDeck.AddRange(deckToUse);
while (tempDeck.Count > 0 && interations < 500)
{
int selected = Random.Range(0, tempDeck.Count);
activeCards.Add(tempDeck[selected]);
tempDeck.RemoveAt(selected);
interations++;
}
}
public void StartAction()
{
StartCoroutine(EnemyActionCo());
}
IEnumerator EnemyActionCo()
{
if(activeCards.Count == 0)
{
SetUpDeck();
}
yield return new WaitForSeconds(.5f);
List<CardPlacePoint> cardPoints = new List<CardPlacePoint>();
cardPoints.AddRange(CardPointsController.instance.enemyCardPoints);
int randomPoint = Random.Range(0, cardPoints.Count);
CardPlacePoint selectedPoint = cardPoints[randomPoint];
if(enemyAIType == AIType.placeFromDeck || enemyAIType == AIType.handRandomPlace)
{
cardPoints.Remove(selectedPoint);
while(selectedPoint.activeCard != null && cardPoints.Count > 0)
{
randomPoint = Random.Range(0, cardPoints.Count);
selectedPoint = cardPoints[randomPoint];
cardPoints.RemoveAt(randomPoint);
}
}
CardScriptableObject selectedCard = null;
int interations = 0;
switch (enemyAIType)
{
case AIType.placeFromDeck:
if(selectedPoint.activeCard == null)
{
Card newCard = Instantiate(cardToSpawn, cardSpawnPoint.position, cardSpawnPoint.rotation);
newCard.cardSO = activeCards[0];
activeCards.RemoveAt(0);
newCard.SetupCard();
newCard.MoveToPoint(selectedPoint.transform.position, selectedPoint.transform.rotation);
selectedPoint.activeCard = newCard;
newCard.assignedPlace = selectedPoint;
}
break;
case AIType.handRandomPlace:
break;
case AIType.handDefensive:
break;
case AIType.handAttacking:
break;
}
yield return new WaitForSeconds(.5f);
BattleController.instance.AdvanceTurn();
}
void SetupHand()
{
for(int i = 0; i < startHandSize; i++)
{
if(activeCards.Count == 0)
{
SetUpDeck();
}
}
cardsInHand.Add(activeCards[0]);
activeCards.RemoveAt(0);
}
public void PlayCard(CardScriptableObject cardSO, CardPlacePoint placePoint)
{
Card newCard = Instantiate(cardToSpawn, cardSpawnPoint.position, cardSpawnPoint.rotation);
newCard.cardSO = cardSO;
newCard.SetupCard();
newCard.MoveToPoint(placePoint.transform.position, placePoint.transform.rotation);
placePoint.activeCard = newCard;
newCard.assignedPlace = placePoint;
cardsInHand.Remove(cardSO);
BattleController.instance.SpendEnemyMana(cardSO.manaCost);
}
}