2022-08-07 21:42:56 +00:00
# include "server/hns/HideAndSeekMode.hpp"
2022-06-16 21:33:18 +00:00
# include <cmath>
# include "al/async/FunctorV0M.hpp"
# include "al/util.hpp"
# include "al/util/ControllerUtil.h"
# include "game/GameData/GameDataHolderAccessor.h"
# include "game/Layouts/CoinCounter.h"
# include "game/Layouts/MapMini.h"
2022-08-10 21:11:52 +00:00
# include "game/Player/PlayerActorBase.h"
2022-06-16 21:33:18 +00:00
# include "game/Player/PlayerActorHakoniwa.h"
2022-08-07 21:42:56 +00:00
# include "heap/seadHeapMgr.h"
2022-06-16 21:33:18 +00:00
# include "layouts/HideAndSeekIcon.h"
# include "logger.hpp"
# include "rs/util.hpp"
# include "server/gamemode/GameModeBase.hpp"
# include "server/Client.hpp"
# include "server/gamemode/GameModeTimer.hpp"
2022-08-07 21:42:56 +00:00
# include <heap/seadHeap.h>
# include "server/gamemode/GameModeManager.hpp"
# include "server/gamemode/GameModeFactory.hpp"
2022-06-16 21:33:18 +00:00
# include "basis/seadNew.h"
2022-08-07 21:42:56 +00:00
# include "server/hns/HideAndSeekConfigMenu.hpp"
2022-06-16 21:33:18 +00:00
HideAndSeekMode : : HideAndSeekMode ( const char * name ) : GameModeBase ( name ) { }
void HideAndSeekMode : : init ( const GameModeInitInfo & info ) {
mSceneObjHolder = info . mSceneObjHolder ;
mMode = info . mMode ;
mCurScene = ( StageScene * ) info . mScene ;
mPuppetHolder = info . mPuppetHolder ;
2022-08-07 21:42:56 +00:00
GameModeInfoBase * curGameInfo = GameModeManager : : instance ( ) - > getInfo < HideAndSeekInfo > ( ) ;
2022-06-16 21:33:18 +00:00
2022-08-07 21:42:56 +00:00
if ( curGameInfo ) Logger : : log ( " Gamemode info found: %s %s \n " , GameModeFactory : : getModeString ( curGameInfo - > mMode ) , GameModeFactory : : getModeString ( info . mMode ) ) ;
else Logger : : log ( " No gamemode info found \n " ) ;
2022-06-16 21:33:18 +00:00
if ( curGameInfo & & curGameInfo - > mMode = = mMode ) {
mInfo = ( HideAndSeekInfo * ) curGameInfo ;
mModeTimer = new GameModeTimer ( mInfo - > mHidingTime ) ;
2022-08-07 21:42:56 +00:00
Logger : : log ( " Reinitialized timer with time %d:%.2d \n " , mInfo - > mHidingTime . mMinutes , mInfo - > mHidingTime . mSeconds ) ;
2022-06-16 21:33:18 +00:00
} else {
2022-08-07 21:42:56 +00:00
if ( curGameInfo ) delete curGameInfo ; // attempt to destory previous info before creating new one
mInfo = GameModeManager : : instance ( ) - > createModeInfo < HideAndSeekInfo > ( ) ;
2022-06-16 21:33:18 +00:00
mModeTimer = new GameModeTimer ( ) ;
}
mModeLayout = new HideAndSeekIcon ( " HideAndSeekIcon " , * info . mLayoutInitInfo ) ;
mModeLayout - > showSeeking ( ) ;
mModeTimer - > disableTimer ( ) ;
}
void HideAndSeekMode : : begin ( ) {
mModeLayout - > appear ( ) ;
mIsFirstFrame = true ;
if ( ! mInfo - > mIsPlayerIt ) {
mModeTimer - > enableTimer ( ) ;
mModeLayout - > showHiding ( ) ;
} else {
mModeTimer - > disableTimer ( ) ;
mModeLayout - > showSeeking ( ) ;
}
2022-08-10 21:11:52 +00:00
CoinCounter * coinCollect = mCurScene - > mSceneLayout - > mCoinCollectLyt ;
CoinCounter * coinCounter = mCurScene - > mSceneLayout - > mCoinCountLyt ;
MapMini * compass = mCurScene - > mSceneLayout - > mMapMiniLyt ;
al : : SimpleLayoutAppearWaitEnd * playGuideLyt = mCurScene - > mSceneLayout - > mPlayGuideMenuLyt ;
2022-06-16 21:33:18 +00:00
2022-09-04 09:23:02 +00:00
mInvulnTime = 0 ;
2022-06-16 21:33:18 +00:00
if ( coinCounter - > mIsAlive )
coinCounter - > tryEnd ( ) ;
if ( coinCollect - > mIsAlive )
coinCollect - > tryEnd ( ) ;
if ( compass - > mIsAlive )
compass - > end ( ) ;
if ( playGuideLyt - > mIsAlive )
playGuideLyt - > end ( ) ;
GameModeBase : : begin ( ) ;
}
void HideAndSeekMode : : end ( ) {
mModeLayout - > tryEnd ( ) ;
mModeTimer - > disableTimer ( ) ;
2022-08-10 21:11:52 +00:00
CoinCounter * coinCollect = mCurScene - > mSceneLayout - > mCoinCollectLyt ;
CoinCounter * coinCounter = mCurScene - > mSceneLayout - > mCoinCountLyt ;
MapMini * compass = mCurScene - > mSceneLayout - > mMapMiniLyt ;
al : : SimpleLayoutAppearWaitEnd * playGuideLyt = mCurScene - > mSceneLayout - > mPlayGuideMenuLyt ;
2022-06-16 21:33:18 +00:00
2022-09-04 09:23:02 +00:00
mInvulnTime = 0.0f ;
2022-06-16 21:33:18 +00:00
if ( ! coinCounter - > mIsAlive )
coinCounter - > tryStart ( ) ;
if ( ! coinCollect - > mIsAlive )
coinCollect - > tryStart ( ) ;
if ( ! compass - > mIsAlive )
compass - > appearSlideIn ( ) ;
if ( ! playGuideLyt - > mIsAlive )
playGuideLyt - > appear ( ) ;
GameModeBase : : end ( ) ;
}
void HideAndSeekMode : : update ( ) {
2022-08-10 21:11:52 +00:00
PlayerActorBase * playerBase = rs : : getPlayerActor ( mCurScene ) ;
bool isYukimaru = ! playerBase - > getPlayerInfo ( ) ; // if PlayerInfo is a nullptr, that means we're dealing with the bound bowl racer
2022-06-16 21:33:18 +00:00
if ( mIsFirstFrame ) {
if ( mInfo - > mIsUseGravityCam & & mTicket ) {
al : : startCamera ( mCurScene , mTicket , - 1 ) ;
}
mIsFirstFrame = false ;
}
if ( ! mInfo - > mIsPlayerIt ) {
if ( mInvulnTime > = 5 ) {
2022-08-10 21:11:52 +00:00
if ( playerBase ) {
2022-06-16 21:33:18 +00:00
for ( size_t i = 0 ; i < mPuppetHolder - > getSize ( ) ; i + + )
{
PuppetInfo * curInfo = Client : : getPuppetInfo ( i ) ;
2022-08-07 21:42:56 +00:00
if ( ! curInfo ) {
Logger : : log ( " Checking %d, hit bounds %d-%d \n " , i , mPuppetHolder - > getSize ( ) , Client : : getMaxPlayerCount ( ) ) ;
break ;
}
2022-06-16 21:33:18 +00:00
if ( curInfo - > isConnected & & curInfo - > isInSameStage & & curInfo - > isIt ) {
2022-08-10 21:11:52 +00:00
float pupDist = al : : calcDistance ( playerBase , curInfo - > playerPos ) ; // TODO: remove distance calculations and use hit sensors to determine this
if ( ! isYukimaru ) {
if ( pupDist < 200.f & & ( ( PlayerActorHakoniwa * ) playerBase ) - > mDimKeeper - > is2DModel = = curInfo - > is2D ) {
if ( ! PlayerFunction : : isPlayerDeadStatus ( playerBase ) ) {
GameDataFunction : : killPlayer ( GameDataHolderAccessor ( this ) ) ;
playerBase - > startDemoPuppetable ( ) ;
al : : setVelocityZero ( playerBase ) ;
rs : : faceToCamera ( playerBase ) ;
( ( PlayerActorHakoniwa * ) playerBase ) - > mPlayerAnimator - > endSubAnim ( ) ;
( ( PlayerActorHakoniwa * ) playerBase ) - > mPlayerAnimator - > startAnimDead ( ) ;
mInfo - > mIsPlayerIt = true ;
mModeTimer - > disableTimer ( ) ;
mModeLayout - > showSeeking ( ) ;
Client : : sendTagInfPacket ( ) ;
}
} else if ( PlayerFunction : : isPlayerDeadStatus ( playerBase ) ) {
2022-06-16 21:33:18 +00:00
mInfo - > mIsPlayerIt = true ;
mModeTimer - > disableTimer ( ) ;
mModeLayout - > showSeeking ( ) ;
2022-08-10 21:11:52 +00:00
2022-06-16 21:33:18 +00:00
Client : : sendTagInfPacket ( ) ;
2022-08-10 21:11:52 +00:00
2022-06-16 21:33:18 +00:00
}
}
}
}
}
} else {
mInvulnTime + = Time : : deltaTime ;
}
mModeTimer - > updateTimer ( ) ;
}
2022-08-10 21:11:52 +00:00
if ( mInfo - > mIsUseGravity & & ! isYukimaru ) {
2022-06-16 21:33:18 +00:00
sead : : Vector3f gravity ;
2022-08-10 21:11:52 +00:00
if ( rs : : calcOnGroundNormalOrGravityDir ( & gravity , playerBase , playerBase - > getPlayerCollision ( ) ) ) {
2022-06-16 21:33:18 +00:00
gravity = - gravity ;
al : : normalize ( & gravity ) ;
2022-08-10 21:11:52 +00:00
al : : setGravity ( playerBase , gravity ) ;
al : : setGravity ( ( ( PlayerActorHakoniwa * ) playerBase ) - > mHackCap , gravity ) ;
2022-06-16 21:33:18 +00:00
}
if ( al : : isPadHoldL ( - 1 ) ) {
if ( al : : isPadTriggerRight ( - 1 ) ) {
if ( al : : isActiveCamera ( mTicket ) ) {
al : : endCamera ( mCurScene , mTicket , - 1 , false ) ;
mInfo - > mIsUseGravityCam = false ;
} else {
al : : startCamera ( mCurScene , mTicket , - 1 ) ;
mInfo - > mIsUseGravityCam = true ;
}
}
} else if ( al : : isPadTriggerZL ( - 1 ) ) {
if ( al : : isPadTriggerLeft ( - 1 ) ) {
2022-08-10 21:11:52 +00:00
killMainPlayer ( ( ( PlayerActorHakoniwa * ) playerBase ) ) ;
2022-06-16 21:33:18 +00:00
}
}
}
if ( al : : isPadTriggerUp ( - 1 ) & & ! al : : isPadHoldZL ( - 1 ) )
{
mInfo - > mIsPlayerIt = ! mInfo - > mIsPlayerIt ;
mModeTimer - > toggleTimer ( ) ;
if ( ! mInfo - > mIsPlayerIt ) {
mInvulnTime = 0 ;
mModeLayout - > showHiding ( ) ;
} else {
mModeLayout - > showSeeking ( ) ;
}
Client : : sendTagInfPacket ( ) ;
}
mInfo - > mHidingTime = mModeTimer - > getTime ( ) ;
}