Skip to content

Commit

Permalink
feat: [Attach Effect] Wings
Browse files Browse the repository at this point in the history
  • Loading branch information
kokekanon committed Apr 13, 2024
1 parent 9030c06 commit 8dfe3b7
Show file tree
Hide file tree
Showing 19 changed files with 505 additions and 24 deletions.
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="2" name="1 wings" speed="20" />
<wing id="11" name="2 wings" speed="20" />
<wing id="8" name="3 wings" speed="20" />
</wings>
5 changes: 4 additions & 1 deletion data/talkactions/scripts/reload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ local reloadTypes = {

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


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

["move"] = RELOAD_TYPE_MOVEMENTS,
["movement"] = RELOAD_TYPE_MOVEMENTS,
["movements"] = RELOAD_TYPE_MOVEMENTS,
Expand Down
13 changes: 11 additions & 2 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ 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',
`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 +360,15 @@ 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 `server_config` (
`config` varchar(50) NOT NULL,
`value` varchar(256) NOT NULL DEFAULT '',
Expand Down
1 change: 1 addition & 0 deletions src/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ enum ReloadTypes_t : uint8_t
RELOAD_TYPE_ITEMS,
RELOAD_TYPE_MONSTERS,
RELOAD_TYPE_MOUNTS,
RELOAD_TYPE_WINGS,
RELOAD_TYPE_MOVEMENTS,
RELOAD_TYPE_NPCS,
RELOAD_TYPE_QUESTS,
Expand Down
1 change: 1 addition & 0 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ class Creature : virtual public Thing
Outfit_t currentOutfit;
Outfit_t defaultOutfit;
uint16_t currentMount;
uint16_t currentWing;

Position lastPosition;
LightInfo internalLight;
Expand Down
1 change: 1 addition & 0 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ struct Outfit_t
uint16_t lookType = 0;
uint16_t lookTypeEx = 0;
uint16_t lookMount = 0;
uint16_t lookWing = 0;
uint8_t lookHead = 0;
uint8_t lookBody = 0;
uint8_t lookLegs = 0;
Expand Down
35 changes: 26 additions & 9 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void Game::setGameState(GameState_t newState)
map.spawns.startup();

mounts.loadFromXml();
wings.loadFromXml();

raids.loadFromXml();
raids.startup();
Expand Down Expand Up @@ -2014,7 +2015,6 @@ void Game::playerSetTyping(uint32_t playerId, bool typing)
}
}


void Game::playerReceivePing(uint32_t playerId)
{
Player* player = getPlayerByID(playerId);
Expand Down Expand Up @@ -3426,6 +3426,7 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, bool randomize
const Outfit* playerOutfit = Outfits::getInstance().getOutfitByLookType(outfit.lookType);
if (!playerOutfit) {
outfit.lookMount = 0;
// outfit.lookWing = 0;
}

if (outfit.lookMount != 0) {
Expand Down Expand Up @@ -3456,6 +3457,28 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, bool randomize
player->wasMounted = false;
}

/// wings
if (outfit.lookWing != 0) {
Wing* wing = wings.getWingByID(outfit.lookWing);
if (!wing) {
return;
}

if (!player->hasWing(wing)) {
return;
}

player->detachEffectById(player->getCurrentWing());
player->setCurrentWing(wing->id);
player->attachEffectById(wing->id);
} else {
if (player->isWinged()) {
player->diswing();
}
player->detachEffectById(player->getCurrentWing());
player->wasWinged = false;
}

if (player->canWear(outfit.lookType, outfit.lookAddons)) {
player->defaultOutfit = outfit;

Expand Down Expand Up @@ -5363,10 +5386,6 @@ bool Game::reload(ReloadTypes_t reloadType)
return true;
}





void Game::sendAttachedEffect(const Creature* creature, uint16_t effectId)
{
SpectatorVec spectators;
Expand Down Expand Up @@ -5412,7 +5431,6 @@ void Game::updateCreatureShader(const Creature* creature)
}
}


void Game::refreshItem(const Item* item)
{
if (!item || !item->getParent()) return;
Expand All @@ -5428,7 +5446,7 @@ void Game::refreshItem(const Item* item)
return;
}

if (const auto container = parent->getContainer()) {
if (const auto container = parent->getContainer()) {
int32_t index = container->getThingIndex(item);
if (index > -1 && index <= std::numeric_limits<uint16_t>::max()) {
SpectatorVec spectators;
Expand Down Expand Up @@ -5465,6 +5483,5 @@ void Game::sendPlayerToolsTips(uint32_t playerId, uint16_t itemID)
}
const ItemType& itemType = Item::items.getItemIdByClientId(itemID);

g_events->eventPlayeronToolsTips(player, itemType.id);

g_events->eventPlayeronToolsTips(player, itemType.id);
}
2 changes: 2 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "item.h"
#include "map.h"
#include "mounts.h"
#include "wings.h"
#include "npc.h"
#include "player.h"
#include "position.h"
Expand Down Expand Up @@ -486,6 +487,7 @@ class Game
Map map;
Raids raids;
Mounts mounts;
Wings wings;

std::forward_list<Item*> toDecayItems;

Expand Down
39 changes: 36 additions & 3 deletions src/iologindata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ bool IOLoginData::loadPlayerById(Player* player, uint32_t id)
return loadPlayer(
player,
db.storeQuery(fmt::format(
"SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `blessings`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `currentmount`, `randomizemount`, `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skulltime`, `skull`, `town_id`, `balance`, `stamina`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries`, `direction` FROM `players` WHERE `id` = {:d}",
"SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `blessings`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `currentmount`, `randomizemount`, `currentwing`, `randomizewing`, `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skulltime`, `skull`, `town_id`, `balance`, `stamina`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries`, `direction` FROM `players` WHERE `id` = {:d}",
id)));
}

