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

Implement trading between players. Includes context menu, dialog, and packets. #215

Merged
merged 18 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3f14500
Convert Trade network API calls to TradeActions
ethanmoffat Jun 14, 2022
1af2c5b
Convert trade packets to new paradigm. Remove PacketAPI and PacketAPI…
ethanmoffat Aug 30, 2022
33bd06b
Calculate inventory weight changes when completing a trade
ethanmoffat Sep 1, 2022
e4d6dc8
Trading WIP
ethanmoffat Sep 7, 2022
aaa474b
Merge branch 'master' into trade
ethanmoffat Sep 15, 2022
64e1ba7
Add check for NPC renderer existence before attempting to show damage…
ethanmoffat Sep 15, 2022
cc295d6
Update base dialog to store a NativeGraphicsManager. Allows trade dia…
ethanmoffat Sep 15, 2022
716f636
Update inventory drag+drop to work with bank deposit
ethanmoffat Sep 15, 2022
c0d1145
First-pass implementation of trade dialog.
ethanmoffat Sep 15, 2022
fdd97b2
Implement InventorySpaceValidator.ItemsFit
ethanmoffat Sep 16, 2022
a4524c2
Support drag+drop to add item to trade offer
ethanmoffat Sep 16, 2022
a461571
Wire up trade actions to context menu. Finish implementing trade dial…
ethanmoffat Sep 16, 2022
f1c2cd9
Fix various minor display bugs in TradeDialog
ethanmoffat Sep 16, 2022
363b619
Ensure equality of InventoryItem/TradeOffer is properly defined
ethanmoffat Sep 16, 2022
15e1514
Remove TradeSessionID (this is probably not what the mystery byte is …
ethanmoffat Sep 16, 2022
23158cc
Ensure trade agree is setting agreement for the correct player
ethanmoffat Sep 16, 2022
78a2a54
Ensure trade offer updates read the break bytes. Ensure weight never …
ethanmoffat Sep 16, 2022
dc5e49f
Remove erroneously added System.Windows.Documents using statement
ethanmoffat Sep 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion EOLib.IO/Map/Matrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Matrix(int rows, int cols, T defaultValue)
Fill(defaultValue);
}

public Matrix(Matrix<T> other)
public Matrix(IReadOnlyMatrix<T> other)
: this(new T[other.Rows, other.Cols])
{
for (int row = 0; row < other.Rows; ++row)
Expand Down
2 changes: 1 addition & 1 deletion EOLib/Domain/Character/InventoryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EOLib.Domain.Character
{
[Record]
[Record(Features.Default | Features.EquatableEquals | Features.ObjectEquals)]
public sealed partial class InventoryItem
{
public short ItemID { get; }
Expand Down
23 changes: 23 additions & 0 deletions EOLib/Domain/Notifiers/ITradeEventNotifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using AutomaticTypeMapper;

namespace EOLib.Domain.Notifiers
{
public interface ITradeEventNotifier
{
void NotifyTradeRequest(short playerId, string name);

void NotifyTradeAccepted();

void NotifyTradeClose(bool cancel);
}

[AutoMappedType]
public class NoopTradeEventNotifier : ITradeEventNotifier
{
public void NotifyTradeRequest(short playerId, string name) { }

public void NotifyTradeAccepted() { }

public void NotifyTradeClose(bool cancel) { }
}
}
84 changes: 84 additions & 0 deletions EOLib/Domain/Trade/TradeActions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using AutomaticTypeMapper;
using EOLib.Net;
using EOLib.Net.Communication;
using System;

namespace EOLib.Domain.Trade
{
[AutoMappedType]
public class TradeActions : ITradeActions
{
private readonly IPacketSendService _packetSendService;

public TradeActions(IPacketSendService packetSendService)
{
_packetSendService = packetSendService;
}

public void RequestTrade(short characterID)
{
var packet = new PacketBuilder(PacketFamily.Trade, PacketAction.Request)
.AddChar(6)
.AddShort(characterID)
.Build();
_packetSendService.SendPacket(packet);
}

public void AcceptTradeRequest(short characterID)
{
var packet = new PacketBuilder(PacketFamily.Trade, PacketAction.Accept)
.AddChar(6)
.AddShort(characterID)
.Build();
_packetSendService.SendPacket(packet);
}

public void RemoveItemFromOffer(short itemID)
{
var packet = new PacketBuilder(PacketFamily.Trade, PacketAction.Remove)
.AddShort(itemID)
.Build();
_packetSendService.SendPacket(packet);
}

public void AddItemToOffer(short itemID, int amount)
{
var packet = new PacketBuilder(PacketFamily.Trade, PacketAction.Add)
.AddShort(itemID)
.AddInt(amount)
.Build();
_packetSendService.SendPacket(packet);
}

public void AgreeToTrade(bool agree)
{
var packet = new PacketBuilder(PacketFamily.Trade, PacketAction.Agree)
.AddChar((byte)(agree ? 1 : 0))
.Build();
_packetSendService.SendPacket(packet);
}

public void CancelTrade()
{
var packet = new PacketBuilder(PacketFamily.Trade, PacketAction.Close)
.AddChar(6)
.Build();
_packetSendService.SendPacket(packet);
}
}

public interface ITradeActions
{
void RequestTrade(short characterID);

void AcceptTradeRequest(short characterID);

void RemoveItemFromOffer(short itemID);

void AddItemToOffer(short itemID, int amount);

void AgreeToTrade(bool agree);

void CancelTrade();
}
}
18 changes: 18 additions & 0 deletions EOLib/Domain/Trade/TradeOffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Amadevus.RecordGenerator;
using EOLib.Domain.Character;
using System.Collections.Generic;

namespace EOLib.Domain.Trade
{
[Record(Features.Default | Features.EquatableEquals | Features.ObjectEquals)]
public sealed partial class TradeOffer
{
public bool Agrees { get; }

public short PlayerID { get; }

public string PlayerName { get; }

public IReadOnlyList<InventoryItem> Items { get; }
}
}
39 changes: 39 additions & 0 deletions EOLib/Domain/Trade/TradeRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using System.Collections.Generic;

namespace EOLib.Domain.Trade
{
public interface ITradeRepository : IResettable
{
TradeOffer PlayerOneOffer { get; set; }

TradeOffer PlayerTwoOffer { get; set; }
}

public interface ITradeProvider
{
TradeOffer PlayerOneOffer { get; }

TradeOffer PlayerTwoOffer { get; }
}

[AutoMappedType(IsSingleton = true)]
public class TradeRepository : ITradeRepository, ITradeProvider
{
public TradeOffer PlayerOneOffer { get; set; }

public TradeOffer PlayerTwoOffer { get; set; }

public TradeRepository()
{
ResetState();
}

public void ResetState()
{
PlayerOneOffer = new TradeOffer(false, 0, string.Empty, new List<InventoryItem>());
PlayerTwoOffer = new TradeOffer(false, 0, string.Empty, new List<InventoryItem>());
}
}
}
30 changes: 0 additions & 30 deletions EOLib/Net/API/PacketAPI.cs

This file was deleted.