effects.cpp

main 64 lines · 1.5 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1#include "otpch.h"
2
3#include "effects.h"
4
5#include "pugicast.h"
6#include "tools.h"
7
8bool Effects::reload()
9{
10 effects.clear();
11 return loadFromXml();
12}
13
14bool Effects::loadFromXml()
15{
16 pugi::xml_document doc;
17 pugi::xml_parse_result result = doc.load_file("data/XML/effects.xml");
18 if (!result) {
19 printXMLError("Error - Effects::loadFromXml", "data/XML/effects.xml", result);
20 return false;
21 }
22
23 for (auto effectNode : doc.child("effects").children()) {
24 effects.emplace_back(
25 static_cast<uint16_t>(pugi::cast<uint16_t>(effectNode.attribute("id").value())), // Changed from uint8_t to uint16_t
26 pugi::cast<uint16_t>(effectNode.attribute("clientid").value()),
27 effectNode.attribute("name").as_string(),
28 pugi::cast<int32_t>(effectNode.attribute("speed").value()),
29 effectNode.attribute("premium").as_bool()
30 );
31 }
32 effects.shrink_to_fit();
33 return true;
34}
35
36Effect* Effects::getEffectByID(uint16_t id) // Changed from uint8_t to uint16_t
37{
38 auto it = std::find_if(effects.begin(), effects.end(), [id](const Effect& effect) {
39 return effect.id == id;
40 });
41
42 return it != effects.end() ? &*it : nullptr;
43}
44
45Effect* Effects::getEffectByName(const std::string& name) {
46 auto effectName = name.c_str();
47 for (auto& it : effects) {
48 if (strcasecmp(effectName, it.name.c_str()) == 0) {
49 return &it;
50 }
51 }
52
53 return nullptr;
54}
55
56Effect* Effects::getEffectByClientID(uint16_t clientId)
57{
58 auto it = std::find_if(effects.begin(), effects.end(), [clientId](const Effect& effect) {
59 return effect.clientId == clientId;
60 });
61
62 return it != effects.end() ? &*it : nullptr;
63}
64
Top