1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-29 07:37:45 +00:00

fix some timeline bugs, temporarily disable gambits

This commit is contained in:
Tahir 2024-06-23 01:30:07 +01:00
parent 7b2ea407e9
commit 2f4efec34d
8 changed files with 66 additions and 33 deletions

View file

@ -854,6 +854,8 @@ void Action::Action::addDefaultActorFilters()
{ {
switch( m_castType ) switch( m_castType )
{ {
case( Common::CastType ) 5:
case Common::CastType::RectangularAOE:
case Common::CastType::SingleTarget: case Common::CastType::SingleTarget:
{ {
auto filter = std::make_shared< World::Util::ActorFilterSingleTarget >( static_cast< uint32_t >( m_targetId ) ); auto filter = std::make_shared< World::Util::ActorFilterSingleTarget >( static_cast< uint32_t >( m_targetId ) );

View file

@ -929,15 +929,16 @@ void BNpc::init()
m_lastRoamTargetReachedTime = Common::Util::getTimeSeconds(); m_lastRoamTargetReachedTime = Common::Util::getTimeSeconds();
/*
//setup a test gambit //setup a test gambit
auto testGambitRule = AI::make_GambitRule( AI::make_TopHateTargetCondition(), Action::make_Action( getAsChara(), 88, 0 ), 5000 ); auto testGambitRule = AI::make_GambitRule( AI::make_TopHateTargetCondition(), Action::make_Action( getAsChara(), 88, 0 ), 5000 );
auto testGambitRule1 = AI::make_GambitRule( AI::make_HPSelfPctLessThanTargetCondition( 50 ), Action::make_Action( getAsChara(), 120, 0 ), 5000 ); auto testGambitRule1 = AI::make_GambitRule( AI::make_HPSelfPctLessThanTargetCondition( 50 ), Action::make_Action( getAsChara(), 120, 0 ), 5000 );
/*
auto gambitPack = AI::make_GambitRuleSetPack(); auto gambitPack = AI::make_GambitRuleSetPack();
gambitPack->addRule( AI::make_TopHateTargetCondition(), Action::make_Action( getAsChara(), 88, 0 ), 5000 ); gambitPack->addRule( AI::make_TopHateTargetCondition(), Action::make_Action( getAsChara(), 88, 0 ), 5000 );
gambitPack->addRule( AI::make_HPSelfPctLessThanTargetCondition( 50 ), Action::make_Action( getAsChara(), 120, 0 ), 10000 ); gambitPack->addRule( AI::make_HPSelfPctLessThanTargetCondition( 50 ), Action::make_Action( getAsChara(), 120, 0 ), 10000 );
m_pGambitPack = gambitPack; m_pGambitPack = gambitPack;
*/
auto gambitPack = AI::make_GambitTimeLinePack( -1 ); auto gambitPack = AI::make_GambitTimeLinePack( -1 );
gambitPack->addTimeLine( AI::make_TopHateTargetCondition(), Action::make_Action( getAsChara(), 88, 0 ), 2 ); gambitPack->addTimeLine( AI::make_TopHateTargetCondition(), Action::make_Action( getAsChara(), 88, 0 ), 2 );
@ -948,7 +949,7 @@ void BNpc::init()
gambitPack->addTimeLine( AI::make_TopHateTargetCondition(), Action::make_Action( getAsChara(), 81, 0 ), 12 ); gambitPack->addTimeLine( AI::make_TopHateTargetCondition(), Action::make_Action( getAsChara(), 81, 0 ), 12 );
gambitPack->addTimeLine( AI::make_TopHateTargetCondition(), Action::make_Action( getAsChara(), 82, 0 ), 14 ); gambitPack->addTimeLine( AI::make_TopHateTargetCondition(), Action::make_Action( getAsChara(), 82, 0 ), 14 );
m_pGambitPack = gambitPack; m_pGambitPack = gambitPack;
*/
using namespace AI::Fsm; using namespace AI::Fsm;
m_fsm = make_StateMachine(); m_fsm = make_StateMachine();
auto stateIdle = make_StateIdle(); auto stateIdle = make_StateIdle();
@ -980,7 +981,8 @@ void BNpc::init()
void BNpc::processGambits( uint64_t tickCount ) void BNpc::processGambits( uint64_t tickCount )
{ {
m_tp = 1000; m_tp = 1000;
m_pGambitPack->update( *this, tickCount ); if( m_pGambitPack )
m_pGambitPack->update( *this, tickCount );
} }
uint32_t BNpc::getLastRoamTargetReachedTime() const uint32_t BNpc::getLastRoamTargetReachedTime() const

View file

@ -22,6 +22,7 @@
#include <Territory/QuestBattle.h> #include <Territory/QuestBattle.h>
#include <Territory/InstanceContent.h> #include <Territory/InstanceContent.h>
#include <Util/UtilMath.h> #include <Util/UtilMath.h>
#include <Util/Util.h>
namespace Sapphire::Encounter namespace Sapphire::Encounter
{ {
@ -348,7 +349,8 @@ namespace Sapphire::Encounter
void TimelinePack::update( TerritoryPtr pTeri, uint64_t time ) void TimelinePack::update( TerritoryPtr pTeri, uint64_t time )
{ {
auto now = Common::Util::getTimeMs();
for( auto& actor : m_actors ) for( auto& actor : m_actors )
actor.update( pTeri, *this, time ); actor.update( pTeri, *this, now );
} }
}// namespace Sapphire::Encounter }// namespace Sapphire::Encounter

View file

@ -29,7 +29,7 @@ namespace Sapphire::Encounter
case ConditionType::HpPctBetween: case ConditionType::HpPctBetween:
{ {
auto hpPct = pBNpc->getHpPercent(); auto hpPct = pBNpc->getHpPercent();
return hpPct >= hp.min && hpPct <= hp.max; return hpPct > hp.min && hpPct < hp.max;
} }
} }
return false; return false;
@ -62,23 +62,26 @@ namespace Sapphire::Encounter
bool ConditionCombatState::isConditionMet( ConditionState& state, TimelinePack& pack, TerritoryPtr pTeri, uint64_t time ) const bool ConditionCombatState::isConditionMet( ConditionState& state, TimelinePack& pack, TerritoryPtr pTeri, uint64_t time ) const
{ {
auto pBattleNpc = pTeri->getActiveBNpcByLayoutId( this->layoutId ); auto pBNpc = pTeri->getActiveBNpcByLayoutId( this->layoutId );
if( !pBNpc )
return false;
// todo: these should really use callbacks when the state transitions or we could miss this tick // todo: these should really use callbacks when the state transitions or we could miss this tick
switch( combatState ) switch( combatState )
{ {
case CombatStateType::Idle: case CombatStateType::Idle:
return pBattleNpc->getState() == Entity::BNpcState::Idle; return pBNpc->getState() == Entity::BNpcState::Idle;
case CombatStateType::Combat: case CombatStateType::Combat:
return pBattleNpc->getState() == Entity::BNpcState::Combat; return pBNpc->getState() == Entity::BNpcState::Combat;
case CombatStateType::Retreat: case CombatStateType::Retreat:
return pBattleNpc->getState() == Entity::BNpcState::Retreat; return pBNpc->getState() == Entity::BNpcState::Retreat;
case CombatStateType::Roaming: case CombatStateType::Roaming:
return pBattleNpc->getState() == Entity::BNpcState::Roaming; return pBNpc->getState() == Entity::BNpcState::Roaming;
case CombatStateType::JustDied: case CombatStateType::JustDied:
return pBattleNpc->getState() == Entity::BNpcState::JustDied; return pBNpc->getState() == Entity::BNpcState::JustDied;
case CombatStateType::Dead: case CombatStateType::Dead:
return pBattleNpc->getState() == Entity::BNpcState::Dead; return pBNpc->getState() == Entity::BNpcState::Dead;
default: default:
break; break;
} }
@ -219,9 +222,9 @@ namespace Sapphire::Encounter
if( state.m_phaseInfo.m_lastTimepointTime == 0 ) if( state.m_phaseInfo.m_lastTimepointTime == 0 )
{ {
state.m_phaseInfo.m_lastTimepointTime = time;
state.m_phaseInfo.m_timepointStates.clear(); state.m_phaseInfo.m_timepointStates.clear();
state.m_phaseInfo.m_timepointStates.resize( m_timepoints.size() ); state.m_phaseInfo.m_timepointStates.resize( m_timepoints.size() );
state.m_phaseInfo.m_lastTimepointTime = time;
} }
for( auto i = state.m_phaseInfo.m_lastTimepointIndex; i < m_timepoints.size(); ) for( auto i = state.m_phaseInfo.m_lastTimepointIndex; i < m_timepoints.size(); )
@ -244,16 +247,13 @@ namespace Sapphire::Encounter
if( timepoint.durationElapsed( timepointElapsed ) && timepoint.finished( tpState, timepointElapsed ) ) if( timepoint.durationElapsed( timepointElapsed ) && timepoint.finished( tpState, timepointElapsed ) )
{ {
// timepoint.reset( tpState ); timepoint.reset( tpState );
// make sure this timepoint isnt run again unless phase loops // make sure this timepoint isnt run again unless phase loops
++i; ++i;
state.m_phaseInfo.m_lastTimepointIndex = i; state.m_phaseInfo.m_lastTimepointIndex = i;
if( i == m_timepoints.size() ) if( i == m_timepoints.size() )
{
state.m_phaseInfo.m_lastTimepointIndex++; state.m_phaseInfo.m_lastTimepointIndex++;
}
continue;
} }
break; break;
} }

View file

@ -79,7 +79,6 @@ namespace Sapphire::Encounter
void execute( ConditionState& state, TimelineActor& self, TimelinePack& pack, TerritoryPtr pTeri, uint64_t time ) const void execute( ConditionState& state, TimelineActor& self, TimelinePack& pack, TerritoryPtr pTeri, uint64_t time ) const
{ {
state.m_startTime = time;
m_phase.execute( state, self, pack, pTeri, time ); m_phase.execute( state, self, pack, pTeri, time );
}; };
@ -96,7 +95,6 @@ namespace Sapphire::Encounter
void reset( ConditionState& state ) const void reset( ConditionState& state ) const
{ {
state.m_startTime = 0; state.m_startTime = 0;
state.m_enabled = isDefaultEnabled();
m_phase.reset( state ); m_phase.reset( state );
} }

View file

@ -36,16 +36,20 @@ namespace Sapphire::Encounter
pCondition->reset( state ); pCondition->reset( state );
} }
} }
else if( pCondition->inProgress( state ) ) // update or execute
{
pCondition->update( state, *this, pack, pTeri, time );
}
else if( pCondition->isConditionMet( state, pack, pTeri, time ) ) else if( pCondition->isConditionMet( state, pack, pTeri, time ) )
{ {
pCondition->execute( state, *this, pack, pTeri, time ); if( pCondition->inProgress( state ) )
{
pCondition->update( state, *this, pack, pTeri, time );
}
else
{
pCondition->execute( state, *this, pack, pTeri, time );
if( pack.getStartTime() == 0 ) if( pack.getStartTime() == 0 )
pack.setStartTime( state.m_startTime ); pack.setStartTime( state.m_startTime );
}
} }
} }
} }

