From 64c814157bacd23fbc61fdcc835aa5fcb9bea036 Mon Sep 17 00:00:00 2001 From: AriAvery <41122212+AriAvery@users.noreply.github.com> Date: Wed, 6 Feb 2019 18:51:51 +0100 Subject: [PATCH] Mostly retial like movement + bnpcs auto attack move delay --- src/common/Common.h | 5 +-- src/world/Actor/BNpc.cpp | 8 ++++- src/world/Network/Handlers/PacketHandlers.cpp | 33 ++++++++++++------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/common/Common.h b/src/common/Common.h index 7332ee86..2cab0b10 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -419,8 +419,9 @@ namespace Sapphire::Common uint8_t { No = 0x00, - Land = 0x02, - Fall = 0x04, + LeaveCollision = 0x01, + EnterCollision = 0x02, + StartFalling = 0x04, }; enum MoveSpeed : diff --git a/src/world/Actor/BNpc.cpp b/src/world/Actor/BNpc.cpp index 17cde8b2..8a1a96a2 100644 --- a/src/world/Actor/BNpc.cpp +++ b/src/world/Actor/BNpc.cpp @@ -36,6 +36,7 @@ #include "Framework.h" #include #include +#include using namespace Sapphire::Common; using namespace Sapphire::Network::Packets; @@ -521,7 +522,12 @@ void Sapphire::Entity::BNpc::update( int64_t currTime ) } if( distance > minActorDistance ) - moveTo( pHatedActor->getPos() ); + { + uint64_t tick = Util::getTimeMs(); + auto pTeriMgr = m_pFw->get< World::Manager::TerritoryMgr >(); + if ( ( tick - m_lastAttack ) > 600 && pTeriMgr->isDefaultTerritory( getCurrentZone()->getTerritoryTypeId() ) ) + moveTo( pHatedActor->getPos() ); + } else { if( face( pHatedActor->getPos() ) ) diff --git a/src/world/Network/Handlers/PacketHandlers.cpp b/src/world/Network/Handlers/PacketHandlers.cpp index 6f801fea..94b59602 100644 --- a/src/world/Network/Handlers/PacketHandlers.cpp +++ b/src/world/Network/Handlers/PacketHandlers.cpp @@ -207,13 +207,12 @@ void Sapphire::Network::GameConnection::updatePositionHandler( FrameworkPtr pFw, auto animationState = updatePositionPacket.data().animationState; auto animationType = updatePositionPacket.data().animationType; auto headRotation = updatePositionPacket.data().headPosition; + uint8_t orgAnimationType = animationType; uint8_t unknownRotation = 0; uint16_t animationSpeed = MoveSpeed::Walk; animationType |= clientAnimationType; - bool shouldSend = true; - if( animationType & MoveType::Strafing ) { if( animationType & MoveType::Walking ) @@ -230,13 +229,25 @@ void Sapphire::Network::GameConnection::updatePositionHandler( FrameworkPtr pFw, } if( animationType & MoveType::Jumping ) { - if( animationState == MoveState::Fall ) + if( animationState == MoveState::LeaveCollision ) + { + if( orgAnimationType & clientAnimationType ) + animationType += 0x10; + else + animationType += 0x04; + } + if( animationState == MoveState::StartFalling ) + { player.m_falling = true; - else - shouldSend = false; + animationType += 0x10; + unknownRotation = 0x7F; + } + if( animationState == MoveState::EnterCollision ) + { + animationType = 2; + player.m_falling = false; + } } - else - player.m_falling = false; if( player.m_falling ) { @@ -244,16 +255,14 @@ void Sapphire::Network::GameConnection::updatePositionHandler( FrameworkPtr pFw, unknownRotation = 0x7F; } + uint64_t currentTime = Util::getTimeMs(); player.m_lastMoveTime = currentTime; player.m_lastMoveflag = animationType; - if( shouldSend ) - { - auto movePacket = std::make_shared< MoveActorPacket >( player, headRotation, animationType, animationState, animationSpeed, unknownRotation ); - player.sendToInRangeSet( movePacket ); - } + auto movePacket = std::make_shared< MoveActorPacket >( player, headRotation, animationType, animationState, animationSpeed, unknownRotation ); + player.sendToInRangeSet( movePacket ); } void