From 585a36dd9d0e4139cb135ddf89b836bdeb0db192 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Tue, 13 Aug 2024 11:02:25 +0200 Subject: [PATCH] Distinguish birthday from finish events This allows us to give birthdays a different effect in the future if we want to. --- datasrc/network.py | 2 ++ src/game/client/components/effects.cpp | 2 +- src/game/client/components/effects.h | 2 +- src/game/client/gameclient.cpp | 7 ++++++- src/game/server/gamecontext.cpp | 12 +++++++++++- src/game/server/gamecontext.h | 3 ++- src/game/server/player.cpp | 2 +- src/game/server/teams.cpp | 2 +- 8 files changed, 25 insertions(+), 7 deletions(-) diff --git a/datasrc/network.py b/datasrc/network.py index f028337d1..1db49da01 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -345,6 +345,8 @@ Objects = [ NetIntAny("m_Angle"), ]), + NetEventEx("Birthday:Common", "birthday@netevent.ddnet.org", []), + NetEventEx("Finish:Common", "finish@netevent.ddnet.org", []), NetObjectEx("MyOwnEvent", "my-own-event@heinrich5991.de", [ diff --git a/src/game/client/components/effects.cpp b/src/game/client/components/effects.cpp index 1d6000baf..d5c7fd608 100644 --- a/src/game/client/components/effects.cpp +++ b/src/game/client/components/effects.cpp @@ -226,7 +226,7 @@ void CEffects::PlayerDeath(vec2 Pos, int ClientId, float Alpha) } } -void CEffects::FinishConfetti(vec2 Pos, float Alpha) +void CEffects::Confetti(vec2 Pos, float Alpha) { ColorRGBA Red(1.0f, 0.4f, 0.4f); ColorRGBA Green(0.4f, 1.0f, 0.4f); diff --git a/src/game/client/components/effects.h b/src/game/client/components/effects.h index f86c27cce..de75e63c9 100644 --- a/src/game/client/components/effects.h +++ b/src/game/client/components/effects.h @@ -30,7 +30,7 @@ public: void PlayerDeath(vec2 Pos, int ClientId, float Alpha = 1.0f); void PowerupShine(vec2 Pos, vec2 Size, float Alpha = 1.0f); void FreezingFlakes(vec2 Pos, vec2 Size, float Alpha = 1.0f); - void FinishConfetti(vec2 Pos, float Alpha = 1.0f); + void Confetti(vec2 Pos, float Alpha = 1.0f); void Update(); }; diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 881ef4f44..3233e9d35 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1183,10 +1183,15 @@ void CGameClient::ProcessEvents() const CNetEvent_HammerHit *pEvent = (const CNetEvent_HammerHit *)Item.m_pData; m_Effects.HammerHit(vec2(pEvent->m_X, pEvent->m_Y), Alpha); } + else if(Item.m_Type == NETEVENTTYPE_BIRTHDAY) + { + const CNetEvent_Birthday *pEvent = (const CNetEvent_Birthday *)Item.m_pData; + m_Effects.Confetti(vec2(pEvent->m_X, pEvent->m_Y), Alpha); + } else if(Item.m_Type == NETEVENTTYPE_FINISH) { const CNetEvent_Finish *pEvent = (const CNetEvent_Finish *)Item.m_pData; - m_Effects.FinishConfetti(vec2(pEvent->m_X, pEvent->m_Y), Alpha); + m_Effects.Confetti(vec2(pEvent->m_X, pEvent->m_Y), Alpha); } else if(Item.m_Type == NETEVENTTYPE_SPAWN) { diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 2f631c3b6..1e3c2524d 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -345,7 +345,17 @@ void CGameContext::CreateDeath(vec2 Pos, int ClientId, CClientMask Mask) } } -void CGameContext::CreateFinishConfetti(vec2 Pos, CClientMask Mask) +void CGameContext::CreateBirthdayEffect(vec2 Pos, CClientMask Mask) +{ + CNetEvent_Birthday *pEvent = m_Events.Create(Mask); + if(pEvent) + { + pEvent->m_X = (int)Pos.x; + pEvent->m_Y = (int)Pos.y; + } +} + +void CGameContext::CreateFinishEffect(vec2 Pos, CClientMask Mask) { CNetEvent_Finish *pEvent = m_Events.Create(Mask); if(pEvent) diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 33d17844a..6005801d3 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -239,7 +239,8 @@ public: void CreateHammerHit(vec2 Pos, CClientMask Mask = CClientMask().set()); void CreatePlayerSpawn(vec2 Pos, CClientMask Mask = CClientMask().set()); void CreateDeath(vec2 Pos, int ClientId, CClientMask Mask = CClientMask().set()); - void CreateFinishConfetti(vec2 Pos, CClientMask Mask = CClientMask().set()); + void CreateBirthdayEffect(vec2 Pos, CClientMask Mask = CClientMask().set()); + void CreateFinishEffect(vec2 Pos, CClientMask Mask = CClientMask().set()); void CreateSound(vec2 Pos, int Sound, CClientMask Mask = CClientMask().set()); void CreateSoundGlobal(int Sound, int Target = -1) const; diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 76d7183a3..d36e631c8 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -937,7 +937,7 @@ void CPlayer::ProcessScoreResult(CScorePlayerResult &Result) GameServer()->SendBroadcast(aBuf, m_ClientId); m_BirthdayAnnounced = true; - GameServer()->CreateFinishConfetti(GetCharacter()->m_Pos, GetCharacter()->TeamMask()); + GameServer()->CreateBirthdayEffect(GetCharacter()->m_Pos, GetCharacter()->TeamMask()); } GameServer()->SendRecord(m_ClientId); break; diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index d7113d57e..5472bd9a1 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -854,7 +854,7 @@ void CGameTeams::OnFinish(CPlayer *Player, int TimeTicks, const char *pTimestamp // Confetti CCharacter *pChar = Player->GetCharacter(); - m_pGameContext->CreateFinishConfetti(pChar->m_Pos, pChar->TeamMask()); + m_pGameContext->CreateFinishEffect(pChar->m_Pos, pChar->TeamMask()); } void CGameTeams::RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team)