From 92594cdc1ce5acf529a7bb3c405f12ea2eec8812 Mon Sep 17 00:00:00 2001 From: Ay'yaruq Dotharl Date: Thu, 7 Dec 2017 17:39:06 +1100 Subject: [PATCH 1/2] Add clang-format config --- .clang-format | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..295a0333 --- /dev/null +++ b/.clang-format @@ -0,0 +1,42 @@ +--- +Language: Cpp +BasedOnStyle: LLVM +AccessModifierOffset: -3 +AllowShortFunctionsOnASingleLine: InlineOnly +AlwaysBreakTemplateDeclarations: true +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: false + AfterStruct: true + AfterUnion: true + AfterExternBlock: false + BeforeCatch: true + BeforeElse: true + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: true +BreakBeforeTernaryOperators: false +BreakConstructorInitializers: AfterColon +BreakStringLiterals: false +ColumnLimit: 120 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +Cpp11BracedListStyle: false +FixNamespaceComments: true +IndentWidth: 3 +KeepEmptyLinesAtTheStartOfBlocks: true +NamespaceIndentation: Inner +PointerAlignment: Left +SortUsingDeclarations: false +SpaceAfterTemplateKeyword: false +SpaceBeforeParens: Never +SpacesInAngles: true +SpacesInParentheses: true +Standard: Cpp11 +UseTab: Never From 72401d5e5e56dc32506c336908abe78215784be4 Mon Sep 17 00:00:00 2001 From: Ay'yaruq Dotharl Date: Mon, 11 Dec 2017 16:55:05 +1100 Subject: [PATCH 2/2] Apply clang-format to zone server --- src/servers/Server_Zone/Action/Action.cpp | 2 - src/servers/Server_Zone/Action/Action.h | 20 +- src/servers/Server_Zone/Action/ActionCast.cpp | 16 +- src/servers/Server_Zone/Action/ActionCast.h | 10 +- .../Server_Zone/Action/ActionCollision.cpp | 40 +- .../Server_Zone/Action/ActionCollision.h | 18 +- .../Server_Zone/Action/ActionMount.cpp | 19 +- src/servers/Server_Zone/Action/ActionMount.h | 10 +- .../Server_Zone/Action/ActionTeleport.cpp | 26 +- .../Server_Zone/Action/ActionTeleport.h | 9 +- .../Server_Zone/Action/EventAction.cpp | 17 +- src/servers/Server_Zone/Action/EventAction.h | 15 +- .../Server_Zone/Action/EventItemAction.cpp | 14 +- .../Server_Zone/Action/EventItemAction.h | 15 +- src/servers/Server_Zone/Actor/Actor.cpp | 129 +- src/servers/Server_Zone/Actor/Actor.h | 657 +++++---- src/servers/Server_Zone/Actor/BattleNpc.cpp | 131 +- src/servers/Server_Zone/Actor/BattleNpc.h | 146 +- .../Server_Zone/Actor/BattleNpcTemplate.cpp | 17 +- .../Server_Zone/Actor/BattleNpcTemplate.h | 9 +- src/servers/Server_Zone/Actor/Player.cpp | 253 ++-- src/servers/Server_Zone/Actor/Player.h | 1226 ++++++++--------- src/servers/Server_Zone/Actor/PlayerEvent.cpp | 87 +- .../Server_Zone/Actor/PlayerInventory.cpp | 35 +- src/servers/Server_Zone/Actor/PlayerQuest.cpp | 49 +- src/servers/Server_Zone/Actor/PlayerSql.cpp | 73 +- .../Server_Zone/ContentFinder/ContentFinder.h | 1 - .../Server_Zone/DebugCommand/DebugCommand.h | 67 +- .../DebugCommand/DebugCommandHandler.cpp | 160 +-- .../DebugCommand/DebugCommandHandler.h | 24 +- src/servers/Server_Zone/Event/Event.cpp | 12 +- src/servers/Server_Zone/Event/Event.h | 134 +- src/servers/Server_Zone/Event/EventHelper.h | 10 +- src/servers/Server_Zone/Forwards.h | 124 +- .../Server_Zone/Inventory/Inventory.cpp | 194 ++- src/servers/Server_Zone/Inventory/Inventory.h | 14 +- src/servers/Server_Zone/Inventory/Item.cpp | 26 +- src/servers/Server_Zone/Inventory/Item.h | 35 +- .../Server_Zone/Inventory/ItemContainer.cpp | 18 +- .../Server_Zone/Inventory/ItemContainer.h | 47 +- .../Server_Zone/Linkshell/Linkshell.cpp | 28 +- src/servers/Server_Zone/Linkshell/Linkshell.h | 17 +- .../Server_Zone/Linkshell/LinkshellMgr.cpp | 11 +- .../Server_Zone/Linkshell/LinkshellMgr.h | 7 +- src/servers/Server_Zone/Math/CalcBattle.cpp | 10 +- src/servers/Server_Zone/Math/CalcBattle.h | 9 +- src/servers/Server_Zone/Math/CalcStats.cpp | 38 +- src/servers/Server_Zone/Math/CalcStats.h | 9 +- .../Server_Zone/Network/GameConnection.cpp | 185 ++- .../Server_Zone/Network/GameConnection.h | 157 +-- .../Network/Handlers/ActionHandler.cpp | 381 ++--- .../Network/Handlers/CFHandlers.cpp | 40 +- .../Network/Handlers/EventHandlers.cpp | 32 +- .../Network/Handlers/GMCommandHandlers.cpp | 140 +- .../Network/Handlers/InventoryHandler.cpp | 78 +- .../Network/Handlers/PacketHandlers.cpp | 153 +- .../Network/Handlers/SkillHandler.cpp | 115 +- .../PacketWrappers/ActorControlPacket142.h | 66 +- .../PacketWrappers/ActorControlPacket143.h | 72 +- .../PacketWrappers/ActorControlPacket144.h | 69 +- .../Network/PacketWrappers/ActorSpawnPacket.h | 143 +- .../Network/PacketWrappers/ChatPacket.h | 54 +- .../PacketWrappers/EventFinishPacket.h | 58 +- .../Network/PacketWrappers/EventPlayPacket.h | 75 +- .../Network/PacketWrappers/EventStartPacket.h | 67 +- .../Network/PacketWrappers/InitUIPacket.h | 133 +- .../Network/PacketWrappers/ModelEquipPacket.h | 61 +- .../Network/PacketWrappers/MoveActorPacket.h | 69 +- .../Network/PacketWrappers/PingPacket.h | 47 +- .../PacketWrappers/PlayerSpawnPacket.h | 231 ++-- .../PacketWrappers/PlayerStateFlagsPacket.h | 76 +- .../PacketWrappers/QuestMessagePacket.h | 59 +- .../PacketWrappers/ServerNoticePacket.h | 46 +- .../PacketWrappers/UpdateHpMpTpPacket.h | 55 +- .../Server_Zone/Script/ScriptManager.cpp | 163 ++- .../Server_Zone/Script/ScriptManager.h | 86 +- .../Server_Zone/Script/ScriptManagerInit.cpp | 45 +- src/servers/Server_Zone/ServerZone.cpp | 59 +- src/servers/Server_Zone/ServerZone.h | 80 +- src/servers/Server_Zone/Session.cpp | 35 +- src/servers/Server_Zone/Session.h | 60 +- .../Server_Zone/StatusEffect/StatusEffect.cpp | 59 +- .../Server_Zone/StatusEffect/StatusEffect.h | 80 +- src/servers/Server_Zone/Zone/Cell.cpp | 292 ++-- src/servers/Server_Zone/Zone/Cell.h | 135 +- src/servers/Server_Zone/Zone/CellHandler.h | 81 +- src/servers/Server_Zone/Zone/Zone.cpp | 142 +- src/servers/Server_Zone/Zone/Zone.h | 23 +- src/servers/Server_Zone/Zone/ZoneMgr.cpp | 141 +- src/servers/Server_Zone/Zone/ZoneMgr.h | 39 +- src/servers/Server_Zone/Zone/ZonePosition.cpp | 12 +- src/servers/Server_Zone/Zone/ZonePosition.h | 14 +- 92 files changed, 3882 insertions(+), 4364 deletions(-) diff --git a/src/servers/Server_Zone/Action/Action.cpp b/src/servers/Server_Zone/Action/Action.cpp index 1405f45a..d67eee4a 100644 --- a/src/servers/Server_Zone/Action/Action.cpp +++ b/src/servers/Server_Zone/Action/Action.cpp @@ -2,14 +2,12 @@ #include - Core::Action::Action::Action() { } Core::Action::Action::~Action() { - } uint16_t Core::Action::Action::getId() const diff --git a/src/servers/Server_Zone/Action/Action.h b/src/servers/Server_Zone/Action/Action.h index 3c270180..a2044e55 100644 --- a/src/servers/Server_Zone/Action/Action.h +++ b/src/servers/Server_Zone/Action/Action.h @@ -1,12 +1,13 @@ #ifndef _ACTION_H_ #define _ACTION_H_ -#include #include "../Forwards.h" +#include -namespace Core { namespace Action { +namespace Core { +namespace Action { - class Action + class Action { public: @@ -33,28 +34,29 @@ namespace Core { namespace Action { Entity::ActorPtr getActionSource() const; + // clang-format off virtual void onStart() {}; virtual void onFinish() {}; virtual void onInterrupt() {}; + // clang-format on // update action, if returns true, action is done and has to be removed from the actor virtual bool update(); protected: - uint16_t m_id; + uint16_t m_id; Common::HandleActionType m_handleActionType; - uint64_t m_startTime; - uint32_t m_castTime; + uint64_t m_startTime; + uint32_t m_castTime; Entity::ActorPtr m_pSource; Entity::ActorPtr m_pTarget; bool m_bInterrupt; - }; -} -} +} // namespace Action +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Action/ActionCast.cpp b/src/servers/Server_Zone/Action/ActionCast.cpp index 7fc79ea3..1b7798a5 100644 --- a/src/servers/Server_Zone/Action/ActionCast.cpp +++ b/src/servers/Server_Zone/Action/ActionCast.cpp @@ -1,15 +1,15 @@ #include "ActionCast.h" #include -#include -#include #include #include +#include +#include +#include "Actor/Player.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket144.h" -#include "Actor/Player.h" #include "Script/ScriptManager.h" using namespace Core::Common; @@ -59,7 +59,6 @@ void Core::Action::ActionCast::onStart() m_pSource->sendToInRangeSet( castPacket, true ); m_pSource->getAsPlayer()->setStateFlag( PlayerStateFlag::Casting ); m_pSource->getAsPlayer()->sendStateFlags(); - } void Core::Action::ActionCast::onFinish() @@ -89,12 +88,11 @@ void Core::Action::ActionCast::onInterrupt() m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Casting ); m_pSource->getAsPlayer()->sendStateFlags(); - auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, - 0x219, 1, m_id, 0 ); + auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, 1, m_id, 0 ); - // Note: When cast interrupt from taking too much damage, set the last value to 1. This enables the cast interrupt effect. Example: - // auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, 1, m_id, 0 ); + // Note: When cast interrupt from taking too much damage, set the last value to 1. This enables the cast interrupt + // effect. Example: auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, + // 1, m_id, 0 ); m_pSource->sendToInRangeSet( control, true ); - } diff --git a/src/servers/Server_Zone/Action/ActionCast.h b/src/servers/Server_Zone/Action/ActionCast.h index b656b391..f5a8d04d 100644 --- a/src/servers/Server_Zone/Action/ActionCast.h +++ b/src/servers/Server_Zone/Action/ActionCast.h @@ -9,21 +9,19 @@ namespace Action { class ActionCast : public Action { - private: - + private: public: ActionCast(); ~ActionCast(); - + ActionCast( Entity::ActorPtr pActor, Entity::ActorPtr pTarget, uint16_t actionId ); void onStart() override; void onFinish() override; void onInterrupt() override; - }; -} -} +} // namespace Action +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Action/ActionCollision.cpp b/src/servers/Server_Zone/Action/ActionCollision.cpp index 6eb11182..4e8cb8d9 100644 --- a/src/servers/Server_Zone/Action/ActionCollision.cpp +++ b/src/servers/Server_Zone/Action/ActionCollision.cpp @@ -1,13 +1,13 @@ -#include #include +#include #include #include "ActionCollision.h" #include "Actor/Actor.h" #include "Actor/Player.h" -#include #include +#include using namespace Core::Entity; using namespace Core::Common; @@ -51,10 +51,10 @@ bool ActionCollision::isActorApplicable( ActorPtr actorPtr, TargetFilter targetF return ( actorApplicable && actorPtr->isAlive() ); } -std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXIVARR_POSITION3 aoePosition, - std::set< ActorPtr > actorsInRange, - boost::shared_ptr< Core::Data::ActionInfo > actionInfo, - TargetFilter targetFilter ) +std::set< Core::Entity::ActorPtr > +ActionCollision::getActorsHitFromAction( FFXIVARR_POSITION3 aoePosition, std::set< ActorPtr > actorsInRange, + boost::shared_ptr< Core::Data::ActionInfo > actionInfo, + TargetFilter targetFilter ) { std::set< ActorPtr > actorsCollided; @@ -71,11 +71,11 @@ std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXI assert( pActor ); // Don't bother wasting on collision if actor doesn't apply for it - if ( !isActorApplicable( pActor, targetFilter ) ) + if( !isActorApplicable( pActor, targetFilter ) ) continue; // Test our collision from actor with the area generated by the action from the AoE data - if ( radiusCollision( pActor->getPos(), aoePosition, actionInfo->aoe_width ) ) + if( radiusCollision( pActor->getPos(), aoePosition, actionInfo->aoe_width ) ) { // Add it to the actors collided with the area actorsCollided.insert( pActor ); @@ -89,10 +89,10 @@ std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXI { assert( pActor ); - if ( !isActorApplicable( pActor, targetFilter ) ) + if( !isActorApplicable( pActor, targetFilter ) ) continue; - if ( radiusCollision( pActor->getPos(), aoePosition, actionInfo->aoe_range ) ) + if( radiusCollision( pActor->getPos(), aoePosition, actionInfo->aoe_range ) ) actorsCollided.insert( pActor ); } break; @@ -103,10 +103,10 @@ std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXI { assert( pActor ); - if ( !isActorApplicable( pActor, targetFilter ) ) + if( !isActorApplicable( pActor, targetFilter ) ) continue; - if ( boxCollision( pActor->getPos(), aoePosition, actionInfo->aoe_width, actionInfo->aoe_range ) ) + if( boxCollision( pActor->getPos(), aoePosition, actionInfo->aoe_width, actionInfo->aoe_range ) ) { // todo: does this actually work? @@ -124,16 +124,16 @@ std::set< Core::Entity::ActorPtr > ActionCollision::getActorsHitFromAction( FFXI return actorsCollided; } -bool ActionCollision::radiusCollision( FFXIVARR_POSITION3 actorPosition, FFXIVARR_POSITION3 aoePosition, uint16_t radius ) +bool ActionCollision::radiusCollision( FFXIVARR_POSITION3 actorPosition, FFXIVARR_POSITION3 aoePosition, + uint16_t radius ) { - return Core::Math::Util::distance( actorPosition.x, actorPosition.y, actorPosition.z, - aoePosition.x, aoePosition.y, aoePosition.z ) <= radius; + return Core::Math::Util::distance( actorPosition.x, actorPosition.y, actorPosition.z, aoePosition.x, aoePosition.y, + aoePosition.z ) <= radius; } -bool ActionCollision::boxCollision( FFXIVARR_POSITION3 actorPosition, FFXIVARR_POSITION3 aoePosition, uint16_t width, uint16_t height ) +bool ActionCollision::boxCollision( FFXIVARR_POSITION3 actorPosition, FFXIVARR_POSITION3 aoePosition, uint16_t width, + uint16_t height ) { - return actorPosition.x < aoePosition.x + width && - actorPosition.x > aoePosition.x && - actorPosition.y < aoePosition.y + height && - actorPosition.y > aoePosition.y; + return actorPosition.x < aoePosition.x + width && actorPosition.x > aoePosition.x && + actorPosition.y < aoePosition.y + height && actorPosition.y > aoePosition.y; } diff --git a/src/servers/Server_Zone/Action/ActionCollision.h b/src/servers/Server_Zone/Action/ActionCollision.h index db3f7120..0755d79a 100644 --- a/src/servers/Server_Zone/Action/ActionCollision.h +++ b/src/servers/Server_Zone/Action/ActionCollision.h @@ -3,25 +3,24 @@ #include -#include "Actor/Actor.h" #include "Action.h" +#include "Actor/Actor.h" namespace Core { namespace Entity { enum class TargetFilter { - All, // All actors in the AoE are applicable for collision - Players, // Only players - Allies, // Only allies (players, ally NPCs) - Party, // Only party members - Enemies // Only enemies + All, // All actors in the AoE are applicable for collision + Players, // Only players + Allies, // Only allies (players, ally NPCs) + Party, // Only party members + Enemies // Only enemies }; class ActionCollision { public: - static bool isActorApplicable( ActorPtr actorPtr, TargetFilter targetFilter ); static std::set< ActorPtr > getActorsHitFromAction( Common::FFXIVARR_POSITION3 aoePosition, std::set< ActorPtr > actorsInRange, @@ -34,10 +33,9 @@ namespace Entity { static bool boxCollision( Common::FFXIVARR_POSITION3 actorPosition, Common::FFXIVARR_POSITION3 aoePosition, uint16_t width, uint16_t height ); - }; -} -} +} // namespace Entity +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Action/ActionMount.cpp b/src/servers/Server_Zone/Action/ActionMount.cpp index b45b460f..6497a833 100644 --- a/src/servers/Server_Zone/Action/ActionMount.cpp +++ b/src/servers/Server_Zone/Action/ActionMount.cpp @@ -1,15 +1,15 @@ #include "ActionMount.h" #include -#include -#include #include #include +#include +#include +#include "Actor/Player.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket144.h" -#include "Actor/Player.h" #include "Script/ScriptManager.h" using namespace Core::Common; @@ -38,7 +38,6 @@ Core::Action::ActionMount::ActionMount( Entity::ActorPtr pActor, uint16_t mountI Core::Action::ActionMount::~ActionMount() { - } void Core::Action::ActionMount::onStart() @@ -61,7 +60,6 @@ void Core::Action::ActionMount::onStart() m_pSource->sendToInRangeSet( castPacket, true ); m_pSource->getAsPlayer()->setStateFlag( PlayerStateFlag::Casting ); m_pSource->getAsPlayer()->sendStateFlags(); - } void Core::Action::ActionMount::onFinish() @@ -79,7 +77,7 @@ void Core::Action::ActionMount::onFinish() effectPacket.data().targetId = pPlayer->getId(); effectPacket.data().actionAnimationId = m_id; // Affects displaying action name next to number in floating text - effectPacket.data().unknown_62 = 13; + effectPacket.data().unknown_62 = 13; effectPacket.data().actionTextId = 4; effectPacket.data().numEffects = 1; effectPacket.data().rotation = Math::Util::floatToUInt16Rot( pPlayer->getRotation() ); @@ -102,12 +100,11 @@ void Core::Action::ActionMount::onInterrupt() m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Casting ); m_pSource->getAsPlayer()->sendStateFlags(); - auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, - 0x219, 1, m_id, 0 ); + auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, 1, m_id, 0 ); - // Note: When cast interrupt from taking too much damage, set the last value to 1. This enables the cast interrupt effect. Example: - // auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, 1, m_id, 0 ); + // Note: When cast interrupt from taking too much damage, set the last value to 1. This enables the cast interrupt + // effect. Example: auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, + // 1, m_id, 0 ); m_pSource->sendToInRangeSet( control, true ); - } diff --git a/src/servers/Server_Zone/Action/ActionMount.h b/src/servers/Server_Zone/Action/ActionMount.h index ba32817d..0d4435a9 100644 --- a/src/servers/Server_Zone/Action/ActionMount.h +++ b/src/servers/Server_Zone/Action/ActionMount.h @@ -9,21 +9,19 @@ namespace Action { class ActionMount : public Action { - private: - + private: public: ActionMount(); ~ActionMount(); - + ActionMount( Entity::ActorPtr pActor, uint16_t mountId ); void onStart() override; void onFinish() override; void onInterrupt() override; - }; -} -} +} // namespace Action +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Action/ActionTeleport.cpp b/src/servers/Server_Zone/Action/ActionTeleport.cpp index c201b0cc..b1314d36 100644 --- a/src/servers/Server_Zone/Action/ActionTeleport.cpp +++ b/src/servers/Server_Zone/Action/ActionTeleport.cpp @@ -1,12 +1,12 @@ #include "ActionTeleport.h" -#include #include #include +#include +#include "Actor/Player.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" -#include "Actor/Player.h" using namespace Core::Common; using namespace Core::Network; @@ -26,7 +26,7 @@ Core::Action::ActionTeleport::ActionTeleport( Entity::ActorPtr pActor, uint16_t m_startTime = 0; m_id = 5; m_handleActionType = HandleActionType::Teleport; - m_castTime = g_exdData.getActionInfo(5)->cast_time; // TODO: Add security checks. + m_castTime = g_exdData.getActionInfo( 5 )->cast_time; // TODO: Add security checks. m_pSource = pActor; m_bInterrupt = false; m_targetAetheryte = targetZone; @@ -35,7 +35,6 @@ Core::Action::ActionTeleport::ActionTeleport( Entity::ActorPtr pActor, uint16_t Core::Action::ActionTeleport::~ActionTeleport() { - } void Core::Action::ActionTeleport::onStart() @@ -55,7 +54,6 @@ void Core::Action::ActionTeleport::onStart() m_pSource->sendToInRangeSet( castPacket, true ); m_pSource->getAsPlayer()->setStateFlag( PlayerStateFlag::Casting ); m_pSource->getAsPlayer()->sendStateFlags(); - } void Core::Action::ActionTeleport::onFinish() @@ -73,30 +71,30 @@ void Core::Action::ActionTeleport::onFinish() } pPlayer->removeCurrency( Inventory::CurrencyType::Gil, m_cost ); - + pPlayer->unsetStateFlag( PlayerStateFlag::Casting ); pPlayer->sendStateFlags(); // TODO: not sure if this ever gets sent - //auto control = Network::Packets::Server::ActorControlPacket142( m_pSource->getId(), Common::ActorControlType::TeleportDone ); - //m_pSource->sendToInRangeSet( control, false ); + // auto control = Network::Packets::Server::ActorControlPacket142( m_pSource->getId(), + // Common::ActorControlType::TeleportDone + // ); m_pSource->sendToInRangeSet( control, false ); pPlayer->setZoningType( ZoneingType::Teleport ); ZoneChannelPacket< FFXIVIpcEffect > effectPacket( pPlayer->getId() ); effectPacket.data().targetId = pPlayer->getId(); effectPacket.data().actionAnimationId = 5; - //effectPacket.data().unknown_3 = 1; + // effectPacket.data().unknown_3 = 1; effectPacket.data().actionTextId = 5; effectPacket.data().unknown_5 = 1; effectPacket.data().numEffects = 1; - effectPacket.data().rotation = static_cast< uint16_t >( 0x8000 * ( ( pPlayer->getRotation() + 3.1415926 ) ) / 3.1415926 ); + effectPacket.data().rotation = + static_cast< uint16_t >( 0x8000 * ( ( pPlayer->getRotation() + 3.1415926 ) ) / 3.1415926 ); effectPacket.data().effectTarget = pPlayer->getId(); pPlayer->sendToInRangeSet( effectPacket, true ); pPlayer->teleport( m_targetAetheryte ); - - } void Core::Action::ActionTeleport::onInterrupt() @@ -107,8 +105,6 @@ void Core::Action::ActionTeleport::onInterrupt() m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Casting ); m_pSource->getAsPlayer()->sendStateFlags(); - auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, - 0x219, 0x04, m_id, 0 ); + auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, 0x04, m_id, 0 ); m_pSource->sendToInRangeSet( control, true ); - } diff --git a/src/servers/Server_Zone/Action/ActionTeleport.h b/src/servers/Server_Zone/Action/ActionTeleport.h index 480090eb..b67d7443 100644 --- a/src/servers/Server_Zone/Action/ActionTeleport.h +++ b/src/servers/Server_Zone/Action/ActionTeleport.h @@ -9,23 +9,22 @@ namespace Action { class ActionTeleport : public Action { - private: + private: uint16_t m_targetAetheryte; uint16_t m_cost; public: ActionTeleport(); ~ActionTeleport(); - + ActionTeleport( Entity::ActorPtr pActor, uint16_t action, uint16_t cost ); void onStart() override; void onFinish() override; void onInterrupt() override; - }; -} -} +} // namespace Action +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Action/EventAction.cpp b/src/servers/Server_Zone/Action/EventAction.cpp index 5e6a9cf3..47f8f61a 100644 --- a/src/servers/Server_Zone/Action/EventAction.cpp +++ b/src/servers/Server_Zone/Action/EventAction.cpp @@ -1,6 +1,6 @@ -#include -#include #include +#include +#include #include "EventAction.h" #include "Network/PacketWrappers/ActorControlPacket142.h" @@ -37,7 +37,6 @@ Core::Action::EventAction::EventAction( Entity::ActorPtr pActor, uint32_t eventI Core::Action::EventAction::~EventAction() { - } void Core::Action::EventAction::onStart() @@ -47,8 +46,7 @@ void Core::Action::EventAction::onStart() m_startTime = Util::getTimeMs(); - auto control = ActorControlPacket142( m_pSource->getId(), Common::ActorControlType::CastStart, - 1, m_id, 0x4000004E ); + auto control = ActorControlPacket142( m_pSource->getId(), Common::ActorControlType::CastStart, 1, m_id, 0x4000004E ); if( m_pSource->isPlayer() ) { @@ -75,7 +73,7 @@ void Core::Action::EventAction::onFinish() m_onActionFinishClb( *m_pSource->getAsPlayer(), m_eventId, m_additional ); auto control = ActorControlPacket142( m_pSource->getId(), Common::ActorControlType::CastStart, 0, m_id ); - + if( !pEvent->hasPlayedScene() ) m_pSource->getAsPlayer()->eventFinish( m_eventId, 1 ); else @@ -94,7 +92,6 @@ void Core::Action::EventAction::onFinish() { g_log.error( e.what() ); } - } void Core::Action::EventAction::onInterrupt() @@ -105,8 +102,7 @@ void Core::Action::EventAction::onInterrupt() try { - auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, - 0x219, 0x04, m_id ); + auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, 0x04, m_id ); if( m_pSource->isPlayer() ) { @@ -121,18 +117,15 @@ void Core::Action::EventAction::onInterrupt() m_pSource->getAsPlayer()->queuePacket( control1 ); m_pSource->getAsPlayer()->queuePacket( control ); m_pSource->getAsPlayer()->eventFinish( m_eventId, 1 ); - } else m_pSource->sendToInRangeSet( control ); if( m_onActionInterruptClb ) m_onActionInterruptClb( *m_pSource->getAsPlayer(), m_eventId, m_additional ); - } catch( std::exception& e ) { g_log.error( e.what() ); } - } diff --git a/src/servers/Server_Zone/Action/EventAction.h b/src/servers/Server_Zone/Action/EventAction.h index 6f8e5614..0b0dcbbc 100644 --- a/src/servers/Server_Zone/Action/EventAction.h +++ b/src/servers/Server_Zone/Action/EventAction.h @@ -9,15 +9,15 @@ namespace Core { namespace Action { - class EventAction : public Action + class EventAction : public Action { public: EventAction(); ~EventAction(); - - EventAction( Entity::ActorPtr pActor, uint32_t eventId, uint16_t action, - ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional ); + + EventAction( Entity::ActorPtr pActor, uint32_t eventId, uint16_t action, ActionCallback finishRef, + ActionCallback interruptRef, uint64_t additional ); void onStart() override; void onFinish() override; @@ -26,13 +26,12 @@ namespace Action { private: uint32_t m_eventId; uint64_t m_additional; - + ActionCallback m_onActionFinishClb; ActionCallback m_onActionInterruptClb; - }; -} -} +} // namespace Action +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Action/EventItemAction.cpp b/src/servers/Server_Zone/Action/EventItemAction.cpp index 6c85b183..bfb43c7c 100644 --- a/src/servers/Server_Zone/Action/EventItemAction.cpp +++ b/src/servers/Server_Zone/Action/EventItemAction.cpp @@ -1,8 +1,8 @@ #include "EventItemAction.h" +#include #include #include -#include #include @@ -23,7 +23,8 @@ Core::Action::EventItemAction::EventItemAction() } Core::Action::EventItemAction::EventItemAction( Entity::ActorPtr pActor, uint32_t eventId, uint16_t action, - ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional ) + ActionCallback finishRef, ActionCallback interruptRef, + uint64_t additional ) { m_additional = additional; m_handleActionType = HandleActionType::Event; @@ -57,7 +58,6 @@ void Core::Action::EventItemAction::onStart() m_pSource->sendToInRangeSet( castPacket, true ); m_pSource->getAsPlayer()->setStateFlag( PlayerStateFlag::Casting ); m_pSource->getAsPlayer()->sendStateFlags(); - } void Core::Action::EventItemAction::onFinish() @@ -70,7 +70,7 @@ void Core::Action::EventItemAction::onFinish() GamePacketNew< FFXIVIpcEffect, ServerZoneIpcType > effectPacket( m_pSource->getId() ); effectPacket.data().targetId = static_cast< uint32_t >( m_additional ); effectPacket.data().actionAnimationId = 1; -// effectPacket.data().unknown_3 = 3; + // effectPacket.data().unknown_3 = 3; effectPacket.data().actionTextId = m_id; effectPacket.data().unknown_5 = 2; effectPacket.data().numEffects = 1; @@ -88,7 +88,6 @@ void Core::Action::EventItemAction::onFinish() { g_log.error( e.what() ); } - } void Core::Action::EventItemAction::onInterrupt() @@ -99,8 +98,7 @@ void Core::Action::EventItemAction::onInterrupt() try { - auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, - 0x219, 0x04, m_id ); + auto control = ActorControlPacket142( m_pSource->getId(), ActorControlType::CastInterrupt, 0x219, 0x04, m_id ); if( m_pSource->isPlayer() ) { m_pSource->getAsPlayer()->unsetStateFlag( PlayerStateFlag::Casting ); @@ -112,11 +110,9 @@ void Core::Action::EventItemAction::onInterrupt() if( m_onActionInterruptClb ) m_onActionInterruptClb( *m_pSource->getAsPlayer(), m_eventId, m_additional ); - } catch( std::exception& e ) { g_log.error( e.what() ); } - } diff --git a/src/servers/Server_Zone/Action/EventItemAction.h b/src/servers/Server_Zone/Action/EventItemAction.h index bd9eee9d..305e1a12 100644 --- a/src/servers/Server_Zone/Action/EventItemAction.h +++ b/src/servers/Server_Zone/Action/EventItemAction.h @@ -7,15 +7,15 @@ namespace Core { namespace Action { - class EventItemAction : public Action + class EventItemAction : public Action { public: EventItemAction(); ~EventItemAction(); - - EventItemAction( Entity::ActorPtr pActor, uint32_t eventId, uint16_t action, - ActionCallback finishRef, ActionCallback interruptRef, uint64_t additional ); + + EventItemAction( Entity::ActorPtr pActor, uint32_t eventId, uint16_t action, ActionCallback finishRef, + ActionCallback interruptRef, uint64_t additional ); void onStart() override; void onFinish() override; @@ -24,13 +24,12 @@ namespace Action { private: uint32_t m_eventId; uint64_t m_additional; - + ActionCallback m_onActionFinishClb; ActionCallback m_onActionInterruptClb; - }; -} -} +} // namespace Action +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Actor/Actor.cpp b/src/servers/Server_Zone/Actor/Actor.cpp index 3439fef7..4210ab31 100644 --- a/src/servers/Server_Zone/Actor/Actor.cpp +++ b/src/servers/Server_Zone/Actor/Actor.cpp @@ -1,11 +1,11 @@ -#include -#include -#include #include #include +#include +#include +#include -#include "Forwards.h" #include "Action/Action.h" +#include "Forwards.h" #include "Zone/Zone.h" @@ -15,13 +15,13 @@ #include "Network/PacketWrappers/ActorControlPacket144.h" #include "Network/PacketWrappers/UpdateHpMpTpPacket.h" -#include "StatusEffect/StatusEffect.h" #include "Action/ActionCollision.h" +#include "Actor.h" +#include "Math/CalcBattle.h" +#include "Player.h" #include "ServerZone.h" #include "Session.h" -#include "Math/CalcBattle.h" -#include "Actor.h" -#include "Player.h" +#include "StatusEffect/StatusEffect.h" extern Core::ServerZone g_serverZone; extern Core::Data::ExdData g_exdData; @@ -75,12 +75,12 @@ bool Core::Entity::Actor::isMob() const /*! \return list of actors currently in range */ std::set< Core::Entity::ActorPtr > Core::Entity::Actor::getInRangeActors( bool includeSelf ) { - auto tempInRange = m_inRangeActors; + auto tempInRange = m_inRangeActors; - if( includeSelf ) - tempInRange.insert( shared_from_this() ); + if( includeSelf ) + tempInRange.insert( shared_from_this() ); - return tempInRange; + return tempInRange; } /*! \return current stance of the actors */ @@ -243,12 +243,12 @@ void Core::Entity::Actor::die() // if the actor is a player, the update needs to be send to himself too bool selfNeedsUpdate = isPlayer(); - sendToInRangeSet( ActorControlPacket142( m_id, SetStatus, static_cast< uint8_t >( ActorStatus::Dead ) ), selfNeedsUpdate ); + sendToInRangeSet( ActorControlPacket142( m_id, SetStatus, static_cast< uint8_t >( ActorStatus::Dead ) ), + selfNeedsUpdate ); // TODO: not all actor show the death animation when they die, some quest npcs might just despawn // although that might be handled by setting the HP to 1 and doing some script magic sendToInRangeSet( ActorControlPacket142( m_id, DeathAnimation, 0, 0, 0, 0x20 ), selfNeedsUpdate ); - } /*! @@ -318,7 +318,6 @@ bool Core::Entity::Actor::checkAction() m_pCurrentAction.reset(); return true; - } /*! @@ -330,8 +329,7 @@ void Core::Entity::Actor::changeTarget( uint64_t targetId ) { setTargetId( targetId ); - sendToInRangeSet( ActorControlPacket144( m_id, SetTarget, - 0, 0, 0, 0, targetId ) ); + sendToInRangeSet( ActorControlPacket144( m_id, SetTarget, 0, 0, 0, 0, targetId ) ); } /*! @@ -355,17 +353,18 @@ void Core::Entity::Actor::takeDamage( uint32_t damage ) { if( damage >= m_hp ) { - switch( m_invincibilityType ) { - case InvincibilityNone: - setHp( 0 ); - die(); - break; - case InvincibilityRefill: - resetHp(); - break; - case InvincibilityStayAlive: - setHp( 0 ); - break; + switch( m_invincibilityType ) + { + case InvincibilityNone: + setHp( 0 ); + die(); + break; + case InvincibilityRefill: + resetHp(); + break; + case InvincibilityStayAlive: + setHp( 0 ); + break; } } else @@ -455,12 +454,8 @@ Core::Entity::ActorPtr Core::Entity::Actor::getClosestActor() for( const auto& pCurAct : m_inRangeActors ) { - float distance = Math::Util::distance( getPos().x, - getPos().y, - getPos().z, - pCurAct->getPos().x, - pCurAct->getPos().y, - pCurAct->getPos().z ); + float distance = Math::Util::distance( getPos().x, getPos().y, getPos().z, pCurAct->getPos().x, + pCurAct->getPos().y, pCurAct->getPos().z ); if( distance < minDistance ) { @@ -495,7 +490,7 @@ void Core::Entity::Actor::sendToInRangeSet( Network::Packets::GamePacketPtr pPac if( m_inRangePlayers.empty() ) return; - for( const auto &pCurAct : m_inRangePlayers ) + for( const auto& pCurAct : m_inRangePlayers ) { assert( pCurAct ); pPacket->setValAt< uint32_t >( 0x04, m_id ); @@ -593,7 +588,7 @@ Get the current cell of a region the actor is in \return Cell* */ -Core::Cell * Core::Entity::Actor::getCell() const +Core::Cell* Core::Entity::Actor::getCell() const { return m_pCell; } @@ -603,7 +598,7 @@ Set the current cell the actor is in \param Cell* for the cell to be set */ -void Core::Entity::Actor::setCell( Cell * pCell ) +void Core::Entity::Actor::setCell( Cell* pCell ) { m_pCell = pCell; } @@ -635,7 +630,7 @@ void Core::Entity::Actor::autoAttack( ActorPtr pTarget ) effectPacket.data().targetId = pTarget->getId(); effectPacket.data().actionAnimationId = 0x366; effectPacket.data().unknown_2 = variation; -// effectPacket.data().unknown_3 = 1; + // effectPacket.data().unknown_3 = 1; effectPacket.data().actionTextId = 0x366; effectPacket.data().numEffects = 1; effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRotation() ); @@ -660,8 +655,8 @@ ChaiScript Skill Handler. \param GamePacketPtr to send \param bool should be send to self? */ -void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, uint64_t param1, - uint64_t param2, Entity::Actor& pTarget ) +void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, uint64_t param1, uint64_t param2, + Entity::Actor& pTarget ) { if( isPlayer() ) @@ -685,7 +680,8 @@ void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, u effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRotation() ); effectPacket.data().effectTarget = pTarget.getId(); - // Todo: for each actor, calculate how much damage the calculated value should deal to them - 2-step damage calc. we only have 1-step + // Todo: for each actor, calculate how much damage the calculated value should deal to them - 2-step damage calc. we + // only have 1-step switch( type ) { @@ -699,16 +695,15 @@ void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, u if( !actionInfoPtr->is_aoe ) { // If action on this specific target is valid... - if ( isPlayer() && !ActionCollision::isActorApplicable( pTarget.shared_from_this(), TargetFilter::Enemies ) ) + if( isPlayer() && !ActionCollision::isActorApplicable( pTarget.shared_from_this(), TargetFilter::Enemies ) ) break; sendToInRangeSet( effectPacket, true ); - if ( pTarget.isAlive() ) + if( pTarget.isAlive() ) pTarget.onActionHostile( shared_from_this() ); pTarget.takeDamage( static_cast< uint32_t >( param1 ) ); - } else { @@ -724,20 +719,20 @@ void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, u // todo: send to range of what? ourselves? when mob script hits this is going to be lacking sendToInRangeSet( effectPacket, true ); - if( pHitActor->isAlive() ) pHitActor->onActionHostile( shared_from_this() ); pHitActor->takeDamage( static_cast< uint32_t >( param1 ) ); // Debug - if ( isPlayer() ) + if( isPlayer() ) { - if ( pHitActor->isPlayer() ) - getAsPlayer()->sendDebug( "AoE hit actor " + std::to_string( pHitActor->getId() ) + " (" + pHitActor->getName() + ")" ); + if( pHitActor->isPlayer() ) + getAsPlayer()->sendDebug( "AoE hit actor " + std::to_string( pHitActor->getId() ) + " (" + + pHitActor->getName() + ")" ); else getAsPlayer()->sendDebug( "AoE hit actor " + std::to_string( pHitActor->getId() ) ); - } + } } } @@ -746,7 +741,8 @@ void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, u case ActionEffectType::Heal: { - uint32_t calculatedHeal = Math::CalcBattle::calculateHealValue( getAsPlayer(), static_cast< uint32_t >( param1 ) ); + uint32_t calculatedHeal = + Math::CalcBattle::calculateHealValue( getAsPlayer(), static_cast< uint32_t >( param1 ) ); effectPacket.data().effects[0].value = calculatedHeal; effectPacket.data().effects[0].effectType = ActionEffectType::Heal; @@ -780,7 +776,8 @@ void Core::Entity::Actor::handleScriptSkill( uint32_t type, uint16_t actionId, u if( isPlayer() ) { if( pHitActor->isPlayer() ) - getAsPlayer()->sendDebug( "AoE hit actor " + std::to_string( pHitActor->getId() ) + " (" + pHitActor->getName() + ")" ); + getAsPlayer()->sendDebug( "AoE hit actor " + std::to_string( pHitActor->getId() ) + " (" + + pHitActor->getName() + ")" ); else getAsPlayer()->sendDebug( "AoE hit actor " + std::to_string( pHitActor->getId() ) ); } @@ -807,7 +804,7 @@ void Core::Entity::Actor::addStatusEffect( StatusEffect::StatusEffectPtr pEffect ZoneChannelPacket< Server::FFXIVIpcAddStatusEffect > statusEffectAdd( getId() ); statusEffectAdd.data().actor_id = pEffect->getTargetActorId(); - statusEffectAdd.data().actor_id1 = pEffect->getSrcActorId(); + statusEffectAdd.data().actor_id1 = pEffect->getSrcActorId(); statusEffectAdd.data().current_hp = getHp(); statusEffectAdd.data().current_mp = getMp(); statusEffectAdd.data().current_tp = getTp(); @@ -817,7 +814,7 @@ void Core::Entity::Actor::addStatusEffect( StatusEffect::StatusEffectPtr pEffect statusEffectAdd.data().max_hp = getMaxHp(); statusEffectAdd.data().max_mp = getMaxMp(); statusEffectAdd.data().max_something = 1; - //statusEffectAdd.data().unknown2 = 28; + // statusEffectAdd.data().unknown2 = 28; statusEffectAdd.data().param = pEffect->getParam(); sendToInRangeSet( statusEffectAdd, isPlayer() ); @@ -826,23 +823,23 @@ void Core::Entity::Actor::addStatusEffect( StatusEffect::StatusEffectPtr pEffect /*! \param StatusEffectPtr to be applied to the actor */ void Core::Entity::Actor::addStatusEffectById( uint32_t id, int32_t duration, Entity::Actor& pSource, uint16_t param ) { - StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, pSource.shared_from_this(), - shared_from_this(), duration, 3000 ) ); + StatusEffect::StatusEffectPtr effect( + new StatusEffect::StatusEffect( id, pSource.shared_from_this(), shared_from_this(), duration, 3000 ) ); effect->setParam( param ); addStatusEffect( effect ); } /*! \param StatusEffectPtr to be applied to the actor */ -void Core::Entity::Actor::addStatusEffectByIdIfNotExist( uint32_t id, int32_t duration, Entity::Actor& pSource, uint16_t param ) +void Core::Entity::Actor::addStatusEffectByIdIfNotExist( uint32_t id, int32_t duration, Entity::Actor& pSource, + uint16_t param ) { if( hasStatusEffect( id ) ) return; - StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, pSource.shared_from_this(), - shared_from_this(), duration, 3000 ) ); + StatusEffect::StatusEffectPtr effect( + new StatusEffect::StatusEffect( id, pSource.shared_from_this(), shared_from_this(), duration, 3000 ) ); effect->setParam( param ); addStatusEffect( effect ); - } float Core::Entity::Actor::getRotation() const @@ -922,8 +919,9 @@ void Core::Entity::Actor::sendStatusEffectUpdate() uint8_t slot = 0; for( auto effectIt : m_statusEffectMap ) { - float timeLeft = static_cast< float >( effectIt.second->getDuration() - - ( currentTimeMs - effectIt.second->getStartTimeMs() ) ) / 1000; + float timeLeft = static_cast< float >( effectIt.second->getDuration() - + ( currentTimeMs - effectIt.second->getStartTimeMs() ) ) / + 1000; statusEffectList.data().effect[slot].duration = timeLeft; statusEffectList.data().effect[slot].effect_id = effectIt.second->getId(); statusEffectList.data().effect[slot].sourceActorId = effectIt.second->getSrcActorId(); @@ -931,7 +929,6 @@ void Core::Entity::Actor::sendStatusEffectUpdate() } sendToInRangeSet( statusEffectList, isPlayer() ); - } void Core::Entity::Actor::updateStatusEffects() @@ -980,22 +977,22 @@ void Core::Entity::Actor::updateStatusEffects() thisTickHeal += thisEffect.second; break; } - } } - } if( thisTickDmg != 0 ) { takeDamage( thisTickDmg ); - sendToInRangeSet( ActorControlPacket142( getId(), HPFloatingText, 0, static_cast< uint8_t >( ActionEffectType::Damage ), thisTickDmg ) ); + sendToInRangeSet( ActorControlPacket142( getId(), HPFloatingText, 0, + static_cast< uint8_t >( ActionEffectType::Damage ), thisTickDmg ) ); } if( thisTickHeal != 0 ) { heal( thisTickDmg ); - sendToInRangeSet( ActorControlPacket142( getId(), HPFloatingText, 0, static_cast< uint8_t >( ActionEffectType::Heal ), thisTickHeal ) ); + sendToInRangeSet( ActorControlPacket142( getId(), HPFloatingText, 0, + static_cast< uint8_t >( ActionEffectType::Heal ), thisTickHeal ) ); } } diff --git a/src/servers/Server_Zone/Actor/Actor.h b/src/servers/Server_Zone/Actor/Actor.h index 35547b01..0b672bbf 100644 --- a/src/servers/Server_Zone/Actor/Actor.h +++ b/src/servers/Server_Zone/Actor/Actor.h @@ -5,343 +5,342 @@ #include #include "Forwards.h" -#include #include #include +#include namespace Core { namespace Entity { -/*! -\class Actor -\brief Base class for all actors + /*! + \class Actor + \brief Base class for all actors -\author Mordred -*/ -class Actor : public boost::enable_shared_from_this< Actor > -{ -public: - enum ObjKind : uint8_t + \author Mordred + */ + class Actor : public boost::enable_shared_from_this< Actor > { - None = 0x00, - Player = 0x01, - BattleNpc = 0x02, - EventNpc = 0x03, - Treasure = 0x04, - Aetheryte = 0x05, - GatheringPoint = 0x06, - EventObj = 0x07, - Mount = 0x08, - Companion = 0x09, - Retainer = 0x0A, - Area = 0x0B, - Housing = 0x0C, - Cutscene = 0x0D, - CardStand = 0x0E, + public: + enum ObjKind : uint8_t + { + None = 0x00, + Player = 0x01, + BattleNpc = 0x02, + EventNpc = 0x03, + Treasure = 0x04, + Aetheryte = 0x05, + GatheringPoint = 0x06, + EventObj = 0x07, + Mount = 0x08, + Companion = 0x09, + Retainer = 0x0A, + Area = 0x0B, + Housing = 0x0C, + Cutscene = 0x0D, + CardStand = 0x0E, + }; + + enum Stance : uint8_t + { + Passive = 0, + Active = 1, + }; + + enum DisplayFlags : uint16_t + { + ActiveStance = 0x001, + Invisible = 0x020, + HideHead = 0x040, + HideWeapon = 0x080, + Faded = 0x100, + Visor = 0x800, + }; + + enum struct ActorStatus : uint8_t + { + Idle = 0x01, + Dead = 0x02, + Sitting = 0x03, + Mounted = 0x04, + Crafting = 0x05, + Gathering = 0x06, + Melding = 0x07, + SMachine = 0x08 + }; + + struct ActorStats + { + uint32_t max_mp = 0; + uint32_t max_hp = 0; + + uint32_t str = 0; + uint32_t dex = 0; + uint32_t vit = 0; + uint32_t inte = 0; + uint32_t mnd = 0; + uint32_t pie = 0; + + uint32_t tenacity = 0; + uint32_t attack = 0; + uint32_t defense = 0; + uint32_t accuracy = 0; + uint32_t spellSpeed = 0; + uint32_t magicDefense = 0; + uint32_t critHitRate = 0; + uint32_t resistSlash = 0; + uint32_t resistPierce = 0; + uint32_t resistBlunt = 0; + uint32_t attackPotMagic = 0; + uint32_t healingPotMagic = 0; + uint32_t determination = 0; + uint32_t skillSpeed = 0; + + uint32_t resistSlow = 0; + uint32_t resistSilence = 0; + uint32_t resistBlind = 0; + uint32_t resistPoison = 0; + uint32_t resistStun = 0; + uint32_t resistSleep = 0; + uint32_t resistBind = 0; + uint32_t resistHeavy = 0; + + uint32_t resistFire = 0; + uint32_t resistIce = 0; + uint32_t resistWind = 0; + uint32_t resistEarth = 0; + uint32_t resistLightning = 0; + uint32_t resistWater = 0; + + } m_baseStats; + + protected: + // TODO: The position class should probably be abolished and + // the FFXIV_POS struct used instead ( the functions in there + // could be moved to a FFXIV_POS_Helper namespace and rotation to + // its own member ) + /*! Position of the actor */ + Common::FFXIVARR_POSITION3 m_pos; + float m_rot; + /*! Name of the actor */ + char m_name[34]; + /*! Id of the zone the actor currently is in */ + uint32_t m_zoneId; + /*! Id of the actor */ + uint32_t m_id; + /*! Type of the actor */ + ObjKind m_objKind; + /*! Ptr to the ZoneObj the actor belongs to */ + ZonePtr m_pCurrentZone; + /*! Last tick time for the actor ( in ms ) */ + uint64_t m_lastTickTime; + /*! Last time the actor performed an autoAttack ( in ms ) */ + uint64_t m_lastAttack; + /*! Last time the actor was updated ( in ms ) */ + uint64_t m_lastUpdate; + /*! Current stance of the actor */ + Stance m_currentStance; + /*! Current staus of the actor */ + ActorStatus m_status; + /*! Max HP of the actor ( based on job / class ) */ + uint32_t m_maxHp; + /*! Max MP of the actor ( based on job / class ) */ + uint32_t m_maxMp; + /*! Current HP of the actor */ + uint32_t m_hp; + /*! Current MP of the actor */ + uint32_t m_mp; + /*! Current TP of the actor */ + uint16_t m_tp; + /*! Current GP of the actor */ + uint16_t m_gp; + /*! Additional look info of the actor */ + uint8_t m_customize[26]; + /*! Current class of the actor */ + Common::ClassJob m_class; + /*! Id of the currently selected target actor */ + uint64_t m_targetId; + /*! Ptr to a queued action */ + Action::ActionPtr m_pCurrentAction; + /*! Invincibility type */ + Common::InvincibilityType m_invincibilityType; + + /*! Status effects */ + const uint8_t MAX_STATUS_EFFECTS = 30; + std::queue< uint8_t > m_statusEffectFreeSlotQueue; + std::vector< std::pair< uint8_t, uint32_t > > m_statusEffectList; + std::map< uint8_t, StatusEffect::StatusEffectPtr > m_statusEffectMap; + + public: + Actor(); + + virtual ~Actor(); + + virtual void calculateStats(){}; + + uint32_t getId() const; + + /// Status effect functions + void addStatusEffect( StatusEffect::StatusEffectPtr pEffect ); + void removeStatusEffect( uint8_t effectSlotId ); + void removeSingleStatusEffectById( uint32_t id ); + void updateStatusEffects(); + + bool hasStatusEffect( uint32_t id ); + + int8_t getStatusEffectFreeSlot(); + void statusEffectFreeSlot( uint8_t slotId ); + + std::map< uint8_t, Core::StatusEffect::StatusEffectPtr > getStatusEffectMap() const; + + void sendStatusEffectUpdate(); + // add a status effect by id + void addStatusEffectById( uint32_t id, int32_t duration, Entity::Actor& pSource, uint16_t param = 0 ); + + // add a status effect by id if it doesn't exist + void addStatusEffectByIdIfNotExist( uint32_t id, int32_t duration, Entity::Actor& pSource, uint16_t param = 0 ); + + // remove a status effect by id + void removeSingleStatusEffectFromId( uint32_t id ); + /// End Status Effect Functions + + void setPosition( const Common::FFXIVARR_POSITION3& pos ); + void setPosition( float x, float y, float z ); + + void setRotation( float rot ); + + float getRotation() const; + + Common::FFXIVARR_POSITION3& getPos(); + + std::string getName() const; + + bool isPlayer() const; + + bool isMob() const; + + std::set< ActorPtr > getInRangeActors( bool includeSelf = false ); + + bool face( const Common::FFXIVARR_POSITION3& p ); + + Stance getStance() const; + + void setStance( Stance stance ); + + ActorStats getStats() const; + + uint32_t getHp() const; + + uint32_t getMp() const; + + uint16_t getTp() const; + + uint16_t getGp() const; + + Common::InvincibilityType getInvincibilityType() const; + + Common::ClassJob getClass() const; + + uint8_t getClassAsInt() const; + + void setClass( Common::ClassJob classJob ); + + void setTargetId( uint64_t targetId ); + + uint64_t getTargetId() const; + + bool isAlive() const; + + virtual uint32_t getMaxHp() const; + + virtual uint32_t getMaxMp() const; + + void resetHp(); + + void resetMp(); + + void setHp( uint32_t hp ); + + void setMp( uint32_t mp ); + + void setGp( uint32_t gp ); + + void setInvincibilityType( Common::InvincibilityType type ); + + void die(); + + ActorStatus getStatus() const; + + void setStatus( ActorStatus status ); + + void handleScriptSkill( uint32_t type, uint16_t actionId, uint64_t param1, uint64_t param2, + Entity::Actor& target ); + + virtual void autoAttack( ActorPtr pTarget ); + + virtual void spawn( PlayerPtr pTarget ) {} + virtual void despawn( ActorPtr pTarget ) {} + + virtual void onRemoveInRangeActor( ActorPtr pActor ) {} + virtual void onDeath(){}; + virtual void onDamageTaken( Actor& pSource ){}; + virtual void onActionHostile( Core::Entity::ActorPtr pSource ){}; + virtual void onActionFriendly( Actor& pSource ){}; + virtual void onTick(){}; + + virtual void changeTarget( uint64_t targetId ); + virtual uint8_t getLevel() const; + virtual void sendStatusUpdate( bool toSelf = true ); + virtual void takeDamage( uint32_t damage ); + virtual void heal( uint32_t amount ); + virtual bool checkAction(); + virtual void update( int64_t currTime ){}; + + PlayerPtr getAsPlayer(); + BattleNpcPtr getAsBattleNpc(); + + Action::ActionPtr getCurrentAction() const; + + void setCurrentAction( Action::ActionPtr pAction ); + + ///// IN RANGE LOGIC ///// + + // check if another actor is in the actors in range set + bool isInRangeSet( ActorPtr pActor ) const; + + ActorPtr getClosestActor(); + + void sendToInRangeSet( Network::Packets::GamePacketPtr pPacket, bool bToSelf = false ); + + // add an actor to in range set + virtual void addInRangeActor( ActorPtr pActor ); + + // remove an actor from the in range set + void removeInRangeActor( ActorPtr pActor ); + + // return true if there is at least one actor in the in range set + bool hasInRangeActor() const; + + // clear the whole in range set, this does no cleanup + virtual void clearInRangeSet(); + + ZonePtr getCurrentZone() const; + + void setCurrentZone( ZonePtr currZone ); + + // get the current cell of a region the actor is in + Cell* getCell() const; + + // set the current cell + void setCell( Cell* pCell ); + + // TODO: Why did i even declare them publicly here?! + std::set< ActorPtr > m_inRangeActors; + std::set< PlayerPtr > m_inRangePlayers; + std::map< uint32_t, ActorPtr > m_inRangeActorMap; + + Core::Cell* m_pCell; }; - enum Stance : uint8_t - { - Passive = 0, - Active = 1, - }; - - enum DisplayFlags : uint16_t - { - ActiveStance = 0x001, - Invisible = 0x020, - HideHead = 0x040, - HideWeapon = 0x080, - Faded = 0x100, - Visor = 0x800, - }; - - enum struct ActorStatus : uint8_t - { - Idle = 0x01, - Dead = 0x02, - Sitting = 0x03, - Mounted = 0x04, - Crafting = 0x05, - Gathering = 0x06, - Melding = 0x07, - SMachine = 0x08 - }; - - struct ActorStats - { - uint32_t max_mp = 0; - uint32_t max_hp = 0; - - uint32_t str = 0; - uint32_t dex = 0; - uint32_t vit = 0; - uint32_t inte = 0; - uint32_t mnd = 0; - uint32_t pie = 0; - - uint32_t tenacity = 0; - uint32_t attack = 0; - uint32_t defense = 0; - uint32_t accuracy = 0; - uint32_t spellSpeed = 0; - uint32_t magicDefense = 0; - uint32_t critHitRate = 0; - uint32_t resistSlash = 0; - uint32_t resistPierce = 0; - uint32_t resistBlunt = 0; - uint32_t attackPotMagic = 0; - uint32_t healingPotMagic = 0; - uint32_t determination = 0; - uint32_t skillSpeed = 0; - - uint32_t resistSlow = 0; - uint32_t resistSilence = 0; - uint32_t resistBlind = 0; - uint32_t resistPoison = 0; - uint32_t resistStun = 0; - uint32_t resistSleep = 0; - uint32_t resistBind = 0; - uint32_t resistHeavy = 0; - - uint32_t resistFire = 0; - uint32_t resistIce = 0; - uint32_t resistWind = 0; - uint32_t resistEarth = 0; - uint32_t resistLightning = 0; - uint32_t resistWater = 0; - - } m_baseStats; - -protected: - // TODO: The position class should probably be abolished and - // the FFXIV_POS struct used instead ( the functions in there - // could be moved to a FFXIV_POS_Helper namespace and rotation to - // its own member ) - /*! Position of the actor */ - Common::FFXIVARR_POSITION3 m_pos; - float m_rot; - /*! Name of the actor */ - char m_name[34]; - /*! Id of the zone the actor currently is in */ - uint32_t m_zoneId; - /*! Id of the actor */ - uint32_t m_id; - /*! Type of the actor */ - ObjKind m_objKind; - /*! Ptr to the ZoneObj the actor belongs to */ - ZonePtr m_pCurrentZone; - /*! Last tick time for the actor ( in ms ) */ - uint64_t m_lastTickTime; - /*! Last time the actor performed an autoAttack ( in ms ) */ - uint64_t m_lastAttack; - /*! Last time the actor was updated ( in ms ) */ - uint64_t m_lastUpdate; - /*! Current stance of the actor */ - Stance m_currentStance; - /*! Current staus of the actor */ - ActorStatus m_status; - /*! Max HP of the actor ( based on job / class ) */ - uint32_t m_maxHp; - /*! Max MP of the actor ( based on job / class ) */ - uint32_t m_maxMp; - /*! Current HP of the actor */ - uint32_t m_hp; - /*! Current MP of the actor */ - uint32_t m_mp; - /*! Current TP of the actor */ - uint16_t m_tp; - /*! Current GP of the actor */ - uint16_t m_gp; - /*! Additional look info of the actor */ - uint8_t m_customize[26]; - /*! Current class of the actor */ - Common::ClassJob m_class; - /*! Id of the currently selected target actor */ - uint64_t m_targetId; - /*! Ptr to a queued action */ - Action::ActionPtr m_pCurrentAction; - /*! Invincibility type */ - Common::InvincibilityType m_invincibilityType; - - /*! Status effects */ - const uint8_t MAX_STATUS_EFFECTS = 30; - std::queue< uint8_t > m_statusEffectFreeSlotQueue; - std::vector< std::pair< uint8_t, uint32_t> > m_statusEffectList; - std::map< uint8_t, StatusEffect::StatusEffectPtr > m_statusEffectMap; - -public: - Actor(); - - virtual ~Actor(); - - virtual void calculateStats() {}; - - uint32_t getId() const; - - /// Status effect functions - void addStatusEffect( StatusEffect::StatusEffectPtr pEffect ); - void removeStatusEffect( uint8_t effectSlotId ); - void removeSingleStatusEffectById( uint32_t id ); - void updateStatusEffects(); - - bool hasStatusEffect( uint32_t id ); - - int8_t getStatusEffectFreeSlot(); - void statusEffectFreeSlot( uint8_t slotId ); - - std::map< uint8_t, Core::StatusEffect::StatusEffectPtr > getStatusEffectMap() const; - - void sendStatusEffectUpdate(); - // add a status effect by id - void addStatusEffectById( uint32_t id, int32_t duration, Entity::Actor& pSource, uint16_t param = 0 ); - - // add a status effect by id if it doesn't exist - void addStatusEffectByIdIfNotExist( uint32_t id, int32_t duration, Entity::Actor& pSource, uint16_t param = 0 ); - - // remove a status effect by id - void removeSingleStatusEffectFromId( uint32_t id ); - /// End Status Effect Functions - - void setPosition( const Common::FFXIVARR_POSITION3& pos ); - void setPosition( float x, float y, float z ); - - void setRotation( float rot ); - - float getRotation() const; - - Common::FFXIVARR_POSITION3& getPos(); - - std::string getName() const; - - bool isPlayer() const; - - bool isMob() const; - - std::set< ActorPtr > getInRangeActors( bool includeSelf = false ); - - bool face( const Common::FFXIVARR_POSITION3& p ); - - Stance getStance() const; - - void setStance( Stance stance ); - - ActorStats getStats() const; - - uint32_t getHp() const; - - uint32_t getMp() const; - - uint16_t getTp() const; - - uint16_t getGp() const; - - Common::InvincibilityType getInvincibilityType() const; - - Common::ClassJob getClass() const; - - uint8_t getClassAsInt() const; - - void setClass( Common::ClassJob classJob ); - - void setTargetId( uint64_t targetId ); - - uint64_t getTargetId() const; - - bool isAlive() const; - - virtual uint32_t getMaxHp() const; - - virtual uint32_t getMaxMp() const; - - void resetHp(); - - void resetMp(); - - void setHp( uint32_t hp ); - - void setMp( uint32_t mp ); - - void setGp( uint32_t gp ); - - void setInvincibilityType( Common::InvincibilityType type ); - - void die(); - - ActorStatus getStatus() const; - - void setStatus( ActorStatus status ); - - void handleScriptSkill( uint32_t type, uint16_t actionId, uint64_t param1, uint64_t param2, Entity::Actor& target ); - - virtual void autoAttack( ActorPtr pTarget ); - - virtual void spawn( PlayerPtr pTarget ) {} - virtual void despawn( ActorPtr pTarget ) {} - - virtual void onRemoveInRangeActor( ActorPtr pActor ) {} - virtual void onDeath() {}; - virtual void onDamageTaken( Actor& pSource ) {}; - virtual void onActionHostile( Core::Entity::ActorPtr pSource ) {}; - virtual void onActionFriendly( Actor& pSource ) {}; - virtual void onTick() {}; - - virtual void changeTarget( uint64_t targetId ); - virtual uint8_t getLevel() const; - virtual void sendStatusUpdate( bool toSelf = true ); - virtual void takeDamage( uint32_t damage ); - virtual void heal( uint32_t amount ); - virtual bool checkAction(); - virtual void update( int64_t currTime ) {}; - - PlayerPtr getAsPlayer(); - BattleNpcPtr getAsBattleNpc(); - - Action::ActionPtr getCurrentAction() const; - - void setCurrentAction( Action::ActionPtr pAction ); - - ///// IN RANGE LOGIC ///// - - // check if another actor is in the actors in range set - bool isInRangeSet( ActorPtr pActor ) const; - - ActorPtr getClosestActor(); - - void sendToInRangeSet( Network::Packets::GamePacketPtr pPacket, bool bToSelf = false ); - - // add an actor to in range set - virtual void addInRangeActor( ActorPtr pActor ); - - // remove an actor from the in range set - void removeInRangeActor( ActorPtr pActor ); - - // return true if there is at least one actor in the in range set - bool hasInRangeActor() const; - - // clear the whole in range set, this does no cleanup - virtual void clearInRangeSet(); - - ZonePtr getCurrentZone() const; - - void setCurrentZone( ZonePtr currZone ); - - // get the current cell of a region the actor is in - Cell* getCell() const; - - // set the current cell - void setCell( Cell* pCell ); - - - // TODO: Why did i even declare them publicly here?! - std::set< ActorPtr > m_inRangeActors; - std::set< PlayerPtr > m_inRangePlayers; - std::map< uint32_t, ActorPtr > m_inRangeActorMap; - - Core::Cell* m_pCell; - -}; - -} -} +} // namespace Entity +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Actor/BattleNpc.cpp b/src/servers/Server_Zone/Actor/BattleNpc.cpp index e76003d7..0aaeb1d6 100644 --- a/src/servers/Server_Zone/Actor/BattleNpc.cpp +++ b/src/servers/Server_Zone/Actor/BattleNpc.cpp @@ -1,20 +1,20 @@ +#include +#include #include #include #include -#include -#include -#include #include +#include #include #include -#include "Player.h" #include "BattleNpc.h" +#include "Player.h" -#include "Network/PacketWrappers/MoveActorPacket.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" +#include "Network/PacketWrappers/MoveActorPacket.h" using namespace Core::Common; using namespace Core::Network::Packets; @@ -34,16 +34,16 @@ Core::Entity::BattleNpc::BattleNpc() Core::Entity::BattleNpc::~BattleNpc() { - } Core::Entity::BattleNpc::BattleNpc( uint16_t modelId, uint16_t nameid, const Common::FFXIVARR_POSITION3& spawnPos, uint16_t bnpcBaseId, uint32_t type, uint8_t level, uint8_t behaviour, - uint32_t mobType ) : Actor() + uint32_t mobType ) : + Actor() { BattleNpc::m_nextID++; m_id = BattleNpc::m_nextID; - //strcpy( m_name, pBNpc->m_name.c_str() ); + // strcpy( m_name, pBNpc->m_name.c_str() ); m_pos = spawnPos; m_posOrigin = spawnPos; @@ -65,7 +65,7 @@ Core::Entity::BattleNpc::BattleNpc( uint16_t modelId, uint16_t nameid, const Com m_currentStance = Stance::Passive; m_class = ClassJob::Gladiator; - m_level = level > uint8_t{0} ? level : uint8_t{70}; + m_level = level > uint8_t{ 0 } ? level : uint8_t{ 70 }; m_modelId = modelId; m_nameId = nameid; @@ -82,46 +82,44 @@ Core::Entity::BattleNpc::BattleNpc( uint16_t modelId, uint16_t nameid, const Com m_invincibilityType = InvincibilityType::InvincibilityNone; - //m_type = static_cast< Common::ObjKind >( type ); - + // m_type = static_cast< Common::ObjKind >( type ); } // spawn this player for pTarget void Core::Entity::BattleNpc::spawn( PlayerPtr pTarget ) { - //GamePacketNew< FFXIVIpcActorSpawn > spawnPacket( getId(), pTarget->getId() ); + // GamePacketNew< FFXIVIpcActorSpawn > spawnPacket( getId(), pTarget->getId() ); - //spawnPacket.data().unknown_0 = 0; - //spawnPacket.data().ownerId = m_pOwner == nullptr ? INVALID_GAME_OBJECT_ID : m_pOwner->getId(); - //spawnPacket.data().targetId = INVALID_GAME_OBJECT_ID & 0xFFFFFFFF; - //spawnPacket.data().hPCurr = m_hp; - //spawnPacket.data().hPMax = m_baseStats.max_hp; - //spawnPacket.data().level = m_level; + // spawnPacket.data().unknown_0 = 0; + // spawnPacket.data().ownerId = m_pOwner == nullptr ? INVALID_GAME_OBJECT_ID : m_pOwner->getId(); + // spawnPacket.data().targetId = INVALID_GAME_OBJECT_ID & 0xFFFFFFFF; + // spawnPacket.data().hPCurr = m_hp; + // spawnPacket.data().hPMax = m_baseStats.max_hp; + // spawnPacket.data().level = m_level; ////spawnPacket.data().tPCurr = 1000; - //spawnPacket.data().model = m_modelId; - //spawnPacket.data().bnpcBaseId = m_bnpcBaseId; - //spawnPacket.data().nameId = m_nameId; - //spawnPacket.data().spawnIndex = pTarget->getSpawnIdForActorId( getId() ); - //g_log.info(std::to_string(spawnPacket.data().spawnIndex) + " " + std::to_string(getId())); - //spawnPacket.data().status = static_cast< uint8_t >( m_status ); - //spawnPacket.data().mobAgressive = m_behavior; - //spawnPacket.data().type = static_cast< uint8_t >( m_type ); - //spawnPacket.data().mobTypeIcon = m_mobType; - //spawnPacket.data().unknown_33 = 5; - //spawnPacket.data().typeFlags = 4; - //spawnPacket.data().pos.x = m_pos.x; - //spawnPacket.data().pos.y = m_pos.y; - //spawnPacket.data().pos.z = m_pos.z; - //spawnPacket.data().rotation = Math::Util::floatToUInt16Rot( getRotation() ); + // spawnPacket.data().model = m_modelId; + // spawnPacket.data().bnpcBaseId = m_bnpcBaseId; + // spawnPacket.data().nameId = m_nameId; + // spawnPacket.data().spawnIndex = pTarget->getSpawnIdForActorId( getId() ); + // g_log.info(std::to_string(spawnPacket.data().spawnIndex) + " " + std::to_string(getId())); + // spawnPacket.data().status = static_cast< uint8_t >( m_status ); + // spawnPacket.data().mobAgressive = m_behavior; + // spawnPacket.data().type = static_cast< uint8_t >( m_type ); + // spawnPacket.data().mobTypeIcon = m_mobType; + // spawnPacket.data().unknown_33 = 5; + // spawnPacket.data().typeFlags = 4; + // spawnPacket.data().pos.x = m_pos.x; + // spawnPacket.data().pos.y = m_pos.y; + // spawnPacket.data().pos.z = m_pos.z; + // spawnPacket.data().rotation = Math::Util::floatToUInt16Rot( getRotation() ); ////spawnPacket.data().unknown_B0[11] = 1; ////spawnPacket.data().unknown_B0[12] = 4; ////spawnPacket.data().unknown_B0[14] = 20; - //pTarget->queuePacket( spawnPacket ); + // pTarget->queuePacket( spawnPacket ); ZoneChannelPacket< FFXIVIpcNpcSpawn > spawnPacket( getId(), pTarget->getId() ); - spawnPacket.data().pos.x = m_pos.x; spawnPacket.data().pos.y = m_pos.y; spawnPacket.data().pos.z = m_pos.z; @@ -158,7 +156,6 @@ void Core::Entity::BattleNpc::despawn( ActorPtr pTarget ) ActorControlPacket143 controlPacket( m_id, DespawnZoneScreenMsg, 0x04, getId(), 0x01 ); pPlayer->queuePacket( controlPacket ); - } uint8_t Core::Entity::BattleNpc::getLevel() const @@ -224,12 +221,11 @@ void Core::Entity::BattleNpc::setOwner( PlayerPtr pPlayer ) } else { - ZoneChannelPacket< FFXIVIpcActorOwner > setOwnerPacket(getId(), INVALID_GAME_OBJECT_ID ); + ZoneChannelPacket< FFXIVIpcActorOwner > setOwnerPacket( getId(), INVALID_GAME_OBJECT_ID ); setOwnerPacket.data().type = 0x01; setOwnerPacket.data().actorId = INVALID_GAME_OBJECT_ID; sendToInRangeSet( setOwnerPacket ); } - } void Core::Entity::BattleNpc::sendPositionUpdate() @@ -241,8 +237,7 @@ void Core::Entity::BattleNpc::sendPositionUpdate() bool Core::Entity::BattleNpc::moveTo( Common::FFXIVARR_POSITION3& pos ) { - if( Math::Util::distance( getPos().x, getPos().y, getPos().z, - pos.x, pos.y, pos.z ) <= 4 ) + if( Math::Util::distance( getPos().x, getPos().y, getPos().z, pos.x, pos.y, pos.z ) <= 4 ) // reached destination return true; @@ -251,7 +246,7 @@ bool Core::Entity::BattleNpc::moveTo( Common::FFXIVARR_POSITION3& pos ) face( pos ); float angle = Math::Util::calcAngFrom( getPos().x, getPos().z, pos.x, pos.z ) + PI; - + float x = static_cast< float >( cosf( angle ) * 1.1f ); float y = ( getPos().y + pos.y ) * 0.5f; // fake value while there is no collision float z = static_cast< float >( sinf( angle ) * 1.1f ); @@ -270,12 +265,11 @@ bool Core::Entity::BattleNpc::moveTo( Common::FFXIVARR_POSITION3& pos ) tmpPos.z = getPos().z + z; setPosition( tmpPos ); - setRotation(newRot); + setRotation( newRot ); sendPositionUpdate(); return false; - } void Core::Entity::BattleNpc::aggro( ActorPtr pActor ) @@ -321,7 +315,6 @@ void Core::Entity::BattleNpc::hateListClear() m_hateList.clear(); } - void Core::Entity::BattleNpc::hateListRemove( ActorPtr pActor ) { auto it = m_hateList.begin(); @@ -384,7 +377,7 @@ void Core::Entity::BattleNpc::hateListUpdate( ActorPtr pActor, int32_t hateAmoun void Core::Entity::BattleNpc::onDeath() { - //LuaManager->onMobDeath( this ); + // LuaManager->onMobDeath( this ); setTimeOfDeath( static_cast< uint32_t >( time( nullptr ) ) ); setTargetId( INVALID_GAME_OBJECT_ID ); @@ -410,13 +403,13 @@ void Core::Entity::BattleNpc::onDeath() totalHate += pHateEntry->m_hateAmount; } - //uint32_t plsBeHatedThisMuchAtLeast = totalHate / ( maxHate + 2 ) / clamp( m_hateList.size(), 1.0f, 1.5f ); + // uint32_t plsBeHatedThisMuchAtLeast = totalHate / ( maxHate + 2 ) / clamp( m_hateList.size(), 1.0f, 1.5f ); for( auto& pHateEntry : m_hateList ) { // todo: this is pure retarded // todo: check for companion - if( pHateEntry->m_pActor->isPlayer() ) // && pHateEntry->m_hateAmount >= plsBeHatedThisMuchAtLeast ) + if( pHateEntry->m_pActor->isPlayer() ) // && pHateEntry->m_hateAmount >= plsBeHatedThisMuchAtLeast ) { uint8_t level = pHateEntry->m_pActor->getLevel(); auto levelDiff = static_cast< int32_t >( this->m_level ) - level; @@ -427,21 +420,26 @@ void Core::Entity::BattleNpc::onDeath() // todo: arbitrary numbers pulled out of my ass if( m_level <= 14 ) - exp = ( expNeeded / ( 100 - levelDiff) ) + cappedLevelDiff + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 9 ) ) + 1 ) ); + exp = ( expNeeded / ( 100 - levelDiff ) ) + cappedLevelDiff + + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 9 ) ) + 1 ) ); else if( m_level <= 24 ) - exp = ( expNeeded / ( 150 - levelDiff) ) + cappedLevelDiff + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 8 ) ) + 1 ) ); + exp = ( expNeeded / ( 150 - levelDiff ) ) + cappedLevelDiff + + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 8 ) ) + 1 ) ); else if( m_level <= 34 ) - exp = ( expNeeded / ( 350 - levelDiff ) ) + cappedLevelDiff + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 7 ) ) + 1 ) ); + exp = ( expNeeded / ( 350 - levelDiff ) ) + cappedLevelDiff + + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 7 ) ) + 1 ) ); else if( m_level <= 44 ) - exp = ( expNeeded / ( 550 - levelDiff ) ) + cappedLevelDiff + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 6 ) ) + 1 ) ); + exp = ( expNeeded / ( 550 - levelDiff ) ) + cappedLevelDiff + + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 6 ) ) + 1 ) ); else if( m_level <= 50 ) - exp = ( expNeeded / ( 750 - levelDiff ) ) + cappedLevelDiff + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 5 ) ) + 1 ) ); + exp = ( expNeeded / ( 750 - levelDiff ) ) + cappedLevelDiff + + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 5 ) ) + 1 ) ); else - exp = ( expNeeded / ( 1200 - levelDiff ) ) + cappedLevelDiff + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 4 ) ) + 1 ) ); - + exp = ( expNeeded / ( 1200 - levelDiff ) ) + cappedLevelDiff + + ( cappedLevelDiff * ( ( rand() % ( cappedLevelDiff * 4 ) ) + 1 ) ); // todo: this is actually retarded, we need real rand() - srand( static_cast< uint32_t > ( time( nullptr ) ) ); + srand( static_cast< uint32_t >( time( nullptr ) ) ); auto pPlayer = pHateEntry->m_pActor->getAsPlayer(); pPlayer->gainExp( exp ); @@ -467,9 +465,8 @@ Core::Entity::ActorPtr Core::Entity::BattleNpc::getClaimer() const return m_pOwner; } - // HACK: this is highly experimental code, will have to be changed eventually -// since there are different types of mobs... (stationary, moving...) likely to be +// since there are different types of mobs... (stationary, moving...) likely to be // handled by scripts entirely. void Core::Entity::BattleNpc::update( int64_t currTime ) { @@ -482,8 +479,7 @@ void Core::Entity::BattleNpc::update( int64_t currTime ) } updateStatusEffects(); - float distance = Math::Util::distance( m_pos.x, m_pos.y, m_pos.z, - m_posOrigin.x, m_posOrigin.y, m_posOrigin.z ); + float distance = Math::Util::distance( m_pos.x, m_pos.y, m_pos.z, m_posOrigin.x, m_posOrigin.y, m_posOrigin.z ); if( ( distance > 70 ) && m_mode != MODE_RETREAT ) { @@ -509,12 +505,10 @@ void Core::Entity::BattleNpc::update( int64_t currTime ) if( pClosestActor && pClosestActor->isAlive() ) { - distance = Math::Util::distance( getPos().x, getPos().y, getPos().z, - pClosestActor->getPos().x, - pClosestActor->getPos().y, - pClosestActor->getPos().z ); + distance = Math::Util::distance( getPos().x, getPos().y, getPos().z, pClosestActor->getPos().x, + pClosestActor->getPos().y, pClosestActor->getPos().z ); - //if( distance < 8 && getbehavior() == 2 ) + // if( distance < 8 && getbehavior() == 2 ) // aggro( pClosestActor ); } } @@ -532,10 +526,8 @@ void Core::Entity::BattleNpc::update( int64_t currTime ) if( pClosestActor != nullptr ) { - distance = Math::Util::distance( getPos().x, getPos().y, getPos().z, - pClosestActor->getPos().x, - pClosestActor->getPos().y, - pClosestActor->getPos().z ); + distance = Math::Util::distance( getPos().x, getPos().y, getPos().z, pClosestActor->getPos().x, + pClosestActor->getPos().y, pClosestActor->getPos().z ); if( distance > 4 ) moveTo( pClosestActor->getPos() ); @@ -554,11 +546,9 @@ void Core::Entity::BattleNpc::update( int64_t currTime ) setOwner( nullptr ); m_mode = MODE_RETREAT; } - } break; } - } uint32_t Core::Entity::BattleNpc::getTimeOfDeath() const @@ -570,4 +560,3 @@ void Core::Entity::BattleNpc::setTimeOfDeath( uint32_t tod ) { m_timeOfDeath = tod; } - diff --git a/src/servers/Server_Zone/Actor/BattleNpc.h b/src/servers/Server_Zone/Actor/BattleNpc.h index 6bc0b93e..edb7fef5 100644 --- a/src/servers/Server_Zone/Actor/BattleNpc.h +++ b/src/servers/Server_Zone/Actor/BattleNpc.h @@ -6,110 +6,108 @@ namespace Core { namespace Entity { -enum StateMode -{ - MODE_COMBAT, - MODE_RETREAT, - MODE_IDLE, -}; + enum StateMode + { + MODE_COMBAT, + MODE_RETREAT, + MODE_IDLE, + }; -typedef struct -{ - uint32_t m_hateAmount; - ActorPtr m_pActor; -} HateListEntry; + typedef struct + { + uint32_t m_hateAmount; + ActorPtr m_pActor; + } HateListEntry; -// class for Mobs inheriting from Actor -class BattleNpc : public Actor -{ -public: - BattleNpc(); - ~BattleNpc(); + // class for Mobs inheriting from Actor + class BattleNpc : public Actor + { + public: + BattleNpc(); + ~BattleNpc(); - BattleNpc( uint16_t modelId, uint16_t nameid, const Common::FFXIVARR_POSITION3& spawnPos, uint16_t bnpcBaseId = 0, - uint32_t type = 2, uint8_t level = 0, uint8_t behaviour = 1, uint32_t mobType = 0 ); + BattleNpc( uint16_t modelId, uint16_t nameid, const Common::FFXIVARR_POSITION3& spawnPos, uint16_t bnpcBaseId = 0, + uint32_t type = 2, uint8_t level = 0, uint8_t behaviour = 1, uint32_t mobType = 0 ); - //BattleNpc( uint32_t modelId, - // uint32_t nameId, - // uint32_t bnpcBaseId, - // uint32_t level, - // const Common::FFXIVARR_POSITION3& spawnPos, - // uint32_t type = 2, uint32_t behaviour = 1, uint32_t mobType = 0 ); + // BattleNpc( uint32_t modelId, + // uint32_t nameId, + // uint32_t bnpcBaseId, + // uint32_t level, + // const Common::FFXIVARR_POSITION3& spawnPos, + // uint32_t type = 2, uint32_t behaviour = 1, uint32_t mobType = 0 ); - void initStatusEffectContainer(); + void initStatusEffectContainer(); - // send spawn packets to pTarget - void spawn( PlayerPtr pTarget ) override; + // send spawn packets to pTarget + void spawn( PlayerPtr pTarget ) override; - // send despawn packets to pTarget - void despawn( ActorPtr pTarget ) override; + // send despawn packets to pTarget + void despawn( ActorPtr pTarget ) override; - uint8_t getLevel() const override; + uint8_t getLevel() const override; - StateMode getMode() const; + StateMode getMode() const; - void setMode( StateMode mode ); + void setMode( StateMode mode ); - uint8_t getbehavior() const; + uint8_t getbehavior() const; - void hateListAdd( ActorPtr pActor, int32_t hateAmount ); + void hateListAdd( ActorPtr pActor, int32_t hateAmount ); - void hateListUpdate( ActorPtr pActor, int32_t hateAmount ); - void hateListRemove( ActorPtr pActor ); + void hateListUpdate( ActorPtr pActor, int32_t hateAmount ); + void hateListRemove( ActorPtr pActor ); - bool hateListHasActor( ActorPtr pActor ); + bool hateListHasActor( ActorPtr pActor ); - void resetPos(); + void resetPos(); - uint32_t getNameId() const; + uint32_t getNameId() const; - void hateListClear(); + void hateListClear(); - ActorPtr hateListGetHighest(); + ActorPtr hateListGetHighest(); - void aggro( ActorPtr pActor ); + void aggro( ActorPtr pActor ); - void deaggro( ActorPtr pActor ); + void deaggro( ActorPtr pActor ); - void setOwner( PlayerPtr pPlayer ); + void setOwner( PlayerPtr pPlayer ); - void onDeath() override; + void onDeath() override; - void onActionHostile( ActorPtr pSource ) override; + void onActionHostile( ActorPtr pSource ) override; - ActorPtr getClaimer() const; + ActorPtr getClaimer() const; - void sendPositionUpdate(); + void sendPositionUpdate(); - // return true if it reached the position - bool moveTo( Common::FFXIVARR_POSITION3& pos ); + // return true if it reached the position + bool moveTo( Common::FFXIVARR_POSITION3& pos ); - void update( int64_t currTime ) override; + void update( int64_t currTime ) override; - uint32_t getTimeOfDeath() const; + uint32_t getTimeOfDeath() const; - void setTimeOfDeath( uint32_t tod ); + void setTimeOfDeath( uint32_t tod ); -private: + private: + static uint32_t m_nextID; + StateMode m_mode; + Common::FFXIVARR_POSITION3 m_posOrigin; + uint8_t m_level; + uint16_t m_modelId; + uint16_t m_nameId; + uint16_t m_bnpcBaseId; + uint8_t m_behavior; + uint32_t m_unk1; + uint32_t m_unk2; + std::set< HateListEntry* > m_hateList; + ActorPtr m_pOwner; + uint32_t m_timeOfDeath; + uint32_t m_mobType; + }; - static uint32_t m_nextID; - StateMode m_mode; - Common::FFXIVARR_POSITION3 m_posOrigin; - uint8_t m_level; - uint16_t m_modelId; - uint16_t m_nameId; - uint16_t m_bnpcBaseId; - uint8_t m_behavior; - uint32_t m_unk1; - uint32_t m_unk2; - std::set< HateListEntry* > m_hateList; - ActorPtr m_pOwner; - uint32_t m_timeOfDeath; - uint32_t m_mobType; - -}; - -} -} +} // namespace Entity +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Actor/BattleNpcTemplate.cpp b/src/servers/Server_Zone/Actor/BattleNpcTemplate.cpp index 62c21ab1..cac0675e 100644 --- a/src/servers/Server_Zone/Actor/BattleNpcTemplate.cpp +++ b/src/servers/Server_Zone/Actor/BattleNpcTemplate.cpp @@ -2,23 +2,20 @@ Core::Entity::BattleNpcTemplate::BattleNpcTemplate() { - } -Core::Entity::BattleNpcTemplate::BattleNpcTemplate( std::string templateName, uint32_t bnpcBaseId, - uint32_t bnpcNameId, uint32_t modelId, std::string aiName ) : - m_templateName( templateName ), - m_bnpcBaseId( bnpcBaseId ), - m_bnpcNameId( bnpcNameId ), - m_modelId( modelId ), - m_aiName( aiName ) +Core::Entity::BattleNpcTemplate::BattleNpcTemplate( std::string templateName, uint32_t bnpcBaseId, uint32_t bnpcNameId, + uint32_t modelId, std::string aiName ) : + m_templateName( templateName ), + m_bnpcBaseId( bnpcBaseId ), + m_bnpcNameId( bnpcNameId ), + m_modelId( modelId ), + m_aiName( aiName ) { - } Core::Entity::BattleNpcTemplate::~BattleNpcTemplate() { - } uint32_t Core::Entity::BattleNpcTemplate::getBnpcBaseId() const diff --git a/src/servers/Server_Zone/Actor/BattleNpcTemplate.h b/src/servers/Server_Zone/Actor/BattleNpcTemplate.h index 07e8f5b9..1da37b67 100644 --- a/src/servers/Server_Zone/Actor/BattleNpcTemplate.h +++ b/src/servers/Server_Zone/Actor/BattleNpcTemplate.h @@ -14,7 +14,8 @@ namespace Entity { { public: BattleNpcTemplate(); - BattleNpcTemplate( std::string templateName, uint32_t bnpcBaseId, uint32_t bnpcNameId, uint32_t modelId, std::string aiName ); + BattleNpcTemplate( std::string templateName, uint32_t bnpcBaseId, uint32_t bnpcNameId, uint32_t modelId, + std::string aiName ); ~BattleNpcTemplate(); @@ -28,11 +29,9 @@ namespace Entity { uint32_t m_bnpcBaseId = 0; uint32_t m_bnpcNameId = 0; uint32_t m_modelId = 0; - - }; -} -} +} // namespace Entity +} // namespace Core #endif \ No newline at end of file diff --git a/src/servers/Server_Zone/Actor/Player.cpp b/src/servers/Server_Zone/Actor/Player.cpp index 0d12b440..8b5cb9bf 100644 --- a/src/servers/Server_Zone/Actor/Player.cpp +++ b/src/servers/Server_Zone/Actor/Player.cpp @@ -1,45 +1,45 @@ #include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include "Session.h" -#include "Player.h" #include "BattleNpc.h" +#include "Player.h" +#include "Session.h" -#include "Zone/ZoneMgr.h" #include "Zone/Zone.h" +#include "Zone/ZoneMgr.h" #include "ServerZone.h" #include "Network/GameConnection.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" -#include "Network/PacketWrappers/InitUIPacket.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" -#include "Network/PacketWrappers/ChatPacket.h" -#include "Network/PacketWrappers/ModelEquipPacket.h" #include "Network/PacketWrappers/ActorSpawnPacket.h" -#include "Network/PacketWrappers/UpdateHpMpTpPacket.h" -#include "Network/PacketWrappers/PlayerStateFlagsPacket.h" +#include "Network/PacketWrappers/ChatPacket.h" +#include "Network/PacketWrappers/InitUIPacket.h" +#include "Network/PacketWrappers/ModelEquipPacket.h" #include "Network/PacketWrappers/PlayerSpawnPacket.h" +#include "Network/PacketWrappers/PlayerStateFlagsPacket.h" +#include "Network/PacketWrappers/ServerNoticePacket.h" +#include "Network/PacketWrappers/UpdateHpMpTpPacket.h" #include "Script/ScriptManager.h" #include "Inventory/Item.h" -#include "Inventory/Inventory.h" -#include "Event/Event.h" #include "Action/Action.h" #include "Action/EventAction.h" #include "Action/EventItemAction.h" -#include "Zone/ZonePosition.h" -#include "Math/CalcStats.h" +#include "Event/Event.h" +#include "Inventory/Inventory.h" #include "Math/CalcBattle.h" +#include "Math/CalcStats.h" +#include "Zone/ZonePosition.h" #include extern Core::Logger g_log; @@ -54,24 +54,24 @@ using namespace Core::Network::Packets::Server; // player constructor Core::Entity::Player::Player() : - Actor(), - m_lastWrite( 0 ), - m_lastPing( 0 ), - m_bIsLogin( false ), - m_contentId( 0 ), - m_modelMainWeapon( 0 ), - m_modelSubWeapon( 0 ), - m_homePoint( 0 ), - m_startTown( 0 ), - m_townWarpFstFlags( 0 ), - m_playTime( 0 ), - m_bInCombat( false ), - m_bLoadingComplete( false ), - m_bMarkedForZoning( false ), - m_zoningType( Common::ZoneingType::None ), - m_bAutoattack( false ), - m_markedForRemoval( false ), - m_mount( 0 ) + Actor(), + m_lastWrite( 0 ), + m_lastPing( 0 ), + m_bIsLogin( false ), + m_contentId( 0 ), + m_modelMainWeapon( 0 ), + m_modelSubWeapon( 0 ), + m_homePoint( 0 ), + m_startTown( 0 ), + m_townWarpFstFlags( 0 ), + m_playTime( 0 ), + m_bInCombat( false ), + m_bLoadingComplete( false ), + m_bMarkedForZoning( false ), + m_zoningType( Common::ZoneingType::None ), + m_bAutoattack( false ), + m_markedForRemoval( false ), + m_mount( 0 ) { m_id = 0; m_objKind = ObjKind::Player; @@ -157,7 +157,7 @@ Core::Common::OnlineStatus Core::Entity::Player::getOnlineStatus() OnlineStatus status = OnlineStatus::Online; - //if( hasStateFlag( Common::PlayerStateFlag::NewAdventurer ) ) + // if( hasStateFlag( Common::PlayerStateFlag::NewAdventurer ) ) if( m_onlineStatus & newMask ) status = OnlineStatus::NewAdventurer; @@ -182,7 +182,8 @@ Core::Common::OnlineStatus Core::Entity::Player::getOnlineStatus() if( hasStateFlag( PlayerStateFlag::WatchingCutscene ) || hasStateFlag( PlayerStateFlag::WatchingCutscene1 ) ) status = OnlineStatus::ViewingCutscene; - // TODO: add all the logic for returning the proper online status, there probably is a better way for this alltogether + // TODO: add all the logic for returning the proper online status, there probably is a better way for this + // alltogether return status; } @@ -216,8 +217,7 @@ void Core::Entity::Player::calculateStats() auto tribeInfoIt = g_exdData.m_tribeInfoMap.find( tribe ); auto paramGrowthInfoIt = g_exdData.m_paramGrowthInfoMap.find( level ); - if( tribeInfoIt == g_exdData.m_tribeInfoMap.end() || - classInfoIt == g_exdData.m_classJobInfoMap.end() || + if( tribeInfoIt == g_exdData.m_tribeInfoMap.end() || classInfoIt == g_exdData.m_classJobInfoMap.end() || paramGrowthInfoIt == g_exdData.m_paramGrowthInfoMap.end() ) return; @@ -228,20 +228,26 @@ void Core::Entity::Player::calculateStats() // TODO: put formula somewhere else... float base = Math::CalcStats::calculateBaseStat( getAsPlayer() ); - m_baseStats.str = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_str ) / 100 ) + tribeInfo.mod_str ); - m_baseStats.dex = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_dex ) / 100 ) + tribeInfo.mod_dex ); - m_baseStats.vit = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_vit ) / 100 ) + tribeInfo.mod_vit ); - m_baseStats.inte = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_int ) / 100 ) + tribeInfo.mod_int ); - m_baseStats.mnd = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_mnd ) / 100 ) + tribeInfo.mod_mnd ); - m_baseStats.pie = static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_pie ) / 100 ) + tribeInfo.mod_pie ); + m_baseStats.str = + static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_str ) / 100 ) + tribeInfo.mod_str ); + m_baseStats.dex = + static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_dex ) / 100 ) + tribeInfo.mod_dex ); + m_baseStats.vit = + static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_vit ) / 100 ) + tribeInfo.mod_vit ); + m_baseStats.inte = + static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_int ) / 100 ) + tribeInfo.mod_int ); + m_baseStats.mnd = + static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_mnd ) / 100 ) + tribeInfo.mod_mnd ); + m_baseStats.pie = + static_cast< uint32_t >( base * ( static_cast< float >( classInfo.mod_pie ) / 100 ) + tribeInfo.mod_pie ); - m_baseStats.skillSpeed = paramGrowthInfo.base_secondary; - m_baseStats.spellSpeed = paramGrowthInfo.base_secondary; - m_baseStats.accuracy = paramGrowthInfo.base_secondary; - m_baseStats.critHitRate = paramGrowthInfo.base_secondary; - m_baseStats.attackPotMagic = paramGrowthInfo.base_secondary; + m_baseStats.skillSpeed = paramGrowthInfo.base_secondary; + m_baseStats.spellSpeed = paramGrowthInfo.base_secondary; + m_baseStats.accuracy = paramGrowthInfo.base_secondary; + m_baseStats.critHitRate = paramGrowthInfo.base_secondary; + m_baseStats.attackPotMagic = paramGrowthInfo.base_secondary; m_baseStats.healingPotMagic = paramGrowthInfo.base_secondary; - m_baseStats.tenacity = paramGrowthInfo.base_secondary; + m_baseStats.tenacity = paramGrowthInfo.base_secondary; m_baseStats.max_mp = Math::CalcStats::calculateMaxMp( getAsPlayer() ); @@ -253,13 +259,10 @@ void Core::Entity::Player::calculateStats() if( m_hp > m_baseStats.max_hp ) m_hp = m_baseStats.max_hp; - m_baseStats.determination = static_cast< uint32_t >( base ); - } - -void Core::Entity::Player::setAutoattack(bool mode) +void Core::Entity::Player::setAutoattack( bool mode ) { m_bAutoattack = mode; m_lastAttack = Util::getTimeMs(); @@ -325,8 +328,8 @@ void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type ) rot = z_pos->getTargetRotation(); } - sendDebug( "Teleport: " + data->placename + " " + data->placename_aethernet + - "(" + std::to_string( data->levelId ) + ")" ); + sendDebug( "Teleport: " + data->placename + " " + data->placename_aethernet + "(" + std::to_string( data->levelId ) + + ")" ); // TODO: this should be simplified and a type created in server_common/common.h. if( type == 1 ) // teleport @@ -349,14 +352,12 @@ void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type ) } m_queuedZoneing = boost::make_shared< QueuedZoning >( data->target_zone, pos, Util::getTimeMs(), rot ); - - } void Core::Entity::Player::forceZoneing( uint32_t zoneId ) { m_queuedZoneing = boost::make_shared< QueuedZoning >( zoneId, getPos(), Util::getTimeMs(), 0.f ); - //performZoning( zoneId, Common::ZoneingType::None, getPos() ); + // performZoning( zoneId, Common::ZoneingType::None, getPos() ); } void Core::Entity::Player::returnToHomepoint() @@ -371,7 +372,6 @@ void Core::Entity::Player::setZone( uint32_t zoneId ) auto pZone = g_zoneMgr.getZone( zoneId ); - if( !pZone /*|| ( ( pZone == m_pCurrentZone ) && m_lastPing )*/ ) { g_log.error( "Zone " + std::to_string( zoneId ) + " not found on this server." ); @@ -397,7 +397,7 @@ void Core::Entity::Player::setZone( uint32_t zoneId ) if( isLogin() ) { - queuePacket(ActorControlPacket143( getId(), SetCharaGearParamUI, m_equipDisplayFlags, 1 ) ); + queuePacket( ActorControlPacket143( getId(), SetCharaGearParamUI, m_equipDisplayFlags, 1 ) ); } // set flags, will be reset automatically by zoning ( only on client side though ) @@ -517,7 +517,6 @@ void Core::Entity::Player::registerAetheryte( uint8_t aetheryteId ) m_aetheryte[index] |= value; queuePacket( ActorControlPacket143( getId(), LearnTeleport, aetheryteId, 1 ) ); - } bool Core::Entity::Player::isAetheryteRegistered( uint8_t aetheryteId ) const @@ -529,7 +528,7 @@ bool Core::Entity::Player::isAetheryteRegistered( uint8_t aetheryteId ) const return ( m_aetheryte[index] & value ) != 0; } -uint8_t * Core::Entity::Player::getDiscoveryBitmask() +uint8_t* Core::Entity::Player::getDiscoveryBitmask() { return m_discovery; } @@ -561,9 +560,6 @@ void Core::Entity::Player::discover( int16_t map_id, int16_t sub_id ) uint32_t exp = ( g_exdData.m_paramGrowthInfoMap[level].needed_exp * 5 / 100 ); gainExp( exp ); - - - } bool Core::Entity::Player::isNewAdventurer() const @@ -573,11 +569,11 @@ bool Core::Entity::Player::isNewAdventurer() const void Core::Entity::Player::setNewAdventurer( bool state ) { - //if( !state ) + // if( !state ) //{ // unsetStateFlag( PlayerStateFlag::NewAdventurer ); //} - //else + // else //{ // setStateFlag( PlayerStateFlag::NewAdventurer ); //} @@ -596,7 +592,7 @@ void Core::Entity::Player::changePosition( float x, float y, float z, float o ) pos.x = x; pos.y = y; pos.z = z; - m_queuedZoneing = boost::make_shared( getZoneId(), pos, Util::getTimeMs(), o ); + m_queuedZoneing = boost::make_shared< QueuedZoning >( getZoneId(), pos, Util::getTimeMs(), o ); } void Core::Entity::Player::learnAction( uint8_t actionId ) @@ -652,16 +648,16 @@ void Core::Entity::Player::gainExp( uint32_t amount ) { // levelup amount = ( currentExp + amount - neededExpToLevel ) > neededExpToLevelplus1 ? - neededExpToLevelplus1 - 1 : - ( currentExp + amount - neededExpToLevel ); + neededExpToLevelplus1 - 1 : + ( currentExp + amount - neededExpToLevel ); setExp( amount ); gainLevel(); queuePacket( ActorControlPacket143( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), amount ) ); - } else { - queuePacket( ActorControlPacket143( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), currentExp + amount ) ); + queuePacket( + ActorControlPacket143( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), currentExp + amount ) ); setExp( currentExp + amount ); } @@ -680,8 +676,8 @@ void Core::Entity::Player::gainLevel() m_mp = getMaxMp(); ZoneChannelPacket< FFXIVIpcStatusEffectList > effectListPacket( getId() ); - effectListPacket.data().classId = static_cast< uint8_t > ( getClass() ); - effectListPacket.data().classId1 = static_cast< uint8_t > ( getClass() ); + effectListPacket.data().classId = static_cast< uint8_t >( getClass() ); + effectListPacket.data().classId1 = static_cast< uint8_t >( getClass() ); effectListPacket.data().level = getLevel(); effectListPacket.data().current_hp = getMaxHp(); effectListPacket.data().current_mp = getMaxMp(); @@ -690,18 +686,17 @@ void Core::Entity::Player::gainLevel() effectListPacket.data().max_mp = getMaxMp(); sendToInRangeSet( effectListPacket, true ); - sendToInRangeSet( ActorControlPacket142( getId(), LevelUpEffect, static_cast< uint8_t >( getClass() ), - getLevel(), getLevel() - 1 ), true ); - + sendToInRangeSet( ActorControlPacket142( getId(), LevelUpEffect, static_cast< uint8_t >( getClass() ), getLevel(), + getLevel() - 1 ), + true ); ZoneChannelPacket< FFXIVIpcUpdateClassInfo > classInfoPacket( getId() ); - classInfoPacket.data().classId = static_cast< uint8_t > ( getClass() ); - classInfoPacket.data().classId1 = static_cast< uint8_t > ( getClass() ); + classInfoPacket.data().classId = static_cast< uint8_t >( getClass() ); + classInfoPacket.data().classId1 = static_cast< uint8_t >( getClass() ); classInfoPacket.data().level = getLevel(); classInfoPacket.data().nextLevelIndex = getLevel(); classInfoPacket.data().currentExp = getExp(); queuePacket( classInfoPacket ); - } void Core::Entity::Player::unlock() @@ -713,7 +708,7 @@ void Core::Entity::Player::sendStatusUpdate( bool toSelf ) { // CGamePacket* pPE = new CGamePacket(0x140, 0x0128, getId(), getId()); - //pPE->setInt8At(0x20, static_cast(getClass())); + // pPE->setInt8At(0x20, static_cast(getClass())); // pPE->setInt8At(0x21, getLevel()); // pPE->setInt8At(0x22, getLevel()); @@ -733,7 +728,6 @@ void Core::Entity::Player::sendStatusUpdate( bool toSelf ) // sendToInRangeSet(pPE, toSelf); sendToInRangeSet( UpdateHpMpTpPacket( shared_from_this() ), true ); - } uint8_t Core::Entity::Player::getLevel() const @@ -767,7 +761,7 @@ bool Core::Entity::Player::isInCombat() const void Core::Entity::Player::setInCombat( bool mode ) { - //m_lastAttack = GetTickCount(); + // m_lastAttack = GetTickCount(); m_bInCombat = mode; } @@ -796,14 +790,15 @@ void Core::Entity::Player::setClassJob( Common::ClassJob classJob ) void Core::Entity::Player::setLevel( uint8_t level ) { - uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( static_cast< uint8_t >( getClass() ) )].exp_idx; + uint8_t classJobIndex = + g_exdData.m_classJobInfoMap[static_cast< uint8_t >( static_cast< uint8_t >( getClass() ) )].exp_idx; m_classArray[classJobIndex] = level; } void Core::Entity::Player::setLevelForClass( uint8_t level, Common::ClassJob classjob ) { - uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( classjob )].exp_idx; - m_classArray[classJobIndex] = level; + uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( classjob )].exp_idx; + m_classArray[classJobIndex] = level; } void Core::Entity::Player::sendModel() @@ -872,9 +867,7 @@ void Core::Entity::Player::setLookAt( uint8_t index, uint8_t value ) // spawn this player for pTarget void Core::Entity::Player::spawn( Entity::PlayerPtr pTarget ) { - g_log.debug( "[" + std::to_string( pTarget->getId() ) + "] Spawning " + - getName() + " for " + - pTarget->getName() ); + g_log.debug( "[" + std::to_string( pTarget->getId() ) + "] Spawning " + getName() + " for " + pTarget->getName() ); PlayerSpawnPacket spawnActor( *getAsPlayer(), *pTarget ); pTarget->queuePacket( spawnActor ); @@ -946,14 +939,13 @@ const uint8_t* Core::Entity::Player::getStateFlags() const return m_stateFlags; } -bool Core::Entity::Player::actionHasCastTime( uint32_t actionId ) //TODO: Add logic for special cases +bool Core::Entity::Player::actionHasCastTime( uint32_t actionId ) // TODO: Add logic for special cases { auto actionInfoPtr = g_exdData.getActionInfo( actionId ); if( actionInfoPtr->is_instant ) return false; return actionInfoPtr->cast_time != 0; - } bool Core::Entity::Player::hasStateFlag( Common::PlayerStateFlag flag ) const @@ -976,7 +968,6 @@ void Core::Entity::Player::setStateFlag( Common::PlayerStateFlag flag ) Util::valueToFlagByteIndexValue( iFlag, value, index ); m_stateFlags[index] |= value; - } void Core::Entity::Player::setStateFlags( std::vector< Common::PlayerStateFlag > flags ) @@ -1010,7 +1001,6 @@ void Core::Entity::Player::unsetStateFlag( Common::PlayerStateFlag flag ) Util::valueToFlagByteIndexValue( iFlag, value, index ); m_stateFlags[index] ^= value; - } void Core::Entity::Player::update( int64_t currTime ) @@ -1022,7 +1012,7 @@ void Core::Entity::Player::update( int64_t currTime ) Common::FFXIVARR_POSITION3 targetPos = m_queuedZoneing->m_targetPosition; if( getCurrentZone()->getId() != m_queuedZoneing->m_targetZone ) { - performZoning( m_queuedZoneing->m_targetZone, targetPos, m_queuedZoneing->m_targetRotation); + performZoning( m_queuedZoneing->m_targetZone, targetPos, m_queuedZoneing->m_targetRotation ); } else { @@ -1055,7 +1045,8 @@ void Core::Entity::Player::update( int64_t currTime ) { auto mainWeap = m_pInventory->getItemAt( Inventory::GearSet0, Inventory::EquipSlot::MainHand ); - // @TODO i dislike this, iterating over all in range actors when you already know the id of the actor you need... + // @TODO i dislike this, iterating over all in range actors when you already know the id of the actor you + // need... for( auto actor : m_inRangeActors ) { if( actor->getId() == m_targetId && actor->isAlive() && mainWeap ) @@ -1065,14 +1056,11 @@ void Core::Entity::Player::update( int64_t currTime ) uint32_t range = 7; // default autoattack range for ranged classes - if( getClass() == ClassJob::Machinist || - getClass() == ClassJob::Bard || - getClass() == ClassJob::Archer ) + if( getClass() == ClassJob::Machinist || getClass() == ClassJob::Bard || getClass() == ClassJob::Archer ) range = 25; - - if( Math::Util::distance(getPos().x, getPos().y, getPos().z, - actor->getPos().x, actor->getPos().y, actor->getPos().z) <= range ) + if( Math::Util::distance( getPos().x, getPos().y, getPos().z, actor->getPos().x, actor->getPos().y, + actor->getPos().z ) <= range ) { if( ( currTime - m_lastAttack ) > mainWeap->getDelay() ) @@ -1080,7 +1068,6 @@ void Core::Entity::Player::update( int64_t currTime ) m_lastAttack = currTime; autoAttack( actor ); } - } } } @@ -1111,10 +1098,9 @@ void Core::Entity::Player::freePlayerSpawnId( uint32_t actorId ) freeActorSpawnPacket.data().actorId = actorId; freeActorSpawnPacket.data().spawnId = spawnId; queuePacket( freeActorSpawnPacket ); - } -uint8_t * Core::Entity::Player::getAetheryteArray() +uint8_t* Core::Entity::Player::getAetheryteArray() { return m_aetheryte; } @@ -1219,7 +1205,6 @@ void Core::Entity::Player::queuePacket( Network::Packets::GamePacketPtr pPacket if( pZoneCon ) pZoneCon->queueOutPacket( pPacket ); - } void Core::Entity::Player::queueChatPacket( Network::Packets::GamePacketPtr pPacket ) @@ -1245,7 +1230,7 @@ void Core::Entity::Player::setLoadingComplete( bool bComplete ) m_bLoadingComplete = bComplete; } -void Core::Entity::Player::performZoning( uint16_t zoneId, const Common::FFXIVARR_POSITION3 &pos, float rotation ) +void Core::Entity::Player::performZoning( uint16_t zoneId, const Common::FFXIVARR_POSITION3& pos, float rotation ) { m_pos = pos; m_zoneId = zoneId; @@ -1292,17 +1277,17 @@ uint8_t Core::Entity::Player::getSearchSelectClass() const return m_searchSelectClass; } -void Core::Entity::Player::sendNotice( const std::string& message ) //Purple Text +void Core::Entity::Player::sendNotice( const std::string& message ) // Purple Text { queuePacket( ServerNoticePacket( getId(), message ) ); } -void Core::Entity::Player::sendUrgent( const std::string& message ) //Red Text +void Core::Entity::Player::sendUrgent( const std::string& message ) // Red Text { queuePacket( ChatPacket( *getAsPlayer(), ChatType::ServerUrgent, message ) ); } -void Core::Entity::Player::sendDebug( const std::string& message ) //Grey Text +void Core::Entity::Player::sendDebug( const std::string& message ) // Grey Text { queuePacket( ChatPacket( *getAsPlayer(), ChatType::ServerDebug, message ) ); } @@ -1317,7 +1302,6 @@ void Core::Entity::Player::updateHowtosSeen( uint32_t howToId ) m_howTo[index] |= value; } - void Core::Entity::Player::onMobAggro( BattleNpcPtr pBNpc ) { hateListAdd( pBNpc ); @@ -1342,7 +1326,6 @@ void Core::Entity::Player::hateListAdd( BattleNpcPtr pBNpc ) m_freeHateSlotQueue.pop(); m_actorIdTohateSlotMap[pBNpc->getId()] = hateId; sendHateList(); - } void Core::Entity::Player::hateListRemove( BattleNpcPtr pBNpc ) @@ -1430,7 +1413,7 @@ void Core::Entity::Player::setTitle( uint16_t titleId ) uint8_t value; Util::valueToFlagByteIndexValue( titleId, value, index ); - if ( ( m_titleList[index] & value ) == 0 ) // Player doesn't have title - bail + if( ( m_titleList[index] & value ) == 0 ) // Player doesn't have title - bail return; m_activeTitle = titleId; @@ -1454,7 +1437,9 @@ uint8_t Core::Entity::Player::getEquipDisplayFlags() const void Core::Entity::Player::mount( uint32_t id ) { m_mount = id; - sendToInRangeSet( ActorControlPacket142( getId(), ActorControlType::SetStatus, static_cast< uint8_t >( Entity::Actor::ActorStatus::Mounted )), true ); + sendToInRangeSet( ActorControlPacket142( getId(), ActorControlType::SetStatus, + static_cast< uint8_t >( Entity::Actor::ActorStatus::Mounted ) ), + true ); sendToInRangeSet( ActorControlPacket143( getId(), 0x39e, 12 ), true ); //? ZoneChannelPacket< FFXIVIpcMount > mountPacket( getId() ); @@ -1465,7 +1450,8 @@ void Core::Entity::Player::mount( uint32_t id ) void Core::Entity::Player::dismount() { sendToInRangeSet( ActorControlPacket142( getId(), ActorControlType::SetStatus, - static_cast< uint8_t >( Entity::Actor::ActorStatus::Idle )), true ); + static_cast< uint8_t >( Entity::Actor::ActorStatus::Idle ) ), + true ); sendToInRangeSet( ActorControlPacket143( getId(), ActorControlType::Dismount, 1 ), true ); m_mount = 0; } @@ -1478,29 +1464,26 @@ uint8_t Core::Entity::Player::getCurrentMount() const void Core::Entity::Player::autoAttack( ActorPtr pTarget ) { - auto mainWeap = m_pInventory->getItemAt( Inventory::GearSet0, - Inventory::EquipSlot::MainHand ); + auto mainWeap = m_pInventory->getItemAt( Inventory::GearSet0, Inventory::EquipSlot::MainHand ); pTarget->onActionHostile( shared_from_this() ); - //uint64_t tick = Util::getTimeMs(); - //srand(static_cast< uint32_t >(tick)); + // uint64_t tick = Util::getTimeMs(); + // srand(static_cast< uint32_t >(tick)); uint32_t damage = static_cast< uint32_t >( mainWeap->getAutoAttackDmg() ); uint32_t variation = 0 + rand() % 3; - if( getClass() == ClassJob::Machinist || - getClass() == ClassJob::Bard || - getClass() == ClassJob::Archer ) + if( getClass() == ClassJob::Machinist || getClass() == ClassJob::Bard || getClass() == ClassJob::Archer ) { - ZoneChannelPacket< FFXIVIpcEffect > effectPacket(getId()); + ZoneChannelPacket< FFXIVIpcEffect > effectPacket( getId() ); effectPacket.data().targetId = pTarget->getId(); effectPacket.data().actionAnimationId = 8; - // effectPacket.data().unknown_2 = variation; + // effectPacket.data().unknown_2 = variation; effectPacket.data().numEffects = 1; effectPacket.data().unknown_61 = 1; effectPacket.data().unknown_62 = 1; effectPacket.data().actionTextId = 8; - effectPacket.data().rotation = Math::Util::floatToUInt16Rot(getRotation()); + effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRotation() ); effectPacket.data().effectTargetId = pTarget->getId(); effectPacket.data().effectTarget = pTarget->getId(); effectPacket.data().effects[0].value = damage; @@ -1508,12 +1491,12 @@ void Core::Entity::Player::autoAttack( ActorPtr pTarget ) effectPacket.data().effects[0].hitSeverity = Common::ActionHitSeverityType::NormalDamage; effectPacket.data().effects[0].unknown_3 = 7; - sendToInRangeSet(effectPacket, true); + sendToInRangeSet( effectPacket, true ); } else { - ZoneChannelPacket< FFXIVIpcEffect > effectPacket(getId()); + ZoneChannelPacket< FFXIVIpcEffect > effectPacket( getId() ); effectPacket.data().targetId = pTarget->getId(); effectPacket.data().actionAnimationId = 7; // effectPacket.data().unknown_2 = variation; @@ -1521,21 +1504,19 @@ void Core::Entity::Player::autoAttack( ActorPtr pTarget ) effectPacket.data().unknown_61 = 1; effectPacket.data().unknown_62 = 1; effectPacket.data().actionTextId = 7; - effectPacket.data().rotation = Math::Util::floatToUInt16Rot(getRotation()); + effectPacket.data().rotation = Math::Util::floatToUInt16Rot( getRotation() ); effectPacket.data().effectTarget = pTarget->getId(); effectPacket.data().effects[0].value = damage; effectPacket.data().effects[0].effectType = Common::ActionEffectType::Damage; effectPacket.data().effects[0].hitSeverity = Common::ActionHitSeverityType::NormalDamage; effectPacket.data().effects[0].unknown_3 = 71; - sendToInRangeSet(effectPacket, true); + sendToInRangeSet( effectPacket, true ); } - pTarget->takeDamage(damage); - + pTarget->takeDamage( damage ); } - ///////////////////////////// // Content Finder ///////////////////////////// @@ -1559,7 +1540,7 @@ uint32_t Core::Entity::Player::getCFPenaltyMinutes() const return 0; auto deltaTime = endTimestamp - currentTimestamp; - return static_cast< uint32_t > ( ceil( static_cast< float > (deltaTime) / 60 ) ); + return static_cast< uint32_t >( ceil( static_cast< float >( deltaTime ) / 60 ) ); } void Core::Entity::Player::setCFPenaltyMinutes( uint32_t minutes ) @@ -1587,7 +1568,7 @@ uint16_t Core::Entity::Player::getItemLevel() const void Core::Entity::Player::setEorzeaTimeOffset( uint64_t timestamp ) { // TODO: maybe change to persistent? - ZoneChannelPacket< FFXIVIpcEorzeaTimeOffset > packet ( getId() ); + ZoneChannelPacket< FFXIVIpcEorzeaTimeOffset > packet( getId() ); packet.data().timestamp = timestamp; // Send to single player diff --git a/src/servers/Server_Zone/Actor/Player.h b/src/servers/Server_Zone/Actor/Player.h index a7b7400b..de4aea81 100644 --- a/src/servers/Server_Zone/Actor/Player.h +++ b/src/servers/Server_Zone/Actor/Player.h @@ -14,635 +14,635 @@ namespace Core { namespace Entity { -struct QueuedZoning -{ - uint16_t m_targetZone; - Common::FFXIVARR_POSITION3 m_targetPosition; - float m_targetRotation; - uint64_t m_queueTime; - - QueuedZoning( uint16_t targetZone, const Common::FFXIVARR_POSITION3& targetPosition, uint64_t queuedTime, float targetRotation ) - : m_targetZone( targetZone ) - , m_targetPosition( targetPosition ) - , m_queueTime( queuedTime ) - , m_targetRotation( targetRotation ) {} -}; - -/** Class representing the Player -* Inheriting from Actor -* -*/ -class Player : public Actor -{ -public: - /*! Contructor */ - Player(); - - /*! Destructor */ - ~Player(); - - void autoAttack( ActorPtr pTarget ) override; - - // EventHandlers - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! start an event action */ - void eventActionStart( uint32_t eventId, uint32_t action, ActionCallback finishCallback, ActionCallback interruptCallback, uint64_t additional ); - /*! start an event item action */ - void eventItemActionStart( uint32_t eventId, uint32_t action, ActionCallback finishCallback, ActionCallback interruptCallback, uint64_t additional ); - /*! start/register a normal event */ - void eventStart( uint64_t actorId, uint32_t eventId, uint8_t eventParam, uint8_t eventParam1, uint32_t eventParam2 ); - /*! play a subevent */ - void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, uint32_t eventParam2, uint32_t eventParam3 ); - /*! play a subevent */ - void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, - uint32_t eventParam2, uint32_t eventParam3, Scripting::EventReturnCallback eventReturnCallback ); - /*! play a subevent */ - void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, - uint32_t eventParam2, uint32_t eventParam3, uint32_t eventParam4, Scripting::EventReturnCallback eventReturnCallback ); - /*! play a subevent */ - void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, Scripting::EventReturnCallback eventReturnCallback ); - /*! play a subevent */ - void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags ); - /*! finish / unregister an event */ - void eventFinish( uint32_t eventId, uint32_t freePlayer ); - /*! add an event to the event array */ - void addEvent( Event::EventPtr pEvent ); - /*! retrieve an event from the event array */ - Event::EventPtr getEvent( uint32_t eventId ); - /*! get number of active events */ - size_t getEventCount(); - /*! remove an event from the event array */ - void removeEvent( uint32_t eventId ); - /*! return the eventlist */ - std::map< uint32_t, Event::EventPtr >& eventList(); - - void checkEvent( uint32_t eventId ); - - - - // Events - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! Event to be called when zoning process gets triggered */ - void onZoneStart(); - /*! Event to be called when zoning process is finished */ - void onZoneDone(); - /*! Event to be called on login */ - void onLogin(); - /*! Event to be called on update tick */ - void onTick() override; - /*! Event to be called upon player death */ - void onDeath() override; - /*! Event called on every session iteration */ - void update( int64_t currTime ) override; - /*! Event to be called upon Bnpc kill */ - void onMobKill( uint16_t nameId ); - - - // Quest - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! load data for currently active quests */ - bool loadActiveQuests(); - /*! update quest ( register it as active quest if new ) */ - void updateQuest( uint16_t questId, uint8_t sequence ); - /*! return true if quest is currently active */ - bool hasQuest( uint16_t questId ); - /*! return the current quest sequence */ - uint8_t getQuestSeq( uint16_t questId ); - /*! send the quest tracker packet */ - void sendQuestTracker(); - /*! set quest tracker flag for a specified slot */ - void setQuestTracker( uint16_t index, int16_t flag ); - /*! return the index of a given quest in the players quest list */ - int8_t getQuestIndex( uint16_t questId ); - /*! finish a given quest */ - void finishQuest( uint16_t questId ); - /*! finish a given quest */ - void unfinishQuest( uint16_t questId ); - /*! remove a given quest */ - void removeQuest( uint16_t questId ); - /*! add a quest to the completed quests mask */ - void updateQuestsCompleted( uint32_t questId ); - /*! remove a quest from the completed quest mask */ - void removeQuestsCompleted( uint32_t questId ); - /*! get the curent opening sequence */ - uint8_t getOpeningSequence() const; - /*! set te current opening sequence */ - void setOpeningSequence( uint8_t seq ); - - bool giveQuestRewards( uint32_t questId, uint32_t optionalChoice ); - - boost::shared_ptr< Common::QuestActive > getQuestActive( uint16_t index ); - - uint8_t getQuestUI8A( uint16_t questId ); - uint8_t getQuestUI8B( uint16_t questId ); - uint8_t getQuestUI8C( uint16_t questId ); - uint8_t getQuestUI8D( uint16_t questId ); - uint8_t getQuestUI8E( uint16_t questId ); - uint8_t getQuestUI8F( uint16_t questId ); - uint8_t getQuestUI8AH( uint16_t questId ); - uint8_t getQuestUI8BH( uint16_t questId ); - uint8_t getQuestUI8CH( uint16_t questId ); - uint8_t getQuestUI8DH( uint16_t questId ); - uint8_t getQuestUI8EH( uint16_t questId ); - uint8_t getQuestUI8FH( uint16_t questId ); - uint8_t getQuestUI8AL( uint16_t questId ); - uint8_t getQuestUI8BL( uint16_t questId ); - uint8_t getQuestUI8CL( uint16_t questId ); - uint8_t getQuestUI8DL( uint16_t questId ); - uint8_t getQuestUI8EL( uint16_t questId ); - uint8_t getQuestUI8FL( uint16_t questId ); - uint16_t getQuestUI16A( uint16_t questId ); - uint16_t getQuestUI16B( uint16_t questId ); - uint16_t getQuestUI16C( uint16_t questId ); - uint32_t getQuestUI32A( uint16_t questId ); - - uint8_t getQuestBitFlag8( uint16_t questId ); - uint8_t getQuestBitFlag16( uint16_t questId ); - uint8_t getQuestBitFlag24( uint16_t questId ); - uint8_t getQuestBitFlag32( uint16_t questId ); - uint8_t getQuestBitFlag40( uint16_t questId ); - uint8_t getQuestBitFlag48( uint16_t questId ); - - - void setQuestUI8A( uint16_t questId, uint8_t val ); - void setQuestUI8B( uint16_t questId, uint8_t val ); - void setQuestUI8C( uint16_t questId, uint8_t val ); - void setQuestUI8D( uint16_t questId, uint8_t val ); - void setQuestUI8E( uint16_t questId, uint8_t val ); - void setQuestUI8F( uint16_t questId, uint8_t val ); - void setQuestUI8AH( uint16_t questId, uint8_t val ); - void setQuestUI8BH( uint16_t questId, uint8_t val ); - void setQuestUI8CH( uint16_t questId, uint8_t val ); - void setQuestUI8DH( uint16_t questId, uint8_t val ); - void setQuestUI8EH( uint16_t questId, uint8_t val ); - void setQuestUI8FH( uint16_t questId, uint8_t val ); - void setQuestUI8AL( uint16_t questId, uint8_t val ); - void setQuestUI8BL( uint16_t questId, uint8_t val ); - void setQuestUI8CL( uint16_t questId, uint8_t val ); - void setQuestUI8DL( uint16_t questId, uint8_t val ); - void setQuestUI8EL( uint16_t questId, uint8_t val ); - void setQuestUI8FL( uint16_t questId, uint8_t val ); - void setQuestUI16A( uint16_t questId, uint16_t val ); - void setQuestUI16B( uint16_t questId, uint16_t val ); - void setQuestUI16C( uint16_t questId, uint16_t val ); - void setQuestUI32A( uint16_t questId, uint32_t val ); - - void setQuestBitFlag8( uint16_t questId, uint8_t val ); - void setQuestBitFlag16( uint16_t questId, uint8_t val ); - void setQuestBitFlag24( uint16_t questId, uint8_t val ); - void setQuestBitFlag32( uint16_t questId, uint8_t val ); - void setQuestBitFlag40( uint16_t questId, uint8_t val ); - void setQuestBitFlag48( uint16_t questId, uint8_t val ); - - // Inventory / Item / Currency - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! add an item to the first free slot in one of the 4 main containers */ - bool tryAddItem( uint16_t catalogId, uint32_t quantity ); - /*! add an item to a given container */ - bool addItem( uint16_t containerId, uint16_t catalogId, uint32_t quantity ); - /*! equip an item to a specified slot */ - void equipItem( Inventory::EquipSlot equipSlotId, ItemPtr pItem, bool sendModel ); - /*! remove an item from an equipment slot */ - void unequipItem( Inventory::EquipSlot equipSlotId, ItemPtr pItem ); - /*! equip a weapon, possibly forcing a job change */ - void equipWeapon( ItemPtr pItem ); - /*! get player ilvl */ - uint16_t getItemLevel() const; - /*! send player ilvl */ - void sendItemLevel(); - /*! get a const pointer to the inventory object */ - InventoryPtr getInventory() const; - /*! get the current main hand model */ - uint64_t getModelMainWeapon() const; - /*! get the current off hand model */ - uint64_t getModelSubWeapon() const; - /*! get the current system hand model */ - uint64_t getModelSystemWeapon() const; - /*! return a const pointer to the model array */ - const uint32_t* getModelArray() const; - /*! return the equipment model in a specified equipment slot */ - uint32_t getModelForSlot( Inventory::EquipSlot slot ); - /*! set the equipment model in a specified equipment slot */ - void setModelForSlot( Inventory::EquipSlot slot, uint32_t val ); - /*! return the current amount of currency of type */ - uint32_t getCurrency( uint8_t type ) const; - /*! add amount to the currency of type */ - void addCurrency( uint8_t type, uint32_t amount ); - /*! remove amount from the currency of type */ - void removeCurrency( uint8_t type, uint32_t amount ); - /*! return the current amount of crystals of type */ - uint32_t getCrystal( uint8_t type ) const; - /*! add amount to the crystals of type */ - void addCrystal( uint8_t type, uint32_t amount ); - /*! remove amount from the crystals of type */ - void removeCrystal( uint8_t type, uint32_t amount ); - - // Class / Job / Exp - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! returns the level of the currently active class / job */ - uint8_t getLevel() const override; - /*! returns the level of the provided class / job */ - uint8_t getLevelForClass( Common::ClassJob pClass ) const; - /*! returns the exp of the currently active class / job */ - uint32_t getExp() const; - /*! sets the exp of the currently active class / job */ - void setExp( uint32_t amount ); - /*! adds exp to the currently active class / job */ - void gainExp( uint32_t amount ); - /*! gain a level on the currently active class / job */ - void gainLevel(); - /*! set level on the currently active class / job to given level */ - void setLevel( uint8_t level ); - /*! set level on the provided class / job to given level */ - void setLevelForClass( uint8_t level, Common::ClassJob classjob ); - /*! change class or job to given class / job */ - void setClassJob( Common::ClassJob classJob ); - /*! returns a pointer to the class array */ - uint16_t* getClassArray(); - /*! returns a const pointer to the class array */ - const uint16_t* getClassArray() const; - /*! returns a pointer to the exp array */ - uint32_t* getExpArray(); - /*! returns a const pointer to the exp array */ - const uint32_t* getExpArray() const; - - // Base Look / Stats / Params - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! return the birth day */ - uint8_t getBirthDay() const; - /*! return the birth month */ - uint8_t getBirthMonth() const; - /*! return the guardian diety Id */ - uint8_t getGuardianDeity() const; - /*! get look at specified index */ - uint8_t getLookAt( uint8_t index ) const; - /*! return the race */ - uint8_t getRace() const; - /*! return gender 0 male, 1 female */ - uint8_t getGender() const; - /*! return the id of the home town */ - uint8_t getStartTown() const; - /*! return the voice id */ - uint8_t getVoiceId() const; - /*! return the grand company */ - uint8_t getGc() const; - /*! return the grand company rank */ - const uint8_t* getGcRankArray() const; - /*! set look at index */ - void setLookAt( uint8_t index, uint8_t value ); - /*! set the voice Id */ - void setVoiceId( uint8_t voiceId ); - /*! set the grand company */ - void setGc( uint8_t gc ); - /*! set the grand company rank */ - void setGcRankAt( uint8_t index, uint8_t rank ); - /*! return a const pointer to the look array */ - const uint8_t* getLookArray() const; - /*! returns true if the player is currently in combat */ - bool isInCombat() const; - /*! sets players combat state */ - void setInCombat( bool mode ); - /*! return current online status depending on current state / activity */ - Common::OnlineStatus getOnlineStatus(); - /*! sets the players zone, initiating a zoning process */ - void setZone( uint32_t zoneId ); - - void forceZoneing( uint32_t zoneId ); - /*! return player to preset homepoint */ - void returnToHomepoint(); - /*! change position, sends update too */ - void changePosition( float x, float y, float z, float o ); - /*! return the contentId */ - uint64_t getContentId() const; - /*! return max hp */ - uint32_t getMaxHp(); - /*! return max mp */ - uint32_t getMaxMp(); - /*! return a players total play time */ - uint32_t getPlayTime() const; - /*! return true if the player has "new adventurere" status */ - bool isNewAdventurer() const; - /*! change the players "new adventurere" status */ - void setNewAdventurer( bool state ); - /*! sets the list of current online status */ - void setOnlineStatusMask( uint64_t status ); - /*! returns the current online status */ - uint64_t getOnlineStatusMask() const; - /*! perform a teleport of a specified type ( teleport,return,aethernet ) */ - void teleport( uint16_t aetheryteId, uint8_t type = 1 ); - /*! prepares zoning / fades out the screen */ - void prepareZoning( uint16_t targetZone, bool fadeOut, uint8_t fadoutTime = 0, uint16_t animation = 0 ); - /*! get player's title list (available titles) */ - uint8_t* getTitleList(); - /*! get player's active title */ - uint16_t getTitle() const; - /*! add title to player title list */ - void addTitle( uint16_t titleId ); - /*! change player's active title */ - void setTitle( uint16_t titleId ); - /*! change gear param state */ - void setEquipDisplayFlags( uint8_t state ); - /*! get gear param state */ - uint8_t getEquipDisplayFlags() const; - /*! mount the specified mount and send the packets */ - void mount( uint32_t id ); - /*! dismount the current mount and send the packets */ - void dismount(); - /*! get the current mount */ - uint8_t getCurrentMount() const; - - void calculateStats() override; - void sendStats(); - - - // Aetheryte / Action / Attribute bitmasks - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! register aetheryte aetheryteId and send update */ - void registerAetheryte( uint8_t aetheryteId ); - /*! check if aetheryte is already registered */ - bool isAetheryteRegistered( uint8_t aetheryteId ) const; - /*! return a const pointer to the aetheryte unlock bitmask array */ - int8_t getAetheryteMaskAt( uint8_t index ) const; - /*! return a pointer to the aetheryte unlock bitmask array */ - uint8_t* getAetheryteArray(); - /*! set homepoint */ - void setHomepoint( uint8_t aetheryteId ); - /*! get homepoint */ - uint8_t getHomepoint() const; - /*! 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 */ - uint8_t* getDiscoveryBitmask(); - /*! helper/debug function to reset all discovered areas */ - void resetDiscovery(); - /*! get a pointer to the howto bitmask array */ - uint8_t* getHowToArray(); - /*! get a const pointer to the howto bitmask array */ - const uint8_t* getHowToArray() const; - /*! update bitmask for how-to's seen */ - void updateHowtosSeen( uint32_t howToId ); - /*! learn an action / update the unlock bitmask. */ - void learnAction( uint8_t actionId ); - /*! learn a song / update the unlock bitmask. */ - void learnSong( uint8_t songId, uint32_t itemId ); - /*! check if an action is already unlocked in the bitmask. */ - bool isActionLearned( uint8_t actionId ) const; - /*! return a const pointer to the unlock bitmask array */ - const uint8_t* getUnlockBitmask() const; - /*! return a const pointer to the orchestrion bitmask array */ - const uint8_t* getOrchestrionBitmask() const; - /*! return a const pointer to the mount guide bitmask array */ - const uint8_t* getMountGuideBitmask() const; - - - // Spawn handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! initialize the spawnId queue */ - void initSpawnIdQueue(); - /*! get the spawn id mapped to a specific actorId */ - uint8_t getSpawnIdForActorId( uint32_t actorId ); - /*! assigns the given spawnId to the actor */ - void assignSpawnIdToPlayerId( uint32_t actorId, uint8_t spawnId ); - /*! frees the spawnId assigned to the given actor */ - void freePlayerSpawnId( uint32_t actorId ); - /*! send spawn packets to pTarget */ - void spawn( PlayerPtr pTarget ) override; - /*! send despawn packets to pTarget */ - void despawn( ActorPtr pTarget ) override; - - // Player State Handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /* return a const pointer to the state flag array */ - const uint8_t* getStateFlags() const; - /* set a specified state flag */ - void setStateFlag( Common::PlayerStateFlag flag ); - /* set a specified state flag */ - void setStateFlags( std::vector< Common::PlayerStateFlag > flags ); - /* check if a specified flag is set */ - bool hasStateFlag( Common::PlayerStateFlag flag ) const; - /* reset a specified flag */ - void unsetStateFlag( Common::PlayerStateFlag flag ); - /* helper function, send an empty state flag update */ - void unlock(); - - // Player Session Handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! return the userlevel */ - uint8_t getUserLevel() const; - /*! set timestamp for last received ping */ - void setLastPing( uint32_t ping ); - /*! get timestamp of last received ping */ - uint32_t getLastPing() const; - - // Player Database Handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! generate the update sql based on update flags */ - void updateSql(); - /*! load player from db, by id */ - bool load( uint32_t charId, SessionPtr pSession ); - /*! load active class data */ - bool loadClassData(); - /*! load search info */ - bool loadSearchInfo(); - - // Player Network Handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! send current models ( equipment ) */ - void sendModel(); - /*! send active state flags */ - void sendStateFlags(); - /*! send status update */ - void sendStatusUpdate( bool toSelf = true ) override; - /*! send the entire inventory sequence */ - void sendInventory() const; - /*! send active quest list */ - void sendQuestInfo(); - /*! send a quest specific message */ - void sendQuestMessage( uint32_t questId, int8_t msgId, uint8_t type, uint32_t var1, uint32_t var2 ); - /*! queue a packet for the player */ - void queuePacket( Network::Packets::GamePacketPtr pPacket ); - /*! queue a char connection packet for the player */ - void queueChatPacket( Network::Packets::GamePacketPtr pPacket ); - /*! returns true if loading is complete ( 0x69 has been received ) */ - bool isLoadingComplete() const; - /*! set the loading complete bool */ - void setLoadingComplete( bool bComplete ); - /*! mark this player for zoning, notify worldserver */ - void performZoning(uint16_t zoneId, const Common::FFXIVARR_POSITION3& pos, float rotation); - /*! return true if the player is marked for zoning */ - bool isMarkedForZoning() const; - - Common::ZoneingType getZoningType() const; - void setZoningType( Common::ZoneingType zoneingType ); - - void setSearchInfo( uint8_t selectRegion, uint8_t selectClass, const char* searchMessage ); - const char* getSearchMessage() const; - uint8_t getSearchSelectRegion() const; - uint8_t getSearchSelectClass() const; - - void sendNotice( const std::string& message ); - void sendUrgent( const std::string& message ); - void sendDebug( const std::string& message ); - - // Player Battle Handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - void onMobAggro( BattleNpcPtr pBNpc ); - void onMobDeaggro( BattleNpcPtr pBNpc ); - - void initHateSlotQueue(); - void hateListAdd( BattleNpcPtr pBNpc ); - void hateListRemove( BattleNpcPtr pBNpc ); - - bool hateListHasMob( BattleNpcPtr pBNpc ); - - void sendHateList(); - - bool actionHasCastTime( uint32_t actionId ); - - Core::Entity::ActorPtr lookupTargetById( uint64_t targetId ); - - bool isLogin() const; - void setIsLogin( bool bIsLogin ); - - uint16_t getZoneId() const; - - uint8_t getGmRank() const; - void setGmRank( uint8_t rank ); - - uint8_t getMode() const; - void setMode( uint8_t mode ); - - void setAutoattack( bool mode ); - bool isAutoattackOn() const; - - // Content Finder handling - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /*! Get an unix time when the player can register into content finder again. */ - uint32_t getCFPenaltyTimestamp() const; - - /*! Set an unix time when the player can register into content finder again. */ - void setCFPenaltyTimestamp( uint32_t timestamp ); - - uint32_t getCFPenaltyMinutes() const; - void setCFPenaltyMinutes( uint32_t minutes ); - - void setEorzeaTimeOffset( uint64_t timestamp ); - - // Database - void updateDbAllQuests() const; - void deleteQuest( uint16_t questId ) const; - void insertQuest( uint16_t questId, uint8_t index, uint8_t seq ) const; - void updateDbSearchInfo() const; - void updateDbClass() const; - - void setMarkedForRemoval(); - bool isMarkedForRemoval() const; - -private: - uint32_t m_lastWrite; - uint32_t m_lastPing; - - bool m_bIsLogin; - - uint64_t m_contentId; // This id will be the name of the folder for character settings in "My Games" - - uint8_t m_mode; - - bool m_markedForRemoval; - -private: - - uint8_t m_voice; - - uint64_t m_modelMainWeapon; - uint64_t m_modelSubWeapon; - uint64_t m_modelSystemWeapon; - - uint32_t m_modelEquip[10]; - - bool m_bNewGame; - - uint8_t m_guardianDeity; - uint8_t m_birthDay; - uint8_t m_birthMonth; - - struct RetainerInfo + struct QueuedZoning { - uint32_t retainerId; - char retainerName[32]; - uint32_t createUnixTime; - bool isActive; - bool isRename; - uint8_t status; - } m_retainerInfo[8]; + uint16_t m_targetZone; + Common::FFXIVARR_POSITION3 m_targetPosition; + float m_targetRotation; + uint64_t m_queueTime; - uint16_t m_activeTitle; - uint8_t m_titleList[48]; - uint8_t m_howTo[33]; - uint8_t m_minions[33]; - uint8_t m_mountGuide[13]; - uint8_t m_homePoint; - uint8_t m_startTown; - uint16_t m_townWarpFstFlags; - uint8_t m_questCompleteFlags[200]; - uint8_t m_discovery[420]; - uint32_t m_playTime; + QueuedZoning( uint16_t targetZone, const Common::FFXIVARR_POSITION3& targetPosition, uint64_t queuedTime, + float targetRotation ) : + m_targetZone( targetZone ), + m_targetPosition( targetPosition ), + m_queueTime( queuedTime ), + m_targetRotation( targetRotation ) + { + } + }; - uint16_t m_classArray[25]; - uint32_t m_expArray[25]; - uint8_t m_aetheryte[16]; - uint8_t m_unlocks[64]; - uint8_t m_orchestrion[38]; + /** Class representing the Player + * Inheriting from Actor + * + */ + class Player : public Actor + { + public: + /*! Contructor */ + Player(); - uint8_t m_openingSequence; + /*! Destructor */ + ~Player(); - uint16_t m_itemLevel; - InventoryPtr m_pInventory; + void autoAttack( ActorPtr pTarget ) override; - std::map< uint32_t, Event::EventPtr > m_eventMap; - std::map< uint32_t, uint8_t > m_playerIdToSpawnIdMap; // maps player to spawn id - std::queue< uint8_t > m_freeSpawnIdQueue; // queue with spawn ids free to be assigned - std::queue< uint8_t > m_freeHateSlotQueue; // queue with "hate slots" free to be assigned - std::map< uint32_t, uint8_t > m_actorIdTohateSlotMap; + // EventHandlers + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! start an event action */ + void eventActionStart( uint32_t eventId, uint32_t action, ActionCallback finishCallback, + ActionCallback interruptCallback, uint64_t additional ); + /*! start an event item action */ + void eventItemActionStart( uint32_t eventId, uint32_t action, ActionCallback finishCallback, + ActionCallback interruptCallback, uint64_t additional ); + /*! start/register a normal event */ + void eventStart( uint64_t actorId, uint32_t eventId, uint8_t eventParam, uint8_t eventParam1, + uint32_t eventParam2 ); + /*! play a subevent */ + void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, uint32_t eventParam2, uint32_t eventParam3 ); + /*! play a subevent */ + void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, uint32_t eventParam2, uint32_t eventParam3, + Scripting::EventReturnCallback eventReturnCallback ); + /*! play a subevent */ + void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, uint32_t eventParam2, uint32_t eventParam3, + uint32_t eventParam4, Scripting::EventReturnCallback eventReturnCallback ); + /*! play a subevent */ + void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, + Scripting::EventReturnCallback eventReturnCallback ); + /*! play a subevent */ + void eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags ); + /*! finish / unregister an event */ + void eventFinish( uint32_t eventId, uint32_t freePlayer ); + /*! add an event to the event array */ + void addEvent( Event::EventPtr pEvent ); + /*! retrieve an event from the event array */ + Event::EventPtr getEvent( uint32_t eventId ); + /*! get number of active events */ + size_t getEventCount(); + /*! remove an event from the event array */ + void removeEvent( uint32_t eventId ); + /*! return the eventlist */ + std::map< uint32_t, Event::EventPtr >& eventList(); - std::map< uint32_t, uint8_t > m_questIdToQuestIdx; // quest mapping, quest id to quest container index - std::map< uint8_t, uint32_t > m_questIdxToQuestId; // quest mapping, quest container index to questId - boost::shared_ptr< Common::QuestActive > m_activeQuests[30]; - int16_t m_questTracking[5]; + void checkEvent( uint32_t eventId ); - uint8_t m_stateFlags[7]; - uint8_t m_gmRank; - uint16_t zoneId; + // Events + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! Event to be called when zoning process gets triggered */ + void onZoneStart(); + /*! Event to be called when zoning process is finished */ + void onZoneDone(); + /*! Event to be called on login */ + void onLogin(); + /*! Event to be called on update tick */ + void onTick() override; + /*! Event to be called upon player death */ + void onDeath() override; + /*! Event called on every session iteration */ + void update( int64_t currTime ) override; + /*! Event to be called upon Bnpc kill */ + void onMobKill( uint16_t nameId ); - uint8_t m_equipDisplayFlags; + // Quest + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! load data for currently active quests */ + bool loadActiveQuests(); + /*! update quest ( register it as active quest if new ) */ + void updateQuest( uint16_t questId, uint8_t sequence ); + /*! return true if quest is currently active */ + bool hasQuest( uint16_t questId ); + /*! return the current quest sequence */ + uint8_t getQuestSeq( uint16_t questId ); + /*! send the quest tracker packet */ + void sendQuestTracker(); + /*! set quest tracker flag for a specified slot */ + void setQuestTracker( uint16_t index, int16_t flag ); + /*! return the index of a given quest in the players quest list */ + int8_t getQuestIndex( uint16_t questId ); + /*! finish a given quest */ + void finishQuest( uint16_t questId ); + /*! finish a given quest */ + void unfinishQuest( uint16_t questId ); + /*! remove a given quest */ + void removeQuest( uint16_t questId ); + /*! add a quest to the completed quests mask */ + void updateQuestsCompleted( uint32_t questId ); + /*! remove a quest from the completed quest mask */ + void removeQuestsCompleted( uint32_t questId ); + /*! get the curent opening sequence */ + uint8_t getOpeningSequence() const; + /*! set te current opening sequence */ + void setOpeningSequence( uint8_t seq ); - bool m_bInCombat; - bool m_bLoadingComplete; - bool m_bAutoattack; + bool giveQuestRewards( uint32_t questId, uint32_t optionalChoice ); - Common::ZoneingType m_zoningType; + boost::shared_ptr< Common::QuestActive > getQuestActive( uint16_t index ); - bool m_bMarkedForZoning; - bool m_bNewAdventurer; - uint64_t m_onlineStatus; - boost::shared_ptr< QueuedZoning > m_queuedZoneing; + uint8_t getQuestUI8A( uint16_t questId ); + uint8_t getQuestUI8B( uint16_t questId ); + uint8_t getQuestUI8C( uint16_t questId ); + uint8_t getQuestUI8D( uint16_t questId ); + uint8_t getQuestUI8E( uint16_t questId ); + uint8_t getQuestUI8F( uint16_t questId ); + uint8_t getQuestUI8AH( uint16_t questId ); + uint8_t getQuestUI8BH( uint16_t questId ); + uint8_t getQuestUI8CH( uint16_t questId ); + uint8_t getQuestUI8DH( uint16_t questId ); + uint8_t getQuestUI8EH( uint16_t questId ); + uint8_t getQuestUI8FH( uint16_t questId ); + uint8_t getQuestUI8AL( uint16_t questId ); + uint8_t getQuestUI8BL( uint16_t questId ); + uint8_t getQuestUI8CL( uint16_t questId ); + uint8_t getQuestUI8DL( uint16_t questId ); + uint8_t getQuestUI8EL( uint16_t questId ); + uint8_t getQuestUI8FL( uint16_t questId ); + uint16_t getQuestUI16A( uint16_t questId ); + uint16_t getQuestUI16B( uint16_t questId ); + uint16_t getQuestUI16C( uint16_t questId ); + uint32_t getQuestUI32A( uint16_t questId ); - // search info - char m_searchMessage[193]; // searchmessage to show in profile - uint8_t m_searchSelectRegion; // regions selected to show up in profile - uint8_t m_searchSelectClass; // class selected to show up in profile + uint8_t getQuestBitFlag8( uint16_t questId ); + uint8_t getQuestBitFlag16( uint16_t questId ); + uint8_t getQuestBitFlag24( uint16_t questId ); + uint8_t getQuestBitFlag32( uint16_t questId ); + uint8_t getQuestBitFlag40( uint16_t questId ); + uint8_t getQuestBitFlag48( uint16_t questId ); - // gc info - uint8_t m_gc; - uint8_t m_gcRank[3]; + void setQuestUI8A( uint16_t questId, uint8_t val ); + void setQuestUI8B( uint16_t questId, uint8_t val ); + void setQuestUI8C( uint16_t questId, uint8_t val ); + void setQuestUI8D( uint16_t questId, uint8_t val ); + void setQuestUI8E( uint16_t questId, uint8_t val ); + void setQuestUI8F( uint16_t questId, uint8_t val ); + void setQuestUI8AH( uint16_t questId, uint8_t val ); + void setQuestUI8BH( uint16_t questId, uint8_t val ); + void setQuestUI8CH( uint16_t questId, uint8_t val ); + void setQuestUI8DH( uint16_t questId, uint8_t val ); + void setQuestUI8EH( uint16_t questId, uint8_t val ); + void setQuestUI8FH( uint16_t questId, uint8_t val ); + void setQuestUI8AL( uint16_t questId, uint8_t val ); + void setQuestUI8BL( uint16_t questId, uint8_t val ); + void setQuestUI8CL( uint16_t questId, uint8_t val ); + void setQuestUI8DL( uint16_t questId, uint8_t val ); + void setQuestUI8EL( uint16_t questId, uint8_t val ); + void setQuestUI8FL( uint16_t questId, uint8_t val ); + void setQuestUI16A( uint16_t questId, uint16_t val ); + void setQuestUI16B( uint16_t questId, uint16_t val ); + void setQuestUI16C( uint16_t questId, uint16_t val ); + void setQuestUI32A( uint16_t questId, uint32_t val ); - // content finder info - uint32_t m_cfPenaltyUntil; // unix time + void setQuestBitFlag8( uint16_t questId, uint8_t val ); + void setQuestBitFlag16( uint16_t questId, uint8_t val ); + void setQuestBitFlag24( uint16_t questId, uint8_t val ); + void setQuestBitFlag32( uint16_t questId, uint8_t val ); + void setQuestBitFlag40( uint16_t questId, uint8_t val ); + void setQuestBitFlag48( uint16_t questId, uint8_t val ); - uint8_t m_mount; -}; + // Inventory / Item / Currency + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! add an item to the first free slot in one of the 4 main containers */ + bool tryAddItem( uint16_t catalogId, uint32_t quantity ); + /*! add an item to a given container */ + bool addItem( uint16_t containerId, uint16_t catalogId, uint32_t quantity ); + /*! equip an item to a specified slot */ + void equipItem( Inventory::EquipSlot equipSlotId, ItemPtr pItem, bool sendModel ); + /*! remove an item from an equipment slot */ + void unequipItem( Inventory::EquipSlot equipSlotId, ItemPtr pItem ); + /*! equip a weapon, possibly forcing a job change */ + void equipWeapon( ItemPtr pItem ); + /*! get player ilvl */ + uint16_t getItemLevel() const; + /*! send player ilvl */ + void sendItemLevel(); + /*! get a const pointer to the inventory object */ + InventoryPtr getInventory() const; + /*! get the current main hand model */ + uint64_t getModelMainWeapon() const; + /*! get the current off hand model */ + uint64_t getModelSubWeapon() const; + /*! get the current system hand model */ + uint64_t getModelSystemWeapon() const; + /*! return a const pointer to the model array */ + const uint32_t* getModelArray() const; + /*! return the equipment model in a specified equipment slot */ + uint32_t getModelForSlot( Inventory::EquipSlot slot ); + /*! set the equipment model in a specified equipment slot */ + void setModelForSlot( Inventory::EquipSlot slot, uint32_t val ); + /*! return the current amount of currency of type */ + uint32_t getCurrency( uint8_t type ) const; + /*! add amount to the currency of type */ + void addCurrency( uint8_t type, uint32_t amount ); + /*! remove amount from the currency of type */ + void removeCurrency( uint8_t type, uint32_t amount ); + /*! return the current amount of crystals of type */ + uint32_t getCrystal( uint8_t type ) const; + /*! add amount to the crystals of type */ + void addCrystal( uint8_t type, uint32_t amount ); + /*! remove amount from the crystals of type */ + void removeCrystal( uint8_t type, uint32_t amount ); -} -} + // Class / Job / Exp + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! returns the level of the currently active class / job */ + uint8_t getLevel() const override; + /*! returns the level of the provided class / job */ + uint8_t getLevelForClass( Common::ClassJob pClass ) const; + /*! returns the exp of the currently active class / job */ + uint32_t getExp() const; + /*! sets the exp of the currently active class / job */ + void setExp( uint32_t amount ); + /*! adds exp to the currently active class / job */ + void gainExp( uint32_t amount ); + /*! gain a level on the currently active class / job */ + void gainLevel(); + /*! set level on the currently active class / job to given level */ + void setLevel( uint8_t level ); + /*! set level on the provided class / job to given level */ + void setLevelForClass( uint8_t level, Common::ClassJob classjob ); + /*! change class or job to given class / job */ + void setClassJob( Common::ClassJob classJob ); + /*! returns a pointer to the class array */ + uint16_t* getClassArray(); + /*! returns a const pointer to the class array */ + const uint16_t* getClassArray() const; + /*! returns a pointer to the exp array */ + uint32_t* getExpArray(); + /*! returns a const pointer to the exp array */ + const uint32_t* getExpArray() const; + + // Base Look / Stats / Params + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! return the birth day */ + uint8_t getBirthDay() const; + /*! return the birth month */ + uint8_t getBirthMonth() const; + /*! return the guardian diety Id */ + uint8_t getGuardianDeity() const; + /*! get look at specified index */ + uint8_t getLookAt( uint8_t index ) const; + /*! return the race */ + uint8_t getRace() const; + /*! return gender 0 male, 1 female */ + uint8_t getGender() const; + /*! return the id of the home town */ + uint8_t getStartTown() const; + /*! return the voice id */ + uint8_t getVoiceId() const; + /*! return the grand company */ + uint8_t getGc() const; + /*! return the grand company rank */ + const uint8_t* getGcRankArray() const; + /*! set look at index */ + void setLookAt( uint8_t index, uint8_t value ); + /*! set the voice Id */ + void setVoiceId( uint8_t voiceId ); + /*! set the grand company */ + void setGc( uint8_t gc ); + /*! set the grand company rank */ + void setGcRankAt( uint8_t index, uint8_t rank ); + /*! return a const pointer to the look array */ + const uint8_t* getLookArray() const; + /*! returns true if the player is currently in combat */ + bool isInCombat() const; + /*! sets players combat state */ + void setInCombat( bool mode ); + /*! return current online status depending on current state / activity */ + Common::OnlineStatus getOnlineStatus(); + /*! sets the players zone, initiating a zoning process */ + void setZone( uint32_t zoneId ); + + void forceZoneing( uint32_t zoneId ); + /*! return player to preset homepoint */ + void returnToHomepoint(); + /*! change position, sends update too */ + void changePosition( float x, float y, float z, float o ); + /*! return the contentId */ + uint64_t getContentId() const; + /*! return max hp */ + uint32_t getMaxHp(); + /*! return max mp */ + uint32_t getMaxMp(); + /*! return a players total play time */ + uint32_t getPlayTime() const; + /*! return true if the player has "new adventurere" status */ + bool isNewAdventurer() const; + /*! change the players "new adventurere" status */ + void setNewAdventurer( bool state ); + /*! sets the list of current online status */ + void setOnlineStatusMask( uint64_t status ); + /*! returns the current online status */ + uint64_t getOnlineStatusMask() const; + /*! perform a teleport of a specified type ( teleport,return,aethernet ) */ + void teleport( uint16_t aetheryteId, uint8_t type = 1 ); + /*! prepares zoning / fades out the screen */ + void prepareZoning( uint16_t targetZone, bool fadeOut, uint8_t fadoutTime = 0, uint16_t animation = 0 ); + /*! get player's title list (available titles) */ + uint8_t* getTitleList(); + /*! get player's active title */ + uint16_t getTitle() const; + /*! add title to player title list */ + void addTitle( uint16_t titleId ); + /*! change player's active title */ + void setTitle( uint16_t titleId ); + /*! change gear param state */ + void setEquipDisplayFlags( uint8_t state ); + /*! get gear param state */ + uint8_t getEquipDisplayFlags() const; + /*! mount the specified mount and send the packets */ + void mount( uint32_t id ); + /*! dismount the current mount and send the packets */ + void dismount(); + /*! get the current mount */ + uint8_t getCurrentMount() const; + + void calculateStats() override; + void sendStats(); + + // Aetheryte / Action / Attribute bitmasks + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! register aetheryte aetheryteId and send update */ + void registerAetheryte( uint8_t aetheryteId ); + /*! check if aetheryte is already registered */ + bool isAetheryteRegistered( uint8_t aetheryteId ) const; + /*! return a const pointer to the aetheryte unlock bitmask array */ + int8_t getAetheryteMaskAt( uint8_t index ) const; + /*! return a pointer to the aetheryte unlock bitmask array */ + uint8_t* getAetheryteArray(); + /*! set homepoint */ + void setHomepoint( uint8_t aetheryteId ); + /*! get homepoint */ + uint8_t getHomepoint() const; + /*! 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 */ + uint8_t* getDiscoveryBitmask(); + /*! helper/debug function to reset all discovered areas */ + void resetDiscovery(); + /*! get a pointer to the howto bitmask array */ + uint8_t* getHowToArray(); + /*! get a const pointer to the howto bitmask array */ + const uint8_t* getHowToArray() const; + /*! update bitmask for how-to's seen */ + void updateHowtosSeen( uint32_t howToId ); + /*! learn an action / update the unlock bitmask. */ + void learnAction( uint8_t actionId ); + /*! learn a song / update the unlock bitmask. */ + void learnSong( uint8_t songId, uint32_t itemId ); + /*! check if an action is already unlocked in the bitmask. */ + bool isActionLearned( uint8_t actionId ) const; + /*! return a const pointer to the unlock bitmask array */ + const uint8_t* getUnlockBitmask() const; + /*! return a const pointer to the orchestrion bitmask array */ + const uint8_t* getOrchestrionBitmask() const; + /*! return a const pointer to the mount guide bitmask array */ + const uint8_t* getMountGuideBitmask() const; + + // Spawn handling + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! initialize the spawnId queue */ + void initSpawnIdQueue(); + /*! get the spawn id mapped to a specific actorId */ + uint8_t getSpawnIdForActorId( uint32_t actorId ); + /*! assigns the given spawnId to the actor */ + void assignSpawnIdToPlayerId( uint32_t actorId, uint8_t spawnId ); + /*! frees the spawnId assigned to the given actor */ + void freePlayerSpawnId( uint32_t actorId ); + /*! send spawn packets to pTarget */ + void spawn( PlayerPtr pTarget ) override; + /*! send despawn packets to pTarget */ + void despawn( ActorPtr pTarget ) override; + + // Player State Handling + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /* return a const pointer to the state flag array */ + const uint8_t* getStateFlags() const; + /* set a specified state flag */ + void setStateFlag( Common::PlayerStateFlag flag ); + /* set a specified state flag */ + void setStateFlags( std::vector< Common::PlayerStateFlag > flags ); + /* check if a specified flag is set */ + bool hasStateFlag( Common::PlayerStateFlag flag ) const; + /* reset a specified flag */ + void unsetStateFlag( Common::PlayerStateFlag flag ); + /* helper function, send an empty state flag update */ + void unlock(); + + // Player Session Handling + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! return the userlevel */ + uint8_t getUserLevel() const; + /*! set timestamp for last received ping */ + void setLastPing( uint32_t ping ); + /*! get timestamp of last received ping */ + uint32_t getLastPing() const; + + // Player Database Handling + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! generate the update sql based on update flags */ + void updateSql(); + /*! load player from db, by id */ + bool load( uint32_t charId, SessionPtr pSession ); + /*! load active class data */ + bool loadClassData(); + /*! load search info */ + bool loadSearchInfo(); + + // Player Network Handling + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! send current models ( equipment ) */ + void sendModel(); + /*! send active state flags */ + void sendStateFlags(); + /*! send status update */ + void sendStatusUpdate( bool toSelf = true ) override; + /*! send the entire inventory sequence */ + void sendInventory() const; + /*! send active quest list */ + void sendQuestInfo(); + /*! send a quest specific message */ + void sendQuestMessage( uint32_t questId, int8_t msgId, uint8_t type, uint32_t var1, uint32_t var2 ); + /*! queue a packet for the player */ + void queuePacket( Network::Packets::GamePacketPtr pPacket ); + /*! queue a char connection packet for the player */ + void queueChatPacket( Network::Packets::GamePacketPtr pPacket ); + /*! returns true if loading is complete ( 0x69 has been received ) */ + bool isLoadingComplete() const; + /*! set the loading complete bool */ + void setLoadingComplete( bool bComplete ); + /*! mark this player for zoning, notify worldserver */ + void performZoning( uint16_t zoneId, const Common::FFXIVARR_POSITION3& pos, float rotation ); + /*! return true if the player is marked for zoning */ + bool isMarkedForZoning() const; + + Common::ZoneingType getZoningType() const; + void setZoningType( Common::ZoneingType zoneingType ); + + void setSearchInfo( uint8_t selectRegion, uint8_t selectClass, const char* searchMessage ); + const char* getSearchMessage() const; + uint8_t getSearchSelectRegion() const; + uint8_t getSearchSelectClass() const; + + void sendNotice( const std::string& message ); + void sendUrgent( const std::string& message ); + void sendDebug( const std::string& message ); + + // Player Battle Handling + ////////////////////////////////////////////////////////////////////////////////////////////////////// + void onMobAggro( BattleNpcPtr pBNpc ); + void onMobDeaggro( BattleNpcPtr pBNpc ); + + void initHateSlotQueue(); + void hateListAdd( BattleNpcPtr pBNpc ); + void hateListRemove( BattleNpcPtr pBNpc ); + + bool hateListHasMob( BattleNpcPtr pBNpc ); + + void sendHateList(); + + bool actionHasCastTime( uint32_t actionId ); + + Core::Entity::ActorPtr lookupTargetById( uint64_t targetId ); + + bool isLogin() const; + void setIsLogin( bool bIsLogin ); + + uint16_t getZoneId() const; + + uint8_t getGmRank() const; + void setGmRank( uint8_t rank ); + + uint8_t getMode() const; + void setMode( uint8_t mode ); + + void setAutoattack( bool mode ); + bool isAutoattackOn() const; + + // Content Finder handling + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /*! Get an unix time when the player can register into content finder again. */ + uint32_t getCFPenaltyTimestamp() const; + + /*! Set an unix time when the player can register into content finder again. */ + void setCFPenaltyTimestamp( uint32_t timestamp ); + + uint32_t getCFPenaltyMinutes() const; + void setCFPenaltyMinutes( uint32_t minutes ); + + void setEorzeaTimeOffset( uint64_t timestamp ); + + // Database + void updateDbAllQuests() const; + void deleteQuest( uint16_t questId ) const; + void insertQuest( uint16_t questId, uint8_t index, uint8_t seq ) const; + void updateDbSearchInfo() const; + void updateDbClass() const; + + void setMarkedForRemoval(); + bool isMarkedForRemoval() const; + + private: + uint32_t m_lastWrite; + uint32_t m_lastPing; + + bool m_bIsLogin; + + uint64_t m_contentId; // This id will be the name of the folder for character settings in "My Games" + + uint8_t m_mode; + + bool m_markedForRemoval; + + private: + uint8_t m_voice; + + uint64_t m_modelMainWeapon; + uint64_t m_modelSubWeapon; + uint64_t m_modelSystemWeapon; + + uint32_t m_modelEquip[10]; + + bool m_bNewGame; + + uint8_t m_guardianDeity; + uint8_t m_birthDay; + uint8_t m_birthMonth; + + struct RetainerInfo + { + uint32_t retainerId; + char retainerName[32]; + uint32_t createUnixTime; + bool isActive; + bool isRename; + uint8_t status; + } m_retainerInfo[8]; + + uint16_t m_activeTitle; + uint8_t m_titleList[48]; + uint8_t m_howTo[33]; + uint8_t m_minions[33]; + uint8_t m_mountGuide[13]; + uint8_t m_homePoint; + uint8_t m_startTown; + uint16_t m_townWarpFstFlags; + uint8_t m_questCompleteFlags[200]; + uint8_t m_discovery[420]; + uint32_t m_playTime; + + uint16_t m_classArray[25]; + uint32_t m_expArray[25]; + uint8_t m_aetheryte[16]; + uint8_t m_unlocks[64]; + uint8_t m_orchestrion[38]; + + uint8_t m_openingSequence; + + uint16_t m_itemLevel; + InventoryPtr m_pInventory; + + std::map< uint32_t, Event::EventPtr > m_eventMap; + std::map< uint32_t, uint8_t > m_playerIdToSpawnIdMap; // maps player to spawn id + std::queue< uint8_t > m_freeSpawnIdQueue; // queue with spawn ids free to be assigned + std::queue< uint8_t > m_freeHateSlotQueue; // queue with "hate slots" free to be assigned + std::map< uint32_t, uint8_t > m_actorIdTohateSlotMap; + + std::map< uint32_t, uint8_t > m_questIdToQuestIdx; // quest mapping, quest id to quest container index + std::map< uint8_t, uint32_t > m_questIdxToQuestId; // quest mapping, quest container index to questId + boost::shared_ptr< Common::QuestActive > m_activeQuests[30]; + int16_t m_questTracking[5]; + + uint8_t m_stateFlags[7]; + uint8_t m_gmRank; + uint16_t zoneId; + + uint8_t m_equipDisplayFlags; + + bool m_bInCombat; + bool m_bLoadingComplete; + bool m_bAutoattack; + + Common::ZoneingType m_zoningType; + + bool m_bMarkedForZoning; + bool m_bNewAdventurer; + uint64_t m_onlineStatus; + boost::shared_ptr< QueuedZoning > m_queuedZoneing; + + // search info + char m_searchMessage[193]; // searchmessage to show in profile + uint8_t m_searchSelectRegion; // regions selected to show up in profile + uint8_t m_searchSelectClass; // class selected to show up in profile + + // gc info + uint8_t m_gc; + uint8_t m_gcRank[3]; + + // content finder info + uint32_t m_cfPenaltyUntil; // unix time + + uint8_t m_mount; + }; + +} // namespace Entity +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Actor/PlayerEvent.cpp b/src/servers/Server_Zone/Actor/PlayerEvent.cpp index 0f4b5aae..50f10f5f 100644 --- a/src/servers/Server_Zone/Actor/PlayerEvent.cpp +++ b/src/servers/Server_Zone/Actor/PlayerEvent.cpp @@ -1,8 +1,8 @@ #include -#include -#include -#include #include +#include +#include +#include #include "Player.h" @@ -12,16 +12,15 @@ #include "Network/GameConnection.h" #include "Network/PacketWrappers/ActorControlPacket142.h" +#include "Network/PacketWrappers/EventFinishPacket.h" +#include "Network/PacketWrappers/EventPlayPacket.h" +#include "Network/PacketWrappers/EventStartPacket.h" #include "Network/PacketWrappers/InitUIPacket.h" #include "Network/PacketWrappers/ServerNoticePacket.h" -#include "Network/PacketWrappers/EventStartPacket.h" -#include "Network/PacketWrappers/EventPlayPacket.h" -#include "Network/PacketWrappers/EventFinishPacket.h" #include "Action/EventAction.h" #include "Action/EventItemAction.h" -#include "Event/Event.h" #include "Event/Event.h" #include "ServerZone.h" @@ -74,9 +73,7 @@ void Core::Entity::Player::checkEvent( uint32_t eventId ) eventFinish( eventId, 1 ); } - -void Core::Entity::Player::eventStart( uint64_t actorId, uint32_t eventId, - uint8_t eventType, uint8_t eventParam1, +void Core::Entity::Player::eventStart( uint64_t actorId, uint32_t eventId, uint8_t eventType, uint8_t eventParam1, uint32_t eventParam2 ) { Event::EventPtr newEvent( new Event::Event( actorId, eventId, eventType, eventParam1, eventParam2 ) ); @@ -86,20 +83,18 @@ void Core::Entity::Player::eventStart( uint64_t actorId, uint32_t eventId, sendStateFlags(); EventStartPacket eventStart( getId(), actorId, eventId, eventType, eventParam1, eventParam2 ); - + queuePacket( eventStart ); - } -void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, - uint32_t flags, uint32_t eventParam2, +void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, uint32_t eventParam2, uint32_t eventParam3 ) { eventPlay( eventId, scene, flags, eventParam2, eventParam3, nullptr ); } -void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, - uint32_t flags, Scripting::EventReturnCallback eventCallback ) +void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, + Scripting::EventReturnCallback eventCallback ) { eventPlay( eventId, scene, flags, 0, 0, eventCallback ); } @@ -109,15 +104,14 @@ void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, uint32_t eventPlay( eventId, scene, flags, 0, 0, nullptr ); } -void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, - uint32_t flags, uint32_t eventParam2, +void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, uint32_t eventParam2, uint32_t eventParam3, Scripting::EventReturnCallback eventCallback ) { if( flags & 0x02 ) { setStateFlag( PlayerStateFlag::WatchingCutscene ); - sendToInRangeSet( ActorControlPacket142( getId(), SetStatusIcon, - static_cast< uint8_t >( getOnlineStatus() ) ), true ); + sendToInRangeSet( ActorControlPacket142( getId(), SetStatusIcon, static_cast< uint8_t >( getOnlineStatus() ) ), + true ); } auto pEvent = getEvent( eventId ); @@ -135,21 +129,20 @@ void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, pEvent->setPlayedScene( true ); pEvent->setEventReturnCallback( eventCallback ); - EventPlayPacket eventPlay( getId(), pEvent->getActorId(), pEvent->getId(), - scene, flags, eventParam2, eventParam3 ); + EventPlayPacket eventPlay( getId(), pEvent->getActorId(), pEvent->getId(), scene, flags, eventParam2, eventParam3 ); queuePacket( eventPlay ); } -void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, - uint32_t flags, uint32_t eventParam2, - uint32_t eventParam3, uint32_t eventParam4, Scripting::EventReturnCallback eventCallback ) +void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, uint32_t flags, uint32_t eventParam2, + uint32_t eventParam3, uint32_t eventParam4, + Scripting::EventReturnCallback eventCallback ) { if( flags & 0x02 ) { setStateFlag( PlayerStateFlag::WatchingCutscene ); - sendToInRangeSet( ActorControlPacket142( getId(), SetStatusIcon, - static_cast< uint8_t >( getOnlineStatus() ) ), true ); + sendToInRangeSet( ActorControlPacket142( getId(), SetStatusIcon, static_cast< uint8_t >( getOnlineStatus() ) ), + true ); } auto pEvent = getEvent( eventId ); @@ -167,8 +160,8 @@ void Core::Entity::Player::eventPlay( uint32_t eventId, uint32_t scene, pEvent->setPlayedScene( true ); pEvent->setEventReturnCallback( eventCallback ); - EventPlayPacket eventPlay( getId(), pEvent->getActorId(), pEvent->getId(), - scene, flags, eventParam2, eventParam3, eventParam4 ); + EventPlayPacket eventPlay( getId(), pEvent->getActorId(), pEvent->getId(), scene, flags, eventParam2, eventParam3, + eventParam4 ); queuePacket( eventPlay ); } @@ -204,7 +197,8 @@ void Core::Entity::Player::eventFinish( uint32_t eventId, uint32_t freePlayer ) if( it.second->hasPlayedScene() == false ) { // TODO: not happy with this, this is also prone to break wit more than one remaining event in there - queuePacket( EventFinishPacket( getId(), it.second->getId(), it.second->getEventType(), it.second->getEventParam3() ) ); + queuePacket( EventFinishPacket( getId(), it.second->getId(), it.second->getEventType(), + it.second->getEventParam3() ) ); removeEvent( it.second->getId() ); } } @@ -221,8 +215,8 @@ void Core::Entity::Player::eventFinish( uint32_t eventId, uint32_t freePlayer ) if( hasStateFlag( PlayerStateFlag::WatchingCutscene ) ) { unsetStateFlag( PlayerStateFlag::WatchingCutscene ); - sendToInRangeSet( ActorControlPacket142( getId(), SetStatusIcon, - static_cast< uint8_t >( getOnlineStatus() ) ), true ); + sendToInRangeSet( ActorControlPacket142( getId(), SetStatusIcon, static_cast< uint8_t >( getOnlineStatus() ) ), + true ); } removeEvent( pEvent->getId() ); @@ -234,14 +228,11 @@ void Core::Entity::Player::eventFinish( uint32_t eventId, uint32_t freePlayer ) } } -void Core::Entity::Player::eventActionStart( uint32_t eventId, - uint32_t action, - ActionCallback finishCallback, - ActionCallback interruptCallback, - uint64_t additional ) +void Core::Entity::Player::eventActionStart( uint32_t eventId, uint32_t action, ActionCallback finishCallback, + ActionCallback interruptCallback, uint64_t additional ) { - Action::ActionPtr pEventAction( new Action::EventAction( shared_from_this(), eventId, action, - finishCallback, interruptCallback, additional ) ); + Action::ActionPtr pEventAction( + new Action::EventAction( shared_from_this(), eventId, action, finishCallback, interruptCallback, additional ) ); setCurrentAction( pEventAction ); auto pEvent = getEvent( eventId ); @@ -263,15 +254,11 @@ void Core::Entity::Player::eventActionStart( uint32_t eventId, pEventAction->onStart(); } - -void Core::Entity::Player::eventItemActionStart( uint32_t eventId, - uint32_t action, - ActionCallback finishCallback, - ActionCallback interruptCallback, - uint64_t additional ) +void Core::Entity::Player::eventItemActionStart( uint32_t eventId, uint32_t action, ActionCallback finishCallback, + ActionCallback interruptCallback, uint64_t additional ) { - Action::ActionPtr pEventItemAction( new Action::EventItemAction( shared_from_this(), eventId, action, - finishCallback, interruptCallback, additional ) ); + Action::ActionPtr pEventItemAction( new Action::EventItemAction( shared_from_this(), eventId, action, finishCallback, + interruptCallback, additional ) ); setCurrentAction( pEventItemAction ); @@ -290,24 +277,20 @@ void Core::Entity::Player::onLogin() void Core::Entity::Player::onZoneStart() { - } void Core::Entity::Player::onZoneDone() { - } void Core::Entity::Player::onDeath() { - } - // TODO: slightly ugly here and way too static. Needs too be done properly void Core::Entity::Player::onTick() { - + bool sendUpdate = false; if( !isAlive() || !isLoadingComplete() ) diff --git a/src/servers/Server_Zone/Actor/PlayerInventory.cpp b/src/servers/Server_Zone/Actor/PlayerInventory.cpp index c35fb10a..240bc21e 100644 --- a/src/servers/Server_Zone/Actor/PlayerInventory.cpp +++ b/src/servers/Server_Zone/Actor/PlayerInventory.cpp @@ -1,12 +1,12 @@ #include #include -#include #include +#include #include "Player.h" -#include "Zone/ZoneMgr.h" #include "Zone/Zone.h" +#include "Zone/ZoneMgr.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" @@ -38,45 +38,37 @@ void Core::Entity::Player::equipWeapon( ItemPtr pItem ) switch( pItem->getCategory() ) { case ItemUICategory::PugilistsArm: - if( currentClass != ClassJob::Pugilist && - currentClass != ClassJob::Monk ) + if( currentClass != ClassJob::Pugilist && currentClass != ClassJob::Monk ) setClassJob( ClassJob::Pugilist ); break; case ItemUICategory::GladiatorsArm: - if( currentClass != ClassJob::Gladiator && - currentClass != ClassJob::Paladin ) + if( currentClass != ClassJob::Gladiator && currentClass != ClassJob::Paladin ) setClassJob( ClassJob::Gladiator ); break; case ItemUICategory::MaraudersArm: - if( currentClass != ClassJob::Marauder && - currentClass != ClassJob::Warrior ) + if( currentClass != ClassJob::Marauder && currentClass != ClassJob::Warrior ) setClassJob( ClassJob::Marauder ); break; case ItemUICategory::ArchersArm: - if( currentClass != ClassJob::Archer && - currentClass != ClassJob::Bard ) + if( currentClass != ClassJob::Archer && currentClass != ClassJob::Bard ) setClassJob( ClassJob::Archer ); break; case ItemUICategory::LancersArm: - if( currentClass != ClassJob::Lancer && - currentClass != ClassJob::Dragoon ) + if( currentClass != ClassJob::Lancer && currentClass != ClassJob::Dragoon ) setClassJob( ClassJob::Lancer ); break; case ItemUICategory::OnehandedThaumaturgesArm: case ItemUICategory::TwohandedThaumaturgesArm: - if( currentClass != ClassJob::Thaumaturge && - currentClass != ClassJob::Blackmage ) + if( currentClass != ClassJob::Thaumaturge && currentClass != ClassJob::Blackmage ) setClassJob( ClassJob::Thaumaturge ); break; case ItemUICategory::OnehandedConjurersArm: case ItemUICategory::TwohandedConjurersArm: - if( currentClass != ClassJob::Conjurer && - currentClass != ClassJob::Whitemage ) + if( currentClass != ClassJob::Conjurer && currentClass != ClassJob::Whitemage ) setClassJob( ClassJob::Conjurer ); break; case ItemUICategory::ArcanistsGrimoire: - if( currentClass != ClassJob::Arcanist && - currentClass != ClassJob::Summoner && + if( currentClass != ClassJob::Arcanist && currentClass != ClassJob::Summoner && currentClass != ClassJob::Scholar ) setClassJob( ClassJob::Arcanist ); break; @@ -89,7 +81,7 @@ void Core::Entity::Player::equipWeapon( ItemPtr pItem ) void Core::Entity::Player::equipItem( Inventory::EquipSlot equipSlotId, ItemPtr pItem, bool sendUpdate ) { - //g_log.debug( "Equipping into slot " + std::to_string( equipSlotId ) ); + // g_log.debug( "Equipping into slot " + std::to_string( equipSlotId ) ); uint64_t model = pItem->getModelId1(); uint64_t model2 = pItem->getModelId2(); @@ -115,11 +107,10 @@ void Core::Entity::Player::equipItem( Inventory::EquipSlot equipSlotId, ItemPtr default: // any other slot m_modelEquip[static_cast< uint8_t >( equipSlotId )] = static_cast< uint32_t >( model ); break; - } if( sendUpdate ) - { + { this->sendModel(); m_itemLevel = getInventory()->calculateEquippedGearItemLevel(); sendItemLevel(); @@ -169,7 +160,6 @@ void Core::Entity::Player::removeCurrency( uint8_t type, uint32_t amount ) queuePacket( invUpPacket ); } - uint32_t Core::Entity::Player::getCrystal( uint8_t type ) const { return m_pInventory->getCrystal( static_cast< Inventory::CrystalType >( type ) ); @@ -228,4 +218,3 @@ void Core::Entity::Player::sendInventory() const { m_pInventory->send(); } - diff --git a/src/servers/Server_Zone/Actor/PlayerQuest.cpp b/src/servers/Server_Zone/Actor/PlayerQuest.cpp index fa938d33..3fadc21e 100644 --- a/src/servers/Server_Zone/Actor/PlayerQuest.cpp +++ b/src/servers/Server_Zone/Actor/PlayerQuest.cpp @@ -1,16 +1,16 @@ #include -#include -#include #include +#include #include +#include #include "Network/GameConnection.h" #include "Network/PacketWrappers/QuestMessagePacket.h" -#include "Server_Zone/Session.h" #include "Player.h" #include "Server_Zone/Inventory/Inventory.h" +#include "Server_Zone/Session.h" extern Core::Data::ExdData g_exdData; @@ -27,7 +27,6 @@ void Core::Entity::Player::finishQuest( uint16_t questId ) updateQuestsCompleted( questId ); sendQuestTracker(); - } void Core::Entity::Player::unfinishQuest( uint16_t questId ) @@ -72,7 +71,6 @@ void Core::Entity::Player::removeQuest( uint16_t questId ) } sendQuestTracker(); - } bool Core::Entity::Player::hasQuest( uint16_t questId ) @@ -408,7 +406,7 @@ uint16_t Core::Entity::Player::getQuestUI16A( uint16_t questId ) if( idx != -1 ) { boost::shared_ptr< QuestActive > pNewQuest = m_activeQuests[idx]; - // value = pNewQuest->d.UI16A; + // value = pNewQuest->d.UI16A; } return value; @@ -421,7 +419,7 @@ uint16_t Core::Entity::Player::getQuestUI16B( uint16_t questId ) if( idx != -1 ) { boost::shared_ptr< QuestActive > pNewQuest = m_activeQuests[idx]; - // value = pNewQuest->d.UI16B; + // value = pNewQuest->d.UI16B; } return value; @@ -434,7 +432,7 @@ uint16_t Core::Entity::Player::getQuestUI16C( uint16_t questId ) if( idx != -1 ) { boost::shared_ptr< QuestActive > pNewQuest = m_activeQuests[idx]; - // value = pNewQuest->d.UI16C; + // value = pNewQuest->d.UI16C; } return value; @@ -447,7 +445,7 @@ uint32_t Core::Entity::Player::getQuestUI32A( uint16_t questId ) if( idx != -1 ) { boost::shared_ptr< QuestActive > pNewQuest = m_activeQuests[idx]; - // value = pNewQuest->e.UI32A; + // value = pNewQuest->e.UI32A; } return value; @@ -713,7 +711,7 @@ void Core::Entity::Player::setQuestUI16A( uint16_t questId, uint16_t val ) { boost::shared_ptr< QuestActive > pNewQuest = m_activeQuests[idx]; - // pNewQuest->d.UI16A = val; + // pNewQuest->d.UI16A = val; updateQuest( questId, pNewQuest->c.sequence ); } @@ -728,7 +726,7 @@ void Core::Entity::Player::setQuestUI16B( uint16_t questId, uint16_t val ) { boost::shared_ptr< QuestActive > pNewQuest = m_activeQuests[idx]; - // pNewQuest->d.UI16B = val; + // pNewQuest->d.UI16B = val; updateQuest( questId, pNewQuest->c.sequence ); } @@ -742,7 +740,7 @@ void Core::Entity::Player::setQuestUI16C( uint16_t questId, uint16_t val ) { boost::shared_ptr< QuestActive > pNewQuest = m_activeQuests[idx]; -// pNewQuest->d.UI16C = val; + // pNewQuest->d.UI16C = val; updateQuest( questId, pNewQuest->c.sequence ); } @@ -756,7 +754,7 @@ void Core::Entity::Player::setQuestUI32A( uint16_t questId, uint32_t val ) { boost::shared_ptr< QuestActive > pNewQuest = m_activeQuests[idx]; - // pNewQuest->e.UI32A = val; + // pNewQuest->e.UI32A = val; updateQuest( questId, pNewQuest->c.sequence ); } @@ -845,8 +843,6 @@ void Core::Entity::Player::setQuestBitFlag48( uint16_t questId, uint8_t val ) } } - - uint8_t Core::Entity::Player::getQuestSeq( uint16_t questId ) { int8_t idx = getQuestIndex( questId ); @@ -870,7 +866,6 @@ void Core::Entity::Player::updateQuest( uint16_t questId, uint8_t sequence ) pe_qa.data().slot = index; pe_qa.data().questInfo = *pNewQuest; queuePacket( pe_qa ); - } else { @@ -911,7 +906,6 @@ void Core::Entity::Player::updateQuest( uint16_t questId, uint8_t sequence ) insertQuest( questId, idx, sequence ); sendQuestTracker(); - } } @@ -934,7 +928,7 @@ void Core::Entity::Player::setQuestTracker( uint16_t index, int16_t flag ) { if( flag == 0 ) { - //remove + // remove for( uint8_t ii = 0; ii < 5; ii++ ) { if( m_questTracking[ii] == index ) @@ -946,7 +940,7 @@ void Core::Entity::Player::setQuestTracker( uint16_t index, int16_t flag ) } else { - //add + // add for( uint8_t ii = 0; ii < 5; ii++ ) { if( m_questTracking[ii] == -1 ) @@ -956,10 +950,8 @@ void Core::Entity::Player::setQuestTracker( uint16_t index, int16_t flag ) } } } - } - void Core::Entity::Player::sendQuestInfo() { ZoneChannelPacket< FFXIVIpcQuestActiveList > pe_qa( getId() ); @@ -972,7 +964,6 @@ void Core::Entity::Player::sendQuestInfo() auto& quest = pe_qa.data().activeQuests[i]; quest = *m_activeQuests[i]; - } } @@ -985,12 +976,12 @@ void Core::Entity::Player::sendQuestInfo() sendQuestTracker(); } -void Core::Entity::Player::sendQuestMessage( uint32_t questId, int8_t msgId, uint8_t type, uint32_t var1, uint32_t var2 ) +void Core::Entity::Player::sendQuestMessage( uint32_t questId, int8_t msgId, uint8_t type, uint32_t var1, + uint32_t var2 ) { queuePacket( QuestMessagePacket( getAsPlayer(), questId, msgId, type, var1, var2 ) ); } - void Core::Entity::Player::updateQuestsCompleted( uint32_t questId ) { uint8_t index = questId / 8; @@ -1009,14 +1000,12 @@ void Core::Entity::Player::removeQuestsCompleted( uint32_t questId ) uint8_t value = 0x80 >> bitIndex; m_questCompleteFlags[index] ^= value; - } bool Core::Entity::Player::giveQuestRewards( uint32_t questId, uint32_t optionalChoice ) { uint32_t playerLevel = getLevel(); auto questInfo = g_exdData.getQuestInfo( questId ); - if( !questInfo ) return false; @@ -1024,7 +1013,8 @@ bool Core::Entity::Player::giveQuestRewards( uint32_t questId, uint32_t optional auto paramGrowth = g_exdData.m_paramGrowthInfoMap[questInfo->quest_level]; // TODO: use the correct formula, this one is wrong - uint32_t exp = ( questInfo->reward_exp_factor * paramGrowth.quest_exp_mod * ( 45 + 5 * questInfo->quest_level) ) / 100; + uint32_t exp = + ( questInfo->reward_exp_factor * paramGrowth.quest_exp_mod * ( 45 + 5 * questInfo->quest_level ) ) / 100; exp = exp + ( questInfo->reward_exp_factor / 100 ) * 10000; exp = questInfo->reward_exp_factor; @@ -1053,15 +1043,14 @@ bool Core::Entity::Player::giveQuestRewards( uint32_t questId, uint32_t optional // TODO: add the correct amount of items instead of 1 addItem( -1, itemId, questInfo->reward_item_optional_count.at( optionalChoice ) ); } - + if( gilReward > 0 ) addCurrency( 1, gilReward ); return true; } -boost::shared_ptr Core::Entity::Player::getQuestActive( uint16_t index ) +boost::shared_ptr< QuestActive > Core::Entity::Player::getQuestActive( uint16_t index ) { return m_activeQuests[index]; } - diff --git a/src/servers/Server_Zone/Actor/PlayerSql.cpp b/src/servers/Server_Zone/Actor/PlayerSql.cpp index d0c23880..1b6537cf 100644 --- a/src/servers/Server_Zone/Actor/PlayerSql.cpp +++ b/src/servers/Server_Zone/Actor/PlayerSql.cpp @@ -1,13 +1,12 @@ #include +#include +#include +#include +#include #include +#include #include #include -#include -#include -#include -#include -#include -#include #include #include @@ -16,24 +15,22 @@ #include "Player.h" -#include "Zone/ZoneMgr.h" #include "Zone/Zone.h" +#include "Zone/ZoneMgr.h" #include "ServerZone.h" #include "Forwards.h" +#include "Inventory/Inventory.h" #include "Network/GameConnection.h" #include "Network/PacketWrappers/InitUIPacket.h" -#include "Inventory/Inventory.h" - extern Core::Logger g_log; extern Core::ServerZone g_serverZone; extern Core::ZoneMgr g_zoneMgr; extern Core::Data::ExdData g_exdData; - using namespace Core::Common; using namespace Core::Network::Packets; using namespace Core::Network::Packets::Server; @@ -47,7 +44,7 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession ) stmt->setUInt( 1, charId ); auto res = g_charaDb.query( stmt ); - + if( !res->next() ) return false; @@ -155,7 +152,7 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession ) auto orchestrion = res->getBlobVector( "Orchestrion" ); memcpy( reinterpret_cast< char* >( m_orchestrion ), orchestrion.data(), orchestrion.size() ); - + auto gcRank = res->getBlobVector( "GrandCompanyRank" ); memcpy( reinterpret_cast< char* >( m_gcRank ), gcRank.data(), gcRank.size() ); @@ -183,7 +180,7 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession ) // first login, run the script event if( m_bNewGame ) { - //g_scriptMgr.onPlayerFirstEnterWorld( pPlayer ); + // g_scriptMgr.onPlayerFirstEnterWorld( pPlayer ); m_bNewGame = false; m_hp = getMaxHp(); m_mp = getMaxMp(); @@ -198,8 +195,8 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession ) if( m_hp == 0 ) m_status = ActorStatus::Dead; - // if( m_bNewAdventurer ) - // setStateFlag( PlayerStateFlag::NewAdventurer ); + // if( m_bNewAdventurer ) + // setStateFlag( PlayerStateFlag::NewAdventurer ); setStateFlag( PlayerStateFlag::BetweenAreas ); @@ -243,12 +240,9 @@ bool Core::Entity::Player::loadActiveQuests() m_questIdToQuestIdx[pActiveQuest->c.questId] = slotId; m_questIdxToQuestId[slotId] = pActiveQuest->c.questId; - - } return true; - } bool Core::Entity::Player::loadClassData() @@ -288,29 +282,28 @@ bool Core::Entity::Player::loadSearchInfo() return true; } - void Core::Entity::Player::updateSql() { - /*"Hp 1, Mp 2, Tp 3, Gp 4, Mode 5, Mount 6, InvincibleGM 7, Voice 8, " - "Customize 9, ModelMainWeapon 10, ModelSubWeapon 11, ModelSystemWeapon 12, " - "ModelEquip 13, EmoteModeType 14, Language 15, IsNewGame 16, IsNewAdventurer 17, " - "TerritoryType 18, TerritoryId 19, PosX 20, PosY 21, PosZ 22, PosR 23, " - "OTerritoryType 24, OTerritoryId 25, OPosX 26, OPosY 27, OPosZ 28, OPosR 29, " - "Class 30, Status 31, TotalPlayTime 32, HomePoint 33, FavoritePoint 34, RestPoint 35, " - "ActiveTitle 36, TitleList 37, Achievement 38, Aetheryte 39, HowTo 40, Minions 41, Mounts 42, Orchestrion 43, " - "EquippedMannequin 44, ConfigFlags 45, QuestCompleteFlags 46, OpeningSequence 47, " - "QuestTracking 48, GrandCompany 49, GrandCompanyRank 50, Discovery 51, GMRank 52, Unlocks 53, " - "CFPenaltyUntil 54"*/ + /*"Hp 1, Mp 2, Tp 3, Gp 4, Mode 5, Mount 6, InvincibleGM 7, Voice 8, " + "Customize 9, ModelMainWeapon 10, ModelSubWeapon 11, ModelSystemWeapon 12, " + "ModelEquip 13, EmoteModeType 14, Language 15, IsNewGame 16, IsNewAdventurer 17, " + "TerritoryType 18, TerritoryId 19, PosX 20, PosY 21, PosZ 22, PosR 23, " + "OTerritoryType 24, OTerritoryId 25, OPosX 26, OPosY 27, OPosZ 28, OPosR 29, " + "Class 30, Status 31, TotalPlayTime 32, HomePoint 33, FavoritePoint 34, RestPoint 35, " + "ActiveTitle 36, TitleList 37, Achievement 38, Aetheryte 39, HowTo 40, Minions 41, Mounts 42, Orchestrion 43, " + "EquippedMannequin 44, ConfigFlags 45, QuestCompleteFlags 46, OpeningSequence 47, " + "QuestTracking 48, GrandCompany 49, GrandCompanyRank 50, Discovery 51, GMRank 52, Unlocks 53, " + "CFPenaltyUntil 54"*/ auto stmt = g_charaDb.getPreparedStatement( Db::CharaDbStatements::CHARA_UP ); stmt->setInt( 1, getHp() ); stmt->setInt( 2, getMp() ); - stmt->setInt( 3, 0 ); // TP - stmt->setInt( 4, 0 ); // GP - stmt->setInt( 5, 0 ); // Mode + stmt->setInt( 3, 0 ); // TP + stmt->setInt( 4, 0 ); // GP + stmt->setInt( 5, 0 ); // Mode stmt->setInt( 6, m_mount ); // Mount - stmt->setInt( 7, 0 ); // InvicibleGM + stmt->setInt( 7, 0 ); // InvicibleGM stmt->setInt( 8, m_voice ); std::vector< uint8_t > customVec( sizeof( m_customize ) ); @@ -331,7 +324,7 @@ void Core::Entity::Player::updateSql() stmt->setInt( 16, static_cast< uint32_t >( m_bNewGame ) ); stmt->setInt( 17, static_cast< uint32_t >( m_bNewAdventurer ) ); - stmt->setInt( 18, 0 ); // TerritoryType + stmt->setInt( 18, 0 ); // TerritoryType stmt->setInt( 19, m_zoneId ); // TerritoryId stmt->setDouble( 20, m_pos.x ); stmt->setDouble( 21, m_pos.y ); @@ -351,10 +344,10 @@ void Core::Entity::Player::updateSql() stmt->setInt( 33, m_homePoint ); stmt->setBinary( 34, { 0, 0, 0 } ); // FavoritePoint - stmt->setInt( 35, 0 ); // RestPoint - stmt->setInt( 36, 0 ); // ActiveTitle + stmt->setInt( 35, 0 ); // RestPoint + stmt->setInt( 36, 0 ); // ActiveTitle - std::vector< uint8_t > titleListVec( sizeof ( m_titleList ) ); + std::vector< uint8_t > titleListVec( sizeof( m_titleList ) ); stmt->setBinary( 37, titleListVec ); std::vector< uint8_t > achievementVec( 16 ); @@ -421,14 +414,13 @@ void Core::Entity::Player::updateSql() ////// Class updateDbClass(); - } void Core::Entity::Player::updateDbClass() const { uint8_t classJobIndex = g_exdData.m_classJobInfoMap[static_cast< uint8_t >( getClass() )].exp_idx; - //Exp = ?, Lvl = ? WHERE CharacterId = ? AND ClassIdx = ? + // Exp = ?, Lvl = ? WHERE CharacterId = ? AND ClassIdx = ? auto stmtS = g_charaDb.getPreparedStatement( Db::CHARA_CLASS_UP ); stmtS->setInt( 1, getExp() ); stmtS->setInt( 2, getLevel() ); @@ -473,10 +465,9 @@ void Core::Entity::Player::updateDbAllQuests() const stmtS3->setInt( 7, m_activeQuests[i]->c.UI8E ); stmtS3->setInt( 8, m_activeQuests[i]->c.UI8F ); stmtS3->setInt( 9, m_activeQuests[i]->c.padding1 ); - stmtS3->setInt( 10, m_id); + stmtS3->setInt( 10, m_id ); stmtS3->setInt( 11, m_activeQuests[i]->c.questId ); g_charaDb.execute( stmtS3 ); - } } diff --git a/src/servers/Server_Zone/ContentFinder/ContentFinder.h b/src/servers/Server_Zone/ContentFinder/ContentFinder.h index c0800273..a7a6ae33 100644 --- a/src/servers/Server_Zone/ContentFinder/ContentFinder.h +++ b/src/servers/Server_Zone/ContentFinder/ContentFinder.h @@ -3,5 +3,4 @@ #include "../Forwards.h" - #endif diff --git a/src/servers/Server_Zone/DebugCommand/DebugCommand.h b/src/servers/Server_Zone/DebugCommand/DebugCommand.h index c6131a75..13335a45 100644 --- a/src/servers/Server_Zone/DebugCommand/DebugCommand.h +++ b/src/servers/Server_Zone/DebugCommand/DebugCommand.h @@ -8,57 +8,42 @@ namespace Core { - class DebugCommandHandler; +class DebugCommandHandler; - class DebugCommand - { - public: +class DebugCommand +{ +public: + using pFunc = void ( DebugCommandHandler::* )( char*, Entity::Player&, boost::shared_ptr< DebugCommand > ); - using pFunc = void ( DebugCommandHandler::* )( char *, Entity::Player&, boost::shared_ptr< DebugCommand > ); + // String for the command + std::string m_commandName; - // String for the command - std::string m_commandName; + // command callback + pFunc m_pFunc; - // command callback - pFunc m_pFunc; + // helptext + std::string m_helpText; - // helptext - std::string m_helpText; + // userlevel needed to execute the command + uint8_t m_gmLevel; - // userlevel needed to execute the command - uint8_t m_gmLevel; + DebugCommand( const std::string& n, pFunc functionPtr, const std::string& hText, uint8_t uLevel ) + { + m_commandName = n; + m_pFunc = functionPtr; + m_helpText = hText; + m_gmLevel = uLevel; + } - DebugCommand( const std::string& n, pFunc functionPtr, const std::string& hText, uint8_t uLevel ) - { - m_commandName = n; - m_pFunc = functionPtr; - m_helpText = hText; - m_gmLevel = uLevel; - } + ~DebugCommand() {} - ~DebugCommand() - { + const std::string& getName() const { return m_commandName; } - } + const std::string& getHelpText() const { return m_helpText; } - const std::string& getName() const - { - return m_commandName; - } - - const std::string& getHelpText() const - { - return m_helpText; - } - - uint8_t getRequiredGmLevel() const - { - return m_gmLevel; - } - - }; - -} + uint8_t getRequiredGmLevel() const { return m_gmLevel; } +}; +} // namespace Core #endif diff --git a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp index 55b63d1d..ab57bec6 100644 --- a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp +++ b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp @@ -1,37 +1,36 @@ #include #include -#include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include #include "DebugCommand.h" #include "DebugCommandHandler.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" +#include "Network/GameConnection.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/InitUIPacket.h" -#include "Network/GameConnection.h" +#include "Network/PacketWrappers/ServerNoticePacket.h" #include "Script/ScriptManager.h" -#include "Actor/Player.h" #include "Actor/BattleNpc.h" +#include "Actor/Player.h" #include "Zone/Zone.h" #include "ServerZone.h" -#include "StatusEffect/StatusEffect.h" #include "Session.h" +#include "StatusEffect/StatusEffect.h" #include - #include extern Core::Scripting::ScriptManager g_scriptMgr; @@ -70,11 +69,11 @@ void Core::DebugCommandHandler::registerCommand( const std::string& n, DebugComm } // try to retrieve the command in question, execute if found -void Core::DebugCommandHandler::execCommand( char * data, Entity::Player& player ) +void Core::DebugCommandHandler::execCommand( char* data, Entity::Player& player ) { // define callback pointer - void ( DebugCommandHandler::*pf )( char *, Entity::Player&, boost::shared_ptr< DebugCommand > ); + void ( DebugCommandHandler::*pf )( char*, Entity::Player&, boost::shared_ptr< DebugCommand > ); std::string commandString; @@ -108,16 +107,13 @@ void Core::DebugCommandHandler::execCommand( char * data, Entity::Player& player ( this->*pf )( data, player, ( *it ).second ); return; } - - } - /////////////////////////////////////////////////////////////////////////////////////// // Definition of the commands /////////////////////////////////////////////////////////////////////////////////////// -void Core::DebugCommandHandler::scriptReload( char * data, Entity::Player& player, +void Core::DebugCommandHandler::scriptReload( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) { g_scriptMgr.reload(); @@ -127,16 +123,16 @@ void Core::DebugCommandHandler::scriptReload( char * data, Entity::Player& playe void Core::DebugCommandHandler::help( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) { player.sendDebug( "Registered debug commands:" ); - for ( auto cmd : m_commandMap ) + for( auto cmd : m_commandMap ) { - if ( player.getGmRank( ) >= cmd.second->m_gmLevel ) + if( player.getGmRank() >= cmd.second->m_gmLevel ) { - player.sendDebug( " - " + cmd.first + " - " + cmd.second->getHelpText( ) ); + player.sendDebug( " - " + cmd.first + " - " + cmd.second->getHelpText() ); } } } -void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) +void Core::DebugCommandHandler::set( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) { std::string subCommand = ""; std::string params = ""; @@ -156,9 +152,7 @@ void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost: if( command->getName().length() + 1 + pos + 1 < strlen( data ) ) params = std::string( data + command->getName().length() + 1 + pos + 1 ); - g_log.debug( "[" + std::to_string( player.getId() ) + "] " + - "subCommand " + subCommand + " params: " + params ); - + g_log.debug( "[" + std::to_string( player.getId() ) + "] " + "subCommand " + subCommand + " params: " + params ); if( ( ( subCommand == "pos" ) || ( subCommand == "posr" ) ) && ( params != "" ) ) { @@ -175,21 +169,18 @@ void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost: } if( subCommand == "pos" ) - player.setPosition( static_cast< float >( posX ), - static_cast< float >( posY ), - static_cast< float >( posZ ) ); + player.setPosition( static_cast< float >( posX ), static_cast< float >( posY ), static_cast< float >( posZ ) ); else player.setPosition( player.getPos().x + static_cast< float >( posX ), player.getPos().y + static_cast< float >( posY ), player.getPos().z + static_cast< float >( posZ ) ); - Network::Packets::ZoneChannelPacket< Network::Packets::Server::FFXIVIpcActorSetPos > - setActorPosPacket( player.getId() ); + Network::Packets::ZoneChannelPacket< Network::Packets::Server::FFXIVIpcActorSetPos > setActorPosPacket( + player.getId() ); setActorPosPacket.data().x = player.getPos().x; setActorPosPacket.data().y = player.getPos().y; setActorPosPacket.data().z = player.getPos().z; player.queuePacket( setActorPosPacket ); - } else if( ( subCommand == "tele" ) && ( params != "" ) ) { @@ -204,7 +195,8 @@ void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost: int32_t discover_id; sscanf( params.c_str(), "%i %i", &map_id, &discover_id ); - Network::Packets::ZoneChannelPacket< Network::Packets::Server::FFXIVIpcDiscovery > discoveryPacket( player.getId() ); + Network::Packets::ZoneChannelPacket< Network::Packets::Server::FFXIVIpcDiscovery > discoveryPacket( + player.getId() ); discoveryPacket.data().map_id = map_id; discoveryPacket.data().map_part_id = discover_id; player.queuePacket( discoveryPacket ); @@ -218,15 +210,14 @@ void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost: sscanf( params.c_str(), "%i %i %i", &pos_id, &map_id, &discover_id ); std::string query2 = "UPDATE IGNORE `discoveryinfo` SET `discover_id` = '" + std::to_string( discover_id ) + - "' WHERE `discoveryinfo`.`id` = " + std::to_string( pos_id ) + ";"; + "' WHERE `discoveryinfo`.`id` = " + std::to_string( pos_id ) + ";"; - std::string query1 = "INSERT IGNORE INTO `discoveryinfo` (`id`, `map_id`, `discover_id`) VALUES ('" + std::to_string( pos_id ) + - "', '" + std::to_string( map_id ) + - "', '" + std::to_string( discover_id ) + "')"; + std::string query1 = "INSERT IGNORE INTO `discoveryinfo` (`id`, `map_id`, `discover_id`) VALUES ('" + + std::to_string( pos_id ) + "', '" + std::to_string( map_id ) + "', '" + + std::to_string( discover_id ) + "')"; g_charaDb.execute( query1 ); g_charaDb.execute( query2 ); - } else if( subCommand == "discovery_reset" ) @@ -236,26 +227,26 @@ void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost: } else if( subCommand == "classjob" ) { - int32_t id; + int32_t id; - sscanf( params.c_str(), "%d", &id ); + sscanf( params.c_str(), "%d", &id ); - if( player.getLevelForClass( static_cast< Common::ClassJob > ( id ) ) == 0 ) - { - player.setLevelForClass( 1, static_cast< Common::ClassJob > ( id ) ); - player.setClassJob( static_cast< Common::ClassJob > ( id ) ); - } - else - player.setClassJob( static_cast< Common::ClassJob > ( id ) ); + if( player.getLevelForClass( static_cast< Common::ClassJob >( id ) ) == 0 ) + { + player.setLevelForClass( 1, static_cast< Common::ClassJob >( id ) ); + player.setClassJob( static_cast< Common::ClassJob >( id ) ); + } + else + player.setClassJob( static_cast< Common::ClassJob >( id ) ); } - else if ( subCommand == "cfpenalty" ) + else if( subCommand == "cfpenalty" ) { int32_t minutes; sscanf( params.c_str(), "%d", &minutes ); player.setCFPenaltyMinutes( minutes ); } - else if ( subCommand == "eorzeatime" ) + else if( subCommand == "eorzeatime" ) { uint64_t timestamp; sscanf( params.c_str(), "%" SCNu64, ×tamp ); @@ -263,7 +254,7 @@ void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost: player.setEorzeaTimeOffset( timestamp ); player.sendNotice( "Eorzea time offset: " + std::to_string( timestamp ) ); } - else if ( subCommand == "model" ) + else if( subCommand == "model" ) { uint32_t slot; uint32_t val; @@ -273,7 +264,7 @@ void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost: player.sendModel(); player.sendDebug( "Model updated" ); } - else if ( subCommand == "mount" ) + else if( subCommand == "mount" ) { int32_t id; sscanf( params.c_str(), "%d", &id ); @@ -285,10 +276,9 @@ void Core::DebugCommandHandler::set( char * data, Entity::Player& player, boost: { player.sendUrgent( subCommand + " is not a valid SET command." ); } - } -void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) +void Core::DebugCommandHandler::add( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) { std::string subCommand; std::string params = ""; @@ -311,9 +301,7 @@ void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost: if( command->getName().length() + 1 + pos + 1 < strlen( data ) ) params = std::string( data + command->getName().length() + 1 + pos + 1 ); - g_log.debug( "[" + std::to_string( player.getId() ) + "] " + - "subCommand " + subCommand + " params: " + params ); - + g_log.debug( "[" + std::to_string( player.getId() ) + "] " + "subCommand " + subCommand + " params: " + params ); if( subCommand == "status" ) { @@ -323,7 +311,8 @@ void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost: sscanf( params.c_str(), "%d %d %hu", &id, &duration, ¶m ); - StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, player.getAsPlayer(), player.getAsPlayer(), duration, 3000 ) ); + StatusEffect::StatusEffectPtr effect( + new StatusEffect::StatusEffect( id, player.getAsPlayer(), player.getAsPlayer(), duration, 3000 ) ); effect->setParam( param ); player.addStatusEffect( effect ); @@ -347,14 +336,14 @@ void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost: auto pZone = player.getCurrentZone(); pBNpc->setCurrentZone( pZone ); pZone->pushActor( pBNpc ); - } else if( subCommand == "op" ) { // temporary research packet int32_t opcode; sscanf( params.c_str(), "%x", &opcode ); - Network::Packets::GamePacketPtr pPe( new Network::Packets::GamePacket( opcode, 0x30, player.getId(), player.getId() ) ); + Network::Packets::GamePacketPtr pPe( + new Network::Packets::GamePacket( opcode, 0x30, player.getId(), player.getId() ) ); player.queuePacket( pPe ); } else if( subCommand == "actrl" ) @@ -371,11 +360,13 @@ void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost: int32_t param6; int32_t playerId; - sscanf( params.c_str(), "%x %x %x %x %x %x %x %x", &opcode, ¶m1, ¶m2, ¶m3, ¶m4, ¶m5, ¶m6, &playerId ); + sscanf( params.c_str(), "%x %x %x %x %x %x %x %x", &opcode, ¶m1, ¶m2, ¶m3, ¶m4, ¶m5, ¶m6, + &playerId ); player.sendNotice( "Injecting ACTOR_CONTROL " + std::to_string( opcode ) ); - Network::Packets::ZoneChannelPacket< Network::Packets::Server::FFXIVIpcActorControl143 > actorControl( playerId, player.getId() ); + Network::Packets::ZoneChannelPacket< Network::Packets::Server::FFXIVIpcActorControl143 > actorControl( + playerId, player.getId() ); actorControl.data().category = opcode; actorControl.data().param1 = param1; actorControl.data().param2 = param2; @@ -385,27 +376,25 @@ void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost: actorControl.data().param6 = param6; player.queuePacket( actorControl ); + /*sscanf(params.c_str(), "%x %x %x %x %x %x %x", &opcode, ¶m1, ¶m2, ¶m3, ¶m4, ¶m5, ¶m6, + &playerId); - /*sscanf(params.c_str(), "%x %x %x %x %x %x %x", &opcode, ¶m1, ¶m2, ¶m3, ¶m4, ¶m5, ¶m6, &playerId); - - Network::Packets::Server::ServerNoticePacket noticePacket( player, "Injecting ACTOR_CONTROL " + std::to_string( opcode ) ); + Network::Packets::Server::ServerNoticePacket noticePacket( player, "Injecting ACTOR_CONTROL " + std::to_string( + opcode ) ); player.queuePacket( noticePacket ); Network::Packets::Server::ActorControlPacket143 controlPacket( player, opcode, param1, param2, param3, param4, param5, param6, playerId ); player.queuePacket( controlPacket );*/ - } else { player.sendUrgent( subCommand + " is not a valid ADD command." ); } - - } -void Core::DebugCommandHandler::get( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) +void Core::DebugCommandHandler::get( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) { std::string subCommand; std::string params = ""; @@ -425,45 +414,41 @@ void Core::DebugCommandHandler::get( char * data, Entity::Player& player, boost: if( command->getName().length() + 1 + pos + 1 < strlen( data ) ) params = std::string( data + command->getName().length() + 1 + pos + 1 ); - g_log.debug( "[" + std::to_string( player.getId() ) + "] " + - "subCommand " + subCommand + " params: " + params ); - + g_log.debug( "[" + std::to_string( player.getId() ) + "] " + "subCommand " + subCommand + " params: " + params ); if( ( subCommand == "pos" ) ) { int16_t map_id = g_exdData.m_zoneInfoMap[player.getCurrentZone()->getId()].map_id; - player.sendNotice( "Pos:\n" + - std::to_string( player.getPos().x ) + "\n" + - std::to_string( player.getPos().y ) + "\n" + - std::to_string( player.getPos().z ) + "\n" + - std::to_string( player.getRotation() ) + "\nMapId: " + - std::to_string( map_id ) + "\nZoneID: " + - std::to_string( player.getCurrentZone()->getId() ) + "\n" ); + player.sendNotice( "Pos:\n" + std::to_string( player.getPos().x ) + "\n" + std::to_string( player.getPos().y ) + + "\n" + std::to_string( player.getPos().z ) + "\n" + std::to_string( player.getRotation() ) + + "\nMapId: " + std::to_string( map_id ) + + "\nZoneID: " + std::to_string( player.getCurrentZone()->getId() ) + "\n" ); } else { player.sendUrgent( subCommand + " is not a valid GET command." ); } - } -void Core::DebugCommandHandler::injectPacket( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) +void Core::DebugCommandHandler::injectPacket( char* data, Entity::Player& player, + boost::shared_ptr< DebugCommand > command ) { auto pSession = g_serverZone.getSession( player.getId() ); if( pSession ) pSession->getZoneConnection()->injectPacket( data + 7, player ); } -void Core::DebugCommandHandler::injectChatPacket( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) +void Core::DebugCommandHandler::injectChatPacket( char* data, Entity::Player& player, + boost::shared_ptr< DebugCommand > command ) { auto pSession = g_serverZone.getSession( player.getId() ); if( pSession ) pSession->getChatConnection()->injectPacket( data + 8, player ); } -void Core::DebugCommandHandler::nudge( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) +void Core::DebugCommandHandler::nudge( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) { std::string subCommand; @@ -489,7 +474,6 @@ void Core::DebugCommandHandler::nudge( char * data, Entity::Player& player, boos { pos.y -= offset; player.sendNotice( "nudge: Placing down " + std::to_string( offset ) + " yalms" ); - } else { @@ -500,8 +484,8 @@ void Core::DebugCommandHandler::nudge( char * data, Entity::Player& player, boos } if( offset != 0 ) { - Network::Packets::ZoneChannelPacket< Network::Packets::Server::FFXIVIpcActorSetPos > - setActorPosPacket( player.getId() ); + Network::Packets::ZoneChannelPacket< Network::Packets::Server::FFXIVIpcActorSetPos > setActorPosPacket( + player.getId() ); setActorPosPacket.data().x = player.getPos().x; setActorPosPacket.data().y = player.getPos().y; setActorPosPacket.data().z = player.getPos().z; @@ -510,14 +494,16 @@ void Core::DebugCommandHandler::nudge( char * data, Entity::Player& player, boos } } -void Core::DebugCommandHandler::serverInfo( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) +void Core::DebugCommandHandler::serverInfo( char* data, Entity::Player& player, + boost::shared_ptr< DebugCommand > command ) { player.sendDebug( "SapphireServer " + Version::VERSION + "\nRev: " + Version::GIT_HASH ); player.sendDebug( "Compiled: " __DATE__ " " __TIME__ ); player.sendDebug( "Sessions: " + std::to_string( g_serverZone.getSessionCount() ) ); } -void Core::DebugCommandHandler::unlockCharacter( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ) +void Core::DebugCommandHandler::unlockCharacter( char* data, Entity::Player& player, + boost::shared_ptr< DebugCommand > command ) { - player.unlock( ); + player.unlock(); } diff --git a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h index fb30cc99..2af61e4e 100644 --- a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h +++ b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h @@ -4,12 +4,11 @@ #include #include "DebugCommand.h" -#include #include "Forwards.h" +#include namespace Core { - // handler for in game commands class DebugCommandHandler { @@ -25,27 +24,26 @@ public: void registerCommand( const std::string& n, DebugCommand::pFunc, const std::string& hText, uint8_t uLevel ); // execute command if registered - void execCommand( char * data, Entity::Player& player ); + void execCommand( char* data, Entity::Player& player ); // help command void help( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); // command handler callbacks - void set( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); - void get( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); - void add( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); - //void debug( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); - void scriptReload( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); + void set( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); + void get( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); + void add( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); + // void debug( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); + void scriptReload( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); - void injectPacket( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); - void injectChatPacket( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); + void injectPacket( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); + void injectChatPacket( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); void nudge( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); - void serverInfo( char * data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); + void serverInfo( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); void unlockCharacter( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); void targetInfo( char* data, Entity::Player& player, boost::shared_ptr< DebugCommand > command ); - }; -} +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Event/Event.cpp b/src/servers/Server_Zone/Event/Event.cpp index ee1a3f6e..b6758eed 100644 --- a/src/servers/Server_Zone/Event/Event.cpp +++ b/src/servers/Server_Zone/Event/Event.cpp @@ -1,11 +1,12 @@ #include "Event.h" -Core::Event::Event::Event( uint64_t actorId, uint32_t eventId, uint8_t eventType, uint8_t eventParam2, uint32_t eventParam3 ) - : m_actorId( actorId ), - m_eventId( eventId ), - m_playedScene( false ) +Core::Event::Event::Event( uint64_t actorId, uint32_t eventId, uint8_t eventType, uint8_t eventParam2, + uint32_t eventParam3 ) : + m_actorId( actorId ), + m_eventId( eventId ), + m_playedScene( false ) { - + m_param1 = static_cast< uint16_t >( eventId ); m_param2 = static_cast< uint16_t >( eventId >> 16 ); @@ -61,7 +62,6 @@ void Core::Event::Event::setEventReturnCallback( Scripting::EventReturnCallback m_callback = callback; } - bool Core::Event::Event::hasPlayedScene() const { return m_playedScene; diff --git a/src/servers/Server_Zone/Event/Event.h b/src/servers/Server_Zone/Event/Event.h index 8935cd22..18babd77 100644 --- a/src/servers/Server_Zone/Event/Event.h +++ b/src/servers/Server_Zone/Event/Event.h @@ -4,75 +4,75 @@ #include "../Forwards.h" namespace Core { - namespace Event { +namespace Event { - class Event + class Event + { + public: + Event( uint64_t actorId, uint32_t eventId, uint8_t eventType, uint8_t eventParam2, uint32_t eventParam3 ); + + ~Event() {} + + uint64_t getActorId() const; + + uint32_t getId() const; + + uint32_t getParam1() const; + + uint16_t getParam2() const; + + uint8_t getEventType() const; + + uint32_t getEventParam2() const; + + uint32_t getEventParam3() const; + + bool hasPlayedScene() const; + + void setPlayedScene( bool playedScene ); + + Scripting::EventReturnCallback getEventReturnCallback() const; + + void setEventReturnCallback( Scripting::EventReturnCallback callback ); + + enum EventType : uint8_t { - public: - Event( uint64_t actorId, uint32_t eventId, uint8_t eventType, uint8_t eventParam2, uint32_t eventParam3 ); - - ~Event() {} - - uint64_t getActorId() const; - - uint32_t getId() const; - - uint32_t getParam1() const; - - uint16_t getParam2() const; - - uint8_t getEventType() const; - - uint32_t getEventParam2() const; - - uint32_t getEventParam3() const; - - bool hasPlayedScene() const; - - void setPlayedScene( bool playedScene ); - - Scripting::EventReturnCallback getEventReturnCallback() const; - - void setEventReturnCallback( Scripting::EventReturnCallback callback ); - - enum EventType : uint8_t - { - Talk = 1, - Emote = 2, - DistanceBelow = 3, - DistanceOver = 4, - BattleReward = 5, - Craft = 6, - Nest = 7, - Item = 8, - Drop = 9, - WithinRange = 10, - OutsideRange = 11, - GameStart = 12, - GameProgress = 13, - EnterTerritory = 15, - GameComeBack = 17, - ActionResult = 18, - MateriaCraft = 19, - Fishing = 20, - UI = 21, - Housing = 22, - Say = 23, - TableGame = 24, - }; - - protected: - uint64_t m_actorId; - uint32_t m_eventId; - uint32_t m_param1; - uint16_t m_param2; - uint8_t m_eventType; - uint8_t m_eventParam2; - uint32_t m_eventParam3; - bool m_playedScene; - Scripting::EventReturnCallback m_callback; + Talk = 1, + Emote = 2, + DistanceBelow = 3, + DistanceOver = 4, + BattleReward = 5, + Craft = 6, + Nest = 7, + Item = 8, + Drop = 9, + WithinRange = 10, + OutsideRange = 11, + GameStart = 12, + GameProgress = 13, + EnterTerritory = 15, + GameComeBack = 17, + ActionResult = 18, + MateriaCraft = 19, + Fishing = 20, + UI = 21, + Housing = 22, + Say = 23, + TableGame = 24, }; - } -} + protected: + uint64_t m_actorId; + uint32_t m_eventId; + uint32_t m_param1; + uint16_t m_param2; + uint8_t m_eventType; + uint8_t m_eventParam2; + uint32_t m_eventParam3; + bool m_playedScene; + Scripting::EventReturnCallback m_callback; + }; + +} // namespace Event +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Event/EventHelper.h b/src/servers/Server_Zone/Event/EventHelper.h index e8c531f2..2ac36eaa 100644 --- a/src/servers/Server_Zone/Event/EventHelper.h +++ b/src/servers/Server_Zone/Event/EventHelper.h @@ -5,12 +5,12 @@ #include namespace Core { - namespace Event { +namespace Event { - std::string getEventName( uint32_t eventId ); + std::string getEventName( uint32_t eventId ); - uint32_t mapEventActorToRealActor( uint32_t eventActorId ); + uint32_t mapEventActorToRealActor( uint32_t eventActorId ); - } -} +} // namespace Event +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Forwards.h b/src/servers/Server_Zone/Forwards.h index 2eaaa75e..eeaea464 100644 --- a/src/servers/Server_Zone/Forwards.h +++ b/src/servers/Server_Zone/Forwards.h @@ -4,78 +4,68 @@ #include #include -#define TYPE_FORWARD( x ) \ -class x; \ -typedef boost::shared_ptr< x > x ## Ptr; \ -typedef std::vector< x > x ## PtrList; +#define TYPE_FORWARD( x ) \ + class x; \ + typedef boost::shared_ptr< x > x##Ptr; \ + typedef std::vector< x > x##PtrList; -namespace Core -{ - TYPE_FORWARD( Cell ); - TYPE_FORWARD( Zone ); - TYPE_FORWARD( Item ); - TYPE_FORWARD( ItemContainer ); - TYPE_FORWARD( Inventory ); - TYPE_FORWARD( Session ); - TYPE_FORWARD( XMLConfig ); - TYPE_FORWARD( ZonePosition ) +namespace Core { +TYPE_FORWARD( Cell ); +TYPE_FORWARD( Zone ); +TYPE_FORWARD( Item ); +TYPE_FORWARD( ItemContainer ); +TYPE_FORWARD( Inventory ); +TYPE_FORWARD( Session ); +TYPE_FORWARD( XMLConfig ); +TYPE_FORWARD( ZonePosition ) - namespace StatusEffect - { - TYPE_FORWARD( StatusEffect ); - TYPE_FORWARD( StatusEffectContainer ); - } +namespace StatusEffect { + TYPE_FORWARD( StatusEffect ); + TYPE_FORWARD( StatusEffectContainer ); +} // namespace StatusEffect - namespace Entity - { - TYPE_FORWARD( Actor ); - TYPE_FORWARD( Player ); - TYPE_FORWARD( BattleNpc ); - TYPE_FORWARD( BattleNpcTemplate ); - } - - namespace Event - { - TYPE_FORWARD( Event ); - } - - namespace Action - { - TYPE_FORWARD( Action ); - TYPE_FORWARD( ActionTeleport ); - TYPE_FORWARD( ActionCast ); - TYPE_FORWARD( ActionMount ); - TYPE_FORWARD( EventAction ); - } - - namespace Network - { - TYPE_FORWARD( Hive ); - TYPE_FORWARD( Acceptor ); - TYPE_FORWARD( Connection ); - TYPE_FORWARD( GameConnection ); - TYPE_FORWARD( SessionConnection ); - TYPE_FORWARD( CustomMsgClientConnection ); - - namespace Packets - { - TYPE_FORWARD( GamePacket ); - } - } - - namespace ContentFinder - { - TYPE_FORWARD( ContentFinder ); - } - - namespace Scripting - { - typedef std::function< void( Entity::Player&, uint32_t, uint16_t, uint16_t, uint16_t ) > EventReturnCallback; - } - - typedef std::function< void( Entity::Player&, uint32_t, uint64_t ) > ActionCallback; +namespace Entity { + TYPE_FORWARD( Actor ); + TYPE_FORWARD( Player ); + TYPE_FORWARD( BattleNpc ); + TYPE_FORWARD( BattleNpcTemplate ); +} // namespace Entity +namespace Event { + TYPE_FORWARD( Event ); } +namespace Action { + TYPE_FORWARD( Action ); + TYPE_FORWARD( ActionTeleport ); + TYPE_FORWARD( ActionCast ); + TYPE_FORWARD( ActionMount ); + TYPE_FORWARD( EventAction ); +} // namespace Action + +namespace Network { + TYPE_FORWARD( Hive ); + TYPE_FORWARD( Acceptor ); + TYPE_FORWARD( Connection ); + TYPE_FORWARD( GameConnection ); + TYPE_FORWARD( SessionConnection ); + TYPE_FORWARD( CustomMsgClientConnection ); + + namespace Packets { + TYPE_FORWARD( GamePacket ); + } +} // namespace Network + +namespace ContentFinder { + TYPE_FORWARD( ContentFinder ); +} + +namespace Scripting { + typedef std::function< void( Entity::Player&, uint32_t, uint16_t, uint16_t, uint16_t ) > EventReturnCallback; +} + +typedef std::function< void( Entity::Player&, uint32_t, uint64_t ) > ActionCallback; + +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Inventory/Inventory.cpp b/src/servers/Server_Zone/Inventory/Inventory.cpp index ee982043..38399b0d 100644 --- a/src/servers/Server_Zone/Inventory/Inventory.cpp +++ b/src/servers/Server_Zone/Inventory/Inventory.cpp @@ -1,19 +1,19 @@ -#include #include #include #include +#include #include "Inventory.h" #include "Actor/Player.h" -#include "ItemContainer.h" #include "Item.h" +#include "ItemContainer.h" #include "Network/PacketWrappers/ServerNoticePacket.h" -#include #include +#include #include "../Forwards.h" #include "Network/PacketWrappers/ActorControlPacket143.h" @@ -35,8 +35,9 @@ Core::Inventory::Inventory( Core::Entity::Player* pOwner ) // shortcut for setting up inventory // TODO: use a loop to set theese up? - auto setupContainer = []( InventoryMap& map, InventoryType type ) - { map[type] = ItemContainerPtr( new ItemContainer( type ) ); }; + auto setupContainer = []( InventoryMap& map, InventoryType type ) { + map[type] = ItemContainerPtr( new ItemContainer( type ) ); + }; // main bags setupContainer( m_inventoryMap, Bag0 ); @@ -52,8 +53,8 @@ Core::Inventory::Inventory( Core::Entity::Player* pOwner ) // crystals?? setupContainer( m_inventoryMap, Crystal ); - //m_inventoryMap[0x07D3] = ItemContainerPtr( new ItemContainer( UNKNOWN_0 ) ); - //m_inventoryMap[0x07D8] = ItemContainerPtr( new ItemContainer( UNKNOWN_1 ) ); + // m_inventoryMap[0x07D3] = ItemContainerPtr( new ItemContainer( UNKNOWN_0 ) ); + // m_inventoryMap[0x07D8] = ItemContainerPtr( new ItemContainer( UNKNOWN_1 ) ); // armory weapons - 0 setupContainer( m_inventoryMap, ArmoryMain ); @@ -61,41 +62,40 @@ Core::Inventory::Inventory( Core::Entity::Player* pOwner ) // armory offhand - 1 setupContainer( m_inventoryMap, ArmoryOff ); - //armory head - 2 + // armory head - 2 setupContainer( m_inventoryMap, ArmoryHead ); - //armory body - 3 + // armory body - 3 setupContainer( m_inventoryMap, ArmoryBody ); - //armory hand - 4 + // armory hand - 4 setupContainer( m_inventoryMap, ArmoryHand ); - //armory waist - 5 + // armory waist - 5 setupContainer( m_inventoryMap, ArmoryWaist ); - //armory legs - 6 + // armory legs - 6 setupContainer( m_inventoryMap, ArmoryLegs ); - //armory feet - 7 + // armory feet - 7 setupContainer( m_inventoryMap, ArmoryFeet ); - //neck + // neck setupContainer( m_inventoryMap, ArmotyNeck ); - //earring + // earring setupContainer( m_inventoryMap, ArmoryEar ); - //wrist + // wrist setupContainer( m_inventoryMap, ArmoryWrist ); - //armory rings - 11 + // armory rings - 11 setupContainer( m_inventoryMap, ArmoryRing ); - //soul crystals - 13 + // soul crystals - 13 setupContainer( m_inventoryMap, ArmorySoulCrystal ); } - Core::Inventory::~Inventory() { } @@ -157,17 +157,13 @@ Core::ItemPtr Core::Inventory::createItem( uint32_t catalogId, uint8_t quantity pItem->setCategory( static_cast< ItemUICategory >( itemInfo->ui_category ) ); g_charaDb.execute( "INSERT INTO charaglobalitem ( CharacterId, itemId, catalogId, stack, flags ) VALUES ( " + - std::to_string( m_pOwner->getId() ) + ", " + - std::to_string( pItem->getUId() ) + ", " + - std::to_string( pItem->getId() ) + ", " + - std::to_string( itemAmount ) + ", " + + std::to_string( m_pOwner->getId() ) + ", " + std::to_string( pItem->getUId() ) + ", " + + std::to_string( pItem->getId() ) + ", " + std::to_string( itemAmount ) + ", " + std::to_string( flags ) + ");" ); return pItem; - } - uint32_t Core::Inventory::getCurrency( CurrencyType type ) { @@ -177,7 +173,6 @@ uint32_t Core::Inventory::getCurrency( CurrencyType type ) return 0; return currItem->getStackSize(); - } uint32_t Core::Inventory::getCrystal( CrystalType type ) @@ -189,7 +184,6 @@ uint32_t Core::Inventory::getCrystal( CrystalType type ) return 0; return currItem->getStackSize(); - } bool Core::Inventory::addCrystal( CrystalType type, uint32_t amount ) @@ -211,7 +205,6 @@ bool Core::Inventory::addCrystal( CrystalType type, uint32_t amount ) updateItemDb( currItem ); return true; - } bool Core::Inventory::addCurrency( CurrencyType type, uint32_t amount ) @@ -233,7 +226,6 @@ bool Core::Inventory::addCurrency( CurrencyType type, uint32_t amount ) updateItemDb( currItem ); return true; - } void Core::Inventory::updateCurrencyDb() @@ -262,7 +254,6 @@ void Core::Inventory::updateCurrencyDb() g_charaDb.execute( query ); } - void Core::Inventory::updateCrystalDb() { int32_t firstItemPos = -1; @@ -304,25 +295,17 @@ void Core::Inventory::updateBagDb( InventoryType type ) } query += " WHERE CharacterId = " + std::to_string( m_pOwner->getId() ) + - " AND storageId = " + std::to_string( static_cast< uint16_t >( type ) ); + " AND storageId = " + std::to_string( static_cast< uint16_t >( type ) ); g_charaDb.execute( query ); } bool Core::Inventory::isArmory( uint16_t containerId ) { - return - containerId == ArmoryBody || - containerId == ArmoryEar || - containerId == ArmoryFeet || - containerId == ArmoryHand || - containerId == ArmoryHead || - containerId == ArmoryLegs || - containerId == ArmoryMain || - containerId == ArmoryOff || - containerId == ArmoryRing || - containerId == ArmoryWaist || - containerId == ArmoryWrist; + return containerId == ArmoryBody || containerId == ArmoryEar || containerId == ArmoryFeet || + containerId == ArmoryHand || containerId == ArmoryHead || containerId == ArmoryLegs || + containerId == ArmoryMain || containerId == ArmoryOff || containerId == ArmoryRing || + containerId == ArmoryWaist || containerId == ArmoryWrist; } uint16_t Core::Inventory::getArmoryToEquipSlot( uint8_t slotId ) @@ -364,14 +347,11 @@ uint16_t Core::Inventory::getArmoryToEquipSlot( uint8_t slotId ) return 0; } - - bool Core::Inventory::isEquipment( uint16_t containerId ) { return containerId == GearSet0; } - void Core::Inventory::updateMannequinDb( InventoryType type ) { std::string query = "UPDATE charaitemgearset SET "; @@ -387,18 +367,17 @@ void Core::Inventory::updateMannequinDb( InventoryType type ) } query += " WHERE CharacterId = " + std::to_string( m_pOwner->getId() ) + - " AND storageId = " + std::to_string( static_cast< uint16_t >( type ) ); + " AND storageId = " + std::to_string( static_cast< uint16_t >( type ) ); g_log.Log( LoggingSeverity::debug, query ); g_charaDb.execute( query ); } - void Core::Inventory::updateItemDb( Core::ItemPtr pItem ) const { g_charaDb.execute( "UPDATE charaglobalitem SET stack = " + std::to_string( pItem->getStackSize() ) + " " + - // TODO: add other attributes - " WHERE itemId = " + std::to_string( pItem->getUId() ) ); + // TODO: add other attributes + " WHERE itemId = " + std::to_string( pItem->getUId() ) ); } bool Core::Inventory::removeCurrency( CurrencyType type, uint32_t amount ) @@ -441,7 +420,7 @@ bool Core::Inventory::removeCrystal( CrystalType type, uint32_t amount ) bool Core::Inventory::isOneHandedWeapon( ItemUICategory weaponCategory ) { - switch ( weaponCategory ) + switch( weaponCategory ) { case ItemUICategory::AlchemistsPrimaryTool: case ItemUICategory::ArmorersPrimaryTool: @@ -465,11 +444,10 @@ bool Core::Inventory::isOneHandedWeapon( ItemUICategory weaponCategory ) bool Core::Inventory::isObtainable( uint32_t catalogId, uint8_t quantity ) { - + return true; } - int16_t Core::Inventory::addItem( uint16_t inventoryId, int8_t slotId, uint32_t catalogId, uint8_t quantity ) { @@ -483,13 +461,13 @@ int16_t Core::Inventory::addItem( uint16_t inventoryId, int8_t slotId, uint32_t int8_t rSlotId = -1; - //if( itemInfo->stack_size > 1 ) + // if( itemInfo->stack_size > 1 ) //{ // auto itemList = this->getSlotsOfItemsInInventory( catalogId ); // // TODO: this is a stacked item so we need to see if the item is already in inventory and // // check how much free space we have on existing stacks before looking for empty slots. //} - //else + // else { auto freeSlot = this->getFreeBagSlot(); inventoryId = freeSlot.first; @@ -500,14 +478,14 @@ int16_t Core::Inventory::addItem( uint16_t inventoryId, int8_t slotId, uint32_t } auto item = createItem( catalogId, quantity ); - + if( rSlotId != -1 ) { m_inventoryMap[inventoryId]->setItem( rSlotId, item ); - g_charaDb.execute( "UPDATE charaiteminventory SET container_" + std::to_string( rSlotId ) + " = " + std::to_string( item->getUId() ) + - " WHERE storageId = " + std::to_string( inventoryId ) + + g_charaDb.execute( "UPDATE charaiteminventory SET container_" + std::to_string( rSlotId ) + " = " + + std::to_string( item->getUId() ) + " WHERE storageId = " + std::to_string( inventoryId ) + " AND CharacterId = " + std::to_string( m_pOwner->getId() ) ); ZoneChannelPacket< FFXIVIpcUpdateInventorySlot > invUpPacket( m_pOwner->getId() ); @@ -519,12 +497,11 @@ int16_t Core::Inventory::addItem( uint16_t inventoryId, int8_t slotId, uint32_t invUpPacket.data().condition = 30000; m_pOwner->queuePacket( invUpPacket ); - m_pOwner->queuePacket( ActorControlPacket143( m_pOwner->getId(), ItemObtainIcon, catalogId, item->getStackSize() ) ); - + m_pOwner->queuePacket( + ActorControlPacket143( m_pOwner->getId(), ItemObtainIcon, catalogId, item->getStackSize() ) ); } return rSlotId; - } void Core::Inventory::moveItem( uint16_t fromInventoryId, uint8_t fromSlotId, uint16_t toInventoryId, uint8_t toSlot ) @@ -557,8 +534,6 @@ void Core::Inventory::moveItem( uint16_t fromInventoryId, uint8_t fromSlotId, ui m_pOwner->unequipItem( static_cast< EquipSlot >( fromSlotId ), tmpItem ); updateMannequinDb( static_cast< InventoryType >( fromInventoryId ) ); } - - } bool Core::Inventory::updateContainer( uint16_t containerId, uint8_t slotId, ItemPtr pItem ) @@ -569,26 +544,26 @@ bool Core::Inventory::updateContainer( uint16_t containerId, uint8_t slotId, Ite switch( containerType ) { - case Armory: - case CurrencyCrystal: - case Bag: - { - updateBagDb( static_cast< InventoryType >( containerId ) ); - break; - } + case Armory: + case CurrencyCrystal: + case Bag: + { + updateBagDb( static_cast< InventoryType >( containerId ) ); + break; + } - case GearSet: - { - if( pItem ) - m_pOwner->equipItem( static_cast< EquipSlot >( slotId ), pItem, true ); - else - m_pOwner->unequipItem( static_cast< EquipSlot >( slotId ), pItem ); + case GearSet: + { + if( pItem ) + m_pOwner->equipItem( static_cast< EquipSlot >( slotId ), pItem, true ); + else + m_pOwner->unequipItem( static_cast< EquipSlot >( slotId ), pItem ); - updateMannequinDb( static_cast< InventoryType >( containerId ) ); - break; - } - default: - break; + updateMannequinDb( static_cast< InventoryType >( containerId ) ); + break; + } + default: + break; } return true; @@ -605,13 +580,11 @@ void Core::Inventory::swapItem( uint16_t fromInventoryId, uint8_t fromSlotId, ui // An item is being moved from bag0-3 to equippment, meaning // the swapped out item will be placed in the matching armory. - if( isEquipment( toInventoryId ) - && !isEquipment( fromInventoryId ) - && !isArmory( fromInventoryId ) ) + if( isEquipment( toInventoryId ) && !isEquipment( fromInventoryId ) && !isArmory( fromInventoryId ) ) { updateContainer( fromInventoryId, fromSlotId, nullptr ); fromInventoryId = getArmoryToEquipSlot( toSlot ); - fromSlotId = static_cast < uint8_t >( m_inventoryMap[fromInventoryId]->getFreeSlot() ); + fromSlotId = static_cast< uint8_t >( m_inventoryMap[fromInventoryId]->getFreeSlot() ); } auto containerTypeFrom = getContainerType( fromInventoryId ); @@ -649,8 +622,9 @@ void Core::Inventory::discardItem( uint16_t fromInventoryId, uint8_t fromSlotId Core::ItemPtr Core::Inventory::loadItem( uint64_t uId ) { - // load actual item - auto itemRes = g_charaDb.query( "SELECT catalogId, stack, flags FROM charaglobalitem WHERE itemId = " + std::to_string( uId ) + ";" ); + // load actual item + auto itemRes = g_charaDb.query( + "SELECT catalogId, stack, flags FROM charaglobalitem WHERE itemId = " + std::to_string( uId ) + ";" ); if( !itemRes->next() ) return nullptr; @@ -658,12 +632,8 @@ Core::ItemPtr Core::Inventory::loadItem( uint64_t uId ) { auto itemInfo = g_exdData.getItemInfo( itemRes->getUInt( 1 ) ); bool isHq = itemRes->getUInt( 3 ) == 1 ? true : false; - ItemPtr pItem( new Item( uId, - itemInfo->id, - itemInfo->model_primary, - itemInfo->model_secondary, - static_cast< ItemUICategory >( itemInfo->ui_category ), - isHq ) ); + ItemPtr pItem( new Item( uId, itemInfo->id, itemInfo->model_primary, itemInfo->model_secondary, + static_cast< ItemUICategory >( itemInfo->ui_category ), isHq ) ); pItem->setStackSize( itemRes->getUInt( 2 ) ); return pItem; @@ -682,8 +652,10 @@ bool Core::Inventory::load() "container_4, container_5, container_6, container_7, " "container_8, container_9, container_10, container_11, " "container_12, container_13 " - "FROM charaitemgearset " \ - "WHERE CharacterId = " + std::to_string( m_pOwner->getId() ) + " " \ + "FROM charaitemgearset " + "WHERE CharacterId = " + + std::to_string( m_pOwner->getId() ) + + " " "ORDER BY storageId ASC;" ); while( res->next() ) @@ -716,8 +688,10 @@ bool Core::Inventory::load() "container_20, container_21, container_22, container_23, container_24, " "container_25, container_26, container_27, container_28, container_29, " "container_30, container_31, container_32, container_33, container_34 " - "FROM charaiteminventory " \ - "WHERE CharacterId = " + std::to_string( m_pOwner->getId() ) + " " \ + "FROM charaiteminventory " + "WHERE CharacterId = " + + std::to_string( m_pOwner->getId() ) + + " " "ORDER BY storageId ASC;" ); while( bagRes->next() ) @@ -738,15 +712,16 @@ bool Core::Inventory::load() } } - /////////////////////////////////////////////////////////////////////////////////////////////////////// // Load Currency auto curRes = g_charaDb.query( "SELECT storageId, " "container_0, container_1, container_2, container_3, container_4, " "container_5, container_6, container_7, container_8, container_9, " "container_10, container_11 " - "FROM charaitemcurrency " \ - "WHERE CharacterId = " + std::to_string( m_pOwner->getId() ) + " " \ + "FROM charaitemcurrency " + "WHERE CharacterId = " + + std::to_string( m_pOwner->getId() ) + + " " "ORDER BY storageId ASC;" ); while( curRes->next() ) @@ -767,7 +742,6 @@ bool Core::Inventory::load() } } - /////////////////////////////////////////////////////////////////////////////////////////////////////// // Load Crystals auto crystalRes = g_charaDb.query( "SELECT storageId, " @@ -775,8 +749,10 @@ bool Core::Inventory::load() "container_5, container_6, container_7, container_8, container_9, " "container_10, container_11, container_12, container_13, container_14, " "container_15, container_16, container_17 " - "FROM charaitemcrystal " \ - "WHERE CharacterId = " + std::to_string( m_pOwner->getId() ) + " " \ + "FROM charaitemcrystal " + "WHERE CharacterId = " + + std::to_string( m_pOwner->getId() ) + + " " "ORDER BY storageId ASC;" ); while( crystalRes->next() ) @@ -800,7 +776,6 @@ bool Core::Inventory::load() return true; } - void Core::Inventory::send() { InventoryMap::iterator it; @@ -848,10 +823,7 @@ void Core::Inventory::send() containerInfoPacket.data().numItems = it->second->getEntryCount(); containerInfoPacket.data().containerId = it->second->getId(); m_pOwner->queuePacket( containerInfoPacket ); - - } - } uint16_t Core::Inventory::calculateEquippedGearItemLevel() @@ -862,16 +834,16 @@ uint16_t Core::Inventory::calculateEquippedGearItemLevel() auto it = gearSetMap.begin(); - while ( it != gearSetMap.end() ) + while( it != gearSetMap.end() ) { auto currItem = it->second; - if ( currItem ) + if( currItem ) { iLvlResult += currItem->getItemLevel(); // If item is weapon and isn't one-handed - if ( currItem->isWeapon() && !isOneHandedWeapon( currItem->getCategory() ) ) + if( currItem->isWeapon() && !isOneHandedWeapon( currItem->getCategory() ) ) { iLvlResult += currItem->getItemLevel(); } @@ -887,7 +859,6 @@ uint16_t Core::Inventory::calculateEquippedGearItemLevel() return boost::algorithm::clamp( iLvlResult / 12, 0, 9999 ); } - uint8_t Core::Inventory::getFreeSlotsInBags() { uint8_t slots = 0; @@ -898,7 +869,6 @@ uint8_t Core::Inventory::getFreeSlotsInBags() return slots; } - Core::Inventory::ContainerType Core::Inventory::getContainerType( uint32_t containerId ) { if( containerId < 5 ) diff --git a/src/servers/Server_Zone/Inventory/Inventory.h b/src/servers/Server_Zone/Inventory/Inventory.h index 508c4733..ea5014bd 100644 --- a/src/servers/Server_Zone/Inventory/Inventory.h +++ b/src/servers/Server_Zone/Inventory/Inventory.h @@ -1,11 +1,10 @@ #ifndef INVENTORY_H_ #define INVENTORY_H_ -#include -#include #include "../Forwards.h" +#include +#include -namespace Core -{ +namespace Core { class ItemContainer; @@ -37,10 +36,10 @@ public: Currency = 2000, Crystal = 2001, - //UNKNOWN_0 = 2003, + // UNKNOWN_0 = 2003, KeyItem = 2004, DamagedGear = 2007, - //UNKNOWN_1 = 2008, + // UNKNOWN_1 = 2008, ArmoryOff = 3200, ArmoryHead = 3201, @@ -193,11 +192,10 @@ public: uint32_t getNextUId(); - private: Entity::Player* m_pOwner; InventoryMap m_inventoryMap; }; -} +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Inventory/Item.cpp b/src/servers/Server_Zone/Inventory/Item.cpp index 2844c73e..5a3e1b01 100644 --- a/src/servers/Server_Zone/Inventory/Item.cpp +++ b/src/servers/Server_Zone/Inventory/Item.cpp @@ -1,28 +1,25 @@ +#include "Item.h" #include #include -#include "Item.h" extern Core::Data::ExdData g_exdData; Core::Item::Item() { - } -Core::Item::Item( uint32_t catalogId ) : - m_id( catalogId ), - m_isHq( false ) +Core::Item::Item( uint32_t catalogId ) : m_id( catalogId ), m_isHq( false ) { - } -Core::Item::Item( uint64_t uId, uint32_t catalogId, uint64_t model1, uint64_t model2, Common::ItemUICategory categoryId, bool isHq ) : - m_id( catalogId ), - m_uId( uId ), - m_category( static_cast< Common::ItemUICategory >( categoryId ) ), - m_model1( model1 ), - m_model2( model2 ), - m_isHq( isHq ) +Core::Item::Item( uint64_t uId, uint32_t catalogId, uint64_t model1, uint64_t model2, Common::ItemUICategory categoryId, + bool isHq ) : + m_id( catalogId ), + m_uId( uId ), + m_category( static_cast< Common::ItemUICategory >( categoryId ) ), + m_model1( model1 ), + m_model2( model2 ), + m_isHq( isHq ) { auto itemInfo = g_exdData.getItemInfo( catalogId ); m_delayMs = itemInfo->delayMs; @@ -35,7 +32,6 @@ Core::Item::Item( uint64_t uId, uint32_t catalogId, uint64_t model1, uint64_t mo Core::Item::~Item() { - } float Core::Item::getAutoAttackDmg() const @@ -70,7 +66,7 @@ uint16_t Core::Item::getWeaponDmg() const bool Core::Item::isWeapon() const { - return (m_weaponDmg != 0); + return ( m_weaponDmg != 0 ); } uint32_t Core::Item::getId() const diff --git a/src/servers/Server_Zone/Inventory/Item.h b/src/servers/Server_Zone/Inventory/Item.h index fdb3e6a3..6eb669fe 100644 --- a/src/servers/Server_Zone/Inventory/Item.h +++ b/src/servers/Server_Zone/Inventory/Item.h @@ -11,7 +11,8 @@ class Item public: Item(); Item( uint32_t catalogId ); - Item( uint64_t uId, uint32_t catalogId, uint64_t model1, uint64_t model2, Common::ItemUICategory categoryId, bool isHq = false ); + Item( uint64_t uId, uint32_t catalogId, uint64_t model1, uint64_t model2, Common::ItemUICategory categoryId, + bool isHq = false ); ~Item(); uint32_t getId() const; @@ -54,31 +55,29 @@ public: uint16_t getItemLevel() const; - protected: - uint32_t m_id; + uint32_t m_id; - uint64_t m_uId; - - Common::ItemUICategory m_category; + uint64_t m_uId; - uint32_t m_stackSize; - std::vector< uint8_t > m_classJobList; + Common::ItemUICategory m_category; - uint64_t m_model1; - uint64_t m_model2; + uint32_t m_stackSize; + std::vector< uint8_t > m_classJobList; - bool m_isHq; + uint64_t m_model1; + uint64_t m_model2; - uint16_t m_delayMs; - uint16_t m_physicalDmg; - uint16_t m_magicalDmg; - uint16_t m_weaponDmg; - float m_autoAttackDmg; - uint16_t m_itemLevel; + bool m_isHq; + uint16_t m_delayMs; + uint16_t m_physicalDmg; + uint16_t m_magicalDmg; + uint16_t m_weaponDmg; + float m_autoAttackDmg; + uint16_t m_itemLevel; }; -} +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Inventory/ItemContainer.cpp b/src/servers/Server_Zone/Inventory/ItemContainer.cpp index baa3da34..727640ab 100644 --- a/src/servers/Server_Zone/Inventory/ItemContainer.cpp +++ b/src/servers/Server_Zone/Inventory/ItemContainer.cpp @@ -1,27 +1,22 @@ -#include "../Forwards.h" #include "ItemContainer.h" +#include "../Forwards.h" #include -#include #include +#include #include "Actor/Player.h" #include "Item.h" - extern Core::Logger g_log; -Core::ItemContainer::ItemContainer( uint16_t locationId ) : - m_id( locationId ), - m_size( 25 ) +Core::ItemContainer::ItemContainer( uint16_t locationId ) : m_id( locationId ), m_size( 25 ) { - } Core::ItemContainer::~ItemContainer() { - } uint16_t Core::ItemContainer::getId() const @@ -52,12 +47,12 @@ void Core::ItemContainer::removeItem( uint8_t slotId ) } } -Core::ItemMap & Core::ItemContainer::getItemMap() +Core::ItemMap& Core::ItemContainer::getItemMap() { return m_itemMap; } -const Core::ItemMap & Core::ItemContainer::getItemMap() const +const Core::ItemMap& Core::ItemContainer::getItemMap() const { return m_itemMap; } @@ -67,8 +62,7 @@ int16_t Core::ItemContainer::getFreeSlot() for( uint8_t slotId = 0; slotId < m_size; slotId++ ) { ItemMap::iterator it = m_itemMap.find( slotId ); - if( it == m_itemMap.end() || - it->second == nullptr ) + if( it == m_itemMap.end() || it->second == nullptr ) return slotId; } return -1; diff --git a/src/servers/Server_Zone/Inventory/ItemContainer.h b/src/servers/Server_Zone/Inventory/ItemContainer.h index 8147905d..53eb3deb 100644 --- a/src/servers/Server_Zone/Inventory/ItemContainer.h +++ b/src/servers/Server_Zone/Inventory/ItemContainer.h @@ -7,41 +7,40 @@ #include "../Forwards.h" -namespace Core +namespace Core { + +typedef std::map< uint8_t, ItemPtr > ItemMap; + +class ItemContainer { - typedef std::map< uint8_t, ItemPtr > ItemMap; +public: + ItemContainer( uint16_t locationId ); + ~ItemContainer(); - class ItemContainer - { + uint16_t getId() const; - public: - ItemContainer( uint16_t locationId ); - ~ItemContainer(); + uint8_t getEntryCount() const; - uint16_t getId() const; + void removeItem( uint8_t slotId ); - uint8_t getEntryCount() const; + ItemMap& getItemMap(); - void removeItem( uint8_t slotId ); + const ItemMap& getItemMap() const; - ItemMap& getItemMap(); + ItemPtr getItem( uint8_t slotId ); - const ItemMap& getItemMap() const; + void setItem( uint8_t slotId, ItemPtr item ); - ItemPtr getItem( uint8_t slotId ); + int16_t getFreeSlot(); - void setItem( uint8_t slotId, ItemPtr item ); +private: + uint16_t m_id; + uint8_t m_size; + ItemMap m_itemMap; + Entity::PlayerPtr m_pOwner; +}; - int16_t getFreeSlot(); - - private: - uint16_t m_id; - uint8_t m_size; - ItemMap m_itemMap; - Entity::PlayerPtr m_pOwner; - }; - -} +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Linkshell/Linkshell.cpp b/src/servers/Server_Zone/Linkshell/Linkshell.cpp index da3fdd8c..140aebd6 100644 --- a/src/servers/Server_Zone/Linkshell/Linkshell.cpp +++ b/src/servers/Server_Zone/Linkshell/Linkshell.cpp @@ -1,20 +1,15 @@ #include "Linkshell.h" - -Core::Linkshell::Linkshell( uint64_t id, - const std::string &name, - uint64_t masterId, - const std::set &members, - const std::set &leaders, - const std::set &invites ) : - m_linkshellId( id ), - m_name( name ), - m_masterCharacterId( masterId ), - m_memberIds( members ), - m_leaderIds( leaders ), - m_inviteIds( invites ) +Core::Linkshell::Linkshell( uint64_t id, const std::string& name, uint64_t masterId, + const std::set< uint64_t >& members, const std::set< uint64_t >& leaders, + const std::set< uint64_t >& invites ) : + m_linkshellId( id ), + m_name( name ), + m_masterCharacterId( masterId ), + m_memberIds( members ), + m_leaderIds( leaders ), + m_inviteIds( invites ) { - } uint64_t Core::Linkshell::getId() const @@ -57,7 +52,7 @@ const std::set< uint64_t >& Core::Linkshell::getInviteIdList() const return m_inviteIds; } -std::set< uint64_t > &Core::Linkshell::getInviteIdList() +std::set< uint64_t >& Core::Linkshell::getInviteIdList() { return m_inviteIds; } @@ -91,6 +86,3 @@ void Core::Linkshell::removeInvite( uint64_t memberId ) { m_inviteIds.erase( memberId ); } - - - diff --git a/src/servers/Server_Zone/Linkshell/Linkshell.h b/src/servers/Server_Zone/Linkshell/Linkshell.h index 62ca1781..2e704dc7 100644 --- a/src/servers/Server_Zone/Linkshell/Linkshell.h +++ b/src/servers/Server_Zone/Linkshell/Linkshell.h @@ -4,8 +4,7 @@ #include #include -namespace Core -{ +namespace Core { class Linkshell { @@ -24,12 +23,8 @@ private: std::set< uint64_t > m_inviteIds; public: - Linkshell( uint64_t id, - const std::string& name, - uint64_t masterId, - const std::set< uint64_t >& members, - const std::set< uint64_t >& leaders, - const std::set< uint64_t >& invites ); + Linkshell( uint64_t id, const std::string& name, uint64_t masterId, const std::set< uint64_t >& members, + const std::set< uint64_t >& leaders, const std::set< uint64_t >& invites ); uint64_t getId() const; @@ -54,9 +49,7 @@ public: void addInvite( uint64_t memberId ); void removeInvite( uint64_t memberId ); - - }; -} -#endif //SAPPHIRE_LINKSHELL_H +} // namespace Core +#endif // SAPPHIRE_LINKSHELL_H diff --git a/src/servers/Server_Zone/Linkshell/LinkshellMgr.cpp b/src/servers/Server_Zone/Linkshell/LinkshellMgr.cpp index e584bced..c81ee19c 100644 --- a/src/servers/Server_Zone/Linkshell/LinkshellMgr.cpp +++ b/src/servers/Server_Zone/Linkshell/LinkshellMgr.cpp @@ -9,26 +9,23 @@ extern Core::Logger g_log; Core::LinkshellMgr::LinkshellMgr() { - } bool Core::LinkshellMgr::loadLinkshells() { auto res = g_charaDb.query( "SELECT LinkshellId, MasterCharacterId, CharacterIdList, " - "LinkshellName, LeaderIdList, InviteIdList " - "FROM infolinkshell " + "LinkshellName, LeaderIdList, InviteIdList " + "FROM infolinkshell " "ORDER BY LinkshellId ASC;" ); - while( res->next() ) { uint64_t linkshellId = res->getUInt64( 1 ); uint32_t masterId = res->getUInt( 2 ); std::string name = res->getString( 4 ); - auto func = []( std::set< uint64_t >& outList, std::vector< char >& inData ) - { + auto func = []( std::set< uint64_t >& outList, std::vector< char >& inData ) { if( inData.size() ) { std::vector< uint64_t > list( inData.size() / 8 ); @@ -54,11 +51,9 @@ bool Core::LinkshellMgr::loadLinkshells() auto lsPtr = boost::make_shared< Linkshell >( linkshellId, name, masterId, members, leaders, invites ); m_linkshellIdMap[linkshellId] = lsPtr; m_linkshellNameMap[name] = lsPtr; - } return true; - } Core::LinkshellPtr Core::LinkshellMgr::getLinkshellByName( const std::string& name ) diff --git a/src/servers/Server_Zone/Linkshell/LinkshellMgr.h b/src/servers/Server_Zone/Linkshell/LinkshellMgr.h index e6274285..286e2772 100644 --- a/src/servers/Server_Zone/Linkshell/LinkshellMgr.h +++ b/src/servers/Server_Zone/Linkshell/LinkshellMgr.h @@ -4,8 +4,7 @@ #include #include -namespace Core -{ +namespace Core { class Linkshell; using LinkshellPtr = boost::shared_ptr< Linkshell >; @@ -24,5 +23,5 @@ public: bool loadLinkshells(); }; -} -#endif //CORE_LINKSHELLMGR_H +} // namespace Core +#endif // CORE_LINKSHELLMGR_H diff --git a/src/servers/Server_Zone/Math/CalcBattle.cpp b/src/servers/Server_Zone/Math/CalcBattle.cpp index f68d1872..67ac8d80 100644 --- a/src/servers/Server_Zone/Math/CalcBattle.cpp +++ b/src/servers/Server_Zone/Math/CalcBattle.cpp @@ -1,11 +1,10 @@ #include -#include -#include #include "Actor/Actor.h" #include "Actor/Player.h" #include "CalcBattle.h" - +#include +#include using namespace Core::Math; using namespace Core::Entity; @@ -17,7 +16,7 @@ extern Core::Data::ExdData g_exdData; Big thanks to the Theoryjerks group! NOTE: - Formulas here shouldn't be considered final. It's possible that the formula it was based on is correct but + Formulas here shouldn't be considered final. It's possible that the formula it was based on is correct but wasn't implemented correctly here, or approximated things due to limited knowledge of how things work in retail. It's also possible that we're using formulas that were correct for previous patches, but not the current version. @@ -33,8 +32,7 @@ uint32_t CalcBattle::calculateHealValue( PlayerPtr pPlayer, uint32_t potency ) auto classInfoIt = g_exdData.m_classJobInfoMap.find( static_cast< uint8_t >( pPlayer->getClass() ) ); auto paramGrowthInfoIt = g_exdData.m_paramGrowthInfoMap.find( pPlayer->getLevel() ); - if ( classInfoIt == g_exdData.m_classJobInfoMap.end() || - paramGrowthInfoIt == g_exdData.m_paramGrowthInfoMap.end()) + if( classInfoIt == g_exdData.m_classJobInfoMap.end() || paramGrowthInfoIt == g_exdData.m_paramGrowthInfoMap.end() ) return 0; auto jobModVal = classInfoIt->second; diff --git a/src/servers/Server_Zone/Math/CalcBattle.h b/src/servers/Server_Zone/Math/CalcBattle.h index b373ac99..bba3cdf3 100644 --- a/src/servers/Server_Zone/Math/CalcBattle.h +++ b/src/servers/Server_Zone/Math/CalcBattle.h @@ -1,24 +1,23 @@ #ifndef _CALCBATTLE_H #define _CALCBATTLE_H -#include #include "Actor/Actor.h" +#include using namespace Core::Entity; namespace Core { namespace Math { - + class CalcBattle { public: static uint32_t calculateHealValue( PlayerPtr pPlayer, uint32_t potency ); private: - }; -} -} +} // namespace Math +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Math/CalcStats.cpp b/src/servers/Server_Zone/Math/CalcStats.cpp index 0e31d183..2834d860 100644 --- a/src/servers/Server_Zone/Math/CalcStats.cpp +++ b/src/servers/Server_Zone/Math/CalcStats.cpp @@ -1,13 +1,12 @@ #include -#include -#include #include "Actor/Actor.h" #include "Actor/Player.h" +#include +#include #include "CalcStats.h" - using namespace Core::Math; using namespace Core::Entity; @@ -18,7 +17,7 @@ extern Core::Data::ExdData g_exdData; Big thanks to the Theoryjerks group! NOTE: - Formulas here shouldn't be considered final. It's possible that the formula it was based on is correct but + Formulas here shouldn't be considered final. It's possible that the formula it was based on is correct but wasn't implemented correctly here, or approximated things due to limited knowledge of how things work in retail. It's also possible that we're using formulas that were correct for previous patches, but not the current version. @@ -38,12 +37,12 @@ float CalcStats::calculateBaseStat( PlayerPtr pPlayer ) uint8_t level = pPlayer->getLevel(); // SB Base Stat Formula (Aligned) - if ( level > 60 ) - { - base = static_cast< float >( ( ( ( level == 61 ) ? 224 : 220 ) + ( level - 61 ) * 8) ); + if( level > 60 ) + { + base = static_cast< float >( ( ( ( level == 61 ) ? 224 : 220 ) + ( level - 61 ) * 8 ) ); } // HW Base Stat Formula (Aligned) - else if ( level > 50 ) + else if( level > 50 ) base = 1.63f * level + 121.02f; // ARR Base Stat Formula (Off by one in several cases) else @@ -58,14 +57,14 @@ float CalcStats::calculateBaseStat( PlayerPtr pPlayer ) uint32_t CalcStats::calculateMaxHp( PlayerPtr pPlayer ) { // TODO: Replace ApproxBaseHP with something that can get us an accurate BaseHP. - // Is there any way to pull reliable BaseHP without having to manually use a pet for every level, and using the values from a table? - // More info here: https://docs.google.com/spreadsheets/d/1de06KGT0cNRUvyiXNmjNgcNvzBCCQku7jte5QxEQRbs/edit?usp=sharing - + // Is there any way to pull reliable BaseHP without having to manually use a pet for every level, and using the + // values from a table? More info here: + // https://docs.google.com/spreadsheets/d/1de06KGT0cNRUvyiXNmjNgcNvzBCCQku7jte5QxEQRbs/edit?usp=sharing + auto classInfoIt = g_exdData.m_classJobInfoMap.find( static_cast< uint8_t >( pPlayer->getClass() ) ); auto paramGrowthInfoIt = g_exdData.m_paramGrowthInfoMap.find( pPlayer->getLevel() ); - if ( classInfoIt == g_exdData.m_classJobInfoMap.end() || - paramGrowthInfoIt == g_exdData.m_paramGrowthInfoMap.end() ) + if( classInfoIt == g_exdData.m_classJobInfoMap.end() || paramGrowthInfoIt == g_exdData.m_paramGrowthInfoMap.end() ) return 0; uint8_t level = pPlayer->getLevel(); @@ -78,14 +77,15 @@ uint32_t CalcStats::calculateMaxHp( PlayerPtr pPlayer ) // These values are not precise. - if ( level >= 60 ) + if( level >= 60 ) approxBaseHp = static_cast< float >( 2600 + ( level - 60 ) * 100 ); - else if ( level >= 50 ) + else if( level >= 50 ) approxBaseHp = 1700 + ( ( level - 50 ) * ( 1700 * 1.04325f ) ); else approxBaseHp = paramGrowthInfoIt->second.mp_const * 0.7667f; - uint16_t result = static_cast< uint16_t >( floor( jobModHp * ( approxBaseHp / 100.0f ) ) + floor( hpMod / 100.0f * ( vitStat - baseStat ) ) ); + uint16_t result = static_cast< uint16_t >( floor( jobModHp * ( approxBaseHp / 100.0f ) ) + + floor( hpMod / 100.0f * ( vitStat - baseStat ) ) ); return result; } @@ -98,8 +98,7 @@ uint32_t CalcStats::calculateMaxMp( PlayerPtr pPlayer ) auto classInfoIt = g_exdData.m_classJobInfoMap.find( static_cast< uint8_t >( pPlayer->getClass() ) ); auto paramGrowthInfoIt = g_exdData.m_paramGrowthInfoMap.find( pPlayer->getLevel() ); - if ( classInfoIt == g_exdData.m_classJobInfoMap.end() || - paramGrowthInfoIt == g_exdData.m_paramGrowthInfoMap.end() ) + if( classInfoIt == g_exdData.m_classJobInfoMap.end() || paramGrowthInfoIt == g_exdData.m_paramGrowthInfoMap.end() ) return 0; float baseStat = calculateBaseStat( pPlayer ); @@ -108,7 +107,8 @@ uint32_t CalcStats::calculateMaxMp( PlayerPtr pPlayer ) uint16_t jobModMp = classInfoIt->second.mod_mpcpgp; uint16_t baseMp = paramGrowthInfoIt->second.mp_const; - uint16_t result = static_cast< uint16_t >( floor( floor( piety - baseStat ) * ( pietyScalar / 100 ) + baseMp ) * jobModMp / 100 ); + uint16_t result = + static_cast< uint16_t >( floor( floor( piety - baseStat ) * ( pietyScalar / 100 ) + baseMp ) * jobModMp / 100 ); return result; } diff --git a/src/servers/Server_Zone/Math/CalcStats.h b/src/servers/Server_Zone/Math/CalcStats.h index 94a0a324..9e7483b3 100644 --- a/src/servers/Server_Zone/Math/CalcStats.h +++ b/src/servers/Server_Zone/Math/CalcStats.h @@ -1,14 +1,14 @@ #ifndef _CALCSTATS_H #define _CALCSTATS_H -#include #include "Actor/Actor.h" +#include using namespace Core::Entity; namespace Core { namespace Math { - + class CalcStats { public: @@ -17,10 +17,9 @@ namespace Math { static uint32_t calculateMaxHp( PlayerPtr pPlayer ); private: - }; -} -} +} // namespace Math +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Network/GameConnection.cpp b/src/servers/Server_Zone/Network/GameConnection.cpp index 1a52c5f6..e977d0e3 100644 --- a/src/servers/Server_Zone/Network/GameConnection.cpp +++ b/src/servers/Server_Zone/Network/GameConnection.cpp @@ -1,20 +1,20 @@ #include -#include -#include #include -#include +#include #include +#include +#include #include #include "GameConnection.h" +#include "Actor/Player.h" +#include "DebugCommand/DebugCommandHandler.h" +#include "Forwards.h" +#include "Network/PacketWrappers/InitUIPacket.h" #include "ServerZone.h" #include "Session.h" #include "Zone/Zone.h" -#include "Network/PacketWrappers/InitUIPacket.h" -#include "DebugCommand/DebugCommandHandler.h" -#include "Actor/Player.h" -#include "Forwards.h" extern Core::DebugCommandHandler g_gameCommandMgr; extern Core::Logger g_log; @@ -24,87 +24,89 @@ using namespace Core::Common; using namespace Core::Network::Packets; using namespace Core::Network::Packets::Server; -Core::Network::GameConnection::GameConnection( Core::Network::HivePtr pHive, - Core::Network::AcceptorPtr pAcceptor ) - : Connection( pHive ) - , m_pAcceptor( pAcceptor ) - , m_conType( ConnectionType::None ) +Core::Network::GameConnection::GameConnection( Core::Network::HivePtr pHive, Core::Network::AcceptorPtr pAcceptor ) : + Connection( pHive ), + m_pAcceptor( pAcceptor ), + m_conType( ConnectionType::None ) { - auto setZoneHandler = [=]( uint16_t opcode, std::string handlerName, GameConnection::Handler pHandler ) - { + auto setZoneHandler = [=]( uint16_t opcode, std::string handlerName, GameConnection::Handler pHandler ) { m_zoneHandlerMap[opcode] = pHandler; m_zoneHandlerStrMap[opcode] = handlerName; }; - auto setChatHandler = [=]( uint16_t opcode, std::string handlerName, GameConnection::Handler pHandler ) - { + auto setChatHandler = [=]( uint16_t opcode, std::string handlerName, GameConnection::Handler pHandler ) { m_chatHandlerMap[opcode] = pHandler; m_chatHandlerStrMap[opcode] = handlerName; }; - setZoneHandler( ClientZoneIpcType::PingHandler, "PingHandler", &GameConnection::pingHandler ); - setZoneHandler( ClientZoneIpcType::InitHandler, "InitHandler", &GameConnection::initHandler ); - setZoneHandler( ClientZoneIpcType::ChatHandler, "ChatHandler", &GameConnection::chatHandler ); + setZoneHandler( ClientZoneIpcType::PingHandler, "PingHandler", &GameConnection::pingHandler ); + setZoneHandler( ClientZoneIpcType::InitHandler, "InitHandler", &GameConnection::initHandler ); + setZoneHandler( ClientZoneIpcType::ChatHandler, "ChatHandler", &GameConnection::chatHandler ); - setZoneHandler( ClientZoneIpcType::FinishLoadingHandler, "FinishLoadingHandler", &GameConnection::finishLoadingHandler ); + setZoneHandler( ClientZoneIpcType::FinishLoadingHandler, "FinishLoadingHandler", + &GameConnection::finishLoadingHandler ); - setZoneHandler( ClientZoneIpcType::PlayTimeHandler, "PlayTimeHandler", &GameConnection::playTimeHandler ); - setZoneHandler( ClientZoneIpcType::LogoutHandler, "LogoutHandler", &GameConnection::logoutHandler ); + setZoneHandler( ClientZoneIpcType::PlayTimeHandler, "PlayTimeHandler", &GameConnection::playTimeHandler ); + setZoneHandler( ClientZoneIpcType::LogoutHandler, "LogoutHandler", &GameConnection::logoutHandler ); - setZoneHandler( ClientZoneIpcType::SocialListHandler, "SocialListHandler", &GameConnection::socialListHandler ); - setZoneHandler( ClientZoneIpcType::SetSearchInfoHandler, "SetSearchInfoHandler", &GameConnection::setSearchInfoHandler ); - setZoneHandler( ClientZoneIpcType::ReqSearchInfoHandler, "ReqSearchInfoHandler", &GameConnection::reqSearchInfoHandler ); + setZoneHandler( ClientZoneIpcType::SocialListHandler, "SocialListHandler", &GameConnection::socialListHandler ); + setZoneHandler( ClientZoneIpcType::SetSearchInfoHandler, "SetSearchInfoHandler", + &GameConnection::setSearchInfoHandler ); + setZoneHandler( ClientZoneIpcType::ReqSearchInfoHandler, "ReqSearchInfoHandler", + &GameConnection::reqSearchInfoHandler ); - setZoneHandler( ClientZoneIpcType::BlackListHandler, "BlackListHandler", &GameConnection::blackListHandler ); + setZoneHandler( ClientZoneIpcType::BlackListHandler, "BlackListHandler", &GameConnection::blackListHandler ); - setZoneHandler( ClientZoneIpcType::LinkshellListHandler, "LinkshellListHandler", &GameConnection::linkshellListHandler ); + setZoneHandler( ClientZoneIpcType::LinkshellListHandler, "LinkshellListHandler", + &GameConnection::linkshellListHandler ); - setZoneHandler( ClientZoneIpcType::FcInfoReqHandler, "FcInfoReqHandler", &GameConnection::fcInfoReqHandler ); + setZoneHandler( ClientZoneIpcType::FcInfoReqHandler, "FcInfoReqHandler", &GameConnection::fcInfoReqHandler ); - setZoneHandler( ClientZoneIpcType::ZoneLineHandler, "ZoneLineHandler", &GameConnection::zoneLineHandler ); - setZoneHandler( ClientZoneIpcType::ActionHandler, "ActionHandler", &GameConnection::actionHandler ); + setZoneHandler( ClientZoneIpcType::ZoneLineHandler, "ZoneLineHandler", &GameConnection::zoneLineHandler ); + setZoneHandler( ClientZoneIpcType::ActionHandler, "ActionHandler", &GameConnection::actionHandler ); - setZoneHandler( ClientZoneIpcType::DiscoveryHandler, "DiscoveryHandler", &GameConnection::discoveryHandler ); + setZoneHandler( ClientZoneIpcType::DiscoveryHandler, "DiscoveryHandler", &GameConnection::discoveryHandler ); - setZoneHandler( ClientZoneIpcType::SkillHandler, "SkillHandler", &GameConnection::skillHandler ); + setZoneHandler( ClientZoneIpcType::SkillHandler, "SkillHandler", &GameConnection::skillHandler ); - setZoneHandler( ClientZoneIpcType::GMCommand1, "GMCommand1", &GameConnection::gm1Handler ); - setZoneHandler( ClientZoneIpcType::GMCommand2, "GMCommand2", &GameConnection::gm2Handler ); + setZoneHandler( ClientZoneIpcType::GMCommand1, "GMCommand1", &GameConnection::gm1Handler ); + setZoneHandler( ClientZoneIpcType::GMCommand2, "GMCommand2", &GameConnection::gm2Handler ); - setZoneHandler( ClientZoneIpcType::UpdatePositionHandler,"UpdatePositionHandler", &GameConnection::updatePositionHandler ); + setZoneHandler( ClientZoneIpcType::UpdatePositionHandler, "UpdatePositionHandler", + &GameConnection::updatePositionHandler ); - setZoneHandler( ClientZoneIpcType::InventoryModifyHandler,"InventoryModifyHandler", &GameConnection::inventoryModifyHandler ); + setZoneHandler( ClientZoneIpcType::InventoryModifyHandler, "InventoryModifyHandler", + &GameConnection::inventoryModifyHandler ); - setZoneHandler( ClientZoneIpcType::TalkEventHandler, "EventHandler", &GameConnection::eventHandler ); - setZoneHandler( ClientZoneIpcType::EmoteEventHandler, "EventHandler", &GameConnection::eventHandler ); - setZoneHandler( ClientZoneIpcType::WithinRangeEventHandler, "EventHandler", &GameConnection::eventHandler ); - setZoneHandler( ClientZoneIpcType::OutOfRangeEventHandler, "EventHandler", &GameConnection::eventHandler ); - setZoneHandler( ClientZoneIpcType::EnterTeriEventHandler, "EventHandler", &GameConnection::eventHandler ); + setZoneHandler( ClientZoneIpcType::TalkEventHandler, "EventHandler", &GameConnection::eventHandler ); + setZoneHandler( ClientZoneIpcType::EmoteEventHandler, "EventHandler", &GameConnection::eventHandler ); + setZoneHandler( ClientZoneIpcType::WithinRangeEventHandler, "EventHandler", &GameConnection::eventHandler ); + setZoneHandler( ClientZoneIpcType::OutOfRangeEventHandler, "EventHandler", &GameConnection::eventHandler ); + setZoneHandler( ClientZoneIpcType::EnterTeriEventHandler, "EventHandler", &GameConnection::eventHandler ); - setZoneHandler( ClientZoneIpcType::ReturnEventHandler, "EventHandlerReturn", &GameConnection::eventHandler ); - setZoneHandler( ClientZoneIpcType::TradeReturnEventHandler, "EventHandlerReturn", &GameConnection::eventHandler ); + setZoneHandler( ClientZoneIpcType::ReturnEventHandler, "EventHandlerReturn", &GameConnection::eventHandler ); + setZoneHandler( ClientZoneIpcType::TradeReturnEventHandler, "EventHandlerReturn", &GameConnection::eventHandler ); - setZoneHandler( ClientZoneIpcType::LinkshellEventHandler, "LinkshellEventHandler", &GameConnection::eventHandler ); + setZoneHandler( ClientZoneIpcType::LinkshellEventHandler, "LinkshellEventHandler", &GameConnection::eventHandler ); setZoneHandler( ClientZoneIpcType::LinkshellEventHandler1, "LinkshellEventHandler1", &GameConnection::eventHandler ); - setZoneHandler( ClientZoneIpcType::CFDutyInfoHandler, "CFDutyInfoRequest", &GameConnection::cfDutyInfoRequest ); - setZoneHandler( ClientZoneIpcType::CFRegisterDuty, "CFRegisterDuty", &GameConnection::cfRegisterDuty ); - setZoneHandler( ClientZoneIpcType::CFRegisterRoulette, "CFRegisterRoulette", &GameConnection::cfRegisterRoulette ); - setZoneHandler( ClientZoneIpcType::CFCommenceHandler, "CFDutyAccepted", &GameConnection::cfDutyAccepted); + setZoneHandler( ClientZoneIpcType::CFDutyInfoHandler, "CFDutyInfoRequest", &GameConnection::cfDutyInfoRequest ); + setZoneHandler( ClientZoneIpcType::CFRegisterDuty, "CFRegisterDuty", &GameConnection::cfRegisterDuty ); + setZoneHandler( ClientZoneIpcType::CFRegisterRoulette, "CFRegisterRoulette", &GameConnection::cfRegisterRoulette ); + setZoneHandler( ClientZoneIpcType::CFCommenceHandler, "CFDutyAccepted", &GameConnection::cfDutyAccepted ); - setZoneHandler( ClientZoneIpcType::ReqEquipDisplayFlagsChange, "ReqEquipDisplayFlagsChange", &GameConnection::reqEquipDisplayFlagsHandler ); + setZoneHandler( ClientZoneIpcType::ReqEquipDisplayFlagsChange, "ReqEquipDisplayFlagsChange", + &GameConnection::reqEquipDisplayFlagsHandler ); setZoneHandler( ClientZoneIpcType::PerformNoteHandler, "PerformNoteHandler", &GameConnection::performNoteHandler ); - setChatHandler( ClientChatIpcType::TellReq, "TellReq", &GameConnection::tellHandler); - + setChatHandler( ClientChatIpcType::TellReq, "TellReq", &GameConnection::tellHandler ); } Core::Network::GameConnection::~GameConnection() = default; - // overwrite the parents onConnect for our game socket needs -void Core::Network::GameConnection::OnAccept( const std::string & host, uint16_t port ) +void Core::Network::GameConnection::OnAccept( const std::string& host, uint16_t port ) { GameConnectionPtr connection( new GameConnection( m_hive, m_pAcceptor ) ); m_pAcceptor->Accept( connection ); @@ -112,14 +114,13 @@ void Core::Network::GameConnection::OnAccept( const std::string & host, uint16_t g_log.info( "Connect from " + m_socket.remote_endpoint().address().to_string() ); } - void Core::Network::GameConnection::OnDisconnect() { g_log.debug( "GameConnection DISCONNECT" ); m_pSession = nullptr; } -void Core::Network::GameConnection::OnRecv( std::vector< uint8_t > & buffer ) +void Core::Network::GameConnection::OnRecv( std::vector< uint8_t >& buffer ) { // This is assumed packet always start with valid FFXIVARR_PACKET_HEADER for now. @@ -139,12 +140,12 @@ void Core::Network::GameConnection::OnRecv( std::vector< uint8_t > & buffer ) Disconnect(); return; } - + // Dissect packet list std::vector< Packets::FFXIVARR_PACKET_RAW > packetList; - const auto packetResult = Packets::getPackets( buffer, sizeof( struct FFXIVARR_PACKET_HEADER ), - packetHeader, packetList ); - + const auto packetResult = + Packets::getPackets( buffer, sizeof( struct FFXIVARR_PACKET_HEADER ), packetHeader, packetList ); + if( packetResult == Incomplete ) { g_log.info( "Dropping connection due to incomplete packets." ); @@ -158,12 +159,12 @@ void Core::Network::GameConnection::OnRecv( std::vector< uint8_t > & buffer ) Disconnect(); return; } - + // Handle it handlePackets( packetHeader, packetList ); } -void Core::Network::GameConnection::OnError( const boost::system::error_code & error ) +void Core::Network::GameConnection::OnError( const boost::system::error_code& error ) { g_log.debug( "GameConnection ERROR: " + error.message() ); } @@ -189,25 +190,24 @@ void Core::Network::GameConnection::handleZonePacket( const Packets::GamePacket& auto itStr = m_zoneHandlerStrMap.find( pPacket.getSubType() ); std::string name = itStr != m_zoneHandlerStrMap.end() ? itStr->second : "unknown"; // dont display packet notification if it is a ping or pos update, don't want the spam - if( pPacket.getSubType() != PingHandler && - pPacket.getSubType() != UpdatePositionHandler ) + if( pPacket.getSubType() != PingHandler && pPacket.getSubType() != UpdatePositionHandler ) - g_log.debug( sessionStr + " Handling Zone IPC : " + name + "( " + - boost::str( boost::format( "%|04X|" ) % - static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + " )" ); + g_log.debug( + sessionStr + " Handling Zone IPC : " + name + "( " + + boost::str( boost::format( "%|04X|" ) % static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + + " )" ); ( this->*( it->second ) )( pPacket, *m_pSession->getPlayer() ); } else { g_log.debug( sessionStr + " Undefined Zone IPC : Unknown ( " + - boost::str( boost::format( "%|04X|" ) % - static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + " )" ); + boost::str( boost::format( "%|04X|" ) % static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + + " )" ); g_log.debug( "\n" + pPacket.toString() ); } } - void Core::Network::GameConnection::handleChatPacket( const Packets::GamePacket& pPacket ) { auto it = m_chatHandlerMap.find( pPacket.getSubType() ); @@ -221,16 +221,16 @@ void Core::Network::GameConnection::handleChatPacket( const Packets::GamePacket& // dont display packet notification if it is a ping or pos update, don't want the spam g_log.debug( sessionStr + " Handling Chat IPC : " + name + "( " + - boost::str( boost::format( "%|04X|" ) % - static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + " )" ); + boost::str( boost::format( "%|04X|" ) % static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + + " )" ); ( this->*( it->second ) )( pPacket, *m_pSession->getPlayer() ); } else { g_log.debug( sessionStr + " Undefined Chat IPC : Unknown ( " + - boost::str( boost::format( "%|04X|" ) % - static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + " )" ); + boost::str( boost::format( "%|04X|" ) % static_cast< uint32_t >( pPacket.getSubType() & 0xFFFF ) ) + + " )" ); g_log.debug( pPacket.toString() ); } } @@ -242,20 +242,19 @@ void Core::Network::GameConnection::handlePacket( Core::Network::Packets::GamePa switch( m_conType ) { - case Network::ConnectionType::Zone: - handleZonePacket( *pPacket ); - break; + case Network::ConnectionType::Zone: + handleZonePacket( *pPacket ); + break; - case Network::ConnectionType::Chat: - handleChatPacket( *pPacket ); - break; + case Network::ConnectionType::Chat: + handleChatPacket( *pPacket ); + break; } - } void Core::Network::GameConnection::sendPackets( Packets::PacketContainer* pPacket ) { - //g_log.Log(LoggingSeverity::info, pPacket->toString()); + // g_log.Log(LoggingSeverity::info, pPacket->toString()); std::vector< uint8_t > sendBuffer; pPacket->fillSendBuffer( sendBuffer ); @@ -297,7 +296,6 @@ void Core::Network::GameConnection::processOutQueue() if( totalSize > 0 ) sendPackets( &pRP ); - } void Core::Network::GameConnection::sendSinglePacket( Packets::GamePacket* pPacket ) @@ -314,7 +312,7 @@ void Core::Network::GameConnection::injectPacket( const std::string& packetpath, memset( packet, 0, 0x11570 ); // get the packet name / path from the command arguments - FILE *fp = nullptr; + FILE* fp = nullptr; fp = fopen( packetpath.c_str(), "rb" ); if( fp == nullptr ) { @@ -326,7 +324,7 @@ void Core::Network::GameConnection::injectPacket( const std::string& packetpath, fseek( fp, 0, SEEK_END ); int32_t size = ftell( fp ); rewind( fp ); - if ( fread( packet, sizeof( char ), size, fp ) != size ) + if( fread( packet, sizeof( char ), size, fp ) != size ) { g_log.error( "Packet " + packetpath + " did not read full size: " + std::to_string( size ) ); return; @@ -356,8 +354,9 @@ void Core::Network::GameConnection::injectPacket( const std::string& packetpath, } } -void Core::Network::GameConnection::handlePackets( const Core::Network::Packets::FFXIVARR_PACKET_HEADER& ipcHeader, - const std::vector< Core::Network::Packets::FFXIVARR_PACKET_RAW >& packetData ) +void Core::Network::GameConnection::handlePackets( + const Core::Network::Packets::FFXIVARR_PACKET_HEADER& ipcHeader, + const std::vector< Core::Network::Packets::FFXIVARR_PACKET_RAW >& packetData ) { // if a session is set, update the last time it recieved a game packet if( m_pSession ) @@ -369,7 +368,7 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets: { case 1: { - char* id = ( char* ) &( inPacket.data[4] ); + char* id = (char*)&( inPacket.data[4] ); uint32_t playerId = boost::lexical_cast< uint32_t >( id ); auto pCon = boost::static_pointer_cast< GameConnection, Connection >( shared_from_this() ); @@ -387,10 +386,10 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets: } session = g_serverZone.getSession( playerId ); } - //TODO: Catch more things in lobby and send real errors + // TODO: Catch more things in lobby and send real errors else if( !session->isValid() || ( session->getPlayer() && session->getPlayer()->getLastPing() != 0 ) ) { - g_log.error( "[" + std::string(id) + "] Session INVALID, disconnecting" ); + g_log.error( "[" + std::string( id ) + "] Session INVALID, disconnecting" ); Disconnect(); return; } @@ -400,7 +399,7 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets: m_pSession = session; GamePacket pPe( 0x00, 0x18, 0, 0, 0x07 ); - //pPe.setValAt< uint32_t >( 0x10, 0xE0000005 ); + // pPe.setValAt< uint32_t >( 0x10, 0xE0000005 ); pPe.setValAt< uint32_t >( 0x10, 0xE0037603 ); pPe.setValAt< uint32_t >( 0x14, static_cast< uint32_t >( time( nullptr ) ) ); sendSinglePacket( &pPe ); @@ -428,7 +427,6 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets: } break; - } case 3: // game packet { @@ -438,8 +436,8 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets: } case 7: // keep alive { - uint32_t id = *( uint32_t* ) &inPacket.data[0]; - uint32_t timeStamp = *( uint32_t* ) &inPacket.data[4]; + uint32_t id = *(uint32_t*)&inPacket.data[0]; + uint32_t timeStamp = *(uint32_t*)&inPacket.data[4]; GamePacket pPe( 0x00, 0x18, 0, 0, 0x08 ); pPe.setValAt< uint32_t >( 0x10, id ); @@ -453,6 +451,5 @@ void Core::Network::GameConnection::handlePackets( const Core::Network::Packets: break; } } - } } diff --git a/src/servers/Server_Zone/Network/GameConnection.h b/src/servers/Server_Zone/Network/GameConnection.h index d4e2dfc2..8155f57e 100644 --- a/src/servers/Server_Zone/Network/GameConnection.h +++ b/src/servers/Server_Zone/Network/GameConnection.h @@ -1,9 +1,9 @@ #ifndef GAMECONNECTION_H #define GAMECONNECTION_H -#include #include #include +#include #include #include @@ -14,117 +14,112 @@ namespace Core { namespace Network { -enum ConnectionType : uint8_t -{ - Zone = 1, - Chat = 2, - Lobby = 3, - None -}; + enum ConnectionType : uint8_t + { + Zone = 1, + Chat = 2, + Lobby = 3, + None + }; -class GameConnection : public Connection -{ + class GameConnection : public Connection + { -private: - typedef void ( GameConnection::* Handler )( const Packets::GamePacket& inPacket, Entity::Player& player ); + private: + typedef void ( GameConnection::*Handler )( const Packets::GamePacket& inPacket, Entity::Player& player ); - using HandlerMap = std::map< uint16_t, Handler >; - using HandlerStrMap = std::map< uint16_t, std::string >; + using HandlerMap = std::map< uint16_t, Handler >; + using HandlerStrMap = std::map< uint16_t, std::string >; - AcceptorPtr m_pAcceptor; + AcceptorPtr m_pAcceptor; - // handler for game packets ( main type 0x03, connection type 1 ) - HandlerMap m_zoneHandlerMap; - HandlerStrMap m_zoneHandlerStrMap; + // handler for game packets ( main type 0x03, connection type 1 ) + HandlerMap m_zoneHandlerMap; + HandlerStrMap m_zoneHandlerStrMap; - // handler for game packets ( main type 0x03, connection type 2 ) - HandlerMap m_chatHandlerMap; - HandlerStrMap m_chatHandlerStrMap; + // handler for game packets ( main type 0x03, connection type 2 ) + HandlerMap m_chatHandlerMap; + HandlerStrMap m_chatHandlerStrMap; - SessionPtr m_pSession; + SessionPtr m_pSession; - LockedQueue< Packets::GamePacketPtr > m_inQueue; - LockedQueue< Packets::GamePacketPtr > m_outQueue; + LockedQueue< Packets::GamePacketPtr > m_inQueue; + LockedQueue< Packets::GamePacketPtr > m_outQueue; -public: - ConnectionType m_conType; + public: + ConnectionType m_conType; - GameConnection( HivePtr pHive, AcceptorPtr pAcceptor ); + GameConnection( HivePtr pHive, AcceptorPtr pAcceptor ); - ~GameConnection(); + ~GameConnection(); - // overwrite the parents onConnect for our game socket needs - void OnAccept( const std::string & host, uint16_t port ) override; + // overwrite the parents onConnect for our game socket needs + void OnAccept( const std::string& host, uint16_t port ) override; - void OnDisconnect() override; + void OnDisconnect() override; - void OnRecv( std::vector< uint8_t > & buffer ) override; + void OnRecv( std::vector< uint8_t >& buffer ) override; - void OnError( const boost::system::error_code & error ) override; + void OnError( const boost::system::error_code& error ) override; - void handlePackets( const Packets::FFXIVARR_PACKET_HEADER& ipcHeader, - const std::vector< Packets::FFXIVARR_PACKET_RAW >& packetData ); + void handlePackets( const Packets::FFXIVARR_PACKET_HEADER& ipcHeader, + const std::vector< Packets::FFXIVARR_PACKET_RAW >& packetData ); - void queueInPacket( Packets::GamePacketPtr inPacket ); - void queueOutPacket( Packets::GamePacketPtr outPacket ); + void queueInPacket( Packets::GamePacketPtr inPacket ); + void queueOutPacket( Packets::GamePacketPtr outPacket ); - void processInQueue(); - void processOutQueue(); + void processInQueue(); + void processOutQueue(); - void handlePacket( Packets::GamePacketPtr pPacket ); + void handlePacket( Packets::GamePacketPtr pPacket ); - void handleZonePacket( const Packets::GamePacket& pPacket ); + void handleZonePacket( const Packets::GamePacket& pPacket ); - void handleChatPacket( const Packets::GamePacket& pPacket ); + void handleChatPacket( const Packets::GamePacket& pPacket ); - void sendPackets( Packets::PacketContainer* pPacket ); + void sendPackets( Packets::PacketContainer* pPacket ); - void sendSinglePacket( Packets::GamePacket* pPacket ); + void sendSinglePacket( Packets::GamePacket* pPacket ); - void injectPacket( const std::string& packetpath, Entity::Player& player ); + void injectPacket( const std::string& packetpath, Entity::Player& player ); - DECLARE_HANDLER( initHandler ); - DECLARE_HANDLER( finishLoadingHandler ); - DECLARE_HANDLER( blackListHandler ); - DECLARE_HANDLER( socialListHandler ); - DECLARE_HANDLER( linkshellListHandler ); - DECLARE_HANDLER( playTimeHandler ); - DECLARE_HANDLER( pingHandler ); - DECLARE_HANDLER( fcInfoReqHandler ); - DECLARE_HANDLER( setSearchInfoHandler ); - DECLARE_HANDLER( reqSearchInfoHandler ); - DECLARE_HANDLER( updatePositionHandler ); - DECLARE_HANDLER( chatHandler ); - DECLARE_HANDLER( zoneLineHandler ); - DECLARE_HANDLER( actionHandler ); - DECLARE_HANDLER( inventoryModifyHandler ); - DECLARE_HANDLER( discoveryHandler ); - DECLARE_HANDLER( eventHandler ); - DECLARE_HANDLER( logoutHandler ); - - DECLARE_HANDLER( cfDutyInfoRequest ); - DECLARE_HANDLER( cfRegisterDuty ); - DECLARE_HANDLER( cfRegisterRoulette ); - DECLARE_HANDLER( cfDutyAccepted ); + DECLARE_HANDLER( initHandler ); + DECLARE_HANDLER( finishLoadingHandler ); + DECLARE_HANDLER( blackListHandler ); + DECLARE_HANDLER( socialListHandler ); + DECLARE_HANDLER( linkshellListHandler ); + DECLARE_HANDLER( playTimeHandler ); + DECLARE_HANDLER( pingHandler ); + DECLARE_HANDLER( fcInfoReqHandler ); + DECLARE_HANDLER( setSearchInfoHandler ); + DECLARE_HANDLER( reqSearchInfoHandler ); + DECLARE_HANDLER( updatePositionHandler ); + DECLARE_HANDLER( chatHandler ); + DECLARE_HANDLER( zoneLineHandler ); + DECLARE_HANDLER( actionHandler ); + DECLARE_HANDLER( inventoryModifyHandler ); + DECLARE_HANDLER( discoveryHandler ); + DECLARE_HANDLER( eventHandler ); + DECLARE_HANDLER( logoutHandler ); + DECLARE_HANDLER( cfDutyInfoRequest ); + DECLARE_HANDLER( cfRegisterDuty ); + DECLARE_HANDLER( cfRegisterRoulette ); + DECLARE_HANDLER( cfDutyAccepted ); - DECLARE_HANDLER( skillHandler ); + DECLARE_HANDLER( skillHandler ); - DECLARE_HANDLER( gm1Handler ); - DECLARE_HANDLER( gm2Handler ); + DECLARE_HANDLER( gm1Handler ); + DECLARE_HANDLER( gm2Handler ); - DECLARE_HANDLER( reqEquipDisplayFlagsHandler ); + DECLARE_HANDLER( reqEquipDisplayFlagsHandler ); - DECLARE_HANDLER( performNoteHandler ); + DECLARE_HANDLER( performNoteHandler ); - DECLARE_HANDLER( tellHandler ); - -}; - - - -} -} + DECLARE_HANDLER( tellHandler ); + }; +} // namespace Network +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp b/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp index 86404013..f4389caa 100644 --- a/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp +++ b/src/servers/Server_Zone/Network/Handlers/ActionHandler.cpp @@ -1,39 +1,39 @@ #include +#include +#include #include #include -#include -#include #include #include #include "Network/GameConnection.h" +#include "ServerZone.h" #include "Session.h" #include "Zone/Zone.h" -#include "Zone/ZonePosition.h" -#include "ServerZone.h" #include "Zone/ZoneMgr.h" +#include "Zone/ZonePosition.h" -#include "Network/PacketWrappers/InitUIPacket.h" -#include "Network/PacketWrappers/PingPacket.h" -#include "Network/PacketWrappers/MoveActorPacket.h" -#include "Network/PacketWrappers/ChatPacket.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket144.h" -#include "Network/PacketWrappers/EventStartPacket.h" +#include "Network/PacketWrappers/ChatPacket.h" #include "Network/PacketWrappers/EventFinishPacket.h" +#include "Network/PacketWrappers/EventStartPacket.h" +#include "Network/PacketWrappers/InitUIPacket.h" +#include "Network/PacketWrappers/MoveActorPacket.h" +#include "Network/PacketWrappers/PingPacket.h" #include "Network/PacketWrappers/PlayerStateFlagsPacket.h" +#include "Network/PacketWrappers/ServerNoticePacket.h" -#include "DebugCommand/DebugCommandHandler.h" -#include "Actor/Player.h" -#include "Inventory/Inventory.h" -#include "Forwards.h" -#include "Event/EventHelper.h" #include "Action/Action.h" #include "Action/ActionTeleport.h" +#include "Actor/Player.h" +#include "DebugCommand/DebugCommandHandler.h" +#include "Event/EventHelper.h" +#include "Forwards.h" +#include "Inventory/Inventory.h" extern Core::Logger g_log; extern Core::ServerZone g_serverZone; @@ -45,198 +45,201 @@ using namespace Core::Common; using namespace Core::Network::Packets; using namespace Core::Network::Packets::Server; -void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { - uint16_t commandId = inPacket.getValAt< uint16_t >( 0x20 ); - uint64_t param1 = inPacket.getValAt< uint64_t >( 0x24 ); - uint32_t param11 = inPacket.getValAt< uint32_t >( 0x24 ); - uint32_t param12 = inPacket.getValAt< uint32_t >( 0x28 ); - uint32_t param2 = inPacket.getValAt< uint32_t >( 0x2C ); - uint64_t param3 = inPacket.getValAt< uint64_t >( 0x38 ); + uint16_t commandId = inPacket.getValAt< uint16_t >( 0x20 ); + uint64_t param1 = inPacket.getValAt< uint64_t >( 0x24 ); + uint32_t param11 = inPacket.getValAt< uint32_t >( 0x24 ); + uint32_t param12 = inPacket.getValAt< uint32_t >( 0x28 ); + uint32_t param2 = inPacket.getValAt< uint32_t >( 0x2C ); + uint64_t param3 = inPacket.getValAt< uint64_t >( 0x38 ); - g_log.debug( "[" + std::to_string( m_pSession->getId() ) + "] Incoming action: " + - boost::str( boost::format( "%|04X|" ) % ( uint32_t ) ( commandId & 0xFFFF ) ) + - "\nparam1: " + boost::str( boost::format( "%|016X|" ) % ( uint64_t ) ( param1 & 0xFFFFFFFFFFFFFFF ) ) + - "\nparam2: " + boost::str( boost::format( "%|08X|" ) % ( uint32_t ) ( param2 & 0xFFFFFFFF ) ) + - "\nparam3: " + boost::str( boost::format( "%|016X|" ) % ( uint64_t ) ( param3 & 0xFFFFFFFFFFFFFFF ) ) - ); + g_log.debug( "[" + std::to_string( m_pSession->getId() ) + + "] Incoming action: " + boost::str( boost::format( "%|04X|" ) % ( uint32_t )( commandId & 0xFFFF ) ) + + "\nparam1: " + boost::str( boost::format( "%|016X|" ) % ( uint64_t )( param1 & 0xFFFFFFFFFFFFFFF ) ) + + "\nparam2: " + boost::str( boost::format( "%|08X|" ) % ( uint32_t )( param2 & 0xFFFFFFFF ) ) + + "\nparam3: " + boost::str( boost::format( "%|016X|" ) % ( uint64_t )( param3 & 0xFFFFFFFFFFFFFFF ) ) ); + // g_log.Log(LoggingSeverity::debug, "[" + std::to_string(m_pSession->getId()) + "] " + pInPacket->toString()); - //g_log.Log(LoggingSeverity::debug, "[" + std::to_string(m_pSession->getId()) + "] " + pInPacket->toString()); + switch( commandId ) + { + case 0x01: // Toggle sheathe + { + if( param11 == 1 ) + player.setStance( Entity::Actor::Stance::Active ); + else + { + player.setStance( Entity::Actor::Stance::Passive ); + player.setAutoattack( false ); + } - switch( commandId ) - { - case 0x01: // Toggle sheathe - { - if ( param11 == 1 ) - player.setStance( Entity::Actor::Stance::Active ); - else - { - player.setStance( Entity::Actor::Stance::Passive ); - player.setAutoattack( false ); - } + player.sendToInRangeSet( ActorControlPacket142( player.getId(), 0, param11, 1 ) ); - player.sendToInRangeSet( ActorControlPacket142( player.getId(), 0, param11, 1 ) ); + break; + } + case 0x02: // Toggle auto-attack + { + if( param11 == 1 ) + { + player.setAutoattack( true ); + player.setStance( Entity::Actor::Stance::Active ); + } + else + player.setAutoattack( false ); - break; - } - case 0x02: // Toggle auto-attack - { - if ( param11 == 1 ) - { - player.setAutoattack( true ); - player.setStance( Entity::Actor::Stance::Active ); - } - else - player.setAutoattack( false ); + player.sendToInRangeSet( ActorControlPacket142( player.getId(), 1, param11, 1 ) ); - player.sendToInRangeSet( ActorControlPacket142( player.getId(), 1, param11, 1 ) ); + break; + } + case 0x03: // Change target + { - break; - } - case 0x03: // Change target - { + uint64_t targetId = inPacket.getValAt< uint64_t >( 0x24 ); + player.changeTarget( targetId ); + break; + } + case 0x65: + { + player.dismount(); + break; + } + case 0x68: // Remove status (clicking it off) + { + // todo: check if status can be removed by client from exd + player.removeSingleStatusEffectById( static_cast< uint32_t >( param1 ) ); + break; + } + case 0x69: // Cancel cast + { + if( player.getCurrentAction() ) + player.getCurrentAction()->setInterrupted(); + break; + } + case 0x12E: // Set player title + { + player.setTitle( static_cast< uint16_t >( param1 ) ); + break; + } + case 0x12F: // Get title list + { + ZoneChannelPacket< FFXIVIpcPlayerTitleList > titleListPacket( player.getId() ); + memcpy( titleListPacket.data().titleList, player.getTitleList(), sizeof( titleListPacket.data().titleList ) ); - uint64_t targetId = inPacket.getValAt< uint64_t >( 0x24 ); - player.changeTarget( targetId ); - break; - } - case 0x65: - { - player.dismount(); - break; - } - case 0x68: // Remove status (clicking it off) - { - // todo: check if status can be removed by client from exd - player.removeSingleStatusEffectById( static_cast< uint32_t >( param1 ) ); - break; - } - case 0x69: // Cancel cast - { - if( player.getCurrentAction() ) - player.getCurrentAction()->setInterrupted(); - break; - } - case 0x12E: // Set player title - { - player.setTitle( static_cast< uint16_t >( param1 ) ); - break; - } - case 0x12F: // Get title list - { - ZoneChannelPacket< FFXIVIpcPlayerTitleList > titleListPacket( player.getId() ); - memcpy( titleListPacket.data().titleList, player.getTitleList(), sizeof( titleListPacket.data().titleList ) ); + player.queuePacket( titleListPacket ); + break; + } + case 0x133: // Update howtos seen + { + uint32_t howToId = static_cast< uint32_t >( param1 ); + player.updateHowtosSeen( howToId ); + break; + } + case 0x1F4: // emote + { + uint64_t targetId = player.getTargetId(); + uint32_t emoteId = inPacket.getValAt< uint32_t >( 0x24 ); - player.queuePacket( titleListPacket ); - break; - } - case 0x133: // Update howtos seen - { - uint32_t howToId = static_cast< uint32_t >( param1 ); - player.updateHowtosSeen( howToId ); - break; - } - case 0x1F4: // emote - { - uint64_t targetId = player.getTargetId(); - uint32_t emoteId = inPacket.getValAt< uint32_t >( 0x24 ); + player.sendToInRangeSet( ActorControlPacket144( player.getId(), Emote, emoteId, 0, 0, 0, targetId ) ); + break; + } + case 0xC8: // return dead + { + switch( static_cast< ResurrectType >( param1 ) ) + { + case ResurrectType::RaiseSpell: + // todo: handle raise case (set position to raiser, apply weakness status, set hp/mp/tp as well as packet) + player.returnToHomepoint(); + break; + case ResurrectType::Return: + player.returnToHomepoint(); + break; + default: + break; + } + } + case 0xC9: // Finish zoning + { + switch( player.getZoningType() ) + { + case ZoneingType::None: + player.sendToInRangeSet( ActorControlPacket143( player.getId(), ZoneIn, 0x01 ), true ); + break; + case ZoneingType::Teleport: + player.sendToInRangeSet( ActorControlPacket143( player.getId(), ZoneIn, 0x01, 0, 0, 110 ), true ); + break; + case ZoneingType::Return: + case ZoneingType::ReturnDead: + { + if( player.getStatus() == Entity::Actor::ActorStatus::Dead ) + { + player.resetHp(); + player.resetMp(); + player.setStatus( Entity::Actor::ActorStatus::Idle ); - player.sendToInRangeSet( ActorControlPacket144( player.getId(), Emote, emoteId, 0, 0, 0, targetId ) ); - break; - } - case 0xC8: // return dead - { - switch ( static_cast < ResurrectType >( param1 ) ) - { - case ResurrectType::RaiseSpell: - // todo: handle raise case (set position to raiser, apply weakness status, set hp/mp/tp as well as packet) - player.returnToHomepoint(); - break; - case ResurrectType::Return: - player.returnToHomepoint(); - break; - default: - break; - } - - } - case 0xC9: // Finish zoning - { - switch( player.getZoningType() ) - { - case ZoneingType::None: - player.sendToInRangeSet( ActorControlPacket143( player.getId(), ZoneIn, 0x01 ), true ); - break; - case ZoneingType::Teleport: - player.sendToInRangeSet( ActorControlPacket143( player.getId(), ZoneIn, 0x01, 0, 0, 110 ), true ); - break; - case ZoneingType::Return: - case ZoneingType::ReturnDead: - { - if( player.getStatus() == Entity::Actor::ActorStatus::Dead ) - { - player.resetHp(); - player.resetMp(); - player.setStatus( Entity::Actor::ActorStatus::Idle ); + player.sendToInRangeSet( ActorControlPacket143( player.getId(), ZoneIn, 0x01, 0x01, 0, 111 ), true ); + player.sendToInRangeSet( + ActorControlPacket142( player.getId(), SetStatus, + static_cast< uint8_t >( Entity::Actor::ActorStatus::Idle ) ), + true ); + } + else + player.sendToInRangeSet( ActorControlPacket143( player.getId(), ZoneIn, 0x01, 0x00, 0, 111 ), true ); + } + break; + case ZoneingType::FadeIn: + break; + } - player.sendToInRangeSet( ActorControlPacket143( player.getId(), ZoneIn, 0x01, 0x01, 0, 111 ), true ); - player.sendToInRangeSet( ActorControlPacket142( player.getId(), SetStatus, static_cast< uint8_t >( Entity::Actor::ActorStatus::Idle ) ), true ); - } - else - player.sendToInRangeSet( ActorControlPacket143( player.getId(), ZoneIn, 0x01, 0x00, 0, 111 ), true ); - } - break; - case ZoneingType::FadeIn: - break; - } + player.setZoningType( Common::ZoneingType::None ); - player.setZoningType( Common::ZoneingType::None ); + player.unsetStateFlag( PlayerStateFlag::BetweenAreas ); + player.unsetStateFlag( PlayerStateFlag::BetweenAreas1 ); + player.sendStateFlags(); + break; + } - player.unsetStateFlag( PlayerStateFlag::BetweenAreas ); - player.unsetStateFlag( PlayerStateFlag::BetweenAreas1 ); - player.sendStateFlags(); - break; - } + case 0xCA: // Teleport + { + // TODO: only register this action if enough gil is in possession + auto targetAetheryte = g_exdData.getAetheryteInfo( param11 ); - case 0xCA: // Teleport - { - // TODO: only register this action if enough gil is in possession - auto targetAetheryte = g_exdData.getAetheryteInfo( param11 ); + if( targetAetheryte ) + { + auto fromAetheryte = g_exdData.getAetheryteInfo( g_exdData.m_zoneInfoMap[player.getZoneId()].aetheryte_index ); - if( targetAetheryte ) - { - auto fromAetheryte = g_exdData.getAetheryteInfo( g_exdData.m_zoneInfoMap[player.getZoneId()].aetheryte_index ); + // calculate cost - does not apply for favorite points or homepoints neither checks for aether tickets + auto cost = + static_cast< uint16_t >( ( sqrt( pow( fromAetheryte->map_coord_x - targetAetheryte->map_coord_x, 2 ) + + pow( fromAetheryte->map_coord_y - targetAetheryte->map_coord_y, 2 ) ) / + 2 ) + + 100 ); - // calculate cost - does not apply for favorite points or homepoints neither checks for aether tickets - auto cost = static_cast< uint16_t > ( ( sqrt( pow( fromAetheryte->map_coord_x - targetAetheryte->map_coord_x, 2 ) + - pow( fromAetheryte->map_coord_y - targetAetheryte->map_coord_y, 2 ) ) / 2 ) + 100 ); + // cap at 999 gil + cost = cost > uint16_t{ 999 } ? uint16_t{ 999 } : cost; - // cap at 999 gil - cost = cost > uint16_t{999} ? uint16_t{999} : cost; + bool insufficientGil = player.getCurrency( Inventory::CurrencyType::Gil ) < cost; + // todo: figure out what param1 really does + player.queuePacket( ActorControlPacket143( player.getId(), TeleportStart, insufficientGil ? 2 : 0, param11 ) ); - bool insufficientGil = player.getCurrency( Inventory::CurrencyType::Gil ) < cost; - // todo: figure out what param1 really does - player.queuePacket( ActorControlPacket143( player.getId(), TeleportStart, insufficientGil ? 2 : 0, param11 ) ); - - if( !insufficientGil ) - { - Action::ActionTeleportPtr pActionTeleport( new Action::ActionTeleport( player.getAsPlayer(), param11, cost ) ); - player.setCurrentAction( pActionTeleport ); - } - } - break; - } - case 0x1B5: // Dye item - { - break; - } - default: - { - g_log.debug( "[" + std::to_string( m_pSession->getId() ) + "] Unhandled action: " + - boost::str( boost::format( "%|04X|" ) % (uint32_t) ( commandId & 0xFFFF ) ) ); - break; - } - } + if( !insufficientGil ) + { + Action::ActionTeleportPtr pActionTeleport( + new Action::ActionTeleport( player.getAsPlayer(), param11, cost ) ); + player.setCurrentAction( pActionTeleport ); + } + } + break; + } + case 0x1B5: // Dye item + { + break; + } + default: + { + g_log.debug( "[" + std::to_string( m_pSession->getId() ) + "] Unhandled action: " + + boost::str( boost::format( "%|04X|" ) % ( uint32_t )( commandId & 0xFFFF ) ) ); + break; + } + } } diff --git a/src/servers/Server_Zone/Network/Handlers/CFHandlers.cpp b/src/servers/Server_Zone/Network/Handlers/CFHandlers.cpp index b3df64e5..a8fc1fc7 100644 --- a/src/servers/Server_Zone/Network/Handlers/CFHandlers.cpp +++ b/src/servers/Server_Zone/Network/Handlers/CFHandlers.cpp @@ -1,17 +1,17 @@ #include +#include #include #include -#include #include +#include "Actor/Player.h" #include "Network/GameConnection.h" -#include "Session.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket144.h" #include "Network/PacketWrappers/PlayerStateFlagsPacket.h" -#include "Actor/Player.h" +#include "Network/PacketWrappers/ServerNoticePacket.h" +#include "Session.h" #include "Forwards.h" @@ -21,14 +21,12 @@ using namespace Core::Common; using namespace Core::Network::Packets; using namespace Core::Network::Packets::Server; - -void Core::Network::GameConnection::cfDutyInfoRequest( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::cfDutyInfoRequest( const Packets::GamePacket& inPacket, Entity::Player& player ) { ZoneChannelPacket< FFXIVIpcCFDutyInfo > dutyInfoPacket( player.getId() ); auto penaltyMinutes = player.getCFPenaltyMinutes(); - if (penaltyMinutes > 255) + if( penaltyMinutes > 255 ) { // cap it since it's uint8_t in packets penaltyMinutes = 255; @@ -39,11 +37,9 @@ void Core::Network::GameConnection::cfDutyInfoRequest( const Packets::GamePacket ZoneChannelPacket< FFXIVIpcCFPlayerInNeed > inNeedsPacket( player.getId() ); queueOutPacket( inNeedsPacket ); - } -void Core::Network::GameConnection::cfRegisterDuty( const Packets::GamePacket& inPacket, - Entity::Player& player) +void Core::Network::GameConnection::cfRegisterDuty( const Packets::GamePacket& inPacket, Entity::Player& player ) { // TODO use for loop for this auto contentId1 = inPacket.getValAt< uint16_t >( 46 ); @@ -52,12 +48,12 @@ void Core::Network::GameConnection::cfRegisterDuty( const Packets::GamePacket& i auto contentId4 = inPacket.getValAt< uint16_t >( 52 ); auto contentId5 = inPacket.getValAt< uint16_t >( 54 ); - player.sendDebug("Duty register request"); - player.sendDebug("ContentId1" + std::to_string(contentId1)); - player.sendDebug("ContentId2" + std::to_string(contentId2)); - player.sendDebug("ContentId3" + std::to_string(contentId3)); - player.sendDebug("ContentId4" + std::to_string(contentId4)); - player.sendDebug("ContentId5" + std::to_string(contentId5)); + player.sendDebug( "Duty register request" ); + player.sendDebug( "ContentId1" + std::to_string( contentId1 ) ); + player.sendDebug( "ContentId2" + std::to_string( contentId2 ) ); + player.sendDebug( "ContentId3" + std::to_string( contentId3 ) ); + player.sendDebug( "ContentId4" + std::to_string( contentId4 ) ); + player.sendDebug( "ContentId5" + std::to_string( contentId5 ) ); // let's cancel it because otherwise you can't register it again ZoneChannelPacket< FFXIVIpcCFNotify > cfCancelPacket( player.getId() ); @@ -66,14 +62,12 @@ void Core::Network::GameConnection::cfRegisterDuty( const Packets::GamePacket& i queueOutPacket( cfCancelPacket ); } -void Core::Network::GameConnection::cfRegisterRoulette( const Packets::GamePacket& inPacket, - Entity::Player& player) +void Core::Network::GameConnection::cfRegisterRoulette( const Packets::GamePacket& inPacket, Entity::Player& player ) { - player.sendDebug("Roulette register"); + player.sendDebug( "Roulette register" ); } -void Core::Network::GameConnection::cfDutyAccepted( const Packets::GamePacket& inPacket, - Entity::Player& player) +void Core::Network::GameConnection::cfDutyAccepted( const Packets::GamePacket& inPacket, Entity::Player& player ) { - player.sendDebug("TODO: Duty accept"); + player.sendDebug( "TODO: Duty accept" ); } diff --git a/src/servers/Server_Zone/Network/Handlers/EventHandlers.cpp b/src/servers/Server_Zone/Network/Handlers/EventHandlers.cpp index 8a9f814b..075eb6b8 100644 --- a/src/servers/Server_Zone/Network/Handlers/EventHandlers.cpp +++ b/src/servers/Server_Zone/Network/Handlers/EventHandlers.cpp @@ -6,19 +6,19 @@ #include +#include "Actor/Player.h" +#include "Event/EventHelper.h" +#include "Forwards.h" #include "Network/GameConnection.h" -#include "Session.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket144.h" -#include "Network/PacketWrappers/EventStartPacket.h" #include "Network/PacketWrappers/EventFinishPacket.h" +#include "Network/PacketWrappers/EventStartPacket.h" #include "Network/PacketWrappers/PlayerStateFlagsPacket.h" +#include "Network/PacketWrappers/ServerNoticePacket.h" #include "Script/ScriptManager.h" -#include "Actor/Player.h" -#include "Forwards.h" -#include "Event/EventHelper.h" +#include "Session.h" extern Core::Scripting::ScriptManager g_scriptMgr; @@ -26,27 +26,26 @@ using namespace Core::Common; using namespace Core::Network::Packets; using namespace Core::Network::Packets::Server; -void Core::Network::GameConnection::eventHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::eventHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { uint16_t eventHandlerId = inPacket.getValAt< uint16_t >( 0x12 ); // we need to abort the event in case it has not been scripted so the player wont be locked up - auto abortEventFunc = []( Core::Entity::Player& player, uint64_t actorId, uint32_t eventId ) - { + auto abortEventFunc = []( Core::Entity::Player& player, uint64_t actorId, uint32_t eventId ) { player.queuePacket( EventStartPacket( player.getId(), actorId, eventId, 1, 0, 0 ) ); player.queuePacket( EventFinishPacket( player.getId(), eventId, 1, 0 ) ); // this isn't ideal as it will also reset any other status that might be active player.queuePacket( PlayerStateFlagsPacket( player, PlayerStateFlagList{} ) ); }; - std::string eventIdStr = boost::str( boost::format( "%|04X|" ) % static_cast< uint32_t >( eventHandlerId & 0xFFFF ) ); + std::string eventIdStr = + boost::str( boost::format( "%|04X|" ) % static_cast< uint32_t >( eventHandlerId & 0xFFFF ) ); player.sendDebug( "---------------------------------------" ); player.sendDebug( "EventHandler ( " + eventIdStr + " )" ); switch( eventHandlerId ) { - + case ClientZoneIpcType::TalkEventHandler: // Talk event { uint64_t actorId = inPacket.getValAt< uint64_t >( 0x20 ); @@ -70,7 +69,6 @@ void Core::Network::GameConnection::eventHandler( const Packets::GamePacket& inP break; } - case ClientZoneIpcType::WithinRangeEventHandler: { uint32_t eventId = inPacket.getValAt< uint32_t >( 0x24 ); @@ -144,14 +142,8 @@ void Core::Network::GameConnection::eventHandler( const Packets::GamePacket& inP linkshellEvent.data().unknown1 = 0x15a; player.queuePacket( linkshellEvent ); -// abortEventFunc( pPlayer, 0, eventId ); + // abortEventFunc( pPlayer, 0, eventId ); break; } - } - } - - - - diff --git a/src/servers/Server_Zone/Network/Handlers/GMCommandHandlers.cpp b/src/servers/Server_Zone/Network/Handlers/GMCommandHandlers.cpp index 923b37b9..55cb4735 100644 --- a/src/servers/Server_Zone/Network/Handlers/GMCommandHandlers.cpp +++ b/src/servers/Server_Zone/Network/Handlers/GMCommandHandlers.cpp @@ -1,39 +1,39 @@ #include +#include +#include #include #include -#include -#include #include #include #include "Network/GameConnection.h" +#include "ServerZone.h" #include "Session.h" #include "Zone/Zone.h" -#include "Zone/ZonePosition.h" -#include "ServerZone.h" #include "Zone/ZoneMgr.h" +#include "Zone/ZonePosition.h" -#include "Network/PacketWrappers/InitUIPacket.h" -#include "Network/PacketWrappers/PingPacket.h" -#include "Network/PacketWrappers/MoveActorPacket.h" -#include "Network/PacketWrappers/ChatPacket.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket144.h" -#include "Network/PacketWrappers/EventStartPacket.h" +#include "Network/PacketWrappers/ChatPacket.h" #include "Network/PacketWrappers/EventFinishPacket.h" +#include "Network/PacketWrappers/EventStartPacket.h" +#include "Network/PacketWrappers/InitUIPacket.h" +#include "Network/PacketWrappers/MoveActorPacket.h" +#include "Network/PacketWrappers/PingPacket.h" #include "Network/PacketWrappers/PlayerStateFlagsPacket.h" +#include "Network/PacketWrappers/ServerNoticePacket.h" -#include "DebugCommand/DebugCommandHandler.h" -#include "Actor/Player.h" -#include "Inventory/Inventory.h" -#include "Forwards.h" -#include "Event/EventHelper.h" #include "Action/Action.h" #include "Action/ActionTeleport.h" +#include "Actor/Player.h" +#include "DebugCommand/DebugCommandHandler.h" +#include "Event/EventHelper.h" +#include "Forwards.h" +#include "Inventory/Inventory.h" extern Core::Logger g_log; extern Core::ServerZone g_serverZone; @@ -102,13 +102,11 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac uint32_t param2 = inPacket.getValAt< uint32_t >( 0x28 ); uint32_t param3 = inPacket.getValAt< uint32_t >( 0x38 ); - g_log.debug( player.getName() + " used GM1 commandId: " + std::to_string( commandId ) + - ", params: " + std::to_string( param1 ) + ", " + - std::to_string( param2 ) + ", " + std::to_string( param3 ) ); + g_log.debug( player.getName() + " used GM1 commandId: " + std::to_string( commandId ) + ", params: " + + std::to_string( param1 ) + ", " + std::to_string( param2 ) + ", " + std::to_string( param3 ) ); Core::Entity::ActorPtr targetActor; - if( player.getId() == param3 ) { targetActor = player.getAsPlayer(); @@ -141,7 +139,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac player.sendNotice( "Race for " + targetPlayer->getName() + " was set to " + std::to_string( param1 ) ); targetPlayer->spawn( targetPlayer ); auto inRange = targetPlayer->getInRangeActors(); - for ( auto actor : inRange ) + for( auto actor : inRange ) { targetPlayer->despawn( actor->getAsPlayer() ); targetPlayer->spawn( actor->getAsPlayer() ); @@ -154,7 +152,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac player.sendNotice( "Tribe for " + targetPlayer->getName() + " was set to " + std::to_string( param1 ) ); targetPlayer->spawn( targetPlayer ); auto inRange = targetPlayer->getInRangeActors(); - for ( auto actor : inRange ) + for( auto actor : inRange ) { targetPlayer->despawn( actor->getAsPlayer() ); targetPlayer->spawn( actor->getAsPlayer() ); @@ -167,7 +165,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac player.sendNotice( "Sex for " + targetPlayer->getName() + " was set to " + std::to_string( param1 ) ); targetPlayer->spawn( targetPlayer ); auto inRange = targetActor->getInRangeActors(); - for ( auto actor : inRange ) + for( auto actor : inRange ) { targetPlayer->despawn( actor->getAsPlayer() ); targetPlayer->spawn( actor->getAsPlayer() ); @@ -184,30 +182,27 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac { targetPlayer->getCurrentZone()->setWeatherOverride( param1 ); player.sendNotice( "Weather in Zone \"" + targetPlayer->getCurrentZone()->getName() + "\" of " + - targetPlayer->getName() + " set in range." ); + targetPlayer->getName() + " set in range." ); break; } case GmCommand::Call: { - if ( targetPlayer->getZoneId() != player.getZoneId() ) + if( targetPlayer->getZoneId() != player.getZoneId() ) targetPlayer->setZone( player.getZoneId() ); - targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z, - player.getRotation() ); + targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z, player.getRotation() ); player.sendNotice( "Calling " + targetPlayer->getName() ); break; } case GmCommand::Inspect: { - player.sendNotice( "Name: " + targetPlayer->getName() + - "\nGil: " + std::to_string( targetPlayer->getCurrency( 1 ) ) + - "\nZone: " + targetPlayer->getCurrentZone()->getName() + - "(" + std::to_string( targetPlayer->getZoneId() ) + ")" + - "\nClass: " + std::to_string( static_cast< uint8_t >( targetPlayer->getClass() ) ) + - "\nLevel: " + std::to_string( targetPlayer->getLevel() ) + - "\nExp: " + std::to_string( targetPlayer->getExp() ) + - "\nSearchMessage: " + targetPlayer->getSearchMessage() + - "\nPlayTime: " + std::to_string( targetPlayer->getPlayTime() ) ); + player.sendNotice( + "Name: " + targetPlayer->getName() + "\nGil: " + std::to_string( targetPlayer->getCurrency( 1 ) ) + + "\nZone: " + targetPlayer->getCurrentZone()->getName() + "(" + std::to_string( targetPlayer->getZoneId() ) + + ")" + "\nClass: " + std::to_string( static_cast< uint8_t >( targetPlayer->getClass() ) ) + "\nLevel: " + + std::to_string( targetPlayer->getLevel() ) + "\nExp: " + std::to_string( targetPlayer->getExp() ) + + "\nSearchMessage: " + targetPlayer->getSearchMessage() + + "\nPlayTime: " + std::to_string( targetPlayer->getPlayTime() ) ); break; } case GmCommand::Speed: @@ -236,9 +231,9 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac strcpy( searchInfoPacket.data().searchMessage, targetPlayer->getSearchMessage() ); targetPlayer->queuePacket( searchInfoPacket ); - targetPlayer->sendToInRangeSet( ActorControlPacket142( player.getId(), SetStatusIcon, - static_cast< uint8_t >( player.getOnlineStatus() ) ), - true ); + targetPlayer->sendToInRangeSet( + ActorControlPacket142( player.getId(), SetStatusIcon, static_cast< uint8_t >( player.getOnlineStatus() ) ), + true ); player.sendNotice( "Icon for " + targetPlayer->getName() + " was set to " + std::to_string( param1 ) ); break; } @@ -268,32 +263,30 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac } case GmCommand::Inv: { - if ( targetActor->getInvincibilityType() == Common::InvincibilityType::InvincibilityRefill ) + if( targetActor->getInvincibilityType() == Common::InvincibilityType::InvincibilityRefill ) targetActor->setInvincibilityType( Common::InvincibilityType::InvincibilityNone ); else targetActor->setInvincibilityType( Common::InvincibilityType::InvincibilityRefill ); - player.sendNotice( "Invincibility for " + targetPlayer->getName() + - " was switched." ); + player.sendNotice( "Invincibility for " + targetPlayer->getName() + " was switched." ); break; } case GmCommand::Orchestrion: { - if ( param1 == 1 ) + if( param1 == 1 ) { - if ( param2 == 0 ) + if( param2 == 0 ) { - for ( uint8_t i = 0; i < 255; i++ ) + for( uint8_t i = 0; i < 255; i++ ) targetActor->getAsPlayer()->learnSong( i, 0 ); - player.sendNotice( "All Songs for " + targetPlayer->getName() + - " were turned on." ); + player.sendNotice( "All Songs for " + targetPlayer->getName() + " were turned on." ); } else { targetActor->getAsPlayer()->learnSong( param2, 0 ); player.sendNotice( "Song " + std::to_string( param2 ) + " for " + targetPlayer->getName() + - " was turned on." ); + " was turned on." ); } } @@ -326,16 +319,15 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac { uint32_t gil = targetPlayer->getCurrency( 1 ); - if ( gil < param1 ) + if( gil < param1 ) { player.sendUrgent( "Player does not have enough Gil(" + std::to_string( gil ) + ")" ); } else { targetPlayer->removeCurrency( 1, param1 ); - player.sendNotice( "Removed " + std::to_string( param1 ) + - " Gil from " + targetPlayer->getName() + - "(" + std::to_string( gil ) + " before)" ); + player.sendNotice( "Removed " + std::to_string( param1 ) + " Gil from " + targetPlayer->getName() + "(" + + std::to_string( gil ) + " before)" ); } break; } @@ -367,35 +359,34 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac case GmCommand::GC: { targetPlayer->setGc( param1 ); - player.sendNotice( "GC for " + targetPlayer->getName() + - " was set to " + std::to_string( targetPlayer->getGc() ) ); + player.sendNotice( "GC for " + targetPlayer->getName() + " was set to " + + std::to_string( targetPlayer->getGc() ) ); break; } case GmCommand::GCRank: { targetPlayer->setGcRankAt( targetPlayer->getGc() - 1, param1 ); - player.sendNotice( "GC Rank for " + targetPlayer->getName() + - " for GC " + std::to_string( targetPlayer->getGc() ) + - " was set to " + std::to_string( targetPlayer->getGcRankArray()[targetPlayer->getGc() - 1] ) ); + player.sendNotice( "GC Rank for " + targetPlayer->getName() + " for GC " + + std::to_string( targetPlayer->getGc() ) + " was set to " + + std::to_string( targetPlayer->getGcRankArray()[targetPlayer->getGc() - 1] ) ); break; } case GmCommand::Aetheryte: { - if ( param1 == 0 ) + if( param1 == 0 ) { - if ( param2 == 0 ) + if( param2 == 0 ) { - for ( uint8_t i = 0; i < 255; i++ ) + for( uint8_t i = 0; i < 255; i++ ) targetActor->getAsPlayer()->registerAetheryte( i ); - player.sendNotice( "All Aetherytes for " + targetPlayer->getName() + - " were turned on." ); + player.sendNotice( "All Aetherytes for " + targetPlayer->getName() + " were turned on." ); } else { targetActor->getAsPlayer()->registerAetheryte( param2 ); player.sendNotice( "Aetheryte " + std::to_string( param2 ) + " for " + targetPlayer->getName() + - " was turned on." ); + " was turned on." ); } } @@ -404,7 +395,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac case GmCommand::Teri: { auto zoneInfo = g_zoneMgr.getZone( param1 ); - if ( !zoneInfo ) + if( !zoneInfo ) { player.sendUrgent( "Invalid zone " + std::to_string( param1 ) ); } @@ -412,16 +403,17 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac { targetPlayer->setPosition( targetPlayer->getPos() ); targetPlayer->performZoning( param1, targetPlayer->getPos(), 0 ); - player.sendNotice( targetPlayer->getName() + " was warped to zone " + std::to_string( param1 ) + " (" + zoneInfo->getName( ) + ")" ); + player.sendNotice( targetPlayer->getName() + " was warped to zone " + std::to_string( param1 ) + " (" + + zoneInfo->getName() + ")" ); } break; } case GmCommand::TeriInfo: { - player.sendNotice( "ZoneId: " + std::to_string( player.getZoneId() ) + "\nName: " + - player.getCurrentZone()->getName() + "\nInternalName: " + - player.getCurrentZone()->getInternalName() + "\nPopCount: " + - std::to_string( player.getCurrentZone()->getPopCount() ) + + player.sendNotice( "ZoneId: " + std::to_string( player.getZoneId() ) + + "\nName: " + player.getCurrentZone()->getName() + + "\nInternalName: " + player.getCurrentZone()->getInternalName() + + "\nPopCount: " + std::to_string( player.getCurrentZone()->getPopCount() ) + "\nCurrentWeather:" + std::to_string( player.getCurrentZone()->getCurrentWeather() ) + "\nNextWeather:" + std::to_string( player.getCurrentZone()->getNextWeather() ) ); break; @@ -438,12 +430,11 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac player.sendNotice( "Jumping to " + targetPlayer->getName() + " in range." ); break; } - + default: player.sendUrgent( "GM1 Command not implemented: " + std::to_string( commandId ) ); break; } - } void Core::Network::GameConnection::gm2Handler( const Packets::GamePacket& inPacket, Entity::Player& player ) @@ -490,8 +481,10 @@ void Core::Network::GameConnection::gm2Handler( const Packets::GamePacket& inPac targetPlayer->setStatus( Entity::Actor::ActorStatus::Idle ); targetPlayer->sendToInRangeSet( ActorControlPacket143( player.getId(), ZoneIn, 0x01, 0x01, 0, 113 ), true ); - targetPlayer->sendToInRangeSet( ActorControlPacket142( player.getId(), SetStatus, - static_cast< uint8_t >( Entity::Actor::ActorStatus::Idle ) ), true ); + targetPlayer->sendToInRangeSet( + ActorControlPacket142( player.getId(), SetStatus, + static_cast< uint8_t >( Entity::Actor::ActorStatus::Idle ) ), + true ); player.sendNotice( "Raised " + targetPlayer->getName() ); break; } @@ -502,7 +495,7 @@ void Core::Network::GameConnection::gm2Handler( const Packets::GamePacket& inPac player.setZone( targetPlayer->getZoneId() ); } player.changePosition( targetActor->getPos().x, targetActor->getPos().y, targetActor->getPos().z, - targetActor->getRotation() ); + targetActor->getRotation() ); player.sendNotice( "Jumping to " + targetPlayer->getName() ); break; } @@ -510,5 +503,4 @@ void Core::Network::GameConnection::gm2Handler( const Packets::GamePacket& inPac player.sendUrgent( "GM2 Command not implemented: " + std::to_string( commandId ) ); break; } - } diff --git a/src/servers/Server_Zone/Network/Handlers/InventoryHandler.cpp b/src/servers/Server_Zone/Network/Handlers/InventoryHandler.cpp index 52aaaad3..a68a6a28 100644 --- a/src/servers/Server_Zone/Network/Handlers/InventoryHandler.cpp +++ b/src/servers/Server_Zone/Network/Handlers/InventoryHandler.cpp @@ -1,29 +1,29 @@ #include +#include +#include #include #include -#include -#include #include #include #include "Network/GameConnection.h" +#include "ServerZone.h" #include "Session.h" #include "Zone/Zone.h" -#include "Zone/ZonePosition.h" -#include "ServerZone.h" #include "Zone/ZoneMgr.h" +#include "Zone/ZonePosition.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket144.h" +#include "Network/PacketWrappers/ServerNoticePacket.h" -#include "DebugCommand/DebugCommandHandler.h" #include "Actor/Player.h" -#include "Inventory/Inventory.h" +#include "DebugCommand/DebugCommandHandler.h" #include "Forwards.h" +#include "Inventory/Inventory.h" extern Core::Logger g_log; extern Core::ServerZone g_serverZone; @@ -35,7 +35,6 @@ using namespace Core::Common; using namespace Core::Network::Packets; using namespace Core::Network::Packets::Server; - void Core::Network::GameConnection::inventoryModifyHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { @@ -51,7 +50,6 @@ void Core::Network::GameConnection::inventoryModifyHandler( const Packets::GameP ackPacket.data().type = 7; player.queuePacket( ackPacket ); - g_log.debug( inPacket.toString() ); g_log.debug( "InventoryAction: " + std::to_string( action ) ); @@ -59,39 +57,35 @@ void Core::Network::GameConnection::inventoryModifyHandler( const Packets::GameP switch( action ) { - case 0x07: // discard item action - { - player.getInventory()->discardItem( fromContainer, fromSlot ); - } + case 0x07: // discard item action + { + player.getInventory()->discardItem( fromContainer, fromSlot ); + } + break; + + case 0x08: // move item action + { + player.getInventory()->moveItem( fromContainer, fromSlot, toContainer, toSlot ); + } + break; + + case 0x09: // swap item action + { + player.getInventory()->swapItem( fromContainer, fromSlot, toContainer, toSlot ); + } + break; + + case 0x0C: // merge stack action + { + } + break; + + case 0x0A: // split stack action + { + } + break; + + default: break; - - case 0x08: // move item action - { - player.getInventory()->moveItem( fromContainer, fromSlot, toContainer, toSlot ); - } - break; - - case 0x09: // swap item action - { - player.getInventory()->swapItem( fromContainer, fromSlot, toContainer, toSlot ); - } - break; - - case 0x0C: // merge stack action - { - - } - break; - - case 0x0A: // split stack action - { - - } - break; - - default: - break; - } } - diff --git a/src/servers/Server_Zone/Network/Handlers/PacketHandlers.cpp b/src/servers/Server_Zone/Network/Handlers/PacketHandlers.cpp index 0f397f2a..b9b0cf60 100644 --- a/src/servers/Server_Zone/Network/Handlers/PacketHandlers.cpp +++ b/src/servers/Server_Zone/Network/Handlers/PacketHandlers.cpp @@ -1,42 +1,41 @@ #include +#include +#include +#include #include #include -#include -#include #include #include -#include #include #include "Network/GameConnection.h" +#include "ServerZone.h" #include "Session.h" #include "Zone/Zone.h" -#include "Zone/ZonePosition.h" -#include "ServerZone.h" #include "Zone/ZoneMgr.h" +#include "Zone/ZonePosition.h" -#include "Network/PacketWrappers/InitUIPacket.h" -#include "Network/PacketWrappers/PingPacket.h" -#include "Network/PacketWrappers/MoveActorPacket.h" -#include "Network/PacketWrappers/ChatPacket.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket144.h" -#include "Network/PacketWrappers/EventStartPacket.h" +#include "Network/PacketWrappers/ChatPacket.h" #include "Network/PacketWrappers/EventFinishPacket.h" +#include "Network/PacketWrappers/EventStartPacket.h" +#include "Network/PacketWrappers/InitUIPacket.h" +#include "Network/PacketWrappers/MoveActorPacket.h" +#include "Network/PacketWrappers/PingPacket.h" #include "Network/PacketWrappers/PlayerStateFlagsPacket.h" +#include "Network/PacketWrappers/ServerNoticePacket.h" -#include "DebugCommand/DebugCommandHandler.h" -#include "Actor/Player.h" -#include "Inventory/Inventory.h" -#include "Forwards.h" -#include "Event/EventHelper.h" #include "Action/Action.h" #include "Action/ActionTeleport.h" - +#include "Actor/Player.h" +#include "DebugCommand/DebugCommandHandler.h" +#include "Event/EventHelper.h" +#include "Forwards.h" +#include "Inventory/Inventory.h" extern Core::Logger g_log; extern Core::ServerZone g_serverZone; @@ -48,16 +47,14 @@ using namespace Core::Common; using namespace Core::Network::Packets; using namespace Core::Network::Packets::Server; -void Core::Network::GameConnection::fcInfoReqHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::fcInfoReqHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { GamePacketPtr pPe( new GamePacket( 0xDD, 0x78, player.getId(), player.getId() ) ); pPe->setValAt< uint8_t >( 0x48, 0x01 ); queueOutPacket( pPe ); } -void Core::Network::GameConnection::setSearchInfoHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::setSearchInfoHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { uint32_t inval = inPacket.getValAt< uint32_t >( 0x20 ); uint32_t inval1 = inPacket.getValAt< uint32_t >( 0x24 ); @@ -86,12 +83,12 @@ void Core::Network::GameConnection::setSearchInfoHandler( const Packets::GamePac strcpy( searchInfoPacket.data().searchMessage, player.getSearchMessage() ); queueOutPacket( searchInfoPacket ); - player.sendToInRangeSet( ActorControlPacket142( player.getId(), SetStatusIcon, - static_cast< uint8_t >( player.getOnlineStatus() ) ), true ); + player.sendToInRangeSet( + ActorControlPacket142( player.getId(), SetStatusIcon, static_cast< uint8_t >( player.getOnlineStatus() ) ), + true ); } -void Core::Network::GameConnection::reqSearchInfoHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::reqSearchInfoHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { ZoneChannelPacket< FFXIVIpcInitSearchInfo > searchInfoPacket( player.getId() ); searchInfoPacket.data().onlineStatusFlags = player.getOnlineStatusMask(); @@ -100,15 +97,13 @@ void Core::Network::GameConnection::reqSearchInfoHandler( const Packets::GamePac queueOutPacket( searchInfoPacket ); } -void Core::Network::GameConnection::linkshellListHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::linkshellListHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { ZoneChannelPacket< FFXIVIpcLinkshellList > linkshellListPacket( player.getId() ); queueOutPacket( linkshellListPacket ); } -void Core::Network::GameConnection::updatePositionHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::updatePositionHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { // if the player is marked for zoning we no longer want to update his pos if( player.isMarkedForZoning() ) @@ -142,13 +137,13 @@ void Core::Network::GameConnection::updatePositionHandler( const Packets::GamePa uint16_t bit16 : 1; } IPC_OP_019AB; - uint16_t flags = inPacket.getValAt( 0x28 ); + uint16_t flags = inPacket.getValAt< uint16_t >( 0x28 ); memcpy( &IPC_OP_019AB, &flags, 2 ); - uint32_t flags1 = inPacket.getValAt( 0x24 ); + uint32_t flags1 = inPacket.getValAt< uint32_t >( 0x24 ); memcpy( &IPC_OP_019A, &flags1, 4 ); - //g_log.Log(LoggingSeverity::debug, "" + boost::lexical_cast((int)IPC_OP_019AB.bit1) + // g_log.Log(LoggingSeverity::debug, "" + boost::lexical_cast((int)IPC_OP_019AB.bit1) // + boost::lexical_cast((int)IPC_OP_019AB.bit2) // + boost::lexical_cast((int)IPC_OP_019AB.bit3) // + boost::lexical_cast((int)IPC_OP_019AB.bit4) @@ -166,26 +161,25 @@ void Core::Network::GameConnection::updatePositionHandler( const Packets::GamePa // + boost::lexical_cast((int)IPC_OP_019AB.bit16) // + " " + boost::lexical_cast((int)flags)); - //g_log.Log(LoggingSeverity::debug, "\n" + boost::lexical_cast((int)IPC_OP_019A.specialMovement) + "\n" + // g_log.Log(LoggingSeverity::debug, "\n" + boost::lexical_cast((int)IPC_OP_019A.specialMovement) + "\n" // + boost::lexical_cast((int)IPC_OP_019A.strafe) + "\n" // + boost::lexical_cast((int)IPC_OP_019A.moveBackward) + "\n" // + boost::lexical_cast((int)IPC_OP_019A.strafeRight)); - //g_log.Log(LoggingSeverity::debug, pInPacket->toString()); + // g_log.Log(LoggingSeverity::debug, pInPacket->toString()); - //pInPacket->debugPrint(); + // pInPacket->debugPrint(); bool bPosChanged = false; if( ( player.getPos().x != inPacket.getValAt< float >( 0x2c ) ) || ( player.getPos().y != inPacket.getValAt< float >( 0x30 ) ) || ( player.getPos().z != inPacket.getValAt< float >( 0x34 ) ) ) bPosChanged = true; - if( !bPosChanged && player.getRotation() == inPacket.getValAt< float >( 0x20 ) ) + if( !bPosChanged && player.getRotation() == inPacket.getValAt< float >( 0x20 ) ) return; player.setRotation( inPacket.getValAt< float >( 0x20 ) ); - player.setPosition( inPacket.getValAt< float >( 0x2c ), - inPacket.getValAt< float >( 0x30 ), + player.setPosition( inPacket.getValAt< float >( 0x2c ), inPacket.getValAt< float >( 0x30 ), inPacket.getValAt< float >( 0x34 ) ); if( ( player.getCurrentAction() != nullptr ) && bPosChanged ) @@ -278,18 +272,17 @@ void Core::Network::GameConnection::updatePositionHandler( const Packets::GamePa MoveActorPacket movePacket( player, unk1, unk2, unk3, unk4 ); player.sendToInRangeSet( movePacket ); - } void Core::Network::GameConnection::reqEquipDisplayFlagsHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { - g_log.info( "[" + std::to_string( player.getId() ) + "] Setting EquipDisplayFlags to " + std::to_string( inPacket.getValAt< uint8_t >( 0x20 ) ) ); + g_log.info( "[" + std::to_string( player.getId() ) + "] Setting EquipDisplayFlags to " + + std::to_string( inPacket.getValAt< uint8_t >( 0x20 ) ) ); player.setEquipDisplayFlags( inPacket.getValAt< uint8_t >( 0x20 ) ); } -void Core::Network::GameConnection::zoneLineHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::zoneLineHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { uint32_t zoneLineId = inPacket.getValAt< uint32_t >( 0x20 ); @@ -313,7 +306,7 @@ void Core::Network::GameConnection::zoneLineHandler( const Packets::GamePacket& ZoneChannelPacket< FFXIVIpcPrepareZoning > preparePacket( player.getId() ); preparePacket.data().targetZone = targetZone; - //ActorControlPacket143 controlPacket( pPlayer, ActorControlType::DespawnZoneScreenMsg, + // ActorControlPacket143 controlPacket( pPlayer, ActorControlType::DespawnZoneScreenMsg, // 0x03, player.getId(), 0x01, targetZone ); player.queuePacket( preparePacket ); } @@ -327,18 +320,17 @@ void Core::Network::GameConnection::zoneLineHandler( const Packets::GamePacket& targetZone = pZone->getId(); } - player.performZoning( targetZone, targetPos, rotation); + player.performZoning( targetZone, targetPos, rotation ); } - -void Core::Network::GameConnection::discoveryHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::discoveryHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { uint32_t ref_position_id = inPacket.getValAt< uint32_t >( 0x20 ); auto pQR = g_charaDb.query( "SELECT id, map_id, discover_id " "FROM discoveryinfo " - "WHERE id = " + std::to_string( ref_position_id ) + ";" ); + "WHERE id = " + + std::to_string( ref_position_id ) + ";" ); if( !pQR->next() ) { @@ -354,21 +346,16 @@ void Core::Network::GameConnection::discoveryHandler( const Packets::GamePacket& player.sendNotice( "Discovery ref pos ID: " + std::to_string( ref_position_id ) ); player.discover( pQR->getUInt16( 2 ), pQR->getUInt16( 3 ) ); - } - -void Core::Network::GameConnection::playTimeHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::playTimeHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { ZoneChannelPacket< FFXIVIpcPlayTime > playTimePacket( player.getId() ); playTimePacket.data().playTimeInMinutes = player.getPlayTime() / 60; player.queuePacket( playTimePacket ); } - -void Core::Network::GameConnection::initHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::initHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { // init handler means this is a login procedure player.setIsLogin( true ); @@ -376,24 +363,19 @@ void Core::Network::GameConnection::initHandler( const Packets::GamePacket& inPa player.setZone( player.getZoneId() ); } - -void Core::Network::GameConnection::blackListHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::blackListHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { uint8_t count = inPacket.getValAt< uint8_t >( 0x21 ); ZoneChannelPacket< FFXIVIpcBlackList > blackListPacket( player.getId() ); blackListPacket.data().sequence = count; // TODO: Fill with actual blacklist data - //blackListPacket.data().entry[0].contentId = 1; - //sprintf( blackListPacket.data().entry[0].name, "Test Test" ); + // blackListPacket.data().entry[0].contentId = 1; + // sprintf( blackListPacket.data().entry[0].name, "Test Test" ); queueOutPacket( blackListPacket ); - } - -void Core::Network::GameConnection::pingHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::pingHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { int32_t inVal = inPacket.getValAt< int32_t >( 0x20 ); PingPacket pingPacket( player, inVal ); @@ -402,9 +384,7 @@ void Core::Network::GameConnection::pingHandler( const Packets::GamePacket& inPa player.setLastPing( static_cast< uint32_t >( time( nullptr ) ) ); } - -void Core::Network::GameConnection::finishLoadingHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::finishLoadingHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { // player is done zoning player.setLoadingComplete( true ); @@ -424,8 +404,7 @@ void Core::Network::GameConnection::finishLoadingHandler( const Packets::GamePac player.getCurrentZone()->changeActorPosition( player.getAsPlayer() ); } -void Core::Network::GameConnection::socialListHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::socialListHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { uint8_t type = inPacket.getValAt< uint8_t >( 0x2A ); @@ -453,18 +432,17 @@ void Core::Network::GameConnection::socialListHandler( const Packets::GamePacket listPacket.data().entries[0].zoneId = player.getCurrentZone()->getId(); listPacket.data().entries[0].zoneId1 = 0x0100; // TODO: no idea what this does - //listPacket.data().entries[0].one = 1; + // listPacket.data().entries[0].one = 1; memcpy( listPacket.data().entries[0].name, player.getName().c_str(), strlen( player.getName().c_str() ) ); // TODO: actually store and read language from somewhere - listPacket.data().entries[0].bytes1[0] = 0x01;//flags (lang) - // TODO: these flags need to be figured out - //listPacket.data().entries[0].bytes1[1] = 0x00;//flags + listPacket.data().entries[0].bytes1[0] = 0x01; // flags (lang) + // TODO: these flags need to be figured out + // listPacket.data().entries[0].bytes1[1] = 0x00;//flags listPacket.data().entries[0].onlineStatusMask = player.getOnlineStatusMask(); queueOutPacket( listPacket ); - } else if( type == 0x0b ) { // friend list @@ -473,17 +451,14 @@ void Core::Network::GameConnection::socialListHandler( const Packets::GamePacket listPacket.data().type = 0x0B; listPacket.data().sequence = count; memset( listPacket.data().entries, 0, sizeof( listPacket.data().entries ) ); - } else if( type == 0x0e ) { // player search result // TODO: implement player search } - } -void Core::Network::GameConnection::chatHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::chatHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { std::string chatString( inPacket.getStringAt( 0x3a ) ); @@ -493,13 +468,13 @@ void Core::Network::GameConnection::chatHandler( const Packets::GamePacket& inPa if( chatString.at( 0 ) == '!' ) { // execute game console command - g_gameCommandMgr.execCommand( const_cast< char * >( chatString.c_str() ) + 1, player ); + g_gameCommandMgr.execCommand( const_cast< char* >( chatString.c_str() ) + 1, player ); return; } ChatType chatType = static_cast< ChatType >( inPacket.getValAt< uint8_t >( 0x38 ) ); - //ToDo, need to implement sending GM chat types. + // ToDo, need to implement sending GM chat types. ChatPacket chatPacket( player, chatType, chatString ); switch( chatType ) @@ -525,15 +500,13 @@ void Core::Network::GameConnection::chatHandler( const Packets::GamePacket& inPa break; } } - } // TODO: this handler needs to be improved for timed logout, also the session should be instantly removed // currently we wait for the session to just time out after logout, this can be a problem is the user tries to // log right back in. // Also the packet needs to be converted to an ipc structure -void Core::Network::GameConnection::logoutHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::logoutHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { ZoneChannelPacket< FFXIVIpcLogout > logoutPacket( player.getId() ); logoutPacket.data().flags1 = 0x02; @@ -543,9 +516,7 @@ void Core::Network::GameConnection::logoutHandler( const Packets::GamePacket& in player.setMarkedForRemoval(); } - -void Core::Network::GameConnection::tellHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::tellHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { std::string targetPcName = inPacket.getStringAt( 0x21 ); std::string msg = inPacket.getStringAt( 0x41 ); @@ -591,15 +562,13 @@ void Core::Network::GameConnection::tellHandler( const Packets::GamePacket& inPa strcpy( tellPacket.data().msg, msg.c_str() ); strcpy( tellPacket.data().receipientName, player.getName().c_str() ); // TODO: do these have a meaning? - //tellPacket.data().u1 = 0x92CD7337; - //tellPacket.data().u2a = 0x2E; - //tellPacket.data().u2b = 0x40; + // tellPacket.data().u1 = 0x92CD7337; + // tellPacket.data().u2a = 0x2E; + // tellPacket.data().u2b = 0x40; pTargetPlayer->queueChatPacket( tellPacket ); - } -void Core::Network::GameConnection::performNoteHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::performNoteHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { GamePacketNew< FFXIVIpcPerformNote, ServerZoneIpcType > performPacket( player.getId() ); diff --git a/src/servers/Server_Zone/Network/Handlers/SkillHandler.cpp b/src/servers/Server_Zone/Network/Handlers/SkillHandler.cpp index eaaa1d2b..804cf71c 100644 --- a/src/servers/Server_Zone/Network/Handlers/SkillHandler.cpp +++ b/src/servers/Server_Zone/Network/Handlers/SkillHandler.cpp @@ -1,9 +1,9 @@ #include -#include #include +#include +#include #include #include -#include #include @@ -11,11 +11,11 @@ #include "Session.h" -#include "Network/PacketWrappers/ServerNoticePacket.h" #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket144.h" #include "Network/PacketWrappers/MoveActorPacket.h" +#include "Network/PacketWrappers/ServerNoticePacket.h" #include "Network/PacketWrappers/PlayerStateFlagsPacket.h" @@ -30,7 +30,6 @@ #include "Action/ActionMount.h" #include "Script/ScriptManager.h" - extern Core::Scripting::ScriptManager g_scriptMgr; extern Core::Data::ExdData g_exdData; extern Core::Logger g_log; @@ -39,92 +38,86 @@ using namespace Core::Common; using namespace Core::Network::Packets; using namespace Core::Network::Packets::Server; -void Core::Network::GameConnection::skillHandler( const Packets::GamePacket& inPacket, - Entity::Player& player ) +void Core::Network::GameConnection::skillHandler( const Packets::GamePacket& inPacket, Entity::Player& player ) { - uint8_t type = inPacket.getValAt< uint32_t >( 0x21 ); + uint8_t type = inPacket.getValAt< uint32_t >( 0x21 ); - uint32_t action = inPacket.getValAt< uint32_t >( 0x24 ); - uint32_t useCount = inPacket.getValAt< uint32_t >( 0x28 ); + uint32_t action = inPacket.getValAt< uint32_t >( 0x24 ); + uint32_t useCount = inPacket.getValAt< uint32_t >( 0x28 ); - uint64_t targetId = inPacket.getValAt< uint64_t >( 0x30 ); + uint64_t targetId = inPacket.getValAt< uint64_t >( 0x30 ); - player.sendDebug( "Skill type:" + std::to_string( type ) ); + player.sendDebug( "Skill type:" + std::to_string( type ) ); - switch( type ) - { - case Common::SkillType::Normal: + switch( type ) + { + case Common::SkillType::Normal: - if( action < 1000000 ) // normal action - { - std::string actionIdStr = boost::str( boost::format( "%|04X|" ) % action ); - player.sendDebug( "---------------------------------------" ); - player.sendDebug( "ActionHandler ( " + actionIdStr + " | " + - g_exdData.getActionInfo( action )->name + - " | " + std::to_string( targetId ) + " )" ); + if( action < 1000000 ) // normal action + { + std::string actionIdStr = boost::str( boost::format( "%|04X|" ) % action ); + player.sendDebug( "---------------------------------------" ); + player.sendDebug( "ActionHandler ( " + actionIdStr + " | " + g_exdData.getActionInfo( action )->name + " | " + + std::to_string( targetId ) + " )" ); - player.queuePacket( ActorControlPacket142( player.getId(), ActorControlType::ActionStart, 0x01, action ) ); + player.queuePacket( ActorControlPacket142( player.getId(), ActorControlType::ActionStart, 0x01, action ) ); - if( action == 5 ) - { + if( action == 5 ) + { auto currentAction = player.getCurrentAction(); // we should always have an action here, if not there is a bug assert( currentAction ); currentAction->onStart(); - } - else - { + } + else + { Core::Entity::ActorPtr targetActor = player.getAsPlayer(); if( targetId != player.getId() ) { - targetActor = player.lookupTargetById( targetId ); + targetActor = player.lookupTargetById( targetId ); } if( !player.actionHasCastTime( action ) ) { - g_scriptMgr.onCastFinish( player, targetActor, action ); + g_scriptMgr.onCastFinish( player, targetActor, action ); } else { - Action::ActionCastPtr pActionCast( new Action::ActionCast( player.getAsPlayer(), targetActor, action ) ); - player.setCurrentAction( pActionCast ); - player.sendDebug( "setCurrentAction()" ); - player.getCurrentAction()->onStart(); + Action::ActionCastPtr pActionCast( new Action::ActionCast( player.getAsPlayer(), targetActor, action ) ); + player.setCurrentAction( pActionCast ); + player.sendDebug( "setCurrentAction()" ); + player.getCurrentAction()->onStart(); } - } - } - else if( action < 2000000 ) // craft action - { - - } - else if( action < 3000000 ) // item action - { - auto info = g_exdData.getEventItemInfo( action ); - if( info ) - { + } + } + else if( action < 2000000 ) // craft action + { + } + else if( action < 3000000 ) // item action + { + auto info = g_exdData.getEventItemInfo( action ); + if( info ) + { g_log.debug( info->name ); g_scriptMgr.onEventItem( player, action, info->eventId, info->castTime, targetId ); - } - } - else if( action > 3000000 ) // unknown - { + } + } + else if( action > 3000000 ) // unknown + { + } - } + break; - break; + case Common::SkillType::MountSkill: - case Common::SkillType::MountSkill: + player.sendDebug( "Request mount " + std::to_string( action ) ); - player.sendDebug( "Request mount " + std::to_string( action ) ); - - Action::ActionMountPtr pActionMount( new Action::ActionMount( player.getAsPlayer(), action ) ); - player.setCurrentAction( pActionMount ); - player.sendDebug( "setCurrentAction()" ); - player.getCurrentAction()->onStart(); - - break; - - } + Action::ActionMountPtr pActionMount( new Action::ActionMount( player.getAsPlayer(), action ) ); + player.setCurrentAction( pActionMount ); + player.sendDebug( "setCurrentAction()" ); + player.getCurrentAction()->onStart(); + break; + } } diff --git a/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket142.h b/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket142.h index 6a6ae79b..1abdbb96 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket142.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket142.h @@ -1,49 +1,43 @@ #ifndef _ACTORCONTROL142_H #define _ACTORCONTROL142_H +#include "Forwards.h" #include #include -#include "Forwards.h" namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The Ping response packet. -*/ -class ActorControlPacket142 : - public ZoneChannelPacket< FFXIVIpcActorControl142 > -{ -public: - ActorControlPacket142( uint32_t actorId, - uint16_t category, - uint32_t param1 = 0, - uint32_t param2 = 0, - uint32_t param3 = 0, - uint32_t param4 = 0, - uint32_t padding1 = 0 ) : - ZoneChannelPacket< FFXIVIpcActorControl142 >( actorId, actorId ) - { - initialize( category, param1, param2, param3, param4 ); - }; + /** + * @brief The Ping response packet. + */ + class ActorControlPacket142 : public ZoneChannelPacket< FFXIVIpcActorControl142 > + { + public: + ActorControlPacket142( uint32_t actorId, uint16_t category, uint32_t param1 = 0, uint32_t param2 = 0, + uint32_t param3 = 0, uint32_t param4 = 0, uint32_t padding1 = 0 ) : + ZoneChannelPacket< FFXIVIpcActorControl142 >( actorId, actorId ) + { + initialize( category, param1, param2, param3, param4 ); + }; -private: - void initialize( uint16_t category, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t param4 ) - { - m_data.padding = 0; - m_data.category = category; - m_data.param1 = param1; - m_data.param2 = param2; - m_data.param3 = param3; - m_data.param4 = param4; - }; -}; + private: + void initialize( uint16_t category, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t param4 ) + { + m_data.padding = 0; + m_data.category = category; + m_data.param1 = param1; + m_data.param2 = param2; + m_data.param3 = param3; + m_data.param4 = param4; + }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_ACTORCONTROL142_H*/ \ No newline at end of file diff --git a/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket143.h b/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket143.h index 09dafb08..64f389b3 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket143.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket143.h @@ -1,52 +1,46 @@ #ifndef _ACTORCONTROL143_H #define _ACTORCONTROL143_H +#include "Forwards.h" #include #include -#include "Forwards.h" - namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The Ping response packet. -*/ -class ActorControlPacket143 : - public ZoneChannelPacket< FFXIVIpcActorControl143 > -{ -public: - ActorControlPacket143( uint32_t actorId, - uint16_t category, - uint32_t param1 = 0, - uint32_t param2 = 0, - uint32_t param3 = 0, - uint32_t param4 = 0, - uint32_t param5 = 0, - uint32_t padding1 = 0 ) : - ZoneChannelPacket< FFXIVIpcActorControl143 >( actorId, actorId ) - { - initialize( category, param1, param2, param3, param4, param5 ); - }; + /** + * @brief The Ping response packet. + */ + class ActorControlPacket143 : public ZoneChannelPacket< FFXIVIpcActorControl143 > + { + public: + ActorControlPacket143( uint32_t actorId, uint16_t category, uint32_t param1 = 0, uint32_t param2 = 0, + uint32_t param3 = 0, uint32_t param4 = 0, uint32_t param5 = 0, + uint32_t padding1 = 0 ) : + ZoneChannelPacket< FFXIVIpcActorControl143 >( actorId, actorId ) + { + initialize( category, param1, param2, param3, param4, param5 ); + }; -private: - void initialize( uint16_t category, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t param4, uint32_t param5 ) - { - m_data.padding = 0; - m_data.category = category; - m_data.param1 = param1; - m_data.param2 = param2; - m_data.param3 = param3; - m_data.param4 = param4; - m_data.param5 = param5; - }; -}; + private: + void initialize( uint16_t category, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t param4, + uint32_t param5 ) + { + m_data.padding = 0; + m_data.category = category; + m_data.param1 = param1; + m_data.param2 = param2; + m_data.param3 = param3; + m_data.param4 = param4; + m_data.param5 = param5; + }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_ACTORCONTROL143_H*/ \ No newline at end of file diff --git a/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket144.h b/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket144.h index ab5d3dad..e08b1b60 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket144.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/ActorControlPacket144.h @@ -6,45 +6,40 @@ namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The Ping response packet. -*/ -class ActorControlPacket144 : - public ZoneChannelPacket< FFXIVIpcActorControl144 > -{ -public: - ActorControlPacket144( uint32_t actorId, - uint16_t category, - uint32_t param1 = 0, - uint32_t param2 = 0, - uint32_t param3 = 0, - uint32_t param4 = 0, - uint64_t targetId = 0, - uint32_t padding1 = 0 ) : - ZoneChannelPacket< FFXIVIpcActorControl144 >( actorId, actorId ) - { - initialize( category, param1, param2, param3, param4, targetId ); - }; + /** + * @brief The Ping response packet. + */ + class ActorControlPacket144 : public ZoneChannelPacket< FFXIVIpcActorControl144 > + { + public: + ActorControlPacket144( uint32_t actorId, uint16_t category, uint32_t param1 = 0, uint32_t param2 = 0, + uint32_t param3 = 0, uint32_t param4 = 0, uint64_t targetId = 0, + uint32_t padding1 = 0 ) : + ZoneChannelPacket< FFXIVIpcActorControl144 >( actorId, actorId ) + { + initialize( category, param1, param2, param3, param4, targetId ); + }; -private: - void initialize( uint16_t category, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t param4, uint64_t targetId ) - { - m_data.padding = 0; - m_data.category = category; - m_data.param1 = param1; - m_data.param2 = param2; - m_data.param3 = param3; - m_data.param4 = param4; - m_data.targetId = targetId; - }; -}; + private: + void initialize( uint16_t category, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t param4, + uint64_t targetId ) + { + m_data.padding = 0; + m_data.category = category; + m_data.param1 = param1; + m_data.param2 = param2; + m_data.param3 = param3; + m_data.param4 = param4; + m_data.targetId = targetId; + }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_ACTORCONTROL144_H*/ \ No newline at end of file diff --git a/src/servers/Server_Zone/Network/PacketWrappers/ActorSpawnPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/ActorSpawnPacket.h index bc52678e..262f886d 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/ActorSpawnPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/ActorSpawnPacket.h @@ -1,91 +1,88 @@ #ifndef _ACTORSPAWN_H #define _ACTORSPAWN_H -#include -#include #include "Actor/Player.h" #include "Forwards.h" +#include +#include namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The packet sent to spawn an actor. -*/ -class ActorSpawnPacket : - public GamePacketNew< FFXIVIpcActorSpawn, ServerZoneIpcType > -{ -public: - ActorSpawnPacket( Entity::PlayerPtr pPlayer, Entity::PlayerPtr pTarget ) : - GamePacketNew< FFXIVIpcActorSpawn, ServerZoneIpcType >( pPlayer->getId(), pTarget->getId() ) - { - initialize( pPlayer, pTarget ); - }; + /** + * @brief The packet sent to spawn an actor. + */ + class ActorSpawnPacket : public GamePacketNew< FFXIVIpcActorSpawn, ServerZoneIpcType > + { + public: + ActorSpawnPacket( Entity::PlayerPtr pPlayer, Entity::PlayerPtr pTarget ) : + GamePacketNew< FFXIVIpcActorSpawn, ServerZoneIpcType >( pPlayer->getId(), pTarget->getId() ) + { + initialize( pPlayer, pTarget ); + }; -private: - void initialize( Entity::PlayerPtr pPlayer, Entity::PlayerPtr pTarget ) - { - // TODO: temporary gm rank - m_data.gmRank = 0xff; - m_data.classJob = static_cast< uint8_t >( pPlayer->getClass() ); - m_data.status = static_cast< uint8_t >( pPlayer->getStatus() ); - m_data.hPCurr = pPlayer->getHp(); - m_data.mPCurr = pPlayer->getMp(); - m_data.tPCurr = pPlayer->getTp(); - m_data.hPMax = pPlayer->getMaxHp(); - m_data.mPMax = pPlayer->getMaxMp(); - m_data.tPMax = 3000; - m_data.level = pPlayer->getLevel(); - memcpy( m_data.look, pPlayer->getLookArray(), 26 ); - m_data.mainWeaponModel = pPlayer->getModelMainWeapon(); - m_data.secWeaponModel = pPlayer->getModelSubWeapon(); - m_data.models[0] = pPlayer->getModelForSlot( Inventory::EquipSlot::Head ); - m_data.models[1] = pPlayer->getModelForSlot( Inventory::EquipSlot::Body ); - m_data.models[2] = pPlayer->getModelForSlot( Inventory::EquipSlot::Hands ); - m_data.models[3] = pPlayer->getModelForSlot( Inventory::EquipSlot::Legs ); - m_data.models[4] = pPlayer->getModelForSlot( Inventory::EquipSlot::Feet ); - strcpy( m_data.name, pPlayer->getName().c_str() ); - m_data.pos.x = pPlayer->getPos().x; - m_data.pos.y = pPlayer->getPos().y; - m_data.pos.z = pPlayer->getPos().z; - m_data.voice = pPlayer->getVoiceId(); - - m_data.rotation = Math::Util::floatToUInt16Rot( pPlayer->getRotation() ); + private: + void initialize( Entity::PlayerPtr pPlayer, Entity::PlayerPtr pTarget ) + { + // TODO: temporary gm rank + m_data.gmRank = 0xff; + m_data.classJob = static_cast< uint8_t >( pPlayer->getClass() ); + m_data.status = static_cast< uint8_t >( pPlayer->getStatus() ); + m_data.hPCurr = pPlayer->getHp(); + m_data.mPCurr = pPlayer->getMp(); + m_data.tPCurr = pPlayer->getTp(); + m_data.hPMax = pPlayer->getMaxHp(); + m_data.mPMax = pPlayer->getMaxMp(); + m_data.tPMax = 3000; + m_data.level = pPlayer->getLevel(); + memcpy( m_data.look, pPlayer->getLookArray(), 26 ); + m_data.mainWeaponModel = pPlayer->getModelMainWeapon(); + m_data.secWeaponModel = pPlayer->getModelSubWeapon(); + m_data.models[0] = pPlayer->getModelForSlot( Inventory::EquipSlot::Head ); + m_data.models[1] = pPlayer->getModelForSlot( Inventory::EquipSlot::Body ); + m_data.models[2] = pPlayer->getModelForSlot( Inventory::EquipSlot::Hands ); + m_data.models[3] = pPlayer->getModelForSlot( Inventory::EquipSlot::Legs ); + m_data.models[4] = pPlayer->getModelForSlot( Inventory::EquipSlot::Feet ); + strcpy( m_data.name, pPlayer->getName().c_str() ); + m_data.pos.x = pPlayer->getPos().x; + m_data.pos.y = pPlayer->getPos().y; + m_data.pos.z = pPlayer->getPos().z; + m_data.voice = pPlayer->getVoiceId(); - m_data.statusIcon = pPlayer->getOnlineStatus(); + m_data.rotation = Math::Util::floatToUInt16Rot( pPlayer->getRotation() ); - if( pTarget == pPlayer ) - { - m_data.spawnIndex = 0x00; - } - else - { - m_data.spawnIndex = pTarget->getSpawnIdForActorId( pPlayer->getId() ); - } - // 0x20 == spawn hidden to be displayed by the spawneffect control - m_data.displayFlags = pPlayer->getStance(); + m_data.statusIcon = pPlayer->getOnlineStatus(); - if( pPlayer->getZoningType() != Common::ZoneingType::None ) - { - m_data.displayFlags |= 0x20; - } + if( pTarget == pPlayer ) + { + m_data.spawnIndex = 0x00; + } + else + { + m_data.spawnIndex = pTarget->getSpawnIdForActorId( pPlayer->getId() ); + } + // 0x20 == spawn hidden to be displayed by the spawneffect control + m_data.displayFlags = pPlayer->getStance(); - m_data.targetId = pPlayer->getTargetId(); - m_data.type = 1; - m_data.unknown_33 = 4; - //m_data.unknown_38 = 0x70; - //m_data.unknown_60 = 3; - //m_data.unknown_61 = 7; + if( pPlayer->getZoningType() != Common::ZoneingType::None ) + { + m_data.displayFlags |= 0x20; + } + m_data.targetId = pPlayer->getTargetId(); + m_data.type = 1; + m_data.unknown_33 = 4; + // m_data.unknown_38 = 0x70; + // m_data.unknown_60 = 3; + // m_data.unknown_61 = 7; + }; + }; - }; -}; - -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_ACTORSPAWN_H*/ \ No newline at end of file diff --git a/src/servers/Server_Zone/Network/PacketWrappers/ChatPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/ChatPacket.h index 1a99ed71..be67507c 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/ChatPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/ChatPacket.h @@ -1,41 +1,39 @@ #ifndef _CHATPACKET_H #define _CHATPACKET_H +#include "Forwards.h" #include #include -#include "Forwards.h" - namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The Chat packet. -*/ -class ChatPacket : - public ZoneChannelPacket< FFXIVIpcChat > -{ -public: - ChatPacket( Entity::Player& player, Common::ChatType chatType, const std::string& msg ) : - ZoneChannelPacket< FFXIVIpcChat >( player.getId(), player.getId() ) - { - initialize( player, chatType, msg ); - }; + /** + * @brief The Chat packet. + */ + class ChatPacket : public ZoneChannelPacket< FFXIVIpcChat > + { + public: + ChatPacket( Entity::Player& player, Common::ChatType chatType, const std::string& msg ) : + ZoneChannelPacket< FFXIVIpcChat >( player.getId(), player.getId() ) + { + initialize( player, chatType, msg ); + }; -private: - void initialize( Entity::Player& player, Common::ChatType chatType, const std::string& msg ) - { - m_data.chatType = chatType; - strcpy( m_data.name, player.getName().c_str() ); - strcpy( m_data.msg, msg.c_str() ); - }; -}; + private: + void initialize( Entity::Player& player, Common::ChatType chatType, const std::string& msg ) + { + m_data.chatType = chatType; + strcpy( m_data.name, player.getName().c_str() ); + strcpy( m_data.msg, msg.c_str() ); + }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_CHATPACKET_H*/ diff --git a/src/servers/Server_Zone/Network/PacketWrappers/EventFinishPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/EventFinishPacket.h index 6e55dc76..e8d72728 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/EventFinishPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/EventFinishPacket.h @@ -5,40 +5,34 @@ namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The packet sent to finish an event. -*/ -class EventFinishPacket : public ZoneChannelPacket< FFXIVIpcEventFinish > -{ -public: - EventFinishPacket( uint32_t playerId, - uint32_t eventId, - uint8_t param1, - uint32_t param3 ) : - ZoneChannelPacket< FFXIVIpcEventFinish >( playerId, playerId ) - { - initialize( eventId, param1, param3 ); - }; + /** + * @brief The packet sent to finish an event. + */ + class EventFinishPacket : public ZoneChannelPacket< FFXIVIpcEventFinish > + { + public: + EventFinishPacket( uint32_t playerId, uint32_t eventId, uint8_t param1, uint32_t param3 ) : + ZoneChannelPacket< FFXIVIpcEventFinish >( playerId, playerId ) + { + initialize( eventId, param1, param3 ); + }; -private: - void initialize( uint32_t eventId, - uint8_t param1, - uint32_t param3 ) - { - m_data.eventId = eventId; - m_data.param1 = param1; - m_data.param2 = 1; - m_data.param3 = param3; + private: + void initialize( uint32_t eventId, uint8_t param1, uint32_t param3 ) + { + m_data.eventId = eventId; + m_data.param1 = param1; + m_data.param2 = 1; + m_data.param3 = param3; + }; + }; - }; -}; - -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_EVENTFINISH_H*/ \ No newline at end of file diff --git a/src/servers/Server_Zone/Network/PacketWrappers/EventPlayPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/EventPlayPacket.h index a3505fa2..27f9b182 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/EventPlayPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/EventPlayPacket.h @@ -1,55 +1,44 @@ #ifndef _EVENTPLAY_H #define _EVENTPLAY_H -#include #include "Forwards.h" +#include namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The packet sent to play an event. -*/ -class EventPlayPacket : public ZoneChannelPacket< FFXIVIpcEventPlay > -{ -public: - EventPlayPacket( uint32_t playerId, - uint64_t actorId, - uint32_t eventId, - uint16_t scene, - uint32_t flags, - uint8_t param3, - uint32_t param4 = 0, - uint32_t param5 = 0 ) : - ZoneChannelPacket< FFXIVIpcEventPlay >( playerId, playerId ) - { - initialize( actorId, eventId, scene, flags, param3, param4, param5 ); - }; + /** + * @brief The packet sent to play an event. + */ + class EventPlayPacket : public ZoneChannelPacket< FFXIVIpcEventPlay > + { + public: + EventPlayPacket( uint32_t playerId, uint64_t actorId, uint32_t eventId, uint16_t scene, uint32_t flags, + uint8_t param3, uint32_t param4 = 0, uint32_t param5 = 0 ) : + ZoneChannelPacket< FFXIVIpcEventPlay >( playerId, playerId ) + { + initialize( actorId, eventId, scene, flags, param3, param4, param5 ); + }; -private: - void initialize( uint64_t actorId, - uint32_t eventId, - uint16_t scene, - uint32_t flags, - uint8_t param3, - uint32_t param4, - uint32_t param5 ) - { - m_data.actorId = actorId; - m_data.eventId = eventId; - m_data.scene = scene; - m_data.flags = flags; - m_data.param3 = param3; - m_data.param4 = param4; - m_data.param5 = param5; - }; -}; + private: + void initialize( uint64_t actorId, uint32_t eventId, uint16_t scene, uint32_t flags, uint8_t param3, + uint32_t param4, uint32_t param5 ) + { + m_data.actorId = actorId; + m_data.eventId = eventId; + m_data.scene = scene; + m_data.flags = flags; + m_data.param3 = param3; + m_data.param4 = param4; + m_data.param5 = param5; + }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_EVENTPLAY_H*/ \ No newline at end of file diff --git a/src/servers/Server_Zone/Network/PacketWrappers/EventStartPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/EventStartPacket.h index 6872fa7d..87501f99 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/EventStartPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/EventStartPacket.h @@ -1,50 +1,41 @@ #ifndef _EVENTSTART_H #define _EVENTSTART_H -#include #include "Forwards.h" +#include namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The packet sent to start an event. -*/ -class EventStartPacket : public ZoneChannelPacket< FFXIVIpcEventStart > -{ -public: - EventStartPacket( uint32_t playerId, - uint64_t actorId, - uint32_t eventId, - uint8_t param1 = 0, - uint8_t param2 = 0, - uint32_t param3 = 0 ) : - ZoneChannelPacket< FFXIVIpcEventStart >( playerId, playerId ) - { - initialize( actorId, eventId, param1, param2, param3 ); - }; + /** + * @brief The packet sent to start an event. + */ + class EventStartPacket : public ZoneChannelPacket< FFXIVIpcEventStart > + { + public: + EventStartPacket( uint32_t playerId, uint64_t actorId, uint32_t eventId, uint8_t param1 = 0, + uint8_t param2 = 0, uint32_t param3 = 0 ) : + ZoneChannelPacket< FFXIVIpcEventStart >( playerId, playerId ) + { + initialize( actorId, eventId, param1, param2, param3 ); + }; -private: - void initialize( uint64_t actorId, - uint32_t eventId, - uint8_t param1, - uint8_t param2, - uint32_t param3 ) - { - m_data.actorId = actorId; - m_data.eventId = eventId; - m_data.param1 = param1; - m_data.param2 = param2; - m_data.param3 = param3; + private: + void initialize( uint64_t actorId, uint32_t eventId, uint8_t param1, uint8_t param2, uint32_t param3 ) + { + m_data.actorId = actorId; + m_data.eventId = eventId; + m_data.param1 = param1; + m_data.param2 = param2; + m_data.param3 = param3; + }; + }; - }; -}; - -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_EVENTSTART_H*/ \ No newline at end of file diff --git a/src/servers/Server_Zone/Network/PacketWrappers/InitUIPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/InitUIPacket.h index 37244eb2..15d2373e 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/InitUIPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/InitUIPacket.h @@ -1,93 +1,92 @@ #ifndef _CORE_NETWORK_PACKETS_INITUIPACKET_H #define _CORE_NETWORK_PACKETS_INITUIPACKET_H -#include -#include #include "Actor/Player.h" #include "Forwards.h" +#include +#include namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The Client UI Initialization packet. This must be sent to the client -* once upon connection to configure the UI. -*/ -class InitUIPacket : public ZoneChannelPacket< FFXIVIpcInitUI > -{ -public: - InitUIPacket( Entity::Player& player ) : - ZoneChannelPacket< FFXIVIpcInitUI >( player.getId(), player.getId() ) - { - initialize( player ); - }; + /** + * @brief The Client UI Initialization packet. This must be sent to the client + * once upon connection to configure the UI. + */ + class InitUIPacket : public ZoneChannelPacket< FFXIVIpcInitUI > + { + public: + InitUIPacket( Entity::Player& player ) : + ZoneChannelPacket< FFXIVIpcInitUI >( player.getId(), player.getId() ) + { + initialize( player ); + }; -private: - void initialize( Entity::Player& player ) - { - m_data.contentId = player.getContentId(); + private: + void initialize( Entity::Player& player ) + { + m_data.contentId = player.getContentId(); - // TODO: Support rested experience. - m_data.restedExp = 0; - //m_data.padding = 0x100; - m_data.charId = player.getId(); - m_data.race = player.getLookAt( Common::CharaLook::Race ); - m_data.tribe = player.getLookAt( Common::CharaLook::Tribe ); - m_data.gender = player.getLookAt( Common::CharaLook::Gender ); - m_data.currentClass = static_cast< uint8_t >( player.getClass() ); - m_data.currentJob = static_cast< uint8_t >( player.getClass() ); - m_data.deity = static_cast< uint8_t >( player.getGuardianDeity() ); - m_data.namedayMonth = player.getBirthMonth(); - m_data.namedayDay = player.getBirthDay(); - // TODO: Support grand company status. - m_data.grandCompany = static_cast< Common::GrandCompany >( player.getGc() ); - //m_data.gcRank = GCRank::None; + // TODO: Support rested experience. + m_data.restedExp = 0; + // m_data.padding = 0x100; + m_data.charId = player.getId(); + m_data.race = player.getLookAt( Common::CharaLook::Race ); + m_data.tribe = player.getLookAt( Common::CharaLook::Tribe ); + m_data.gender = player.getLookAt( Common::CharaLook::Gender ); + m_data.currentClass = static_cast< uint8_t >( player.getClass() ); + m_data.currentJob = static_cast< uint8_t >( player.getClass() ); + m_data.deity = static_cast< uint8_t >( player.getGuardianDeity() ); + m_data.namedayMonth = player.getBirthMonth(); + m_data.namedayDay = player.getBirthDay(); + // TODO: Support grand company status. + m_data.grandCompany = static_cast< Common::GrandCompany >( player.getGc() ); + // m_data.gcRank = GCRank::None; - // TODO: Support starting city. - //m_data.startCity = Town::Gridania; - m_data.homepoint = player.getHomepoint(); + // TODO: Support starting city. + // m_data.startCity = Town::Gridania; + m_data.homepoint = player.getHomepoint(); - memset( &m_data.name[0], 0, sizeof( m_data.name ) ); + memset( &m_data.name[0], 0, sizeof( m_data.name ) ); - strcpy( &m_data.name[0], player.getName().c_str() ); + strcpy( &m_data.name[0], player.getName().c_str() ); - memcpy( m_data.aetheryte, player.getAetheryteArray(), sizeof ( m_data.aetheryte ) ); + memcpy( m_data.aetheryte, player.getAetheryteArray(), sizeof( m_data.aetheryte ) ); - // Set the class levels and exp. - for( uint8_t i = 0; i < 25; i++ ) - { - m_data.levels[i] = player.getClassArray()[i]; - m_data.exp[i] = player.getExpArray()[i]; - } + // Set the class levels and exp. + for( uint8_t i = 0; i < 25; i++ ) + { + m_data.levels[i] = player.getClassArray()[i]; + m_data.exp[i] = player.getExpArray()[i]; + } - memcpy( m_data.orchestrionMask, player.getOrchestrionBitmask(), sizeof( m_data.orchestrionMask ) ); + memcpy( m_data.orchestrionMask, player.getOrchestrionBitmask(), sizeof( m_data.orchestrionMask ) ); - memcpy( m_data.mountGuideMask, player.getMountGuideBitmask(), sizeof( m_data.mountGuideMask) ); + memcpy( m_data.mountGuideMask, player.getMountGuideBitmask(), sizeof( m_data.mountGuideMask ) ); - memcpy( m_data.unlockBitmask, player.getUnlockBitmask(), sizeof( m_data.unlockBitmask ) ); + memcpy( m_data.unlockBitmask, player.getUnlockBitmask(), sizeof( m_data.unlockBitmask ) ); - memcpy( m_data.discovery, player.getDiscoveryBitmask(), sizeof( m_data.discovery ) ); + memcpy( m_data.discovery, player.getDiscoveryBitmask(), sizeof( m_data.discovery ) ); - memcpy( m_data.howto, player.getHowToArray(), sizeof( m_data.howto ) ); + memcpy( m_data.howto, player.getHowToArray(), sizeof( m_data.howto ) ); - m_data.unknown_13 = 0x46; - m_data.expansion = 2; + m_data.unknown_13 = 0x46; + m_data.expansion = 2; - //memset( m_data.unlockBitmask, 0xFF, sizeof( m_data.unlockBitmask ) ); - //memset( m_data.unknown_0344, 0xFF, sizeof( m_data.unknown_0344 ) ); - //memset( m_data.unknown_F4, 0xFF, sizeof( m_data.unknown_F4 ) ); - //m_data.pos.x = player->getPos().getX(); - //m_data.pos.y = player->getPos().getY(); - //m_data.pos.z = player->getPos().getZ(); + // memset( m_data.unlockBitmask, 0xFF, sizeof( m_data.unlockBitmask ) ); + // memset( m_data.unknown_0344, 0xFF, sizeof( m_data.unknown_0344 ) ); + // memset( m_data.unknown_F4, 0xFF, sizeof( m_data.unknown_F4 ) ); + // m_data.pos.x = player->getPos().getX(); + // m_data.pos.y = player->getPos().getY(); + // m_data.pos.z = player->getPos().getZ(); + }; + }; - }; -}; - -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_CORE_NETWORK_PACKETS_CINITUIPACKET_H*/ diff --git a/src/servers/Server_Zone/Network/PacketWrappers/ModelEquipPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/ModelEquipPacket.h index 88536c0d..b4996953 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/ModelEquipPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/ModelEquipPacket.h @@ -1,44 +1,43 @@ #ifndef _MODELEQUIPPACKET_H #define _MODELEQUIPPACKET_H -#include #include "Actor/Player.h" #include "Forwards.h" +#include namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The update model packet. -*/ -class ModelEquipPacket : - public ZoneChannelPacket< FFXIVIpcModelEquip > -{ -public: - ModelEquipPacket( Entity::Player& player ) : - ZoneChannelPacket< FFXIVIpcModelEquip >( player.getId(), player.getId() ) - { - initialize( player ); - }; + /** + * @brief The update model packet. + */ + class ModelEquipPacket : public ZoneChannelPacket< FFXIVIpcModelEquip > + { + public: + ModelEquipPacket( Entity::Player& player ) : + ZoneChannelPacket< FFXIVIpcModelEquip >( player.getId(), player.getId() ) + { + initialize( player ); + }; -private: - void initialize( Entity::Player& player ) - { - m_data.mainWeapon = player.getModelMainWeapon(); - m_data.offWeapon = player.getModelSubWeapon(); - m_data.models[0] = player.getModelForSlot( Inventory::EquipSlot::Head ); - m_data.models[1] = player.getModelForSlot( Inventory::EquipSlot::Body ); - m_data.models[2] = player.getModelForSlot( Inventory::EquipSlot::Hands ); - m_data.models[3] = player.getModelForSlot( Inventory::EquipSlot::Legs ); - m_data.models[4] = player.getModelForSlot( Inventory::EquipSlot::Feet ); - }; -}; + private: + void initialize( Entity::Player& player ) + { + m_data.mainWeapon = player.getModelMainWeapon(); + m_data.offWeapon = player.getModelSubWeapon(); + m_data.models[0] = player.getModelForSlot( Inventory::EquipSlot::Head ); + m_data.models[1] = player.getModelForSlot( Inventory::EquipSlot::Body ); + m_data.models[2] = player.getModelForSlot( Inventory::EquipSlot::Hands ); + m_data.models[3] = player.getModelForSlot( Inventory::EquipSlot::Legs ); + m_data.models[4] = player.getModelForSlot( Inventory::EquipSlot::Feet ); + }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_MODELEQUIPPACKET_H*/ diff --git a/src/servers/Server_Zone/Network/PacketWrappers/MoveActorPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/MoveActorPacket.h index abc7f9d6..9ad026a4 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/MoveActorPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/MoveActorPacket.h @@ -1,51 +1,48 @@ #ifndef _MOVEACTORPACKET_H #define _MOVEACTORPACKET_H +#include "Actor/Player.h" +#include "Forwards.h" #include #include #include -#include "Actor/Player.h" -#include "Forwards.h" - namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The Client UI Initialization packet. This must be sent to the client -* once upon connection to configure the UI. -*/ -class MoveActorPacket : - public ZoneChannelPacket< FFXIVIpcActorMove > -{ -public: - MoveActorPacket( Entity::Actor& actor, uint8_t unk1, uint8_t unk2, uint8_t unk3, uint16_t unk4 ) : - ZoneChannelPacket< FFXIVIpcActorMove >( actor.getId(), actor.getId() ) - { - initialize( actor, unk1, unk2, unk3, unk4 ); - }; + /** + * @brief The Client UI Initialization packet. This must be sent to the client + * once upon connection to configure the UI. + */ + class MoveActorPacket : public ZoneChannelPacket< FFXIVIpcActorMove > + { + public: + MoveActorPacket( Entity::Actor& actor, uint8_t unk1, uint8_t unk2, uint8_t unk3, uint16_t unk4 ) : + ZoneChannelPacket< FFXIVIpcActorMove >( actor.getId(), actor.getId() ) + { + initialize( actor, unk1, unk2, unk3, unk4 ); + }; -private: - void initialize( Entity::Actor& actor, uint8_t unk1, uint8_t unk2, uint8_t unk3, uint16_t unk4 ) - { - - m_data.rotation = Math::Util::floatToUInt8Rot( actor.getRotation() ); - m_data.unknown_1 = unk1; - m_data.unknown_2 = unk2; - m_data.unknown_3 = unk3; - m_data.unknown_4 = unk4; - m_data.posX = Math::Util::floatToUInt16( actor.getPos().x ); - m_data.posY = Math::Util::floatToUInt16( actor.getPos().y ); - m_data.posZ = Math::Util::floatToUInt16( actor.getPos().z ); + private: + void initialize( Entity::Actor& actor, uint8_t unk1, uint8_t unk2, uint8_t unk3, uint16_t unk4 ) + { - }; -}; + m_data.rotation = Math::Util::floatToUInt8Rot( actor.getRotation() ); + m_data.unknown_1 = unk1; + m_data.unknown_2 = unk2; + m_data.unknown_3 = unk3; + m_data.unknown_4 = unk4; + m_data.posX = Math::Util::floatToUInt16( actor.getPos().x ); + m_data.posY = Math::Util::floatToUInt16( actor.getPos().y ); + m_data.posZ = Math::Util::floatToUInt16( actor.getPos().z ); + }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_MOVEACTORPACKET_H*/ diff --git a/src/servers/Server_Zone/Network/PacketWrappers/PingPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/PingPacket.h index 8a3e1836..a9a85610 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/PingPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/PingPacket.h @@ -7,32 +7,31 @@ namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The Ping response packet. -*/ -class PingPacket : - public ZoneChannelPacket< FFXIVIpcPing > -{ -public: - PingPacket( Entity::Player& player, int32_t inVal ) : - ZoneChannelPacket< FFXIVIpcPing >( player.getId(), player.getId() ) - { - initialize( player, inVal ); - }; + /** + * @brief The Ping response packet. + */ + class PingPacket : public ZoneChannelPacket< FFXIVIpcPing > + { + public: + PingPacket( Entity::Player& player, int32_t inVal ) : + ZoneChannelPacket< FFXIVIpcPing >( player.getId(), player.getId() ) + { + initialize( player, inVal ); + }; -private: - void initialize( Entity::Player& player, int32_t inVal ) - { - m_data.timeInMilliseconds = 0x000014D00000000 + inVal; - }; -}; + private: + void initialize( Entity::Player& player, int32_t inVal ) + { + m_data.timeInMilliseconds = 0x000014D00000000 + inVal; + }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_CORE_NETWORK_PACKETS_CPINGPACKET_H*/ diff --git a/src/servers/Server_Zone/Network/PacketWrappers/PlayerSpawnPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/PlayerSpawnPacket.h index 4ee95f5b..b3c1d19a 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/PlayerSpawnPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/PlayerSpawnPacket.h @@ -1,141 +1,140 @@ #ifndef _PLAYERSPAWN_H #define _PLAYERSPAWN_H -#include -#include -#include #include "Actor/Player.h" #include "Forwards.h" #include "Inventory/Inventory.h" #include "Inventory/Item.h" #include "StatusEffect/StatusEffect.h" +#include +#include +#include namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { - /** - * @brief The packet sent to spawn a player. - */ - class PlayerSpawnPacket : - public GamePacketNew< FFXIVIpcPlayerSpawn, ServerZoneIpcType > - { - public: - PlayerSpawnPacket( Entity::Player& player, Entity::Player& target ) : - GamePacketNew< FFXIVIpcPlayerSpawn, ServerZoneIpcType >( player.getId(), target.getId() ) - { - initialize( player, target ); - }; - - private: - void initialize( Entity::Player& player, Entity::Player& target ) - { - // todo: figure out unkown offsets - // TODO: temporary gm rank - //m_data.gmRank = 0xff; - - m_data.classJob = static_cast< uint8_t >( player.getClass() ); - //m_data.status = static_cast< uint8_t >( pPlayer->getStatus() ); - - m_data.hPCurr = player.getHp(); - m_data.mPCurr = player.getMp(); - m_data.tPCurr = player.getTp(); - m_data.hPMax = player.getMaxHp(); - m_data.mPMax = player.getMaxMp(); - - //m_data.tPMax = 3000; - m_data.level = player.getLevel(); - m_data.gmRank = player.getGmRank(); - m_data.pose = 0; - - memcpy( m_data.look, player.getLookArray(), 26 ); - - auto item = player.getInventory()->getItemAt( Inventory::GearSet0, Inventory::EquipSlot::MainHand ); - if( item ) - m_data.mainWeaponModel = item->getModelId1(); - m_data.secWeaponModel = player.getModelSubWeapon(); - - m_data.models[0] = player.getModelForSlot( Inventory::EquipSlot::Head ); - m_data.models[1] = player.getModelForSlot( Inventory::EquipSlot::Body ); - m_data.models[2] = player.getModelForSlot( Inventory::EquipSlot::Hands ); - m_data.models[3] = player.getModelForSlot( Inventory::EquipSlot::Legs ); - m_data.models[4] = player.getModelForSlot( Inventory::EquipSlot::Feet ); - strcpy( m_data.name, player.getName().c_str() ); - - m_data.pos.x = player.getPos().x; - m_data.pos.y = player.getPos().y; - m_data.pos.z = player.getPos().z; - m_data.rotation = Math::Util::floatToUInt16Rot( player.getRotation() ); - - - m_data.title = player.getTitle(); - m_data.voice = player.getVoiceId(); - m_data.currentMount = player.getCurrentMount(); - - m_data.onlineStatus = static_cast< uint8_t >( player.getOnlineStatus() ); - - //m_data.u23 = 0x04; - //m_data.u24 = 256; - m_data.state = static_cast< uint8_t >( player.getStatus() ); - m_data.type = 1; - if( target.getId() == player.getId() ) + /** + * @brief The packet sent to spawn a player. + */ + class PlayerSpawnPacket : public GamePacketNew< FFXIVIpcPlayerSpawn, ServerZoneIpcType > { - m_data.spawnIndex = 0x00; - } - else - { - m_data.spawnIndex = target.getSpawnIdForActorId( player.getId() ); - } - // 0x20 == spawn hidden to be displayed by the spawneffect control - m_data.displayFlags = player.getStance(); + public: + PlayerSpawnPacket( Entity::Player& player, Entity::Player& target ) : + GamePacketNew< FFXIVIpcPlayerSpawn, ServerZoneIpcType >( player.getId(), target.getId() ) + { + initialize( player, target ); + }; - if( player.getZoningType() != Common::ZoneingType::None ) - { - m_data.displayFlags |= Entity::Actor::DisplayFlags::Invisible; - } + private: + void initialize( Entity::Player& player, Entity::Player& target ) + { + // todo: figure out unkown offsets + // TODO: temporary gm rank + // m_data.gmRank = 0xff; - if( player.getEquipDisplayFlags() & Core::Common::EquipDisplayFlags::HideHead ) - { - m_data.displayFlags |= Entity::Actor::DisplayFlags::HideHead; - } + m_data.classJob = static_cast< uint8_t >( player.getClass() ); + // m_data.status = static_cast< uint8_t >( pPlayer->getStatus() ); - if( player.getEquipDisplayFlags() & Core::Common::EquipDisplayFlags::HideWeapon ) - { - m_data.displayFlags |= Entity::Actor::DisplayFlags::HideWeapon; - } + m_data.hPCurr = player.getHp(); + m_data.mPCurr = player.getMp(); + m_data.tPCurr = player.getTp(); + m_data.hPMax = player.getMaxHp(); + m_data.mPMax = player.getMaxMp(); - if( player.getEquipDisplayFlags() & Core::Common::EquipDisplayFlags::Visor ) - { - m_data.displayFlags |= Entity::Actor::DisplayFlags::Visor; - } + // m_data.tPMax = 3000; + m_data.level = player.getLevel(); + m_data.gmRank = player.getGmRank(); + m_data.pose = 0; - m_data.currentMount = player.getCurrentMount(); + memcpy( m_data.look, player.getLookArray(), 26 ); - m_data.targetId = player.getTargetId(); - //m_data.type = 1; - //m_data.unknown_33 = 4; - //m_data.unknown_38 = 0x70; - //m_data.unknown_60 = 3; - //m_data.unknown_61 = 7; + auto item = player.getInventory()->getItemAt( Inventory::GearSet0, Inventory::EquipSlot::MainHand ); + if( item ) + m_data.mainWeaponModel = item->getModelId1(); + m_data.secWeaponModel = player.getModelSubWeapon(); - uint64_t currentTimeMs = Util::getTimeMs(); + m_data.models[0] = player.getModelForSlot( Inventory::EquipSlot::Head ); + m_data.models[1] = player.getModelForSlot( Inventory::EquipSlot::Body ); + m_data.models[2] = player.getModelForSlot( Inventory::EquipSlot::Hands ); + m_data.models[3] = player.getModelForSlot( Inventory::EquipSlot::Legs ); + m_data.models[4] = player.getModelForSlot( Inventory::EquipSlot::Feet ); + strcpy( m_data.name, player.getName().c_str() ); - for( auto const& effect : player.getStatusEffectMap() ) - { - m_data.effect[effect.first].effect_id = effect.second->getId(); - m_data.effect[effect.first].duration = static_cast< float >( effect.second->getDuration() - - ( currentTimeMs - effect.second->getStartTimeMs() ) ) / 1000; - m_data.effect[effect.first].sourceActorId = effect.second->getSrcActorId(); - m_data.effect[effect.first].unknown1 = effect.second->getParam(); - } + m_data.pos.x = player.getPos().x; + m_data.pos.y = player.getPos().y; + m_data.pos.z = player.getPos().z; + m_data.rotation = Math::Util::floatToUInt16Rot( player.getRotation() ); - }; - }; + m_data.title = player.getTitle(); + m_data.voice = player.getVoiceId(); + m_data.currentMount = player.getCurrentMount(); -} -} -} -} + m_data.onlineStatus = static_cast< uint8_t >( player.getOnlineStatus() ); + + // m_data.u23 = 0x04; + // m_data.u24 = 256; + m_data.state = static_cast< uint8_t >( player.getStatus() ); + m_data.type = 1; + if( target.getId() == player.getId() ) + { + m_data.spawnIndex = 0x00; + } + else + { + m_data.spawnIndex = target.getSpawnIdForActorId( player.getId() ); + } + // 0x20 == spawn hidden to be displayed by the spawneffect control + m_data.displayFlags = player.getStance(); + + if( player.getZoningType() != Common::ZoneingType::None ) + { + m_data.displayFlags |= Entity::Actor::DisplayFlags::Invisible; + } + + if( player.getEquipDisplayFlags() & Core::Common::EquipDisplayFlags::HideHead ) + { + m_data.displayFlags |= Entity::Actor::DisplayFlags::HideHead; + } + + if( player.getEquipDisplayFlags() & Core::Common::EquipDisplayFlags::HideWeapon ) + { + m_data.displayFlags |= Entity::Actor::DisplayFlags::HideWeapon; + } + + if( player.getEquipDisplayFlags() & Core::Common::EquipDisplayFlags::Visor ) + { + m_data.displayFlags |= Entity::Actor::DisplayFlags::Visor; + } + + m_data.currentMount = player.getCurrentMount(); + + m_data.targetId = player.getTargetId(); + // m_data.type = 1; + // m_data.unknown_33 = 4; + // m_data.unknown_38 = 0x70; + // m_data.unknown_60 = 3; + // m_data.unknown_61 = 7; + + uint64_t currentTimeMs = Util::getTimeMs(); + + for( auto const& effect : player.getStatusEffectMap() ) + { + m_data.effect[effect.first].effect_id = effect.second->getId(); + m_data.effect[effect.first].duration = + static_cast< float >( effect.second->getDuration() - + ( currentTimeMs - effect.second->getStartTimeMs() ) ) / + 1000; + m_data.effect[effect.first].sourceActorId = effect.second->getSrcActorId(); + m_data.effect[effect.first].unknown1 = effect.second->getParam(); + } + }; + }; + + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_PlayerSpawn_H*/ diff --git a/src/servers/Server_Zone/Network/PacketWrappers/PlayerStateFlagsPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/PlayerStateFlagsPacket.h index ac0c4826..a2dd2d0a 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/PlayerStateFlagsPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/PlayerStateFlagsPacket.h @@ -1,58 +1,54 @@ #ifndef _PLAYERSTATE_H #define _PLAYERSTATE_H -#include #include "Actor/Player.h" #include "Forwards.h" +#include namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief Packet sent to set a players state, this impacts which actions he can perform. -*/ -class PlayerStateFlagsPacket : - public ZoneChannelPacket< FFXIVIpcPlayerStateFlags > -{ -public: - PlayerStateFlagsPacket( Entity::Player& player ) : - ZoneChannelPacket< FFXIVIpcPlayerStateFlags >( player.getId(), player.getId() ) - { - initialize( player.getStateFlags() ); - } + /** + * @brief Packet sent to set a players state, this impacts which actions he can perform. + */ + class PlayerStateFlagsPacket : public ZoneChannelPacket< FFXIVIpcPlayerStateFlags > + { + public: + PlayerStateFlagsPacket( Entity::Player& player ) : + ZoneChannelPacket< FFXIVIpcPlayerStateFlags >( player.getId(), player.getId() ) + { + initialize( player.getStateFlags() ); + } - PlayerStateFlagsPacket( Entity::Player& player, std::vector< Common::PlayerStateFlag > flags ) : - ZoneChannelPacket< FFXIVIpcPlayerStateFlags >( player.getId(), player.getId() ) - { - uint8_t newFlags[7]; - memset( newFlags, 0, 7 ); + PlayerStateFlagsPacket( Entity::Player& player, std::vector< Common::PlayerStateFlag > flags ) : + ZoneChannelPacket< FFXIVIpcPlayerStateFlags >( player.getId(), player.getId() ) + { + uint8_t newFlags[7]; + memset( newFlags, 0, 7 ); - for( auto& flag : flags ) - { - int32_t iFlag = static_cast< uint32_t >( flag ); - uint8_t index = iFlag / 8; - uint8_t bitIndex = iFlag % 8; + for( auto& flag : flags ) + { + int32_t iFlag = static_cast< uint32_t >( flag ); + uint8_t index = iFlag / 8; + uint8_t bitIndex = iFlag % 8; - uint8_t value = 1 << bitIndex; + uint8_t value = 1 << bitIndex; - newFlags[index] |= value; - } + newFlags[index] |= value; + } - initialize( newFlags ); - } + initialize( newFlags ); + } -private: - void initialize( const uint8_t* flags ) - { - memcpy( m_data.flags, flags, 7 ); - }; -}; + private: + void initialize( const uint8_t* flags ) { memcpy( m_data.flags, flags, 7 ); }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_PLAYERSTATE_H*/ diff --git a/src/servers/Server_Zone/Network/PacketWrappers/QuestMessagePacket.h b/src/servers/Server_Zone/Network/PacketWrappers/QuestMessagePacket.h index 1c846b11..cf305ce6 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/QuestMessagePacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/QuestMessagePacket.h @@ -1,43 +1,42 @@ #ifndef _QUESTMESSAGE_H #define _QUESTMESSAGE_H -#include #include "Actor/Player.h" #include "Forwards.h" +#include namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief Packet to display a quest specific info message. -*/ -class QuestMessagePacket : - public ZoneChannelPacket< FFXIVIpcQuestMessage > -{ -public: - QuestMessagePacket( Entity::ActorPtr pActor, uint32_t questId, int8_t msgId, - uint8_t type = 0, uint32_t var1 = 0, uint32_t var2 = 0 ) : - ZoneChannelPacket< FFXIVIpcQuestMessage >( pActor->getId(), pActor->getId() ) - { - initialize( questId, msgId, type, var1, var2 ); - }; + /** + * @brief Packet to display a quest specific info message. + */ + class QuestMessagePacket : public ZoneChannelPacket< FFXIVIpcQuestMessage > + { + public: + QuestMessagePacket( Entity::ActorPtr pActor, uint32_t questId, int8_t msgId, uint8_t type = 0, + uint32_t var1 = 0, uint32_t var2 = 0 ) : + ZoneChannelPacket< FFXIVIpcQuestMessage >( pActor->getId(), pActor->getId() ) + { + initialize( questId, msgId, type, var1, var2 ); + }; -private: - void initialize( uint32_t questId, int8_t msgId, uint8_t type, uint32_t var1, uint32_t var2 ) - { - m_data.questId = questId; - m_data.msgId = msgId; - m_data.type = type; - m_data.var1 = var1; - m_data.var2 = var2; - }; -}; + private: + void initialize( uint32_t questId, int8_t msgId, uint8_t type, uint32_t var1, uint32_t var2 ) + { + m_data.questId = questId; + m_data.msgId = msgId; + m_data.type = type; + m_data.var1 = var1; + m_data.var2 = var2; + }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /* _QUESTMESSAGE_H */ \ No newline at end of file diff --git a/src/servers/Server_Zone/Network/PacketWrappers/ServerNoticePacket.h b/src/servers/Server_Zone/Network/PacketWrappers/ServerNoticePacket.h index 07ec036e..31f5fdc8 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/ServerNoticePacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/ServerNoticePacket.h @@ -1,38 +1,34 @@ #ifndef _SERVERNOTICEPACKET_H #define _SERVERNOTICEPACKET_H +#include "Forwards.h" #include #include -#include "Forwards.h" namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The Ping response packet. -*/ -class ServerNoticePacket : - public ZoneChannelPacket< FFXIVIpcServerNotice > -{ -public: - ServerNoticePacket( uint32_t playerId, const std::string& message ) : - ZoneChannelPacket< FFXIVIpcServerNotice >( playerId, playerId ) - { - initialize( message ); - }; + /** + * @brief The Ping response packet. + */ + class ServerNoticePacket : public ZoneChannelPacket< FFXIVIpcServerNotice > + { + public: + ServerNoticePacket( uint32_t playerId, const std::string& message ) : + ZoneChannelPacket< FFXIVIpcServerNotice >( playerId, playerId ) + { + initialize( message ); + }; -private: - void initialize( const std::string& message ) - { - strcpy( m_data.message, message.c_str() ); - }; -}; + private: + void initialize( const std::string& message ) { strcpy( m_data.message, message.c_str() ); }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_SERVERNOTICEPACKET_H*/ \ No newline at end of file diff --git a/src/servers/Server_Zone/Network/PacketWrappers/UpdateHpMpTpPacket.h b/src/servers/Server_Zone/Network/PacketWrappers/UpdateHpMpTpPacket.h index 927d968f..59d73002 100644 --- a/src/servers/Server_Zone/Network/PacketWrappers/UpdateHpMpTpPacket.h +++ b/src/servers/Server_Zone/Network/PacketWrappers/UpdateHpMpTpPacket.h @@ -1,40 +1,39 @@ #ifndef _UPDATEHPMPTP_H #define _UPDATEHPMPTP_H -#include -#include #include "Forwards.h" +#include +#include namespace Core { namespace Network { -namespace Packets { -namespace Server { + namespace Packets { + namespace Server { -/** -* @brief The Ping response packet. -*/ -class UpdateHpMpTpPacket : - public ZoneChannelPacket< FFXIVIpcUpdateHpMpTp > -{ -public: - UpdateHpMpTpPacket( Entity::ActorPtr pActor ) : - ZoneChannelPacket< FFXIVIpcUpdateHpMpTp >( pActor->getId(), pActor->getId() ) - { - initialize( pActor ); - }; + /** + * @brief The Ping response packet. + */ + class UpdateHpMpTpPacket : public ZoneChannelPacket< FFXIVIpcUpdateHpMpTp > + { + public: + UpdateHpMpTpPacket( Entity::ActorPtr pActor ) : + ZoneChannelPacket< FFXIVIpcUpdateHpMpTp >( pActor->getId(), pActor->getId() ) + { + initialize( pActor ); + }; -private: - void initialize( Entity::ActorPtr pActor ) - { - m_data.hp = pActor->getHp(); - m_data.mp = pActor->getMp(); - m_data.tp = pActor->getTp(); - }; -}; + private: + void initialize( Entity::ActorPtr pActor ) + { + m_data.hp = pActor->getHp(); + m_data.mp = pActor->getMp(); + m_data.tp = pActor->getTp(); + }; + }; -} -} -} -} + } // namespace Server + } // namespace Packets +} // namespace Network +} // namespace Core #endif /*_UPDATEHPMPTP_H*/ \ No newline at end of file diff --git a/src/servers/Server_Zone/Script/ScriptManager.cpp b/src/servers/Server_Zone/Script/ScriptManager.cpp index 7ee72a52..63b611d1 100644 --- a/src/servers/Server_Zone/Script/ScriptManager.cpp +++ b/src/servers/Server_Zone/Script/ScriptManager.cpp @@ -1,24 +1,24 @@ -#include #include +#include #include #include -#include "Zone/Zone.h" -#include "Actor/Player.h" #include "Actor/BattleNpc.h" -#include "ServerZone.h" +#include "Actor/Player.h" #include "Event/Event.h" #include "Event/EventHelper.h" -#include "StatusEffect/StatusEffect.h" #include "Network/PacketWrappers/ServerNoticePacket.h" #include "Script/ScriptManager.h" +#include "ServerZone.h" +#include "StatusEffect/StatusEffect.h" +#include "Zone/Zone.h" -#include -#include -#include -#include #include +#include +#include +#include +#include extern Core::Logger g_log; extern Core::Data::ExdData g_exdData; @@ -31,10 +31,9 @@ Core::Scripting::ScriptManager::ScriptManager() Core::Scripting::ScriptManager::~ScriptManager() { - } -void Core::Scripting::ScriptManager::loadDir( std::string dirname, std::set& chaiFiles ) +void Core::Scripting::ScriptManager::loadDir( std::string dirname, std::set< std::string >& chaiFiles ) { g_log.info( "ScriptEngine: loading scripts from " + dirname ); @@ -52,7 +51,6 @@ void Core::Scripting::ScriptManager::loadDir( std::string dirname, std::set& Core::Scripting::ScriptManage return m_pChaiHandler; } - bool Core::Scripting::ScriptManager::onTalk( Entity::Player& player, uint64_t actorId, uint32_t eventId ) { std::string eventName = "onTalk"; std::string objName = Event::getEventName( eventId ); - player.sendDebug( "Actor: " + - std::to_string( actorId ) + " -> " + + player.sendDebug( "Actor: " + std::to_string( actorId ) + " -> " + std::to_string( Event::mapEventActorToRealActor( static_cast< uint32_t >( actorId ) ) ) + - " \neventId: " + - std::to_string( eventId ) + - " (0x" + boost::str( boost::format( "%|08X|" ) - % static_cast< uint64_t >( eventId & 0xFFFFFFF ) ) + ")" ); + " \neventId: " + std::to_string( eventId ) + " (0x" + + boost::str( boost::format( "%|08X|" ) % static_cast< uint64_t >( eventId & 0xFFFFFFF ) ) + ")" ); uint16_t eventType = eventId >> 16; @@ -110,15 +104,16 @@ bool Core::Scripting::ScriptManager::onTalk( Entity::Player& player, uint64_t ac player.eventStart( actorId, eventId, Event::Event::Talk, 0, 0 ); - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, - uint32_t, Entity::Player&, uint64_t ) > >( eventName ); + auto fn = m_pChaiHandler + ->eval< std::function< void( chaiscript::Boxed_Value&, uint32_t, Entity::Player&, uint64_t ) > >( + eventName ); fn( obj, eventId, player, actorId ); player.checkEvent( eventId ); } catch( std::exception& e ) { - player.sendDebug( e.what( ) ); + player.sendDebug( e.what() ); if( eventType == Common::EventType::Quest ) { @@ -135,8 +130,8 @@ bool Core::Scripting::ScriptManager::onTalk( Entity::Player& player, uint64_t ac return true; } -bool Core::Scripting::ScriptManager::onEnterTerritory( Entity::Player& player, uint32_t eventId, - uint16_t param1, uint16_t param2 ) +bool Core::Scripting::ScriptManager::onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, + uint16_t param2 ) { std::string eventName = "onEnterTerritory"; std::string objName = Event::getEventName( eventId ); @@ -150,8 +145,9 @@ bool Core::Scripting::ScriptManager::onEnterTerritory( Entity::Player& player, u player.eventStart( player.getId(), eventId, Event::Event::EnterTerritory, 0, player.getZoneId() ); - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, - Entity::Player&, uint16_t, uint16_t ) > >( eventName ); + auto fn = m_pChaiHandler->eval< + std::function< void( chaiscript::Boxed_Value&, uint32_t, Entity::Player&, uint16_t, uint16_t ) > >( + eventName ); fn( obj, eventId, player, param1, param2 ); player.checkEvent( eventId ); @@ -164,8 +160,8 @@ bool Core::Scripting::ScriptManager::onEnterTerritory( Entity::Player& player, u return true; } -bool Core::Scripting::ScriptManager::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, - float x, float y, float z ) +bool Core::Scripting::ScriptManager::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, + float y, float z ) { std::string eventName = "onWithinRange"; std::string objName = Event::getEventName( eventId ); @@ -173,14 +169,15 @@ bool Core::Scripting::ScriptManager::onWithinRange( Entity::Player& player, uint try { // Get object from engine - auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) ); + auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) ); player.sendDebug( "Calling: " + objName + "." + eventName ); player.eventStart( player.getId(), eventId, Event::Event::WithinRange, 1, param1 ); - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, uint32_t, - float, float, float ) > >( eventName ); + auto fn = m_pChaiHandler->eval< + std::function< void( chaiscript::Boxed_Value&, uint32_t, Entity::Player&, uint32_t, float, float, float ) > >( + eventName ); fn( obj, eventId, player, param1, x, y, z ); player.checkEvent( eventId ); @@ -193,8 +190,8 @@ bool Core::Scripting::ScriptManager::onWithinRange( Entity::Player& player, uint return true; } -bool Core::Scripting::ScriptManager::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, - float x, float y, float z ) +bool Core::Scripting::ScriptManager::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, + float y, float z ) { std::string eventName = "onOutsideRange"; std::string objName = Event::getEventName( eventId ); @@ -208,8 +205,9 @@ bool Core::Scripting::ScriptManager::onOutsideRange( Entity::Player& player, uin player.eventStart( player.getId(), eventId, Event::Event::OutsideRange, 1, param1 ); - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, uint32_t, - float, float, float ) > >( eventName ); + auto fn = m_pChaiHandler->eval< + std::function< void( chaiscript::Boxed_Value&, uint32_t, Entity::Player&, uint32_t, float, float, float ) > >( + eventName ); fn( obj, eventId, player, param1, x, y, z ); player.checkEvent( eventId ); @@ -222,8 +220,8 @@ bool Core::Scripting::ScriptManager::onOutsideRange( Entity::Player& player, uin return true; } -bool Core::Scripting::ScriptManager::onEmote( Entity::Player& player, uint64_t actorId, - uint32_t eventId, uint8_t emoteId ) +bool Core::Scripting::ScriptManager::onEmote( Entity::Player& player, uint64_t actorId, uint32_t eventId, + uint8_t emoteId ) { std::string eventName = "onEmote"; std::string objName = Event::getEventName( eventId ); @@ -236,8 +234,10 @@ bool Core::Scripting::ScriptManager::onEmote( Entity::Player& player, uint64_t a player.eventStart( actorId, eventId, Event::Event::Emote, 0, emoteId ); - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, - uint64_t, uint8_t ) > >( eventName ); + auto fn = + m_pChaiHandler + ->eval< std::function< void( chaiscript::Boxed_Value&, uint32_t, Entity::Player&, uint64_t, uint8_t ) > >( + eventName ); fn( obj, eventId, player, actorId, emoteId ); player.checkEvent( eventId ); @@ -260,18 +260,14 @@ bool Core::Scripting::ScriptManager::onEmote( Entity::Player& player, uint64_t a return true; } -bool Core::Scripting::ScriptManager::onEventHandlerReturn( Entity::Player& player, uint32_t eventId, - uint16_t subEvent, uint16_t param1, uint16_t param2, - uint16_t param3 ) +bool Core::Scripting::ScriptManager::onEventHandlerReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, + uint16_t param1, uint16_t param2, uint16_t param3 ) { - player.sendDebug( "eventId: " + - std::to_string( eventId ) + - " ( 0x" + boost::str( boost::format( "%|08X|" ) % ( uint64_t ) ( eventId & 0xFFFFFFF ) ) + " ) " + - " scene: " + std::to_string( subEvent ) + - " p1: " + std::to_string( param1 ) + - " p2: " + std::to_string( param2 ) + - " p3: " + std::to_string( param3 ) ); + player.sendDebug( "eventId: " + std::to_string( eventId ) + " ( 0x" + + boost::str( boost::format( "%|08X|" ) % ( uint64_t )( eventId & 0xFFFFFFF ) ) + " ) " + + " scene: " + std::to_string( subEvent ) + " p1: " + std::to_string( param1 ) + + " p2: " + std::to_string( param2 ) + " p3: " + std::to_string( param3 ) ); try { @@ -311,8 +307,9 @@ bool Core::Scripting::ScriptManager::onEventHandlerTradeReturn( Entity::Player& try { - auto fn = m_pChaiHandler->eval< std::function< void( Entity::Player&, uint32_t, - uint16_t, uint16_t, uint32_t ) > >( eventName ); + auto fn = + m_pChaiHandler->eval< std::function< void( Entity::Player&, uint32_t, uint16_t, uint16_t, uint32_t ) > >( + eventName ); fn( player, eventId, subEvent, param, catalogId ); } catch( ... ) @@ -323,8 +320,8 @@ bool Core::Scripting::ScriptManager::onEventHandlerTradeReturn( Entity::Player& return true; } -bool Core::Scripting::ScriptManager::onEventItem( Entity::Player& player, uint32_t eventItemId, - uint32_t eventId, uint32_t castTime, uint64_t targetId ) +bool Core::Scripting::ScriptManager::onEventItem( Entity::Player& player, uint32_t eventItemId, uint32_t eventId, + uint32_t castTime, uint64_t targetId ) { std::string eventName = "onEventItem"; std::string objName = Event::getEventName( eventId ); @@ -336,9 +333,10 @@ bool Core::Scripting::ScriptManager::onEventItem( Entity::Player& player, uint32 player.sendDebug( "Calling: " + objName + "." + eventName ); player.eventStart( targetId, eventId, Event::Event::Item, 0, 0 ); - - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, - uint32_t, uint32_t, uint64_t ) > >( eventName ); + + auto fn = m_pChaiHandler->eval< + std::function< void( chaiscript::Boxed_Value&, uint32_t, Entity::Player&, uint32_t, uint32_t, uint64_t ) > >( + eventName ); fn( obj, eventId, player, eventItemId, castTime, targetId ); } catch( std::exception& e ) @@ -348,14 +346,12 @@ bool Core::Scripting::ScriptManager::onEventItem( Entity::Player& player, uint32 } return true; - } bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t nameId ) { std::string eventName = "onBnpcKill_" + std::to_string( nameId ); - // loop through all active quests and try to call available onMobKill callbacks for( size_t i = 0; i < 30; i++ ) { @@ -369,18 +365,18 @@ bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t auto obj = m_pChaiHandler->eval( Event::getEventName( 0x00010000 | questId ) ); std::string objName = Event::getEventName( 0x00010000 | questId ); - player.sendDebug("Calling: " + objName + "." + eventName); + player.sendDebug( "Calling: " + objName + "." + eventName ); try { - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Player& ) > >(eventName); + auto fn = + m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value&, Entity::Player& ) > >( eventName ); fn( obj, player ); } catch( std::exception& e ) { g_log.info( e.what() ); } - } } @@ -389,24 +385,25 @@ bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t bool Core::Scripting::ScriptManager::onCastFinish( Entity::Player& player, Entity::ActorPtr pTarget, uint32_t actionId ) { - std::string eventName = "onFinish"; + std::string eventName = "onFinish"; - try - { - auto obj = m_pChaiHandler->eval( "skillDef_" + std::to_string( actionId ) ); - std::string objName = "skillDef_" + std::to_string( actionId ); + try + { + auto obj = m_pChaiHandler->eval( "skillDef_" + std::to_string( actionId ) ); + std::string objName = "skillDef_" + std::to_string( actionId ); - player.sendDebug( "Calling: " + objName + "." + eventName ); - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Player&, - Entity::Actor& ) > >( eventName ); - fn( obj, player, *pTarget ); - } - catch( std::exception& e ) - { - player.sendUrgent( e.what() ); - } + player.sendDebug( "Calling: " + objName + "." + eventName ); + auto fn = + m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value&, Entity::Player&, Entity::Actor& ) > >( + eventName ); + fn( obj, player, *pTarget ); + } + catch( std::exception& e ) + { + player.sendUrgent( e.what() ); + } - return true; + return true; } bool Core::Scripting::ScriptManager::onStatusReceive( Entity::ActorPtr pActor, uint32_t effectId ) @@ -421,7 +418,7 @@ bool Core::Scripting::ScriptManager::onStatusReceive( Entity::ActorPtr pActor, u if( pActor->isPlayer() ) pActor->getAsPlayer()->sendDebug( "Calling: " + objName + "." + eventName ); - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Actor&) > >( eventName ); + auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value&, Entity::Actor& ) > >( eventName ); fn( obj, *pActor ); } catch( std::exception& e ) @@ -445,8 +442,10 @@ bool Core::Scripting::ScriptManager::onStatusTick( Entity::ActorPtr pActor, Core if( pActor->isPlayer() ) pActor->getAsPlayer()->sendDebug( "Calling: " + objName + "." + eventName ); - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Actor&, - StatusEffect::StatusEffect& ) > >( eventName ); + auto fn = + m_pChaiHandler + ->eval< std::function< void( chaiscript::Boxed_Value&, Entity::Actor&, StatusEffect::StatusEffect& ) > >( + eventName ); fn( obj, *pActor, effect ); } catch( std::exception& e ) @@ -470,7 +469,7 @@ bool Core::Scripting::ScriptManager::onStatusTimeOut( Entity::ActorPtr pActor, u if( pActor->isPlayer() ) pActor->getAsPlayer()->sendDebug( "Calling: " + objName + "." + eventName ); - auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, Entity::Actor& ) > >( eventName ); + auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value&, Entity::Actor& ) > >( eventName ); fn( obj, *pActor ); } catch( std::exception& e ) @@ -498,6 +497,4 @@ bool Core::Scripting::ScriptManager::onZoneInit( ZonePtr pZone ) } return true; - } - diff --git a/src/servers/Server_Zone/Script/ScriptManager.h b/src/servers/Server_Zone/Script/ScriptManager.h index 2e66f3cf..014916e0 100644 --- a/src/servers/Server_Zone/Script/ScriptManager.h +++ b/src/servers/Server_Zone/Script/ScriptManager.h @@ -5,67 +5,63 @@ #include #include -#include #include "Forwards.h" +#include - -namespace chaiscript -{ - class ChaiScript; +namespace chaiscript { +class ChaiScript; } -namespace Core -{ - namespace Scripting +namespace Core { +namespace Scripting { + + class ScriptManager { + private: + boost::shared_ptr< chaiscript::ChaiScript > m_pChaiHandler; - class ScriptManager - { - private: + std::function< std::string( Entity::Player& ) > m_onFirstEnterWorld; + // auto fn = m_pChaiHandler->eval< std::function >( "onFirstEnterWorld" ); - boost::shared_ptr< chaiscript::ChaiScript > m_pChaiHandler; + public: + ScriptManager(); + ~ScriptManager(); - std::function< std::string( Entity::Player& ) > m_onFirstEnterWorld; - // auto fn = m_pChaiHandler->eval< std::function >( "onFirstEnterWorld" ); + int32_t init(); + void reload(); - public: - ScriptManager(); - ~ScriptManager(); + const boost::shared_ptr< chaiscript::ChaiScript >& getHandler() const; - int32_t init(); - void reload(); + void onPlayerFirstEnterWorld( Entity::Player& player ); - const boost::shared_ptr< chaiscript::ChaiScript >& getHandler() const; + static bool registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, uint32_t bnpcNameId, + uint32_t modelId, std::string aiName ); - void onPlayerFirstEnterWorld( Entity::Player& player ); + bool onTalk( Entity::Player& player, uint64_t actorId, uint32_t eventId ); + bool onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ); + bool onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ); + bool onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ); + bool onEmote( Entity::Player& player, uint64_t actorId, uint32_t eventId, uint8_t emoteId ); + bool onEventItem( Entity::Player& player, uint32_t eventItemId, uint32_t eventId, uint32_t castTime, + uint64_t targetId ); - static bool registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, uint32_t bnpcNameId, uint32_t modelId, std::string aiName ); + bool onMobKill( Entity::Player& player, uint16_t nameId ); - bool onTalk( Entity::Player& player, uint64_t actorId, uint32_t eventId ); - bool onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ); - bool onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ); - bool onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ); - bool onEmote( Entity::Player& player, uint64_t actorId, uint32_t eventId, uint8_t emoteId ); - bool onEventItem( Entity::Player& player, uint32_t eventItemId, uint32_t eventId, uint32_t castTime, uint64_t targetId ); + bool onCastFinish( Entity::Player& pPlayer, Entity::ActorPtr pTarget, uint32_t actionId ); - bool onMobKill( Entity::Player& player, uint16_t nameId ); + bool onStatusReceive( Entity::ActorPtr pActor, uint32_t effectId ); + bool onStatusTick( Entity::ActorPtr pActor, Core::StatusEffect::StatusEffect& effect ); + bool onStatusTimeOut( Entity::ActorPtr pActor, uint32_t effectId ); - bool onCastFinish( Entity::Player& pPlayer, Entity::ActorPtr pTarget, uint32_t actionId ); + bool onZoneInit( ZonePtr pZone ); - bool onStatusReceive( Entity::ActorPtr pActor, uint32_t effectId ); - bool onStatusTick( Entity::ActorPtr pActor, Core::StatusEffect::StatusEffect& effect ); - bool onStatusTimeOut( Entity::ActorPtr pActor, uint32_t effectId ); + bool onEventHandlerReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param1, + uint16_t param2, uint16_t param3 ); + bool onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param, + uint32_t catalogId ); - bool onZoneInit( ZonePtr pZone ); - - bool onEventHandlerReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param1, uint16_t param2, uint16_t param3 ); - bool onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param, uint32_t catalogId ); - - - void loadDir( std::string dirname, std::set& chaiFiles ); - - - }; - } -} + void loadDir( std::string dirname, std::set< std::string >& chaiFiles ); + }; +} // namespace Scripting +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Script/ScriptManagerInit.cpp b/src/servers/Server_Zone/Script/ScriptManagerInit.cpp index dbf76194..e74f2fdb 100644 --- a/src/servers/Server_Zone/Script/ScriptManagerInit.cpp +++ b/src/servers/Server_Zone/Script/ScriptManagerInit.cpp @@ -8,13 +8,13 @@ #include "Script/ScriptManager.h" -#include "Zone/Zone.h" -#include "Actor/Player.h" #include "Actor/BattleNpc.h" +#include "Actor/Player.h" #include "Event/Event.h" #include "Event/EventHelper.h" #include "Network/PacketWrappers/ServerNoticePacket.h" #include "StatusEffect/StatusEffect.h" +#include "Zone/Zone.h" #include @@ -34,7 +34,8 @@ int Core::Scripting::ScriptManager::init() m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::getTargetId ), "getTargetId" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::addStatusEffect ), "addStatusEffect" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::addStatusEffectById ), "addStatusEffectById" ); - m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::addStatusEffectByIdIfNotExist ), "addStatusEffectByIdIfNotExist" ); + m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::addStatusEffectByIdIfNotExist ), + "addStatusEffectByIdIfNotExist" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Actor::takeDamage ), "takeDamage" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::forceZoneing ), "setZone" ); @@ -51,7 +52,7 @@ int Core::Scripting::ScriptManager::init() m_pChaiHandler->add( chaiscript::fun( &Entity::Player::teleport ), "teleport" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::prepareZoning ), "prepareZoning" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::isInCombat ), "isInCombat" ); - + m_pChaiHandler->add( chaiscript::fun( &Entity::Player::getCurrency ), "getCurrency" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::addCurrency ), "addCurrency" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::removeCurrency ), "removeCurrency" ); @@ -137,13 +138,24 @@ int Core::Scripting::ScriptManager::init() m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestBitFlag40 ), "setQuestBitFlag40" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::setQuestBitFlag48 ), "setQuestBitFlag48" ); - m_pChaiHandler->add(chaiscript::fun(&Entity::Player::giveQuestRewards), "giveQuestRewards"); + m_pChaiHandler->add( chaiscript::fun( &Entity::Player::giveQuestRewards ), "giveQuestRewards" ); - m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t >( &Entity::Player::eventPlay ), "eventPlay" ); - m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, EventReturnCallback >( &Entity::Player::eventPlay ), "eventPlay" ); - m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, EventReturnCallback >( &Entity::Player::eventPlay ), "eventPlay" ); - m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, EventReturnCallback >( &Entity::Player::eventPlay ), "eventPlay" ); - m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t >( &Entity::Player::eventPlay ), "eventPlay" ); + m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t >( + &Entity::Player::eventPlay ), + "eventPlay" ); + m_pChaiHandler->add( + chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, EventReturnCallback >( + &Entity::Player::eventPlay ), + "eventPlay" ); + m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, + uint32_t, EventReturnCallback >( &Entity::Player::eventPlay ), + "eventPlay" ); + m_pChaiHandler->add( chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t, EventReturnCallback >( + &Entity::Player::eventPlay ), + "eventPlay" ); + m_pChaiHandler->add( + chaiscript::fun< void, Entity::Player, uint32_t, uint32_t, uint32_t >( &Entity::Player::eventPlay ), + "eventPlay" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::eventActionStart ), "eventActionStart" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::eventItemActionStart ), "eventItemActionStart" ); m_pChaiHandler->add( chaiscript::fun( &Entity::Player::changePosition ), "changePos" ); @@ -172,7 +184,8 @@ int Core::Scripting::ScriptManager::init() std::set< std::string > chaiFiles; - loadDir( g_serverZone.getConfig()->getValue< std::string >( "Settings.General.ScriptPath", "../scripts/chai" ), chaiFiles ); + loadDir( g_serverZone.getConfig()->getValue< std::string >( "Settings.General.ScriptPath", "../scripts/chai" ), + chaiFiles ); uint16_t scriptCount = 0; uint16_t errorCount = 0; @@ -190,18 +203,14 @@ int Core::Scripting::ScriptManager::init() g_log.Log( LoggingSeverity::error, e.what() ); errorCount++; } - } - g_log.info( "\tloaded " + std::to_string( scriptCount ) + - " scripts, " + std::to_string( errorCount ) + " errors." ); + g_log.info( "\tloaded " + std::to_string( scriptCount ) + " scripts, " + std::to_string( errorCount ) + " errors." ); - std::function f = - m_pChaiHandler->eval< std::function >( "onFirstEnterWorld" ); + std::function< std::string( Entity::Player& ) > f = + m_pChaiHandler->eval< std::function< std::string( Entity::Player& ) > >( "onFirstEnterWorld" ); m_onFirstEnterWorld = f; - return true; } - diff --git a/src/servers/Server_Zone/ServerZone.cpp b/src/servers/Server_Zone/ServerZone.cpp index a863b06a..b5be9e4e 100644 --- a/src/servers/Server_Zone/ServerZone.cpp +++ b/src/servers/Server_Zone/ServerZone.cpp @@ -1,22 +1,21 @@ #include "ServerZone.h" -#include -#include #include +#include #include -#include #include +#include #include #include -#include -#include -#include #include +#include #include #include +#include +#include #include "Network/GameConnection.h" #include "Session.h" @@ -25,13 +24,13 @@ #include "DebugCommand/DebugCommandHandler.h" -#include "Script/ScriptManager.h" #include "Linkshell/LinkshellMgr.h" +#include "Script/ScriptManager.h" #include "Forwards.h" +#include #include #include -#include #include Core::Logger g_log; @@ -42,10 +41,10 @@ Core::ZoneMgr g_zoneMgr; Core::LinkshellMgr g_linkshellMgr; Core::Db::DbWorkerPool< Core::Db::CharaDbConnection > g_charaDb; -Core::ServerZone::ServerZone( const std::string& configPath ) - : m_configPath( configPath ), - m_bRunning( true ), - m_lastDBPingTime( 0 ) +Core::ServerZone::ServerZone( const std::string& configPath ) : + m_configPath( configPath ), + m_bRunning( true ), + m_lastDBPingTime( 0 ) { m_pConfig = XMLConfigPtr( new XMLConfig ); } @@ -64,8 +63,8 @@ size_t Core::ServerZone::getSessionCount() const return m_sessionMapById.size(); } -bool Core::ServerZone::registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, - uint32_t bnpcNameId, uint32_t modelId, std::string aiName ) +bool Core::ServerZone::registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, uint32_t bnpcNameId, + uint32_t modelId, std::string aiName ) { auto it = m_bnpcTemplates.find( templateName ); @@ -76,7 +75,8 @@ bool Core::ServerZone::registerBnpcTemplate( std::string templateName, uint32_t return false; } - Entity::BattleNpcTemplatePtr pNpcTemplate( new Entity::BattleNpcTemplate( templateName, bnpcBaseId, bnpcNameId, modelId, aiName ) ); + Entity::BattleNpcTemplatePtr pNpcTemplate( + new Entity::BattleNpcTemplate( templateName, bnpcBaseId, bnpcNameId, modelId, aiName ) ); m_bnpcTemplates[templateName] = pNpcTemplate; return true; @@ -86,7 +86,7 @@ Core::Entity::BattleNpcTemplatePtr Core::ServerZone::getBnpcTemplate( std::strin { auto it = m_bnpcTemplates.find( templateName ); - if (it != m_bnpcTemplates.end()) + if( it != m_bnpcTemplates.end() ) return nullptr; return it->second; @@ -102,7 +102,7 @@ bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] ) return false; } - std::vector args( argv + 1, argv + argc ); + std::vector< std::string > args( argv + 1, argv + argc ); for( uint32_t i = 0; i + 1 < args.size(); i += 2 ) { std::string arg( "" ); @@ -229,7 +229,7 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) std::vector< std::thread > thread_list; thread_list.emplace_back( std::thread( std::bind( &Network::Hive::Run, hive.get() ) ) ); - + g_log.info( "Server listening on port: " + std::to_string( m_port ) ); g_log.info( "Ready for connections..." ); @@ -239,12 +239,11 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) { thread_entry.join(); } - } void Core::ServerZone::printBanner() const { - g_log.info("===========================================================" ); + g_log.info( "===========================================================" ); g_log.info( "Sapphire Server Project " ); g_log.info( "Version: " + Version::VERSION ); g_log.info( "Git Hash: " + Version::GIT_HASH ); @@ -273,7 +272,6 @@ void Core::ServerZone::mainLoop() // else do it here. if( !session->getPlayer()->getCurrentZone() ) session->update(); - } } @@ -283,7 +281,6 @@ void Core::ServerZone::mainLoop() m_lastDBPingTime = currTime; } - auto it = this->m_sessionMapById.begin(); for( ; it != this->m_sessionMapById.end(); ) { @@ -297,7 +294,7 @@ void Core::ServerZone::mainLoop() it->second->close(); // if( it->second.unique() ) { - g_log.info("[" + std::to_string(it->second->getId() ) + "] Session removal" ); + g_log.info( "[" + std::to_string( it->second->getId() ) + "] Session removal" ); it = this->m_sessionMapById.erase( it ); removeSession( pPlayer->getName() ); continue; @@ -307,7 +304,7 @@ void Core::ServerZone::mainLoop() // remove sessions that simply timed out if( diff > 20 ) { - g_log.info("[" + std::to_string(it->second->getId() ) + "] Session time out" ); + g_log.info( "[" + std::to_string( it->second->getId() ) + "] Session time out" ); it->second->close(); // if( it->second.unique() ) { @@ -319,9 +316,7 @@ void Core::ServerZone::mainLoop() { ++it; } - } - } } @@ -341,7 +336,7 @@ bool Core::ServerZone::createSession( uint32_t sessionId ) g_log.info( "[" + session_id_str + "] Creating new session" ); - boost::shared_ptr newSession( new Session( sessionId ) ); + boost::shared_ptr< Session > newSession( new Session( sessionId ) ); m_sessionMapById[sessionId] = newSession; if( !newSession->loadPlayer() ) @@ -353,7 +348,6 @@ bool Core::ServerZone::createSession( uint32_t sessionId ) m_sessionMapByName[newSession->getPlayer()->getName()] = newSession; return true; - } void Core::ServerZone::removeSession( uint32_t sessionId ) @@ -372,7 +366,7 @@ void Core::ServerZone::updateSession( uint32_t id ) Core::SessionPtr Core::ServerZone::getSession( uint32_t id ) { - //std::lock_guard lock( m_sessionMutex ); + // std::lock_guard lock( m_sessionMutex ); auto it = m_sessionMapById.find( id ); @@ -384,12 +378,12 @@ Core::SessionPtr Core::ServerZone::getSession( uint32_t id ) Core::SessionPtr Core::ServerZone::getSession( std::string playerName ) { - //std::lock_guard lock( m_sessionMutex ); + // std::lock_guard lock( m_sessionMutex ); auto it = m_sessionMapByName.find( playerName ); - if (it != m_sessionMapByName.end()) - return (it->second); + if( it != m_sessionMapByName.end() ) + return ( it->second ); return nullptr; } @@ -412,4 +406,3 @@ bool Core::ServerZone::isRunning() const { return m_bRunning; } - diff --git a/src/servers/Server_Zone/ServerZone.h b/src/servers/Server_Zone/ServerZone.h index 724f031e..ed7d12d7 100644 --- a/src/servers/Server_Zone/ServerZone.h +++ b/src/servers/Server_Zone/ServerZone.h @@ -4,73 +4,69 @@ #include #include -#include #include +#include -#include "Forwards.h" #include "Actor/BattleNpcTemplate.h" +#include "Forwards.h" namespace Core { - class ServerZone - { - public: - ServerZone( const std::string& configPath ); - ~ServerZone(); +class ServerZone +{ +public: + ServerZone( const std::string& configPath ); + ~ServerZone(); - void run( int32_t argc, char* argv[] ); + void run( int32_t argc, char* argv[] ); - bool createSession( uint32_t sessionId ); - void removeSession( uint32_t sessionId ); - void removeSession( std::string playerName ); + bool createSession( uint32_t sessionId ); + void removeSession( uint32_t sessionId ); + void removeSession( std::string playerName ); - bool loadSettings( int32_t argc, char* argv[] ); + bool loadSettings( int32_t argc, char* argv[] ); - SessionPtr getSession( uint32_t id ); - SessionPtr getSession( std::string playerName ); - void updateSession( uint32_t id ); - void updateSession( std::string playerName ); + SessionPtr getSession( uint32_t id ); + SessionPtr getSession( std::string playerName ); + void updateSession( uint32_t id ); + void updateSession( std::string playerName ); - XMLConfigPtr getConfig() const; + XMLConfigPtr getConfig() const; - size_t getSessionCount() const; + size_t getSessionCount() const; - bool registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, - uint32_t bnpcNameId, uint32_t modelId, std::string aiName ); + bool registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, uint32_t bnpcNameId, uint32_t modelId, + std::string aiName ); - Entity::BattleNpcTemplatePtr getBnpcTemplate( std::string templateName ); + Entity::BattleNpcTemplatePtr getBnpcTemplate( std::string templateName ); - void mainLoop(); + void mainLoop(); - bool isRunning() const; + bool isRunning() const; - void printBanner() const; + void printBanner() const; +private: + uint16_t m_port; + std::string m_ip; + uint32_t m_lastDBPingTime; - private: + bool m_bRunning; - uint16_t m_port; - std::string m_ip; - uint32_t m_lastDBPingTime; + std::string m_configPath; - bool m_bRunning; + XMLConfigPtr m_pConfig; - std::string m_configPath; + std::mutex m_sessionMutex; - XMLConfigPtr m_pConfig; + std::map< uint32_t, SessionPtr > m_sessionMapById; + std::map< std::string, SessionPtr > m_sessionMapByName; - std::mutex m_sessionMutex; + std::map< uint32_t, uint32_t > m_zones; - std::map< uint32_t, SessionPtr > m_sessionMapById; - std::map< std::string, SessionPtr > m_sessionMapByName; + std::map< std::string, Entity::BattleNpcTemplatePtr > m_bnpcTemplates; +}; - std::map< uint32_t, uint32_t > m_zones; - - std::map< std::string, Entity::BattleNpcTemplatePtr > m_bnpcTemplates; - - }; - -} +} // namespace Core #endif - diff --git a/src/servers/Server_Zone/Session.cpp b/src/servers/Server_Zone/Session.cpp index 03965da3..bad2b879 100644 --- a/src/servers/Server_Zone/Session.cpp +++ b/src/servers/Server_Zone/Session.cpp @@ -1,22 +1,21 @@ #include -#include -#include #include "Network/GameConnection.h" #include "Session.h" +#include +#include #include "Actor/Player.h" -Core::Session::Session( uint32_t sessionId ) - : m_sessionId( sessionId ) - , m_lastDataTime( static_cast< uint32_t >( Util::getTimeSeconds() ) ) - , m_lastSqlTime( static_cast< uint32_t >( Util::getTimeSeconds() ) ) - , m_isValid( false ) +Core::Session::Session( uint32_t sessionId ) : + m_sessionId( sessionId ), + m_lastDataTime( static_cast< uint32_t >( Util::getTimeSeconds() ) ), + m_lastSqlTime( static_cast< uint32_t >( Util::getTimeSeconds() ) ), + m_isValid( false ) { // boost::posix_time::ptime now = boost::date_time::not_a_date_time; // now = boost::posix_time::microsec_clock::universal_time(); - } Core::Session::~Session() @@ -31,8 +30,8 @@ void Core::Session::setZoneConnection( Network::GameConnectionPtr pZoneCon ) void Core::Session::setChatConnection( Network::GameConnectionPtr pChatCon ) { - pChatCon->m_conType = Network::ConnectionType::Chat; - m_pChatConnection = pChatCon; + pChatCon->m_conType = Network::ConnectionType::Chat; + m_pChatConnection = pChatCon; } Core::Network::GameConnectionPtr Core::Session::getZoneConnection() const @@ -42,10 +41,9 @@ Core::Network::GameConnectionPtr Core::Session::getZoneConnection() const Core::Network::GameConnectionPtr Core::Session::getChatConnection() const { - return m_pChatConnection; + return m_pChatConnection; } - bool Core::Session::loadPlayer() { @@ -56,11 +54,10 @@ bool Core::Session::loadPlayer() m_isValid = false; return false; } - + m_isValid = true; return true; - } void Core::Session::close() @@ -112,11 +109,11 @@ void Core::Session::update() if( m_pZoneConnection ) { m_pZoneConnection->processInQueue(); - + // SESSION LOGIC m_pPlayer->update( Util::getTimeMs() ); - if( ( static_cast< uint32_t >( Util::getTimeSeconds() ) - static_cast< uint32_t >( getLastSqlTime() ) ) > 10 ) + if( ( static_cast< uint32_t >( Util::getTimeSeconds() ) - static_cast< uint32_t >( getLastSqlTime() ) ) > 10 ) { updateLastSqlTime(); m_pPlayer->updateSql(); @@ -127,14 +124,12 @@ void Core::Session::update() if( m_pChatConnection ) { - m_pChatConnection->processInQueue(); - m_pChatConnection->processOutQueue(); + m_pChatConnection->processInQueue(); + m_pChatConnection->processOutQueue(); } - } Core::Entity::PlayerPtr Core::Session::getPlayer() const { return m_pPlayer; } - diff --git a/src/servers/Server_Zone/Session.h b/src/servers/Server_Zone/Session.h index 7145c1e9..98856ce1 100644 --- a/src/servers/Server_Zone/Session.h +++ b/src/servers/Server_Zone/Session.h @@ -7,53 +7,51 @@ namespace Core { - class Session : public boost::enable_shared_from_this< Session > - { - public: - Session( uint32_t sessionId ); - ~Session(); +class Session : public boost::enable_shared_from_this< Session > +{ +public: + Session( uint32_t sessionId ); + ~Session(); - void setZoneConnection( Network::GameConnectionPtr zoneCon ); + void setZoneConnection( Network::GameConnectionPtr zoneCon ); - void setChatConnection( Network::GameConnectionPtr chatCon ); + void setChatConnection( Network::GameConnectionPtr chatCon ); - Network::GameConnectionPtr getZoneConnection() const; - Network::GameConnectionPtr getChatConnection() const; + Network::GameConnectionPtr getZoneConnection() const; + Network::GameConnectionPtr getChatConnection() const; - uint32_t getLastDataTime() const; - uint32_t getLastSqlTime() const; + uint32_t getLastDataTime() const; + uint32_t getLastSqlTime() const; - void updateLastDataTime(); - void updateLastSqlTime(); + void updateLastDataTime(); + void updateLastSqlTime(); - void close(); + void close(); - uint32_t getId() const; + uint32_t getId() const; - bool loadPlayer(); + bool loadPlayer(); - void update(); + void update(); - bool isValid() const; + bool isValid() const; - Entity::PlayerPtr getPlayer() const; + Entity::PlayerPtr getPlayer() const; - private: - uint32_t m_sessionId; +private: + uint32_t m_sessionId; - Entity::PlayerPtr m_pPlayer; + Entity::PlayerPtr m_pPlayer; - uint32_t m_lastDataTime; + uint32_t m_lastDataTime; - uint32_t m_lastSqlTime; - bool m_isValid; + uint32_t m_lastSqlTime; + bool m_isValid; - Network::GameConnectionPtr m_pZoneConnection; - Network::GameConnectionPtr m_pChatConnection; + Network::GameConnectionPtr m_pZoneConnection; + Network::GameConnectionPtr m_pChatConnection; +}; - }; - -} +} // namespace Core #endif - diff --git a/src/servers/Server_Zone/StatusEffect/StatusEffect.cpp b/src/servers/Server_Zone/StatusEffect/StatusEffect.cpp index 6a4d439c..b082cf19 100644 --- a/src/servers/Server_Zone/StatusEffect/StatusEffect.cpp +++ b/src/servers/Server_Zone/StatusEffect/StatusEffect.cpp @@ -1,16 +1,15 @@ #include -#include -#include #include -#include +#include +#include -#include #include +#include #include "Actor/Actor.h" -#include "StatusEffect.h" #include "Script/ScriptManager.h" +#include "StatusEffect.h" extern Core::Logger g_log; extern Core::Data::ExdData g_exdData; @@ -20,20 +19,19 @@ using namespace Core::Network::Packets; using namespace Core::Network::Packets::Server; extern Core::Scripting::ScriptManager g_scriptMgr; - Core::StatusEffect::StatusEffect::StatusEffect( uint32_t id, Entity::ActorPtr sourceActor, Entity::ActorPtr targetActor, - uint32_t duration, uint32_t tickRate ) - : m_id( id ) - , m_sourceActor( sourceActor ) - , m_targetActor( targetActor ) - , m_duration( duration ) - , m_startTime( 0 ) - , m_tickRate( tickRate ) - , m_lastTick( 0 ) + uint32_t duration, uint32_t tickRate ) : + m_id( id ), + m_sourceActor( sourceActor ), + m_targetActor( targetActor ), + m_duration( duration ), + m_startTime( 0 ), + m_tickRate( tickRate ), + m_lastTick( 0 ) { auto& entry = g_exdData.m_statusEffectInfoMap[id]; m_name = entry.name; - + std::replace( m_name.begin(), m_name.end(), ' ', '_' ); std::replace( m_name.begin(), m_name.end(), ':', '_' ); std::replace( m_name.begin(), m_name.end(), '&', '_' ); @@ -45,7 +43,6 @@ Core::StatusEffect::StatusEffect::StatusEffect( uint32_t id, Entity::ActorPtr so boost::erase_all( m_name, ")" ); } - Core::StatusEffect::StatusEffect::~StatusEffect() { } @@ -55,7 +52,7 @@ void Core::StatusEffect::StatusEffect::registerTickEffect( uint8_t type, uint32_ m_currTickEffect = std::make_pair( type, param ); } -std::pair< uint8_t, uint32_t> Core::StatusEffect::StatusEffect::getTickEffect() +std::pair< uint8_t, uint32_t > Core::StatusEffect::StatusEffect::getTickEffect() { auto thisTick = m_currTickEffect; m_currTickEffect = std::make_pair( 0, 0 ); @@ -90,20 +87,20 @@ void Core::StatusEffect::StatusEffect::applyStatus() // this is only right when an action is being used by the player // else you probably need to use an actorcontrol - //GamePacketNew< FFXIVIpcEffect > effectPacket( m_sourceActor->getId() ); - //effectPacket.data().targetId = m_sourceActor->getId(); - //effectPacket.data().actionAnimationId = 3; - //effectPacket.data().unknown_3 = 1; - //effectPacket.data().actionTextId = 3; - //effectPacket.data().unknown_5 = 1; - //effectPacket.data().unknown_6 = 321; - //effectPacket.data().rotation = ( uint16_t ) ( 0x8000 * ( ( m_sourceActor->getPos().getR() + 3.1415926 ) ) / 3.1415926 ); - //effectPacket.data().effectTargetId = m_sourceActor->getId(); - //effectPacket.data().effects[4].unknown_1 = 17; - //effectPacket.data().effects[4].bonusPercent = 30; - //effectPacket.data().effects[4].param1 = m_id; - //effectPacket.data().effects[4].unknown_5 = 0x80; - //m_sourceActor->sendToInRangeSet( effectPacket, true ); + // GamePacketNew< FFXIVIpcEffect > effectPacket( m_sourceActor->getId() ); + // effectPacket.data().targetId = m_sourceActor->getId(); + // effectPacket.data().actionAnimationId = 3; + // effectPacket.data().unknown_3 = 1; + // effectPacket.data().actionTextId = 3; + // effectPacket.data().unknown_5 = 1; + // effectPacket.data().unknown_6 = 321; + // effectPacket.data().rotation = ( uint16_t ) ( 0x8000 * ( ( m_sourceActor->getPos().getR() + 3.1415926 ) ) + // / 3.1415926 ); effectPacket.data().effectTargetId = m_sourceActor->getId(); + // effectPacket.data().effects[4].unknown_1 = 17; + // effectPacket.data().effects[4].bonusPercent = 30; + // effectPacket.data().effects[4].param1 = m_id; + // effectPacket.data().effects[4].unknown_5 = 0x80; + // m_sourceActor->sendToInRangeSet( effectPacket, true ); g_log.debug( "StatusEffect applied: " + m_name ); g_scriptMgr.onStatusReceive( m_targetActor, m_id ); diff --git a/src/servers/Server_Zone/StatusEffect/StatusEffect.h b/src/servers/Server_Zone/StatusEffect/StatusEffect.h index 070bfb44..2c93e9d9 100644 --- a/src/servers/Server_Zone/StatusEffect/StatusEffect.h +++ b/src/servers/Server_Zone/StatusEffect/StatusEffect.h @@ -5,53 +5,49 @@ #include "Forwards.h" -namespace Core -{ -namespace StatusEffect -{ +namespace Core { +namespace StatusEffect { + class StatusEffect + { + public: + StatusEffect( uint32_t id, Entity::ActorPtr sourceActor, Entity::ActorPtr targetActor, uint32_t duration, + uint32_t tickRate ); -class StatusEffect -{ -public: - StatusEffect( uint32_t id, Entity::ActorPtr sourceActor, Entity::ActorPtr targetActor, - uint32_t duration, uint32_t tickRate ); + ~StatusEffect(); - ~StatusEffect(); + void onTick(); + void applyStatus(); + void removeStatus(); - void onTick(); - void applyStatus(); - void removeStatus(); + uint32_t getId() const; + uint32_t getDuration() const; + uint32_t getTickRate() const; + uint32_t getSrcActorId() const; + uint32_t getTargetActorId() const; + uint64_t getLastTickMs() const; + uint64_t getStartTimeMs() const; + uint16_t getParam() const; + void setLastTick( uint64_t lastTick ); + void setParam( uint16_t param ); + void registerTickEffect( uint8_t type, uint32_t param ); + std::pair< uint8_t, uint32_t > getTickEffect(); + const std::string& getName() const; - uint32_t getId() const; - uint32_t getDuration() const; - uint32_t getTickRate() const; - uint32_t getSrcActorId() const; - uint32_t getTargetActorId() const; - uint64_t getLastTickMs() const; - uint64_t getStartTimeMs() const; - uint16_t getParam() const; - void setLastTick( uint64_t lastTick ); - void setParam( uint16_t param ); - void registerTickEffect( uint8_t type, uint32_t param ); - std::pair< uint8_t, uint32_t> getTickEffect(); - const std::string& getName() const; + private: + uint32_t m_id; + Entity::ActorPtr m_sourceActor; + Entity::ActorPtr m_targetActor; + uint32_t m_duration; + uint64_t m_startTime; + uint32_t m_tickRate; + uint64_t m_lastTick; + uint16_t m_param; + std::string m_name; + std::pair< uint8_t, uint32_t > m_currTickEffect; + }; -private: - uint32_t m_id; - Entity::ActorPtr m_sourceActor; - Entity::ActorPtr m_targetActor; - uint32_t m_duration; - uint64_t m_startTime; - uint32_t m_tickRate; - uint64_t m_lastTick; - uint16_t m_param; - std::string m_name; - std::pair< uint8_t, uint32_t> m_currTickEffect; - -}; - -} -} +} // namespace StatusEffect +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Zone/Cell.cpp b/src/servers/Server_Zone/Zone/Cell.cpp index 9ee35e31..0b1f5281 100644 --- a/src/servers/Server_Zone/Zone/Cell.cpp +++ b/src/servers/Server_Zone/Zone/Cell.cpp @@ -5,167 +5,149 @@ #include "Forwards.h" #include "Zone.h" - // TODO: the entire zone / areahandling is a bit outdated ( in parts i used this for the 1.0 iteration ) // likely this could be greatly improved or redone -namespace Core +namespace Core { + +Cell::Cell() : m_bActive( false ), m_bLoaded( false ), m_playerCount( 0 ), m_bUnloadPending( false ) +{ + m_bForcedActive = false; +} + +Cell::~Cell() +{ + removeActors(); +} + +void Cell::init( uint32_t x, uint32_t y, ZonePtr pZone ) +{ + // Console->outDebOnly("[Region:%X] Initializing a new cell[%i/%i]", pRegion->getId(), x, y ); + m_pZone = pZone; + m_posX = x; + m_posY = y; + + m_actors.clear(); +} + +void Cell::loadActors( CellCache* pCC ) { + m_bLoaded = true; + assert( pCC ); - Cell::Cell() - : m_bActive(false) - , m_bLoaded(false) - , m_playerCount(0) - , m_bUnloadPending(false) - { - m_bForcedActive = false; - } - - Cell::~Cell() - { - removeActors(); - } - - void Cell::init(uint32_t x, uint32_t y, ZonePtr pZone) - { - //Console->outDebOnly("[Region:%X] Initializing a new cell[%i/%i]", pRegion->getId(), x, y ); - m_pZone = pZone; - m_posX = x; - m_posY = y; - - m_actors.clear(); - } - - void Cell::loadActors(CellCache* pCC) + for( auto entry : pCC->battleNpcCache ) { - m_bLoaded = true; - assert(pCC); - - for( auto entry : pCC->battleNpcCache ) - { - - entry->setCurrentZone( m_pZone ); - m_pZone->pushActor( entry ); - - } + entry->setCurrentZone( m_pZone ); + m_pZone->pushActor( entry ); } - - void Cell::addActor(Entity::ActorPtr pAct) - { - if(pAct->isPlayer()) - { - //Console->outDebOnly("[Region:%X] Adding player %i to cell[%i/%i]", m_pZone->getId(), pAct->getId(), m_posX, m_posY); - ++m_playerCount; - } - - m_actors.insert(pAct); - } - - void Cell::removeActor(Entity::ActorPtr pAct) - { - if(pAct->isPlayer()) - { - //->outDebOnly("[Region:%X] Removing player %i from cell[%i/%i]", m_pZone->getId(), pAct->getId(), m_posX, m_posY); - --m_playerCount; - } - - m_actors.erase(pAct); - } - - void Cell::setActivity(bool state) - { - if(!m_bActive && state) - { - // Move all objects to active set. - for(auto itr = m_actors.begin(); itr != m_actors.end(); ++itr) - { - - } - - if(m_bUnloadPending) - { - cancelPendingUnload(); - } - - } - else if(m_bActive && !state) - { - // Move all objects from active set. - for(auto itr = m_actors.begin(); itr != m_actors.end(); ++itr) - { - - } - - - } - - m_bActive = state; - - } - void Cell::removeActors() - { - //uint32_t ltime = getMSTime(); - - m_actors.clear(); - - //This time it's simpler! We just remove everything - Entity::ActorPtr pAct; //do this outside the loop! - for(auto itr = m_actors.begin(); itr != m_actors.end();) - { - pAct = (*itr); - itr++; - - if(!pAct) - { - continue; - } - - if(m_bUnloadPending) - { - - } - - } - - m_playerCount = 0; - m_bLoaded = false; - } - - - - void Cell::queueUnloadPending() - { - if(m_bUnloadPending) - { - return; - } - - m_bUnloadPending = true; - - } - - void Cell::cancelPendingUnload() - { - - if(!m_bUnloadPending) - { - return; - } - - } - - void Cell::unload() - { - - assert(m_bUnloadPending); - if(m_bActive) - { - return; - } - - removeActors(); - m_bUnloadPending = false; - } - } + +void Cell::addActor( Entity::ActorPtr pAct ) +{ + if( pAct->isPlayer() ) + { + // Console->outDebOnly("[Region:%X] Adding player %i to cell[%i/%i]", m_pZone->getId(), pAct->getId(), m_posX, + // m_posY); + ++m_playerCount; + } + + m_actors.insert( pAct ); +} + +void Cell::removeActor( Entity::ActorPtr pAct ) +{ + if( pAct->isPlayer() ) + { + //->outDebOnly("[Region:%X] Removing player %i from cell[%i/%i]", m_pZone->getId(), pAct->getId(), m_posX, + // m_posY); + --m_playerCount; + } + + m_actors.erase( pAct ); +} + +void Cell::setActivity( bool state ) +{ + if( !m_bActive && state ) + { + // Move all objects to active set. + for( auto itr = m_actors.begin(); itr != m_actors.end(); ++itr ) + { + } + + if( m_bUnloadPending ) + { + cancelPendingUnload(); + } + } + else if( m_bActive && !state ) + { + // Move all objects from active set. + for( auto itr = m_actors.begin(); itr != m_actors.end(); ++itr ) + { + } + } + + m_bActive = state; +} +void Cell::removeActors() +{ + // uint32_t ltime = getMSTime(); + + m_actors.clear(); + + // This time it's simpler! We just remove everything + Entity::ActorPtr pAct; // do this outside the loop! + for( auto itr = m_actors.begin(); itr != m_actors.end(); ) + { + pAct = ( *itr ); + itr++; + + if( !pAct ) + { + continue; + } + + if( m_bUnloadPending ) + { + } + } + + m_playerCount = 0; + m_bLoaded = false; +} + +void Cell::queueUnloadPending() +{ + if( m_bUnloadPending ) + { + return; + } + + m_bUnloadPending = true; +} + +void Cell::cancelPendingUnload() +{ + + if( !m_bUnloadPending ) + { + return; + } +} + +void Cell::unload() +{ + + assert( m_bUnloadPending ); + if( m_bActive ) + { + return; + } + + removeActors(); + m_bUnloadPending = false; +} + +} // namespace Core diff --git a/src/servers/Server_Zone/Zone/Cell.h b/src/servers/Server_Zone/Zone/Cell.h index ede57a6f..58b4f9e0 100644 --- a/src/servers/Server_Zone/Zone/Cell.h +++ b/src/servers/Server_Zone/Zone/Cell.h @@ -9,120 +9,77 @@ namespace Core { +struct CellCache +{ + std::vector< Entity::BattleNpcPtr > battleNpcCache; +}; - struct CellCache - { - std::vector< Entity::BattleNpcPtr > battleNpcCache; - }; +typedef std::set< Entity::ActorPtr > ActorSet; - typedef std::set< Entity::ActorPtr > ActorSet; +class Cell +{ + friend class Zone; - class Cell - { - friend class Zone; +private: + bool m_bForcedActive; + uint16_t m_posX; + uint16_t m_posY; + ActorSet m_actors; + bool m_bActive; + bool m_bLoaded; + bool m_bUnloadPending; - private: - bool m_bForcedActive; - uint16_t m_posX; - uint16_t m_posY; - ActorSet m_actors; - bool m_bActive; - bool m_bLoaded; - bool m_bUnloadPending; + uint16_t m_playerCount; + ZonePtr m_pZone; - uint16_t m_playerCount; - ZonePtr m_pZone; +public: + Cell(); + ~Cell(); - public: - Cell(); - ~Cell(); + void init( uint32_t x, uint32_t y, ZonePtr pZone ); - void init(uint32_t x, uint32_t y, ZonePtr pZone); + void addActor( Entity::ActorPtr pAct ); - void addActor(Entity::ActorPtr pAct); + void removeActor( Entity::ActorPtr pAct ); - void removeActor(Entity::ActorPtr pAct); + void loadActors( CellCache* pCC ); - void loadActors(CellCache* pCC); + bool hasActor( Entity::ActorPtr pAct ) { return ( m_actors.find( pAct ) != m_actors.end() ); } - bool hasActor(Entity::ActorPtr pAct) - { - return (m_actors.find(pAct) != m_actors.end()); - } + bool hasPlayers() const { return ( ( m_playerCount > 0 ) ? true : false ); } - bool hasPlayers() const - { - return ((m_playerCount > 0) ? true : false); - } + size_t getActorCount() const { return m_actors.size(); } - size_t getActorCount() const - { - return m_actors.size(); - } + void removeActors(); - void removeActors(); + ActorSet::iterator begin() { return m_actors.begin(); } - ActorSet::iterator begin() - { - return m_actors.begin(); - } + ActorSet::iterator end() { return m_actors.end(); } - ActorSet::iterator end() - { - return m_actors.end(); - } + void setActivity( bool state ); - void setActivity(bool state); + bool isActive() const { return m_bActive; } - bool isActive() const - { - return m_bActive; - } + bool isLoaded() const { return m_bLoaded; } - bool isLoaded() const - { - return m_bLoaded; - } + uint32_t getPlayerCount() const { return m_playerCount; } - uint32_t getPlayerCount() const - { - return m_playerCount; - } + bool isUnloadPending() const { return m_bUnloadPending; } - bool isUnloadPending() const - { - return m_bUnloadPending; - } + void setUnloadPending( bool up ) { m_bUnloadPending = up; } - void setUnloadPending(bool up) - { - m_bUnloadPending = up; - } + void queueUnloadPending(); + void cancelPendingUnload(); + void unload(); - void queueUnloadPending(); - void cancelPendingUnload(); - void unload(); + void setPermanentActivity( bool val ) { m_bForcedActive = val; } - void setPermanentActivity(bool val) - { - m_bForcedActive = val; - } + bool isForcedActive() const { return m_bForcedActive; } - bool isForcedActive() const - { - return m_bForcedActive; - } + uint16_t getPosX() const { return m_posX; } - uint16_t getPosX() const - { - return m_posX; - } + uint16_t getPosY() const { return m_posY; } +}; - uint16_t getPosY() const - { - return m_posY; - } - }; - -} +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Zone/CellHandler.h b/src/servers/Server_Zone/Zone/CellHandler.h index 253f4823..a27eee90 100644 --- a/src/servers/Server_Zone/Zone/CellHandler.h +++ b/src/servers/Server_Zone/Zone/CellHandler.h @@ -3,23 +3,23 @@ #define TilesCount 32 #define TileSize 250.0f -#define _minY (-TilesCount*TileSize/2) -#define _minX (-TilesCount*TileSize/2) +#define _minY ( -TilesCount * TileSize / 2 ) +#define _minX ( -TilesCount * TileSize / 2 ) -#define _maxY (TilesCount*TileSize/2) -#define _maxX (TilesCount*TileSize/2) +#define _maxY ( TilesCount * TileSize / 2 ) +#define _maxX ( TilesCount * TileSize / 2 ) #define CellsPerTile 4 -#define _cellSize (TileSize/CellsPerTile) -#define _sizeX (TilesCount*CellsPerTile) -#define _sizeY (TilesCount*CellsPerTile) +#define _cellSize ( TileSize / CellsPerTile ) +#define _sizeX ( TilesCount * CellsPerTile ) +#define _sizeY ( TilesCount * CellsPerTile ) -#define GetRelatCoord(Coord,CellCoord) ((_maxX-Coord)-CellCoord*_cellSize) +#define GetRelatCoord( Coord, CellCoord ) ( ( _maxX - Coord ) - CellCoord * _cellSize ) namespace Core { class Zone; -template +template< class T > class CellHandler { public: @@ -32,10 +32,7 @@ public: T* createByCoords( float x, float y ); void remove( uint32_t x, uint32_t y ); - bool allocated( uint32_t x, uint32_t y ) - { - return m_pCells[x][y] != nullptr; - } + bool allocated( uint32_t x, uint32_t y ) { return m_pCells[x][y] != nullptr; } static uint32_t getPosX( float x ); static uint32_t getPosY( float y ); @@ -43,21 +40,18 @@ public: protected: void _init(); - - T *** m_pCells; - + T*** m_pCells; }; -template -CellHandler::CellHandler() +template< class T > +CellHandler< T >::CellHandler() { _init(); } - -template -void CellHandler::_init() +template< class T > +void CellHandler< T >::_init() { m_pCells = new T**[_sizeX]; @@ -66,11 +60,10 @@ void CellHandler::_init() { m_pCells[i] = nullptr; } - } -template -CellHandler::~CellHandler() +template< class T > +CellHandler< T >::~CellHandler() { if( m_pCells ) { @@ -94,8 +87,8 @@ CellHandler::~CellHandler() } } -template -T* CellHandler::create( uint32_t x, uint32_t y ) +template< class T > +T* CellHandler< T >::create( uint32_t x, uint32_t y ) { if( x >= _sizeX || y >= _sizeY ) { @@ -105,25 +98,25 @@ T* CellHandler::create( uint32_t x, uint32_t y ) if( !m_pCells[x] ) { m_pCells[x] = new T*[_sizeY]; - memset( m_pCells[x], 0, sizeof( T* )*_sizeY ); + memset( m_pCells[x], 0, sizeof( T* ) * _sizeY ); } assert( m_pCells[x][y] == nullptr ); - T *cls = new T; + T* cls = new T; m_pCells[x][y] = cls; return cls; } -template -T* CellHandler::createByCoords( float x, float y ) +template< class T > +T* CellHandler< T >::createByCoords( float x, float y ) { return create( getPosX( x ), getPosY( y ) ); } -template -void CellHandler::remove( uint32_t x, uint32_t y ) +template< class T > +void CellHandler< T >::remove( uint32_t x, uint32_t y ) { if( x >= _sizeX || y >= _sizeY ) { @@ -137,14 +130,14 @@ void CellHandler::remove( uint32_t x, uint32_t y ) assert( m_pCells[x][y] != nullptr ); - T *cls = m_pCells[x][y]; + T* cls = m_pCells[x][y]; m_pCells[x][y] = nullptr; delete cls; } -template -T* CellHandler::getCell( uint32_t x, uint32_t y ) +template< class T > +T* CellHandler< T >::getCell( uint32_t x, uint32_t y ) { if( !m_pCells[x] ) { @@ -154,25 +147,25 @@ T* CellHandler::getCell( uint32_t x, uint32_t y ) return m_pCells[x][y]; } -template -T* CellHandler::getCellByCoords( float x, float y ) +template< class T > +T* CellHandler< T >::getCellByCoords( float x, float y ) { return getCell( getPosX( x ), getPosY( y ) ); } -template -uint32_t CellHandler::getPosX( float x ) +template< class T > +uint32_t CellHandler< T >::getPosX( float x ) { assert( ( x >= _minX ) && ( x <= _maxX ) ); - return ( uint32_t ) ( ( _maxX - x ) / _cellSize ); + return ( uint32_t )( ( _maxX - x ) / _cellSize ); } -template -uint32_t CellHandler::getPosY( float y ) +template< class T > +uint32_t CellHandler< T >::getPosY( float y ) { assert( ( y >= _minY ) && ( y <= _maxY ) ); - return ( uint32_t ) ( ( _maxY - y ) / _cellSize ); + return ( uint32_t )( ( _maxY - y ) / _cellSize ); } -} +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Zone/Zone.cpp b/src/servers/Server_Zone/Zone/Zone.cpp index 9da356eb..99da2c0e 100644 --- a/src/servers/Server_Zone/Zone/Zone.cpp +++ b/src/servers/Server_Zone/Zone/Zone.cpp @@ -1,30 +1,30 @@ #include #include +#include +#include #include -#include -#include +#include #include #include -#include -#include -#include #include -#include +#include +#include +#include #include "Zone.h" #include "ZoneMgr.h" -#include "Session.h" #include "Actor/Actor.h" -#include "Actor/Player.h" #include "Actor/BattleNpc.h" +#include "Actor/Player.h" +#include "Session.h" #include "Forwards.h" #include "Network/GameConnection.h" -#include "ServerZone.h" #include "Script/ScriptManager.h" +#include "ServerZone.h" #include "CellHandler.h" @@ -38,22 +38,22 @@ extern Core::Scripting::ScriptManager g_scriptMgr; namespace Core { /** -* \brief -*/ -Zone::Zone() - : m_zoneId( 0 ) - , m_layoutId( 0 ) - , m_bPrivate( false ) - , m_type( Common::RegionType::normal ) - , m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) ) - , m_weatherOverride( 0 ) - , m_lastMobUpdate( 0 ) + * \brief + */ +Zone::Zone() : + m_zoneId( 0 ), + m_layoutId( 0 ), + m_bPrivate( false ), + m_type( Common::RegionType::normal ), + m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) ), + m_weatherOverride( 0 ), + m_lastMobUpdate( 0 ) { } -Zone::Zone( uint16_t zoneId, uint32_t layoutId, std::string name, std::string interName, bool bPrivate = false ) - : m_type( Common::RegionType::normal ) - , m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) ) +Zone::Zone( uint16_t zoneId, uint32_t layoutId, std::string name, std::string interName, bool bPrivate = false ) : + m_type( Common::RegionType::normal ), + m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) ) { m_layoutId = layoutId; @@ -117,12 +117,12 @@ CellCache* Zone::getCellCacheAndCreate( uint32_t cellx, uint32_t celly ) if( m_pCellCache[cellx] == nullptr ) { m_pCellCache[cellx] = new CellCache*[_sizeY]; - memset(m_pCellCache[cellx], 0, sizeof( CellCache* ) * _sizeY); + memset( m_pCellCache[cellx], 0, sizeof( CellCache* ) * _sizeY ); } if( m_pCellCache[cellx][celly] == nullptr ) { - //m_pCellCache[cellx][celly] = new CellCache; + // m_pCellCache[cellx][celly] = new CellCache; } return m_pCellCache[cellx][celly]; @@ -150,7 +150,8 @@ void Zone::loadCellCache() "Look," "Models," "type " - "FROM battlenpc WHERE ZoneId = " + std::to_string( getId() ) + ";" ); + "FROM battlenpc WHERE ZoneId = " + + std::to_string( getId() ) + ";" ); std::vector< Entity::BattleNpcPtr > cache; @@ -179,14 +180,12 @@ void Zone::loadCellCache() pos.x = posX; pos.y = posY; pos.z = posZ; - Entity::BattleNpcPtr pBNpc( new Entity::BattleNpc( modelId, nameId, pos, - sizeId, type, level, behaviour, mobType ) ); + Entity::BattleNpcPtr pBNpc( + new Entity::BattleNpc( modelId, nameId, pos, sizeId, type, level, behaviour, mobType ) ); pBNpc->setRotation( static_cast< float >( rotation ) ); cache.push_back( pBNpc ); } - - for( auto entry : cache ) { // get cell position @@ -206,12 +205,11 @@ void Zone::loadCellCache() // add the populace cache object to the cells list m_pCellCache[cellX][cellY]->battleNpcCache.push_back( entry ); } - } uint8_t Zone::getNextWeather() { - auto zoneInfo = g_exdData.m_zoneInfoMap[ getLayoutId() ]; + auto zoneInfo = g_exdData.m_zoneInfoMap[getLayoutId()]; uint32_t unixTime = static_cast< uint32_t >( time( nullptr ) ); // Get Eorzea hour for weather start @@ -227,7 +225,7 @@ uint8_t Zone::getNextWeather() uint32_t step1 = ( calcBase << 0xB ) ^ calcBase; uint32_t step2 = ( step1 >> 8 ) ^ step1; - uint8_t rate = static_cast< uint8_t >(step2 % 0x64); + uint8_t rate = static_cast< uint8_t >( step2 % 0x64 ); for( auto entry : zoneInfo.weather_rate_map ) { @@ -288,7 +286,6 @@ void Zone::pushActor( Entity::ActorPtr pActor ) m_sessionSet.insert( pSession ); m_playerMap[pPlayer->getId()] = pPlayer; updateCellActivity( cx, cy, 2 ); - } else if( pActor->isMob() ) { @@ -296,9 +293,7 @@ void Zone::pushActor( Entity::ActorPtr pActor ) Entity::BattleNpcPtr pBNpc = pActor->getAsBattleNpc(); m_BattleNpcMap[pBNpc->getId()] = pBNpc; pBNpc->setPosition( pBNpc->getPos() ); - } - } void Zone::removeActor( Entity::ActorPtr pActor ) @@ -315,15 +310,14 @@ void Zone::removeActor( Entity::ActorPtr pActor ) g_log.debug( "[Zone:" + m_zoneCode + "] Removing player [" + std::to_string( pActor->getId() ) + "]" ); // If it's a player and he's inside boundaries - update his nearby cells - if( pActor->getPos().x <= _maxX && pActor->getPos().x >= _minX && - pActor->getPos().z <= _maxY && pActor->getPos().z >= _minY ) + if( pActor->getPos().x <= _maxX && pActor->getPos().x >= _minX && pActor->getPos().z <= _maxY && + pActor->getPos().z >= _minY ) { uint32_t x = getPosX( pActor->getPos().x ); uint32_t y = getPosY( pActor->getPos().z ); updateCellActivity( x, y, 3 ); } m_playerMap.erase( pActor->getId() ); - } else if( pActor->isMob() ) m_BattleNpcMap.erase( pActor->getId() ); @@ -341,19 +335,16 @@ void Zone::removeActor( Entity::ActorPtr pActor ) } } pActor->clearInRangeSet(); - } -void Zone::queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, Network::Packets::GamePacketPtr pPacketEntry ) +void Zone::queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, + Network::Packets::GamePacketPtr pPacketEntry ) { for( auto it = m_playerMap.begin(); it != m_playerMap.end(); ++it ) { - float distance = Math::Util::distance( sourcePlayer.getPos().x, - sourcePlayer.getPos().y, - sourcePlayer.getPos().z, - ( *it ).second->getPos().x, - ( *it ).second->getPos().y, - ( *it ).second->getPos().z ); + float distance = + Math::Util::distance( sourcePlayer.getPos().x, sourcePlayer.getPos().y, sourcePlayer.getPos().z, + ( *it ).second->getPos().x, ( *it ).second->getPos().y, ( *it ).second->getPos().z ); if( ( distance < range ) && sourcePlayer.getId() != ( *it ).second->getId() ) { @@ -402,9 +393,9 @@ std::size_t Zone::getPopCount() const bool Zone::checkWeather() { - if ( m_weatherOverride != 0 ) + if( m_weatherOverride != 0 ) { - if ( m_weatherOverride != m_currentWeather ) + if( m_weatherOverride != m_currentWeather ) { m_currentWeather = m_weatherOverride; g_log.debug( "[Zone:" + m_zoneCode + "] overriding weather to : " + std::to_string( m_weatherOverride ) ); @@ -414,7 +405,7 @@ bool Zone::checkWeather() else { auto nextWeather = getNextWeather(); - if ( nextWeather != m_currentWeather ) + if( nextWeather != m_currentWeather ) { m_currentWeather = nextWeather; g_log.debug( "[Zone:" + m_zoneCode + "] changing weather to : " + std::to_string( nextWeather ) ); @@ -451,11 +442,10 @@ void Zone::updateBnpcs( int64_t tickCount ) } } - for( auto entry : m_BattleNpcMap ) { Entity::BattleNpcPtr pBNpc = entry.second; - + if( !pBNpc ) continue; @@ -465,9 +455,8 @@ void Zone::updateBnpcs( int64_t tickCount ) m_BattleNpcDeadMap.insert( pBNpc ); break; } - - pBNpc->update( tickCount ); + pBNpc->update( tickCount ); } } } @@ -479,13 +468,13 @@ bool Zone::runZoneLogic() bool changedWeather = checkWeather(); auto it = m_sessionSet.begin(); - + // update sessions in this zone for( ; it != m_sessionSet.end(); ) { auto pSession = ( *it ); - + if( !pSession ) { it = m_sessionSet.erase( it ); @@ -493,7 +482,8 @@ bool Zone::runZoneLogic() } // this session is not linked to this area anymore, remove it from zone session list - if( ( !pSession->getPlayer()->getCurrentZone() ) || ( pSession->getPlayer()->getCurrentZone() != shared_from_this() ) ) + if( ( !pSession->getPlayer()->getCurrentZone() ) || + ( pSession->getPlayer()->getCurrentZone() != shared_from_this() ) ) { g_log.debug( "[Zone:" + m_zoneCode + "] removing session " + std::to_string( pSession->getId() ) ); @@ -506,8 +496,8 @@ bool Zone::runZoneLogic() if( changedWeather ) { - Network::Packets::ZoneChannelPacket< Network::Packets::Server::FFXIVIpcWeatherChange > - weatherChangePacket( pSession->getPlayer()->getId() ); + Network::Packets::ZoneChannelPacket< Network::Packets::Server::FFXIVIpcWeatherChange > weatherChangePacket( + pSession->getPlayer()->getId() ); weatherChangePacket.data().weatherId = m_currentWeather; weatherChangePacket.data().delay = 5.0f; pSession->getPlayer()->queuePacket( weatherChangePacket ); @@ -576,21 +566,21 @@ void Zone::updateCellActivity( uint32_t x, uint32_t y, int32_t radius ) assert( !pCell->isLoaded() ); - CellCache * pCC = getCellCacheAndCreate( posX, posY ); + CellCache* pCC = getCellCacheAndCreate( posX, posY ); if( pCC ) pCell->loadActors( pCC ); } } else { - //Cell is now active + // Cell is now active if( isCellActive( posX, posY ) && !pCell->isActive() ) { pCell->setActivity( true ); if( !pCell->isLoaded() ) { - CellCache * pCC = getCellCacheAndCreate( posX, posY ); + CellCache* pCC = getCellCacheAndCreate( posX, posY ); if( pCC ) pCell->loadActors( pCC ); } @@ -613,17 +603,13 @@ void Zone::changeActorPosition( Entity::ActorPtr pActor ) Entity::ActorPtr pCurAct; float fRange = 70.0f; - for( auto iter = pActor->m_inRangeActors.begin(); iter != pActor->m_inRangeActors.end();) + for( auto iter = pActor->m_inRangeActors.begin(); iter != pActor->m_inRangeActors.end(); ) { pCurAct = *iter; auto iter2 = iter++; - float distance = Math::Util::distance( pCurAct->getPos().x, - pCurAct->getPos().y, - pCurAct->getPos().z, - pActor->getPos().x, - pActor->getPos().y, - pActor->getPos().z ); + float distance = Math::Util::distance( pCurAct->getPos().x, pCurAct->getPos().y, pCurAct->getPos().z, + pActor->getPos().x, pActor->getPos().y, pActor->getPos().z ); if( fRange > 0.0f && distance > fRange ) { @@ -634,8 +620,8 @@ void Zone::changeActorPosition( Entity::ActorPtr pActor ) pActor->removeInRangeActor( *iter2 ); - // @TODO FIXME! - // this break is more or less a hack, iteration will break otherwise after removing + // @TODO FIXME! + // this break is more or less a hack, iteration will break otherwise after removing break; } } @@ -676,8 +662,8 @@ void Zone::changeActorPosition( Entity::ActorPtr pActor ) if( pOldCell != nullptr ) { // only do the second check if theres -/+ 2 difference - if( abs( ( int32_t ) cellX - ( int32_t ) pOldCell->m_posX ) > 2 || - abs( ( int32_t ) cellY - ( int32_t ) pOldCell->m_posY ) > 2 ) + if( abs( (int32_t)cellX - (int32_t)pOldCell->m_posX ) > 2 || + abs( (int32_t)cellY - (int32_t)pOldCell->m_posY ) > 2 ) updateCellActivity( pOldCell->m_posX, pOldCell->m_posY, 2 ); } } @@ -701,7 +687,6 @@ void Zone::changeActorPosition( Entity::ActorPtr pActor ) } } - void Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell ) { if( pCell == nullptr ) @@ -721,12 +706,8 @@ void Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell ) if( !pCurAct ) continue; - float distance = Math::Util::distance( pCurAct->getPos().x, - pCurAct->getPos().y, - pCurAct->getPos().z, - pActor->getPos().x, - pActor->getPos().y, - pActor->getPos().z ); + float distance = Math::Util::distance( pCurAct->getPos().x, pCurAct->getPos().y, pCurAct->getPos().z, + pActor->getPos().x, pActor->getPos().y, pActor->getPos().z ); // Add if we are not ourself and range == 0 or distance is withing range. if( pCurAct != pActor && ( fRange == 0.0f || distance <= fRange ) ) @@ -760,7 +741,6 @@ void Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell ) pActor->spawn( pPlayer ); } - } else if( pActor->isMob() && pCurAct->isPlayer() && pActor->isAlive() ) { @@ -781,4 +761,4 @@ void Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell ) } } -} +} // namespace Core diff --git a/src/servers/Server_Zone/Zone/Zone.h b/src/servers/Server_Zone/Zone/Zone.h index fa318535..5f5ea733 100644 --- a/src/servers/Server_Zone/Zone/Zone.h +++ b/src/servers/Server_Zone/Zone/Zone.h @@ -1,25 +1,24 @@ #ifndef _ZONE_H #define _ZONE_H -#include #include +#include #include "Cell.h" #include "CellHandler.h" #include "Forwards.h" -#include #include +#include #include #include namespace Core { -namespace Entity -{ +namespace Entity { class Actor; class Player; -} +} // namespace Entity class Session; @@ -27,11 +26,13 @@ class ZonePosition; typedef std::set< SessionPtr > SessionSet; -class Zone : public CellHandler< Cell >, public boost::enable_shared_from_this< Zone > +class Zone + : public CellHandler< Cell > + , public boost::enable_shared_from_this< Zone > { protected: - uint32_t m_zoneId; - uint32_t m_layoutId; + uint32_t m_zoneId; + uint32_t m_layoutId; std::string m_zoneName; std::string m_zoneCode; @@ -89,7 +90,8 @@ public: void updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell ); - void queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, Network::Packets::GamePacketPtr pPacketEntry ); + void queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, + Network::Packets::GamePacketPtr pPacketEntry ); virtual uint32_t getId(); @@ -108,9 +110,8 @@ public: void updateBnpcs( int64_t tickCount ); bool runZoneLogic(); - }; -} +} // namespace Core #endif diff --git a/src/servers/Server_Zone/Zone/ZoneMgr.cpp b/src/servers/Server_Zone/Zone/ZoneMgr.cpp index 100422f4..555580c8 100644 --- a/src/servers/Server_Zone/Zone/ZoneMgr.cpp +++ b/src/servers/Server_Zone/Zone/ZoneMgr.cpp @@ -1,9 +1,9 @@ -#include -#include #include +#include +#include -#include "ZoneMgr.h" #include "Zone.h" +#include "ZoneMgr.h" #include "ZonePosition.h" #include @@ -13,77 +13,76 @@ extern Core::Data::ExdData g_exdData; namespace Core { - ZoneMgr::ZoneMgr() = default; +ZoneMgr::ZoneMgr() = default; - ZoneMgr::~ZoneMgr() = default; +ZoneMgr::~ZoneMgr() = default; - void ZoneMgr::loadZonePositionMap() +void ZoneMgr::loadZonePositionMap() +{ + auto pQR = g_charaDb.query( "SELECT id, target_zone_id, pos_x, pos_y, pos_z, pos_o, radius FROM zonepositions;" ); + + while( pQR->next() ) { - auto pQR = g_charaDb.query( "SELECT id, target_zone_id, pos_x, pos_y, pos_z, pos_o, radius FROM zonepositions;" ); + uint32_t id = pQR->getUInt( 1 ); + uint32_t targetZoneId = pQR->getUInt( 2 ); + Common::FFXIVARR_POSITION3 pos; + pos.x = pQR->getFloat( 3 ); + pos.y = pQR->getFloat( 4 ); + pos.z = pQR->getFloat( 5 ); + float posO = pQR->getFloat( 6 ); + uint32_t radius = pQR->getUInt( 7 ); - while( pQR->next() ) - { - uint32_t id = pQR->getUInt( 1 ); - uint32_t targetZoneId = pQR->getUInt( 2 ); - Common::FFXIVARR_POSITION3 pos; - pos.x = pQR->getFloat( 3 ); - pos.y = pQR->getFloat( 4 ); - pos.z = pQR->getFloat( 5 ); - float posO = pQR->getFloat( 6 ); - uint32_t radius = pQR->getUInt( 7 ); - - m_zonePositionMap[id] = ZonePositionPtr( new ZonePosition( id, targetZoneId, pos, radius, posO ) ); - } + m_zonePositionMap[id] = ZonePositionPtr( new ZonePosition( id, targetZoneId, pos, radius, posO ) ); } - - ZonePositionPtr ZoneMgr::getZonePosition( uint32_t zonePositionId ) - { - auto it = m_zonePositionMap.find( zonePositionId ); - - if( it != m_zonePositionMap.end() ) - return it->second; - - return nullptr; - } - - bool ZoneMgr::createZones() - { - loadZonePositionMap(); - - // find zone info from exd - for( auto zone : g_exdData.m_zoneInfoMap ) - { - uint32_t zoneId = zone.first; - - - auto info = zone.second; - g_log.Log( LoggingSeverity::info, std::to_string( info.id ) + "\t" + info.zone_str ); - - ZonePtr pZone( new Zone( info.id, info.layout_id, info.zone_name, info.zone_str, false ) ); - pZone->init(); - m_zoneMap[info.id] = pZone; - } - - return true; - } - - void ZoneMgr::updateZones() - { - for( auto zone : m_zoneMap ) - { - zone.second->runZoneLogic(); - } - } - - ZonePtr ZoneMgr::getZone( uint32_t zoneId ) - { - ZoneMap::iterator it; - it = m_zoneMap.find( zoneId ); - - if( it != m_zoneMap.end() ) - return it->second; - - return nullptr; - } - } + +ZonePositionPtr ZoneMgr::getZonePosition( uint32_t zonePositionId ) +{ + auto it = m_zonePositionMap.find( zonePositionId ); + + if( it != m_zonePositionMap.end() ) + return it->second; + + return nullptr; +} + +bool ZoneMgr::createZones() +{ + loadZonePositionMap(); + + // find zone info from exd + for( auto zone : g_exdData.m_zoneInfoMap ) + { + uint32_t zoneId = zone.first; + + auto info = zone.second; + g_log.Log( LoggingSeverity::info, std::to_string( info.id ) + "\t" + info.zone_str ); + + ZonePtr pZone( new Zone( info.id, info.layout_id, info.zone_name, info.zone_str, false ) ); + pZone->init(); + m_zoneMap[info.id] = pZone; + } + + return true; +} + +void ZoneMgr::updateZones() +{ + for( auto zone : m_zoneMap ) + { + zone.second->runZoneLogic(); + } +} + +ZonePtr ZoneMgr::getZone( uint32_t zoneId ) +{ + ZoneMap::iterator it; + it = m_zoneMap.find( zoneId ); + + if( it != m_zoneMap.end() ) + return it->second; + + return nullptr; +} + +} // namespace Core diff --git a/src/servers/Server_Zone/Zone/ZoneMgr.h b/src/servers/Server_Zone/Zone/ZoneMgr.h index bab6c23b..c398579d 100644 --- a/src/servers/Server_Zone/Zone/ZoneMgr.h +++ b/src/servers/Server_Zone/Zone/ZoneMgr.h @@ -1,39 +1,36 @@ #ifndef _ZONEMGR_H #define _ZONEMGR_H - -#include -#include #include "Forwards.h" +#include +#include namespace Core { - using ZoneMap = std::unordered_map< uint32_t, ZonePtr >; +using ZoneMap = std::unordered_map< uint32_t, ZonePtr >; - class ZoneMgr - { - public: - ZoneMgr(); - ~ZoneMgr(); +class ZoneMgr +{ +public: + ZoneMgr(); + ~ZoneMgr(); - bool createZones(); + bool createZones(); - ZonePtr getZone( uint32_t zoneId ); + ZonePtr getZone( uint32_t zoneId ); - void loadZonePositionMap(); + void loadZonePositionMap(); - ZonePositionPtr getZonePosition( uint32_t zonePositionId ); + ZonePositionPtr getZonePosition( uint32_t zonePositionId ); - void updateZones(); + void updateZones(); - private: - ZoneMap m_zoneMap; +private: + ZoneMap m_zoneMap; - std::unordered_map m_zonePositionMap; + std::unordered_map< int32_t, ZonePositionPtr > m_zonePositionMap; +}; - }; - -} +} // namespace Core #endif - diff --git a/src/servers/Server_Zone/Zone/ZonePosition.cpp b/src/servers/Server_Zone/Zone/ZonePosition.cpp index 2e80e6c5..cae915c6 100644 --- a/src/servers/Server_Zone/Zone/ZonePosition.cpp +++ b/src/servers/Server_Zone/Zone/ZonePosition.cpp @@ -1,13 +1,11 @@ #include "ZonePosition.h" -Core::ZonePosition::ZonePosition() - : m_id(0) - , m_targetZoneId(0) - , m_radius(0) +Core::ZonePosition::ZonePosition() : m_id( 0 ), m_targetZoneId( 0 ), m_radius( 0 ) { } -Core::ZonePosition::ZonePosition( uint32_t id, uint32_t targetZoneId, const Common::FFXIVARR_POSITION3& targetPosition, uint32_t radius, float rotation ) +Core::ZonePosition::ZonePosition( uint32_t id, uint32_t targetZoneId, const Common::FFXIVARR_POSITION3& targetPosition, + uint32_t radius, float rotation ) { m_id = id; m_targetZoneId = targetZoneId; @@ -30,7 +28,7 @@ uint32_t Core::ZonePosition::getTargetZoneId() const return m_targetZoneId; } -const Core::Common::FFXIVARR_POSITION3 & Core::ZonePosition::getTargetPosition() const +const Core::Common::FFXIVARR_POSITION3& Core::ZonePosition::getTargetPosition() const { return m_targetPos; } @@ -39,5 +37,3 @@ float Core::ZonePosition::getTargetRotation() const { return m_rotation; } - - diff --git a/src/servers/Server_Zone/Zone/ZonePosition.h b/src/servers/Server_Zone/Zone/ZonePosition.h index 0b4cad7c..fbc558f9 100644 --- a/src/servers/Server_Zone/Zone/ZonePosition.h +++ b/src/servers/Server_Zone/Zone/ZonePosition.h @@ -8,15 +8,16 @@ namespace Core { class ZonePosition { protected: - uint32_t m_id; - uint32_t m_targetZoneId; - Common::FFXIVARR_POSITION3 m_targetPos; + uint32_t m_id; + uint32_t m_targetZoneId; + Common::FFXIVARR_POSITION3 m_targetPos; float m_rotation; - uint32_t m_radius; + uint32_t m_radius; public: ZonePosition(); - ZonePosition( uint32_t id, uint32_t targetZoneId, const Common::FFXIVARR_POSITION3& targetPosition, uint32_t radius, float rotation ); + ZonePosition( uint32_t id, uint32_t targetZoneId, const Common::FFXIVARR_POSITION3& targetPosition, uint32_t radius, + float rotation ); virtual ~ZonePosition(); uint32_t getId() const; @@ -26,8 +27,7 @@ public: const Common::FFXIVARR_POSITION3& getTargetPosition() const; float getTargetRotation() const; - }; -} +} // namespace Core #endif