Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Attach Effect] Outfit -> Wings // Auras // Effects #7

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data/XML/auras.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<auras>
<aura id="8" name="3 aura" speed="20" />
</auras>
4 changes: 4 additions & 0 deletions data/XML/effects.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<effects>
<effect id="7" name="1 effect" speed="20" />
</effects>
5 changes: 5 additions & 0 deletions data/XML/wings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<wings>
<wing id="2" name="1 wings" speed="20" />
<wing id="11" name="11 wings" speed="20" />
</wings>
9 changes: 9 additions & 0 deletions data/talkactions/scripts/reload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ local reloadTypes = {

["mount"] = RELOAD_TYPE_MOUNTS,
["mounts"] = RELOAD_TYPE_MOUNTS,

["wing"] = RELOAD_TYPE_WINGS,
["wings"] = RELOAD_TYPE_WINGS,

["effect"] = RELOAD_TYPE_EFFECT,
["effects"] = RELOAD_TYPE_EFFECT,

["aura"] = RELOAD_TYPE_AURA,
["auras"] = RELOAD_TYPE_AURA,

["move"] = RELOAD_TYPE_MOVEMENTS,
["movement"] = RELOAD_TYPE_MOVEMENTS,
Expand Down
29 changes: 27 additions & 2 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ CREATE TABLE IF NOT EXISTS `players` (
`lookaddons` int NOT NULL DEFAULT '0',
`currentmount` smallint UNSIGNED NOT NULL DEFAULT '0',
`randomizemount` tinyint NOT NULL DEFAULT '0',
`currentwing` smallint UNSIGNED NOT NULL DEFAULT '0',
`randomizewing` tinyint NOT NULL DEFAULT '0',
`currentaura` smallint UNSIGNED NOT NULL DEFAULT '0',
`randomizeaura` tinyint NOT NULL DEFAULT '0',
`currenteffect` smallint UNSIGNED NOT NULL DEFAULT '0',
`randomizeeffect` tinyint NOT NULL DEFAULT '0',
`direction` tinyint unsigned NOT NULL DEFAULT '2',
`currentmount` smallint unsigned NOT NULL DEFAULT '0',
`randomizemount` tinyint NOT NULL DEFAULT '0',
`maglevel` int NOT NULL DEFAULT '0',
`mana` int NOT NULL DEFAULT '0',
`manamax` int NOT NULL DEFAULT '0',
Expand Down Expand Up @@ -360,6 +364,27 @@ CREATE TABLE `player_mounts` (
`mount_id` smallint UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `player_wings` (
`player_id` int NOT NULL DEFAULT '0',
`wing_id` smallint unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`player_id`,`wing_id`),
FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;

CREATE TABLE IF NOT EXISTS `player_effects` (
`player_id` int NOT NULL DEFAULT '0',
`effect_id` smallint unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`player_id`,`effect_id`),
FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;

CREATE TABLE IF NOT EXISTS `player_auras` (
`player_id` int NOT NULL DEFAULT '0',
`aura_id` smallint unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`player_id`,`aura_id`),
FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;

CREATE TABLE IF NOT EXISTS `server_config` (
`config` varchar(50) NOT NULL,
`value` varchar(256) NOT NULL DEFAULT '',
Expand Down
64 changes: 64 additions & 0 deletions src/auras.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2023 The Forgotten Server Authors. All rights reserved.
// Use of this source code is governed by the GPL-2.0 License that can be found in the LICENSE file.

#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()) {
uint16_t nodeId = pugi::cast<uint16_t>(auraNode.attribute("id").value());
if (nodeId == 0 || nodeId > std::numeric_limits<uint16_t>::max()) {
std::cout << "[Notice - Auras::loadFromXml] Aura id "" << nodeId << "" is not within 1 and 65535 range"
<< std::endl;
continue;
}

if (getAuraByID(nodeId)) {
std::cout << "[Notice - Auras::loadFromXml] Duplicate aura with id: " << nodeId << std::endl;
continue;
}

auras.emplace_back(
static_cast<uint16_t>(nodeId),
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(uint16_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(std::string_view name)
{
for (auto& it : auras) {
if (caseInsensitiveEqual(name, it.name)) {
return &it;
}
}

return nullptr;
}
35 changes: 35 additions & 0 deletions src/auras.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2023 The Forgotten Server Authors. All rights reserved.
// Use of this source code is governed by the GPL-2.0 License that can be found in the LICENSE file.

#ifndef FS_AURAS_H
#define FS_AURAS_H

struct Aura
{
Aura(uint16_t id, std::string_view name, int32_t speed, bool premium) :
name{name}, speed{speed}, id{id}, premium{premium}
{}

std::string name;
int32_t speed;

uint16_t id;
bool premium;
};

class Auras
{
public:
bool reload();
bool loadFromXml();
Aura* getAuraByID(uint16_t id);
Aura* getAuraByName(std::string_view name);


const std::vector<Aura>& getAuras() const { return auras; }

private:
std::vector<Aura> auras;
};

#endif // FS_AURAS_H
3 changes: 3 additions & 0 deletions src/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ enum ReloadTypes_t : uint8_t
RELOAD_TYPE_ITEMS,
RELOAD_TYPE_MONSTERS,
RELOAD_TYPE_MOUNTS,
RELOAD_TYPE_WINGS,
RELOAD_TYPE_AURAS,
RELOAD_TYPE_EFFECTS,
RELOAD_TYPE_MOVEMENTS,
RELOAD_TYPE_NPCS,
RELOAD_TYPE_QUESTS,
Expand Down
3 changes: 3 additions & 0 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ class Creature : virtual public Thing
Outfit_t currentOutfit;
Outfit_t defaultOutfit;
uint16_t currentMount;
uint16_t currentWing;
uint16_t currentAura;
uint16_t currentEffect;

Position lastPosition;
LightInfo internalLight;
Expand Down
64 changes: 64 additions & 0 deletions src/effects.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2023 The Forgotten Server Authors. All rights reserved.
// Use of this source code is governed by the GPL-2.0 License that can be found in the LICENSE file.

#include "otpch.h"

#include "effects.h"

#include "pugicast.h"
#include "tools.h"

bool Effects::reload()
{
effects.clear();
return loadFromXml();
}

bool Effects::loadFromXml()
{
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file("data/XML/effects.xml");
if (!result) {
printXMLError("Error - Effects::loadFromXml", "data/XML/effects.xml", result);
return false;
}

for (auto effectNode : doc.child("effects").children()) {
uint16_t nodeId = pugi::cast<uint16_t>(effectNode.attribute("id").value());
if (nodeId == 0 || nodeId > std::numeric_limits<uint16_t>::max()) {
std::cout << "[Notice - Effects::loadFromXml] Effect id "" << nodeId << "" is not within 1 and 65535 range"
<< std::endl;
continue;
}

if (getEffectByID(nodeId)) {
std::cout << "[Notice - Effects::loadFromXml] Duplicate effect with id: " << nodeId << std::endl;
continue;
}

effects.emplace_back(
static_cast<uint16_t>(nodeId),
effectNode.attribute("name").as_string(), pugi::cast<int32_t>(effectNode.attribute("speed").value()),
effectNode.attribute("premium").as_bool());
}
effects.shrink_to_fit();
return true;
}

Effect* Effects::getEffectByID(uint16_t id)
{
auto it = std::find_if(effects.begin(), effects.end(), [id](const Effect& effect) { return effect.id == id; });

return it != effects.end() ? &*it : nullptr;
}

Effect* Effects::getEffectByName(std::string_view name)
{
for (auto& it : effects) {
if (caseInsensitiveEqual(name, it.name)) {
return &it;
}
}

return nullptr;
}
35 changes: 35 additions & 0 deletions src/effects.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2023 The Forgotten Server Authors. All rights reserved.
// Use of this source code is governed by the GPL-2.0 License that can be found in the LICENSE file.

#ifndef FS_EFFECTS_H
#define FS_EFFECTS_H

struct Effect
{
Effect(uint16_t id, std::string_view name, int32_t speed, bool premium) :
name{name}, speed{speed}, id{id}, premium{premium}
{}

std::string name;
int32_t speed;

uint16_t id;
bool premium;
};

class Effects
{
public:
bool reload();
bool loadFromXml();
Effect* getEffectByID(uint16_t id);
Effect* getEffectByName(std::string_view name);


const std::vector<Effect>& getEffects() const { return effects; }

private:
std::vector<Effect> effects;
};

#endif // FS_EFFECTS_H
3 changes: 3 additions & 0 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ struct Outfit_t
uint16_t lookType = 0;
uint16_t lookTypeEx = 0;
uint16_t lookMount = 0;
uint16_t lookWing = 0;
uint16_t lookAura = 0;
uint16_t lookEffect = 0;
uint8_t lookHead = 0;
uint8_t lookBody = 0;
uint8_t lookLegs = 0;
Expand Down
Loading