Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
luanluciano93 committed Oct 3, 2023
2 parents c4259cf + 992816b commit dc42b0e
Show file tree
Hide file tree
Showing 56 changed files with 1,274 additions and 966 deletions.
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [ "Windows" ]
"hostOS": ["Windows"]
}
},
"condition": {
Expand Down
18 changes: 8 additions & 10 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "creatures/monsters/monster.hpp"
#include "creatures/monsters/monsters.hpp"
#include "items/weapons/weapons.hpp"
#include "map/spectators.hpp"

int32_t Combat::getLevelFormula(std::shared_ptr<Player> player, const std::shared_ptr<Spell> wheelSpell, const CombatDamage &damage) const {
if (!player) {
Expand Down Expand Up @@ -754,7 +755,7 @@ void Combat::CombatNullFunc(std::shared_ptr<Creature> caster, std::shared_ptr<Cr
CombatDispelFunc(caster, target, params, nullptr);
}

void Combat::combatTileEffects(const SpectatorHashSet &spectators, std::shared_ptr<Creature> caster, std::shared_ptr<Tile> tile, const CombatParams &params) {
void Combat::combatTileEffects(const CreatureVector &spectators, std::shared_ptr<Creature> caster, std::shared_ptr<Tile> tile, const CombatParams &params) {
if (params.itemId != 0) {
uint16_t itemId = params.itemId;
switch (itemId) {
Expand Down Expand Up @@ -998,7 +999,6 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
getCombatArea(pos, pos, area, tileList);
}

SpectatorHashSet spectators;
uint32_t maxX = 0;
uint32_t maxY = 0;

Expand All @@ -1019,7 +1019,6 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin

const int32_t rangeX = maxX + MAP_MAX_VIEW_PORT_X;
const int32_t rangeY = maxY + MAP_MAX_VIEW_PORT_Y;
g_game().map.getSpectators(spectators, pos, true, true, rangeX, rangeX, rangeY, rangeY);

int affected = 0;
for (std::shared_ptr<Tile> tile : tileList) {
Expand Down Expand Up @@ -1071,6 +1070,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
}

// Wheel of destiny get beam affected total
auto spectators = Spectators().find<Player>(pos, true, rangeX, rangeX, rangeY, rangeY);
std::shared_ptr<Player> casterPlayer = caster ? caster->getPlayer() : nullptr;
uint8_t beamAffectedTotal = casterPlayer ? casterPlayer->wheel()->getBeamAffectedTotal(tmpDamage) : 0;
uint8_t beamAffectedCurrent = 0;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
}
}
}
combatTileEffects(spectators, caster, tile, params);
combatTileEffects(spectators.data(), caster, tile, params);
}

// Wheel of destiny update beam mastery damage
Expand Down Expand Up @@ -1339,11 +1339,10 @@ void Combat::doCombatDefault(std::shared_ptr<Creature> caster, std::shared_ptr<C

void Combat::doCombatDefault(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const Position &origin, const CombatParams &params) {
if (!params.aggressive || (caster != target && Combat::canDoCombat(caster, target, params.aggressive) == RETURNVALUE_NOERROR)) {
SpectatorHashSet spectators;
g_game().map.getSpectators(spectators, target->getPosition(), true, true);
auto spectators = Spectators().find<Player>(target->getPosition(), true);

CombatNullFunc(caster, target, params, nullptr);
combatTileEffects(spectators, caster, target->getTile(), params);
combatTileEffects(spectators.data(), caster, target->getTile(), params);

if (params.targetCallback) {
params.targetCallback->onTargetCombat(caster, target);
Expand Down Expand Up @@ -1396,13 +1395,12 @@ std::vector<std::pair<Position, std::vector<uint32_t>>> Combat::pickChainTargets
const int maxBacktrackingAttempts = 10; // Can be adjusted as needed
while (!targets.empty() && targets.size() <= maxTargets) {
auto currentTarget = targets.back();
SpectatorHashSet spectators;
g_game().map.getSpectators(spectators, currentTarget->getPosition(), false, false, chainDistance, chainDistance, chainDistance, chainDistance);
auto spectators = Spectators().find<Creature>(currentTarget->getPosition(), false, chainDistance, chainDistance, chainDistance, chainDistance);
g_logger().debug("Combat::pickChainTargets: currentTarget: {}, spectators: {}", currentTarget->getName(), spectators.size());

double closestDistance = std::numeric_limits<double>::max();
std::shared_ptr<Creature> closestSpectator = nullptr;
for (std::shared_ptr<Creature> spectator : spectators) {
for (const auto &spectator : spectators) {
if (!spectator || visited.contains(spectator->getID())) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/combat/combat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class Combat {
static void CombatDispelFunc(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const CombatParams &params, CombatDamage* data);
static void CombatNullFunc(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const CombatParams &params, CombatDamage* data);

static void combatTileEffects(const SpectatorHashSet &spectators, std::shared_ptr<Creature> caster, std::shared_ptr<Tile> tile, const CombatParams &params);
static void combatTileEffects(const CreatureVector &spectators, std::shared_ptr<Creature> caster, std::shared_ptr<Tile> tile, const CombatParams &params);

/**
* @brief Calculate the level formula for combat.
Expand Down
6 changes: 3 additions & 3 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "game/game.hpp"
#include "game/scheduling/dispatcher.hpp"
#include "io/fileloader.hpp"
#include "map/spectators.hpp"

/**
* Condition
Expand Down Expand Up @@ -1190,13 +1191,12 @@ bool ConditionRegeneration::executeCondition(std::shared_ptr<Creature> creature,
message.primary.color = TEXTCOLOR_PASTELRED;
player->sendTextMessage(message);

SpectatorHashSet spectators;
g_game().map.getSpectators(spectators, player->getPosition(), false, true);
auto spectators = Spectators().find<Player>(player->getPosition());
spectators.erase(player);
if (!spectators.empty()) {
message.type = MESSAGE_HEALED_OTHERS;
message.text = player->getName() + " was healed for " + healString;
for (std::shared_ptr<Creature> spectator : spectators) {
for (const auto &spectator : spectators) {
spectator->getPlayer()->sendTextMessage(message);
}
}
Expand Down
19 changes: 5 additions & 14 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "creatures/monsters/monster.hpp"
#include "game/scheduling/scheduler.hpp"
#include "game/zones/zone.hpp"
#include "map/spectators.hpp"

double Creature::speedA = 857.36;
double Creature::speedB = 261.29;
Expand Down Expand Up @@ -1201,8 +1202,7 @@ void Creature::onGainExperience(uint64_t gainExp, std::shared_ptr<Creature> targ
master->onGainExperience(gainExp, target);

if (!m->isFamiliar()) {
SpectatorHashSet spectators;
g_game().map.getSpectators(spectators, position, false, true);
auto spectators = Spectators().find<Player>(position);
if (spectators.empty()) {
return;
}
Expand All @@ -1212,7 +1212,7 @@ void Creature::onGainExperience(uint64_t gainExp, std::shared_ptr<Creature> targ
message.primary.color = TEXTCOLOR_WHITE_EXP;
message.primary.value = gainExp;

for (std::shared_ptr<Creature> spectator : spectators) {
for (const auto &spectator : spectators) {
spectator->getPlayer()->sendTextMessage(message);
}
}
Expand Down Expand Up @@ -1800,16 +1800,7 @@ void Creature::iconChanged() {
return;
}

SpectatorHashSet spectators;
g_game().map.getSpectators(spectators, tile->getPosition(), true);
for (auto spectator : spectators) {
if (!spectator) {
continue;
}

auto player = spectator->getPlayer();
if (player) {
player->sendCreatureIcon(getCreature());
}
for (const auto &spectator : Spectators().find<Player>(tile->getPosition(), true)) {
spectator->getPlayer()->sendCreatureIcon(getCreature());
}
}
Loading

0 comments on commit dc42b0e

Please sign in to comment.