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

SelectCard bug fix #59

Merged
merged 5 commits into from
Aug 20, 2018
Merged
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
114 changes: 82 additions & 32 deletions Game/GameAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ public void OnNewTurn()
/// </summary>
public void OnNewPhase()
{
m_selector = null;
m_nextSelector = null;
m_thirdSelector = null;
m_selector.Clear();
m_selector_pointer = -1;
m_materialSelector = null;
m_option = -1;
m_yesno = -1;
Expand Down Expand Up @@ -129,6 +128,8 @@ public void OnChaining(ClientCard card, int player)
/// </summary>
public void OnChainEnd()
{
m_selector.Clear();
m_selector_pointer = -1;
Executor.OnChainEnd();
}

Expand Down Expand Up @@ -721,9 +722,7 @@ public int OnAnnounceCard()
// _ Others functions _
// Those functions are used by the AI behavior.

private CardSelector m_selector;
private CardSelector m_nextSelector;
private CardSelector m_thirdSelector;

private CardSelector m_materialSelector;
private CardPosition m_position = CardPosition.FaceUpAttack;
private int m_place;
Expand All @@ -732,81 +731,138 @@ public int OnAnnounceCard()
private int m_announce;
private int m_yesno;
private IList<CardAttribute> m_attributes = new List<CardAttribute>();
private IList<CardSelector> m_selector = new List<CardSelector>();
private int m_selector_pointer = -1;
private IList<CardRace> m_races = new List<CardRace>();

public void SelectCard(ClientCard card)
{
m_selector = new CardSelector(card);
m_selector_pointer = m_selector.Count();
m_selector.Add(new CardSelector(card));
}

public void SelectCard(IList<ClientCard> cards)
{
m_selector = new CardSelector(cards);
m_selector_pointer = m_selector.Count();
m_selector.Add(new CardSelector(cards));
}

public void SelectCard(int cardId)
{
m_selector = new CardSelector(cardId);
m_selector_pointer = m_selector.Count();
m_selector.Add(new CardSelector(cardId));
}

public void SelectCard(IList<int> ids)
{
m_selector = new CardSelector(ids);
m_selector_pointer = m_selector.Count();
m_selector.Add(new CardSelector(ids));
}

public void SelectCard(CardLocation loc)
{
m_selector = new CardSelector(loc);
m_selector_pointer = m_selector.Count();
m_selector.Add(new CardSelector(loc));
}

public void SelectNextCard(ClientCard card)
{
m_nextSelector = new CardSelector(card);
if (m_selector_pointer == -1)
{
Logger.WriteErrorLine("Error: Call SelectNextCard() before SelectCard()");
m_selector_pointer = 0;
}
m_selector.Insert(m_selector_pointer, new CardSelector(card));
}

public void SelectNextCard(IList<ClientCard> cards)
{
m_nextSelector = new CardSelector(cards);
if (m_selector_pointer == -1)
{
Logger.WriteErrorLine("Error: Call SelectNextCard() before SelectCard()");
m_selector_pointer = 0;
}
m_selector.Insert(m_selector_pointer, new CardSelector(cards));
}

public void SelectNextCard(int cardId)
{
m_nextSelector = new CardSelector(cardId);
if (m_selector_pointer == -1)
{
Logger.WriteErrorLine("Error: Call SelectNextCard() before SelectCard()");
m_selector_pointer = 0;
}
m_selector.Insert(m_selector_pointer, new CardSelector(cardId));
}

public void SelectNextCard(IList<int> ids)
{
m_nextSelector = new CardSelector(ids);
if (m_selector_pointer == -1)
{
Logger.WriteErrorLine("Error: Call SelectNextCard() before SelectCard()");
m_selector_pointer = 0;
}
m_selector.Insert(m_selector_pointer, new CardSelector(ids));
}

public void SelectNextCard(CardLocation loc)
{
m_nextSelector = new CardSelector(loc);
if (m_selector_pointer == -1)
{
Logger.WriteErrorLine("Error: Call SelectNextCard() before SelectCard()");
m_selector_pointer = 0;
}
m_selector.Insert(m_selector_pointer, new CardSelector(loc));
}

public void SelectThirdCard(ClientCard card)
{
m_thirdSelector = new CardSelector(card);
if (m_selector_pointer == -1)
{
Logger.WriteErrorLine("Error: Call SelectThirdCard() before SelectCard()");
m_selector_pointer = 0;
}
m_selector.Insert(m_selector_pointer, new CardSelector(card));
}

public void SelectThirdCard(IList<ClientCard> cards)
{
m_thirdSelector = new CardSelector(cards);
if (m_selector_pointer == -1)
{
Logger.WriteErrorLine("Error: Call SelectThirdCard() before SelectCard()");
m_selector_pointer = 0;
}
m_selector.Insert(m_selector_pointer, new CardSelector(cards));
}

public void SelectThirdCard(int cardId)
{
m_thirdSelector = new CardSelector(cardId);
if (m_selector_pointer == -1)
{
Logger.WriteErrorLine("Error: Call SelectThirdCard() before SelectCard()");
m_selector_pointer = 0;
}
m_selector.Insert(m_selector_pointer, new CardSelector(cardId));
}

public void SelectThirdCard(IList<int> ids)
{
m_thirdSelector = new CardSelector(ids);
if (m_selector_pointer == -1)
{
Logger.WriteErrorLine("Error: Call SelectThirdCard() before SelectCard()");
m_selector_pointer = 0;
}
m_selector.Insert(m_selector_pointer, new CardSelector(ids));
}

public void SelectThirdCard(CardLocation loc)
{
m_thirdSelector = new CardSelector(loc);
if (m_selector_pointer == -1)
{
Logger.WriteErrorLine("Error: Call SelectThirdCard() before SelectCard()");
m_selector_pointer = 0;
}
m_selector.Insert(m_selector_pointer, new CardSelector(loc));
}

public void SelectMaterials(ClientCard card)
Expand Down Expand Up @@ -841,17 +897,11 @@ public void CleanSelectMaterials()

public CardSelector GetSelectedCards()
{
CardSelector selected = m_selector;
m_selector = null;
if (m_nextSelector != null)
CardSelector selected = null;
if (m_selector.Count > 0)
{
m_selector = m_nextSelector;
m_nextSelector = null;
if (m_thirdSelector != null)
{
m_nextSelector = m_thirdSelector;
m_thirdSelector = null;
}
selected = m_selector[m_selector.Count - 1];
m_selector.RemoveAt(m_selector.Count - 1);
}
return selected;
}
Expand Down Expand Up @@ -1004,4 +1054,4 @@ private bool ShouldExecute(CardExecutor exec, ClientCard card, ExecutorType type
return false;
}
}
}
}