#include "ModifierInstance.h" #include #include nejlika::ModifierInstance::ModifierInstance(const nlohmann::json& config) { type = magic_enum::enum_cast(config["type"].get()).value_or(ModifierType::Invalid); value = config["value"].get(); if (config.contains("op")) { op = magic_enum::enum_cast(config["op"].get()).value_or(ModifierOperator::Additive); } else { op = ModifierOperator::Additive; } isResistance = config.contains("resistance") ? config["resistance"].get() : false; if (config.contains("category")) { category = magic_enum::enum_cast(config["category"].get()).value_or(ModifierCategory::Player); } else { category = ModifierCategory::Player; } effectID = config.contains("effect-id") ? config["effect-id"].get() : 0; effectType = config.contains("effect-type") ? config["effect-type"].get() : ""; } nlohmann::json nejlika::ModifierInstance::ToJson() const { nlohmann::json config; config["type"] = magic_enum::enum_name(type); config["value"] = value; config["op"] = magic_enum::enum_name(op); config["resistance"] = isResistance; config["category"] = magic_enum::enum_name(category); config["effect-id"] = effectID; config["effect-type"] = effectType; return config; } std::string nejlika::ModifierInstance::GenerateHtmlString(const std::vector& modifiers) { std::stringstream ss; // target -> resistance -> op -> type -> value std::unordered_map>>> modifierMap; for (const auto& modifier : modifiers) { if (modifier.type == ModifierType::Invalid) { continue; } modifierMap[modifier.category][modifier.isResistance][modifier.op][modifier.type] = modifier.value; } // Resistances and addatives are not separated, pet and player are // Summarize the resistances and addatives for (const auto& target : modifierMap) { if (target.first == ModifierCategory::Pet) { ss << "\nPets:\n"; } for (const auto& resistance : target.second) { ss << "\n"; ss << ((resistance.first) ? "Resistances" : "Modifiers"); ss << ":\n"; for (const auto& math : resistance.second) { for (const auto& modifier : math.second) { ss << ""; ss << magic_enum::enum_name(modifier.first) << ": "; ss << ((modifier.second > 0) ? "+" : "-"); ss << std::fixed << std::setprecision(0) << std::abs(modifier.second); if (math.first == ModifierOperator::Multiplicative) { ss << "%"; } ss << "\n"; } } } } return ss.str(); }