Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: speed and conditions #3063

Merged
merged 3 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
phacUFPE marked this conversation as resolved.
Show resolved Hide resolved

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
Loading