Skip to content

Commit

Permalink
Merge branch 'main' into merge-branches
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored Mar 27, 2024
2 parents 0351c06 + 8dec6f9 commit 5c8e530
Show file tree
Hide file tree
Showing 22 changed files with 468 additions and 312 deletions.
6 changes: 5 additions & 1 deletion src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,11 @@ bool ConditionFeared::executeCondition(std::shared_ptr<Creature> creature, int32
}

if (getFleePath(creature, currentPos, listDir)) {
g_dispatcher().addEvent(std::bind(&Game::forcePlayerAutoWalk, &g_game(), creature->getID(), listDir.data()), "ConditionFeared::executeCondition");
g_dispatcher().addEvent([id = creature->getID(), listDir = listDir.data()] {
g_game().forcePlayerAutoWalk(id, listDir);
},
"ConditionFeared::executeCondition");

g_logger().debug("[ConditionFeared::executeCondition] Walking Scheduled");
}
}
Expand Down
34 changes: 21 additions & 13 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ void Creature::addEventWalk(bool firstStep) {
}

self->eventWalk = g_dispatcher().scheduleEvent(
static_cast<uint32_t>(ticks), std::bind(&Game::checkCreatureWalk, &g_game(), self->getID()),
"Creature::checkCreatureWalk"
static_cast<uint32_t>(ticks),
[creatureId = self->getID()] { g_game().checkCreatureWalk(creatureId); }, "Creature::checkCreatureWalk"
);
});
}
Expand Down Expand Up @@ -600,7 +600,7 @@ void Creature::onCreatureMove(const std::shared_ptr<Creature> &creature, const s
if (followCreature && (creature == getCreature() || creature == followCreature)) {
if (hasFollowPath) {
isUpdatingPath = true;
g_dispatcher().addEvent(std::bind(&Game::updateCreatureWalk, &g_game(), getID()), "Game::updateCreatureWalk");
g_dispatcher().addEvent([creatureId = getID()] { g_game().updateCreatureWalk(creatureId); }, "Game::updateCreatureWalk");
}

if (newPos.z != oldPos.z || !canSee(followCreature->getPosition())) {
Expand All @@ -615,7 +615,7 @@ void Creature::onCreatureMove(const std::shared_ptr<Creature> &creature, const s
} else {
if (hasExtraSwing()) {
// our target is moving lets see if we can get in hit
g_dispatcher().addEvent(std::bind(&Game::checkCreatureAttack, &g_game(), getID()), "Game::checkCreatureAttack");
g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, "Game::checkCreatureAttack");
}

if (newTile->getZoneType() != oldTile->getZoneType()) {
Expand Down Expand Up @@ -813,11 +813,21 @@ bool Creature::dropCorpse(std::shared_ptr<Creature> lastHitCreature, std::shared
player->sendLootMessage(lootMessage.str());
}

if (player->checkAutoLoot(monster->isRewardBoss()) && corpseContainer && mostDamageCreature->getPlayer()) {
g_dispatcher().addEvent(
std::bind(&Game::playerQuickLootCorpse, &g_game(), player, corpseContainer, corpse->getPosition()),
"Game::playerQuickLootCorpse"
);
stdext::arraylist<Direction> dirList(128);
FindPathParams fpp;
fpp.minTargetDist = 0;
fpp.maxTargetDist = 1;
fpp.fullPathSearch = true;
fpp.clearSight = true;
fpp.maxSearchDist = 0;

auto isReachable = g_game().map.getPathMatching(player->getPosition(), dirList, FrozenPathingConditionCall(corpse->getPosition()), fpp);

if (player->checkAutoLoot(monster->isRewardBoss()) && corpseContainer && mostDamageCreature->getPlayer() && isReachable) {
g_dispatcher().addEvent([player, corpseContainer, corpsePosition = corpse->getPosition()] {
g_game().playerQuickLootCorpse(player, corpseContainer, corpsePosition);
},
"Game::playerQuickLootCorpse");
}
}
}
Expand Down Expand Up @@ -861,7 +871,7 @@ void Creature::changeHealth(int32_t healthChange, bool sendHealthChange /* = tru
g_game().addCreatureHealth(static_self_cast<Creature>());
}
if (health <= 0) {
g_dispatcher().addEvent(std::bind(&Game::executeDeath, &g_game(), getID()), "Game::executeDeath");
g_dispatcher().addEvent([creatureId = getID()] { g_game().executeDeath(creatureId); }, "Game::executeDeath");
}
}

Expand Down Expand Up @@ -1401,9 +1411,7 @@ void Creature::removeCondition(ConditionType_t conditionType, ConditionId_t cond
int32_t walkDelay = getWalkDelay();
if (walkDelay > 0) {
g_dispatcher().scheduleEvent(
walkDelay,
std::bind(&Game::forceRemoveCondition, &g_game(), getID(), conditionType, conditionId),
"Game::forceRemoveCondition"
walkDelay, [creatureId = getID(), conditionType, conditionId] { g_game().forceRemoveCondition(creatureId, conditionType, conditionId); }, "Game::forceRemoveCondition"
);
return;
}
Expand Down
4 changes: 3 additions & 1 deletion src/creatures/interactions/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ bool ChatChannel::addUser(const std::shared_ptr<Player> &player) {
if (id == CHANNEL_GUILD) {
const auto guild = player->getGuild();
if (guild && !guild->getMotd().empty()) {
g_dispatcher().scheduleEvent(150, std::bind(&Game::sendGuildMotd, &g_game(), player->getID()), "Game::sendGuildMotd");
g_dispatcher().scheduleEvent(
150, [playerId = player->getID()] { g_game().sendGuildMotd(playerId); }, "Game::sendGuildMotd"
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ bool Monster::selectTarget(const std::shared_ptr<Creature> &creature) {

if (isHostile() || isSummon()) {
if (setAttackedCreature(creature)) {
g_dispatcher().addEvent(std::bind(&Game::checkCreatureAttack, &g_game(), getID()), "Game::checkCreatureAttack");
g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, "Game::checkCreatureAttack");
}
}
return setFollowCreature(creature);
Expand Down
17 changes: 12 additions & 5 deletions src/creatures/monsters/spawns/spawn_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ bool SpawnsMonster::isInZone(const Position &centerPos, int32_t radius, const Po

void SpawnMonster::startSpawnMonsterCheck() {
if (checkSpawnMonsterEvent == 0) {
checkSpawnMonsterEvent = g_dispatcher().scheduleEvent(getInterval(), std::bind(&SpawnMonster::checkSpawnMonster, this), "SpawnMonster::checkSpawnMonster");
checkSpawnMonsterEvent = g_dispatcher().scheduleEvent(
getInterval(), [this] { checkSpawnMonster(); }, "SpawnMonster::checkSpawnMonster"
);
}
}

Expand Down Expand Up @@ -178,6 +180,7 @@ bool SpawnMonster::spawnMonster(uint32_t spawnMonsterId, spawnBlock_t &sb, const
return false;
}
} else {
g_logger().debug("[SpawnMonster] Spawning {} at {}", monsterType->name, sb.pos.toString());
if (!g_game().placeCreature(monster, sb.pos, false, true)) {
return false;
}
Expand Down Expand Up @@ -225,7 +228,7 @@ void SpawnMonster::startup(bool delayed) {
continue;
}
if (delayed) {
g_dispatcher().addEvent(std::bind(&SpawnMonster::scheduleSpawn, this, spawnMonsterId, sb, mType, 0, true), "SpawnMonster::startup");
g_dispatcher().addEvent([this, spawnMonsterId, &sb, mType] { scheduleSpawn(spawnMonsterId, sb, mType, 0, true); }, "SpawnMonster::startup");
} else {
scheduleSpawn(spawnMonsterId, sb, mType, 0, true);
}
Expand Down Expand Up @@ -258,14 +261,16 @@ void SpawnMonster::checkSpawnMonster() {
}

if (mType->info.isBlockable) {
spawnMonster(spawnMonsterId, sb, mType, true);
spawnMonster(spawnMonsterId, sb, mType);
} else {
scheduleSpawn(spawnMonsterId, sb, mType, 3 * NONBLOCKABLE_SPAWN_MONSTER_INTERVAL);
}
}

if (spawnedMonsterMap.size() < spawnMonsterMap.size()) {
checkSpawnMonsterEvent = g_dispatcher().scheduleEvent(getInterval(), std::bind(&SpawnMonster::checkSpawnMonster, this), "SpawnMonster::checkSpawnMonster");
checkSpawnMonsterEvent = g_dispatcher().scheduleEvent(
getInterval(), [this] { checkSpawnMonster(); }, "SpawnMonster::checkSpawnMonster"
);
}
}

Expand All @@ -274,7 +279,9 @@ void SpawnMonster::scheduleSpawn(uint32_t spawnMonsterId, spawnBlock_t &sb, cons
spawnMonster(spawnMonsterId, sb, mType, startup);
} else {
g_game().addMagicEffect(sb.pos, CONST_ME_TELEPORT);
g_dispatcher().scheduleEvent(NONBLOCKABLE_SPAWN_MONSTER_INTERVAL, std::bind(&SpawnMonster::scheduleSpawn, this, spawnMonsterId, sb, mType, interval - NONBLOCKABLE_SPAWN_MONSTER_INTERVAL, startup), "SpawnMonster::scheduleSpawn");
g_dispatcher().scheduleEvent(
NONBLOCKABLE_SPAWN_MONSTER_INTERVAL, [=, this, &sb] { scheduleSpawn(spawnMonsterId, sb, mType, interval - NONBLOCKABLE_SPAWN_MONSTER_INTERVAL, startup); }, "SpawnMonster::scheduleSpawn"
);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/creatures/npcs/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, u
return;
}
if (hasMore) {
g_dispatcher().scheduleEvent(SCHEDULER_MINTICKS, std::bind(&Npc::onPlayerSellAllLoot, this, player->getID(), itemId, ignore, totalPrice), __FUNCTION__);
g_dispatcher().scheduleEvent(
SCHEDULER_MINTICKS, [this, playerId = player->getID(), itemId, ignore, totalPrice] { onPlayerSellAllLoot(playerId, itemId, ignore, totalPrice); }, __FUNCTION__
);
return;
}
ss << "You sold all of the items from your loot pouch for ";
Expand All @@ -366,7 +368,9 @@ void Npc::onPlayerSellItem(std::shared_ptr<Player> player, uint16_t itemId, uint
return;
}
if (itemId == ITEM_GOLD_POUCH) {
g_dispatcher().scheduleEvent(SCHEDULER_MINTICKS, std::bind(&Npc::onPlayerSellAllLoot, this, player->getID(), itemId, ignore, 0), __FUNCTION__);
g_dispatcher().scheduleEvent(
SCHEDULER_MINTICKS, [this, playerId = player->getID(), itemId, ignore] { onPlayerSellAllLoot(playerId, itemId, ignore, 0); }, __FUNCTION__
);
return;
}

Expand Down
12 changes: 9 additions & 3 deletions src/creatures/npcs/spawns/spawn_npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ bool SpawnsNpc::isInZone(const Position &centerPos, int32_t radius, const Positi

void SpawnNpc::startSpawnNpcCheck() {
if (checkSpawnNpcEvent == 0) {
checkSpawnNpcEvent = g_dispatcher().scheduleEvent(getInterval(), std::bind(&SpawnNpc::checkSpawnNpc, this), "SpawnNpc::checkSpawnNpc");
checkSpawnNpcEvent = g_dispatcher().scheduleEvent(
getInterval(), [this] { checkSpawnNpc(); }, "SpawnNpc::checkSpawnNpc"
);
}
}

Expand Down Expand Up @@ -217,7 +219,9 @@ void SpawnNpc::checkSpawnNpc() {
}

if (spawnedNpcMap.size() < spawnNpcMap.size()) {
checkSpawnNpcEvent = g_dispatcher().scheduleEvent(getInterval(), std::bind(&SpawnNpc::checkSpawnNpc, this), __FUNCTION__);
checkSpawnNpcEvent = g_dispatcher().scheduleEvent(
getInterval(), [this] { checkSpawnNpc(); }, __FUNCTION__
);
}
}

Expand All @@ -226,7 +230,9 @@ void SpawnNpc::scheduleSpawnNpc(uint32_t spawnId, spawnBlockNpc_t &sb, uint16_t
spawnNpc(spawnId, sb.npcType, sb.pos, sb.direction);
} else {
g_game().addMagicEffect(sb.pos, CONST_ME_TELEPORT);
g_dispatcher().scheduleEvent(1400, std::bind(&SpawnNpc::scheduleSpawnNpc, this, spawnId, sb, interval - NONBLOCKABLE_SPAWN_NPC_INTERVAL), __FUNCTION__);
g_dispatcher().scheduleEvent(
1400, [=, this, &sb] { scheduleSpawnNpc(spawnId, sb, interval - NONBLOCKABLE_SPAWN_NPC_INTERVAL); }, __FUNCTION__
);
}
}

Expand Down
22 changes: 13 additions & 9 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ void Player::onCreatureMove(const std::shared_ptr<Creature> &creature, const std
const auto &followCreature = getFollowCreature();
if (hasFollowPath && (creature == followCreature || (creature.get() == this && followCreature))) {
isUpdatingPath = false;
g_dispatcher().addEvent(std::bind(&Game::updateCreatureWalk, &g_game(), getID()), "Game::updateCreatureWalk");
g_dispatcher().addEvent([creatureId = getID()] { g_game().updateCreatureWalk(creatureId); }, "Game::updateCreatureWalk");
}

if (creature != getPlayer()) {
Expand Down Expand Up @@ -4245,7 +4245,7 @@ bool Player::updateSaleShopList(std::shared_ptr<Item> item) {
return true;
}

g_dispatcher().addEvent(std::bind(&Game::updatePlayerSaleItems, &g_game(), getID()), "updatePlayerSaleItems");
g_dispatcher().addEvent([creatureId = getID()] { g_game().updatePlayerSaleItems(creatureId); }, "Game::updatePlayerSaleItems");
scheduledSaleUpdate = true;
return true;
}
Expand Down Expand Up @@ -4316,7 +4316,7 @@ bool Player::setAttackedCreature(std::shared_ptr<Creature> creature) {
}

if (creature) {
g_dispatcher().addEvent(std::bind(&Game::checkCreatureAttack, &g_game(), getID()), "Game::checkCreatureAttack");
g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, "Game::checkCreatureAttack");
}
return true;
}
Expand Down Expand Up @@ -4376,7 +4376,11 @@ void Player::doAttacking(uint32_t) {
result = Weapon::useFist(static_self_cast<Player>(), attackedCreature);
}

std::shared_ptr<Task> task = createPlayerTask(std::max<uint32_t>(SCHEDULER_MINTICKS, delay), std::bind(&Game::checkCreatureAttack, &g_game(), getID()), "Game::checkCreatureAttack");
const auto &task = createPlayerTask(
std::max<uint32_t>(SCHEDULER_MINTICKS, delay),
[playerId = getID()] { g_game().checkCreatureAttack(playerId); }, "Game::checkCreatureAttack"
);

if (!classicSpeed) {
setNextActionTask(task, false);
} else {
Expand Down Expand Up @@ -6448,7 +6452,7 @@ void Player::stowItem(std::shared_ptr<Item> item, uint32_t count, bool allItems)
// Stow locker items
std::shared_ptr<DepotLocker> depotLocker = getDepotLocker(getLastDepotId());
auto [itemVector, itemMap] = requestLockerItems(depotLocker);
for (auto lockerItem : itemVector) {
for (const auto &lockerItem : itemVector) {
if (lockerItem == nullptr) {
break;
}
Expand All @@ -6459,7 +6463,7 @@ void Player::stowItem(std::shared_ptr<Item> item, uint32_t count, bool allItems)
}
} else if (item->getContainer()) {
itemDict = item->getContainer()->getStowableItems();
for (std::shared_ptr<Item> containerItem : item->getContainer()->getItems(true)) {
for (const std::shared_ptr<Item> &containerItem : item->getContainer()->getItems(true)) {
uint32_t depotChest = g_configManager().getNumber(DEPOTCHEST, __FUNCTION__);
bool validDepot = depotChest > 0 && depotChest < 21;
if (g_configManager().getBoolean(STASH_MOVING, __FUNCTION__) && containerItem && !containerItem->isStackable() && validDepot) {
Expand All @@ -6469,10 +6473,10 @@ void Player::stowItem(std::shared_ptr<Item> item, uint32_t count, bool allItems)
}
}
} else {
itemDict.push_back(std::pair<std::shared_ptr<Item>, uint32_t>(item, count));
itemDict.emplace_back(item, count);
}

if (itemDict.size() == 0) {
if (itemDict.empty()) {
sendCancelMessage("There is no stowable items on this container.");
return;
}
Expand Down Expand Up @@ -7776,7 +7780,7 @@ bool Player::canAutoWalk(const Position &toPosition, const std::function<void()>
// Check if can walk to the toPosition and send event to use function
stdext::arraylist<Direction> listDir(128);
if (getPathTo(toPosition, listDir, 0, 1, true, true)) {
g_dispatcher().addEvent(std::bind(&Game::playerAutoWalk, &g_game(), getID(), listDir.data()), __FUNCTION__);
g_dispatcher().addEvent([creatureId = getID(), dirs = listDir.data()] { g_game().playerAutoWalk(creatureId, dirs); }, __FUNCTION__);

std::shared_ptr<Task> task = createPlayerTask(delay, function, __FUNCTION__);
setNextWalkActionTask(task);
Expand Down
Loading

0 comments on commit 5c8e530

Please sign in to comment.