Skip to content

Commit

Permalink
feat: some reverts
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Oct 16, 2024
1 parent 6e10a67 commit b0d8af6
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 358 deletions.
6 changes: 3 additions & 3 deletions data/XML/groups.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@
<flag cannotusecombat="0" /> <!-- Is combat not allowed? Set to 0 to enable the two flags below. If set to 1 these two flags below will be ignored. -->
<flag cannotattackplayer="1" /> <!-- If combat is allowed (set to 0 above), attack players is not allowed? -->
<flag cannotattackmonster="0" /> <!-- If combat is allowed (set to 0 above), attack monsters is not allowed? -->
<flag cannotbeattacked="0" />
<flag cannotbeattacked="1" />
<flag canconvinceall="1" />
<flag cansummonall="1" />
<flag canillusionall="1" />
<flag cansenseinvisibility="1" />
<flag ignoredbymonsters="0" />
<flag ignoredbynpcs="0" />
<flag ignoredbymonsters="1" />
<flag ignoredbynpcs="1" />
<flag notgaininfight="1" />
<flag hasinfinitemana="1" />
<flag hasinfinitesoul="1" />
Expand Down
16 changes: 8 additions & 8 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,28 +309,28 @@ ReturnValue Combat::canDoCombat(const std::shared_ptr<Creature> &attacker, const
return RETURNVALUE_NOERROR;
}

