Skip to content

Commit

Permalink
Added early wings and aura support
Browse files Browse the repository at this point in the history
  • Loading branch information
OTCv8 committed Aug 15, 2020
1 parent 7f5b4fb commit 866a98f
Show file tree
Hide file tree
Showing 20 changed files with 412 additions and 10 deletions.
6 changes: 6 additions & 0 deletions data/XML/auras.xml
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>
6 changes: 6 additions & 0 deletions data/XML/wings.xml
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>
6 changes: 6 additions & 0 deletions data/talkactions/scripts/reload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ local reloadTypes = {
["mount"] = RELOAD_TYPE_MOUNTS,
["mounts"] = RELOAD_TYPE_MOUNTS,

["aura"] = RELOAD_TYPE_AURAS,
["auras"] = RELOAD_TYPE_AURAS,

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

["move"] = RELOAD_TYPE_MOVEMENTS,
["movement"] = RELOAD_TYPE_MOVEMENTS,
["movements"] = RELOAD_TYPE_MOVEMENTS,
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(tfs_SRC
${CMAKE_CURRENT_LIST_DIR}/otpch.cpp
${CMAKE_CURRENT_LIST_DIR}/actions.cpp
${CMAKE_CURRENT_LIST_DIR}/auras.cpp
${CMAKE_CURRENT_LIST_DIR}/ban.cpp
${CMAKE_CURRENT_LIST_DIR}/baseevents.cpp
${CMAKE_CURRENT_LIST_DIR}/bed.cpp
Expand Down Expand Up @@ -75,6 +76,7 @@ set(tfs_SRC
${CMAKE_CURRENT_LIST_DIR}/waitlist.cpp
${CMAKE_CURRENT_LIST_DIR}/weapons.cpp
${CMAKE_CURRENT_LIST_DIR}/wildcardtree.cpp
${CMAKE_CURRENT_LIST_DIR}/wings.cpp
${CMAKE_CURRENT_LIST_DIR}/xtea.cpp
PARENT_SCOPE)

63 changes: 63 additions & 0 deletions src/auras.cpp
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 &it;
}
}

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;
}
33 changes: 33 additions & 0 deletions src/auras.h
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
10 changes: 10 additions & 0 deletions src/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ enum PlayerFlags : uint64_t {
enum ReloadTypes_t : uint8_t {
RELOAD_TYPE_ALL,
RELOAD_TYPE_ACTIONS,
RELOAD_TYPE_AURAS,
RELOAD_TYPE_CHAT,
RELOAD_TYPE_CONFIG,
RELOAD_TYPE_CREATURESCRIPTS,
Expand All @@ -570,6 +571,7 @@ enum ReloadTypes_t : uint8_t {
RELOAD_TYPE_SPELLS,
RELOAD_TYPE_TALKACTIONS,
RELOAD_TYPE_WEAPONS,
RELOAD_TYPE_WINGS,
};

// OTCv8 features (from src/client/const.h)
Expand Down Expand Up @@ -706,6 +708,14 @@ static constexpr int32_t PSTRG_OUTFITS_RANGE_SIZE = 500;
static constexpr int32_t PSTRG_MOUNTS_RANGE_START = (PSTRG_RESERVED_RANGE_START + 2001);
static constexpr int32_t PSTRG_MOUNTS_RANGE_SIZE = 10;
static constexpr int32_t PSTRG_MOUNTS_CURRENTMOUNT = (PSTRG_MOUNTS_RANGE_START + 10);
//[2012 - 2022];
static constexpr int32_t PSTRG_WINGS_RANGE_START = (PSTRG_RESERVED_RANGE_START + 2012);
static constexpr int32_t PSTRG_WINGS_RANGE_SIZE = 10;
static constexpr int32_t PSTRG_WINGS_CURRENTWINGS = (PSTRG_WINGS_RANGE_START + 10);
//[2023 - 2033];
static constexpr int32_t PSTRG_AURAS_RANGE_START = (PSTRG_RESERVED_RANGE_START + 2013);
static constexpr int32_t PSTRG_AURAS_RANGE_SIZE = 10;
static constexpr int32_t PSTRG_AURAS_CURRENTAURA = (PSTRG_AURAS_RANGE_START + 10);


#define IS_IN_KEYRANGE(key, range) (key >= PSTRG_##range##_START && ((key - PSTRG_##range##_START) <= PSTRG_##range##_SIZE))
Expand Down
2 changes: 2 additions & 0 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ struct Outfit_t {
uint16_t lookType = 0;
uint16_t lookTypeEx = 0;
uint16_t lookMount = 0;
uint16_t lookWings = 0;
uint16_t lookAura = 0;
uint8_t lookHead = 0;
uint8_t lookBody = 0;
uint8_t lookLegs = 0;
Expand Down
16 changes: 14 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ void Game::setGameState(GameState_t newState)

quests.loadFromXml();
mounts.loadFromXml();
auras.loadFromXml();
wings.loadFromXml();

loadMotdNum();
loadPlayersRecord();
Expand Down Expand Up @@ -3361,14 +3363,15 @@ void Game::playerRequestOutfit(uint32_t playerId)
player->sendOutfitWindow();
}

void Game::playerToggleMount(uint32_t playerId, bool mount)
void Game::playerToggleOutfitExtension(uint32_t playerId, int mount, int wings, int aura)
{
Player* player = getPlayerByID(playerId);
if (!player) {
return;
}

player->toggleMount(mount);
if(mount != -1)
player->toggleMount(mount == 1);
}

void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit)
Expand All @@ -3385,6 +3388,8 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit)
const Outfit* playerOutfit = Outfits::getInstance().getOutfitByLookType(player->getSex(), outfit.lookType);
if (!playerOutfit) {
outfit.lookMount = 0;
outfit.lookWings = 0;
outfit.lookAura = 0;
}

