Skip to content

Commit

Permalink
Added support for filtering items based on skill charges. The new key…
Browse files Browse the repository at this point in the history
…word is CHSK and is used much the same way as SK.
  • Loading branch information
youbetterdont committed Mar 1, 2020
1 parent f8a5014 commit e7b74f0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
35 changes: 35 additions & 0 deletions BH/Modules/Item/ItemDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,13 @@ void Condition::BuildConditions(vector<Condition*> &conditions, string token) {
return;
}
Condition::AddOperand(conditions, new ItemStatCondition(STAT_NONCLASSSKILL, num, operation, value));
} else if (key.compare(0, 4, "CHSK") == 0) { // skills granted by charges
int num = -1;
stringstream ss(key.substr(4));
if ((ss >> num).fail() || num < 0 || num > (int)SKILL_MAX) {
return;
}
Condition::AddOperand(conditions, new ChargedCondition(operation, num, value));
} else if (key.compare(0, 4, "CLSK") == 0) {
int num = -1;
stringstream ss(key.substr(4));
Expand Down Expand Up @@ -1145,6 +1152,34 @@ bool DurabilityCondition::EvaluateInternalFromPacket(ItemInfo *info, Condition *
return IntegerCompare(value, operation, targetDurability);
}

bool ChargedCondition::EvaluateInternal(UnitItemInfo *uInfo, Condition *arg1, Condition *arg2) {
DWORD value = 0;
Stat aStatList[256] = { NULL };
StatList* pStatList = D2COMMON_GetStatList(uInfo->item, NULL, 0x40);
if (pStatList) {
DWORD dwStats = D2COMMON_CopyStatList(pStatList, (Stat*)aStatList, 256);
for (UINT i = 0; i < dwStats; i++) {
//if (aStatList[i].wStatIndex == STAT_CHARGED)
// PrintText(1, "ChargedCondition::EvaluateInternal: Index=%hx, SubIndex=%hx, Value=%x", aStatList[i].wStatIndex, aStatList[i].wSubIndex, aStatList[i].dwStatValue);
if (aStatList[i].wStatIndex == STAT_CHARGED && (aStatList[i].wSubIndex>>6) == skill) { // 10 MSBs of subindex is the skill ID
unsigned int level = aStatList[i].wSubIndex & 0x3F; // 6 LSBs are the skill level
value = (level > value) ? level : value; // use highest level
}
}
}
return IntegerCompare(value, operation, targetLevel);
}
bool ChargedCondition::EvaluateInternalFromPacket(ItemInfo *info, Condition *arg1, Condition *arg2) {
DWORD num = 0;
for (vector<ItemProperty>::iterator prop = info->properties.begin(); prop < info->properties.end(); prop++) {
if (prop->stat == STAT_CHARGED && prop->skill == skill) {
num = (prop->level > num) ? prop->level : num; // use the highest level charges for the comparison
//PrintText(1, "Found charged skill. skill=%u level=%u", prop->skill, prop->level);
}
}
return IntegerCompare(num, operation, targetLevel);
}

bool FoolsCondition::EvaluateInternal(UnitItemInfo *uInfo, Condition *arg1, Condition *arg2) {
// 1 = MAX DMG / level
// 2 = AR / level
Expand Down
12 changes: 12 additions & 0 deletions BH/Modules/Item/ItemDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,18 @@ class DurabilityCondition : public Condition
bool EvaluateInternalFromPacket(ItemInfo *info, Condition *arg1, Condition *arg2);
};

class ChargedCondition : public Condition
{
public:
ChargedCondition(BYTE op, unsigned int sk, unsigned int target) : operation(op), skill(sk), targetLevel(target) { conditionType = CT_Operand; };
private:
BYTE operation;
unsigned int skill;
unsigned int targetLevel;
bool EvaluateInternal(UnitItemInfo *uInfo, Condition *arg1, Condition *arg2);
bool EvaluateInternalFromPacket(ItemInfo *info, Condition *arg1, Condition *arg2);
};

class FoolsCondition : public Condition
{
public:
Expand Down

0 comments on commit e7b74f0

Please sign in to comment.