-
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.
Add handling for F11 sit and rendering of sit state
Rendering offsets WIP
- Loading branch information
1 parent
d4fde4d
commit c89193d
Showing
9 changed files
with
216 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace EOLib.Domain.Character | ||
{ | ||
public enum SitAction | ||
{ | ||
Sit = 1, | ||
Stand = 2 | ||
} | ||
} |
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,86 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Linq; | ||
|
||
namespace EOLib.PacketHandlers | ||
{ | ||
public abstract class PlayerSitHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly ICharacterRepository _characterRepository; | ||
private readonly ICurrentMapStateRepository _currentMapStateRepository; | ||
|
||
public override PacketAction Action => PacketAction.Player; | ||
|
||
public PlayerSitHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICharacterRepository characterRepository, | ||
ICurrentMapStateRepository currentMapStateRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_characterRepository = characterRepository; | ||
_currentMapStateRepository = currentMapStateRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var playerId = packet.ReadShort(); | ||
var x = packet.ReadChar(); | ||
var y = packet.ReadChar(); | ||
var direction = (EODirection)packet.ReadChar(); | ||
|
||
var sitState = Family == PacketFamily.Sit ? SitState.Floor : SitState.Chair; | ||
|
||
if (packet.ReadChar() != 0) | ||
return false; | ||
|
||
if (playerId == _characterRepository.MainCharacter.ID) | ||
{ | ||
var renderProperties = _characterRepository.MainCharacter.RenderProperties; | ||
var updatedRenderProperties = renderProperties.WithSitState(sitState) | ||
.WithMapX(x) | ||
.WithMapY(y) | ||
.WithDirection(direction); | ||
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithRenderProperties(updatedRenderProperties); | ||
} | ||
else | ||
{ | ||
var oldCharacter = _currentMapStateRepository.Characters.Single(c => c.ID == playerId); | ||
var renderProperties = oldCharacter.RenderProperties.WithSitState(sitState) | ||
.WithMapX(x) | ||
.WithMapY(y) | ||
.WithDirection(direction); | ||
var newCharacter = oldCharacter.WithRenderProperties(renderProperties); | ||
|
||
_currentMapStateRepository.Characters.Remove(oldCharacter); | ||
_currentMapStateRepository.Characters.Add(newCharacter); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
[AutoMappedType] | ||
public class PlayerSitFloorHandler : PlayerSitHandler | ||
{ | ||
public override PacketFamily Family => PacketFamily.Sit; | ||
|
||
public PlayerSitFloorHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICharacterRepository characterRepository, | ||
ICurrentMapStateRepository currentMapStateRepository) | ||
: base(playerInfoProvider, characterRepository, currentMapStateRepository) { } | ||
} | ||
|
||
[AutoMappedType] | ||
public class PlayerSitChairHandler : PlayerSitHandler | ||
{ | ||
public override PacketFamily Family => PacketFamily.Chair; | ||
|
||
public PlayerSitChairHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICharacterRepository characterRepository, | ||
ICurrentMapStateRepository currentMapStateRepository) | ||
: base(playerInfoProvider, characterRepository, currentMapStateRepository) { } | ||
} | ||
} |
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,78 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Linq; | ||
|
||
namespace EOLib.PacketHandlers | ||
{ | ||
public abstract class PlayerStandHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly ICharacterRepository _characterRepository; | ||
private readonly ICurrentMapStateRepository _currentMapStateRepository; | ||
|
||
public override PacketFamily Family => PacketFamily.Sit; | ||
|
||
public PlayerStandHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICharacterRepository characterRepository, | ||
ICurrentMapStateRepository currentMapStateRepository) | ||
: base(playerInfoProvider) | ||
{ | ||
_characterRepository = characterRepository; | ||
_currentMapStateRepository = currentMapStateRepository; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var playerId = packet.ReadShort(); | ||
var x = packet.ReadChar(); | ||
var y = packet.ReadChar(); | ||
|
||
if (playerId == _characterRepository.MainCharacter.ID) | ||
{ | ||
var renderProperties = _characterRepository.MainCharacter.RenderProperties; | ||
var updatedRenderProperties = renderProperties.WithSitState(SitState.Standing) | ||
.WithMapX(x) | ||
.WithMapY(y); | ||
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithRenderProperties(updatedRenderProperties); | ||
} | ||
else | ||
{ | ||
var oldCharacter = _currentMapStateRepository.Characters.Single(c => c.ID == playerId); | ||
var renderProperties = oldCharacter.RenderProperties.WithSitState(SitState.Standing) | ||
.WithMapX(x) | ||
.WithMapY(y); | ||
var newCharacter = oldCharacter.WithRenderProperties(renderProperties); | ||
|
||
_currentMapStateRepository.Characters.Remove(oldCharacter); | ||
_currentMapStateRepository.Characters.Add(newCharacter); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
[AutoMappedType] | ||
public class OtherPlayerStandHandler : PlayerStandHandler | ||
{ | ||
public override PacketAction Action => PacketAction.Remove; | ||
|
||
public OtherPlayerStandHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICharacterRepository characterRepository, | ||
ICurrentMapStateRepository currentMapStateRepository) | ||
: base(playerInfoProvider, characterRepository, currentMapStateRepository) { } | ||
} | ||
|
||
[AutoMappedType] | ||
public class MainPlayerStandHandler : PlayerStandHandler | ||
{ | ||
public override PacketAction Action => PacketAction.Close; | ||
|
||
public MainPlayerStandHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICharacterRepository characterRepository, | ||
ICurrentMapStateRepository currentMapStateRepository) | ||
: base(playerInfoProvider, characterRepository, currentMapStateRepository) { } | ||
} | ||
} |
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
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