From 42af1aa97b804c7824193b1769189a1f0288c635 Mon Sep 17 00:00:00 2001 From: Engels Quintero Date: Fri, 20 Aug 2021 10:39:06 -0400 Subject: [PATCH] Added action to reduce HP and/or MP from player --- README.md | 18 ++++++++++++++++++ vSRO-GameServer/AppManager.cpp | 13 +++++++++++++ vSRO-GameServer/Silkroad/Object/CGObjPC.cpp | 14 ++++++++++++-- vSRO-GameServer/Silkroad/Object/CGObjPC.h | 4 ++-- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ec8c30d..b0f5bb9 100644 --- a/README.md +++ b/README.md @@ -358,6 +358,24 @@ VALUES ); ``` +19. Reduces health and/or mana points from player +```sql +INSERT INTO [SRO_VT_SHARD].[dbo].[_ExeGameServer] +( + Action_ID, + CharName16, + Param02, -- HP reduced + Param02 -- MP reduced +) +VALUES +( + 19, + 'JellyBitz', + 5000, -- Reducing HP only + 0 +); +``` + ### Action Result Code diff --git a/vSRO-GameServer/AppManager.cpp b/vSRO-GameServer/AppManager.cpp index 425fd68..af7375a 100644 --- a/vSRO-GameServer/AppManager.cpp +++ b/vSRO-GameServer/AppManager.cpp @@ -927,6 +927,19 @@ DWORD WINAPI AppManager::DatabaseFetchThread() actionResult = FETCH_ACTION_STATE::CHARNAME_NOT_FOUND; } } break; + case 19: + { + SQLINTEGER cParam02, cParam03, cParam04; + if (m_dbLink.sqlCmd.GetData(5, SQL_C_LONG, &cParam02, 0, NULL) + && m_dbLink.sqlCmd.GetData(6, SQL_C_LONG, &cParam03, 0, NULL)) + { + CGObjPC* player = CGObjManager::GetObjPCByCharName16(cCharName); + if (player) + player->ReduceHPMP(cParam02, cParam03, true); + else + actionResult = FETCH_ACTION_STATE::CHARNAME_NOT_FOUND; + } + } break; case 3312: // For testing references { CGObjPC* player = CGObjManager::GetObjPCByCharName16(cCharName); diff --git a/vSRO-GameServer/Silkroad/Object/CGObjPC.cpp b/vSRO-GameServer/Silkroad/Object/CGObjPC.cpp index 33c99f7..4a282cd 100644 --- a/vSRO-GameServer/Silkroad/Object/CGObjPC.cpp +++ b/vSRO-GameServer/Silkroad/Object/CGObjPC.cpp @@ -42,9 +42,19 @@ void CGObjPC::UpdateSP(int32_t Offset) { CallVirtual(this, 93)(this, Offset, 1); } -void CGObjPC::UpdateHPMP(int32_t Health, int32_t Mana, uint16_t DisplayEffectType) +void CGObjPC::ReduceHPMP(uint32_t Health, uint32_t Mana, bool ShowEffect) { - CallVirtual(this, 194)(this, Health, Mana, DisplayEffectType); + // Check if player will die by health reduction + bool died = Health > m_CInstancePC->CurHealth; + if (died) + { + Health = m_CInstancePC->CurHealth; + Mana = m_CInstancePC->CurMana; + } + CallVirtual(this, 194)(this, Health, Mana, ShowEffect ? 1024 : 0); + // Set dead status + if (died) + SetLifeState(false); } void CGObjPC::UpdatePVPCapeType(uint8_t CapeType) { diff --git a/vSRO-GameServer/Silkroad/Object/CGObjPC.h b/vSRO-GameServer/Silkroad/Object/CGObjPC.h index fe1f6ec..b1ae92c 100644 --- a/vSRO-GameServer/Silkroad/Object/CGObjPC.h +++ b/vSRO-GameServer/Silkroad/Object/CGObjPC.h @@ -29,8 +29,8 @@ class CGObjPC : public CGObjChar void UpdateExperience(int64_t ExpOffset); // Add skill experience void AddSPExperience(uint32_t SPExpOffset); - // Updates the HP and MP - void UpdateHPMP(int32_t Health, int32_t Mana, uint16_t DisplayEffectType); + // Reduces health and/or mana points. If health reduced exceeds the current amount, the player will die + void ReduceHPMP(uint32_t Health, uint32_t Mana, bool ShowEffect); // Updates the cape state from PVP void UpdatePVPCapeType(uint8_t CapeType); // Moves the player to the map location. Return success