From 84fd70bd2eb6ddffb5452e252adc9c112ac5da10 Mon Sep 17 00:00:00 2001 From: TracentEden <92269743+TracentEden@users.noreply.github.com> Date: Tue, 13 Feb 2024 01:38:34 +0200 Subject: [PATCH] Fix ksnm trial weapon crit mods Co-Authored-By: OpheliaXI --- scripts/enum/mod.lua | 1 + sql/item_latents.sql | 24 ++++++++++++------------ sql/item_mods.sql | 2 +- src/map/entities/battleentity.cpp | 3 ++- src/map/modifier.h | 1 + src/map/utils/battleutils.cpp | 13 ++++++++++++- src/map/utils/battleutils.h | 2 +- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/scripts/enum/mod.lua b/scripts/enum/mod.lua index 6bd72fd7ae4..79d0c65b65b 100644 --- a/scripts/enum/mod.lua +++ b/scripts/enum/mod.lua @@ -225,6 +225,7 @@ xi.mod = DARK_ABSORB = 466, -- Occasionally absorbs dark elemental damage. CRITHITRATE = 165, + CRITHITRATE_ONLY_WEP = 141, CRIT_DMG_INCREASE = 421, RANGED_CRIT_DMG_INCREASE = 964, -- Increases ranged critical damage by a percent ENEMYCRITRATE = 166, diff --git a/sql/item_latents.sql b/sql/item_latents.sql index e1babb9ede7..ad0b7874c06 100644 --- a/sql/item_latents.sql +++ b/sql/item_latents.sql @@ -1699,7 +1699,7 @@ INSERT INTO `item_latents` VALUES (17447,5,20,53,1); -- MP +20 in areas outs INSERT INTO `item_latents` VALUES (17448,13,1,53,1); -- MND +1 in areas outside own nation's control INSERT INTO `item_latents` VALUES (17449,13,2,53,1); -- MND +2 in areas outside own nation's control -INSERT INTO `item_latents` VALUES (17451,165,6,47,0); -- Morgenstern Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (17451,141,6,47,0); -- Morgenstern Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (17451,287,13,47,0); -- Morgenstern DMG+13 when broken (500 WS points) INSERT INTO `item_latents` VALUES (17456,2,-10,47,0); INSERT INTO `item_latents` VALUES (17456,5,-10,47,0); @@ -1734,7 +1734,7 @@ INSERT INTO `item_latents` VALUES (17507,20,-10,47,0); -- Master Caster's baghnakhs -- INSERT INTO `item_latents` VALUES (17508,23,10,?,?); -- Citizens of Windurst: Attack+10 -INSERT INTO `item_latents` VALUES (17509,165,6,47,0); -- Destroyers Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (17509,141,6,47,0); -- Destroyers Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (17509,287,13,47,0); -- Destroyers DMG+13 when broken (500 WS points) INSERT INTO `item_latents` VALUES (17527,2,-10,47,0); INSERT INTO `item_latents` VALUES (17527,5,-10,47,0); @@ -1750,7 +1750,7 @@ INSERT INTO `item_latents` VALUES (17540,5,12,53,1); -- MP +12 in areas outs INSERT INTO `item_latents` VALUES (17581,17,15,31,0); -- Mighty Pole [Element: Wind]+15 on Windsday INSERT INTO `item_latents` VALUES (17581,111,13,31,0); -- Mighty Pole Divine magic skill +13 Windsday INSERT INTO `item_latents` VALUES (17581,115,13,31,0); -- Mighty Pole Elemental magic skill +13 Windsday -INSERT INTO `item_latents` VALUES (17589,165,6,47,0); -- Thyrsusstab Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (17589,141,6,47,0); -- Thyrsusstab Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (17589,287,13,47,0); -- Thyrsusstab DMG+13 when broken (500 WS points) INSERT INTO `item_latents` VALUES (17590,25,10,49,4468); -- Primate Staff (pamamas) INSERT INTO `item_latents` VALUES (17590,25,10,49,4596); -- (wild pamamas) @@ -1822,7 +1822,7 @@ INSERT INTO `item_latents` VALUES (17681,5,20,53,1); -- MP +20 in areas outs INSERT INTO `item_latents` VALUES (17697,17,15,31,0); -- Mighty Talwar [Element: Wind]+15 on Windsday INSERT INTO `item_latents` VALUES (17697,287,8,31,0); -- Mighty Talwar DMG+8 on Windsday -INSERT INTO `item_latents` VALUES (17699,165,6,47,0); -- Dissector Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (17699,141,6,47,0); -- Dissector Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (17699,287,13,47,0); -- Dissector DMG+13 when broken (500 WS points) -- Shiva's Shotel @@ -1867,7 +1867,7 @@ INSERT INTO `item_latents` VALUES (17788,8,4,32,0); -- Sairen STR +4 on Dar INSERT INTO `item_latents` VALUES (17788,27,1,32,0); -- Enmity +1 INSERT INTO `item_latents` VALUES (17791,15,15,28,0); -- Rai Kunimitsu [Element: Fire]+15 on Firesday INSERT INTO `item_latents` VALUES (17791,287,7,28,0); -- Rai Kunimitsu DMG+7 on Firesday -INSERT INTO `item_latents` VALUES (17793,165,6,47,0); -- Senjuinrikio Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (17793,141,6,47,0); -- Senjuinrikio Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (17793,287,13,47,0); -- Senjuinrikio DMG+13 when broken (500 WS points) INSERT INTO `item_latents` VALUES (17804,25,7,59,6); -- Ushikirimaru - Vs. beasts: Accuracy+7 @@ -1882,7 +1882,7 @@ INSERT INTO `item_latents` VALUES (17815,16,-10,47,0); INSERT INTO `item_latents` VALUES (17815,22,-10,47,0); INSERT INTO `item_latents` VALUES (17824,15,15,28,0); -- Nukemaru [Element: Fire]+15 on Firesday INSERT INTO `item_latents` VALUES (17824,287,10,28,0); -- Nukemaru DMG+10 on Firesday -INSERT INTO `item_latents` VALUES (17827,165,6,47,0); -- Michishiba Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (17827,141,6,47,0); -- Michishiba Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (17827,287,13,47,0); -- Michishiba DMG+13 when broken (500 WS points) INSERT INTO `item_latents` VALUES (17831,369,1,13,2); INSERT INTO `item_latents` VALUES (17831,370,1,13,19); @@ -1905,7 +1905,7 @@ INSERT INTO `item_latents` VALUES (17934,23,10,44,0); -- Citizens of San d'Oria: INSERT INTO `item_latents` VALUES (17941,17,15,31,0); -- Mighty Pick [Element: Wind]+15 on Windsday INSERT INTO `item_latents` VALUES (17941,287,5,31,0); -- Mighty Pick DMG+5 on Windsday -INSERT INTO `item_latents` VALUES (17944,165,6,47,0); -- Retributor Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (17944,141,6,47,0); -- Retributor Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (17944,287,13,47,0); -- Retributor DMG+13 when broken (500 WS points) -- Maneater @@ -1967,7 +1967,7 @@ INSERT INTO `item_latents` VALUES (17991,5,16,53,1); -- MP +16 in areas outs INSERT INTO `item_latents` VALUES (18000,17,15,31,0); -- Mighty Knife [Element: Wind]+15 on Windsday INSERT INTO `item_latents` VALUES (18000,287,10,31,0); -- Mighty Knife DMG+10 on Windsday -INSERT INTO `item_latents` VALUES (18005,165,6,47,0); -- Heart Snatcher Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (18005,141,6,47,0); -- Heart Snatcher Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (18005,287,15,47,0); -- Heart Snatcher DMG+15 when broken (500 WS points) -- Blau Dolch @@ -1984,7 +1984,7 @@ INSERT INTO `item_latents` VALUES (18036,5,10,53,1); -- MP +10 in areas outs INSERT INTO `item_latents` VALUES (18037,5,12,53,1); -- MP +12 in areas outside own nation's control INSERT INTO `item_latents` VALUES (18049,17,15,31,0); -- Mighty Zaghnal [Element: Wind]+15 on Windsday INSERT INTO `item_latents` VALUES (18049,287,8,31,0); -- Mighty Zaghnal DMG+8 on Windsday -INSERT INTO `item_latents` VALUES (18053,165,6,47,0); -- Gravedigger Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (18053,141,6,47,0); -- Gravedigger Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (18053,287,13,47,0); -- Gravedigger DMG+13 when broken (500 WS points) -- Garuda's Sickle @@ -2010,7 +2010,7 @@ INSERT INTO `item_latents` VALUES (18084,369,-3,56,0); -- Rune Halberd -3MP/ti INSERT INTO `item_latents` VALUES (18091,15,15,28,0); -- Mighty Lance [Element: Fire]+15 on Firesday INSERT INTO `item_latents` VALUES (18091,287,12,28,0); -- Mighty Lance DMG+12 on Firesday -INSERT INTO `item_latents` VALUES (18097,165,6,47,0); -- Gondo-Shizunori Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (18097,141,6,47,0); -- Gondo-Shizunori Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (18097,287,13,47,0); -- Gondo-Shizunori DMG+13 when broken (500 WS points) -- Stone-splitter @@ -2056,7 +2056,7 @@ INSERT INTO `item_latents` VALUES (18206,369,-3,56,0); -- Rune Chopper -3MP/ti INSERT INTO `item_latents` VALUES (18206,384,900,56,0); -- Rune Chopper +9% haste INSERT INTO `item_latents` VALUES (18213,15,15,28,0); -- Mighty Axe [Element: Fire]+15 on Firesday INSERT INTO `item_latents` VALUES (18213,287,10,28,0); -- Mighty Axe DMG+10 on Firesday -INSERT INTO `item_latents` VALUES (18217,165,6,47,0); -- Rampager Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (18217,141,6,47,0); -- Rampager Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (18217,287,13,47,0); -- Rampager DMG+13 when broken (500 WS points) INSERT INTO `item_latents` VALUES (18256,23,1,25,0); -- Orphic Egg,ATT+1 song/roll active INSERT INTO `item_latents` VALUES (18256,25,1,25,0); -- Orphic Egg,ACC+1 song/roll active @@ -2198,7 +2198,7 @@ INSERT INTO `item_latents` VALUES (18364,287,2,58,0); -- Pahluwan Katars dmg INSERT INTO `item_latents` VALUES (18364,291,1,58,0); -- counter +1 INSERT INTO `item_latents` VALUES (18374,15,15,28,0); -- Mighty Sword [Element: Fire]+15 INSERT INTO `item_latents` VALUES (18374,287,9,28,0); -- Mighty Sword DMG+9 on Firesday -INSERT INTO `item_latents` VALUES (18378,165,6,47,0); -- Subduer Crit Rate +6% when broken (500 WS points) +INSERT INTO `item_latents` VALUES (18378,141,6,47,0); -- Subduer Crit Rate +6% (for this weapon only) when broken (500 WS points) INSERT INTO `item_latents` VALUES (18378,287,13,47,0); -- Subduer DMG+13 when broken (500 WS points) INSERT INTO `item_latents` VALUES (18387,25,5,58,0); -- Djinnbringer Accuracy +5 in Assault INSERT INTO `item_latents` VALUES (18387,287,3,58,0); -- Djinnbringer DMG+3 in Assault diff --git a/sql/item_mods.sql b/sql/item_mods.sql index 43841c4c2f5..bb3db4f852b 100644 --- a/sql/item_mods.sql +++ b/sql/item_mods.sql @@ -32750,7 +32750,7 @@ INSERT INTO `item_mods` VALUES (16897,953,20); -- ITEM_ADDEFFECT_DURATION: 20 INSERT INTO `item_mods` VALUES (16899,25,3); -- ACC: 3 -- Fudo -INSERT INTO `item_mods` VALUES (16904,165,3); -- CRITHITRATE: 3 +INSERT INTO `item_mods` VALUES (16904,141,3); -- CRITHITRATE_ONLY_WEP: 3 -- Bokuto INSERT INTO `item_mods` VALUES (16905,431,2); -- ITEM_ADDEFFECT_TYPE: DEBUFF diff --git a/src/map/entities/battleentity.cpp b/src/map/entities/battleentity.cpp index 003c6438db3..dcb024d7174 100644 --- a/src/map/entities/battleentity.cpp +++ b/src/map/entities/battleentity.cpp @@ -2272,8 +2272,9 @@ bool CBattleEntity::OnAttack(CAttackState& state, action_t& action) } else { + SLOTTYPE weaponSlot = static_cast(attack.GetWeaponSlot()); // Set this attack's critical flag. - attack.SetCritical(xirand::GetRandomNumber(100) < battleutils::GetCritHitRate(this, PTarget, !attack.IsFirstSwing())); + attack.SetCritical(xirand::GetRandomNumber(100) < battleutils::GetCritHitRate(this, PTarget, !attack.IsFirstSwing(), weaponSlot)); this->PAI->EventHandler.triggerListener("MELEE_SWING_HIT", CLuaBaseEntity(this), CLuaBaseEntity(PTarget), CLuaAttack(&attack)); diff --git a/src/map/modifier.h b/src/map/modifier.h index b6dda0aa66f..ff8b6e173bc 100644 --- a/src/map/modifier.h +++ b/src/map/modifier.h @@ -250,6 +250,7 @@ enum class Mod // Crit Damage / Delay CRITHITRATE = 165, // Raises chance to crit + CRITHITRATE_ONLY_WEP = 141, // Raises chance to crit (but only for attacks with the specific weapon that has the mod) CRIT_DMG_INCREASE = 421, // Raises the damage of critical hit by percent % RANGED_CRIT_DMG_INCREASE = 964, // Increases ranged critical damage by a percent ENEMYCRITRATE = 166, // Raises chance enemy will crit diff --git a/src/map/utils/battleutils.cpp b/src/map/utils/battleutils.cpp index bb306ee6c7d..d55a1ce73d0 100644 --- a/src/map/utils/battleutils.cpp +++ b/src/map/utils/battleutils.cpp @@ -2747,7 +2747,7 @@ namespace battleutils * * ************************************************************************/ - uint8 GetCritHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, bool ignoreSneakTrickAttack) + uint8 GetCritHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, bool ignoreSneakTrickAttack, SLOTTYPE weaponSlot) { int32 critHitRate = 5; if (PAttacker->StatusEffectContainer->HasStatusEffect(EFFECT_MIGHTY_STRIKES, 0) || @@ -2810,6 +2810,17 @@ namespace battleutils critHitRate += GetDexCritBonus(PAttacker, PDefender); critHitRate += PAttacker->getMod(Mod::CRITHITRATE); critHitRate += PDefender->getMod(Mod::ENEMYCRITRATE); + + // need to check for mods that only impact attacks with a specific weapon (like Senjuinrikio) + if (auto* player = dynamic_cast(PAttacker)) + { + auto* weapon = dynamic_cast(player->getEquip(weaponSlot)); + if (weapon && weapon->getModifier(Mod::CRITHITRATE_ONLY_WEP) > 0) + { + critHitRate += weapon->getModifier(Mod::CRITHITRATE_ONLY_WEP); + } + } + critHitRate = std::clamp(critHitRate, 0, 100); } return (uint8)critHitRate; diff --git a/src/map/utils/battleutils.h b/src/map/utils/battleutils.h index 9cbfa787584..0f71fd1eed2 100644 --- a/src/map/utils/battleutils.h +++ b/src/map/utils/battleutils.h @@ -144,7 +144,7 @@ namespace battleutils uint8 GetHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender); uint8 GetHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint8 attackNumber); uint8 GetHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint8 attackNumber, int8 offsetAccuracy); - uint8 GetCritHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, bool ignoreSneakTrickAttack); + uint8 GetCritHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, bool ignoreSneakTrickAttack, SLOTTYPE weaponSlot = SLOT_MAIN); uint8 GetRangedCritHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender); int8 GetDexCritBonus(CBattleEntity* PAttacker, CBattleEntity* PDefender); int8 GetAGICritBonus(CBattleEntity* PAttacker, CBattleEntity* PDefender);