Skip to content

Commit

Permalink
fix: speed and conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
phacUFPE committed Nov 5, 2024
1 parent b82568a commit bbdc0f6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 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
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
11 changes: 11 additions & 0 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,17 @@ LightInfo Creature::getCreatureLight() const {
return internalLight;
}

uint16_t Creature::getSpeed() const {
const auto speed = baseSpeed + varSpeed;
if (speed >= 0 && speed <= std::numeric_limits<uint16_t>::max()) {
return speed;
} else if (speed < 0) {
return 0;
} else {
return 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

0 comments on commit bbdc0f6

Please sign in to comment.