Skip to content

Commit cf35072

Browse files
authored
Merge pull request #28 from jprzimba/fix-drunk
* Fix drunk
2 parents 222dd9a + 32336a5 commit cf35072

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

src/creatures/creature.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,42 @@ void Creature::onCreatureWalk() {
220220
}
221221

222222
void Creature::onWalk(Direction &dir) {
223-
if (hasCondition(CONDITION_DRUNK)) {
224-
uint32_t r = uniform_random(0, 60);
225-
if (r <= DIRECTION_DIAGONAL_MASK) {
226-
if (r < DIRECTION_DIAGONAL_MASK) {
227-
dir = static_cast<Direction>(r);
223+
int32_t highestDrunkSubId = -1;
224+
if (!isSuppress(CONDITION_DRUNK, false)) {
225+
for (const auto &condition : conditions) {
226+
if (condition->getType() != CONDITION_DRUNK) {
227+
continue;
228+
}
229+
230+
int32_t subId = condition->getSubId();
231+
if ((!condition->getEndTime() || condition->getEndTime() >= OTSYS_TIME()) && subId > highestDrunkSubId) {
232+
highestDrunkSubId = subId;
228233
}
229-
g_game().internalCreatureSay(static_self_cast<Creature>(), TALKTYPE_MONSTER_SAY, "Hicks!", false);
230234
}
231235
}
236+
237+
if (highestDrunkSubId < 0) {
238+
return;
239+
}
240+
241+
highestDrunkSubId += 25;
242+
int32_t randomValue = normal_random(1, 100);
243+
if (randomValue > highestDrunkSubId) {
244+
return;
245+
}
246+
247+
int32_t threshold = highestDrunkSubId / 5;
248+
if (randomValue <= threshold) {
249+
dir = DIRECTION_NORTH;
250+
} else if (randomValue <= (threshold * 2)) {
251+
dir = DIRECTION_WEST;
252+
} else if (randomValue <= (threshold * 3)) {
253+
dir = DIRECTION_SOUTH;
254+
} else if (randomValue <= (threshold * 4)) {
255+
dir = DIRECTION_EAST;
256+
}
257+
258+
g_game().internalCreatureSay(static_self_cast<Creature>(), TALKTYPE_MONSTER_SAY, "Hicks!", false);
232259
}
233260

234261
void Creature::resetMovementState() {

0 commit comments

Comments
 (0)