ManaPlus
src
resources
skill
skillinfo.cpp
Go to the documentation of this file.
1
/*
2
* The ManaPlus Client
3
* Copyright (C) 2004-2009 The Mana World Development Team
4
* Copyright (C) 2009-2010 The Mana Developers
5
* Copyright (C) 2011-2019 The ManaPlus Developers
6
* Copyright (C) 2019-2021 Andrei Karas
7
*
8
* This file is part of The ManaPlus Client.
9
*
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*/
23
24
#include "
resources/skill/skillinfo.h
"
25
26
#include "
being/playerinfo.h
"
27
28
#include "
gui/models/skillmodel.h
"
29
30
#include "
utils/foreach.h
"
31
#include "
utils/stringutils.h
"
32
33
#include "
resources/skill/skilldata.h
"
34
#include "
resources/skill/skilltypelist.h
"
35
36
#include "
debug.h
"
37
38
SkillInfo::SkillInfo
() :
39
skillLevel(),
40
skillEffect(),
41
useButton(),
42
errorText(),
43
castingAction(),
44
castingRideAction(),
45
castingSkyAction(),
46
castingWaterAction(),
47
dataMap(),
48
model(
nullptr
),
49
tab(
nullptr
),
50
data
(
nullptr
),
51
level(0),
52
customSelectedLevel(0),
53
customOffsetX(0),
54
customOffsetY(0),
55
skillLevelWidth(0),
56
id(0),
57
range(0),
58
sp(0),
59
duration(0),
60
durationTime(0),
61
cooldown(0),
62
x
(0),
63
y
(0),
64
type(
SkillType
::
Unknown
),
65
owner(
SkillOwner
::
Player
),
66
customCastType(
CastType
::
Default
),
67
modifiable(
Modifiable_false
),
68
visible(
Visible_false
),
69
alwaysVisible(
Visible_false
),
70
useTextParameter(false)
71
{
72
dataMap
[0] =
new
SkillData
;
73
data
=
dataMap
[0];
74
}
75
76
SkillInfo::~SkillInfo
()
77
{
78
FOR_EACH
(
SkillDataMapIter
, it,
dataMap
)
79
delete
(*it).second;
80
dataMap
.clear();
81
}
82
83
void
SkillInfo::update
()
84
{
85
const
int
baseLevel =
PlayerInfo::getSkillLevel
(
id
);
86
if
(
modifiable
==
Modifiable_false
&& baseLevel == 0)
87
{
88
if
(
visible
==
Visible_true
)
89
{
90
visible
=
Visible_false
;
91
if
(
model
!=
nullptr
)
92
model
->
updateVisibilities
();
93
}
94
return
;
95
}
96
97
const
bool
updateVisibility = (
visible
==
Visible_false
);
98
visible
=
Visible_true
;
99
100
if
(baseLevel == 0)
101
{
102
skillLevel
.clear();
103
}
104
else
105
{
106
if
(
customSelectedLevel
== 0)
107
{
108
// TRANSLATORS: skill level
109
skillLevel
=
strprintf
(
_
(
"Lvl: %d"
), baseLevel);
110
}
111
else
112
{
113
// TRANSLATORS: skill level
114
skillLevel
=
strprintf
(
_
(
"Lvl: %d / %d"
),
115
customSelectedLevel
,
116
baseLevel);
117
}
118
}
119
120
// TRANSLATORS: skill type
121
const
char
*
const
typeStr =
_
(
"Type: %s"
);
122
123
if
(
type
==
SkillType::Unknown
)
124
{
125
// TRANSLATORS: Skill type
126
skillEffect
=
strprintf
(typeStr,
_
(
"Unknown"
));
127
}
128
else
129
{
130
skillEffect
.clear();
131
for
(
size_t
f = 0; f <
skillTypeListSize
; f ++)
132
{
133
const
SkillTypeEntry
&item =
skillTypeList
[f];
134
if
((item.
type
&
type
) != 0)
135
{
136
if
(!
skillEffect
.empty())
137
skillEffect
.append(
", "
);
138
skillEffect
.append(
strprintf
(typeStr, item.
name
));
139
}
140
}
141
}
142
if
(
skillEffect
.empty())
143
{
144
// TRANSLATORS: Skill type
145
skillEffect
=
strprintf
(typeStr,
_
(
"Unknown:"
));
146
skillEffect
.append(
" "
).append(
toString
(
CAST_S32
(
type
)));
147
}
148
149
if
(
sp
!= 0)
150
{
151
// TRANSLATORS: skill mana
152
skillEffect
.append(
strprintf
(
_
(
" / Mana: -%d"
),
sp
));
153
}
154
155
if
(
range
> 0)
156
{
157
if
(!
skillEffect
.empty())
158
skillEffect
.append(
" / "
);
159
// TRANSLATORS: skill range
160
skillEffect
.append(
strprintf
(
_
(
"Range: %d"
),
range
));
161
}
162
163
level
= baseLevel;
164
if
(
customSelectedLevel
>
level
)
165
customSelectedLevel
=
level
;
166
167
skillLevelWidth
= -1;
168
169
if
(updateVisibility && (
model
!=
nullptr
))
170
model
->
updateVisibilities
();
171
172
data
=
getData
(
level
);
173
if
(
data
==
nullptr
)
174
data
=
dataMap
[0];
175
}
176
177
178
void
SkillInfo::addData
(
const
int
level1,
SkillData
*
const
data1)
179
{
180
dataMap
[level1] = data1;
181
}
182
183
SkillData
*
SkillInfo::getData
(
const
int
level1)
const
184
{
185
const
SkillDataMapCIter
it =
dataMap
.find(level1);
186
if
(it ==
dataMap
.end())
187
return
nullptr
;
188
return
(*it).second;
189
}
190
191
SkillData
*
SkillInfo::getData1
(
const
int
lev)
const
192
{
193
const
SkillDataMapCIter
it =
dataMap
.find(lev);
194
if
(it ==
dataMap
.end())
195
return
(*
dataMap
.begin()).second;
196
return
(*it).second;
197
}
198
199
std::string
SkillInfo::toDataStr
()
const
200
{
201
return
strprintf
(
"%d %d %d"
,
202
CAST_S32
(
customCastType
),
203
customOffsetX
,
204
customOffsetY
);
205
}
CAST_S32
#define CAST_S32
Definition:
cast.h:30
SkillModel::updateVisibilities
void updateVisibilities()
Definition:
skillmodel.cpp:54
debug.h
foreach.h
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition:
foreach.h:25
_
#define _(s)
Definition:
gettext.h:35
y
y
Definition:
graphics_calcImageRect.hpp:73
x
x
Definition:
graphics_calcImageRect.hpp:73
nullptr
#define nullptr
Definition:
localconsts.h:45
data
uint32_t data
Definition:
maptypeproperty2.h:1
Modifiable_false
const bool Modifiable_false
Definition:
modifiable.h:30
ActorType::Player
@ Player
Definition:
actortype.h:31
ActorType::Unknown
@ Unknown
Definition:
actortype.h:30
CastType
Definition:
casttype.h:27
CastType::Default
@ Default
Definition:
casttype.h:29
Catch::toString
std::string toString(T const &value)
converts any type to a string
Definition:
catch.hpp:1774
PlayerInfo::getSkillLevel
int getSkillLevel(const int id)
Definition:
playerinfo.cpp:120
SkillOwner
Definition:
skillowner.h:26
SkillType
Definition:
skilltype.h:27
SkillType::Unknown
@ Unknown
Definition:
skilltype.h:30
playerinfo.h
skilldata.h
skillinfo.h
SkillDataMapCIter
SkillDataMap::const_iterator SkillDataMapCIter
Definition:
skillinfo.h:48
SkillDataMapIter
SkillDataMap::iterator SkillDataMapIter
Definition:
skillinfo.h:47
skillmodel.h
skilltypelist.h
skillTypeListSize
const size_t skillTypeListSize
Definition:
skilltypelist.h:31
skillTypeList
SkillTypeEntry skillTypeList[skillTypeListSize]
Definition:
skilltypelist.h:33
strprintf
std::string strprintf(const char *const format,...)
Definition:
stringutils.cpp:100
stringutils.h
SkillData
Definition:
skilldata.h:33
SkillInfo::addData
void addData(const int level, SkillData *const data)
Definition:
skillinfo.cpp:178
SkillInfo::modifiable
Modifiable modifiable
Definition:
skillinfo.h:80
SkillInfo::getData
SkillData * getData(const int level) const
Definition:
skillinfo.cpp:183
SkillInfo::customCastType
CastTypeT customCastType
Definition:
skillinfo.h:79
SkillInfo::visible
Visible visible
Definition:
skillinfo.h:81
SkillInfo::customSelectedLevel
int customSelectedLevel
Definition:
skillinfo.h:65
SkillInfo::getData1
SkillData * getData1(const int level) const
Definition:
skillinfo.cpp:191
SkillInfo::skillLevelWidth
int skillLevelWidth
Definition:
skillinfo.h:68
SkillInfo::update
void update()
Definition:
skillinfo.cpp:83
SkillInfo::skillEffect
std::string skillEffect
Definition:
skillinfo.h:53
SkillInfo::SkillInfo
SkillInfo()
Definition:
skillinfo.cpp:38
SkillInfo::toDataStr
std::string toDataStr() const
Definition:
skillinfo.cpp:199
SkillInfo::type
SkillType::SkillType type
Definition:
skillinfo.h:77
SkillInfo::sp
int sp
Definition:
skillinfo.h:71
SkillInfo::skillLevel
std::string skillLevel
Definition:
skillinfo.h:52
SkillInfo::data
SkillData * data
Definition:
skillinfo.h:63
SkillInfo::level
int level
Definition:
skillinfo.h:64
SkillInfo::model
SkillModel * model
Definition:
skillinfo.h:61
SkillInfo::range
int range
Definition:
skillinfo.h:70
SkillInfo::customOffsetY
int customOffsetY
Definition:
skillinfo.h:67
SkillInfo::~SkillInfo
~SkillInfo()
Definition:
skillinfo.cpp:76
SkillInfo::customOffsetX
int customOffsetX
Definition:
skillinfo.h:66
SkillInfo::dataMap
SkillDataMap dataMap
Definition:
skillinfo.h:60
SkillTypeEntry
Definition:
skilltypeentry.h:30
SkillTypeEntry::name
const char *const name
Definition:
skilltypeentry.h:34
SkillTypeEntry::type
const SkillType::SkillType type
Definition:
skilltypeentry.h:33
Visible_false
const bool Visible_false
Definition:
visible.h:30
Visible_true
const bool Visible_true
Definition:
visible.h:30
Generated on Wed Mar 17 2021 19:19:10 for ManaPlus by
1.9.1