Skip to content

Commit

Permalink
Implement guild bank deposit logic (#384)
Browse files Browse the repository at this point in the history
* Implement guild bank deposit logic

* Add gold item name suffix to "new balance" dialog

* Ensure guild bank balance works if the balance is zero
  • Loading branch information
ethanmoffat authored Oct 23, 2024
1 parent e073abf commit f380b5d
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 10 deletions.
2 changes: 1 addition & 1 deletion EOLib.Localization/DialogResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public enum DialogResourceID
GUILD_REMOVE_PLAYER_NOT_MEMBER = 186,
GUILD_REMOVE_PLAYER_IS_LEADER = 188,
GUILD_REMOVE_SUCCESS = 190,
GUILD_DEPOSIT_IS_1000 = 192,
GUILD_MINIMUM_DEPOSIT_IS_1000 = 192,
GUILD_DEPOSIT_NEW_BALANCE = 194,
ITEM_IS_LORE_ITEM = 196,
ITEM_IS_CURSED_ITEM = 198,
Expand Down
10 changes: 5 additions & 5 deletions EOLib.Localization/EOResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ public enum EOResourceID
GUILD_INFORMATION = 178,
GUILD_ADMINISTRATION = 179,
GUILD_MANAGEMENT = 180,

ADMIN_INFO_WORD_BANK_ACCOUNT = 181,

GUILD_BANK_ACCOUNT = ADMIN_INFO_WORD_BANK_ACCOUNT,
GUILD_LEARN_MORE = 182,
GUILD_JOIN_LEAVE_REGISTER = 183,
Expand Down Expand Up @@ -208,17 +206,16 @@ public enum EOResourceID
GUILD_ENTER_YOUR_GUILD_DETAILS = 216,
GUILD_GUILD_TAG = 217,
GUILD_GUILD_NAME = 218,
GUILD_GUILD_DESCRIPTION = 219,
GUILD_WORD_DESCRIPTION = 219,

GUILD_PLEASE_WAIT_FOR_ALL_MEMBERS_TO_JOIN = 222,
GUILD_DO_YOU_ACCEPT = 223,
GUILD_RECRUITER = 224,
GUILD_YOUR_ACCOUNT_WILL_BE_CHARGED = 225,
GUILD_PLEASE_CONSIDER_CAREFULLY_RECRUIT = 226,
GUILD_TO_VIEW_INFORMATION_ABOUT_A_GUILD_ENTER_ITS_TAG = 227,

GUILD_SIGNUP_DATE = 228,

GUILD_GUILD_DESCRIPTION = 229,
GUILD_RANKING_SYSTEM = 230,
GUILD_LEADERS = 231,

Expand All @@ -227,6 +224,9 @@ public enum EOResourceID
GUILD_CLICK_HERE_TO_CHANGE_THE_DESCRIPTION = 235,

GUILD_BANK_STATUS = 244,
GUILD_BANK_DESCRIPTION_1 = 245,
GUILD_BANK_DESCRIPTION_2 = 246,
GUILD_BANK_DESCRIPTION_3 = 247,

SETTING_KEYBOARD_ENGLISH = 253,
SETTING_KEYBOARD_DUTCH = 254,
Expand Down
23 changes: 23 additions & 0 deletions EOLib/Domain/Interact/Guild/GuildActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ public void SetGuildDescription(string description)
});
}

public void GetGuildBankBalance(string guildTag)
{
_packetSendService.SendPacket(new GuildTakeClientPacket
{
SessionId = _guildSessionRepository.SessionID,
InfoType = GuildInfoType.Bank,
GuildTag = guildTag
});
}

public void BankDeposit(int depositAmount)
{
_packetSendService.SendPacket(new GuildBuyClientPacket
{
SessionId = _guildSessionRepository.SessionID,
GoldAmount = depositAmount
});
}

public void RequestToJoinGuild(string guildTag, string recruiterName)
{
_packetSendService.SendPacket(new GuildPlayerClientPacket { SessionId = _guildSessionRepository.SessionID, GuildTag = guildTag, RecruiterName = recruiterName });
Expand Down Expand Up @@ -117,6 +136,10 @@ public interface IGuildActions

void SetGuildDescription(string description);

void GetGuildBankBalance(string guildTag);

void BankDeposit(int depositAmount);

void RequestToJoinGuild(string guildTag, string recruiterName);

void LeaveGuild();
Expand Down
7 changes: 7 additions & 0 deletions EOLib/Domain/Interact/Guild/GuildSessionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface IGuildSessionProvider

string GuildDescription { get; }

int GuildBalance { get; }

Option<GuildInfo> GuildInfo { get; }

IReadOnlyList<GuildMember> GuildMembers { get; }
Expand All @@ -26,6 +28,8 @@ public interface IGuildSessionRepository : IResettable

string GuildDescription { get; set; }

int GuildBalance { get; set; }

Option<GuildInfo> GuildInfo { get; set; }

List<GuildMember> GuildMembers { get; set; }
Expand All @@ -40,6 +44,8 @@ public class GuildSessionRepository : IGuildSessionRepository, IGuildSessionProv

public string GuildDescription { get; set; }

public int GuildBalance { get; set; }

public Option<GuildInfo> GuildInfo { get; set; }

public List<GuildMember> GuildMembers { get; set; }
Expand All @@ -56,6 +62,7 @@ public void ResetState()
SessionID = 0;
CreationSession = Option.None<GuildCreationSession>();
GuildDescription = string.Empty;
GuildBalance = 0;
GuildInfo = Option.None<GuildInfo>();
GuildMembers = new List<GuildMember>();
}
Expand Down
3 changes: 3 additions & 0 deletions EOLib/Domain/Notifiers/IGuildNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface IGuildNotifier
void NotifyGuildReply(GuildReply reply);

