Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
beats-dh committed Mar 24, 2024
1 parent 2295243 commit 3fd4c3f
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 111 deletions.
12 changes: 6 additions & 6 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ bool Combat::isProtected(std::shared_ptr<Player> attacker, std::shared_ptr<Playe
return true;
}

if (!attacker->getVocation()->canCombat() || !target->getVocation()->canCombat() && (attacker->getVocationId() == VOCATION_NONE || target->getVocationId() == VOCATION_NONE)) {
if ((!attacker->getVocation()->canCombat() || !target->getVocation()->canCombat()) && (attacker->getVocationId() == VOCATION_NONE || target->getVocationId() == VOCATION_NONE)) {
return true;
}

Expand Down Expand Up @@ -699,7 +699,7 @@ bool Combat::checkFearConditionAffected(std::shared_ptr<Player> player) {
auto affectedCount = (party->getMemberCount() + 5) / 5;
g_logger().debug("[{}] Player is member of a party, {} members can be feared", __FUNCTION__, affectedCount);

for (const auto member : party->getMembers()) {
for (const auto &member : party->getMembers()) {
if (member->hasCondition(CONDITION_FEARED)) {
affectedCount -= 1;
}
Expand Down Expand Up @@ -751,7 +751,7 @@ void Combat::CombatConditionFunc(std::shared_ptr<Creature> caster, std::shared_p
}
}

if (caster == target || target && !target->isImmune(condition->getType())) {
if (caster == target || (target && !target->isImmune(condition->getType()))) {
auto conditionCopy = condition->clone();
if (caster) {
conditionCopy->setParam(CONDITION_PARAM_OWNER, caster->getID());
Expand Down Expand Up @@ -1025,7 +1025,7 @@ bool Combat::doCombatChain(std::shared_ptr<Creature> caster, std::shared_ptr<Cre
auto targets = pickChainTargets(caster, params, chainDistance, maxTargets, backtracking, aggressive, target);

g_logger().debug("[{}] Chain targets: {}", __FUNCTION__, targets.size());
if (targets.empty() || targets.size() == 1 && targets.begin()->second.empty()) {
if (targets.empty() || (targets.size() == 1 && targets.begin()->second.empty())) {
return false;
}

Expand Down Expand Up @@ -2068,7 +2068,7 @@ void AreaCombat::setupExtArea(const std::list<uint32_t> &list, uint32_t rows) {

void MagicField::onStepInField(const std::shared_ptr<Creature> &creature) {
// remove magic walls/wild growth
if (!isBlocking() && g_game().getWorldType() == WORLD_TYPE_NO_PVP && id == ITEM_MAGICWALL_SAFE || id == ITEM_WILDGROWTH_SAFE) {
if ((!isBlocking() && g_game().getWorldType() == WORLD_TYPE_NO_PVP && id == ITEM_MAGICWALL_SAFE) || id == ITEM_WILDGROWTH_SAFE) {
if (!creature->isInGhostMode()) {
g_game().internalRemoveItem(static_self_cast<Item>(), 1);
}
Expand All @@ -2083,7 +2083,7 @@ void MagicField::onStepInField(const std::shared_ptr<Creature> &creature) {
if (ownerId) {
bool harmfulField = true;
auto itemTile = getTile();
if (g_game().getWorldType() == WORLD_TYPE_NO_PVP || itemTile && itemTile->hasFlag(TILESTATE_NOPVPZONE)) {
if (g_game().getWorldType() == WORLD_TYPE_NO_PVP || (itemTile && itemTile->hasFlag(TILESTATE_NOPVPZONE))) {
auto ownerPlayer = g_game().getPlayerByGUID(ownerId);
if (ownerPlayer) {
harmfulField = false;
Expand Down
2 changes: 2 additions & 0 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,8 @@ bool ConditionFeared::getFleePath(std::shared_ptr<Creature> creature, const Posi
futurePos.y -= wsize;
g_logger().debug("[{}] Trying to flee to NORTHWEST to {} [{}]", __FUNCTION__, futurePos.toString(), wsize);
break;
case DIRECTION_NONE:
break;
}

found = creature->getPathTo(futurePos, dirList, 0, 30);
Expand Down
1 change: 0 additions & 1 deletion src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,6 @@ uint32_t Spell::getManaCost(std::shared_ptr<Player> player) const {
if (manaPercent != 0) {
uint32_t maxMana = player->getMaxMana();
uint32_t manaCost = (maxMana * manaPercent) / 100;
WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName());
if (manaRedution > manaCost) {
return 0;
}
Expand Down
36 changes: 19 additions & 17 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Website: https://docs.opentibiabr.com/
*/

#include <utility>

#include "pch.hpp"

#include "creatures/creature.hpp"
Expand Down Expand Up @@ -125,7 +127,7 @@ void Creature::onThink(uint32_t interval) {
auto onThink = [self = getCreature(), interval] {
// scripting event - onThink
const auto &thinkEvents = self->getCreatureEvents(CREATURE_EVENT_THINK);
for (const auto creatureEventPtr : thinkEvents) {
for (const auto &creatureEventPtr : thinkEvents) {
creatureEventPtr->executeOnThink(self->static_self_cast<Creature>(), interval);
}
};
Expand Down Expand Up @@ -299,7 +301,7 @@ void Creature::updateTileCache(std::shared_ptr<Tile> upTile, const Position &pos
if (pos.z == myPos.z) {
int32_t dx = Position::getOffsetX(pos, myPos);
int32_t dy = Position::getOffsetY(pos, myPos);
updateTileCache(upTile, dx, dy);
updateTileCache(std::move(upTile), dx, dy);
}
}

Expand Down Expand Up @@ -332,7 +334,7 @@ int32_t Creature::getWalkCache(const Position &pos) {

void Creature::onAddTileItem(std::shared_ptr<Tile> tileItem, const Position &pos) {
if (isMapLoaded && pos.z == getPosition().z) {
updateTileCache(tileItem, pos);
updateTileCache(std::move(tileItem), pos);
}
}

Expand All @@ -343,7 +345,7 @@ void Creature::onUpdateTileItem(std::shared_ptr<Tile> updateTile, const Position

if (oldType.blockSolid || oldType.blockPathFind || newType.blockPathFind || newType.blockSolid) {
if (pos.z == getPosition().z) {
updateTileCache(updateTile, pos);
updateTileCache(std::move(updateTile), pos);
}
}
}
Expand All @@ -355,7 +357,7 @@ void Creature::onRemoveTileItem(std::shared_ptr<Tile> updateTile, const Position

if (iType.blockSolid || iType.blockPathFind || iType.isGroundTile()) {
if (pos.z == getPosition().z) {
updateTileCache(updateTile, pos);
updateTileCache(std::move(updateTile), pos);
}
}
}
Expand Down Expand Up @@ -439,7 +441,7 @@ void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) {
// Check if any of our summons is out of range (+/- 2 floors or 30 tiles away)
bool checkRemoveDist = Position::getDistanceZ(newPos, pos) > 2 || (std::max<int32_t>(Position::getDistanceX(newPos, pos), Position::getDistanceY(newPos, pos)) > 30);

if (monster && monster->isFamiliar() && checkSummonDist || teleportSummon && !protectionZoneCheck && checkSummonDist) {
if ((monster && monster->isFamiliar() && checkSummonDist) || (teleportSummon && !protectionZoneCheck && checkSummonDist)) {
const auto &creatureMaster = summon->getMaster();
if (!creatureMaster) {
continue;
Expand Down Expand Up @@ -761,7 +763,7 @@ bool Creature::dropCorpse(std::shared_ptr<Creature> lastHitCreature, std::shared
if (getMaster()) {
// Scripting event onDeath
const CreatureEventList &deathEvents = getCreatureEvents(CREATURE_EVENT_DEATH);
for (const auto deathEventPtr : deathEvents) {
for (const auto &deathEventPtr : deathEvents) {
deathEventPtr->executeOnDeath(static_self_cast<Creature>(), nullptr, lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified);
}
}
Expand Down Expand Up @@ -823,7 +825,7 @@ bool Creature::dropCorpse(std::shared_ptr<Creature> lastHitCreature, std::shared
}

// Scripting event onDeath
for (const auto deathEventPtr : getCreatureEvents(CREATURE_EVENT_DEATH)) {
for (const auto &deathEventPtr : getCreatureEvents(CREATURE_EVENT_DEATH)) {
if (deathEventPtr) {
deathEventPtr->executeOnDeath(static_self_cast<Creature>(), corpse, lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified);
}
Expand Down Expand Up @@ -1158,7 +1160,7 @@ double Creature::getDamageRatio(std::shared_ptr<Creature> attacker) const {
}

uint64_t Creature::getGainedExperience(std::shared_ptr<Creature> attacker) const {
return std::floor(getDamageRatio(attacker) * getLostExperience());
return std::floor(getDamageRatio(std::move(attacker)) * getLostExperience());
}

void Creature::addDamagePoints(std::shared_ptr<Creature> attacker, int32_t damagePoints) {
Expand All @@ -1170,7 +1172,7 @@ void Creature::addDamagePoints(std::shared_ptr<Creature> attacker, int32_t damag

auto it = damageMap.find(attackerId);
if (it == damageMap.end()) {
CountBlock_t cb;
CountBlock_t cb {};
cb.ticks = OTSYS_TIME();
cb.total = damagePoints;
damageMap[attackerId] = cb;
Expand Down Expand Up @@ -1236,7 +1238,7 @@ void Creature::onTickCondition(ConditionType_t type, bool &bRemove) {
}

void Creature::onCombatRemoveCondition(std::shared_ptr<Condition> condition) {
removeCondition(condition);
removeCondition(std::move(condition));
}

void Creature::onAttacked() {
Expand Down Expand Up @@ -1264,7 +1266,7 @@ bool Creature::deprecatedOnKilledCreature(std::shared_ptr<Creature> target, bool

// scripting event - onKill
const CreatureEventList &killEvents = getCreatureEvents(CREATURE_EVENT_KILL);
for (const auto killEventPtr : killEvents) {
for (const auto &killEventPtr : killEvents) {
killEventPtr->executeOnKill(static_self_cast<Creature>(), target, lastHit);
}
return false;
Expand All @@ -1282,7 +1284,7 @@ void Creature::onGainExperience(uint64_t gainExp, std::shared_ptr<Creature> targ
gainExp /= 2;
}

master->onGainExperience(gainExp, target);
master->onGainExperience(gainExp, std::move(target));

if (!m->isFamiliar()) {
auto spectators = Spectators().find<Player>(position);
Expand Down Expand Up @@ -1563,7 +1565,7 @@ void Creature::setSpeed(int32_t varSpeedDelta) {
}

void Creature::setCreatureLight(LightInfo lightInfo) {
internalLight = std::move(lightInfo);
internalLight = lightInfo;
}

void Creature::setNormalCreatureLight() {
Expand All @@ -1578,7 +1580,7 @@ bool Creature::registerCreatureEvent(const std::string &name) {

CreatureEventType_t type = event->getEventType();
if (hasEventRegistered(type)) {
for (const auto creatureEventPtr : eventsList) {
for (const auto &creatureEventPtr : eventsList) {
if (creatureEventPtr == event) {
return false;
}
Expand Down Expand Up @@ -1631,7 +1633,7 @@ CreatureEventList Creature::getCreatureEvents(CreatureEventType_t type) {
return tmpEventList;
}

for (const auto creatureEventPtr : eventsList) {
for (const auto &creatureEventPtr : eventsList) {
if (creatureEventPtr->getEventType() == type) {
tmpEventList.push_back(creatureEventPtr);
}
Expand Down Expand Up @@ -1716,7 +1718,7 @@ bool FrozenPathingConditionCall::operator()(const Position &startPos, const Posi
}

bool Creature::isInvisible() const {
return std::find_if(conditions.begin(), conditions.end(), [](const std::shared_ptr<Condition> condition) {
return std::find_if(conditions.begin(), conditions.end(), [](const std::shared_ptr<Condition> &condition) {
return condition->getType() == CONDITION_INVISIBLE;
})
!= conditions.end();
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ void Monster::updateIdleStatus() {
isWalkingBack = true;
}
} else if (const auto &master = getMaster()) {
if ((!isSummon() && totalPlayersOnScreen == 0 || isSummon() && master->getMonster() && master->getMonster()->totalPlayersOnScreen == 0) && getFaction() != FACTION_DEFAULT) {
if (((!isSummon() && totalPlayersOnScreen == 0) || (isSummon() && master->getMonster() && master->getMonster()->totalPlayersOnScreen == 0)) && getFaction() != FACTION_DEFAULT) {
idle = true;
}
}
Expand Down Expand Up @@ -838,7 +838,7 @@ void Monster::doAttacking(uint32_t interval) {
for (const spellBlock_t &spellBlock : mType->info.attackSpells) {
bool inRange = false;

if (spellBlock.spell == nullptr || spellBlock.isMelee && isFleeing()) {
if (spellBlock.spell == nullptr || (spellBlock.isMelee && isFleeing())) {
continue;
}

Expand Down
9 changes: 1 addition & 8 deletions src/creatures/monsters/spawns/spawn_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ bool SpawnsMonster::loadFromXML(const std::string &filemonstername) {
this->filemonstername = filemonstername;
loaded = true;

uint32_t eventschedule = g_eventsScheduler().getSpawnMonsterSchedule();
std::string boostedNameGet = g_game().getBoostedMonsterName();

for (auto spawnMonsterNode : doc.child("monsters").children()) {
Expand Down Expand Up @@ -89,12 +88,6 @@ bool SpawnsMonster::loadFromXML(const std::string &filemonstername) {
centerPos.z
);

int32_t boostedrate = 1;

if (nameAttribute.value() == boostedNameGet) {
boostedrate = 2;
}

pugi::xml_attribute weightAttribute = childMonsterNode.attribute("weight");
uint32_t weight = 1;
if (weightAttribute) {
Expand Down Expand Up @@ -343,7 +336,7 @@ bool SpawnMonster::addMonster(const std::string &name, const Position &pos, Dire
g_logger().error("[SpawnMonster] Monster {} already exists in spawn block at {}", name, pos.toString());
return false;
}
if (monsterType->isBoss() && sb->monsterTypes.size() > 0) {
if (monsterType->isBoss() && !sb->monsterTypes.empty()) {
g_logger().error("[SpawnMonster] Boss monster {} has been added to spawn block with other monsters. This is not allowed.", name);
return false;
}
Expand Down
1 change: 0 additions & 1 deletion src/creatures/npcs/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ void Npc::onPlayerCheckItem(std::shared_ptr<Player> player, uint16_t itemId, uin
return;
}

const ItemType &itemType = Item::items[itemId];
// onPlayerCheckItem(self, player, itemId, subType)
CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, getNpc());
if (callback.startScriptInterface(npcType->info.playerLookEvent)) {
Expand Down
6 changes: 4 additions & 2 deletions src/creatures/players/highscore_category.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <utility>

/**
* Canary - A free and open-source MMORPG server emulator
* Copyright (©) 2019-2024 OpenTibiaBR <[email protected]>
Expand All @@ -10,8 +12,8 @@
#pragma once

struct HighscoreCategory {
HighscoreCategory(const std::string &name, uint8_t id) :
m_name(name),
HighscoreCategory(std::string name, uint8_t id) :
m_name(std::move(name)),
m_id(id) { }

std::string m_name;
Expand Down
Loading

0 comments on commit 3fd4c3f

Please sign in to comment.