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

Re-implement paperdoll/context menu #122

Merged
merged 9 commits into from
Mar 24, 2022
2 changes: 1 addition & 1 deletion EOBot/TrainerBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private async Task UseHealItem(IEnumerable<IInventoryItem> healItems)

ConsoleHelper.WriteMessage(ConsoleHelper.Type.UseItem, $"{itemToUse.Name} - {itemToUse.HP} HP - inventory: {amount - 1} - (other heal item types: {healItems.Count() - 1})");

await TrySend(() => _characterActions.UseItem(itemToUse.ID));
await TrySend(() => _characterActions.UseItem((short)itemToUse.ID));

await Task.Delay(ATTACK_BACKOFF_MS);
}
Expand Down
30 changes: 27 additions & 3 deletions EOLib/Domain/Character/CharacterActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,30 @@ public void ToggleSit()
_packetSendService.SendPacket(packet);
}

public void UseItem(int itemId)
public void UseItem(short itemId)
{
var packet = new PacketBuilder(PacketFamily.Item, PacketAction.Use)
.AddShort((short)itemId)
.AddShort(itemId)
.Build();

_packetSendService.SendPacket(packet);
}

public void EquipItem(short itemId, bool alternateLocation)
{
var packet = new PacketBuilder(PacketFamily.PaperDoll, PacketAction.Add)
.AddShort(itemId)
.AddChar((byte)(alternateLocation ? 1 : 0))
.Build();

_packetSendService.SendPacket(packet);
}

public void UnequipItem(short itemId, bool alternateLocation)
{
var packet = new PacketBuilder(PacketFamily.PaperDoll, PacketAction.Remove)
.AddShort(itemId)
.AddChar((byte)(alternateLocation ? 1 : 0))
.Build();

_packetSendService.SendPacket(packet);
Expand Down Expand Up @@ -159,7 +179,11 @@ public interface ICharacterActions

void ToggleSit();

void UseItem(int itemId);
void UseItem(short itemId);

void EquipItem(short itemId, bool alternateLocation);

void UnequipItem(short itemId, bool alternateLocation);

void PrepareCastSpell(int spellId);

Expand Down
168 changes: 168 additions & 0 deletions EOLib/Domain/Character/PaperdollData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
using EOLib.Domain.Online;
using EOLib.IO;
using System.Collections.Generic;
using System.Linq;

namespace EOLib.Domain.Character
{
public class PaperdollData : IPaperdollData
{
public string Name { get; private set; }

public string Home { get; private set; }

public string Partner { get; private set; }

public string Title { get; private set; }

public string Guild { get; private set; }

public string Rank { get; private set; }

public short PlayerID { get; private set; }

public byte Class { get; private set; }

public byte Gender { get; private set; }

public IReadOnlyDictionary<EquipLocation, short> Paperdoll { get; private set; }

public OnlineIcon Icon { get; private set; }

public PaperdollData()
{
Paperdoll = new Dictionary<EquipLocation, short>();
}

private PaperdollData(string name,
string home,
string partner,
string title,
string guild,
string rank,
short playerID,
byte @class,
byte gender,
IReadOnlyDictionary<EquipLocation, short> paperdoll,
OnlineIcon icon)
{
Name = name;
Home = home;
Partner = partner;
Title = title;
Guild = guild;
Rank = rank;
PlayerID = playerID;
Class = @class;
Gender = gender;
Paperdoll = paperdoll;
Icon = icon;
}

public IPaperdollData WithName(string name)
{
return new PaperdollData(name, Home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon);
}

public IPaperdollData WithHome(string home)
{
return new PaperdollData(Name, home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon);
}

public IPaperdollData WithPartner(string partner)
{
return new PaperdollData(Name, Home, partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon);
}

public IPaperdollData WithTitle(string title)
{
return new PaperdollData(Name, Home, Partner, title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon);
}

public IPaperdollData WithGuild(string guild)
{
return new PaperdollData(Name, Home, Partner, Title, guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon);
}

public IPaperdollData WithRank(string rank)
{
return new PaperdollData(Name, Home, Partner, Title, Guild, rank, PlayerID, Class, Gender, Paperdoll, Icon);
}

public IPaperdollData WithPlayerID(short playerID)
{
return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, playerID, Class, Gender, Paperdoll, Icon);
}

public IPaperdollData WithClass(byte @class)
{
return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, @class, Gender, Paperdoll, Icon);
}

public IPaperdollData WithGender(byte gender)
{
return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, Class, gender, Paperdoll, Icon);
}