void NotifyConfirmCreateGuild();

void NotifyNewGuildBankBalance(int balance);
}

[AutoMappedType]
Expand All @@ -21,5 +23,6 @@ public void NotifyGuildCreationRequest(int creatorPlayerID, string guildIdentity
public void NotifyRequestToJoinGuild(int playerId, string name) { }
public void NotifyGuildReply(GuildReply reply) { }
public void NotifyConfirmCreateGuild() { }
public void NotifyNewGuildBankBalance(int balance) { }
}
}
57 changes: 57 additions & 0 deletions EOLib/PacketHandlers/Guild/GuildBuyHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Interact.Guild;
using EOLib.Domain.Login;
using EOLib.Domain.Notifiers;
using EOLib.Net.Handlers;
using Moffat.EndlessOnline.SDK.Protocol.Net;
using Moffat.EndlessOnline.SDK.Protocol.Net.Server;
using Optional.Collections;

namespace EOLib.PacketHandlers.Guild
{
[AutoMappedType]

public class GuildBuyHandler : InGameOnlyPacketHandler<GuildBuyServerPacket>
{
private readonly IGuildSessionProvider _guildSessionProvider;
private readonly ICharacterInventoryRepository _characterInventoryRepository;
private readonly IEnumerable<IGuildNotifier> _guildNotifiers;

public override PacketFamily Family => PacketFamily.Guild;

public override PacketAction Action => PacketAction.Buy;

public GuildBuyHandler(IPlayerInfoProvider playerInfoProvider,
IGuildSessionProvider guildSessionProvider,
ICharacterInventoryRepository characterInventoryRepository,
IEnumerable<IGuildNotifier> guildNotifiers)
: base(playerInfoProvider)
{
_guildSessionProvider = guildSessionProvider;
_characterInventoryRepository = characterInventoryRepository;
_guildNotifiers = guildNotifiers;
}

public override bool HandlePacket(GuildBuyServerPacket packet)
{
var oldAmount = _characterInventoryRepository.ItemInventory
.SingleOrNone(x => x.ItemID == 1)
.ValueOr(new InventoryItem(1, 0))
.Amount;

_characterInventoryRepository.ItemInventory.RemoveWhere(x => x.ItemID == 1);
_characterInventoryRepository.ItemInventory.Add(new InventoryItem(1, packet.GoldAmount));

var newBalance = _guildSessionProvider.GuildBalance + (oldAmount - packet.GoldAmount);

foreach (var notifier in _guildNotifiers)
{
notifier.NotifyNewGuildBankBalance(newBalance);
}

return true;
}
}
}
33 changes: 33 additions & 0 deletions EOLib/PacketHandlers/Guild/GuildSellHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using AutomaticTypeMapper;
using EOLib.Domain.Interact.Guild;
using EOLib.Domain.Login;
using EOLib.Net.Handlers;
using Moffat.EndlessOnline.SDK.Protocol.Net;
using Moffat.EndlessOnline.SDK.Protocol.Net.Server;

namespace EOLib.PacketHandlers.Guild
{
[AutoMappedType]

public class GuildSellHandler : InGameOnlyPacketHandler<GuildSellServerPacket>
{
private readonly IGuildSessionRepository _guildSessionRepository;

public override PacketFamily Family => PacketFamily.Guild;

public override PacketAction Action => PacketAction.Sell;

public GuildSellHandler(IPlayerInfoProvider playerInfoProvider,
IGuildSessionRepository guildSessionRepository)
: base(playerInfoProvider)
{
_guildSessionRepository = guildSessionRepository;
}

public override bool HandlePacket(GuildSellServerPacket packet)
{
_guildSessionRepository.GuildBalance = packet.GoldAmount;
return true;
}
}
}
4 changes: 4 additions & 0 deletions EndlessClient/Dialogs/Factories/GuildDialogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class GuildDialogFactory : IGuildDialogFactory
private readonly IGuildActions _guildActions;
private readonly ITextInputDialogFactory _textInputDialogFactory;
private readonly ITextMultiInputDialogFactory _textMultiInputDialogFactory;
private readonly IItemTransferDialogFactory _itemTransferDialogFactory;
private readonly IContentProvider _contentProvider;
private readonly ICharacterInventoryProvider _characterInventoryProvider;
private readonly IEIFFileProvider _eifFileProvider;
Expand All @@ -38,6 +39,7 @@ public GuildDialogFactory(INativeGraphicsManager nativeGraphicsManager,
IGuildActions guildActions,
ITextInputDialogFactory textInputDialogFactory,
ITextMultiInputDialogFactory textMultiInputDialogFactory,
IItemTransferDialogFactory itemTransferDialogFactory,
IContentProvider contentProvider,
ICharacterInventoryProvider characterInventoryProvider,
IEIFFileProvider eifFileProvider,
Expand All @@ -53,6 +55,7 @@ public GuildDialogFactory(INativeGraphicsManager nativeGraphicsManager,
_guildActions = guildActions;
_textInputDialogFactory = textInputDialogFactory;
_textMultiInputDialogFactory = textMultiInputDialogFactory;
_itemTransferDialogFactory = itemTransferDialogFactory;
_contentProvider = contentProvider;
_characterInventoryProvider = characterInventoryProvider;
_eifFileProvider = eifFileProvider;
Expand All @@ -71,6 +74,7 @@ public GuildDialog Create()
_guildActions,
_textInputDialogFactory,
_textMultiInputDialogFactory,
_itemTransferDialogFactory,
_contentProvider,
_characterInventoryProvider,
_eifFileProvider,
Expand Down
Loading

0 comments on commit f380b5d

Please sign in to comment.