Repository navigation
Expand file tree
/
Copy pathAutoArmor.cpp
More file actions
115 lines (95 loc) · 3.42 KB
/
Copy pathAutoArmor.cpp
File metadata and controls
115 lines (95 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "AutoArmor.h"
#include "InventoryUtils.h"
#include "MovementUtils.h"
#include "Container.h"
#include "ItemStack.h"
#include "EnchantmentHelper.h"
#include "Logger.h"
void AutoArmor::runModule()
{
static clock_t lastCheck = 0L;
if (clock() - lastCheck < 50) {
return;
}
lastCheck = clock();
//Logger::addInfo("aa stage 1");
if (onlyInInv && !InventoryUtils::isGuiOpen()) {
return;
}
//Logger::addInfo("aa stage 2");
if (onlyWhileNotMoving && MovementUtils::isMoving()) {
return;
}
//Logger::addInfo("aa stage 3");
if (CContainer::isChest(InventoryUtils::getPlayerOpenContainer())) {
lastStart = clock();
}
if (clock() - lastStart > delay)
{
//Logger::addInfo("aa stage 4");
for (int armorSlot = 5; armorSlot < 9; armorSlot++) {
//Logger::addInfo("aa stage 5 slot " + str(armorSlot));
if (equipBest(armorSlot)) {
//Logger::addInfo("equipBest: " + str(armorSlot));
lastStart = clock();
break;
}
}
}
}
bool AutoArmor::isValidPiece(int armorSlot, jobject item)
{
string unlocalizedName = jstring2string(CItem::getUnlocalizedName(item));
//Logger::addInfo(unlocalizedName);
return armorSlot == 5 && unlocalizedName.find("item.helmet") != string::npos
|| armorSlot == 6 && unlocalizedName.find("item.chestplate") != string::npos
|| armorSlot == 7 && unlocalizedName.find("item.leggings") != string::npos
|| armorSlot == 8 && unlocalizedName.find("item.boots") != string::npos;
}
bool AutoArmor::equipBest(int armorSlot)
{
int equipSlot = -1, currProt = -1;
jobject invContainer = InventoryUtils::getPlayerInventoryContainer();
if (invContainer == nullptr)
return true;
//Logger::addInfo("equipBest stage 1");
jobject currItem = nullptr; // orig. ItemArmor
jobject slotStack = CSlot::getStack(CContainer::getSlot(invContainer, armorSlot));
//Logger::addInfo("equipBest stage 2");
if (slotStack != nullptr && CItemStack::isArmor(CItemStack::getItem(slotStack))) {
currItem = CItemStack::getItem(slotStack);
currProt = CItemArmor::getDamageReductionAmount(currItem);
+ CEnchantmentHelper::getEnchantmentLevel(ENCHANT_PROTECTION, slotStack);
}
//Logger::addInfo("equipBest stage 3");
//Logger::addInfo("currProt: " + str(currProt));
// find best piece
for (int i = 9; i < 45; i++) {
jobject is = CSlot::getStack(CContainer::getSlot(invContainer, i));
if (is != nullptr && CItemStack::isArmor(CItemStack::getItem(is))) {
int prot = CItemArmor::getDamageReductionAmount(CItemStack::getItem(is))
+ CEnchantmentHelper::getEnchantmentLevel(ENCHANT_PROTECTION, is);
//Logger::addInfo("prot: " + str(prot));
if ((currItem == nullptr || currProt < prot)
&& isValidPiece(armorSlot, CItemStack::getItem(is))) {
currItem = CItemStack::getItem(is);
equipSlot = i;
currProt = prot;
}
}
}
//Logger::addInfo("equipBest stage 4");
// equip best piece (if there is a better one)
if (equipSlot != -1) {
if (slotStack != nullptr) {
//Logger::addInfo("dropping");
InventoryUtils::drop(armorSlot);
}
else {
//Logger::addInfo("equipping");
InventoryUtils::click(equipSlot, 0, true);
}
return true;
}
return false;
}