Skip to content

Commit

Permalink
Merge branch 'main' into remove_walkcache_code
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah authored Nov 10, 2024
2 parents fde69e4 + 685f4cd commit fdfd384
Show file tree
Hide file tree
Showing 32 changed files with 94 additions and 51 deletions.
6 changes: 5 additions & 1 deletion data-otservbr-global/migrations/46.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
function onUpdateDatabase()
return false -- true = There are others migrations file | false = this is the last migration file
logger.info("Updating database to version 47 (fix: creature speed and conditions)")

db.query("ALTER TABLE `players` MODIFY `conditions` mediumblob NOT NULL;")

return true
end
3 changes: 3 additions & 0 deletions data-otservbr-global/migrations/47.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function onUpdateDatabase()
return false -- true = There are others migrations file | false = this is the last migration file
end
10 changes: 5 additions & 5 deletions data-otservbr-global/scripts/creaturescripts/others/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ function playerLogin.onLogin(player)
town = table.contains(freeTowns, town:getName()) and town or Town(defaultTown)
player:teleportTo(town:getTemplePosition())
player:setTown(town)
player:sendTextMessage(MESSAGE_FAILURE, "Your premium time has expired.")
player:sendTextMessage(MESSAGE_FAILURE, "Your premium time has expired!")

if sex == 1 then
player:setOutfit({ lookType = 128, lookFeet = 114, lookLegs = 134, lookHead = 114, lookAddons = 0 })
player:setOutfit({ lookType = 128, lookHead = 114, lookBody = 120, lookLegs = 132, lookFeet = 115, lookAddons = 0 })
elseif sex == 0 then
player:setOutfit({ lookType = 136, lookFeet = 114, lookLegs = 134, lookHead = 114, lookAddons = 0 })
player:setOutfit({ lookType = 136, lookHead = 114, lookBody = 120, lookLegs = 132, lookFeet = 115, lookAddons = 0 })
end

if home and not player:isPremium() then
setHouseOwner(home, 0)
player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "You've lost your house because you are not premium anymore.")
player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "Your items from house are send to your inbox.")
player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "You have lost your house because you are no longer a premium account.")
player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "Your items from the house have been sent to your inbox.")
end
end

