the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2
3#include "AttributeModifier.h"
4#include "HtmlString.h"
5
6void AttributeModifier::_init(eMODIFIER_ID id, const wstring name, double amount, int operation)
7{
8 assert(operation < TOTAL_OPERATIONS);
9 this->amount = amount;
10 this->operation = operation;
11 this->name = name;
12 this->id = id;
13 this->serialize = true;
14}
15
16AttributeModifier::AttributeModifier(double amount, int operation)
17{
18 // Create an anonymous attribute
19 _init(eModifierId_ANONYMOUS, name, amount, operation);
20}
21
22AttributeModifier::AttributeModifier(eMODIFIER_ID id, double amount, int operation)
23{
24 _init(id, name, amount, operation);
25
26 //Validate.notEmpty(name, "Modifier name cannot be empty");
27 //Validate.inclusiveBetween(0, TOTAL_OPERATIONS - 1, operation, "Invalid operation");
28}
29
30eMODIFIER_ID AttributeModifier::getId()
31{
32 return id;
33}
34
35wstring AttributeModifier::getName()
36{
37 return name;
38}
39
40int AttributeModifier::getOperation()
41{
42 return operation;
43}
44
45double AttributeModifier::getAmount()
46{
47 return amount;
48}
49
50bool AttributeModifier::isSerializable()
51{
52 return serialize;
53}
54
55AttributeModifier *AttributeModifier::setSerialize(bool serialize)
56{
57 this->serialize = serialize;
58 return this;
59}
60
61bool AttributeModifier::equals(AttributeModifier *modifier)
62{
63 if (this == modifier) return true;
64 if (modifier == NULL) return false; //|| getClass() != o.getClass()) return false;
65
66 if (id != modifier->id) return false;
67
68 return true;
69}
70
71wstring AttributeModifier::toString()
72{
73 return L"";
74
75 /*return L"AttributeModifier{" +
76 L"amount=" + amount +
77 L", operation=" + operation +
78 L", name='" + name + '\'' +
79 L", id=" + id +
80 L", serialize=" + serialize +
81 L'}';*/
82}
83
84HtmlString AttributeModifier::getHoverText(eATTRIBUTE_ID attribute)
85{
86 double amount = getAmount();
87 double displayAmount;
88
89 if (getOperation() == AttributeModifier::OPERATION_MULTIPLY_BASE || getOperation() == AttributeModifier::OPERATION_MULTIPLY_TOTAL)
90 {
91 displayAmount = getAmount() * 100.0f;
92 }
93 else
94 {
95 displayAmount = getAmount();
96 }
97
98 eMinecraftColour color;
99
100 if (amount > 0)
101 {
102 color = eHTMLColor_9;
103 }
104 else if (amount < 0)
105 {
106 displayAmount *= -1;
107 color = eHTMLColor_c;
108 }
109
110 bool percentage = false;
111 switch(getOperation())
112 {
113 case AttributeModifier::OPERATION_ADDITION:
114 percentage = false;
115 break;
116 case AttributeModifier::OPERATION_MULTIPLY_BASE:
117 case AttributeModifier::OPERATION_MULTIPLY_TOTAL:
118 percentage = true;
119 break;
120 default:
121 // No other operations
122 assert(0);
123 }
124
125 wchar_t formatted[256];
126 swprintf(formatted, 256, L"%ls%d%ls %ls", (amount > 0 ? L"+" : L"-"), (int) displayAmount, (percentage ? L"%" : L""), app.GetString(Attribute::getName(attribute)));
127
128 return HtmlString(formatted, color);
129}