diff --git a/scripts/chai/opening/OpeningGridania.chai b/scripts/chai/opening/OpeningGridania.chai index fbaf1005..207cf8fe 100644 --- a/scripts/chai/opening/OpeningGridania.chai +++ b/scripts/chai/opening/OpeningGridania.chai @@ -34,7 +34,7 @@ class OpeningGridaniaDef def Scene00000( player ) { - player.eventPlay( this.id, 0, 0x2001, 0, 1, + player.eventPlay( this.id, 0, 0x04AC05, 0, 1, fun( player, eventId, param1, param2, param3 ) { player.setOpeningSequence( 1 ); diff --git a/scripts/chai/opening/OpeningLimsa.chai b/scripts/chai/opening/OpeningLimsa.chai index ebae5446..f7ab44c7 100644 --- a/scripts/chai/opening/OpeningLimsa.chai +++ b/scripts/chai/opening/OpeningLimsa.chai @@ -72,7 +72,6 @@ class OpeningLimsaLominsaDef player.eventPlay( this.id, 40, 1, 2, 1, fun( player, eventId, param1, param2, param3 ) { - player.eventFinish( eventId, UNLOCK ); if( player.getOpeningSequence() == 2 ) { // update the instance boundaries diff --git a/scripts/chai/opening/OpeningUldah.chai b/scripts/chai/opening/OpeningUldah.chai index 6c19e6c4..829bab1b 100644 --- a/scripts/chai/opening/OpeningUldah.chai +++ b/scripts/chai/opening/OpeningUldah.chai @@ -35,7 +35,7 @@ class OpeningUldahDef def Scene00000( player ) { - player.eventPlay( this.id, 0, 0x2001, 0, 1, + player.eventPlay( this.id, 0, 0x04AC05, 0, 1, fun( player, eventId, param1, param2, param3 ) { player.setOpeningSequence( 1 ); diff --git a/scripts/chai/quest/ManFst003.chai b/scripts/chai/quest/ManFst003.chai index 8d592cff..403d18d3 100644 --- a/scripts/chai/quest/ManFst003.chai +++ b/scripts/chai/quest/ManFst003.chai @@ -9,11 +9,11 @@ // Start NPC: 1001140 // End NPC: 1000100 -class ManFst003Def +class ManFst003Def { def ManFst003Def() { - // Basic quest information + // Basic quest information this.name = "Close to Home"; this.id = 65659; @@ -24,13 +24,13 @@ class ManFst003Def // GetQuestUI8BL // GetQuestUI8CH - // Steps in this quest ( 0 is before accepting, + // Steps in this quest ( 0 is before accepting, // 1 is first, 255 means ready for turning it in this.SEQ_0 = 0; this.SEQ_1 = 1; this.SEQ_FINISH = 255; - // Quest rewards + // Quest rewards this.RewardExpFactor = 100; this.RewardGil = 107; @@ -74,7 +74,6 @@ class ManFst003Def def checkQuestCompletion( player, varIdx ) { - print( varIdx ); if (varIdx == 3) { player.questMessage(this.id, 1, 0, 0, 0 ); @@ -118,8 +117,8 @@ class ManFst003Def player.eventPlay( this.id, 1, 0x0EFB/*flags*/, 0/*unk*/, 0/*unk*/, fun( player, eventId, param1, param2, param3 ) { - player.setQuestUI8AL( ManFst004.id, 1 ); - ManFst003.checkQuestCompletion( player, 1 ); + player.setQuestUI8AL( ManFst003.id, 1 ); + ManFst003.checkQuestCompletion( player, 0 ); }); } @@ -128,7 +127,7 @@ class ManFst003Def player.eventPlay( this.id, 2, 0, 0, 0, fun( player, eventId, param1, param2, param3 ) { - player.setQuestUI8BH( ManFst004.id, 1 ); + player.setQuestUI8BH( ManFst003.id, 1 ); ManFst003.checkQuestCompletion( player, 3 ); }); } @@ -207,8 +206,8 @@ class ManFst003Def player.eventPlay( this.id, 100, 0x0EFB, 0, 0, fun( player, eventId, param1, param2, param3 ) { - player.setQuestUI8CH( ManFst004.id, 0 ); // remove key item, since we have just traded it - player.setQuestUI8BL( ManFst004.id, 1 ); + player.setQuestUI8CH( ManFst003.id, 0 ); // remove key item, since we have just traded it + player.setQuestUI8BL( ManFst003.id, 1 ); ManFst003.checkQuestCompletion(player, 2 ); }); } @@ -237,7 +236,6 @@ class ManFst003Def }, fun( player, eventId, additional ) {}, eventId ); - player.unlock(); } else if( actor == this.ACTOR2 ) { @@ -257,4 +255,3 @@ class ManFst003Def }; GLOBAL ManFst003 = ManFst003Def(); - diff --git a/scripts/chai/quest/ManSea001.chai b/scripts/chai/quest/ManSea001.chai index c3af3b76..8c060bf2 100644 --- a/scripts/chai/quest/ManSea001.chai +++ b/scripts/chai/quest/ManSea001.chai @@ -51,11 +51,12 @@ class ManSea001Def // Available Scenes in this quest, not necessarly all are used def Scene00000( player ) { - player.eventPlay( this.id, 0, HIDE_HOTBAR, 0/*unk*/, 0/*unk*/, + player.eventPlay( this.id, 0, 0x2000, 0, 0, fun( player, eventId, param1, param2, param3 ) { if( param2 == 1 ) { + player.setOpeningSequence( 2 ); ManSea001.Scene00001( player ); } }); @@ -63,7 +64,7 @@ class ManSea001Def def Scene00001( player ) { - player.eventPlay( this.id, 1, HIDE_HOTBAR, 0/*unk*/, 0/*unk*/, + player.eventPlay( this.id, 1, 0xF8482EFB, 0, 0, fun( player, eventId, param1, param2, param3 ) { ManSea001.Scene00002( player ); @@ -81,13 +82,13 @@ class ManSea001Def def Scene00003( player ) { - player.eventPlay( this.id, 3, NONE, 0/*unk*/, 0/*unk*/, + player.eventPlay( this.id, 3, NONE, 0, 0, fun( player, eventId, param1, param2, param3 ) { player.questUpdate( ManSea001.id, 0x01 ); // add quest to player. // update the instance boundaries, call to the opening event - //player.eventPlay( ManSea001.OPENING_EVENT_HANDLER, 0x1E, HIDE_HOTBAR, 1, 0); + player.eventPlay( ManSea001.OPENING_EVENT_HANDLER, 0x1E, 0x2001, 1, 0); }); } @@ -107,7 +108,7 @@ class ManSea001Def def Scene00006( player ) { - player.eventPlay( this.id, 6, NONE, 0/*unk*/, 0/*unk*/, + player.eventPlay( this.id, 6, 0x20, 0/*unk*/, 0/*unk*/, fun( player, eventId, param1, param2, param3 ) { if( param2 == 1 ) @@ -141,7 +142,7 @@ class ManSea001Def def Scene00011( player ) { - player.eventPlay( this.id, 11, NONE, 0, 0, + player.eventPlay( this.id, 11, 0x2c02, 0, 0, fun( player, eventId, param1, param2, param3 ) { ManSea001.Scene00012( player ); @@ -150,7 +151,7 @@ class ManSea001Def def Scene00012( player ) { - player.eventPlay( this.id, 12, NONE, 0, 0, + player.eventPlay( this.id, 12, 0x20, 0, 0, fun( player, eventId, param1, param2, param3 ) { if( param2 == 1 ) diff --git a/scripts/chai/quest/ManWil001.chai b/scripts/chai/quest/ManWil001.chai index 1799e45a..da55f8c1 100644 --- a/scripts/chai/quest/ManWil001.chai +++ b/scripts/chai/quest/ManWil001.chai @@ -9,25 +9,25 @@ // Start NPC: 1003987 // End NPC: 1003988 -class ManWil001Def +class ManWil001Def { ////////////////////////////////////////////////////////////////////// // default ctor def ManWil001Def() { - // Basic quest information + // Basic quest information this.name = "Coming to Ul'dah"; this.id = 66130; // Quest vars / flags used // GetQuestUI8AL - // Steps in this quest ( 0 is before accepting, + // Steps in this quest ( 0 is before accepting, // 1 is first, 255 means ready for turning it in this.SEQ_0 = 0; this.SEQ_FINISH = 255; - // Quest rewards + // Quest rewards this.RewardExpFactor = 50; this.RewardGil = 103; @@ -49,11 +49,12 @@ class ManWil001Def // Available Scenes in this quest, not necessarly all are used def Scene00000( player ) { - player.eventPlay( this.id, 0, 0, 0, 0, + player.eventPlay( this.id, 0, 0x2000, 0, 0, fun( player, eventId, param1, param2, param3 ) { if( param2 == 1 ) // accept quest { + player.setOpeningSequence( 2 ); ManWil001.Scene00001( player ); } }); @@ -61,7 +62,7 @@ class ManWil001Def def Scene00001( player ) { - player.eventPlay( this.id, 1, 0, 0, 0, + player.eventPlay( this.id, 1, 0xF8482EFB, 0, 0, fun( player, eventId, param1, param2, param3 ) { ManWil001.Scene00002( player ); @@ -70,11 +71,11 @@ class ManWil001Def def Scene00002( player ) { - player.eventPlay( this.id, 2, 0, 0, 0, + player.eventPlay( this.id, 2, NONE, 0, 0, fun( player, eventId, param1, param2, param3 ) { - player.questUpdate( ManWil001.id, ManWil001Obj.SEQ_FINISH );// add quest to player. - player.eventPlay( ManWil001.OPENING_EVENT_HANDLER, 0x1E, 0x2001, 0, 0 ); + player.questUpdate( ManWil001.id, ManWil001.SEQ_FINISH );// add quest to player. + player.eventPlay( ManWil001.OPENING_EVENT_HANDLER, 0x1E, 0x2001, 0, 0 ); }); } @@ -85,7 +86,7 @@ class ManWil001Def def Scene00004( player ) { - player.eventPlay( this.id, 4, 0, 0, 0, + player.eventPlay( this.id, 4, 0x2c02, 0, 0, fun( player, eventId, param1, param2, param3 ) { ManWil001.Scene00005( player ); @@ -94,7 +95,7 @@ class ManWil001Def def Scene00005( player ) { - player.eventPlay( this.id, 5, 0/*flags*/, 0/*unk*/, 0/*unk*/, + player.eventPlay( this.id, 5, 0x20/*flags*/, 0/*unk*/, 0/*unk*/, fun( player, eventId, param1, param2, param3 ) { if( param2 == 1 ) // clicked finish button diff --git a/src/servers/Server_Common/Common.h b/src/servers/Server_Common/Common.h index a2a243be..2aa8c2b5 100644 --- a/src/servers/Server_Common/Common.h +++ b/src/servers/Server_Common/Common.h @@ -636,6 +636,7 @@ namespace Core { enum struct PlayerStateFlag : uint8_t { + SomeFlag, NoCombat, Combat, Casting, @@ -643,9 +644,9 @@ namespace Core { StatusAffliction1, Occupied, Occupied1, - Occupied2, Occupied3, + BoundByDuty, Occupied4, DuelingArea, @@ -656,6 +657,7 @@ namespace Core { PreparingToCraft, Gathering, Fishing, + BeingRaised, BetweenAreas, Stealthed, @@ -666,9 +668,9 @@ namespace Core { BetweenAreas1, SystemError, LoggingOut, + InvalidLocation, WaitingForDuty, - BoundByDuty1, Mounting, WatchingCutscene, @@ -686,9 +688,9 @@ namespace Core { FreeTrail, BeingMoved, Mounting2, - StatusAffliction3, StatusAffliction4, + RegisteringRaceOrMatch, WaitingForRaceOrMatch, WaitingForTripleTriadMatch, diff --git a/src/servers/Server_Common/Exd/ExdData.cpp b/src/servers/Server_Common/Exd/ExdData.cpp index 3eb295fd..40e6e28d 100644 --- a/src/servers/Server_Common/Exd/ExdData.cpp +++ b/src/servers/Server_Common/Exd/ExdData.cpp @@ -345,7 +345,6 @@ bool Core::Data::ExdData::loadActionInfo() uint8_t points_type = getField< uint8_t >( fields, 30 ); // 30 uint16_t points_cost = getField< uint16_t >( fields, 31 ); // 31 - bool is_instant = getField< bool >( fields, 35 ); // 35 uint16_t cast_time = getField< uint16_t >( fields, 36 ); // 36 uint16_t recast_time = getField< uint16_t >( fields, 37 ); // 37 diff --git a/src/servers/Server_Zone/Actor/Actor.cpp b/src/servers/Server_Zone/Actor/Actor.cpp index b9d9e210..8209e365 100644 --- a/src/servers/Server_Zone/Actor/Actor.cpp +++ b/src/servers/Server_Zone/Actor/Actor.cpp @@ -57,13 +57,13 @@ std::string Core::Entity::Actor::getName() const /*! \return true if the actor is of type player */ bool Core::Entity::Actor::isPlayer() const { - return ( m_type == ActorType::Player ? true : false ); + return m_type == ActorType::Player; } /*! \return true if the actor is of type mob */ bool Core::Entity::Actor::isMob() const { - return ( m_type == ActorType::BattleNpc ? true : false ); + return m_type == ActorType::BattleNpc; } /*! \return list of actors currently in range */ @@ -244,10 +244,7 @@ bool Core::Entity::Actor::face( const Common::FFXIVARR_POSITION3& p ) setRotation( newRot ); - if( oldRot != newRot ) - return true; - - return false; + return oldRot != newRot ? true : false; } /*! @@ -762,7 +759,8 @@ 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 ); } @@ -772,7 +770,8 @@ void Core::Entity::Actor::addStatusEffectByIdIfNotExist( uint32_t id, int32_t du { if( !m_pStatusEffectContainer->hasStatusEffect( id ) ) { - 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 ); } diff --git a/src/servers/Server_Zone/Actor/BattleNpc.cpp b/src/servers/Server_Zone/Actor/BattleNpc.cpp index b9891203..6ec2a5d7 100644 --- a/src/servers/Server_Zone/Actor/BattleNpc.cpp +++ b/src/servers/Server_Zone/Actor/BattleNpc.cpp @@ -54,6 +54,7 @@ Core::Entity::BattleNpc::BattleNpc( uint32_t modelId, uint32_t nameid, const Com m_type = ActorType::BattleNpc; m_mode = MODE_IDLE; + m_targetId = INVALID_GAME_OBJECT_ID; m_maxHp = 150; m_maxMp = 100; @@ -229,7 +230,7 @@ void Core::Entity::BattleNpc::setOwner( Core::Entity::PlayerPtr pPlayer ) } else { - GamePacketNew< FFXIVIpcActorOwner, ServerZoneIpcType > setOwnerPacket(getId(), INVALID_GAME_OBJECT_ID); + GamePacketNew< FFXIVIpcActorOwner, ServerZoneIpcType > setOwnerPacket(getId(), INVALID_GAME_OBJECT_ID ); setOwnerPacket.data().type = 0x01; setOwnerPacket.data().actorId = INVALID_GAME_OBJECT_ID; sendToInRangeSet( setOwnerPacket ); @@ -251,15 +252,15 @@ bool Core::Entity::BattleNpc::moveTo( Common::FFXIVARR_POSITION3& pos ) // reached destination return true; - float rot = Math::Util::calcAngFrom(getPos().x, getPos().z, pos.x, pos.z); + float rot = Math::Util::calcAngFrom( getPos().x, getPos().z, pos.x, pos.z ); float newRot = PI - rot + (PI / 2); 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 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 ); + float z = static_cast< float >( sinf( angle ) * 1.1f ); Common::FFXIVARR_POSITION3 newPos; diff --git a/src/servers/Server_Zone/Actor/BattleNpc.h b/src/servers/Server_Zone/Actor/BattleNpc.h index d13d082b..f74f9536 100644 --- a/src/servers/Server_Zone/Actor/BattleNpc.h +++ b/src/servers/Server_Zone/Actor/BattleNpc.h @@ -104,7 +104,7 @@ private: uint32_t m_unk2; std::set< HateListEntry* > m_hateList; ActorPtr m_pOwner; - int32_t m_timeOfDeath; + uint32_t m_timeOfDeath; uint32_t m_mobType; }; diff --git a/src/servers/Server_Zone/Actor/CalcBattle.cpp b/src/servers/Server_Zone/Actor/CalcBattle.cpp index d83ead39..5bc0d252 100644 --- a/src/servers/Server_Zone/Actor/CalcBattle.cpp +++ b/src/servers/Server_Zone/Actor/CalcBattle.cpp @@ -111,7 +111,6 @@ uint32_t CalcBattle::calculateMaxMp( PlayerPtr pPlayer ) return result; } - uint32_t CalcBattle::calculateHealValue( PlayerPtr pPlayer, uint32_t potency ) { auto classInfoIt = g_exdData.m_classJobInfoMap.find( pPlayer->getClass() ); diff --git a/src/servers/Server_Zone/Actor/Player.cpp b/src/servers/Server_Zone/Actor/Player.cpp index 4c6e3fe6..f364f1d0 100644 --- a/src/servers/Server_Zone/Actor/Player.cpp +++ b/src/servers/Server_Zone/Actor/Player.cpp @@ -192,7 +192,7 @@ void Core::Entity::Player::prepareZoning( uint16_t targetZone, bool fadeOut, uin preparePacket.data().targetZone = targetZone; preparePacket.data().fadeOutTime = fadeOutTime; preparePacket.data().animation = animation; - preparePacket.data().fadeOut = fadeOut == true ? 1 : 0; + preparePacket.data().fadeOut = static_cast< uint8_t >( fadeOut ? 1 : 0 ); queuePacket( preparePacket ); } @@ -398,7 +398,7 @@ void Core::Entity::Player::setZone( uint32_t zoneId ) if( isLogin() ) { GamePacketNew< FFXIVIpcCFAvailableContents, ServerZoneIpcType > contentFinderList( getId() ); - for( auto i = 0; i < 72; i++ ) + for( auto i = 0; i < sizeof( contentFinderList.data().contents ); i++ ) { // unlock all contents for now contentFinderList.data().contents[i] = 0xFF; @@ -632,7 +632,9 @@ void Core::Entity::Player::gainExp( uint32_t amount ) if( ( currentExp + amount ) >= neededExpToLevel ) { // levelup - amount = ( currentExp + amount - neededExpToLevel ) > neededExpToLevelplus1 ? neededExpToLevelplus1 - 1 : ( currentExp + amount - neededExpToLevel ); + amount = ( currentExp + amount - neededExpToLevel ) > neededExpToLevelplus1 ? + neededExpToLevelplus1 - 1 : + ( currentExp + amount - neededExpToLevel ); setExp( amount ); gainLevel(); queuePacket( ActorControlPacket143( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), amount ) ); @@ -791,50 +793,6 @@ void Core::Entity::Player::setLevelForClass( uint8_t level, Core::Common::ClassJ setSyncFlag( PlayerSyncFlags::ExpLevel ); } -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 ) ); - - setCurrentAction( pEventAction ); - auto pEvent = getEvent( eventId ); - - if( !pEvent && getEventCount() ) - { - // We're trying to play a nested event, need to start it first. - eventStart( getId(), eventId, Event::Event::Nest, 0, 0 ); - pEvent = getEvent( eventId ); - } - else if( !pEvent ) - { - g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" ); - return; - } - - if( pEvent ) - pEvent->setPlayedScene( true ); - pEventAction->onStart(); -} - - -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 ) ); - - setCurrentAction( pEventItemAction ); - - pEventItemAction->onStart(); -} - void Core::Entity::Player::sendModel() { ModelEquipPacket modelEquip( getAsPlayer() ); @@ -973,7 +931,7 @@ void Core::Entity::Player::setGcRankAt( uint8_t index, uint8_t rank ) setSyncFlag( PlayerSyncFlags::GC ); } -const uint8_t * Core::Entity::Player::getStateFlags() const +const uint8_t* Core::Entity::Player::getStateFlags() const { return m_stateFlags; } @@ -1086,21 +1044,16 @@ void Core::Entity::Player::update( int64_t currTime ) m_lastUpdate = currTime; - // @TODO needs to happen in a if check. Don't want autoattacking while an action is being performed. if( !checkAction() ) { - if( m_targetId ) + if( m_targetId && m_currentStance == Entity::Actor::Stance::Active && isAutoattackOn() ) { 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... for( auto actor : m_inRangeActors ) { - if( isAutoattackOn() && - actor->getId() == m_targetId && - actor->isAlive() && - mainWeap && - m_currentStance == Entity::Actor::Stance::Active - ) + if( actor->getId() == m_targetId && actor->isAlive() && mainWeap ) { // default autoattack range // TODO make this dependant on bnpc size @@ -1536,9 +1489,7 @@ uint32_t Core::Entity::Player::getCFPenaltyMinutes() const // check if penalty timestamp already passed current time if (currentTimestamp > endTimestamp) - { return 0; - } auto deltaTime = endTimestamp - currentTimestamp; return static_cast< uint32_t > ( ceil( static_cast< float > (deltaTime) / 60 ) ); diff --git a/src/servers/Server_Zone/Actor/PlayerEvent.cpp b/src/servers/Server_Zone/Actor/PlayerEvent.cpp index f0bf77fe..721456e9 100644 --- a/src/servers/Server_Zone/Actor/PlayerEvent.cpp +++ b/src/servers/Server_Zone/Actor/PlayerEvent.cpp @@ -18,6 +18,10 @@ #include "src/servers/Server_Zone/Network/PacketWrappers/EventPlayPacket.h" #include "src/servers/Server_Zone/Network/PacketWrappers/EventFinishPacket.h" +#include "src/servers/Server_Zone/Action/EventAction.h" +#include "src/servers/Server_Zone/Action/EventItemAction.h" + +#include "src/servers/Server_Zone/Event/Event.h" #include "src/servers/Server_Zone/Event/Event.h" #include "Server_Zone/ServerZone.h" @@ -230,6 +234,50 @@ 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 ) +{ + Action::ActionPtr pEventAction( new Action::EventAction( shared_from_this(), eventId, action, + finishCallback, interruptCallback, additional ) ); + + setCurrentAction( pEventAction ); + auto pEvent = getEvent( eventId ); + + if( !pEvent && getEventCount() ) + { + // We're trying to play a nested event, need to start it first. + eventStart( getId(), eventId, Event::Event::Nest, 0, 0 ); + pEvent = getEvent( eventId ); + } + else if( !pEvent ) + { + g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" ); + return; + } + + if( pEvent ) + pEvent->setPlayedScene( true ); + pEventAction->onStart(); +} + + +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 ) ); + + setCurrentAction( pEventItemAction ); + + pEventItemAction->onStart(); +} + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Core::Entity::Player::onLogin() diff --git a/src/servers/Server_Zone/ServerZone.cpp b/src/servers/Server_Zone/ServerZone.cpp index 2ff42a92..eef00e5a 100644 --- a/src/servers/Server_Zone/ServerZone.cpp +++ b/src/servers/Server_Zone/ServerZone.cpp @@ -41,7 +41,8 @@ Core::LinkshellMgr g_linkshellMgr; Core::ServerZone::ServerZone( const std::string& configPath, uint16_t serverId ) - : m_configPath( configPath ) + : m_configPath( configPath ), + m_bRunning( true ) { m_pConfig = XMLConfigPtr( new XMLConfig ); } @@ -224,18 +225,32 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) g_scriptMgr.init(); std::vector< std::thread > thread_list; - thread_list.push_back( std::thread( std::bind( &Network::Hive::Run, hive.get() ) ) ); + 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..." ); - while( true ) + mainLoop(); + + for( auto& thread_entry : thread_list ) { - std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) ); + thread_entry.join(); + } + +} + +void Core::ServerZone::mainLoop() +{ + while( isRunning() ) + { + this_thread::sleep_for( chrono::milliseconds( 50 ) ); g_zoneMgr.updateZones(); - std::lock_guard lock( m_sessionMutex ); - for( auto sessionIt : m_sessionMap ) + + auto currTime = static_cast< uint32_t >( time( nullptr ) ); + + lock_guard< std::mutex > lock( this->m_sessionMutex ); + for( auto sessionIt : this->m_sessionMap ) { auto session = sessionIt.second; if( session && session->getPlayer() ) @@ -247,9 +262,9 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) } } - uint32_t currTime = static_cast< uint32_t >( time( nullptr ) ); - auto it = m_sessionMap.begin(); - for( ; it != m_sessionMap.end(); ) + + auto it = this->m_sessionMap.begin(); + for( ; it != this->m_sessionMap.end(); ) { uint32_t diff = currTime - it->second->getLastDataTime(); @@ -257,11 +272,11 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) 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() ) { - it = m_sessionMap.erase( it ); + it = this->m_sessionMap.erase(it ); } } else @@ -272,13 +287,6 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) } } - - // currently never reached, need a "stopServer" variable to break out of the above while loop - /*for( auto& thread_entry : thread_list ) - { - thread_entry.join(); - }*/ - } bool Core::ServerZone::createSession( uint32_t sessionId ) @@ -364,3 +372,8 @@ void Core::ServerZone::updateSession( std::string playerName ) it->second->loadPlayer(); } +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 2472c487..130d2f22 100644 --- a/src/servers/Server_Zone/ServerZone.h +++ b/src/servers/Server_Zone/ServerZone.h @@ -40,12 +40,18 @@ namespace Core { Entity::BattleNpcTemplatePtr getBnpcTemplate( std::string templateName ); + void mainLoop(); + + bool isRunning() const; + private: uint16_t m_port; std::string m_ip; + bool m_bRunning; + std::string m_configPath; XMLConfigPtr m_pConfig;