Mana
Loading...
Searching...
No Matches
statuseffectdb.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2008-2009 The Mana World Development Team
4 * Copyright (C) 2009-2025 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "statuseffectdb.h"
23
24bool StatusEffectDB::mLoaded = false;
25std::map<int, StatusEffect> StatusEffectDB::mStatusEffects;
30
31
33{
34 auto it = mStatusEffects.find(id);
35 if (it == mStatusEffects.end())
36 return nullptr;
37 return &it->second;
38}
39
41{
42 if (mLoaded)
43 unload();
44}
45
46void StatusEffectDB::readStatusEffectNode(XML::Node node, const std::string &/* filename */)
47{
48 const int id = node.getProperty("id", -1);
49
50 const int opt0 = node.getProperty("option", 0);
51 const int opt1 = node.getProperty("opt1", 0);
52 const int opt2 = node.getProperty("opt2", 0);
53 const int opt3 = node.getProperty("opt3", 0);
54 if (opt0 != 0 && opt0 <= UINT16_MAX)
55 mOpt0ToIdMap[opt0] = id;
56 if (opt1 != 0 && opt1 <= UINT16_MAX)
57 mOpt1ToIdMap[opt1] = id;
58 if (opt2 != 0 && opt2 <= UINT16_MAX)
59 mOpt2ToIdMap[opt2] = id;
60 if (opt3 != 0 && opt3 <= UINT16_MAX)
61 mOpt3ToIdMap[opt3] = id;
62
63 auto &effect = mStatusEffects[id];
64
65 node.attribute("name", effect.name);
66
67 node.attribute("start-message", effect.start.message);
68 node.attribute("start-audio", effect.start.sfx);
69 node.attribute("start-particle", effect.start.particleEffect);
70
71 // For now we don't support separate particle effect for "already applied"
72 // status effects.
73 if (effect.start.particleEffect.empty())
74 node.attribute("particle", effect.start.particleEffect);
75
76 node.attribute("end-message", effect.end.message);
77 node.attribute("end-audio", effect.end.sfx);
78 node.attribute("end-particle", effect.end.particleEffect);
79
80 node.attribute("icon", effect.icon);
81 node.attribute("persistent-particle-effect", effect.persistentParticleEffect);
82}
83
85{
86 mLoaded = true;
87}
88
90{
91 if (!mLoaded)
92 return;
93
94 mStatusEffects.clear();
95 mLoaded = false;
96}
static void init()
static OptionsMap mOpt3ToIdMap
static OptionsMap mOpt1ToIdMap
static std::map< int, StatusEffect > mStatusEffects
static bool mLoaded
std::map< uint16_t, int > OptionsMap
static OptionsMap mOpt0ToIdMap
static void checkStatus()
static OptionsMap mOpt2ToIdMap
static const StatusEffect * getStatusEffect(int id)
Retrieves a status effect.
static void readStatusEffectNode(XML::Node node, const std::string &filename)
static void unload()
int getProperty(const char *name, int def) const
Definition xml.h:144
bool attribute(const char *name, T &value) const
Definition xml.h:129