View file

@ -66,6 +66,7 @@ namespace Sapphire::Encounter
{ "spawnBNpc", TimepointDataType::SpawnBNpc }, { "spawnBNpc", TimepointDataType::SpawnBNpc },
{ "bNpcFlags", TimepointDataType::SetBNpcFlags }, { "bNpcFlags", TimepointDataType::SetBNpcFlags },
{ "setEObjState", TimepointDataType::SetEObjState }, { "setEObjState", TimepointDataType::SetEObjState },
{ "setBGM", TimepointDataType::SetBgm },
{ "setCondition", TimepointDataType::SetCondition }, { "setCondition", TimepointDataType::SetCondition },
{ "snapshot", TimepointDataType::Snapshot } { "snapshot", TimepointDataType::Snapshot }
@ -112,6 +113,7 @@ namespace Sapphire::Encounter
m_duration = json.at( "duration" ).get< uint64_t >(); m_duration = json.at( "duration" ).get< uint64_t >();
//m_overrideFlags = json.at( "overrideFlags" ).get< TimepointOverrideFlags >(); //m_overrideFlags = json.at( "overrideFlags" ).get< TimepointOverrideFlags >();
m_description = json.at( "description" ).get< std::string >(); m_description = json.at( "description" ).get< std::string >();
m_type = tpType;
switch( tpType ) switch( tpType )
{ {
@ -292,7 +294,14 @@ namespace Sapphire::Encounter
// todo: SetEObjState // todo: SetEObjState
} }
break; break;
case TimepointDataType::SetBgm:
{
auto& dataJ = json.at( "data" );
auto bgmId = dataJ.at( "bgmId" ).get< uint32_t >();
m_pData = std::make_shared< TimepointDataBGM >( bgmId );
}
break;
case TimepointDataType::SetCondition: case TimepointDataType::SetCondition:
{ {
auto& dataJ = json.at( "data" ); auto& dataJ = json.at( "data" );
@ -322,6 +331,17 @@ namespace Sapphire::Encounter
void Timepoint::execute( TimepointState& state, TimelineActor& self, TimelinePack& pack, TerritoryPtr pTeri, uint64_t time ) const void Timepoint::execute( TimepointState& state, TimelineActor& self, TimelinePack& pack, TerritoryPtr pTeri, uint64_t time ) const
{ {
state.m_startTime = time; state.m_startTime = time;
const auto& players = pTeri->getPlayers();
// send debug msg
if( !m_description.empty() )
{
auto& playerMgr = Common::Service< Sapphire::World::Manager::PlayerMgr >::ref();
for( const auto& player : players )
playerMgr.sendDebug( *player.second, m_description );
}
update( state, self, pack, pTeri, time ); update( state, self, pack, pTeri, time );
} }
@ -357,7 +377,6 @@ namespace Sapphire::Encounter
break; break;
case ActionTargetType::Selector: case ActionTargetType::Selector:
{ {
// todo: selector
const auto& results = pack.getSnapshotTargetIds( pActionData->m_selectorRef ); const auto& results = pack.getSnapshotTargetIds( pActionData->m_selectorRef );
if( pActionData->m_selectorIndex < results.size() ) if( pActionData->m_selectorIndex < results.size() )
targetId = results[ pActionData->m_selectorIndex ]; targetId = results[ pActionData->m_selectorIndex ];
@ -369,8 +388,11 @@ namespace Sapphire::Encounter
auto& actionMgr = Common::Service< Sapphire::World::Manager::ActionMgr >::ref(); auto& actionMgr = Common::Service< Sapphire::World::Manager::ActionMgr >::ref();
// todo: this is probably wrong // todo: this is probably wrong
if( pBNpc->getCurrentAction() && pBNpc->getCurrentAction()->getId() != pActionData->m_actionId ) if( !pBNpc->getCurrentAction() )
actionMgr.handleTargetedAction( *pBNpc.get(), pActionData->m_actionId, targetId, 0 ); {
actionMgr.handleTargetedAction( *pBNpc, pActionData->m_actionId, targetId, 0 );
state.m_finished = true;
}
} }
} }
break; break;
@ -381,8 +403,9 @@ namespace Sapphire::Encounter
if( pBNpc ) if( pBNpc )
{ {
pBNpc->setPos( pSetPosData->m_x, pSetPosData->m_y, pSetPosData->m_z );
pBNpc->setRot( pSetPosData->m_rot ); pBNpc->setRot( pSetPosData->m_rot );
pBNpc->setPos( pSetPosData->m_x, pSetPosData->m_y, pSetPosData->m_z, true );
state.m_finished = true;
} }
} }
break; break;
@ -446,6 +469,7 @@ namespace Sapphire::Encounter
auto handlerId = pHandler ? pHandler->getId() : 0xE0000000; auto handlerId = pHandler ? pHandler->getId() : 0xE0000000;
auto talkerId = pTalker ? pTalker->getId() : 0xE0000000; auto talkerId = pTalker ? pTalker->getId() : 0xE0000000;
// todo: use Actrl EventBattleDialog = 0x39C maybe?,
auto& playerMgr = Common::Service< Sapphire::World::Manager::PlayerMgr >::ref(); auto& playerMgr = Common::Service< Sapphire::World::Manager::PlayerMgr >::ref();
for( auto& player : pTeri->getPlayers() ) for( auto& player : pTeri->getPlayers() )
{ {
@ -650,7 +674,7 @@ namespace Sapphire::Encounter
break; break;
} }
if( m_type != TimepointDataType::SetPos && m_type != TimepointDataType::CastAction ) if( m_type != TimepointDataType::CastAction )
state.m_finished = true; state.m_finished = true;
state.m_finished = state.m_finished || state.m_startTime + m_duration <= time; state.m_finished = state.m_finished || state.m_startTime + m_duration <= time;

View file

@ -150,7 +150,8 @@ namespace Sapphire::Encounter
uint32_t m_params[ 8 ]{ 0 }; uint32_t m_params[ 8 ]{ 0 };
TimepointDataBattleTalk( const std::vector< uint32_t >& params ) : TimepointData( TimepointDataType::BattleTalk ) TimepointDataBattleTalk( const std::vector< uint32_t >& params ) :
TimepointData( TimepointDataType::BattleTalk )
{ {
for( auto i = 0; i < params.size() && i < 8; ++i ) for( auto i = 0; i < params.size() && i < 8; ++i )
m_params[ i ] = params[ i ]; m_params[ i ] = params[ i ];