3445: Add (un)endless_hook command r=heinrich5991 a=def-

As requested by Kicker

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [x] Tested in combination with possibly related configuration options
- [x] Written a unit test if it works standalone, system.c especially
- [x] Considered possible null pointers and out of bounds array indexing
- [x] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2020-12-26 22:21:01 +00:00 committed by GitHub
commit 896881079f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 8 deletions

View file

@ -27,6 +27,8 @@ CONSOLE_COMMAND("unweapons", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConUnWeapons, th
CONSOLE_COMMAND("ninja", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConNinja, this, "Makes you a ninja")
CONSOLE_COMMAND("super", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConSuper, this, "Makes you super")
CONSOLE_COMMAND("unsuper", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConUnSuper, this, "Removes super from you")
CONSOLE_COMMAND("endless_hook", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConEndlessHook, this, "Gives you endless hook")
CONSOLE_COMMAND("unendless_hook", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConUnEndlessHook, this, "Removes endless hook from you")
CONSOLE_COMMAND("unsolo", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConUnSolo, this, "Puts you out of solo part")
CONSOLE_COMMAND("undeep", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConUnDeep, this, "Puts you out of deep freeze")
CONSOLE_COMMAND("left", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConGoLeft, this, "Makes you move 1 tile left")

View file

@ -94,6 +94,30 @@ void CGameContext::ConNinja(IConsole::IResult *pResult, void *pUserData)
pSelf->ModifyWeapons(pResult, pUserData, WEAPON_NINJA, false);
}
void CGameContext::ConEndlessHook(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!CheckClientID(pResult->m_ClientID))
return;
CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientID);
if(pChr)
{
pChr->SetEndlessHook(true);
}
}
void CGameContext::ConUnEndlessHook(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!CheckClientID(pResult->m_ClientID))
return;
CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientID);
if(pChr)
{
pChr->SetEndlessHook(false);
}
}
void CGameContext::ConSuper(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;

View file

@ -1606,17 +1606,13 @@ void CCharacter::HandleTiles(int Index)
m_DeepFreeze = false;
// endless hook
if(((m_TileIndex == TILE_EHOOK_ENABLE) || (m_TileFIndex == TILE_EHOOK_ENABLE)) && !m_EndlessHook)
if(((m_TileIndex == TILE_EHOOK_ENABLE) || (m_TileFIndex == TILE_EHOOK_ENABLE)))
{
GameServer()->SendChatTarget(GetPlayer()->GetCID(), "Endless hook has been activated");
m_EndlessHook = true;
m_Core.m_EndlessHook = true;
SetEndlessHook(true);
}
else if(((m_TileIndex == TILE_EHOOK_DISABLE) || (m_TileFIndex == TILE_EHOOK_DISABLE)) && m_EndlessHook)
else if(((m_TileIndex == TILE_EHOOK_DISABLE) || (m_TileFIndex == TILE_EHOOK_DISABLE)))
{
GameServer()->SendChatTarget(GetPlayer()->GetCID(), "Endless hook has been deactivated");
m_EndlessHook = false;
m_Core.m_EndlessHook = false;
SetEndlessHook(false);
}
// hit others
@ -2355,6 +2351,18 @@ void CCharacter::GiveAllWeapons()
}
}
void CCharacter::SetEndlessHook(bool Enable)
{
if(m_EndlessHook == Enable)
{
return;
}
GameServer()->SendChatTarget(GetPlayer()->GetCID(), Enable ? "Endless hook has been activated" : "Endless hook has been deactived");
m_EndlessHook = Enable;
m_Core.m_EndlessHook = Enable;
}
void CCharacter::Pause(bool Pause)
{
m_Paused = Pause;

View file

@ -82,6 +82,7 @@ public:
void GiveWeapon(int Weapon, bool Remove = false);
void GiveNinja();
void RemoveNinja();
void SetEndlessHook(bool Enable);
void SetEmote(int Emote, int Tick);

View file

@ -297,6 +297,8 @@ private:
static void ConKillPlayer(IConsole::IResult *pResult, void *pUserData);
static void ConNinja(IConsole::IResult *pResult, void *pUserData);
static void ConEndlessHook(IConsole::IResult *pResult, void *pUserData);
static void ConUnEndlessHook(IConsole::IResult *pResult, void *pUserData);
static void ConUnSolo(IConsole::IResult *pResult, void *pUserData);
static void ConUnDeep(IConsole::IResult *pResult, void *pUserData);
static void ConUnSuper(IConsole::IResult *pResult, void *pUserData);