CCharacter: Move start/finish tiles handling to the DDRace Controller

This commit is contained in:
Alexander Akulich 2021-01-13 01:54:46 +03:00
parent acfb541db9
commit f7dfd8c9b9
3 changed files with 62 additions and 49 deletions

View file

@ -1448,19 +1448,6 @@ void CCharacter::HandleTiles(int Index)
m_TileIndex = GameServer()->Collision()->GetTileIndex(MapIndex); m_TileIndex = GameServer()->Collision()->GetTileIndex(MapIndex);
m_TileFIndex = GameServer()->Collision()->GetFTileIndex(MapIndex); m_TileFIndex = GameServer()->Collision()->GetFTileIndex(MapIndex);
m_MoveRestrictions = GameServer()->Collision()->GetMoveRestrictions(IsSwitchActiveCb, this, m_Pos, 18.0f, MapIndex); m_MoveRestrictions = GameServer()->Collision()->GetMoveRestrictions(IsSwitchActiveCb, this, m_Pos, 18.0f, MapIndex);
//Sensitivity
int S1 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x + GetProximityRadius() / 3.f, m_Pos.y - GetProximityRadius() / 3.f));
int S2 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x + GetProximityRadius() / 3.f, m_Pos.y + GetProximityRadius() / 3.f));
int S3 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x - GetProximityRadius() / 3.f, m_Pos.y - GetProximityRadius() / 3.f));
int S4 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x - GetProximityRadius() / 3.f, m_Pos.y + GetProximityRadius() / 3.f));
int Tile1 = GameServer()->Collision()->GetTileIndex(S1);
int Tile2 = GameServer()->Collision()->GetTileIndex(S2);
int Tile3 = GameServer()->Collision()->GetTileIndex(S3);
int Tile4 = GameServer()->Collision()->GetTileIndex(S4);
int FTile1 = GameServer()->Collision()->GetFTileIndex(S1);
int FTile2 = GameServer()->Collision()->GetFTileIndex(S2);
int FTile3 = GameServer()->Collision()->GetFTileIndex(S3);
int FTile4 = GameServer()->Collision()->GetFTileIndex(S4);
if(Index < 0) if(Index < 0)
{ {
m_LastRefillJumps = false; m_LastRefillJumps = false;
@ -1526,42 +1513,6 @@ void CCharacter::HandleTiles(int Index)
GameServer()->m_pController->HandleCharacterTiles(this, Index); GameServer()->m_pController->HandleCharacterTiles(this, Index);
// start
if(((m_TileIndex == TILE_START) || (m_TileFIndex == TILE_START) || FTile1 == TILE_START || FTile2 == TILE_START || FTile3 == TILE_START || FTile4 == TILE_START || Tile1 == TILE_START || Tile2 == TILE_START || Tile3 == TILE_START || Tile4 == TILE_START) && (m_DDRaceState == DDRACE_NONE || m_DDRaceState == DDRACE_FINISHED || (m_DDRaceState == DDRACE_STARTED && !Team() && g_Config.m_SvTeam != 3)))
{
if(Teams()->GetSaving(Team()))
{
if(m_LastStartWarning < Server()->Tick() - 3 * Server()->TickSpeed())
{
GameServer()->SendChatTarget(GetPlayer()->GetCID(), "You can't start while loading/saving of team is in progress");
m_LastStartWarning = Server()->Tick();
}
Die(GetPlayer()->GetCID(), WEAPON_WORLD);
return;
}
if(g_Config.m_SvTeam == 2 && (Team() == TEAM_FLOCK || Teams()->Count(Team()) <= 1))
{
if(m_LastStartWarning < Server()->Tick() - 3 * Server()->TickSpeed())
{
GameServer()->SendChatTarget(GetPlayer()->GetCID(), "You have to be in a team with other tees to start");
m_LastStartWarning = Server()->Tick();
}
Die(GetPlayer()->GetCID(), WEAPON_WORLD);
return;
}
if(g_Config.m_SvResetPickups)
{
ResetPickups();
}
Teams()->OnCharacterStart(m_pPlayer->GetCID());
m_CpActive = -2;
}
// finish
if(((m_TileIndex == TILE_FINISH) || (m_TileFIndex == TILE_FINISH) || FTile1 == TILE_FINISH || FTile2 == TILE_FINISH || FTile3 == TILE_FINISH || FTile4 == TILE_FINISH || Tile1 == TILE_FINISH || Tile2 == TILE_FINISH || Tile3 == TILE_FINISH || Tile4 == TILE_FINISH) && m_DDRaceState == DDRACE_STARTED)
Controller->m_Teams.OnCharacterFinish(m_pPlayer->GetCID());
// freeze // freeze
if(((m_TileIndex == TILE_FREEZE) || (m_TileFIndex == TILE_FREEZE)) && !m_Super && !m_DeepFreeze) if(((m_TileIndex == TILE_FREEZE) || (m_TileFIndex == TILE_FREEZE)) && !m_Super && !m_DeepFreeze)
Freeze(); Freeze();

View file

@ -22,6 +22,66 @@ CGameControllerDDRace::~CGameControllerDDRace()
// Nothing to clean // Nothing to clean
} }
void CGameControllerDDRace::HandleCharacterTiles(CCharacter *pChr, int MapIndex)
{
CPlayer *pPlayer = pChr->GetPlayer();
int ClientID = pPlayer->GetCID();
int m_TileIndex = GameServer()->Collision()->GetTileIndex(MapIndex);
int m_TileFIndex = GameServer()->Collision()->GetFTileIndex(MapIndex);
//Sensitivity
int S1 = GameServer()->Collision()->GetPureMapIndex(vec2(pChr->GetPos().x + pChr->GetProximityRadius() / 3.f, pChr->GetPos().y - pChr->GetProximityRadius() / 3.f));
int S2 = GameServer()->Collision()->GetPureMapIndex(vec2(pChr->GetPos().x + pChr->GetProximityRadius() / 3.f, pChr->GetPos().y + pChr->GetProximityRadius() / 3.f));
int S3 = GameServer()->Collision()->GetPureMapIndex(vec2(pChr->GetPos().x - pChr->GetProximityRadius() / 3.f, pChr->GetPos().y - pChr->GetProximityRadius() / 3.f));
int S4 = GameServer()->Collision()->GetPureMapIndex(vec2(pChr->GetPos().x - pChr->GetProximityRadius() / 3.f, pChr->GetPos().y + pChr->GetProximityRadius() / 3.f));
int Tile1 = GameServer()->Collision()->GetTileIndex(S1);
int Tile2 = GameServer()->Collision()->GetTileIndex(S2);
int Tile3 = GameServer()->Collision()->GetTileIndex(S3);
int Tile4 = GameServer()->Collision()->GetTileIndex(S4);
int FTile1 = GameServer()->Collision()->GetFTileIndex(S1);
int FTile2 = GameServer()->Collision()->GetFTileIndex(S2);
int FTile3 = GameServer()->Collision()->GetFTileIndex(S3);
int FTile4 = GameServer()->Collision()->GetFTileIndex(S4);
const int PlayerDDRaceState = pChr->m_DDRaceState;
// start
if(((m_TileIndex == TILE_START) || (m_TileFIndex == TILE_START) || FTile1 == TILE_START || FTile2 == TILE_START || FTile3 == TILE_START || FTile4 == TILE_START || Tile1 == TILE_START || Tile2 == TILE_START || Tile3 == TILE_START || Tile4 == TILE_START) && (PlayerDDRaceState == DDRACE_NONE || PlayerDDRaceState == DDRACE_FINISHED || (PlayerDDRaceState == DDRACE_STARTED && !GetPlayerTeam(ClientID) && g_Config.m_SvTeam != 3)))
{
if(m_Teams.GetSaving(GetPlayerTeam(ClientID)))
{
if(pChr->m_LastStartWarning < Server()->Tick() - 3 * Server()->TickSpeed())
{
GameServer()->SendChatTarget(ClientID, "You can't start while loading/saving of team is in progress");
pChr->m_LastStartWarning = Server()->Tick();
}
pChr->Die(ClientID, WEAPON_WORLD);
return;
}
if(g_Config.m_SvTeam == 2 && (GetPlayerTeam(ClientID) == TEAM_FLOCK || m_Teams.Count(GetPlayerTeam(ClientID)) <= 1))
{
if(pChr->m_LastStartWarning < Server()->Tick() - 3 * Server()->TickSpeed())
{
GameServer()->SendChatTarget(ClientID, "You have to be in a team with other tees to start");
pChr->m_LastStartWarning = Server()->Tick();
}
pChr->Die(ClientID, WEAPON_WORLD);
return;
}
if(g_Config.m_SvResetPickups)
{
pChr->ResetPickups();
}
m_Teams.OnCharacterStart(ClientID);
pChr->m_CpActive = -2;
}
// finish
if(((m_TileIndex == TILE_FINISH) || (m_TileFIndex == TILE_FINISH) || FTile1 == TILE_FINISH || FTile2 == TILE_FINISH || FTile3 == TILE_FINISH || FTile4 == TILE_FINISH || Tile1 == TILE_FINISH || Tile2 == TILE_FINISH || Tile3 == TILE_FINISH || Tile4 == TILE_FINISH) && PlayerDDRaceState == DDRACE_STARTED)
m_Teams.OnCharacterFinish(ClientID);
}
void CGameControllerDDRace::OnPlayerDisconnect(CPlayer *pPlayer, const char *pReason) void CGameControllerDDRace::OnPlayerDisconnect(CPlayer *pPlayer, const char *pReason)
{ {
int ClientID = pPlayer->GetCID(); int ClientID = pPlayer->GetCID();

View file

@ -15,6 +15,8 @@ public:
CGameControllerDDRace(class CGameContext *pGameServer); CGameControllerDDRace(class CGameContext *pGameServer);
~CGameControllerDDRace(); ~CGameControllerDDRace();
void HandleCharacterTiles(class CCharacter *pChr, int MapIndex) override;
void OnPlayerDisconnect(class CPlayer *pPlayer, const char *pReason) override; void OnPlayerDisconnect(class CPlayer *pPlayer, const char *pReason) override;
void Tick() override; void Tick() override;