Skip to content

Commit

Permalink
Commits till' 14 April 2023
Browse files Browse the repository at this point in the history
Co-Authored-By: Luan Luciano <luanluciano@live.com>
  • Loading branch information
ralke23 and luanzera committed May 26, 2023
1 parent b4c3729 commit 1c99242
Show file tree
Hide file tree
Showing 31 changed files with 242 additions and 246 deletions.
2 changes: 1 addition & 1 deletion data/actions/actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<!-- Other -->
<action itemid="430" script="other/teleport.lua" />
<action itemid="486" script="other/snow_heap.lua" />
<action itemid="1369" script="other/teleport.lua" />
<action itemid="1369" script="other/draw_well.lua" />
<action itemid="1386" script="other/teleport.lua" />
<action fromid="1728" toid="1731" script="other/watch.lua" />
<action fromid="1816" toid="1817" script="other/wall_mirror.lua" />
Expand Down
7 changes: 7 additions & 0 deletions data/actions/scripts/other/draw_well.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item:getActionId() == actionIds.drawWell then
fromPosition.z = fromPosition.z + 1
player:teleportTo(fromPosition, false)
return true
end
end
2 changes: 2 additions & 0 deletions data/events/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<event class="Player" method="onGainExperience" enabled="1" />
<event class="Player" method="onLoseExperience" enabled="0" />
<event class="Player" method="onGainSkillTries" enabled="1" />
<event class="Player" method="onInventoryUpdate" enabled="1" />


<!-- Monster methods -->
<event class="Monster" method="onDropLoot" enabled="1" />
Expand Down
6 changes: 6 additions & 0 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ function Player:onGainSkillTries(skill, tries)
if APPLY_SKILL_MULTIPLIER == false then
return hasEventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES) and EventCallback(EVENT_CALLBACK_ONGAINSKILLTRIES, self, skill, tries) or tries
end

unction Player:onInventoryUpdate(item, slot, equip)
if hasEventCallback(EVENT_CALLBACK_ONINVENTORYUPDATE) then
EventCallback(EVENT_CALLBACK_ONINVENTORYUPDATE, self, item, slot, equip)
end
end

