Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ static ArchipelagoSession CreateTestSession(IArchipelagoSocketHelper socket,
var roomState = new RoomStateHelper(socket, locations);
var dataStorage = new DataStorageHelper(socket, connectionInfo);
var messageLog = new MessageLogHelper(socket, itemInfoResolver, players, connectionInfo);
var createHints = new CreateHintsHelper(socket, players, locations, roomState);

return new ArchipelagoSession(socket, items, locations, players, roomState, connectionInfo, dataStorage, messageLog);
return new ArchipelagoSession(socket, items, locations, players, roomState, connectionInfo, dataStorage, messageLog, createHints);
}

static void SetupLoginResultPacket(IArchipelagoSocketHelper socket, ArchipelagoPacketBase loginResultPacket) =>
Expand Down
7 changes: 6 additions & 1 deletion Archipelago.MultiClient.Net/ArchipelagoSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ public partial class ArchipelagoSession : IArchipelagoSession
/// <inheritdoc/>
public IMessageLogHelper MessageLog { get; }

/// <inheritdoc/>
public ICreateHintsHelper CreateHints { get; }

#if NET35
volatile bool awaitingRoomInfo;
volatile bool expectingLoginResult;
Expand All @@ -165,7 +168,8 @@ internal ArchipelagoSession(IArchipelagoSocketHelper socket,
IRoomStateHelper roomState,
ConnectionInfoHelper connectionInfoHelper,
IDataStorageHelper dataStorage,
IMessageLogHelper messageLog)
IMessageLogHelper messageLog,
ICreateHintsHelper createHints)
{
Socket = socket;
Items = items;
Expand All @@ -175,6 +179,7 @@ internal ArchipelagoSession(IArchipelagoSocketHelper socket,
connectionInfo = connectionInfoHelper;
DataStorage = dataStorage;
MessageLog = messageLog;
CreateHints = createHints;

socket.PacketReceived += Socket_PacketReceived;
}
Expand Down
11 changes: 6 additions & 5 deletions Archipelago.MultiClient.Net/ArchipelagoSessionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ public static ArchipelagoSession CreateSession(Uri uri)
var dataPackageCache = new DataPackageCache(socket);
var connectionInfo = new ConnectionInfoHelper(socket);
var players = new PlayerHelper(socket, connectionInfo);
var itemInfoResolver = new ItemInfoResolver(dataPackageCache, connectionInfo);
var locations = new LocationCheckHelper(socket, itemInfoResolver, connectionInfo, players);
var itemInfoResolver = new ItemInfoResolver(dataPackageCache, connectionInfo);
var locations = new LocationCheckHelper(socket, itemInfoResolver, connectionInfo, players);
var items = new ReceivedItemsHelper(socket, locations, itemInfoResolver, connectionInfo, players);
var roomState = new RoomStateHelper(socket, locations);
var dataStorage = new DataStorageHelper(socket, connectionInfo);
var roomState = new RoomStateHelper(socket, locations);
var dataStorage = new DataStorageHelper(socket, connectionInfo);
var messageLog = new MessageLogHelper(socket, itemInfoResolver, players, connectionInfo);
var createHints = new CreateHintsHelper(socket, players, locations, roomState);

return new ArchipelagoSession(socket, items, locations, players, roomState, connectionInfo, dataStorage, messageLog);
return new ArchipelagoSession(socket, items, locations, players, roomState, connectionInfo, dataStorage, messageLog, createHints);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class ArchipelagoPacketConverter : JsonConverter
[ArchipelagoPacketType.Connect] = obj => obj.ToObject<ConnectPacket>(),
[ArchipelagoPacketType.ConnectUpdate] = obj => obj.ToObject<ConnectUpdatePacket>(),
[ArchipelagoPacketType.LocationChecks] = obj => obj.ToObject<LocationChecksPacket>(),
[ArchipelagoPacketType.LocationScouts] = obj => obj.ToObject<LocationScoutsPacket>(),
[ArchipelagoPacketType.LocationScouts] = obj => obj.ToObject<LocationScoutsPacket>(),
[ArchipelagoPacketType.CreateHints] = obj => obj.ToObject<CreateHintsPacket>(),
[ArchipelagoPacketType.StatusUpdate] = obj => obj.ToObject<StatusUpdatePacket>(),
[ArchipelagoPacketType.Say] = obj => obj.ToObject<SayPacket>(),
[ArchipelagoPacketType.GetDataPackage] = obj => obj.ToObject<GetDataPackagePacket>(),
Expand Down
1 change: 1 addition & 0 deletions Archipelago.MultiClient.Net/Enums/ArchipelagoPacketType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum ArchipelagoPacketType
ConnectUpdate,
LocationChecks,
LocationScouts,
CreateHints,
StatusUpdate,
Say,
GetDataPackage,
Expand Down
107 changes: 107 additions & 0 deletions Archipelago.MultiClient.Net/Helpers/CreateHintsHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using Archipelago.MultiClient.Net.Enums;
using Archipelago.MultiClient.Net.Packets;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Archipelago.MultiClient.Net.Helpers
{
/// <summary>
/// Provides information about the current state of the server
/// </summary>
public interface ICreateHintsHelper
{
/// <summary>
/// Tell the server to create hints for the specified locations.
/// When creating hints for another slot's locations, the packet will fail if any of those locations do not contain an item for the requesting slot.
/// When creating hints for your own slot's locations, non-existing locations will be silently skipped.
/// </summary>
/// <param name="player">
/// The ID of the player whose locations ar ebeing hinted for.
/// </param>
/// <param name="hintStatus">
/// If included, sets the status of the created hints to this status.
/// Defaults to unspecified.
/// </param>
/// <param name="ids">
/// The location ids to create hints for.
/// </param>
/// <exception cref="T:Archipelago.MultiClient.Net.Exceptions.ArchipelagoSocketClosedException">
/// The websocket connection is not alive.
/// </exception>
void CreateHints(int player, HintStatus hintStatus = HintStatus.Unspecified, params long[] ids);

/// <summary>
/// Tell the server to create hints for the specified locations.
/// This version does not include the player id, and as such will only hint for locations in the active player's game.
/// When creating hints, non-existing locations will be silently skipped.
/// </summary>
/// <param name="hintStatus">
/// If included, sets the status of the created hints to this status.
/// Defaults to unspecified.
/// </param>
/// <param name="ids">
/// The location ids to create hints for.
/// </param>
/// <exception cref="T:Archipelago.MultiClient.Net.Exceptions.ArchipelagoSocketClosedException">
/// The websocket connection is not alive.
/// </exception>
void CreateHints(HintStatus hintStatus = HintStatus.Unspecified, params long[] ids);
}

///<inheritdoc/>
public class CreateHintsHelper : ICreateHintsHelper
{
readonly IArchipelagoSocketHelper socket;
readonly ILocationCheckHelper locationCheckHelper;
readonly IRoomStateHelper roomStateHelper;
readonly IPlayerHelper players;

///<inheritdoc/>
public Version Version { get; private set; }

internal CreateHintsHelper(IArchipelagoSocketHelper socket, IPlayerHelper players, ILocationCheckHelper locationCheckHelper, IRoomStateHelper roomStateHelper)
{
this.socket = socket;
this.players = players;
this.locationCheckHelper = locationCheckHelper;
this.roomStateHelper = roomStateHelper;
}

/// <inheritdoc/>
public void CreateHints(int player, HintStatus hintStatus = HintStatus.Unspecified, params long[] ids)
{
// The server supports CreateHints after version 0.6.2
if (roomStateHelper.Version.CompareTo(new Version(0, 6, 2)) <= 0)
{
CreateHintsFallback(ids);
}
else
{
socket.SendPacket(new CreateHintsPacket
{
Locations = ids,
Player = player,
Status = (int)hintStatus
});
}
}

#if NET35

/// <inheritdoc/>
public void CreateHintsFallback(params long[] ids) => locationCheckHelper.ScoutLocationsAsync(null, createAsHint: true, ids);
#else
/// <inheritdoc/>
public void CreateHintsFallback(params long[] ids) => locationCheckHelper.ScoutLocationsAsync(createAsHint: true, ids);
#endif

/// <inheritdoc/>
public void CreateHints(HintStatus hintStatus = HintStatus.Unspecified, params long[] ids)
{
// When the player is not included, it defaults to the requesting slot.
var currentPlayer = players.ActivePlayer.Slot;
CreateHints(currentPlayer, hintStatus, ids);
}
}
}
2 changes: 1 addition & 1 deletion Archipelago.MultiClient.Net/Helpers/LocationCheckHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ LocationChecksPacket GetLocationChecksPacket() =>

#if NET35
/// <inheritdoc/>
public void ScoutLocationsAsync(Action<Dictionary<long, ScoutedItemInfo>> callback = null,
public void ScoutLocationsAsync(Action<Dictionary<long, ScoutedItemInfo>> callback = null,
HintCreationPolicy hintCreationPolicy = HintCreationPolicy.None, params long[] ids)
{
var idsToScout = ids.Where(i => allLocations.Contains(i)).ToArray();
Expand Down
19 changes: 19 additions & 0 deletions Archipelago.MultiClient.Net/Packets/CreateHintsPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Archipelago.MultiClient.Net.Enums;
using Newtonsoft.Json;

namespace Archipelago.MultiClient.Net.Packets
{
public class CreateHintsPacket : ArchipelagoPacketBase
{
public override ArchipelagoPacketType PacketType => ArchipelagoPacketType.CreateHints;

[JsonProperty("locations")]
public long[] Locations { get; set; }

[JsonProperty("player")]
public int Player { get; set; }

[JsonProperty("status")]
public int Status { get; set; }
}
}
Loading