forked from otland/forgottenserver
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
412 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<auras> | ||
<!-- <aura id="1" clientid="368" name="Widow Queen" speed="20" /> | ||
<aura id="2" clientid="369" name="Racing Bird" speed="20" /> | ||
<aura id="3" clientid="370" name="War Bear" speed="20" /> --> | ||
</auras> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<wings> | ||
<!-- <wing id="1" clientid="368" name="Widow Queen" speed="20" /> | ||
<wing id="2" clientid="369" name="Racing Bird" speed="20" /> | ||
<wing id="3" clientid="370" name="War Bear" speed="20" /> --> | ||
</wings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "otpch.h" | ||
|
||
#include "auras.h" | ||
|
||
#include "pugicast.h" | ||
#include "tools.h" | ||
|
||
bool Auras::reload() | ||
{ | ||
auras.clear(); | ||
return loadFromXml(); | ||
} | ||
|
||
bool Auras::loadFromXml() | ||
{ | ||
pugi::xml_document doc; | ||
pugi::xml_parse_result result = doc.load_file("data/XML/auras.xml"); | ||
if (!result) { | ||
printXMLError("Error - Auras::loadFromXml", "data/XML/auras.xml", result); | ||
return false; | ||
} | ||
|
||
for (auto auraNode : doc.child("auras").children()) { | ||
auras.emplace_back( | ||
static_cast<uint8_t>(pugi::cast<uint16_t>(auraNode.attribute("id").value())), | ||
pugi::cast<uint16_t>(auraNode.attribute("clientid").value()), | ||
auraNode.attribute("name").as_string(), | ||
pugi::cast<int32_t>(auraNode.attribute("speed").value()), | ||
auraNode.attribute("premium").as_bool() | ||
); | ||
} | ||
auras.shrink_to_fit(); | ||
return true; | ||
} | ||
|
||
Aura* Auras::getAuraByID(uint8_t id) | ||
{ | ||
auto it = std::find_if(auras.begin(), auras.end(), [id](const Aura& aura) { | ||
return aura.id == id; | ||
}); | ||
|
||
return it != auras.end() ? &*it : nullptr; | ||
} | ||
|
||
Aura* Auras::getAuraByName(const std::string& name) { | ||
auto auraName = name.c_str(); | ||
for (auto& it : auras) { | ||
if (strcasecmp(auraName, it.name.c_str()) == 0) { | ||
return ⁢ | ||
} | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
Aura* Auras::getAuraByClientID(uint16_t clientId) | ||
{ | ||
auto it = std::find_if(auras.begin(), auras.end(), [clientId](const Aura& aura) { | ||
return aura.clientId == clientId; | ||
}); | ||
|
||
return it != auras.end() ? &*it : nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef FS_AURAS_H | ||
#define FS_AURAS_H | ||
|
||
struct Aura | ||
{ | ||
Aura(uint8_t id, uint16_t clientId, std::string name, int32_t speed, bool premium) : | ||
name(std::move(name)), speed(speed), clientId(clientId), id(id), premium(premium) {} | ||
|
||
std::string name; | ||
int32_t speed; | ||
uint16_t clientId; | ||
uint8_t id; | ||
bool premium; | ||
}; | ||
|
||
class Auras | ||
{ | ||
public: | ||
bool reload(); | ||
bool loadFromXml(); | ||
Aura* getAuraByID(uint8_t id); | ||
Aura* getAuraByName(const std::string& name); | ||
Aura* getAuraByClientID(uint16_t clientId); | ||
|
||
const std::vector<Aura>& getAuras() const { | ||
return auras; | ||
} | ||
|
||
private: | ||
std::vector<Aura> auras; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.