if (outfit.lookMount != 0) {
Expand Down Expand Up @@ -5831,6 +5836,7 @@ bool Game::reload(ReloadTypes_t reloadType)
{
switch (reloadType) {
case RELOAD_TYPE_ACTIONS: return g_actions->reload();
case RELOAD_TYPE_AURAS: return auras.reload();
case RELOAD_TYPE_CHAT: return g_chat->load();
case RELOAD_TYPE_CONFIG: return g_config.reload();
case RELOAD_TYPE_CREATURESCRIPTS: {
Expand Down Expand Up @@ -5871,6 +5877,8 @@ bool Game::reload(ReloadTypes_t reloadType)
return results;
}

case RELOAD_TYPE_WINGS: return wings.reload();

case RELOAD_TYPE_SCRIPTS: {
// commented out stuff is TODO, once we approach further in revscriptsys
g_actions->clear(true);
Expand All @@ -5889,6 +5897,8 @@ bool Game::reload(ReloadTypes_t reloadType)
Item::items.reload();
quests.reload();
mounts.reload();
auras.reload();
wings.reload();
g_config.reload();
g_events->load();
g_chat->load();
Expand Down Expand Up @@ -5918,7 +5928,9 @@ bool Game::reload(ReloadTypes_t reloadType)
g_weapons->clear(true);
g_weapons->loadDefaults();
quests.reload();
auras.reload();
mounts.reload();
wings.reload();
g_globalEvents->reload();
g_events->load();
g_chat->load();
Expand Down
6 changes: 4 additions & 2 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class Game
void playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId);
void playerLeaveParty(uint32_t playerId);
void playerEnableSharedPartyExperience(uint32_t playerId, bool sharedExpActive);
void playerToggleMount(uint32_t playerId, bool mount);
void playerToggleOutfitExtension(uint32_t playerId, int mount, int wings, int aura);
void playerLeaveMarket(uint32_t playerId);
void playerBrowseMarket(uint32_t playerId, uint16_t spriteId);
void playerBrowseMarketOwnOffers(uint32_t playerId);
Expand Down Expand Up @@ -501,11 +501,13 @@ class Game

bool reload(ReloadTypes_t reloadType);

Auras auras;
Groups groups;
Map map;
Map map;
Mounts mounts;
Raids raids;
Quests quests;
Wings wings;

std::forward_list<Item*> toDecayItems;

Expand Down
10 changes: 9 additions & 1 deletion src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ Outfit_t LuaScriptInterface::getOutfit(lua_State* L, int32_t arg)
{
Outfit_t outfit;
outfit.lookMount = getField<uint16_t>(L, arg, "lookMount");
outfit.lookWings = getField<uint16_t>(L, arg, "lookWings");
outfit.lookAura = getField<uint16_t>(L, arg, "lookAura");
outfit.lookAddons = getField<uint8_t>(L, arg, "lookAddons");

outfit.lookFeet = getField<uint8_t>(L, arg, "lookFeet");
Expand Down Expand Up @@ -948,6 +950,8 @@ void LuaScriptInterface::pushOutfit(lua_State* L, const Outfit_t& outfit)
setField(L, "lookFeet", outfit.lookFeet);
setField(L, "lookAddons", outfit.lookAddons);
setField(L, "lookMount", outfit.lookMount);
setField(L, "lookWings", outfit.lookWings);
setField(L, "lookAura", outfit.lookAura);
}

void LuaScriptInterface::pushLoot(lua_State* L, const std::vector<LootBlock>& lootList)
Expand Down Expand Up @@ -1821,6 +1825,7 @@ void LuaScriptInterface::registerFunctions()

registerEnum(RELOAD_TYPE_ALL)
registerEnum(RELOAD_TYPE_ACTIONS)
registerEnum(RELOAD_TYPE_AURAS)
registerEnum(RELOAD_TYPE_CHAT)
registerEnum(RELOAD_TYPE_CONFIG)
registerEnum(RELOAD_TYPE_CREATURESCRIPTS)
Expand All @@ -1838,6 +1843,7 @@ void LuaScriptInterface::registerFunctions()
registerEnum(RELOAD_TYPE_SPELLS)
registerEnum(RELOAD_TYPE_TALKACTIONS)
registerEnum(RELOAD_TYPE_WEAPONS)
registerEnum(RELOAD_TYPE_WINGS)

registerEnum(ZONE_PROTECTION)
registerEnum(ZONE_NOPVP)
Expand Down Expand Up @@ -12084,11 +12090,13 @@ int LuaScriptInterface::luaConditionSetFormula(lua_State* L)
int LuaScriptInterface::luaConditionSetOutfit(lua_State* L)
{
// condition:setOutfit(outfit)
// condition:setOutfit(lookTypeEx, lookType, lookHead, lookBody, lookLegs, lookFeet[, lookAddons[, lookMount]])
// condition:setOutfit(lookTypeEx, lookType, lookHead, lookBody, lookLegs, lookFeet[, lookAddons[, lookMount, lookWings, lookAura]])
Outfit_t outfit;
if (isTable(L, 2)) {
outfit = getOutfit(L, 2);
} else {
outfit.lookAura = getNumber<uint16_t>(L, 11, outfit.lookAura);
outfit.lookWings = getNumber<uint16_t>(L, 10, outfit.lookWings);
outfit.lookMount = getNumber<uint16_t>(L, 9, outfit.lookMount);
outfit.lookAddons = getNumber<uint8_t>(L, 8, outfit.lookAddons);
outfit.lookFeet = getNumber<uint8_t>(L, 7);
Expand Down
8 changes: 8 additions & 0 deletions src/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,14 @@ MonsterType* Monsters::loadMonster(const std::string& file, const std::string& m
mType->info.outfit.lookMount = pugi::cast<uint16_t>(attr.value());
}

if ((attr = node.attribute("aura"))) {
mType->info.outfit.lookAura = pugi::cast<uint16_t>(attr.value());
}

if ((attr = node.attribute("wings"))) {
mType->info.outfit.lookWings = pugi::cast<uint16_t>(attr.value());
}

if ((attr = node.attribute("corpse"))) {
mType->info.lookcorpse = pugi::cast<uint16_t>(attr.value());
}
Expand Down
6 changes: 6 additions & 0 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ bool Npc::loadFromXml()
defaultOutfit.lookTypeEx = pugi::cast<uint16_t>(attr.value());
}
defaultOutfit.lookMount = pugi::cast<uint16_t>(lookNode.attribute("mount").value());
if ((attr = lookNode.attribute("wings"))) {
defaultOutfit.lookWings = pugi::cast<uint16_t>(attr.value());
}
if ((attr = lookNode.attribute("aura"))) {
defaultOutfit.lookAura = pugi::cast<uint16_t>(attr.value());
}

currentOutfit = defaultOutfit;
}
Expand Down
Loading

0 comments on commit 866a98f

Please sign in to comment.