Skip to content

Commit

Permalink
Merge pull request #5406 from CatsAndBoats/random_Deal
Browse files Browse the repository at this point in the history
[core] Random deal functionality
  • Loading branch information
claywar authored Apr 15, 2024
2 parents f8c5982 + 5c7bee3 commit 0655eff
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 6 deletions.
21 changes: 21 additions & 0 deletions scripts/actions/abilities/random_deal.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----------------------------------
-- Ability: Random Deal
-- Has the possibility of resetting the reuse time of a job ability for each party member within area of effect.
-- Obtained: Corsair Level 50
-- Recast Time: 0:20:00
-- Duration: Instant
-----------------------------------
local abilityObject = {}

abilityObject.onAbilityCheck = function(player, target, ability)
return 0, 0
end

abilityObject.onUseAbility = function(caster, target, ability, action)
ability:setMsg(xi.msg.basic.JA_RECEIVES_EFFECT_3)
if not caster:doRandomDeal(target) then
ability:setMsg(xi.msg.basic.JA_MISS_2)
end
end

return abilityObject
1 change: 1 addition & 0 deletions scripts/enum/mod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ xi.mod =
DAY_NUKE_BONUS = 565, -- Bonus damage from "Elemental magic affected by day" (Sorc. Tonban)
IRIDESCENCE = 566, -- Iridescence trait (additional weather damage/penalty)
BARSPELL_AMOUNT = 567, -- Additional elemental resistance granted by bar- spells
RANDOM_DEAL_BONUS = 220, -- % chance to reset 2 abilities
BARSPELL_MDEF_BONUS = 827, -- Extra magic defense bonus granted to the bar- spell effect
RAPTURE_AMOUNT = 568, -- Bonus amount added to Rapture effect
EBULLIENCE_AMOUNT = 569, -- Bonus amount added to Ebullience effect
Expand Down
1 change: 1 addition & 0 deletions scripts/enum/msg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ xi.msg.basic =
JA_REMOVE_EFFECT_2 = 321, -- <user> uses <ability>. <target>'s <status> wears off.
JA_NO_EFFECT_2 = 323, -- <user> uses <ability>. No effect on <target>. (2 line msg)
JA_MISS_2 = 324, -- <user> uses <ability>, but misses <target>. (includes target name)
JA_RECEIVES_EFFECT_3 = 441, -- <user> receives the effect of <ability>.
JA_RECOVERS_MP = 451, -- <user> uses <ability>. <target> regains <amount> MP.
JA_ATK_ENHANCED = 285, -- <target>'s attacks are enhanced.
STATUS_BOOST = 364, -- <user> uses <ability>. All of <target>'s status parameters are boosted.
Expand Down
7 changes: 6 additions & 1 deletion sql/item_mods.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2625,6 +2625,7 @@ INSERT INTO `item_mods` VALUES (10686,8,5); -- STR: 5
INSERT INTO `item_mods` VALUES (10686,11,5); -- AGI: 5
INSERT INTO `item_mods` VALUES (10686,24,12); -- RATT: 12
INSERT INTO `item_mods` VALUES (10686,25,12); -- ACC: 12
INSERT INTO `item_mods` VALUES (10686,220,5); -- RANDOM_DEAL_BONUS: 5

-- Pantin Tobe +2
INSERT INTO `item_mods` VALUES (10687,1,59); -- DEF: 59
Expand Down Expand Up @@ -6157,12 +6158,14 @@ INSERT INTO `item_mods` VALUES (11295,1,45); -- DEF: 45
INSERT INTO `item_mods` VALUES (11295,8,3); -- STR: 3
INSERT INTO `item_mods` VALUES (11295,24,8); -- RATT: 8
INSERT INTO `item_mods` VALUES (11295,25,8); -- ACC: 8
INSERT INTO `item_mods` VALUES (11295,220,5); -- RANDOM_DEAL_BONUS: 5

