Skip to content

Commit

Permalink
allow 0 in spellDamageFormula entry & support player-to-npc mult
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove committed Dec 24, 2024
1 parent bf93881 commit ca626ff
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@
#include <sstream>

namespace SweetPieSpellDamageFormulaPrivate {

bool IsPlayerBaseId(const MpActor& actor)
{
return actor.GetBaseId() == 0x7;
}

float SelectRespectiveMult(
const MpActor& aggressor, const MpActor& target,
const SweetPieSpellDamageFormulaSettingsEntry& entry)
{
const bool isPlayerAggressor = IsPlayerBaseId(aggressor);
const bool isPlayerTarget = IsPlayerBaseId(target);

if (isPlayerAggressor && isPlayerTarget) {
return entry.multPlayerHitsPlayer.has_value() ? *entry.multPlayerHitsPlayer
: 1.f;
}

if (isPlayerAggressor && !isPlayerTarget) {
return entry.multPlayerHitsNpc.has_value() ? *entry.multPlayerHitsNpc
: 1.f;
}

return 1.f;
}

template <class T>
T Clamp(T value, T minValue, T maxValue)
{
Expand Down Expand Up @@ -60,7 +86,8 @@ float SweetPieSpellDamageFormula::CalculateDamage(
for (auto& entry : settings->entries) {
const std::string& itemId = entry.itemId;
const float mult = SweetPieSpellDamageFormulaPrivate::Clamp(
entry.mult, 0.f, std::numeric_limits<float>::infinity());
SelectRespectiveMult(aggressor, target, entry), 0.f,
std::numeric_limits<float>::infinity());

uint32_t itemIdParsed = 0;

Expand All @@ -73,7 +100,8 @@ float SweetPieSpellDamageFormula::CalculateDamage(
ss >> itemIdParsed;
}

if (aggressor.GetInventory().GetItemCount(itemIdParsed) > 0) {
if (itemIdParsed == 0 ||
aggressor.GetInventory().GetItemCount(itemIdParsed) > 0) {
biggestMult = std::max(biggestMult, mult);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ struct SweetPieSpellDamageFormulaSettingsEntry
template <class Archive>
void Serialize(Archive& archive)
{
archive.Serialize("itemId", itemId).Serialize("multPlayerHitsPlayer", mult);
archive.Serialize("itemId", itemId)
.Serialize("multPlayerHitsPlayer", multPlayerHitsPlayer)
.Serialize("multPlayerHitsNpc", multPlayerHitsNpc);
}

std::string itemId; // supports hex and decimal ids: "0x000feef1", "0"
float mult = 0.f;
std::optional<float> multPlayerHitsPlayer;
std::optional<float> multPlayerHitsNpc;
};

struct SweetPieSpellDamageFormulaSettings
Expand Down

0 comments on commit ca626ff

Please sign in to comment.