const auto targetPlayer = target ? target->getPlayer() : nullptr;
const auto &targetPlayer = target ? target->getPlayer() : nullptr;
if (target) {
const std::shared_ptr<Tile> &tile = target->getTile();
if (tile->hasProperty(CONST_PROP_BLOCKPROJECTILE)) {
return RETURNVALUE_NOTENOUGHROOM;
}
if (tile->hasFlag(TILESTATE_PROTECTIONZONE)) {
const auto permittedOnPz = targetPlayer ? targetPlayer->hasPermittedConditionInPZ() : false;
if (targetPlayer && tile->hasFlag(TILESTATE_PROTECTIONZONE)) {
const auto permittedOnPz = targetPlayer->hasPermittedConditionInPZ();
return permittedOnPz ? RETURNVALUE_NOERROR : RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE;
}
}

if (attacker) {
const auto &attackerMaster = attacker->getMaster();
const auto &attackerPlayer = attacker->getPlayer();
if (targetPlayer) {
if (targetPlayer->hasFlag(PlayerFlags_t::CannotBeAttacked)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
}

const auto &targetPlayerTile = targetPlayer->getTile();

if (const auto &attackerPlayer = attacker->getPlayer()) {
if (attackerPlayer) {
if (attackerPlayer->hasFlag(PlayerFlags_t::CannotAttackPlayer)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
}
Expand All @@ -340,7 +340,7 @@ ReturnValue Combat::canDoCombat(const std::shared_ptr<Creature> &attacker, const
}

// nopvp-zone
const auto attackerTile = attackerPlayer->getTile();
const auto &attackerTile = attackerPlayer->getTile();
if (targetPlayerTile && targetPlayerTile->hasFlag(TILESTATE_NOPVPZONE)) {
return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE;
}
Expand Down Expand Up @@ -379,7 +379,7 @@ ReturnValue Combat::canDoCombat(const std::shared_ptr<Creature> &attacker, const
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
}

if (const auto &attackerPlayer = attacker->getPlayer()) {
if (attackerPlayer) {
if (attackerPlayer->hasFlag(PlayerFlags_t::CannotAttackMonster)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
}
Expand Down Expand Up @@ -501,7 +501,7 @@ bool Combat::setParam(CombatParam_t param, uint32_t value) {
return false;
}

bool Combat::setCallback(const CallBackParam_t &key) {
bool Combat::setCallback(CallBackParam_t key) {
switch (key) {
case CALLBACK_PARAM_LEVELMAGICVALUE: {
params.valueCallback = std::make_unique<ValueCallback>(COMBAT_FORMULA_LEVELMAGIC);
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 @@ -306,7 +306,7 @@ class Combat {
bool doCombat(const std::shared_ptr<Creature> &caster, const std::shared_ptr<Creature> &target, const Position &origin, int affected = 1) const;
bool doCombat(const std::shared_ptr<Creature> &caster, const Position &pos) const;

bool setCallback(const CallBackParam_t &key);
bool setCallback(CallBackParam_t key);
void setChainCallback(uint8_t chainTargets, uint8_t chainDistance, bool backtracking);
CallBack* getCallback(CallBackParam_t key) const;

Expand Down
62 changes: 31 additions & 31 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,16 @@ bool Spells::registerInstantLuaEvent(const std::shared_ptr<InstantSpell> &instan
bool Spells::registerRuneLuaEvent(const std::shared_ptr<RuneSpell> &rune) {
if (rune) {
uint16_t id = rune->getRuneItemId();
const auto &[fst, snd] = runes.emplace(rune->getRuneItemId(), rune);
if (!snd) {
const auto &[iter, inserted] = runes.emplace(rune->getRuneItemId(), rune);
if (!inserted) {
g_logger().warn(
"[{}] duplicate registered rune with id: {}, for script: {}",
__FUNCTION__,
id,
rune->getScriptInterface()->getLoadingScriptName()
);
}
return snd;
return inserted;
}

return false;
Expand All @@ -158,13 +158,13 @@ bool Spells::registerRuneLuaEvent(const std::shared_ptr<RuneSpell> &rune) {
std::list<uint16_t> Spells::getSpellsByVocation(uint16_t vocationId) const {
std::list<uint16_t> spellsList;

for (const auto &[fst, snd] : instants) {
const VocSpellMap &vocSpells = snd->getVocMap();
for (const auto &[name, spell] : instants) {
const VocSpellMap &vocSpells = spell->getVocMap();
const auto &vocSpellsIt = vocSpells.find(vocationId);

if (vocSpellsIt != vocSpells.end()
&& vocSpellsIt->second) {
spellsList.emplace_back(snd->getSpellId());
spellsList.emplace_back(spell->getSpellId());
}
}

Expand All @@ -180,22 +180,17 @@ std::shared_ptr<Spell> Spells::getSpellByName(const std::string &name) const {
}

std::shared_ptr<RuneSpell> Spells::getRuneSpell(uint16_t id) {
const auto &it = runes.find(id);
if (it == runes.end()) {
for (const auto &[fst, snd] : runes) {
if (snd->getRuneItemId() == id) {
return snd;
}
}
return nullptr;
const auto it = runes.find(id);
if (it != runes.end()) {
return it->second;
}
return it->second;
}

return nullptr;
}
std::shared_ptr<RuneSpell> Spells::getRuneSpellByName(const std::string &name) const {
for (const auto &[fst, snd] : runes) {
if (strcasecmp(snd->getName().c_str(), name.c_str()) == 0) {
return snd;
for (const auto &[runeId, runeSpell] : runes) {
if (caseInsensitiveCompare(runeSpell->getName(), name)) {
return runeSpell;
}
}
return nullptr;
Expand All @@ -204,12 +199,17 @@ std::shared_ptr<RuneSpell> Spells::getRuneSpellByName(const std::string &name) c
std::shared_ptr<InstantSpell> Spells::getInstantSpell(const std::string &words) const {
std::shared_ptr<InstantSpell> result = nullptr;

for (const auto &[fst, snd] : instants) {
const std::string &instantSpellWords = snd->getWords();
for (const auto &[spellName, instantSpell] : instants) {
const std::string &instantSpellWords = instantSpell->getWords();
const size_t spellLen = instantSpellWords.length();
if (strncasecmp(instantSpellWords.c_str(), words.c_str(), spellLen) == 0) {

if (words.length() < spellLen) {
continue;
}

if (caseInsensitiveCompare(instantSpellWords, words, spellLen)) {
if (!result || spellLen > result->getWords().length()) {
result = snd;
result = instantSpell;
if (words.length() == spellLen) {
break;
}
Expand All @@ -230,24 +230,24 @@ std::shared_ptr<InstantSpell> Spells::getInstantSpell(const std::string &words)
return nullptr;
}
}
return result;
}
return nullptr;

return result;
}

std::shared_ptr<InstantSpell> Spells::getInstantSpellById(uint16_t spellId) const {
for (const auto &[fst, snd] : instants) {
if (snd->getSpellId() == spellId) {
return snd;
for (const auto &[spellName, instantSpell] : instants) {
if (instantSpell->getSpellId() == spellId) {
return instantSpell;
}
}
return nullptr;
}

std::shared_ptr<InstantSpell> Spells::getInstantSpellByName(const std::string &name) const {
for (const auto &[fst, snd] : instants) {
if (strcasecmp(snd->getName().c_str(), name.c_str()) == 0) {
return snd;
for (const auto &[spellName, instantSpell] : instants) {
if (caseInsensitiveCompare(instantSpell->getName(), name)) {
return instantSpell;
}
}
return nullptr;
Expand Down
38 changes: 25 additions & 13 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,17 @@ void Creature::onDeath() {
int32_t mostDamage = 0;
std::map<std::shared_ptr<Creature>, uint64_t> experienceMap;
std::unordered_set<std::shared_ptr<Player>> killers;
for (const auto &[fst, snd] : damageMap) {
if (auto attacker = g_game().getCreatureByID(fst)) {
const auto [total, ticks] = snd;
for (const auto &[creatureId, damageInfo] : damageMap) {
if (creatureId == 0) {
continue;
}

if (auto attacker = g_game().getCreatureByID(creatureId)) {
const auto &[total, ticks] = damageInfo;

Check warning on line 662 in src/creatures/creature.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] src/creatures/creature.cpp#L662

Variable 'total' is not assigned a value.
Raw output
src/creatures/creature.cpp:662:Variable 'total' is not assigned a value.
if (total == 0 || ticks == 0) {
continue;
}

if ((total > mostDamage && (timeNow - ticks <= inFightTicks))) {
mostDamage = total;
mostDamageCreature = attacker;
Expand Down Expand Up @@ -690,8 +698,8 @@ void Creature::onDeath() {
}
}

for (const auto &[fst, snd] : experienceMap) {
fst->onGainExperience(snd, getCreature());
for (const auto &[creature, experience] : experienceMap) {
creature->onGainExperience(experience, getCreature());
}

mostDamageCreature = mostDamageCreature && mostDamageCreature->getMaster() ? mostDamageCreature->getMaster() : mostDamageCreature;
Expand Down Expand Up @@ -1166,11 +1174,15 @@ double Creature::getDamageRatio(const std::shared_ptr<Creature> &attacker) const
uint32_t totalDamage = 0;
uint32_t attackerDamage = 0;

for (const auto &[fst, snd] : damageMap) {
const auto &[total, ticks] = snd;
totalDamage += total;
if (fst == attacker->getID()) {
attackerDamage += total;
for (const auto &[attackerId, damageInfo] : damageMap) {

Check warning on line 1177 in src/creatures/creature.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] src/creatures/creature.cpp#L1177

Variable 'attackerId' is not assigned a value.
Raw output
src/creatures/creature.cpp:1177:Variable 'attackerId' is not assigned a value.
const auto &[totalDamageValue, ticks] = damageInfo;

Check warning on line 1178 in src/creatures/creature.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] src/creatures/creature.cpp#L1178

Variable 'totalDamageValue' is not assigned a value.
Raw output
src/creatures/creature.cpp:1178:Variable 'totalDamageValue' is not assigned a value.
if (attackerId == 0 || totalDamageValue == 0) {
continue;
}

totalDamage += totalDamageValue;
if (attackerId == attacker->getID()) {
attackerDamage += totalDamageValue;
}
}

Expand Down Expand Up @@ -1206,19 +1218,19 @@ void Creature::addDamagePoints(const std::shared_ptr<Creature> &attacker, int32_
lastHitCreatureId = attackerId;
}

void Creature::onAddCondition(const ConditionType_t &type) {
void Creature::onAddCondition(ConditionType_t type) {
if (type == CONDITION_PARALYZE && hasCondition(CONDITION_HASTE)) {
removeCondition(CONDITION_HASTE);
} else if (type == CONDITION_HASTE && hasCondition(CONDITION_PARALYZE)) {
removeCondition(CONDITION_PARALYZE);
}
}

void Creature::onAddCombatCondition(const ConditionType_t &) {
void Creature::onAddCombatCondition(ConditionType_t) {
//
}

void Creature::onEndCondition(const ConditionType_t &) {
void Creature::onEndCondition(ConditionType_t) {
//
}

Expand Down
6 changes: 3 additions & 3 deletions src/creatures/creature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ class Creature : virtual public Thing, public SharedObject {
bool hasBeenAttacked(uint32_t attackerId);

// combat event functions
virtual void onAddCondition(const ConditionType_t &type);
virtual void onAddCombatCondition(const ConditionType_t &type);
virtual void onEndCondition(const ConditionType_t &type);
virtual void onAddCondition(ConditionType_t type);
virtual void onAddCombatCondition(ConditionType_t type);
virtual void onEndCondition(ConditionType_t type);
void onTickCondition(ConditionType_t type, bool &bRemove);
virtual void onCombatRemoveCondition(const std::shared_ptr<Condition> &condition);
virtual void onAttackedCreature(const std::shared_ptr<Creature> &) { }
Expand Down
Loading

0 comments on commit b0d8af6

Please sign in to comment.