-
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.
- Loading branch information
1 parent
4568927
commit 714caf6
Showing
4 changed files
with
53 additions
and
79 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 |
---|---|---|
@@ -1,97 +1,77 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Interact; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Collections.Generic; | ||
using EOLib.Domain.Interact.Barber; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Domain.Notifiers; | ||
using EOLib.Net.Handlers; | ||
using Moffat.EndlessOnline.SDK.Protocol.Net; | ||
using Moffat.EndlessOnline.SDK.Protocol.Net.Server; | ||
|
||
namespace EOLib.PacketHandlers.Barber | ||
{ | ||
[AutoMappedType] | ||
public class BarberAgreeHandler : InGameOnlyPacketHandler | ||
public class BarberAgreeHandler : InGameOnlyPacketHandler<BarberAgreeServerPacket> | ||
{ | ||
private readonly IBarberDataRepository _barberDataRepository; | ||
private readonly IEnumerable<INPCInteractionNotifier> _npcInteractionNotifiers; | ||
private readonly ICharacterRepository _characterRepository; | ||
private readonly ICurrentMapStateRepository _currentMapStateRepository; | ||
private readonly ICharacterInventoryRepository _characterInventoryRepository; | ||
|
||
public override PacketFamily Family => PacketFamily.Barber; | ||
|
||
public override PacketAction Action => PacketAction.Agree; | ||
|
||
public BarberAgreeHandler( | ||
IPlayerInfoProvider playerInfoProvider, | ||
IEnumerable<INPCInteractionNotifier> npcInteractionNotifiers, | ||
IBarberDataRepository barberDataRepository, | ||
ICharacterRepository characterRepository, | ||
ICurrentMapStateRepository currentMapStateRepository, | ||
ICharacterInventoryRepository characterInventoryRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_npcInteractionNotifiers = npcInteractionNotifiers; | ||
_barberDataRepository = barberDataRepository; | ||
_characterRepository = characterRepository; | ||
_currentMapStateRepository = currentMapStateRepository; | ||
_characterInventoryRepository = characterInventoryRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
public override bool HandlePacket(BarberAgreeServerPacket packet) | ||
{ | ||
var amount = packet.ReadInt(); | ||
var gold = new InventoryItem(1, amount); | ||
var playerID = packet.ReadShort(); | ||
|
||
_characterInventoryRepository.ItemInventory.RemoveWhere(x => x.ItemID == 1); | ||
_characterInventoryRepository.ItemInventory.Add(gold); | ||
|
||
var currentCharacter = _characterRepository.MainCharacter.ID == playerID | ||
? _characterRepository.MainCharacter | ||
: null; | ||
_characterInventoryRepository.ItemInventory.Add(new InventoryItem(1, packet.GoldAmount)); | ||
|
||
if (currentCharacter == null) | ||
if (_characterRepository.MainCharacter.ID == packet.Change.PlayerId) | ||
{ | ||
return false; | ||
var currentCharacter = _characterRepository.MainCharacter; | ||
_characterRepository.MainCharacter = currentCharacter.WithRenderProperties(UpdateRenderProperties(currentCharacter, packet)); | ||
} | ||
|
||
var currentRenderProps = currentCharacter.RenderProperties; | ||
var slot = (AvatarSlot)packet.ReadChar(); | ||
|
||
switch (slot) | ||
else if (_currentMapStateRepository.Characters.ContainsKey(packet.Change.PlayerId)) | ||
{ | ||
case AvatarSlot.Hair: | ||
if (packet.ReadChar() != 0) | ||
throw new MalformedPacketException("Missing expected 0 byte in updating hair packet", packet); | ||
|
||
currentRenderProps = currentRenderProps | ||
.WithHairStyle(packet.ReadChar()) | ||
.WithHairColor(packet.ReadChar()); | ||
break; | ||
|
||
case AvatarSlot.HairColor: | ||
if (packet.ReadChar() != 0) | ||
throw new MalformedPacketException("Missing expected 0 byte in updating hair color packet", packet); | ||
|
||
currentRenderProps = currentRenderProps | ||
.WithHairColor(packet.ReadChar()); | ||
break; | ||
var currentCharacter = _currentMapStateRepository.Characters[packet.Change.PlayerId]; | ||
_currentMapStateRepository.Characters.Update(currentCharacter, currentCharacter.WithRenderProperties(UpdateRenderProperties(currentCharacter, packet))); | ||
} | ||
|
||
var updatedCharacter = currentCharacter.WithRenderProperties(currentRenderProps); | ||
return true; | ||
} | ||
|
||
if (_characterRepository.MainCharacter.ID == playerID) | ||
{ | ||
_characterRepository.MainCharacter = updatedCharacter; | ||
} | ||
else | ||
private CharacterRenderProperties UpdateRenderProperties(Character currentCharacter, BarberAgreeServerPacket packet) | ||
{ | ||
var currentRenderProps = currentCharacter.RenderProperties; | ||
switch (packet.Change.ChangeType) | ||
{ | ||
_currentMapStateRepository.Characters.Update(currentCharacter, updatedCharacter); | ||
case AvatarChangeType.Hair: | ||
{ | ||
var data = (AvatarChange.ChangeTypeDataHair)packet.Change.ChangeTypeData; | ||
currentRenderProps = currentRenderProps | ||
.WithHairStyle(data.HairStyle) | ||
.WithHairColor(data.HairColor); | ||
} | ||
break; | ||
case AvatarChangeType.HairColor: | ||
{ | ||
var data = (AvatarChange.ChangeTypeDataHairColor)packet.Change.ChangeTypeData; | ||
currentRenderProps = currentRenderProps | ||
.WithHairColor(data.HairColor); | ||
} | ||
break; | ||
} | ||
|
||
return true; | ||
return currentRenderProps; | ||
} | ||
} | ||
} |
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