-
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 #97 from ethanmoffat/sitting
Implement chair/floor sitting - Add handling for walking to a chair, F11 toggling of sit, and clicking to stand - Update offsets to work for sitting in chairs/floor - Fix crash bug when receiving PM
- Loading branch information
Showing
21 changed files
with
401 additions
and
28 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
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,89 @@ | ||
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) { } | ||
} | ||
|
||
[AutoMappedType] | ||
public class MainPlayerStandFromChairHandler : MainPlayerStandHandler | ||
{ | ||
public override PacketFamily Family => PacketFamily.Chair; | ||
|
||
public MainPlayerStandFromChairHandler(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
Oops, something went wrong.