Expand All @@ -239,7 +239,7 @@ bool IOLoginData::loadPlayerByName(Player* player, std::string_view name)
return loadPlayer(
player,
db.storeQuery(fmt::format(
"SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `blessings`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `currentmount`, `randomizemount`, `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skulltime`, `skull`, `town_id`, `balance`, `stamina`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries`, `direction` FROM `players` WHERE `name` = {:s}",
"SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `blessings`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `currentmount`, `randomizemount`, `currentwing`, `randomizewing`, `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skulltime`, `skull`, `town_id`, `balance`, `stamina`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries`, `direction` FROM `players` WHERE `name` = {:s}",
db.escapeString(name))));
}

Expand Down Expand Up @@ -361,9 +361,10 @@ bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result)
player->defaultOutfit.lookAddons = result->getNumber<uint16_t>("lookaddons");
player->currentOutfit = player->defaultOutfit;
player->currentMount = result->getNumber<uint16_t>("currentmount");
player->currentWing = result->getNumber<uint16_t>("currentwing");
player->direction = static_cast<Direction>(result->getNumber<uint16_t>("direction"));
player->randomizeMount = result->getNumber<uint8_t>("randomizemount") != 0;

player->randomizeWing = result->getNumber<uint8_t>("randomizewing") != 0;
if (g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED) {
const time_t skullSeconds = result->getNumber<time_t>("skulltime") - time(nullptr);
if (skullSeconds > 0) {
Expand Down Expand Up @@ -598,6 +599,19 @@ bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result)
} while (result->next());
}

// load Wings
if ((result = db.storeQuery(
fmt::format("SELECT `wing_id` FROM `player_wings` WHERE `player_id` = {:d}", player->getGUID())))) {
do {
player->tameWing(result->getNumber<uint16_t>("wing_id"));
} while (result->next());
}

uint16_t currentWing = player->getCurrentWing();
if (currentWing > 0) {
player->attachEffectById(currentWing);
}

player->updateBaseSpeed();
player->updateInventoryWeight();
player->updateItemsLight(true);
Expand Down Expand Up @@ -705,6 +719,8 @@ bool IOLoginData::savePlayer(Player* player)
query << "`lookaddons` = " << static_cast<uint32_t>(player->defaultOutfit.lookAddons) << ',';
query << "`currentmount` = " << static_cast<uint16_t>(player->currentMount) << ',';
query << "`randomizemount` = " << player->randomizeMount << ",";
query << "`currentwing` = " << static_cast<uint16_t>(player->currentWing) << ',';
query << "`randomizewing` = " << player->randomizeWing << ",";
query << "`maglevel` = " << player->magLevel << ',';
query << "`mana` = " << player->mana << ',';
query << "`manamax` = " << player->manaMax << ',';
Expand Down Expand Up @@ -923,6 +939,23 @@ bool IOLoginData::savePlayer(Player* player)
return false;
}

// save wings
if (!db.executeQuery(fmt::format("DELETE FROM `player_wings` WHERE `player_id` = {:d}", player->getGUID()))) {
return false;
}

DBInsert wingQuery("INSERT INTO `player_wings` (`player_id`, `wing_id`) VALUES ");

for (const auto& it : player->wings) {
if (!wingQuery.addRow(fmt::format("{:d}, {:d}", player->getGUID(), it))) {
return false;
}
}

if (!wingQuery.execute()) {
return false;
}

// End the transaction
return transaction.commit();
}
Expand Down
18 changes: 17 additions & 1 deletion src/luagame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ int luaGameGetMounts(lua_State* L)
return 1;
}

int luaGameGetWings(lua_State* L)
{
// Game.getWings()
const auto& wings = g_game.wings.getWings();
lua_createtable(L, wings.size(), 0);

int index = 0;
for (const auto& wing : wings) {
pushWing(L, &wing);
lua_rawseti(L, -2, ++index);
}

return 1;
}

int luaGameGetVocations(lua_State* L)
{
// Game.getVocations()
Expand Down Expand Up @@ -436,7 +451,7 @@ int luaGameCreateMonster(lua_State* L)
monster->setShader(monster->shaderEffect());
g_game.updateCreatureShader(monster);
}

} else {
delete monster;
lua_pushnil(L);
Expand Down Expand Up @@ -690,6 +705,7 @@ void LuaScriptInterface::registerGame()
registerMethod("Game", "getHouses", luaGameGetHouses);
registerMethod("Game", "getOutfits", luaGameGetOutfits);
registerMethod("Game", "getMounts", luaGameGetMounts);
registerMethod("Game", "getWings", luaGameGetWings);

registerMethod("Game", "getGameState", luaGameGetGameState);
registerMethod("Game", "setGameState", luaGameSetGameState);
Expand Down
Loading

1 comment on commit 8dfe3b7

@kokekanon
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.