Commit b9f20076 authored by wind2009's avatar wind2009

Add player hint

parent d70c30ec
......@@ -6,6 +6,7 @@
*.user
*.sln.docstates
.vs/
.vscode/
# Build results
......
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using YGOSharp.OCGWrapper.Enums;
......@@ -578,6 +578,18 @@ namespace WindBot.Game.AI
return null;
}
public override void OnPlayerHint(int player, int hintType, int description)
{
base.OnPlayerHint(player, hintType, description);
if (player != 0 && player != 1)
return;
ClientField field = (player == 0) ? Bot : Enemy;
if (hintType == (int)PlayerHintType.DescAdd)
field.HintDescriptions.Add(description);
else if (hintType == (int)PlayerHintType.DescRemove)
field.HintDescriptions.Remove(description);
}
public override void OnReceivingAnnouce(int player, int data)
{
if (player == 1 && data == Util.GetStringId(_CardId.LightningStorm, 0) || data == Util.GetStringId(_CardId.LightningStorm, 1))
......
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using YGOSharp.OCGWrapper.Enums;
......@@ -121,6 +121,17 @@ namespace WindBot.Game.AI
// Some AI need do something on draw
}
/// <summary>
/// Called when a PlayerHint is received (e.g. effect description add/remove; can be used to track "once per turn" usage).
/// </summary>
/// <param name="player">Player index</param>
/// <param name="hintType">Hint type, see PlayerHintType (DescAdd=6, DescRemove=7)</param>
/// <param name="description">Effect description id (peffect->description)</param>
public virtual void OnPlayerHint(int player, int hintType, int description)
{
// For overriding
}
public virtual void OnMove(ClientCard card, int previousControler, int previousLocation, int currentControler, int currentLocation)
{
// Some AI need do something on card's moving
......
......@@ -19,6 +19,8 @@ namespace WindBot.Game
public ClientCard BattlingMonster;
public bool UnderAttack;
public HashSet<int> HintDescriptions { get; private set; }
public ClientField()
{
}
......@@ -32,6 +34,7 @@ namespace WindBot.Game
Banished = new List<ClientCard>();
Deck = new List<ClientCard>();
ExtraDeck = new List<ClientCard>();
HintDescriptions = new HashSet<int>();
for (int i = 0; i < deck; ++i)
Deck.Add(new ClientCard(0, CardLocation.Deck, -1));
......
using System.Linq;
using System.Linq;
using System.Collections.Generic;
using System.Threading;
using WindBot.Game.AI;
......@@ -185,6 +185,17 @@ namespace WindBot.Game
CheckSurrender();
}
/// <summary>
/// Called when a PlayerHint message is received (e.g. effect description add/remove hints).
/// </summary>
/// <param name="player">Player index</param>
/// <param name="hintType">Hint type, see PlayerHintType (DescAdd=6, DescRemove=7)</param>
/// <param name="description">Effect description id (peffect->description)</param>
public void OnPlayerHint(int player, int hintType, int description)
{
Executor.OnPlayerHint(player, hintType, description);
}
/// <summary>
/// Called when receiving annouce
/// </summary>
......
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
......@@ -151,6 +151,7 @@ namespace WindBot.Game
_messages.Add(GameMessage.FlipSummoning, OnSummoning);
_messages.Add(GameMessage.FlipSummoned, OnSummoned);
_messages.Add(GameMessage.ConfirmCards, OnConfirmCards);
_messages.Add(GameMessage.PlayerHint, OnPlayerHint);
}
private void OnJoinGame(BinaryReader packet)
......@@ -2015,5 +2016,18 @@ namespace WindBot.Game
Logger.WriteLine("(Confirm " + player.ToString() + "'s " + (CardLocation)loc + " card: " + (card.Name ?? "UnKnowCard") + ")");
}
}
/// <summary>
/// Handles PlayerHint message. Protocol: player(buffer8), hintType(buffer8), description(buffer32).
/// hintType values: PlayerHintType (e.g. PHINT_DESC_ADD=6, PHINT_DESC_REMOVE=7).
/// </summary>
private void OnPlayerHint(BinaryReader packet)
{
int player = packet.ReadByte();
int hintType = packet.ReadByte();
int description = packet.ReadInt32();
Logger.DebugWriteLine("PlayerHint received: player=" + player + ", hintType=" + hintType + " (" + (PlayerHintType)hintType + "), description=" + description);
_ai.OnPlayerHint(player, hintType, description);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
......@@ -181,6 +181,7 @@
<Compile Include="YGOSharp.OCGWrapper.Enums\CardType.cs" />
<Compile Include="YGOSharp.OCGWrapper.Enums\DuelPhase.cs" />
<Compile Include="YGOSharp.OCGWrapper.Enums\GameMessage.cs" />
<Compile Include="YGOSharp.OCGWrapper.Enums\PlayerHintType.cs" />
<Compile Include="YGOSharp.OCGWrapper.Enums\Query.cs" />
<Compile Include="YGOSharp.OCGWrapper\Card.cs" />
<Compile Include="YGOSharp.OCGWrapper\CardsManager.cs" />
......
namespace YGOSharp.OCGWrapper.Enums
{
/// <summary>
/// Hint type for PlayerHint message (matches PHINT constants in core).
/// </summary>
public enum PlayerHintType
{
/// <summary>Add effect description hint</summary>
DescAdd = 6,
/// <summary>Remove effect description hint</summary>
DescRemove = 7
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment