Skip to content

Commit

Permalink
fix: convert 16 to 32 int mana shield (opentibiabr#2603)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlospess0a authored May 7, 2024
1 parent afb1b0d commit 231b3c8
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion data-otservbr-global/migrations/43.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function onUpdateDatabase()
logger.info("Updating database to version 43 (feat frags_limit, payment and duration_days in guild wars)")
logger.info("Updating database to version 44 (feat frags_limit, payment and duration_days in guild wars)")

db.query([[
ALTER TABLE `guild_wars`
Expand Down
10 changes: 9 additions & 1 deletion data-otservbr-global/migrations/44.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
function onUpdateDatabase()
return false -- true = There are others migrations file | false = this is the last migration file
logger.info("Updating database to version 45 (fix: mana shield column size for more than 65k)")

db.query([[
ALTER TABLE `players`
MODIFY COLUMN `manashield` INT UNSIGNED NOT NULL DEFAULT '0',
MODIFY COLUMN `max_manashield` INT UNSIGNED NOT NULL DEFAULT '0';
]])

return true
end
3 changes: 3 additions & 0 deletions data-otservbr-global/migrations/45.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
6 changes: 3 additions & 3 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS `server_config` (
CONSTRAINT `server_config_pk` PRIMARY KEY (`config`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '44'), ('motd_hash', ''), ('motd_num', '0'), ('players_record', '0');
INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '45'), ('motd_hash', ''), ('motd_num', '0'), ('players_record', '0');

-- Table structure `accounts`
CREATE TABLE IF NOT EXISTS `accounts` (
Expand Down Expand Up @@ -127,8 +127,8 @@ CREATE TABLE IF NOT EXISTS `players` (
`skill_lifeleech_amount` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`skill_manaleech_chance` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`skill_manaleech_amount` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`manashield` SMALLINT UNSIGNED NOT NULL DEFAULT '0',
`max_manashield` SMALLINT UNSIGNED NOT NULL DEFAULT '0',
`manashield` INT UNSIGNED NOT NULL DEFAULT '0',
`max_manashield` INT UNSIGNED NOT NULL DEFAULT '0',
`xpboost_stamina` smallint(5) UNSIGNED DEFAULT NULL,
`xpboost_value` tinyint(4) UNSIGNED DEFAULT NULL,
`marriage_status` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ void ConditionManaShield::addCondition(std::shared_ptr<Creature> creature, const

bool ConditionManaShield::unserializeProp(ConditionAttr_t attr, PropStream &propStream) {
if (attr == CONDITIONATTR_MANASHIELD) {
return propStream.read<uint16_t>(manaShield);
return propStream.read<uint32_t>(manaShield);
}
return Condition::unserializeProp(attr, propStream);
}
Expand All @@ -1317,7 +1317,7 @@ void ConditionManaShield::serialize(PropWriteStream &propWriteStream) {
Condition::serialize(propWriteStream);

propWriteStream.write<uint8_t>(CONDITIONATTR_MANASHIELD);
propWriteStream.write<uint16_t>(manaShield);
propWriteStream.write<uint32_t>(manaShield);
}

bool ConditionManaShield::setParam(ConditionParam_t param, int32_t value) {
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/combat/condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class ConditionManaShield final : public Condition {
bool unserializeProp(ConditionAttr_t attr, PropStream &propStream) override;

private:
uint16_t manaShield = 0;
uint32_t manaShield = 0;
};

class ConditionSoul final : public ConditionGeneric {
Expand Down
8 changes: 4 additions & 4 deletions src/creatures/creature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,19 @@ class Creature : virtual public Thing, public SharedObject {
return mana;
}

uint16_t getManaShield() const {
uint32_t getManaShield() const {
return manaShield;
}

void setManaShield(uint16_t value) {
void setManaShield(uint32_t value) {
manaShield = value;
}

uint16_t getMaxManaShield() const {
uint32_t getMaxManaShield() const {
return maxManaShield;
}

void setMaxManaShield(uint16_t value) {
void setMaxManaShield(uint32_t value) {
maxManaShield = value;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7008,7 +7008,7 @@ bool Game::combatChangeHealth(std::shared_ptr<Creature> attacker, std::shared_pt

if (target->hasCondition(CONDITION_MANASHIELD) && damage.primary.type != COMBAT_UNDEFINEDDAMAGE) {
int32_t manaDamage = std::min<int32_t>(target->getMana(), healthChange);
uint16_t manaShield = target->getManaShield();
uint32_t manaShield = target->getManaShield();
if (manaShield > 0) {
if (manaShield > manaDamage) {
target->setManaShield(manaShield - manaDamage);
Expand Down
4 changes: 2 additions & 2 deletions src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr<Player> player, DBResult_p
player->setXpBoostPercent(result->getNumber<uint16_t>("xpboost_value"));
player->setXpBoostTime(result->getNumber<uint16_t>("xpboost_stamina"));

player->setManaShield(result->getNumber<uint16_t>("manashield"));
player->setMaxManaShield(result->getNumber<uint16_t>("max_manashield"));
player->setManaShield(result->getNumber<uint32_t>("manashield"));
player->setMaxManaShield(result->getNumber<uint32_t>("max_manashield"));
return true;
}

Expand Down

0 comments on commit 231b3c8

Please sign in to comment.