diff options
| author | daoge <3523206925@qq.com> | 2026-03-03 03:04:10 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-03 03:04:10 +0800 |
| commit | b3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch) | |
| tree | 267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/AttributeModifier.cpp | |
| parent | 84c31a2331f7a0ec85b9d438992e244f60e5020f (diff) | |
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict
* feat: TU19 (Dec 2014) Features & Content (#32)
* December 2014 files
* Working release build
* Fix compilation issues
* Add sound to Windows64Media
* Add DLC content and force Tutorial DLC
* Revert "Add DLC content and force Tutorial DLC"
This reverts commit 97a43994725008e35fceb984d5549df9c8cea470.
* Disable broken light packing
* Disable breakpoint during DLC texture map load
Allows DLC loading but the DLC textures are still broken
* Fix post build not working
* ...
* fix vs2022 build
* fix cmake build
---------
Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/AttributeModifier.cpp')
| -rw-r--r-- | Minecraft.World/AttributeModifier.cpp | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/Minecraft.World/AttributeModifier.cpp b/Minecraft.World/AttributeModifier.cpp new file mode 100644 index 00000000..c479853d --- /dev/null +++ b/Minecraft.World/AttributeModifier.cpp @@ -0,0 +1,129 @@ +#include "stdafx.h" + +#include "AttributeModifier.h" +#include "HtmlString.h" + +void AttributeModifier::_init(eMODIFIER_ID id, const wstring name, double amount, int operation) +{ + assert(operation < TOTAL_OPERATIONS); + this->amount = amount; + this->operation = operation; + this->name = name; + this->id = id; + this->serialize = true; +} + +AttributeModifier::AttributeModifier(double amount, int operation) +{ + // Create an anonymous attribute + _init(eModifierId_ANONYMOUS, name, amount, operation); +} + +AttributeModifier::AttributeModifier(eMODIFIER_ID id, double amount, int operation) +{ + _init(id, name, amount, operation); + + //Validate.notEmpty(name, "Modifier name cannot be empty"); + //Validate.inclusiveBetween(0, TOTAL_OPERATIONS - 1, operation, "Invalid operation"); +} + +eMODIFIER_ID AttributeModifier::getId() +{ + return id; +} + +wstring AttributeModifier::getName() +{ + return name; +} + +int AttributeModifier::getOperation() +{ + return operation; +} + +double AttributeModifier::getAmount() +{ + return amount; +} + +bool AttributeModifier::isSerializable() +{ + return serialize; +} + +AttributeModifier *AttributeModifier::setSerialize(bool serialize) +{ + this->serialize = serialize; + return this; +} + +bool AttributeModifier::equals(AttributeModifier *modifier) +{ + if (this == modifier) return true; + if (modifier == NULL) return false; //|| getClass() != o.getClass()) return false; + + if (id != modifier->id) return false; + + return true; +} + +wstring AttributeModifier::toString() +{ + return L""; + + /*return L"AttributeModifier{" + + L"amount=" + amount + + L", operation=" + operation + + L", name='" + name + '\'' + + L", id=" + id + + L", serialize=" + serialize + + L'}';*/ +} + +HtmlString AttributeModifier::getHoverText(eATTRIBUTE_ID attribute) +{ + double amount = getAmount(); + double displayAmount; + + if (getOperation() == AttributeModifier::OPERATION_MULTIPLY_BASE || getOperation() == AttributeModifier::OPERATION_MULTIPLY_TOTAL) + { + displayAmount = getAmount() * 100.0f; + } + else + { + displayAmount = getAmount(); + } + + eMinecraftColour color; + + if (amount > 0) + { + color = eHTMLColor_9; + } + else if (amount < 0) + { + displayAmount *= -1; + color = eHTMLColor_c; + } + + bool percentage = false; + switch(getOperation()) + { + case AttributeModifier::OPERATION_ADDITION: + percentage = false; + break; + case AttributeModifier::OPERATION_MULTIPLY_BASE: + case AttributeModifier::OPERATION_MULTIPLY_TOTAL: + percentage = true; + break; + default: + // No other operations + assert(0); + } + + wchar_t formatted[256]; + swprintf(formatted, 256, L"%ls%d%ls %ls", (amount > 0 ? L"+" : L"-"), (int) displayAmount, (percentage ? L"%" : L""), app.GetString(Attribute::getName(attribute))); + + return HtmlString(formatted, color); +}
\ No newline at end of file |