-- Commodore Frac +1
INSERT INTO `item_mods` VALUES (11296,1,46); -- DEF: 46
INSERT INTO `item_mods` VALUES (11296,8,3); -- STR: 3
INSERT INTO `item_mods` VALUES (11296,24,10); -- RATT: 10
INSERT INTO `item_mods` VALUES (11296,25,10); -- ACC: 10
INSERT INTO `item_mods` VALUES (11296,220,5); -- RANDOM_DEAL_BONUS: 5

-- Puppetry Tobe +1
INSERT INTO `item_mods` VALUES (11297,1,37); -- DEF: 37
Expand Down Expand Up @@ -48691,7 +48694,7 @@ INSERT INTO `item_mods` VALUES (23146,31,74); -- MEVA: 74
INSERT INTO `item_mods` VALUES (23146,68,59); -- EVA: 59
INSERT INTO `item_mods` VALUES (23146,161,-500); -- DMGPHYS: -5%
INSERT INTO `item_mods` VALUES (23146,384,400); -- HASTE_GEAR: 4%
-- TODO: "Random Deal" effect +50: Occasionally allows Random Deal to restore two used job abilities.
INSERT INTO `item_mods` VALUES (23146,220,50); -- RANDOM_DEAL_BONUS: 50

-- Pitre Tobe +2
INSERT INTO `item_mods` VALUES (23147,1,143); -- DEF: 143
Expand Down Expand Up @@ -64328,6 +64331,7 @@ INSERT INTO `item_mods` VALUES (26832,31,43); -- MEVA: 43
INSERT INTO `item_mods` VALUES (26832,68,23); -- EVA: 23
INSERT INTO `item_mods` VALUES (26832,161,-300); -- DMGPHYS: -300
INSERT INTO `item_mods` VALUES (26832,384,400); -- HASTE_GEAR: 400
INSERT INTO `item_mods` VALUES (26832,220,50); -- RANDOM_DEAL_BONUS: 50

-- Lanun Frac +1
INSERT INTO `item_mods` VALUES (26833,1,131); -- DEF: 131
Expand All @@ -64348,6 +64352,7 @@ INSERT INTO `item_mods` VALUES (26833,31,64); -- MEVA: 64
INSERT INTO `item_mods` VALUES (26833,68,49); -- EVA: 49
INSERT INTO `item_mods` VALUES (26833,161,-400); -- DMGPHYS: -400
INSERT INTO `item_mods` VALUES (26833,384,400); -- HASTE_GEAR: 400
INSERT INTO `item_mods` VALUES (26833,220,50); -- RANDOM_DEAL_BONUS: 50

-- Pitre Tobe
INSERT INTO `item_mods` VALUES (26834,1,94); -- DEF: 94
Expand Down
4 changes: 2 additions & 2 deletions sql/traits.sql
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ INSERT INTO `traits` VALUES (89,'strafe',14,60,3,986,25,'TOAU',0);
INSERT INTO `traits` VALUES (89,'strafe',14,80,4,986,30,'TOAU',0);
INSERT INTO `traits` VALUES (90,'enchainment',16,75,1,0,0,'TOAU',0);
INSERT INTO `traits` VALUES (91,'assimilation',16,75,1,0,0,'TOAU',0);
INSERT INTO `traits` VALUES (92,'winning streak',17,75,1,0,0,'TOAU',0);
INSERT INTO `traits` VALUES (93,'loaded deck',17,75,1,0,0,'TOAU',0);
INSERT INTO `traits` VALUES (92,'winning streak',17,75,1,0,0,'TOAU',3076);
INSERT INTO `traits` VALUES (93,'loaded deck',17,75,1,0,0,'TOAU',3078);
INSERT INTO `traits` VALUES (94,'fine-tuning',18,75,1,0,0,'TOAU',3140);
INSERT INTO `traits` VALUES (95,'optimization',18,75,1,0,0,'TOAU',3142);
INSERT INTO `traits` VALUES (96,'closed position',19,75,1,0,0,'WOTG',3206);
Expand Down
24 changes: 24 additions & 0 deletions src/map/lua/lua_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13063,6 +13063,29 @@ void CLuaBaseEntity::doWildCard(CLuaBaseEntity* PEntity, uint8 total)
battleutils::DoWildCardToEntity(static_cast<CCharEntity*>(m_PBaseEntity), static_cast<CCharEntity*>(PEntity->m_PBaseEntity), total);
}

