-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from ethanmoffat/trade
Implement trading between players. Includes context menu, dialog, and packets.
- Loading branch information
Showing
51 changed files
with
1,351 additions
and
1,373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>()); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.