Expand Down
2 changes: 1 addition & 1 deletion schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ CREATE TABLE IF NOT EXISTS `players` (
`posx` int(11) NOT NULL DEFAULT '0',
`posy` int(11) NOT NULL DEFAULT '0',
`posz` int(11) NOT NULL DEFAULT '0',
`conditions` blob NOT NULL,
`conditions` mediumblob NOT NULL,
`cap` int(11) NOT NULL DEFAULT '0',
`sex` int(11) NOT NULL DEFAULT '0',
`pronoun` int(11) NOT NULL DEFAULT '0',
Expand Down
1 change: 1 addition & 0 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "lua/callbacks/events_callbacks.hpp"
#include "lua/creature/events.hpp"
#include "map/spectators.hpp"
#include "creatures/players/player.hpp"

int32_t Combat::getLevelFormula(const std::shared_ptr<Player> &player, const std::shared_ptr<Spell> &wheelSpell, const CombatDamage &damage) const {
if (!player) {
Expand Down
4 changes: 4 additions & 0 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,10 @@ LightInfo Creature::getCreatureLight() const {
return internalLight;
}

uint16_t Creature::getSpeed() const {
return std::clamp(baseSpeed + varSpeed, 0, static_cast<int>(std::numeric_limits<uint16_t>::max()));
}

void Creature::setSpeed(int32_t varSpeedDelta) {
// Prevents creatures from not exceeding the maximum allowed speed
if (getSpeed() >= PLAYER_MAX_SPEED) {
Expand Down
4 changes: 1 addition & 3 deletions src/creatures/creature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ class Creature : virtual public Thing, public SharedObject {
virtual uint16_t getStepSpeed() const {
return getSpeed();
}
uint16_t getSpeed() const {
return static_cast<uint16_t>(baseSpeed + varSpeed);
}
uint16_t getSpeed() const;
void setSpeed(int32_t varSpeedDelta);

void setBaseSpeed(uint16_t newBaseSpeed) {
Expand Down
5 changes: 3 additions & 2 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "creatures/players/player.hpp"

#include "account/account.hpp"
#include "config/configmanager.hpp"
#include "core.hpp"
#include "creatures/appearance/mounts/mounts.hpp"
Expand Down Expand Up @@ -1773,8 +1774,8 @@ std::shared_ptr<DepotLocker> Player::getDepotLocker(uint32_t depotId) {
depotLocker->internalAddThing(marketItem);
depotLocker->internalAddThing(inbox);
if (createSupplyStash) {
const auto &supplyStash = Item::CreateItem(ITEM_SUPPLY_STASH);
depotLocker->internalAddThing(supplyStash);
const auto &supplyStashPtr = Item::CreateItem(ITEM_SUPPLY_STASH);
depotLocker->internalAddThing(supplyStashPtr);
}
const auto &depotChest = Item::CreateItemAsContainer(ITEM_DEPOT, static_cast<uint16_t>(g_configManager().getNumber(DEPOT_BOXES)));
for (uint32_t i = g_configManager().getNumber(DEPOT_BOXES); i > 0; i--) {
Expand Down
1 change: 1 addition & 0 deletions src/creatures/players/vip/player_vip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "creatures/players/vip/player_vip.hpp"

#include "account/account.hpp"
#include "creatures/players/grouping/groups.hpp"
#include "creatures/players/player.hpp"
#include "io/iologindata.hpp"
Expand Down
4 changes: 1 addition & 3 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2907,9 +2907,7 @@ ReturnValue Game::internalTeleport(const std::shared_ptr<Thing> &thing, const Po
return ret;
}

g_dispatcher().addWalkEvent([=] {
g_game().map.moveCreature(creature, toTile, !pushMove);
});
map.moveCreature(creature, toTile, !pushMove);

return RETURNVALUE_NOERROR;
} else if (const auto &item = thing->getItem()) {
Expand Down
8 changes: 4 additions & 4 deletions src/game/movement/teleport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ void Teleport::addThing(int32_t, const std::shared_ptr<Thing> &thing) {
g_game().internalCreatureTurn(creature, origPos.x > destPos.x ? DIRECTION_WEST : DIRECTION_EAST);
g_dispatcher().addWalkEvent([=] {
g_game().map.moveCreature(creature, destTile);
if (effect != CONST_ME_NONE) {
g_game().addMagicEffect(origPos, effect);
g_game().addMagicEffect(destTile->getPosition(), effect);
}
});
if (effect != CONST_ME_NONE) {
g_game().addMagicEffect(origPos, effect);
g_game().addMagicEffect(destTile->getPosition(), effect);
}
} else if (const auto &item = thing->getItem()) {
if (effect != CONST_ME_NONE) {
g_game().addMagicEffect(destTile->getPosition(), effect);
Expand Down
1 change: 1 addition & 0 deletions src/game/scheduling/save_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "io/iologindata.hpp"
#include "kv/kv.hpp"
#include "lib/di/container.hpp"
#include "creatures/players/player.hpp"

SaveManager::SaveManager(ThreadPool &threadPool, KVStore &kvStore, Logger &logger, Game &game) :
threadPool(threadPool), kv(kvStore), logger(logger), game(game) { }
Expand Down
3 changes: 3 additions & 0 deletions src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

#include "io/functions/iologindata_load_player.hpp"

#include "account/account.hpp"
#include "config/configmanager.hpp"
#include "creatures/combat/condition.hpp"
#include "database/database.hpp"
#include "creatures/monsters/monsters.hpp"
#include "creatures/players/achievement/player_achievement.hpp"
#include "creatures/players/cyclopedia/player_badge.hpp"
Expand All @@ -29,6 +31,7 @@
#include "items/containers/inbox/inbox.hpp"
#include "items/containers/rewards/reward.hpp"
#include "items/containers/rewards/rewardchest.hpp"
#include "creatures/players/player.hpp"
#include "utils/tools.hpp"

void IOLoginDataLoad::loadItems(ItemsMap &itemsMap, const DBResult_ptr &result, const std::shared_ptr<Player> &player) {
Expand Down
4 changes: 4 additions & 0 deletions src/io/functions/iologindata_load_player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

#include "io/iologindata.hpp"

class Player;
class DBResult;
using DBResult_ptr = std::shared_ptr<DBResult>;

class IOLoginDataLoad : public IOLoginData {
public:
static bool loadPlayerBasicInfo(const std::shared_ptr<Player> &player, const DBResult_ptr &result);
Expand Down
1 change: 1 addition & 0 deletions src/io/functions/iologindata_save_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "items/containers/depot/depotchest.hpp"
#include "items/containers/inbox/inbox.hpp"
#include "items/containers/rewards/reward.hpp"
#include "creatures/players/player.hpp"

bool IOLoginDataSave::saveItems(const std::shared_ptr<Player> &player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &propWriteStream) {
if (!player) {
Expand Down
1 change: 1 addition & 0 deletions src/io/functions/iologindata_save_player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "io/iologindata.hpp"

class PropWriteStream;
class DBInsert;

class IOLoginDataSave : public IOLoginData {
public:
Expand Down
3 changes: 3 additions & 0 deletions src/io/iologindata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

#include "io/iologindata.hpp"

#include "account/account.hpp"
#include "config/configmanager.hpp"
#include "database/database.hpp"
#include "io/functions/iologindata_load_player.hpp"
#include "io/functions/iologindata_save_player.hpp"
#include "game/game.hpp"
#include "creatures/monsters/monster.hpp"
#include "creatures/players/wheel/player_wheel.hpp"
#include "creatures/players/player.hpp"
#include "lib/metrics/metrics.hpp"
#include "enums/account_type.hpp"
#include "enums/account_errors.hpp"
Expand Down
11 changes: 7 additions & 4 deletions src/io/iologindata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

#pragma once

#include "account/account.hpp"
#include "creatures/players/player.hpp"
#include "database/database.hpp"
class Player;
class Item;
class DBResult;

struct VIPEntry;
struct VIPGroupEntry;

using ItemBlockList = std::list<std::pair<int32_t, std::shared_ptr<Item>>>;

Expand All @@ -21,7 +24,7 @@ class IOLoginData {
static uint8_t getAccountType(uint32_t accountId);
static bool loadPlayerById(const std::shared_ptr<Player> &player, uint32_t id, bool disableIrrelevantInfo = true);
static bool loadPlayerByName(const std::shared_ptr<Player> &player, const std::string &name, bool disableIrrelevantInfo = true);
static bool loadPlayer(const std::shared_ptr<Player> &player, const DBResult_ptr &result, bool disableIrrelevantInfo = false);
static bool loadPlayer(const std::shared_ptr<Player> &player, const std::shared_ptr<DBResult> &result, bool disableIrrelevantInfo = false);
static bool savePlayer(const std::shared_ptr<Player> &player);
static uint32_t getGuidByName(const std::string &name);
static bool getGuidByNameEx(uint32_t &guid, bool &specialVip, std::string &name);
Expand Down
1 change: 1 addition & 0 deletions src/io/iomarket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "game/scheduling/save_manager.hpp"
#include "io/iologindata.hpp"
#include "items/containers/inbox/inbox.hpp"
#include "creatures/players/player.hpp"

uint8_t IOMarket::getTierFromDatabaseTable(const std::string &string) {
auto tier = static_cast<uint8_t>(std::atoi(string.c_str()));
Expand Down
1 change: 1 addition & 0 deletions src/items/bed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "game/scheduling/save_manager.hpp"
#include "io/iologindata.hpp"
#include "server/network/protocol/protocolgame.hpp"
#include "creatures/players/player.hpp"

BedItem::BedItem(uint16_t id) :
Item(id) {
Expand Down
53 changes: 27 additions & 26 deletions src/items/items_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,34 +140,35 @@ enum ItemGroup_t {
enum ItemTypes_t {
ITEM_TYPE_NONE,

// Odered to make the cast from protobuf::itemCategory to ItemTypes_t easier.
// Ordered to make the cast from protobuf::itemCategory to ItemTypes_t easier.
// Do not edit it from Start-End
// Start
ITEM_TYPE_ARMOR,
ITEM_TYPE_AMULET,
ITEM_TYPE_BOOTS,
ITEM_TYPE_CONTAINER,
ITEM_TYPE_DECORATION,
ITEM_TYPE_FOOD,
ITEM_TYPE_HELMET,
ITEM_TYPE_LEGS,
ITEM_TYPE_OTHER,
ITEM_TYPE_POTION,
ITEM_TYPE_RING,
ITEM_TYPE_RUNE,
ITEM_TYPE_SHIELD,
ITEM_TYPE_TOOLS,
ITEM_TYPE_VALUABLE,
ITEM_TYPE_AMMO,
ITEM_TYPE_AXE,
ITEM_TYPE_CLUB,
ITEM_TYPE_DISTANCE,
ITEM_TYPE_SWORD,
ITEM_TYPE_WAND,
ITEM_TYPE_PREMIUMSCROLL,
ITEM_TYPE_TIBIACOIN,
ITEM_TYPE_CREATUREPRODUCT,
ITEM_TYPE_QUIVER,
ITEM_TYPE_ARMOR = 1,
ITEM_TYPE_AMULET = 2,
ITEM_TYPE_BOOTS = 3,
ITEM_TYPE_CONTAINER = 4,
ITEM_TYPE_DECORATION = 5,
ITEM_TYPE_FOOD = 6,
ITEM_TYPE_HELMET = 7,
ITEM_TYPE_LEGS = 8,
ITEM_TYPE_OTHER = 9,
ITEM_TYPE_POTION = 10,
ITEM_TYPE_RING = 11,
ITEM_TYPE_RUNE = 12,
ITEM_TYPE_SHIELD = 13,
ITEM_TYPE_TOOLS = 14,
ITEM_TYPE_VALUABLE = 15,
ITEM_TYPE_AMMO = 16,
ITEM_TYPE_AXE = 17,
ITEM_TYPE_CLUB = 18,
ITEM_TYPE_DISTANCE = 19,
ITEM_TYPE_SWORD = 20,
ITEM_TYPE_WAND = 21,
ITEM_TYPE_PREMIUMSCROLL = 22,
ITEM_TYPE_TIBIACOIN = 23,
ITEM_TYPE_CREATUREPRODUCT = 24,
ITEM_TYPE_QUIVER = 25,
ITEM_TYPE_SOULCORES = 26,
// End

ITEM_TYPE_DEPOT,
Expand Down
2 changes: 1 addition & 1 deletion src/items/weapons/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "creatures/combat/combat.hpp"
#include "game/game.hpp"
#include "lua/creature/events.hpp"

#include "lua/global/lua_variant.hpp"
#include "creatures/players/player.hpp"

Weapons::Weapons() = default;
Weapons::~Weapons() = default;
Expand Down
1 change: 0 additions & 1 deletion src/items/weapons/weapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#pragma once

#include "lua/scripts/luascript.hpp"
#include "creatures/players/player.hpp"
#include "lua/scripts/scripts.hpp"
#include "creatures/combat/combat.hpp"
#include "utils/utils_definitions.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/lua/functions/core/game/game_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "lua/functions/events/event_callback_functions.hpp"
#include "lua/scripts/lua_environment.hpp"
#include "map/spectators.hpp"
#include "creatures/players/player.hpp"

// Game
int GameFunctions::luaGameCreateMonsterType(lua_State* L) {
Expand Down
1 change: 1 addition & 0 deletions src/lua/functions/core/game/global_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "lua/scripts/lua_environment.hpp"
#include "lua/scripts/script_environment.hpp"
#include "server/network/protocol/protocolstatus.hpp"
#include "creatures/players/player.hpp"

void GlobalFunctions::init(lua_State* L) {
lua_register(L, "addEvent", GlobalFunctions::luaAddEvent);
Expand Down
1 change: 1 addition & 0 deletions src/lua/functions/creatures/combat/combat_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "game/game.hpp"
#include "lua/global/lua_variant.hpp"
#include "lua/scripts/lua_environment.hpp"
#include "creatures/players/player.hpp"

int CombatFunctions::luaCombatCreate(lua_State* L) {
// Combat()
Expand Down
1 change: 1 addition & 0 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "lua/functions/creatures/player/player_functions.hpp"

#include "account/account.hpp"
#include "creatures/appearance/mounts/mounts.hpp"
#include "creatures/combat/spells.hpp"
#include "creatures/creature.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/lua/functions/map/house_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "game/movement/position.hpp"
#include "io/iologindata.hpp"
#include "map/house/house.hpp"
#include "creatures/players/player.hpp"

int HouseFunctions::luaHouseCreate(lua_State* L) {
// House(id)
Expand Down
1 change: 1 addition & 0 deletions src/map/house/house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "items/containers/inbox/inbox.hpp"
#include "lib/metrics/metrics.hpp"
#include "utils/pugicast.hpp"
#include "creatures/players/player.hpp"

House::House(uint32_t houseId) :
id(houseId) { }
Expand Down
7 changes: 7 additions & 0 deletions src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,13 @@ void Map::moveCreature(const std::shared_ptr<Creature> &creature, const std::sha
} else {
events();
}

if (forceTeleport) {
if (const auto &player = creature->getPlayer()) {
player->sendMagicEffect(oldPos, CONST_ME_TELEPORT);
player->sendMagicEffect(newPos, CONST_ME_TELEPORT);
}
}
}

bool Map::canThrowObjectTo(const Position &fromPos, const Position &toPos, const SightLines_t lineOfSight /*= SightLine_CheckSightLine*/, const int32_t rangex /*= Map::maxClientViewportX*/, const int32_t rangey /*= Map::maxClientViewportY*/) {
Expand Down
1 change: 1 addition & 0 deletions src/protobuf/appearances.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum ITEM_CATEGORY {
ITEM_CATEGORY_TIBIA_COINS = 23;
ITEM_CATEGORY_CREATURE_PRODUCTS = 24;
ITEM_CATEGORY_QUIVER = 25;
ITEM_CATEGORY_SOULCORES = 26;
}

enum PLAYER_PROFESSION {
Expand Down
1 change: 1 addition & 0 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "server/network/protocol/protocolgame.hpp"

#include "account/account.hpp"
#include "config/configmanager.hpp"
#include "core.hpp"
#include "creatures/appearance/mounts/mounts.hpp"
Expand Down

0 comments on commit fdfd384

Please sign in to comment.