if skill == SKILL_MAGLEVEL then
tries = tries * configManager.getNumber(configKeys.RATE_MAGIC)
Expand Down
1 change: 1 addition & 0 deletions data/lib/core/actionids.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
actionIds = {
sandHole = 100, -- hidden sand hole
pickHole = 105, -- hidden mud hole
drawWell = 106, -- draw well teleport
levelDoor = 1000, -- level door
citizenship = 30020, -- citizenship teleport
citizenshipLast = 30050, -- citizenship teleport last
Expand Down
1 change: 1 addition & 0 deletions data/movements/movements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- Decaying tiles -->
<movevent event="StepIn" itemid="293" script="decay.lua" />
<movevent event="StepIn" itemid="461" script="decay.lua" />
<movevent event="StepIn" itemid="3310" script="decay.lua" />

<!-- (Depot & Level) tiles -->
<movevent event="StepIn" itemid="416" script="tiles.lua" />
Expand Down
3 changes: 3 additions & 0 deletions data/movements/scripts/decay.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
function onStepIn(creature, item, position, fromPosition)
if not creature:isPlayer() or creature:isInGhostMode() then
return true
end
item:transform(item.itemid + 1)
item:decay()
return true
Expand Down
6 changes: 4 additions & 2 deletions data/scripts/lib/event_callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ EVENT_CALLBACK_ONGAINEXPERIENCE = 24
EVENT_CALLBACK_ONLOSEEXPERIENCE = 25
EVENT_CALLBACK_ONGAINSKILLTRIES = 26
EVENT_CALLBACK_ONWRAPITEM = 27
EVENT_CALLBACK_ONINVENTORYUPDATE = 29
-- Monster
EVENT_CALLBACK_ONDROPLOOT = 28
EVENT_CALLBACK_ONSPAWN = 29
EVENT_CALLBACK_ONDROPLOOT = 30
EVENT_CALLBACK_ONSPAWN = 31
-- last (for correct table counting)
EVENT_CALLBACK_LAST = EVENT_CALLBACK_ONSPAWN

Expand Down Expand Up @@ -65,6 +66,7 @@ local callbacks = {
["onLoseExperience"] = EVENT_CALLBACK_ONLOSEEXPERIENCE,
["onGainSkillTries"] = EVENT_CALLBACK_ONGAINSKILLTRIES,
["onWrapItem"] = EVENT_CALLBACK_ONWRAPITEM,
["onInventoryUpdate"] = EVENT_CALLBACK_ONINVENTORYUPDATE,
-- Monster
["onDropLoot"] = EVENT_CALLBACK_ONDROPLOOT,
["onSpawn"] = EVENT_CALLBACK_ONSPAWN
Expand Down
6 changes: 1 addition & 5 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,7 @@ void Creature::onCreatureAppear(Creature* creature, bool isLogin)
void Creature::onRemoveCreature(Creature* creature, bool)
{
onCreatureDisappear(creature, true);
if (creature == this) {
if (master && !master->isRemoved()) {
setMaster(nullptr);
}
} else if (isMapLoaded) {
if (creature != this && isMapLoaded) {
if (creature->getPosition().z == getPosition().z) {
updateTileCache(creature->getTile(), creature->getPosition());
}
Expand Down
6 changes: 3 additions & 3 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,12 @@ struct LightInfo {
struct ShopInfo {
uint16_t itemId = 0;
int32_t subType = 1;
uint32_t buyPrice = 0;
uint32_t sellPrice = 0;
int64_t buyPrice = 0;
int64_t sellPrice = 0;
std::string realName = "";

ShopInfo() = default;
ShopInfo(uint16_t itemId, int32_t subType = 0, uint32_t buyPrice = 0, uint32_t sellPrice = 0, std::string realName = "")
ShopInfo(uint16_t itemId, int32_t subType = 0, int64_t buyPrice = 0, int64_t sellPrice = 0, std::string realName = "")
: itemId(itemId), subType(subType), buyPrice(buyPrice), sellPrice(sellPrice), realName(std::move(realName)) {}
};

Expand Down
10 changes: 10 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ bool Game::removeCreature(Creature* creature, bool isLogout/* = true*/)
spectator->onRemoveCreature(creature, isLogout);
}

Creature* master = creature->getMaster();
if (master && !master->isRemoved()) {
creature->setMaster(nullptr);
}

creature->getParent()->postRemoveNotification(creature, nullptr, 0);

creature->removeList();
Expand Down Expand Up @@ -724,6 +729,11 @@ void Game::playerMoveCreature(Player* player, Creature* movingCreature, const Po
return;
}

if (!Position::areInRange<1, 1, 0>(movingCreaturePos, player->getPosition())) {
player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE);
return;
}

if (player != movingCreature) {
if (toTile->hasFlag(TILESTATE_BLOCKPATH)) {
player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM);
Expand Down
27 changes: 27 additions & 0 deletions src/guild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,30 @@ void Guild::addRank(uint32_t rankId, const std::string& rankName, uint8_t level)
{
ranks.emplace_back(std::make_shared<GuildRank>(rankId, rankName, level));
}

Guild* IOGuild::loadGuild(uint32_t guildId)
{
Database& db = Database::getInstance();
if (DBResult_ptr result = db.storeQuery(fmt::format("SELECT `name` FROM `guilds` WHERE `id` = {:d}", guildId))) {
Guild* guild = new Guild(guildId, result->getString("name"));

if ((result = db.storeQuery(fmt::format("SELECT `id`, `name`, `level` FROM `guild_ranks` WHERE `guild_id` = {:d}", guildId)))) {
do {
guild->addRank(result->getNumber<uint32_t>("id"), result->getString("name"), result->getNumber<uint16_t>("level"));
} while (result->next());
}
return guild;
}
return nullptr;
}

uint32_t IOGuild::getGuildIdByName(const std::string& name)
{
Database& db = Database::getInstance();

DBResult_ptr result = db.storeQuery(fmt::format("SELECT `id` FROM `guilds` WHERE `name` = {:s}", db.escapeString(name)));
if (!result) {
return 0;
}
return result->getNumber<uint32_t>("id");
}
8 changes: 8 additions & 0 deletions src/guild.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,12 @@ class Guild
uint32_t memberCount = 0;
};

using GuildWarVector = std::vector<uint32_t>;

namespace IOGuild
{
Guild* loadGuild(uint32_t guildId);
uint32_t getGuildIdByName(const std::string& name);
};

#endif
70 changes: 0 additions & 70 deletions src/ioguild.cpp

This file was deleted.

34 changes: 0 additions & 34 deletions src/ioguild.h

This file was deleted.

22 changes: 21 additions & 1 deletion src/iologindata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,26 @@ bool IOLoginData::loadPlayerByName(Player* player, const std::string& 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`, `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))));
}

static GuildWarVector getWarList(uint32_t guildId)
{
DBResult_ptr result = Database::getInstance().storeQuery(fmt::format("SELECT `guild1`, `guild2` FROM `guild_wars` WHERE (`guild1` = {:d} OR `guild2` = {:d}) AND `ended` = 0 AND `status` = 1", guildId, guildId));
if (!result) {
return {};
}

GuildWarVector guildWarVector;
do {
uint32_t guild1 = result->getNumber<uint32_t>("guild1");
if (guildId != guild1) {
guildWarVector.push_back(guild1);
}
else {
guildWarVector.push_back(result->getNumber<uint32_t>("guild2"));
}
} while (result->next());
return std::move(guildWarVector);
}

bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result)
{
if (!result) {
Expand Down Expand Up @@ -388,7 +408,7 @@ bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result)

player->guildRank = rank;

IOGuild::getWarList(guildId, player->guildWarVector);
player->guildWarVector = getWarList(guildId);

if ((result = db.storeQuery(fmt::format("SELECT COUNT(*) AS `members` FROM `guild_membership` WHERE `guild_id` = {:d}", guildId)))) {
guild->setMemberCount(result->getNumber<uint32_t>("members"));
Expand Down

0 comments on commit 1c99242

Please sign in to comment.