Skip to content

Commit

Permalink
Update game.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
luanluciano93 authored May 1, 2024
1 parent d3c24ba commit 0096b71
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3526,8 +3526,10 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f
std::shared_ptr<Task> task = createPlayerTask(
400, [this, playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId] { playerUseItemEx(playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId); }, "Game::playerUseItemEx"
);
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
player->setNextPotionActionTask(task);
} else if (it.isRune()) {
player->setNextRuneActionTask(task);
} else {
player->setNextWalkActionTask(task);
}
Expand All @@ -3542,29 +3544,37 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f
}

bool canDoAction = player->canDoAction();
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
canDoAction = player->canDoPotionAction();
} else if (it.isRune()) {
canDoAction = player->canDoRuneAction();
}

if (!canDoAction) {
uint32_t delay = player->getNextActionTime();
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
delay = player->getNextPotionActionTime();
} else if (it.isRune()) {
delay = player->getNextRuneActionTime();
}
std::shared_ptr<Task> task = createPlayerTask(
delay, [this, playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId] { playerUseItemEx(playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId); }, "Game::playerUseItemEx"
);
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
player->setNextPotionActionTask(task);
} else if (it.isRune()) {
player->setNextRuneActionTask(task);
} else {
player->setNextActionTask(task);
}
return;
}

player->resetIdleTime();
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
player->setNextPotionActionTask(nullptr);
} else if (it.isRune()) {
player->setNextRuneActionTask(nullptr);
} else {
player->setNextActionTask(nullptr);
}
Expand Down Expand Up @@ -3640,8 +3650,10 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo
std::shared_ptr<Task> task = createPlayerTask(
400, [this, playerId, pos, stackPos, index, itemId] { playerUseItem(playerId, pos, stackPos, index, itemId); }, "Game::playerUseItem"
);
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
player->setNextPotionActionTask(task);
} else if (it.isRune()) {
player->setNextRuneActionTask(task);
} else {
player->setNextWalkActionTask(task);
}
Expand All @@ -3656,20 +3668,26 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo
}

bool canDoAction = player->canDoAction();
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
canDoAction = player->canDoPotionAction();
} else if (it.isRune()) {
canDoAction = player->canDoRuneAction();
}

if (!canDoAction) {
uint32_t delay = player->getNextActionTime();
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
delay = player->getNextPotionActionTime();
} else if (it.isRune()) {
delay = player->getNextRuneActionTime();
}
std::shared_ptr<Task> task = createPlayerTask(
delay, [this, playerId, pos, stackPos, index, itemId] { playerUseItem(playerId, pos, stackPos, index, itemId); }, "Game::playerUseItem"
);
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
player->setNextPotionActionTask(task);
} else if (it.isRune()) {
player->setNextRuneActionTask(task);
} else {
player->setNextActionTask(task);
}
Expand Down Expand Up @@ -3800,8 +3818,10 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin
},
"Game::playerUseWithCreature"
);
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
player->setNextPotionActionTask(task);
} else if (it.isRune()) {
player->setNextRuneActionTask(task);
} else {
player->setNextWalkActionTask(task);
}
Expand All @@ -3816,30 +3836,38 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin
}

bool canDoAction = player->canDoAction();
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
canDoAction = player->canDoPotionAction();
} else if (it.isRune()) {
canDoAction = player->canDoRuneAction();
}

if (!canDoAction) {
uint32_t delay = player->getNextActionTime();
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
delay = player->getNextPotionActionTime();
} else if (it.isRune()) {
delay = player->getNextRuneActionTime();
}
std::shared_ptr<Task> task = createPlayerTask(
delay, [this, playerId, fromPos, fromStackPos, creatureId, itemId] { playerUseWithCreature(playerId, fromPos, fromStackPos, creatureId, itemId); }, "Game::playerUseWithCreature"
);

if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
player->setNextPotionActionTask(task);
} else if (it.isRune()) {
player->setNextRuneActionTask(task);
} else {
player->setNextActionTask(task);
}
return;
}

player->resetIdleTime();
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
player->setNextPotionActionTask(nullptr);
} else if (it.isRune()) {
player->setNextRuneActionTask(nullptr);
} else {
player->setNextActionTask(nullptr);
}
Expand Down

0 comments on commit 0096b71

Please sign in to comment.