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

improve: could not get creature message #799

Merged
Merged
Changes from all commits
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
93 changes: 56 additions & 37 deletions src/client/protocolgameparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,13 @@ void ProtocolGame::parsePlayerHelpers(const InputMessagePtr& msg) const
const uint32_t id = msg->getU32();
const uint16_t helpers = msg->getU16();

if (g_map.getCreatureById(id))
Game::processPlayerHelpers(helpers);
else
g_logger.traceError(stdext::format("could not get creature with id %d", id));
const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError(stdext::format("ProtocolGame::parsePlayerHelpers: could not get creature with id %d", id));
return;
}

Game::processPlayerHelpers(helpers);
}

void ProtocolGame::parseGMActions(const InputMessagePtr& msg)
Expand Down Expand Up @@ -1531,11 +1534,13 @@ void ProtocolGame::parseCreatureMark(const InputMessagePtr& msg)
const uint32_t id = msg->getU32();
const uint8_t color = msg->getU8();

const CreaturePtr creature = g_map.getCreatureById(id);
if (creature)
creature->addTimedSquare(color);
else
g_logger.traceError("could not get creature");
const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError(stdext::format("ProtocolGame::parseCreatureMark: could not get creature with id %d", id));
return;
}

creature->addTimedSquare(color);
}

void ProtocolGame::parseTrappers(const InputMessagePtr& msg)
Expand All @@ -1547,10 +1552,13 @@ void ProtocolGame::parseTrappers(const InputMessagePtr& msg)

for (auto i = 0; i < numTrappers; ++i) {
const uint32_t id = msg->getU32();
if (const auto& creature = g_map.getCreatureById(id)) {
//TODO: set creature as trapper
} else
g_logger.traceError("could not get creature");
const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError(stdext::format("ProtocolGame::parseTrappers: could not get creature with id %d", id));
continue;
}

//TODO: set creature as trapper
}
}

Expand All @@ -1560,7 +1568,12 @@ void ProtocolGame::parseCreatureHealth(const InputMessagePtr& msg)
const uint8_t healthPercent = msg->getU8();

const auto& creature = g_map.getCreatureById(id);
if (creature) creature->setHealthPercent(healthPercent);
if (!creature) {
g_logger.traceError(stdext::format("ProtocolGame::parseCreatureHealth: could not get creature with id %d", id));
return;
}

creature->setHealthPercent(healthPercent);
}

void ProtocolGame::parseCreatureLight(const InputMessagePtr& msg)
Expand All @@ -1573,7 +1586,7 @@ void ProtocolGame::parseCreatureLight(const InputMessagePtr& msg)

const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError("could not get creature");
g_logger.traceError(stdext::format("ProtocolGame::parseCreatureLight: could not get creature with id %d", id));
return;
}

Expand All @@ -1587,7 +1600,7 @@ void ProtocolGame::parseCreatureOutfit(const InputMessagePtr& msg) const

const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError("could not get creature");
g_logger.traceError(stdext::format("ProtocolGame::parseCreatureOutfit: could not get creature with id %d", id));
return;
}

Expand All @@ -1605,7 +1618,10 @@ void ProtocolGame::parseCreatureSpeed(const InputMessagePtr& msg)
const uint16_t speed = msg->getU16();

const auto& creature = g_map.getCreatureById(id);
if (!creature) return;
if (!creature) {
g_logger.traceError(stdext::format("ProtocolGame::parseCreatureSpeed: could not get creature with id %d", id));
return;
}

creature->setSpeed(speed);
if (baseSpeed != 0)
Expand All @@ -1619,7 +1635,7 @@ void ProtocolGame::parseCreatureSkulls(const InputMessagePtr& msg)

const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError("could not get creature");
g_logger.traceError(stdext::format("ProtocolGame::parseCreatureSkulls: could not get creature with id %d", id));
return;
}

Expand All @@ -1633,7 +1649,7 @@ void ProtocolGame::parseCreatureShields(const InputMessagePtr& msg)

const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError("could not get creature");
g_logger.traceError(stdext::format("ProtocolGame::parseCreatureShields: could not get creature with id %d", id));
return;
}

