Finalised AI scripts and added in some limitations to mana and hand size, removed auto draw at the end of each turn, as well as reducing mana top-up each round to 1

This commit is contained in:
SHOUTING_PIRATE
2025-04-28 17:25:10 +01:00
parent 11297a3078
commit ab6878fa69
56 changed files with 69508 additions and 5065 deletions

View File

@@ -3,7 +3,7 @@ using System.Collections;
using UnityEngine;
using System;
using Random = UnityEngine.Random;
using System.IO.Compression;
public class EnemyController : MonoBehaviour
{
@@ -50,18 +50,18 @@ public class EnemyController : MonoBehaviour
{
activeCards.Clear();
int interations = 0;
int iterations = 0;
List<CardScriptableObject> tempDeck = new List<CardScriptableObject>();
tempDeck.AddRange(deckToUse);
while (tempDeck.Count > 0 && interations < 500)
while (tempDeck.Count > 0 && iterations < 500)
{
int selected = Random.Range(0, tempDeck.Count);
activeCards.Add(tempDeck[selected]);
tempDeck.RemoveAt(selected);
interations++;
iterations++;
}
}
@@ -78,6 +78,19 @@ public class EnemyController : MonoBehaviour
}
yield return new WaitForSeconds(.5f);
if(enemyAIType != AIType.placeFromDeck)
{
for(int i = 0; i < BattleController.instance.cardsToDrawPerTurn; i++)
{
cardsInHand.Add(activeCards[0]);
activeCards.RemoveAt(0);
if(activeCards.Count == 0)
{
SetUpDeck();
}
}
}
List<CardPlacePoint> cardPoints = new List<CardPlacePoint>();
cardPoints.AddRange(CardPointsController.instance.enemyCardPoints);
@@ -96,7 +109,9 @@ public class EnemyController : MonoBehaviour
}
CardScriptableObject selectedCard = null;
int interations = 0;
int iterations = 0;
List<CardPlacePoint> preferredPoints = new List<CardPlacePoint>();
List<CardPlacePoint> secondaryPoints = new List<CardPlacePoint>();
switch (enemyAIType)
{
@@ -115,12 +130,101 @@ public class EnemyController : MonoBehaviour
break;
case AIType.handRandomPlace:
selectedCard = SelectedCardToPlay();
iterations = 50;
while(selectedCard != null && iterations > 0 && selectedPoint.activeCard == null)
{
PlayCard(selectedCard, selectedPoint);
selectedCard = SelectedCardToPlay();
iterations--;
yield return new WaitForSeconds(CardPointsController.instance.timeBetweenAttacks);
while(selectedPoint.activeCard != null && cardPoints.Count > 0)
{
randomPoint = Random.Range(0, cardPoints.Count);
selectedPoint = cardPoints[randomPoint];
cardPoints.RemoveAt(randomPoint);
}
}
break;
case AIType.handDefensive:
selectedCard = SelectedCardToPlay();
preferredPoints.Clear();
secondaryPoints.Clear();
for(int i = 0; i < cardPoints.Count; i++)
{
if(cardPoints[i].activeCard == null)
{
if(CardPointsController.instance.playerCardPoints[i].activeCard != null)
{
preferredPoints.Add(cardPoints[i]);
}
else
{
secondaryPoints.Add(cardPoints[i]);
}
}
}
iterations = 50;
while(selectedCard != null && iterations > 0 && preferredPoints.Count + secondaryPoints.Count > 0)
{
if(preferredPoints.Count > 0)
{
int selectPoint = Random.Range(0, preferredPoints.Count);
selectedPoint = preferredPoints[selectPoint];
preferredPoints.RemoveAt(selectPoint);
}
else
{
int selectPoint = Random.Range(0, secondaryPoints.Count);
selectedPoint = secondaryPoints[selectPoint];
secondaryPoints.RemoveAt(selectPoint);
}
PlayCard(selectedCard, selectedPoint);
selectedCard = SelectedCardToPlay();
iterations--;
yield return new WaitForSeconds(CardPointsController.instance.timeBetweenAttacks);
}
break;
case AIType.handAttacking:
selectedCard = SelectedCardToPlay();
preferredPoints.Clear();
secondaryPoints.Clear();
for(int i = 0; i < cardPoints.Count; i++)
{
if(cardPoints[i].activeCard == null)
{
if(CardPointsController.instance.playerCardPoints[i].activeCard == null)
{
preferredPoints.Add(cardPoints[i]);
}
else
{
secondaryPoints.Add(cardPoints[i]);
}
}
}
iterations = 50;
while(selectedCard != null && iterations > 0 && preferredPoints.Count + secondaryPoints.Count > 0)
{
if(preferredPoints.Count > 0)
{
int selectPoint = Random.Range(0, preferredPoints.Count);
selectedPoint = preferredPoints[selectPoint];
preferredPoints.RemoveAt(selectPoint);
}
else
{
int selectPoint = Random.Range(0, secondaryPoints.Count);
selectedPoint = secondaryPoints[selectPoint];
secondaryPoints.RemoveAt(selectPoint);
}
PlayCard(selectedCard, selectedPoint);
selectedCard = SelectedCardToPlay();
iterations--;
yield return new WaitForSeconds(CardPointsController.instance.timeBetweenAttacks);
}
break;
}
@@ -138,9 +242,9 @@ public class EnemyController : MonoBehaviour
{
SetUpDeck();
}
}
cardsInHand.Add(activeCards[0]);
activeCards.RemoveAt(0);
}
}
public void PlayCard(CardScriptableObject cardSO, CardPlacePoint placePoint)
@@ -154,5 +258,27 @@ public class EnemyController : MonoBehaviour
cardsInHand.Remove(cardSO);
BattleController.instance.SpendEnemyMana(cardSO.manaCost);
}
CardScriptableObject SelectedCardToPlay()
{
CardScriptableObject cardToPlay = null;
List<CardScriptableObject> cardsToPlay = new List<CardScriptableObject>();
foreach(CardScriptableObject card in cardsInHand)
{
if(card.manaCost <= BattleController.instance.enemyMana)
{
cardsToPlay.Add(card);
}
}
if(cardsToPlay.Count > 0)
{
int selected = Random.Range(0, cardsToPlay.Count);
cardToPlay = cardsToPlay[selected];
}
return cardToPlay;
}
}