Skip to content

Commit

Permalink
fix loops and others from otserv
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyx14 committed Nov 28, 2024
1 parent de321de commit 21f0a50
Show file tree
Hide file tree
Showing 28 changed files with 211 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ monster.loot = {
{ id = 6558, chance = 10000 }, -- flask of demonic blood
{ id = 6558, chance = 10000 }, -- flask of demonic blood
{ id = 6558, chance = 10000 }, -- flask of demonic blood
{ id = 17838, chance = 1800 }, -- unknown item
{ id = 3019, chance = 1000 }, -- demonbone amulet
{ id = 3026, chance = 12000, maxCount = 8 }, -- white pearl
{ id = 3029, chance = 12000, maxCount = 9 }, -- small sapphire
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ monster.loot = {
{ name = "butcher's axe", chance = 1000 },
{ name = "dreaded cleaver", chance = 1000 },
{ name = "mercenary sword", chance = 1000 },
{ id = 28341, chance = 1000 }, -- tessellated wall
{ name = "slightly rusted shield", chance = 5880 },
{ name = "slightly rusted helmet", chance = 35290 },
{ name = "epaulette", chance = 500 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ monster.loot = {
{ name = "dreaded cleaver", chance = 30000 },
{ name = "slightly rusted shield", chance = 26670 },
{ name = "wand of inferno", chance = 30000 },
{ id = 28341, chance = 1000 }, -- tessellated wall
{ name = "sturdy book", chance = 1000 },
}

Expand Down
2 changes: 1 addition & 1 deletion data/libs/functions/boss_lever.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function BossLever:onUse(player)
return true
end

local isAccountNormal = creature:getAccountType() == ACCOUNT_TYPE_NORMAL
local isAccountNormal = creature:getAccountType() < ACCOUNT_TYPE_GAMEMASTER
if isAccountNormal and creature:getLevel() < self.requiredLevel then
local message = "All players need to be level " .. self.requiredLevel .. " or higher."
creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
Expand Down
12 changes: 6 additions & 6 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ void Combat::setupChain(const std::shared_ptr<Weapon> &weapon) {
}

bool Combat::doCombatChain(const std::shared_ptr<Creature> &caster, const std::shared_ptr<Creature> &target, bool aggressive) const {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (!params.chainCallback) {
return false;
}
Expand Down Expand Up @@ -1469,7 +1469,7 @@ void Combat::setRuneSpellName(const std::string &value) {

std::vector<std::pair<Position, std::vector<uint32_t>>> Combat::pickChainTargets(const std::shared_ptr<Creature> &caster, const CombatParams &params, uint8_t chainDistance, uint8_t maxTargets, bool backtracking, bool aggressive, const std::shared_ptr<Creature> &initialTarget /* = nullptr */) {
Benchmark bm_pickChain;
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (!caster) {
return {};
}
Expand Down Expand Up @@ -1512,7 +1512,7 @@ std::vector<std::pair<Position, std::vector<uint32_t>>> Combat::pickChainTargets
}

if (closestSpectator) {
g_logger().trace("[{}] closestSpectator: {}", __METHOD_NAME__, closestSpectator->getName());
g_logger().trace("[{}] closestSpectator: {}", __FUNCTION__, closestSpectator->getName());

bool found = false;
for (auto &[pos, vec] : resultMap) {
Expand All @@ -1531,15 +1531,15 @@ std::vector<std::pair<Position, std::vector<uint32_t>>> Combat::pickChainTargets
continue;
}
if (backtracking) {
g_logger().debug("[{}] backtracking", __METHOD_NAME__);
g_logger().debug("[{}] backtracking", __FUNCTION__);
targets.pop_back();
backtrackingAttempts--;
continue;
}
break;
}

g_logger().debug("[{}] resultMap: {} in {} ms", __METHOD_NAME__, resultMap.size(), bm_pickChain.duration());
g_logger().debug("[{}] resultMap: {} in {} ms", __FUNCTION__, resultMap.size(), bm_pickChain.duration());
return resultMap;
}

Expand Down Expand Up @@ -2221,7 +2221,7 @@ void MagicField::onStepInField(const std::shared_ptr<Creature> &creature) {
}

void Combat::applyExtensions(const std::shared_ptr<Creature> &caster, const std::shared_ptr<Creature> &target, CombatDamage &damage, const CombatParams &params) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (damage.extension || !caster || damage.primary.type == COMBAT_HEALING) {
return;
}
Expand Down
3 changes: 0 additions & 3 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#include "lua/scripts/scripts.hpp"
#include "lib/di/container.hpp"

std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyRegularBoost = { 0 };
std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyUpgradedBoost = { 0 };

Spells::Spells() = default;
Spells::~Spells() = default;

Expand Down
6 changes: 3 additions & 3 deletions src/creatures/combat/spells.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#pragma once

#include "lua/creature/actions.hpp"

enum class WheelSpellBoost_t : uint8_t;
enum class WheelSpellGrade_t : uint8_t;
#include "creatures/players/wheel/wheel_definitions.hpp"

class InstantSpell;
class RuneSpell;
Expand Down Expand Up @@ -256,6 +254,8 @@ class Spell : public BaseSpell {
bool pzLocked = false;

bool whellOfDestinyUpgraded = false;
std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyRegularBoost = { 0 };
std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyUpgradedBoost = { 0 };

private:
uint32_t mana = 0;
Expand Down
50 changes: 25 additions & 25 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Creature::~Creature() {
}

bool Creature::canSee(const Position &myPos, const Position &pos, int32_t viewRangeX, int32_t viewRangeY) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (myPos.z <= MAP_INIT_SURFACE_LAYER) {
// we are on ground level or above (7 -> 0)
// view is from 7 -> 0
Expand Down Expand Up @@ -95,7 +95,7 @@ int32_t Creature::getWalkSize() {
}

void Creature::onThink(uint32_t interval) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);

const auto &followCreature = getFollowCreature();
const auto &master = getMaster();
Expand Down Expand Up @@ -168,7 +168,7 @@ void Creature::onCreatureWalk() {

checkingWalkCreature = true;

metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);

g_dispatcher().addWalkEvent([self = getCreature(), this] {
checkingWalkCreature = false;
Expand Down Expand Up @@ -287,7 +287,7 @@ void Creature::stopEventWalk() {
}

void Creature::onCreatureAppear(const std::shared_ptr<Creature> &creature, bool isLogin) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (creature.get() == this) {
if (isLogin) {
setLastPosition(getPosition());
Expand All @@ -296,7 +296,7 @@ void Creature::onCreatureAppear(const std::shared_ptr<Creature> &creature, bool
}

void Creature::onRemoveCreature(const std::shared_ptr<Creature> &creature, bool) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
onCreatureDisappear(creature, true);

// Update player from monster target list (avoid memory usage after clean)
Expand All @@ -307,7 +307,7 @@ void Creature::onRemoveCreature(const std::shared_ptr<Creature> &creature, bool)
}

void Creature::onCreatureDisappear(const std::shared_ptr<Creature> &creature, bool isLogout) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (getAttackedCreature() == creature) {
setAttackedCreature(nullptr);
onAttackedCreatureDisappear(isLogout);
Expand All @@ -320,15 +320,15 @@ void Creature::onCreatureDisappear(const std::shared_ptr<Creature> &creature, bo
}

void Creature::onChangeZone(ZoneType_t zone) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
const auto &attackedCreature = getAttackedCreature();
if (attackedCreature && zone == ZONE_PROTECTION) {
onCreatureDisappear(attackedCreature, false);
}
}

void Creature::onAttackedCreatureChangeZone(ZoneType_t zone) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (zone == ZONE_PROTECTION) {
const auto &attackedCreature = getAttackedCreature();
if (attackedCreature) {
Expand All @@ -338,7 +338,7 @@ void Creature::onAttackedCreatureChangeZone(ZoneType_t zone) {
}

void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (hasSummons()) {
std::vector<std::shared_ptr<Creature>> despawnMonsterList;
for (const auto &summon : getSummons()) {
Expand Down Expand Up @@ -385,7 +385,7 @@ void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) {
}

void Creature::onCreatureMove(const std::shared_ptr<Creature> &creature, const std::shared_ptr<Tile> &newTile, const Position &newPos, const std::shared_ptr<Tile> &oldTile, const Position &oldPos, bool teleport) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (creature.get() == this) {
lastStep = OTSYS_TIME();
lastStepCost = 1;
Expand Down Expand Up @@ -447,7 +447,7 @@ void Creature::onCreatureMove(const std::shared_ptr<Creature> &creature, const s
}

void Creature::onDeath() {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
bool lastHitUnjustified = false;
bool mostDamageUnjustified = false;
const auto &lastHitCreature = g_game().getCreatureByID(lastHitCreatureId);
Expand Down Expand Up @@ -585,7 +585,7 @@ void Creature::onDeath() {
}

bool Creature::dropCorpse(const std::shared_ptr<Creature> &lastHitCreature, const std::shared_ptr<Creature> &mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (!lootDrop && getMonster()) {
if (getMaster()) {
// Scripting event onDeath
Expand Down Expand Up @@ -882,7 +882,7 @@ void Creature::goToFollowCreature_async(std::function<void()> &&onComplete) {
}

void Creature::goToFollowCreature() {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
const auto &followCreature = getFollowCreature();
if (!followCreature) {
return;
Expand Down Expand Up @@ -937,7 +937,7 @@ bool Creature::canFollowMaster() const {
}

bool Creature::setFollowCreature(const std::shared_ptr<Creature> &creature) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (creature) {
if (getFollowCreature() == creature) {
return true;
Expand Down Expand Up @@ -1086,15 +1086,15 @@ void Creature::onAttackedCreatureDrainHealth(const std::shared_ptr<Creature> &ta
}

void Creature::onAttackedCreatureKilled(const std::shared_ptr<Creature> &target) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (target != getCreature()) {
uint64_t gainExp = target->getGainedExperience(static_self_cast<Creature>());
onGainExperience(gainExp, target);
}
}

bool Creature::deprecatedOnKilledCreature(const std::shared_ptr<Creature> &target, bool lastHit) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
const auto &master = getMaster();
if (master) {
master->deprecatedOnKilledCreature(target, lastHit);
Expand All @@ -1109,7 +1109,7 @@ bool Creature::deprecatedOnKilledCreature(const std::shared_ptr<Creature> &targe
}

void Creature::onGainExperience(uint64_t gainExp, const std::shared_ptr<Creature> &target) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
const auto &master = getMaster();
if (gainExp == 0 || !master) {
return;
Expand Down Expand Up @@ -1140,7 +1140,7 @@ void Creature::onGainExperience(uint64_t gainExp, const std::shared_ptr<Creature
}

bool Creature::setMaster(const std::shared_ptr<Creature> &newMaster, bool reloadCreature /* = false*/) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
// Persists if this creature has ever been a summon
this->summoned = true;
const auto &oldMaster = getMaster();
Expand Down Expand Up @@ -1173,7 +1173,7 @@ bool Creature::setMaster(const std::shared_ptr<Creature> &newMaster, bool reload
}

bool Creature::addCondition(const std::shared_ptr<Condition> &condition, bool attackerPlayer /* = false*/) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (condition == nullptr) {
return false;
}
Expand Down Expand Up @@ -1211,7 +1211,7 @@ bool Creature::addCombatCondition(const std::shared_ptr<Condition> &condition, b
}

void Creature::removeCondition(ConditionType_t type) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
auto it = conditions.begin(), end = conditions.end();
while (it != end) {
std::shared_ptr<Condition> condition = *it;
Expand All @@ -1229,7 +1229,7 @@ void Creature::removeCondition(ConditionType_t type) {
}

void Creature::removeCondition(ConditionType_t conditionType, ConditionId_t conditionId, bool force /* = false*/) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
auto it = conditions.begin();
const auto end = conditions.end();
while (it != end) {
Expand Down Expand Up @@ -1292,7 +1292,7 @@ std::shared_ptr<Condition> Creature::getCondition(ConditionType_t type) const {
}

std::shared_ptr<Condition> Creature::getCondition(ConditionType_t type, ConditionId_t conditionId, uint32_t subId /* = 0*/) const {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
for (const auto &condition : conditions) {
if (condition->getType() == type && condition->getId() == conditionId && condition->getSubId() == subId) {
return condition;
Expand All @@ -1312,7 +1312,7 @@ std::vector<std::shared_ptr<Condition>> Creature::getConditionsByType(ConditionT
}

void Creature::executeConditions(uint32_t interval) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
auto it = conditions.begin(), end = conditions.end();
while (it != end) {
std::shared_ptr<Condition> condition = *it;
Expand All @@ -1331,7 +1331,7 @@ void Creature::executeConditions(uint32_t interval) {
}

bool Creature::hasCondition(ConditionType_t type, uint32_t subId /* = 0*/) const {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (isSuppress(type, false)) {
return false;
}
Expand Down Expand Up @@ -1607,7 +1607,7 @@ ZoneType_t Creature::getZoneType() {
}

bool Creature::getPathTo(const Position &targetPos, std::vector<Direction> &dirList, const FindPathParams &fpp) {
metrics::method_latency measure(__METHOD_NAME__);
metrics::method_latency measure(__METRICS_METHOD_NAME__);
if (fpp.maxSearchDist != 0 || fpp.keepDistance) {
return g_game().map.getPathMatchingCond(getCreature(), targetPos, dirList, FrozenPathingConditionCall(targetPos), fpp);
}
Expand Down
Loading

0 comments on commit 21f0a50

Please sign in to comment.