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

Separate runes #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,20 @@ void Player::setNextPotionActionTask(std::shared_ptr<Task> task) {
}
}

void Player::setNextRuneActionTask(std::shared_ptr<Task> task) {
if (actionRuneTaskEvent != 0) {
g_dispatcher().stopEvent(actionRuneTaskEvent);
actionRuneTaskEvent = 0;
}

cancelPush();

if (task) {
actionRuneTaskEvent = g_dispatcher().scheduleEvent(task);
// resetIdleTime();
}
}

uint32_t Player::getNextActionTime() const {
return std::max<int64_t>(SCHEDULER_MINTICKS, nextAction - OTSYS_TIME());
}
Expand All @@ -2158,6 +2172,10 @@ uint32_t Player::getNextPotionActionTime() const {
return std::max<int64_t>(SCHEDULER_MINTICKS, nextPotionAction - OTSYS_TIME());
}

uint32_t Player::getNextRuneActionTime() const {
return std::max<int64_t>(SCHEDULER_MINTICKS, nextRuneAction - OTSYS_TIME());
}

void Player::cancelPush() {
if (actionTaskEventPush != 0) {
g_dispatcher().stopEvent(actionTaskEventPush);
Expand Down
13 changes: 13 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,15 @@ class Player final : public Creature, public Cylinder, public Bankable {
return nextPotionAction <= OTSYS_TIME();
}

void setNextRuneAction(int64_t time) {
if (time > nextRuneAction) {
nextRuneAction = time;
}
}
bool canDoRuneAction() const {
return nextRuneAction <= OTSYS_TIME();
}

void cancelPush();

void setModuleDelay(uint8_t byteortype, int16_t delay) {
Expand All @@ -1744,6 +1753,7 @@ class Player final : public Creature, public Cylinder, public Bankable {

uint32_t getNextActionTime() const;
uint32_t getNextPotionActionTime() const;
uint32_t getNextRuneActionTime() const;

std::shared_ptr<Item> getWriteItem(uint32_t &windowTextId, uint16_t &maxWriteLen);
void setWriteItem(std::shared_ptr<Item> item, uint16_t maxWriteLen = 0);
Expand Down Expand Up @@ -2632,6 +2642,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
void setNextActionTask(std::shared_ptr<Task> task, bool resetIdleTime = true);
void setNextActionPushTask(std::shared_ptr<Task> task);
void setNextPotionActionTask(std::shared_ptr<Task> task);
void setNextRuneActionTask(std::shared_ptr<Task> task);

void death(std::shared_ptr<Creature> lastHitCreature) override;
bool spawn();
Expand Down Expand Up @@ -2751,6 +2762,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
int64_t lastPong;
int64_t nextAction = 0;
int64_t nextPotionAction = 0;
int64_t nextRuneAction = 0;
int64_t lastQuickLootNotification = 0;
int64_t lastWalking = 0;
uint64_t asyncOngoingTasks = 0;
Expand Down Expand Up @@ -2789,6 +2801,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
uint32_t actionTaskEvent = 0;
uint32_t actionTaskEventPush = 0;
uint32_t actionPotionTaskEvent = 0;
uint32_t actionRuneTaskEvent = 0;
uint32_t nextStepEvent = 0;
uint32_t walkTaskEvent = 0;
uint32_t MessageBufferTicks = 0;
Expand Down
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
8 changes: 6 additions & 2 deletions src/lua/creature/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,10 @@ bool Actions::useItem(std::shared_ptr<Player> player, const Position &pos, uint8
return false;
}

if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
player->setNextPotionAction(OTSYS_TIME() + g_configManager().getNumber(ACTIONS_DELAY_INTERVAL, __FUNCTION__));
} else if (it.isRune()) {
player->setNextRuneAction(OTSYS_TIME() + g_configManager().getNumber(ACTIONS_DELAY_INTERVAL, __FUNCTION__));
} else {
player->setNextAction(OTSYS_TIME() + g_configManager().getNumber(ACTIONS_DELAY_INTERVAL, __FUNCTION__));
}
Expand Down Expand Up @@ -460,8 +462,10 @@ bool Actions::useItemEx(std::shared_ptr<Player> player, const Position &fromPos,
return false;
}

if (it.isRune() || it.type == ITEM_TYPE_POTION) {
if (it.type == ITEM_TYPE_POTION) {
player->setNextPotionAction(OTSYS_TIME() + g_configManager().getNumber(EX_ACTIONS_DELAY_INTERVAL, __FUNCTION__));
} else if (it.isRune()) {
player->setNextRuneAction(OTSYS_TIME() + g_configManager().getNumber(EX_ACTIONS_DELAY_INTERVAL, __FUNCTION__));
} else {
player->setNextAction(OTSYS_TIME() + g_configManager().getNumber(EX_ACTIONS_DELAY_INTERVAL, __FUNCTION__));
}
Expand Down
Loading