public IPaperdollData WithPaperdoll(IReadOnlyDictionary<EquipLocation, short> paperdoll)
{
return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, paperdoll, Icon);
}

public IPaperdollData WithIcon(OnlineIcon icon)
{
return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, icon);
}

public override bool Equals(object obj)
{
var other = obj as PaperdollData;
if (other == null)
return false;

return Name == other.Name && Home == other.Home && Partner == other.Partner && Title == other.Title &&
Guild == other.Guild && Rank == other.Rank && PlayerID == other.PlayerID &&
Class == other.Class && Gender == other.Gender && Icon == other.Icon && Paperdoll.SequenceEqual(other.Paperdoll);
}
}

public interface IPaperdollData
{
string Name { get; }
string Home { get; }
string Partner { get; }
string Title { get; }
string Guild { get; }
string Rank { get; }

short PlayerID { get; }
byte Class { get; }
byte Gender { get; }

IReadOnlyDictionary<EquipLocation, short> Paperdoll { get; }

OnlineIcon Icon { get; }

IPaperdollData WithName(string name);

IPaperdollData WithHome(string home);

IPaperdollData WithPartner(string partner);

IPaperdollData WithTitle(string title);

IPaperdollData WithGuild(string guild);

IPaperdollData WithRank(string rank);

IPaperdollData WithPlayerID(short playerID);

IPaperdollData WithClass(byte @class);

IPaperdollData WithGender(byte gender);

IPaperdollData WithPaperdoll(IReadOnlyDictionary<EquipLocation, short> paperdoll);

IPaperdollData WithIcon(OnlineIcon icon);
}
}
29 changes: 6 additions & 23 deletions EOLib/Domain/Character/PaperdollRepository.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,23 @@
using System.Collections.Generic;
using System.Linq;
using AutomaticTypeMapper;
using AutomaticTypeMapper;
using System.Collections.Generic;

namespace EOLib.Domain.Character
{
public interface IPaperdollRepository
{
List<short> MainCharacterPaperdoll { get; set; }

Dictionary<int, List<short>> VisibleCharacterPaperdolls { get; set; }
Dictionary<int, IPaperdollData> VisibleCharacterPaperdolls { get; set; }
}

public interface IPaperdollProvider
{
IReadOnlyList<short> MainCharacterPaperdoll { get; }

IReadOnlyDictionary<int, IReadOnlyList<short>> VisibleCharacterPaperdolls { get; }
IReadOnlyDictionary<int, IPaperdollData> VisibleCharacterPaperdolls { get; }
}

[AutoMappedType(IsSingleton = true)]
public class PaperdollRepository : IPaperdollRepository, IPaperdollProvider
{
public List<short> MainCharacterPaperdoll { get; set; }

public Dictionary<int, List<short>> VisibleCharacterPaperdolls { get; set; }

IReadOnlyList<short> IPaperdollProvider.MainCharacterPaperdoll => MainCharacterPaperdoll;
public Dictionary<int, IPaperdollData> VisibleCharacterPaperdolls { get; set; } = new Dictionary<int, IPaperdollData>();

IReadOnlyDictionary<int, IReadOnlyList<short>> IPaperdollProvider.VisibleCharacterPaperdolls
{
get
{
return VisibleCharacterPaperdolls.ToDictionary(
k => k.Key,
v => (IReadOnlyList<short>)v.Value);
}
}
IReadOnlyDictionary<int, IPaperdollData> IPaperdollProvider.VisibleCharacterPaperdolls => VisibleCharacterPaperdolls;
}
}
25 changes: 0 additions & 25 deletions EOLib/Domain/Extensions/PaperdollRepositoryExtensions.cs

This file was deleted.

1 change: 0 additions & 1 deletion EOLib/Domain/Login/LoginActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public async Task RequestCharacterLogin(ICharacter character)
.WithMapID(data.MapID)
.WithAdminLevel(data.AdminLevel)
.WithStats(data.CharacterStats);
_paperdollRepository.MainCharacterPaperdoll = data.Paperdoll.ToList();

_playerInfoRepository.PlayerID = data.PlayerID;
_playerInfoRepository.IsFirstTimePlayer = data.FirstTimePlayer;
Expand Down
54 changes: 0 additions & 54 deletions EOLib/Net/API/Avatar.cs

This file was deleted.

1 change: 0 additions & 1 deletion EOLib/Net/API/PacketAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public PacketAPI(EOClient client)
_createLockerMembers();
_createMessageMembers();
_createMusicMembers();
_createPaperdollMembers();
_createPartyMembers();
_createNPCMembers();
_createQuestMembers();
Expand Down