Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spaw enemies in a visitor #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Assets/Gameplay/Core/GameRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public class GameRoom : MonoBehaviour

Dealer Dealer { get; } = new Dealer();

public float maxTime = 20;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todas essas variáveis iriam para a classe do Bot descrita alí embaixo

public float minTime = 2;

private float time;

//The time to spawn the object
public float spawnTime;
void Start()
{
var gameObjectFactory = new GameObjectFactory(cardPrefabMap, playerPrefab);
Expand All @@ -39,10 +46,19 @@ void Start()
Dealer.DealInitialCards(VisitorPlayer);

matchReferee.Setup(gameActionFactory, players: new []{HomePlayer, VisitorPlayer});

SetRandomTime();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O GameRoom não parece o lugar ideal pra controlar a estratégia do bot que vai jogar pelo visitante, acho que uma solução mais robusta seria onde o VisitorPlayer é criado no gameObjectFactory ser instanciado uma PlayerBotController ou algo do tipo que implementa a interface IPlayer e no Update dele controla a estratégia de quando jogar uma carta e qual carta jogar, chamando nesse momento o OnVisitorUsedCard.

As vantagens dessa abordagem são principalmente continuar com a semântica do GameRoom só inicializar a sala e ter a lógica do Bot isolada em um lugar que facilita a extensão dela, no futuro poderemos ter varias estratégias diferentes para o bot e essa classe pode controlar isso.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se vocês discordarem dessa proposta de solução ou não entenderem algo do que eu falei a gente pode marcar uma call pra conversar melhor

time = minTime;
}

void SetRandomTime(){
spawnTime = Random.Range(minTime, maxTime);
Debug.Log ("Next object spawn in " + spawnTime + " seconds.");
}

void Awake() => AddObservers();


void OnDestroy() => RemoveObservers();

void AddObservers()
Expand All @@ -51,6 +67,16 @@ void AddObservers()
gameplayHUD.OnUseCard += OnHomePlayerUsedCard;
}

void Update(){
time += Time.deltaTime;

if(time >= spawnTime){
Dealer.DealCard(VisitorPlayer);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse DealCard do visitor iria pro OnVisitorUsedCard após o uso da carta assim como acontece no OnHomePlayerUsedCard

OnVisitorUsedCard();
time = 0;
}
}

void RemoveObservers()
{
Dealer.OnDealtCard -= gameplayHUD.OnCardDealt;
Expand All @@ -59,8 +85,16 @@ void RemoveObservers()

void OnHomePlayerUsedCard(CardType card, int laneIdx)
{

matchReferee.OnPlayerUsedCard(card, HomePlayer.Team, laneIdx);
Dealer.DealCard(HomePlayer);

}

void OnVisitorUsedCard(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse método está no lugar certo, mas ele precisa ser acessado pelo Bot, um jeito interessante seria o Bot ter uma Action<CardType, int> PlayCard que pode ser setada no Start do GameRoom, assim a gente não cria o acoplamento de ter no Bot acesso direto ao GameRoom

CardType Card = VisitorPlayer.Hand.Cards[0];
matchReferee.OnPlayerUsedCard(Card, VisitorPlayer.Team, 0);

}
}
}
2 changes: 1 addition & 1 deletion Assets/Gameplay/Core/PlayerHand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class PlayerHand
{
public const int HandSize = 4;

List<CardType> Cards { get; } = new List<CardType>();
public List<CardType> Cards { get; } = new List<CardType>();

public int Size => Cards.Count;

Expand Down
8 changes: 0 additions & 8 deletions Assets/Plugins/Editor.meta

This file was deleted.

4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2019.4.9f1
m_EditorVersionWithRevision: 2019.4.9f1 (50fe8a171dd9)
m_EditorVersion: 2019.4.10f1
m_EditorVersionWithRevision: 2019.4.10f1 (5311b3af6f69)