summaryrefslogtreecommitdiff
path: root/src/resources/skill/skillinfo.cpp
blob: 9d71ffda73afba682d3cf0ae08ba416ad6e3b68b (plain) (blame)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 *  The ManaPlus Client
 *  Copyright (C) 2004-2009  The Mana World Development Team
 *  Copyright (C) 2009-2010  The Mana Developers
 *  Copyright (C) 2011-2016  The ManaPlus Developers
 *
 *  This file is part of The ManaPlus Client.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "resources/skill/skillinfo.h"

#include "being/playerinfo.h"

#include "gui/models/skillmodel.h"

#include "utils/stringutils.h"

#include "resources/skill/skilldata.h"
#include "resources/skill/skilltypelist.h"

#include "debug.h"

SkillInfo::SkillInfo() :
    skillLevel(),
    skillEffect(),
    useButton(),
    errorText(),
    castingAction(),
    castingRideAction(),
    castingSkyAction(),
    castingWaterAction(),
    dataMap(),
    model(nullptr),
    data(nullptr),
    level(0),
    selectedLevel(0),
    skillLevelWidth(0),
    id(0),
    range(0),
    sp(0),
    duration(0),
    durationTime(0),
    cooldown(0),
    castingSrcEffectId(-1),
    castingDstEffectId(-1),
    type(SkillType::Unknown),
    owner(SkillOwner::Player),
    modifiable(Modifiable_false),
    visible(Visible_false),
    alwaysVisible(Visible_false),
    useTextParameter(false)
{
    dataMap[0] = new SkillData();
    data = dataMap[0];
}

SkillInfo::~SkillInfo()
{
    FOR_EACH (SkillDataMapIter, it, dataMap)
        delete (*it).second;
    dataMap.clear();
}

void SkillInfo::update()
{
    const int baseLevel = PlayerInfo::getSkillLevel(id);
    if (modifiable == Modifiable_false && baseLevel == 0)
    {
        if (visible == Visible_true)
        {
            visible = Visible_false;
            if (model)
                model->updateVisibilities();
        }
        return;
    }

    const bool updateVisibility = (visible == Visible_false);
    visible = Visible_true;

    if (baseLevel == 0)
    {
        skillLevel.clear();
    }
    else
    {
        if (!selectedLevel)
        {
            // TRANSLATORS: skill level
            skillLevel = strprintf(_("Lvl: %d"), baseLevel);
        }
        else
        {
            // TRANSLATORS: skill level
            skillLevel = strprintf(_("Lvl: %d / %d"),
                selectedLevel,
                baseLevel);
        }
    }

    // TRANSLATORS: skill type
    const char *const typeStr = _("Type: %s");

    if (type == SkillType::Unknown)
    {
        // TRANSLATORS: Skill type
        skillEffect = strprintf(typeStr, _("Unknown"));
    }
    else
    {
        skillEffect.clear();
        for (size_t f = 0; f < skillTypeListSize; f ++)
        {
            const SkillTypeEntry &item = skillTypeList[f];
            if ((item.type & type) != 0)
            {
                if (!skillEffect.empty())
                    skillEffect.append(", ");
                skillEffect.append(strprintf(typeStr, item.name));
            }
        }
    }
    if (skillEffect.empty())
    {
        // TRANSLATORS: Skill type
        skillEffect = strprintf(typeStr, _("Unknown:"));
        skillEffect.append(" ").append(toString(CAST_S32(type)));
    }

    if (sp)
    {
        // TRANSLATORS: skill mana
        skillEffect.append(strprintf(_(" / Mana: -%d"), sp));
    }

    if (range > 0)
    {
        if (!skillEffect.empty())
            skillEffect.append(" / ");
        // TRANSLATORS: skill range
        skillEffect.append(strprintf(_("Range: %d"), range));
    }

    level = baseLevel;
    if (selectedLevel > level)
        selectedLevel = level;

    skillLevelWidth = -1;

    if (updateVisibility && model)
        model->updateVisibilities();

    data = getData(level);
    if (!data)
        data = dataMap[0];
}


void SkillInfo::addData(const int level1, SkillData *const data1)
{
    dataMap[level1] = data1;
}

SkillData *SkillInfo::getData(const int level1) const
{
    const SkillDataMapCIter it = dataMap.find(level1);
    if (it == dataMap.end())
        return nullptr;
    return (*it).second;
}

SkillData *SkillInfo::getData1(const int lev) const
{
    const SkillDataMapCIter it = dataMap.find(lev);
    if (it == dataMap.end())
        return (*dataMap.begin()).second;
    return (*it).second;
}