/************************************************************************
* Function: doRandomDeal()
* Purpose : Executes the Random Deal job ability
* Example : player:doRandomDeal(target)
* Notes : Calls the DoRandomDealToEntity function of battleutils
************************************************************************/
bool CLuaBaseEntity::doRandomDeal(CLuaBaseEntity* PTarget)
{
if (m_PBaseEntity->objtype != TYPE_PC)
{
ShowWarning("Invalid entity type calling function (%s).", m_PBaseEntity->getName());
return false;
}

if (!PTarget || !PTarget->m_PBaseEntity)
{
ShowWarning("Invalid entity type passed as target (%s).", m_PBaseEntity->getName());
return false;
}

return battleutils::DoRandomDealToEntity(static_cast<CCharEntity*>(m_PBaseEntity), static_cast<CCharEntity*>(PTarget->m_PBaseEntity));
}

/************************************************************************
* Function: addCorsairRoll()
* Purpose : Adds the Corsair Roll to the Target's Status Effect Container
Expand Down Expand Up @@ -17815,6 +17838,7 @@ void CLuaBaseEntity::Register()

SOL_REGISTER("fold", CLuaBaseEntity::fold);
SOL_REGISTER("doWildCard", CLuaBaseEntity::doWildCard);
SOL_REGISTER("doRandomDeal", CLuaBaseEntity::doRandomDeal);
SOL_REGISTER("addCorsairRoll", CLuaBaseEntity::addCorsairRoll);
SOL_REGISTER("hasCorsairEffect", CLuaBaseEntity::hasCorsairEffect);
SOL_REGISTER("hasBustEffect", CLuaBaseEntity::hasBustEffect);
Expand Down
1 change: 1 addition & 0 deletions src/map/lua/lua_baseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ class CLuaBaseEntity

void fold();
void doWildCard(CLuaBaseEntity* PEntity, uint8 total);
bool doRandomDeal(CLuaBaseEntity* PTarget);
bool addCorsairRoll(uint8 casterJob, uint8 bustDuration, uint16 effectID, uint16 power, uint32 tick, uint32 duration,
sol::object const& arg6, sol::object const& arg7, sol::object const& arg8);
bool hasCorsairEffect();
Expand Down
3 changes: 2 additions & 1 deletion src/map/modifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ enum class Mod
EXP_BONUS = 382, //
ROLL_RANGE = 528, // Additional range for COR roll abilities.
JOB_BONUS_CHANCE = 542, // Chance to apply job bonus to COR roll without having the job in the party.
RANDOM_DEAL_BONUS = 220, // % chance to reset 2 abilities
TRIPLE_SHOT_RATE = 999, // Percent increase to Triple Shot Rate
QUICK_DRAW_RECAST = 1060, // Quick Draw Charge Reduction (seconds)

Expand Down Expand Up @@ -1012,7 +1013,7 @@ enum class Mod
// 570 through 825 used by WS DMG mods these are not spares.
//
// SPARE IDs:
// 220 to 222
// 221 to 222
// 274 to 276
//
// SPARE = 1082 and onward
Expand Down
101 changes: 101 additions & 0 deletions src/map/utils/battleutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "modifier.h"
#include "notoriety_container.h"
#include "packets/char_abilities.h"
#include "packets/char_recast.h"
#include "packets/char_sync.h"
#include "packets/lock_on.h"
#include "packets/pet_sync.h"
Expand Down Expand Up @@ -5864,6 +5865,106 @@ namespace battleutils
}
}

/************************************************************************
* *
* Does the random deal effect to a specific character (reset ability) *
* *
************************************************************************/
bool DoRandomDealToEntity(CCharEntity* PChar, CCharEntity* PTarget)
{
std::vector<uint16> resetCandidateList;
std::vector<uint16> activeCooldownList;

if (PChar == nullptr || PTarget == nullptr)
{
// Invalid User or Target
return false;
}

RecastList_t* recastList = PTarget->PRecastContainer->GetRecastList(RECAST_ABILITY);

// Get position of abilites and add to the 2 lists
for (uint8 i = 0; i < recastList->size(); ++i)
{
Recast_t* recast = &recastList->at(i);

// Do not reset 2hrs or Random Deal
if (recast->ID != 0 && recast->ID != 196)
{
resetCandidateList.push_back(i);
if (recast->RecastTime > 0)
{
activeCooldownList.push_back(i);
}
}
}

if (resetCandidateList.size() == 0 || activeCooldownList.size() == 0)
{
// Evade because we have no abilities that can be reset
return false;
}

uint8 loadedDeck = PChar->PMeritPoints->GetMeritValue(MERIT_LOADED_DECK, PChar);
uint8 loadedDeckChance = 50 + loadedDeck;
uint8 resetTwoChance = std::min<int8>(PChar->getMod(Mod::RANDOM_DEAL_BONUS), 50);

if (loadedDeck > 0) // Loaded Deck Merit Version
{
if (activeCooldownList.size() > 1)
{
// Shuffle active cooldowns and take first (loaded deck)
std::shuffle(std::begin(activeCooldownList), std::end(activeCooldownList), xirand::rng());
loadedDeckChance = 100;
}

if (loadedDeckChance >= xirand::GetRandomNumber(100))
{
PTarget->PRecastContainer->DeleteByIndex(RECAST_ABILITY, activeCooldownList.at(0));

// Reset 2 abilities by chance
if (activeCooldownList.size() > 1 && resetTwoChance >= xirand::GetRandomNumber(100))
{
PTarget->PRecastContainer->DeleteByIndex(RECAST_ABILITY, activeCooldownList.at(1));
}
if (PChar != PTarget)
{
// Update target's recast state; caster's will be handled in CCharEntity::OnAbility.
PTarget->pushPacket(new CCharRecastPacket(PTarget));
}
return true;
}

// Evade because we failed to reset with loaded deck
return false;
}
else // Standard Version
{
if (resetCandidateList.size() > 1)
{
// Shuffle if more than 1 ability
std::shuffle(std::begin(resetCandidateList), std::end(resetCandidateList), xirand::rng());
}

// Reset first ability (shuffled or only)
PTarget->PRecastContainer->DeleteByIndex(RECAST_ABILITY, resetCandidateList.at(0));

// Reset 2 abilities by chance (could be 2 abilitie that don't need resets)
if (resetCandidateList.size() > 1 && activeCooldownList.size() > 1 && resetTwoChance >= xirand::GetRandomNumber(1, 100))
{
PTarget->PRecastContainer->DeleteByIndex(RECAST_ABILITY, resetCandidateList.at(1));
}

if (PChar != PTarget)
{
// Update target's recast state; caster's will be handled in CCharEntity::OnAbility.
PTarget->pushPacket(new CCharRecastPacket(PTarget));
}

return true;
}
}

/************************************************************************
* *
* Get the Snapshot shot time reduction *
Expand Down
6 changes: 4 additions & 2 deletions src/map/utils/battleutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ namespace battleutils
bool WeatherMatchesElement(WEATHER weather, uint8 element);
bool DrawIn(CBattleEntity* PEntity, CMobEntity* PMob, float offset);
void DoWildCardToEntity(CCharEntity* PCaster, CCharEntity* PTarget, uint8 roll);
void AddTraits(CBattleEntity* PEntity, TraitList_t* TraitList, uint8 level);
bool HasClaim(CBattleEntity* PEntity, CBattleEntity* PTarget);
bool DoRandomDealToEntity(CCharEntity* PChar, CCharEntity* PTarget);

void AddTraits(CBattleEntity* PEntity, TraitList_t* TraitList, uint8 level);
bool HasClaim(CBattleEntity* PEntity, CBattleEntity* PTarget);

uint32 CalculateSpellCastTime(CBattleEntity*, CMagicState*);
uint16 CalculateSpellCost(CBattleEntity*, CSpell*);
Expand Down

0 comments on commit 0655eff

Please sign in to comment.