Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Punish use of anchor (anvil) against teammates in Team GP #13

Merged
merged 1 commit into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/items/powerup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "utils/string_utils.hpp"
#include "utils/log.hpp" //TODO: remove after debugging is done

#include "network/protocols/server_lobby.hpp"

//-----------------------------------------------------------------------------
/** Constructor, stores the kart to which this powerup belongs.
* \param kart The kart to which this powerup belongs.
Expand Down Expand Up @@ -400,6 +402,11 @@ void Powerup::use()
if(kart == m_kart) continue;
if(kart->getPosition() == 1)
{
// check if we are in team gp and hit a teammate and should punish the attacker
auto sl = LobbyProtocol::get<ServerLobby>();
if(sl && !kart->hasFinishedRace())
sl->handleAnvilHit(m_kart->getWorldKartId(), kart->getWorldKartId());

kart->getAttachment()->set(Attachment::ATTACH_ANVIL,
stk_config->
time2Ticks(kp->getAnvilDuration()) );
Expand Down
58 changes: 58 additions & 0 deletions src/network/protocols/server_lobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9393,3 +9393,61 @@ void ServerLobby::handleSwatterHit(unsigned int ownerID, unsigned int victimID,
m_teammate_swatter_punish.push_back(owner);
}
}

void ServerLobby::handleAnvilHit(unsigned int ownerID, unsigned int victimID)
{
const std::string ownername = StringUtils::wideToUtf8(
RaceManager::get()->getKartInfo(ownerID).getPlayerName());
const int ownerTeam = m_team_for_player[ownername];
if (ownerTeam == 0)
return;

const std::string victimname = StringUtils::wideToUtf8(
RaceManager::get()->getKartInfo(victimID).getPlayerName());
const int victimTeam = m_team_for_player[victimname];
if (victimTeam != ownerTeam)
return;

AbstractKart *owner = World::getWorld()->getKart(ownerID);

// should we tell the world?
if (showTeamMateHits())
{
std::string msg = ServerConfig::m_teammate_hit_msg_prefix;
msg += ownername;
msg += " just gave an anchor to teammate ";
msg += victimname;
sendTeamMateHitMsg(msg);
}
if (useTeamMateHitMode())
{
if (owner->getAttachment()->getType() == Attachment::ATTACH_BOMB)
{
// make bomb explode
owner->getAttachment()->update(10000);
}
else
{
if (owner->isShielded())
{
// if owner is shielded, take away shield
// since the anvil will also destroy the shield of the victim
// we also punish this severely
owner->decreaseShieldTime();
}

// now give anvil to owner
int left_over_ticks = 0;
// if owner already has an anvil or a parachute, make new anvil last longer
if (owner->getAttachment()->getType() == Attachment::ATTACH_ANVIL
|| owner->getAttachment()->getType() == Attachment::ATTACH_PARACHUTE)
{
left_over_ticks = owner->getAttachment()->getTicksLeft();
}
owner->getAttachment()->set(Attachment::ATTACH_ANVIL,
stk_config->time2Ticks(owner->getKartProperties()->getAnvilDuration()) + left_over_ticks);
// the powerup anvil is very strong, copy these values (from powerup.cpp)
owner->adjustSpeed(owner->getKartProperties()->getAnvilSpeedFactor() * 0.5f);
}
}
}
2 changes: 2 additions & 0 deletions src/network/protocols/server_lobby.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ class ServerLobby : public LobbyProtocol

// handle swatters
void handleSwatterHit(unsigned int ownerID, unsigned int victimID, bool success, bool has_hit_kart, uint16_t ticks_active);
// handle anvil
void handleAnvilHit(unsigned int ownerID, unsigned int victimID);

void sendTeamMateHitMsg(std::string& s);
bool showTeamMateHits() const { return m_show_teammate_hits; }
Expand Down