-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCItemLevelCriteria.cpp
128 lines (99 loc) · 2.48 KB
/
CItemLevelCriteria.cpp
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
116
117
118
119
120
121
122
123
124
125
126
127
128
// CItemLevelCriteria.cpp
//
// CItemLevelCriteria class
// Copyright (c) 2018 Kronosaur Productions, LLC. All Rights Reserved.
#include "PreComp.h"
#define TYPE_LEVEL CONSTLIT("level")
#define TYPE_REPAIR_LEVEL CONSTLIT("repairLevel")
ALERROR CItemLevelCriteria::InitFromXML (SDesignLoadCtx &Ctx, const CString &sValue)
// InitFromXML
//
// Initializes criteria.
{
if (sValue.IsBlank())
m_iType = checkNone;
else if (CXMLElement::IsBoolTrueValue(sValue))
m_iType = checkLessEqualToLevel;
else if (strEquals(sValue, TYPE_LEVEL))
m_iType = checkLessEqualToLevel;
else if (strEquals(sValue, TYPE_REPAIR_LEVEL))
m_iType = checkLessEqualToRepairLevel;
else
{
Ctx.sError = strPatternSubst(CONSTLIT("Unknown levelCheck: %s"), sValue);
return ERR_FAIL;
}
return NOERROR;
}
bool CItemLevelCriteria::MatchesCriteria (int iLevel, const CItem &Item) const
// MatchesCriteria
//
// Returns TRUE if the given item matches our defined criteria.
{
if (Item.IsEmpty())
return false;
// Start by getting the item level that we want to compare.
int iItemLevel = 0;
switch (m_iType)
{
case checkNone:
return true;
case checkLessEqualToLevel:
case checkLessThanLevel:
case checkGreaterEqualToLevel:
case checkGreaterThanLevel:
iItemLevel = Item.GetLevel();
break;
case checkLessEqualToRepairLevel:
case checkLessThanRepairLevel:
case checkGreaterEqualToRepairLevel:
case checkGreaterThanRepairLevel:
{
if (!Item.IsArmor())
return false;
CArmorClass *pArmor = Item.GetType()->GetArmorClass();
if (pArmor == NULL)
return false;
iItemLevel = pArmor->GetRepairTech();
break;
}
default:
ASSERT(false);
return true;
}
// Now do a comparison
switch (m_iType)
{
case checkLessEqualToLevel:
case checkLessEqualToRepairLevel:
return (iItemLevel <= iLevel);
case checkLessThanLevel:
case checkLessThanRepairLevel:
return (iItemLevel < iLevel);
case checkGreaterEqualToLevel:
case checkGreaterEqualToRepairLevel:
return (iItemLevel >= iLevel);
case checkGreaterThanRepairLevel:
case checkGreaterThanLevel:
return (iItemLevel > iLevel);
default:
ASSERT(false);
return false;
}
}
void CItemLevelCriteria::ReadFromStream (SLoadCtx &Ctx)
// ReadFromStream
//
// DWORD m_iType
{
DWORD dwLoad;
Ctx.pStream->Read(dwLoad);
m_iType = (ETypes)dwLoad;
}
void CItemLevelCriteria::WriteToStream (IWriteStream &Stream) const
// WriteToStream
//
// DWORD m_iType
{
Stream.Write((DWORD)m_iType);
}