Expand All @@ -1647,7 +1663,7 @@ void ProtocolGame::parseCreatureUnpass(const InputMessagePtr& msg)

const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError("could not get creature");
g_logger.traceError(stdext::format("ProtocolGame::parseCreatureUnpass: could not get creature with id %d", id));
return;
}

Expand Down Expand Up @@ -2639,7 +2655,7 @@ void ProtocolGame::parseCreaturesMark(const InputMessagePtr& msg)
} else
creature->addTimedSquare(markType);
} else
g_logger.traceError("could not get creature");
g_logger.traceError(stdext::format("ProtocolGame::parseCreaturesMark: could not get creature with id %d", id));
}
}

Expand All @@ -2649,10 +2665,12 @@ void ProtocolGame::parseCreatureType(const InputMessagePtr& msg)
const uint8_t type = msg->getU8();

const auto& creature = g_map.getCreatureById(id);
if (creature)
creature->setType(type);
else
g_logger.traceError("could not get creature");
if (!creature) {
g_logger.traceError(stdext::format("ProtocolGame::parseCreatureType: could not get creature with id %d", id));
return;
}

creature->setType(type);
}

void ProtocolGame::setMapDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height)
Expand Down Expand Up @@ -2820,7 +2838,7 @@ ThingPtr ProtocolGame::getMappedThing(const InputMessagePtr& msg) const
if (const auto& thing = g_map.getCreatureById(id))
return thing;

g_logger.traceError(stdext::format("no creature with id %u", id));
g_logger.traceError(stdext::format("ProtocolGame::getMappedThing: no creature with id %u", id));
}

return nullptr;
Expand All @@ -2838,7 +2856,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) cons
const uint32_t id = msg->getU32();
creature = g_map.getCreatureById(id);
if (!creature)
g_logger.traceError("server said that a creature is known, but it's not");
g_logger.traceError("ProtocolGame::getCreature: server said that a creature is known, but it's not");
} else {
const uint32_t removeId = msg->getU32();
const uint32_t id = msg->getU32();
Expand Down Expand Up @@ -3029,9 +3047,8 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) cons
// this is send creature turn
const uint32_t id = msg->getU32();
creature = g_map.getCreatureById(id);

if (!creature)
g_logger.traceError("invalid creature");
g_logger.traceError("ProtocolGame::getCreature: invalid creature");

const auto direction = static_cast<Otc::Direction>(msg->getU8());
if (creature)
Expand Down Expand Up @@ -4105,7 +4122,7 @@ void ProtocolGame::parseAttachedEffect(const InputMessagePtr& msg) {

const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError(stdext::format("could not get creature with id %d", id));
g_logger.traceError(stdext::format("ProtocolGame::parseAttachedEffect: could not get creature with id %d", id));
return;
}

Expand All @@ -4122,7 +4139,7 @@ void ProtocolGame::parseDetachEffect(const InputMessagePtr& msg) {

const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError(stdext::format("could not get creature with id %d", id));
g_logger.traceError(stdext::format("ProtocolGame::parseDetachEffect: could not get creature with id %d", id));
return;
}

Expand All @@ -4135,7 +4152,7 @@ void ProtocolGame::parseCreatureShader(const InputMessagePtr& msg) {

const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError(stdext::format("could not get creature with id %d", id));
g_logger.traceError(stdext::format("ProtocolGame::parseCreatureShader: could not get creature with id %d", id));
return;
}

Expand All @@ -4155,9 +4172,11 @@ void ProtocolGame::parseCreatureTyping(const InputMessagePtr& msg)
const uint32_t id = msg->getU32();
const bool typing = msg->getU8();

const CreaturePtr creature = g_map.getCreatureById(id);
if (creature)
creature->setTyping(typing);
else
g_logger.traceError("could not get creature");
const auto& creature = g_map.getCreatureById(id);
if (!creature) {
g_logger.traceError(stdext::format("ProtocolGame::parseCreatureTyping: could not get creature with id %d", id));
return;
}

creature->setTyping(typing);
}
Loading