diff --git a/src/common/Common.h b/src/common/Common.h index 7872bb42..467c8112 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -587,7 +587,7 @@ namespace Sapphire::Common WaterCluster = 0x12 }; - enum struct ZoneingType : uint8_t + enum struct ZoningType : uint8_t { None = 1, Teleport = 2, diff --git a/src/scripts/action/common/ActionReturn6.cpp b/src/scripts/action/common/ActionReturn6.cpp index 539ba1a0..06841c94 100644 --- a/src/scripts/action/common/ActionReturn6.cpp +++ b/src/scripts/action/common/ActionReturn6.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include class ActionReturn6 : public Sapphire::ScriptAPI::ActionScript @@ -17,7 +19,9 @@ public: if( !action.getSourceChara()->isPlayer() ) return; - action.getSourceChara()->getAsPlayer()->teleport( action.getSourceChara()->getAsPlayer()->getHomepoint(), 3 ); + auto pPlayer = action.getSourceChara()->getAsPlayer(); + + warpMgr().requestPlayerTeleport( *pPlayer, pPlayer->getHomepoint(), 3 ); } }; diff --git a/src/scripts/action/common/ActionTeleport5.cpp b/src/scripts/action/common/ActionTeleport5.cpp index 1a2fcd77..155c680e 100644 --- a/src/scripts/action/common/ActionTeleport5.cpp +++ b/src/scripts/action/common/ActionTeleport5.cpp @@ -16,26 +16,27 @@ public: void onExecute( Sapphire::World::Action::Action& action ) override { - auto player = action.getSourceChara()->getAsPlayer(); + auto pPlayer = action.getSourceChara()->getAsPlayer(); - if( !player ) + if( !pPlayer ) return; - auto teleportQuery = player->getTeleportQuery(); + auto teleportQuery = pPlayer->getTeleportQuery(); - if( player->getCurrency( Common::CurrencyType::Gil ) < teleportQuery.cost || + if( pPlayer->getCurrency( Common::CurrencyType::Gil ) < teleportQuery.cost || teleportQuery.targetAetheryte == 0 ) { action.interrupt(); return; } - player->removeCurrency( Common::CurrencyType::Gil, teleportQuery.cost ); + pPlayer->removeCurrency( Common::CurrencyType::Gil, teleportQuery.cost ); - player->setZoningType( Common::ZoneingType::Teleport ); - player->teleport( teleportQuery.targetAetheryte ); + pPlayer->setZoningType( Common::ZoningType::Teleport ); - player->clearTeleportQuery(); + warpMgr().requestPlayerTeleport( *pPlayer, teleportQuery.targetAetheryte, 1 ); + + pPlayer->clearTeleportQuery(); } }; diff --git a/src/scripts/common/aethernet/Aetheryte.cpp b/src/scripts/common/aethernet/Aetheryte.cpp index 342944cc..2af4abef 100644 --- a/src/scripts/common/aethernet/Aetheryte.cpp +++ b/src/scripts/common/aethernet/Aetheryte.cpp @@ -35,7 +35,7 @@ public: auto destination = result.getResult( 0 ); if( result.numOfResults == 1 && destination != 0 ) { - player.teleport( destination, 2 ); + warpMgr().requestPlayerTeleport( player, destination, 2 ); } } ); } @@ -73,7 +73,7 @@ public: auto data = result.getResult( 1 ); if( cmd == 4 && data != 0 ) { - player.teleport( data, 2 ); + warpMgr().requestPlayerTeleport( player, data, 2 ); } else if( cmd == 2 ) // register favored destination { diff --git a/src/scripts/quest/ManFst303.cpp b/src/scripts/quest/ManFst303.cpp index 8818e5fb..dd6b8138 100644 --- a/src/scripts/quest/ManFst303.cpp +++ b/src/scripts/quest/ManFst303.cpp @@ -101,8 +101,8 @@ private: void Scene00001Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) { - player.setGc( OrderOfTwinAdder ); - player.setGcRankAt( OrderOfTwinAdder, 1 ); + playerMgr().onSetGc( player, OrderOfTwinAdder ); + playerMgr().onSetGcRank( player, OrderOfTwinAdder, 1 ); Scene00002( quest, player ); } diff --git a/src/scripts/quest/subquest/mordhona/GaiUsc605.cpp b/src/scripts/quest/subquest/mordhona/GaiUsc605.cpp index 243bc6f7..8bd58dbf 100644 --- a/src/scripts/quest/subquest/mordhona/GaiUsc605.cpp +++ b/src/scripts/quest/subquest/mordhona/GaiUsc605.cpp @@ -396,7 +396,7 @@ private: { eventMgr().sendEventNotice( player, getId(), 3, 0 ); quest.setSeq( Seq5 ); - player.setMount( Mount0 ); + playerMgr().onMountUpdate( player, Mount0 ); } ////////////////////////////////////////////////////////////////////// @@ -490,7 +490,7 @@ private: void Scene00017Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) { - player.setMount( Mount0 ); + playerMgr().onMountUpdate( player, Mount0 ); } ////////////////////////////////////////////////////////////////////// @@ -562,7 +562,7 @@ private: void Scene00023Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) { - player.setMount( Mount0 ); + playerMgr().onMountUpdate( player, Mount0 ); } ////////////////////////////////////////////////////////////////////// @@ -611,7 +611,7 @@ private: { eventMgr().sendEventNotice( player, getId(), 6, 0 ); quest.setSeq( Seq8 ); - player.setMount( 0 ); + playerMgr().onMountUpdate( player, 0 ); } } @@ -646,7 +646,7 @@ private: void Scene00030Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) { - player.setMount( Mount0 ); + playerMgr().onMountUpdate( player, Mount0 ); } ////////////////////////////////////////////////////////////////////// diff --git a/src/world/Action/Action.cpp b/src/world/Action/Action.cpp index 5a26c0f6..ca9762b2 100644 --- a/src/world/Action/Action.cpp +++ b/src/world/Action/Action.cpp @@ -320,7 +320,7 @@ void Action::Action::start() if( player ) { - player->setStateFlag( PlayerStateFlag::Casting ); + Service< World::Manager::PlayerMgr >::ref().onSendStateFlags( *player, PlayerStateFlag::Casting ); } } @@ -368,14 +368,14 @@ void Action::Action::interrupt() // things that aren't players don't care about cooldowns and state flags if( m_pSource->isPlayer() ) { - auto player = m_pSource->getAsPlayer(); + auto pPlayer = m_pSource->getAsPlayer(); // todo: reset cooldown for actual player // reset state flag //player->unsetStateFlag( PlayerStateFlag::Occupied1 ); - player->setLastActionTick( 0 ); - player->unsetStateFlag( PlayerStateFlag::Casting ); + pPlayer->setLastActionTick( 0 ); + Service< World::Manager::PlayerMgr >::ref().onUnsetStateFlag( *pPlayer, PlayerStateFlag::Casting ); } if( hasCastTime() ) @@ -424,10 +424,10 @@ void Action::Action::execute() 0x219, m_id, m_id, m_id, m_id ); m_pSource->sendToInRangeSet( control, true );*/ - if( auto player = m_pSource->getAsPlayer() ) + if( auto pPlayer = m_pSource->getAsPlayer(); pPlayer ) { - player->setLastActionTick( 0 ); - player->unsetStateFlag( PlayerStateFlag::Casting ); + pPlayer->setLastActionTick( 0 ); + Service< World::Manager::PlayerMgr >::ref().onUnsetStateFlag( *pPlayer, PlayerStateFlag::Casting ); } } diff --git a/src/world/Action/EffectResult.cpp b/src/world/Action/EffectResult.cpp index d32c92fd..7d69febf 100644 --- a/src/world/Action/EffectResult.cpp +++ b/src/world/Action/EffectResult.cpp @@ -2,6 +2,9 @@ #include +#include +#include + #include "Actor/Chara.h" #include "Actor/Player.h" @@ -133,7 +136,7 @@ void EffectResult::execute() case Common::ActionEffectType::CALC_RESULT_TYPE_MOUNT: { auto pPlayer = m_target->getAsPlayer(); - pPlayer->setMount( m_value ); + Common::Service< World::Manager::PlayerMgr >::ref().onMountUpdate( *pPlayer, m_value ); break; } diff --git a/src/world/Action/EventAction.cpp b/src/world/Action/EventAction.cpp index 7c7e6249..94708b0e 100644 --- a/src/world/Action/EventAction.cpp +++ b/src/world/Action/EventAction.cpp @@ -4,9 +4,12 @@ #include #include +#include +#include -#include "Network/PacketWrappers/ActorControlPacket.h" -#include "Network/PacketWrappers/ActorControlSelfPacket.h" +#include +#include +#include #include "Actor/Player.h" @@ -14,7 +17,6 @@ #include "WorldServer.h" #include "Session.h" #include "Network/GameConnection.h" -#include "Manager/EventMgr.h" #include "EventAction.h" @@ -54,9 +56,11 @@ void Action::EventAction::start() if( m_pSource->isPlayer() ) { + auto pPlayer = m_pSource->getAsPlayer(); + m_pSource->sendToInRangeSet( control, true ); - if( m_pSource->getAsPlayer()->hasStateFlag( PlayerStateFlag::InNpcEvent ) ) - m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::InNpcEvent ); + if( pPlayer->hasStateFlag( PlayerStateFlag::InNpcEvent ) ) + Service< World::Manager::PlayerMgr >::ref().onUnsetStateFlag( *pPlayer, PlayerStateFlag::InNpcEvent ); } else m_pSource->sendToInRangeSet( control ); diff --git a/src/world/Action/MountAction.cpp b/src/world/Action/MountAction.cpp index 757de387..c5276d46 100644 --- a/src/world/Action/MountAction.cpp +++ b/src/world/Action/MountAction.cpp @@ -2,17 +2,19 @@ #include -#include "Actor/Player.h" +#include +#include + +#include #include -#include "Network/PacketWrappers/ActorControlSelfPacket.h" +#include #include #include #include "WorldServer.h" #include "Session.h" -#include "Network/GameConnection.h" using namespace Sapphire; using namespace Sapphire::Network::Packets; @@ -59,20 +61,19 @@ void MountAction::start() m_pSource->sendToInRangeSet( castPacket, true ); - player->setStateFlag( Common::PlayerStateFlag::Casting ); + Common::Service< World::Manager::PlayerMgr >::ref().onSetStateFlag( *player, Common::PlayerStateFlag::Casting ); auto actionStartPkt = makeActorControlSelf( m_pSource->getId(), ActorControlType::ActionStart, 1, getId(), m_recastTimeMs / 10 ); auto& server = Common::Service< World::WorldServer >::ref(); server.queueForPlayer( m_pSource->getAsPlayer()->getCharacterId(), actionStartPkt ); - } void MountAction::execute() { assert( m_pSource ); - m_pSource->getAsPlayer()->unsetStateFlag( Common::PlayerStateFlag::Casting ); + Common::Service< World::Manager::PlayerMgr >::ref().onUnsetStateFlag( *m_pSource->getAsPlayer(), Common::PlayerStateFlag::Casting ); m_effectBuilder->mount( m_pSource, m_mountId ); m_effectBuilder->buildAndSendPackets( { m_pSource } ); } \ No newline at end of file diff --git a/src/world/Actor/Chara.h b/src/world/Actor/Chara.h index a1971390..b2f80dc9 100644 --- a/src/world/Actor/Chara.h +++ b/src/world/Actor/Chara.h @@ -27,8 +27,8 @@ namespace Sapphire::Entity using ActorStatsArray = std::array< uint32_t, STAT_ARRAY_SIZE >; - ActorStatsArray m_baseStats; - ActorStatsArray m_bonusStats; + ActorStatsArray m_baseStats{ 0 }; + ActorStatsArray m_bonusStats{ 0 }; protected: char m_name[34]; diff --git a/src/world/Actor/Player.cpp b/src/world/Actor/Player.cpp index 1ff17bd0..b64d6384 100644 --- a/src/world/Actor/Player.cpp +++ b/src/world/Actor/Player.cpp @@ -70,7 +70,7 @@ Player::Player() : m_lastActionTick( 0 ), m_bInCombat( false ), m_bLoadingComplete( false ), - m_zoningType( Common::ZoneingType::None ), + m_zoningType( Common::ZoningType::None ), m_bAutoattack( false ), m_markedForRemoval( false ), m_mount( 0 ), @@ -317,6 +317,8 @@ void Player::removeOnlineStatus( const std::vector< Common::OnlineStatus >& stat void Player::calculateStats() { + calculateBonusStats(); + uint8_t tribe = getLookAt( Common::CharaLook::Tribe ); uint8_t level = getLevel(); auto job = static_cast< uint8_t >( getClass() ); @@ -403,72 +405,6 @@ void Player::sendStats() Service< World::Manager::PlayerMgr >::ref().onSendStats( *this ); } -void Player::teleport( uint16_t aetheryteId, uint8_t type ) -{ - auto& exdData = Common::Service< Data::ExdData >::ref(); - auto& teriMgr = Common::Service< TerritoryMgr >::ref(); - auto& warpMgr = Common::Service< WarpMgr >::ref(); - - auto aetherData = exdData.getRow< Excel::Aetheryte >( aetheryteId ); - - if( !aetherData ) - return; - - const auto& data = aetherData->data(); - - auto& instanceObjectCache = Common::Service< InstanceObjectCache >::ref(); - auto pop = instanceObjectCache.getPopRangeInfo( data.PopRange[ 0 ] ); - - Common::FFXIVARR_POSITION3 pos{ 0.f, 0.f, 0.f }; - - float rot = 0.f; - - if( pop ) - { - PlayerMgr::sendDebug( *this, "Teleport: popRange {0} found!", data.PopRange[ 0 ] ); - pos = pop->m_pos; - rot = pop->m_rotation; - } - else - { - PlayerMgr::sendDebug( *this, "Teleport: popRange {0} not found in {1}!", data.PopRange[ 0 ], data.TerritoryType ); - } - - auto townPlace = exdData.getRow< Excel::PlaceName >( data.TelepoName ); - auto aetherytePlace = exdData.getRow< Excel::PlaceName >( data.TransferName ); - - PlayerMgr::sendDebug( *this, "Teleport: {0} - {1} ({2})", - townPlace->getString( townPlace->data().Text.SGL ), - aetherytePlace->getString( aetherytePlace->data().Text.SGL ), - data.TerritoryType ); - - // if it is a teleport in the same zone, we want to do warp instead of moveTerri - bool sameTerritory = getTerritoryTypeId() == data.TerritoryType; - - WarpType warpType = WarpType::WARP_TYPE_NORMAL; - // TODO: this should be simplified and a type created in server_common/common.h. - if( type == 1 || type == 2 ) // teleport - { - warpType = WarpType::WARP_TYPE_TELEPO; - setZoningType( Common::ZoneingType::Teleport ); - } - else if( type == 3 ) // return - { - warpType = WarpType::WARP_TYPE_HOME_POINT; - setZoningType( Common::ZoneingType::Return ); - } - - if( sameTerritory ) - warpMgr.requestWarp( *this, warpType, pos, rot ); - else - { - auto pTeri = teriMgr.getZoneByTerritoryTypeId( data.TerritoryType ); - if( !pTeri ) - return; - warpMgr.requestMoveTerritory( *this, warpType, pTeri->getGuId(), pos, rot ); - } -} - void Player::forceZoneing( uint32_t zoneId ) { auto& teriMgr = Common::Service< TerritoryMgr >::ref(); @@ -670,8 +606,6 @@ void Player::learnSong( uint8_t songId, uint32_t itemId ) Util::valueToFlagByteIndexValue( songId, value, index ); m_orchestrion[ index ] |= value; - - Service< World::Manager::PlayerMgr >::ref().onUnlockOrchestrion( *this, songId, itemId ); } bool Player::hasReward( Common::UnlockEntry unlockId ) const @@ -735,6 +669,7 @@ void Player::levelUp() void Player::sendStatusUpdate() { + // todo: overrides are funky Service< World::Manager::PlayerMgr >::ref().onPlayerHpMpTpChanged( *this ); } @@ -926,15 +861,11 @@ void Player::setVoiceId( uint8_t voiceId ) void Player::setGc( uint8_t gc ) { m_gc = gc; - - Service< World::Manager::PlayerMgr >::ref().onGcUpdate( *this ); } void Player::setGcRankAt( uint8_t index, uint8_t rank ) { m_gcRank[ index ] = rank; - - Service< World::Manager::PlayerMgr >::ref().onGcUpdate( *this ); } const Player::StateFlags& Player::getStateFlags() const @@ -955,7 +886,6 @@ bool Player::hasStateFlag( Common::PlayerStateFlag flag ) const void Player::setStateFlag( Common::PlayerStateFlag flag ) { - auto prevOnlineStatus = getOnlineStatus(); auto iFlag = static_cast< int32_t >( flag ); uint16_t index; @@ -963,22 +893,6 @@ void Player::setStateFlag( Common::PlayerStateFlag flag ) Util::valueToFlagByteIndexValue( iFlag, value, index ); m_stateFlags[ index ] |= value; - - auto newOnlineStatus = getOnlineStatus(); - sendStateFlags( prevOnlineStatus != newOnlineStatus ); -} - -void Player::setStateFlags( std::vector< Common::PlayerStateFlag > flags ) -{ - for( const auto& flag : flags ) - { - setStateFlag( flag ); - } -} - -void Player::sendStateFlags( bool updateInRange ) -{ - Service< World::Manager::PlayerMgr >::ref().onSendStateFlags( *this, updateInRange ); } void Player::unsetStateFlag( Common::PlayerStateFlag flag ) @@ -986,8 +900,6 @@ void Player::unsetStateFlag( Common::PlayerStateFlag flag ) if( !hasStateFlag( flag ) ) return; - auto prevOnlineStatus = getOnlineStatus(); - auto iFlag = static_cast< int32_t >( flag ); uint16_t index; @@ -995,60 +907,21 @@ void Player::unsetStateFlag( Common::PlayerStateFlag flag ) Util::valueToFlagByteIndexValue( iFlag, value, index ); m_stateFlags[ index ] ^= value; - - auto newOnlineStatus = getOnlineStatus(); - sendStateFlags( prevOnlineStatus != newOnlineStatus ); } void Player::update( uint64_t tickCount ) { - if( m_hp <= 0 && m_status != ActorStatus::Dead ) - { - die(); - Service< World::Manager::PlayerMgr >::ref().onDeath( *this ); - } - - if( !isAlive() ) - return; - - m_lastUpdate = tickCount; - - if( !checkAction() ) - { - if( m_targetId && m_currentStance == Common::Stance::Active && isAutoattackOn() ) - { - auto mainWeap = getItemAt( Common::GearSet0, Common::GearSetSlot::MainHand ); - - // @TODO i dislike this, iterating over all in range actors when you already know the id of the actor you need... - for( const auto& actor : m_inRangeActor ) - { - if( actor->getId() == m_targetId && actor->getAsChara()->isAlive() && mainWeap ) - { - auto chara = actor->getAsChara(); - - // default autoattack range - float range = 3.f + chara->getRadius() + getRadius() * 0.5f; - - // default autoattack range for ranged classes - if( getClass() == ClassJob::Machinist || getClass() == ClassJob::Bard || getClass() == ClassJob::Archer ) - range = 25.f + chara->getRadius() + getRadius() * 0.5f; - - if( Util::distance( getPos(), actor->getPos() ) <= range ) - { - if( ( tickCount - m_lastAttack ) > mainWeap->getDelay() ) - { - m_lastAttack = tickCount; - autoAttack( actor->getAsChara() ); - } - } - } - } - } - } + // todo: better way to handle this override chara update + Service< World::Manager::PlayerMgr >::ref().onUpdate( *this, tickCount ); Chara::update( tickCount ); } +uint64_t Player::getLastAttack() const +{ + return m_lastAttack; +} + void Player::setLastAttack( uint64_t tickCount ) { m_lastAttack = tickCount; @@ -1112,6 +985,11 @@ const Player::OrchestrionList& Player::getOrchestrionBitmask() const return m_orchestrion; } +void Player::setOrchestrionBitmask( const Player::OrchestrionList& orchestrion ) +{ + m_orchestrion = orchestrion; +} + void Player::unlockMount( uint32_t mountId ) { auto& exdData = Common::Service< Data::ExdData >::ref(); @@ -1189,12 +1067,12 @@ void Player::setLoadingComplete( bool bComplete ) m_bLoadingComplete = bComplete; } -ZoneingType Player::getZoningType() const +ZoningType Player::getZoningType() const { return m_zoningType; } -void Player::setZoningType( Common::ZoneingType zoneingType ) +void Player::setZoningType( Common::ZoningType zoneingType ) { m_zoningType = zoneingType; } @@ -1373,21 +1251,11 @@ uint8_t Player::getEquipDisplayFlags() const void Player::setMount( uint32_t mountId ) { m_mount = mountId; - - Service< World::Manager::PlayerMgr >::ref().onMountUpdate( *this, m_mount ); } void Player::setCompanion( uint8_t id ) { - auto& exdData = Common::Service< Data::ExdData >::ref(); - - auto companion = exdData.getRow< Excel::Companion >( id ); - if( !id ) - return; - m_companionId = id; - - Service< World::Manager::PlayerMgr >::ref().onCompanionUpdate( *this, m_companionId ); } uint8_t Player::getCurrentCompanion() const @@ -1617,7 +1485,8 @@ void Player::dyeItemFromDyeingInfo() uint32_t dyeBagContainer = m_dyeingInfo.dyeBagContainer; uint32_t dyeBagSlot = m_dyeingInfo.dyeBagSlot; - sendStateFlags(); // Retail sends all 0s to unlock player after a dye? Possibly not setting a flag when the action is started in the backend..? + Service< World::Manager::PlayerMgr >::ref().onSendStateFlags( *this, true ); // Retail sends all 0s to unlock player after a dye? Possibly not setting a flag when the action is started in the backend..? + auto itemToDye = getItemAt( itemToDyeContainer, itemToDyeSlot ); auto dyeToUse = getItemAt( dyeBagContainer, dyeBagSlot ); @@ -1936,7 +1805,7 @@ void Player::setFalling( bool state, const Common::FFXIVARR_POSITION3& pos, bool // if we've hit the breakpoint in fall damage (min: 10y) if( fallHeight >= 10.f ) { - // calculate how much damage to deal out (max. 20y : 100%) + // calculate how much damage to deal out (max. 30y : 100%) float deltaMax = std::min( fallHeight, 30.f ); // get hp percentage starting from 0.1, increasing to 100% at max height diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index 2d45ba86..41f0a5d4 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -83,6 +83,10 @@ namespace Sapphire::Entity /*! Event called on every session iteration */ void update( uint64_t tickCount ) override; + /*! get last attack tick for player */ + uint64_t getLastAttack() const; + + /*! set last attack tick for player */ void setLastAttack( uint64_t tickCount ); // Quest @@ -343,9 +347,6 @@ namespace Sapphire::Entity uint64_t getFullOnlineStatusMask() const; - /*! perform a teleport of a specified type ( teleport,return,aethernet ) */ - void teleport( uint16_t aetheryteId, uint8_t type = 1 ); - /*! query teleport of a specified type */ void teleportQuery( uint16_t aetheryteId ); @@ -418,7 +419,7 @@ namespace Sapphire::Entity /*! check if aetheryte is already registered */ bool isAetheryteRegistered( uint8_t aetheryteId ) const; - /*! return a const pointer to the aetheryte unlock bitmask array */ + /*! return aetheryte mask */ uint8_t getAetheryteMaskAt( uint8_t index ) const; /*! return a pointer to the aetheryte unlock bitmask array */ @@ -433,13 +434,13 @@ namespace Sapphire::Entity /*! discover subarea subid fo map map_id, also send udpate packet */ void discover( int16_t map_id, int16_t sub_id ); - /*! return a pointer to the discovery bitmask array */ + /*! return a reference to the discovery bitmask array */ Discovery& getDiscoveryBitmask(); /*! helper/debug function to reset all discovered areas */ void resetDiscovery(); - /*! get a pointer to the howto bitmask array */ + /*! get a reference to the howto bitmask array */ HowToList& getHowToArray(); /*! update bitmask for how-to's seen */ @@ -454,22 +455,25 @@ namespace Sapphire::Entity /*! check if an action is already unlocked in the bitmask. */ bool hasReward( Common::UnlockEntry unlockId ) const; - /*! return a const pointer to the unlock bitmask array */ + /*! return a const reference to the unlock bitmask array */ const UnlockList& getUnlockBitmask() const; - /*! return a const pointer to the orchestrion bitmask array */ + /*! return a const reference to the orchestrion bitmask array */ const OrchestrionList& getOrchestrionBitmask() const; + /*! set orchestrion bitmask array */ + void setOrchestrionBitmask( const OrchestrionList& orchestrion ); + /*! unlock a mount */ void unlockMount( uint32_t mountId ); /*! unlock a companion */ void unlockCompanion( uint32_t companionId ); - /*! return a const pointer to the minion guide bitmask array */ + /*! return a reference to the minion guide bitmask array */ MinionList& getMinionGuideBitmask(); - /*! return a const pointer to the setMount guide bitmask array */ + /*! return a reference to the setMount guide bitmask array */ MountList& getMountGuideBitmask(); bool checkAction() override; @@ -567,9 +571,6 @@ namespace Sapphire::Entity /*! send current models ( equipment ) */ void sendModel(); - /*! send active state flags */ - void sendStateFlags( bool updateInRange = true ); - /*! send status update */ void sendStatusUpdate() override; @@ -582,9 +583,9 @@ namespace Sapphire::Entity /*! set the loading complete bool */ void setLoadingComplete( bool bComplete ); - Common::ZoneingType getZoningType() const; + Common::ZoningType getZoningType() const; - void setZoningType( Common::ZoneingType zoneingType ); + void setZoningType( Common::ZoningType zoneingType ); void setSearchInfo( uint8_t selectRegion, uint8_t selectClass, const char* searchMessage ); @@ -742,6 +743,10 @@ namespace Sapphire::Entity /*! calculate and return player ilvl based off equipped gear */ uint16_t calculateEquippedGearItemLevel(); + + /*! calculate bonus stats from gear */ + void calculateBonusStats(); + ItemPtr getEquippedWeapon(); /*! return the current amount of currency of type */ @@ -921,7 +926,7 @@ namespace Sapphire::Entity bool m_bIsConnected; - Common::ZoneingType m_zoningType; + Common::ZoningType m_zoningType; bool m_bNewAdventurer{}; uint64_t m_onlineStatus; diff --git a/src/world/Actor/PlayerInventory.cpp b/src/world/Actor/PlayerInventory.cpp index acff88c5..a48515d8 100644 --- a/src/world/Actor/PlayerInventory.cpp +++ b/src/world/Actor/PlayerInventory.cpp @@ -224,16 +224,6 @@ void Sapphire::Entity::Player::equipItem( Common::GearSetSlot equipSlotId, Item& updateModels( equipSlotId, item ); - auto baseParams = item.getBaseParams(); - for( auto i = 0; i < 6; ++i ) - { - if( baseParams[ i ].baseParam != static_cast< uint8_t >( Common::BaseParam::None ) ) - m_bonusStats[ baseParams[ i ].baseParam ] += baseParams[ i ].value; - } - - m_bonusStats[ static_cast< uint8_t >( Common::BaseParam::Defense ) ] += item.getDefense(); - m_bonusStats[ static_cast< uint8_t >( Common::BaseParam::MagicDefense ) ] += item.getDefenseMag(); - calculateStats(); if( sendUpdate ) { @@ -254,16 +244,6 @@ void Sapphire::Entity::Player::unequipItem( Common::GearSetSlot equipSlotId, Ite if ( equipSlotId == SoulCrystal ) unequipSoulCrystal(); - auto baseParams = item.getBaseParams(); - for( auto i = 0; i < 6; ++i ) - { - if( baseParams[ i ].baseParam != static_cast< uint8_t >( Common::BaseParam::None ) ) - m_bonusStats[ baseParams[ i ].baseParam ] -= baseParams[ i ].value; - } - - m_bonusStats[ static_cast< uint8_t >( Common::BaseParam::Defense ) ] -= item.getDefense(); - m_bonusStats[ static_cast< uint8_t >( Common::BaseParam::MagicDefense ) ] -= item.getDefenseMag(); - calculateStats(); if( sendUpdate ) @@ -999,6 +979,38 @@ uint16_t Sapphire::Entity::Player::calculateEquippedGearItemLevel() return ilvl; } +void Sapphire::Entity::Player::calculateBonusStats() +{ + m_bonusStats.fill( 0 ); + + auto gearSetMap = m_storageMap[ GearSet0 ]->getItemMap(); + + auto it = gearSetMap.begin(); + + while( it != gearSetMap.end() ) + { + auto pItem = it->second; + + if( pItem && pItem->getCategory() != Common::ItemUICategory::SoulCrystal ) + { + auto baseParams = pItem->getBaseParams(); + for( auto i = 0; i < 6; ++i ) + { + auto itemBaseParam = baseParams[ i ].baseParam; + auto itemBaseVal = baseParams[ i ].value; + if( itemBaseParam != static_cast< uint8_t >( Common::BaseParam::None ) ) + m_bonusStats[ itemBaseParam ] += itemBaseVal; + } + + m_bonusStats[ static_cast< uint8_t >( Common::BaseParam::Defense ) ] += pItem->getDefense(); + m_bonusStats[ static_cast< uint8_t >( Common::BaseParam::MagicDefense ) ] += pItem->getDefenseMag(); + } + + it++; + } +} + + Sapphire::ItemPtr Sapphire::Entity::Player::getEquippedWeapon() { return m_storageMap[ GearSet0 ]->getItem( GearSetSlot::MainHand ); diff --git a/src/world/Manager/AchievementMgr.h b/src/world/Manager/AchievementMgr.h index c928d6c0..c32c771a 100644 --- a/src/world/Manager/AchievementMgr.h +++ b/src/world/Manager/AchievementMgr.h @@ -132,7 +132,7 @@ namespace Sapphire::World::Manager if( !pAchv ) continue; - auto achvExdData = pAchv->data(); + auto& achvExdData = pAchv->data(); if( achvExdData.ConditionArg[ 1 ] <= static_cast< int32_t >( achvData.progressData[ dataKey.u32 ] ) ) unlockAchievement( player, achvId ); diff --git a/src/world/Manager/DebugCommandMgr.cpp b/src/world/Manager/DebugCommandMgr.cpp index d6a30186..782c5ee4 100644 --- a/src/world/Manager/DebugCommandMgr.cpp +++ b/src/world/Manager/DebugCommandMgr.cpp @@ -217,7 +217,7 @@ void DebugCommandMgr::set( char* data, Entity::Player& player, std::shared_ptr< int32_t aetheryteId; sscanf( params.c_str(), "%i", &aetheryteId ); - player.teleport( static_cast< uint16_t >( aetheryteId ) ); + Common::Service< WarpMgr >::ref().requestPlayerTeleport( player, static_cast< uint16_t >( aetheryteId ), 1 ); } else if( ( subCommand == "discovery" ) && ( !params.empty() ) ) { @@ -269,8 +269,8 @@ void DebugCommandMgr::set( char* data, Entity::Player& player, std::shared_ptr< int32_t id; sscanf( params.c_str(), "%d", &id ); - player.setMount( 0 ); - player.setMount( static_cast< uint32_t >( id )); + Common::Service< World::Manager::PlayerMgr >::ref().onMountUpdate( player, 0 ); + Common::Service< World::Manager::PlayerMgr >::ref().onMountUpdate( player, id ); } else if( subCommand == "weatheroverride" || subCommand == "wo" ) { diff --git a/src/world/Manager/EventMgr.cpp b/src/world/Manager/EventMgr.cpp index 5f52d7f6..1241e74b 100644 --- a/src/world/Manager/EventMgr.cpp +++ b/src/world/Manager/EventMgr.cpp @@ -555,12 +555,12 @@ void EventMgr::eventFinish( Sapphire::Entity::Player& player, uint32_t eventId, } if( player.hasStateFlag( Common::PlayerStateFlag::WatchingCutscene ) ) - player.unsetStateFlag( Common::PlayerStateFlag::WatchingCutscene ); + Common::Service< World::Manager::PlayerMgr >::ref().onUnsetStateFlag( player, Common::PlayerStateFlag::WatchingCutscene ); player.removeEvent( pEvent->getId() ); if( freePlayer == 1 ) - player.unsetStateFlag( Common::PlayerStateFlag::InNpcEvent ); + Common::Service< World::Manager::PlayerMgr >::ref().onUnsetStateFlag( player, Common::PlayerStateFlag::InNpcEvent ); } void EventMgr::eventStart( Entity::Player& player, uint64_t actorId, uint32_t eventId, Event::EventHandler::EventType eventType, uint8_t eventParam1, @@ -571,7 +571,7 @@ void EventMgr::eventStart( Entity::Player& player, uint64_t actorId, uint32_t ev newEvent->setEventFinishCallback( std::move( callback ) ); player.addEvent( newEvent ); - player.setStateFlag( Common::PlayerStateFlag::InNpcEvent ); + Common::Service< World::Manager::PlayerMgr >::ref().onSetStateFlag( player, Common::PlayerStateFlag::InNpcEvent ); server.queueForPlayer( player.getCharacterId(), std::make_shared< EventStartPacket >( player.getId(), actorId, eventId, eventType, eventParam1, eventParam2 ) ); @@ -836,7 +836,7 @@ Sapphire::Event::EventHandlerPtr EventMgr::bootstrapSceneEvent( Entity::Player& } if( flags & CONDITION_CUTSCENE ) - player.setStateFlag( Common::PlayerStateFlag::WatchingCutscene ); + Common::Service< World::Manager::PlayerMgr >::ref().onSetStateFlag( player, Common::PlayerStateFlag::WatchingCutscene ); return pEvent; } diff --git a/src/world/Manager/PlayerMgr.cpp b/src/world/Manager/PlayerMgr.cpp index 060ce7ed..6c020626 100644 --- a/src/world/Manager/PlayerMgr.cpp +++ b/src/world/Manager/PlayerMgr.cpp @@ -13,8 +13,8 @@ #include #include -#include "Script/ScriptMgr.h" -#include "WorldServer.h" +#include