Mana
Loading...
Searching...
No Matches
monsterdb.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2013 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 "resources/monsterdb.h"
23
24#include "log.h"
25
26#include "net/net.h"
27
28#include "resources/beinginfo.h"
29
30#include "utils/dtor.h"
31#include "utils/gettext.h"
32
33#include "configuration.h"
34
35#define OLD_TMWATHENA_OFFSET 1002
36
37
38namespace
39{
40 std::map<int, BeingInfo *> mMonsterInfos;
41 bool mLoaded = false;
42 int mMonsterIdOffset;
43}
44
45
52{
53 if (mLoaded)
54 unload();
55
56 // This can be overridden by an 'offset' attribute on a 'monsters' root tag.
58}
59
61{
62 mMonsterIdOffset = offset;
63}
64
68void MonsterDB::readMonsterNode(XML::Node node, const std::string &filename)
69{
70 auto *currentInfo = new BeingInfo;
71
72 currentInfo->blockType = Map::BLOCKTYPE_MONSTER;
73
74 currentInfo->name = node.getProperty("name", _("unnamed"));
75
76 currentInfo->setTargetCursorSize(node.getProperty("targetCursor", "medium"));
77 currentInfo->setHoverCursor(node.getProperty("hoverCursor", "attack"));
78
79 currentInfo->targetSelection = node.getProperty("targetSelection", true);
80
81 SpriteDisplay &display = currentInfo->display;
82
83 for (auto spriteNode : node.children())
84 {
85 if (spriteNode.name() == "sprite")
86 {
87 SpriteReference &currentSprite = display.sprites.emplace_back();
88 currentSprite.sprite = spriteNode.textContent();
89 currentSprite.variant = spriteNode.getProperty("variant", 0);
90 }
91 else if (spriteNode.name() == "sound")
92 {
93 std::string event = spriteNode.getProperty("event", std::string());
94 const std::string soundFile { spriteNode.textContent() };
95
96 if (event == "hit")
97 {
98 currentInfo->addSound(SoundEvent::Hit, soundFile);
99 }
100 else if (event == "miss")
101 {
102 currentInfo->addSound(SoundEvent::Miss, soundFile);
103 }
104 else if (event == "hurt")
105 {
106 currentInfo->addSound(SoundEvent::Hurt, soundFile);
107 }
108 else if (event == "die")
109 {
110 currentInfo->addSound(SoundEvent::Die, soundFile);
111 }
112 else
113 {
114 Log::info("MonsterDB: Warning, sound effect %s for "
115 "unknown event %s of monster %s in %s",
116 soundFile.c_str(), event.c_str(),
117 currentInfo->name.c_str(),
118 filename.c_str());
119 }
120 }
121 else if (spriteNode.name() == "attack")
122 {
123 Attack attack;
124 const int id = spriteNode.getProperty("id", 0);
125
126 attack.effectId = spriteNode.getProperty("effect-id", -1);
127 attack.hitEffectId =
128 spriteNode.getProperty("hit-effect-id",
129 paths.getIntValue("hitEffectId"));
130 attack.criticalHitEffectId =
131 spriteNode.getProperty("critical-hit-effect-id",
132 paths.getIntValue("criticalHitEffectId"));
134 spriteNode.getProperty("missile-particle", "");
135
136 attack.action = spriteNode.getProperty("action", "attack");
137
138 currentInfo->addAttack(id, std::move(attack));
139 }
140 else if (spriteNode.name() == "particlefx")
141 {
142 display.particles.emplace_back(spriteNode.textContent());
143 }
144 }
145
146 mMonsterInfos[node.getProperty("id", 0) + mMonsterIdOffset] = currentInfo;
147}
148
153{
154 // there is nothing to check for now
155}
156
158{
159 delete_all(mMonsterInfos);
160 mMonsterInfos.clear();
161
162 mLoaded = false;
163}
164
166{
167 auto i = mMonsterInfos.find(id);
168
169 if (i == mMonsterInfos.end())
170 {
171 Log::info("MonsterDB: Warning, unknown monster ID %d requested", id);
172 return BeingInfo::Unknown;
173 }
174
175 return i->second;
176}
Holds information about a certain type of monster.
Definition beinginfo.h:59
static BeingInfo * Unknown
Definition beinginfo.h:61
Map::BlockType blockType
Definition beinginfo.h:71
int getIntValue(const std::string &key) const
returns a value corresponding to the given key.
@ BLOCKTYPE_MONSTER
Definition map.h:154
int getProperty(const char *name, int def) const
Definition xml.h:144
Children children() const
Definition xml.h:97
Configuration paths
XML default paths information reader.
Definition client.cpp:99
void delete_all(Container &c)
Definition dtor.h:46
#define _(s)
Definition gettext.h:38
#define OLD_TMWATHENA_OFFSET
Definition monsterdb.cpp:35
void info(const char *log_text,...) LOG_PRINTF_ATTR
void init()
Initialize MonsterDB.
Definition monsterdb.cpp:51
void setMonsterIdOffset(int offset)
Definition monsterdb.cpp:60
BeingInfo * get(int id)
void readMonsterNode(XML::Node node, const std::string &filename)
Read <monster> node from settings.
Definition monsterdb.cpp:68
void unload()
void checkStatus()
Check if everything was loaded correctly.
ServerType getNetworkType()
Definition net.cpp:200
std::string missileParticleFilename
Definition beinginfo.h:40
int effectId
Definition beinginfo.h:37
std::string action
Definition beinginfo.h:36
int hitEffectId
Definition beinginfo.h:38
int criticalHitEffectId
Definition beinginfo.h:39
std::vector< SpriteReference > sprites
Definition spritedef.h:44
std::vector< std::string > particles
Definition spritedef.h:45
std::string sprite
Definition spritedef.h:37