Skip to content

Commit

Permalink
ayeye
Browse files Browse the repository at this point in the history
  • Loading branch information
MillhioreBT committed Oct 8, 2023
1 parent c043fdc commit 62f3615
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 30 deletions.
6 changes: 5 additions & 1 deletion src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,10 @@ void Creature::onDeath()

if (master) {
setMaster(nullptr);

if (getMonster()) {
decrementReferenceCounter();
}
}

if (droppedCorpse) {
Expand Down Expand Up @@ -808,7 +812,7 @@ void Creature::changeHealth(int32_t healthChange, bool sendHealthChange /* = tru
g_game.addCreatureHealth(this);
}

if (health <= 0) {
if (isDead()) {
g_dispatcher.addTask([id = getID()]() { g_game.executeDeath(id); });
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ Creature* Game::getCreatureByName(const std::string& s)
}

auto equalCreatureName = [&](const std::pair<uint32_t, Creature*>& it) {
auto name = it.second->getName();
auto& name = it.second->getName();
return lowerCaseName.size() == name.size() &&
std::equal(lowerCaseName.begin(), lowerCaseName.end(), name.begin(),
[](char a, char b) { return a == std::tolower(b); });
Expand Down Expand Up @@ -1530,7 +1530,7 @@ bool Game::removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*
const uint32_t worth = moneyEntry.first / item->getItemCount();
const uint32_t removeCount = std::ceil(money / static_cast<double>(worth));

addMoney(cylinder, (worth * removeCount) - money, flags);
addMoney(cylinder, static_cast<uint64_t>(worth * removeCount) - money, flags);
internalRemoveItem(item, removeCount);
break;
} else {
Expand Down Expand Up @@ -3399,22 +3399,22 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, s

bool Game::playerSaySpell(Player* player, SpeakClasses type, std::string_view text)
{
TalkActionResult_t result = g_talkActions->playerSaySpell(player, type, text);
if (result == TALKACTION_BREAK) {
TalkActionResult result = g_talkActions->playerSaySpell(player, type, text);
if (result == TalkActionResult::BREAK) {
return true;
}

std::string words{text};

result = g_spells->playerSaySpell(player, words);
if (result == TALKACTION_BREAK) {
if (result == TalkActionResult::BREAK) {
if (!g_config[ConfigKeysBoolean::EMOTE_SPELLS]) {
return internalCreatureSay(player, TALKTYPE_SAY, words, false);
} else {
return internalCreatureSay(player, TALKTYPE_MONSTER_SAY, words, false);
}

} else if (result == TALKACTION_FAILED) {
} else if (result == TalkActionResult::FAILED) {
return true;
}

Expand Down Expand Up @@ -4569,7 +4569,8 @@ void Game::checkDecay()
ReleaseItem(item);
} else if (duration < EVENT_DECAYINTERVAL * EVENT_DECAY_BUCKETS) {
it = decayItems[bucket].erase(it);
size_t newBucket = (bucket + ((duration + EVENT_DECAYINTERVAL / 2) / 1000)) % EVENT_DECAY_BUCKETS;
size_t newBucket =
(bucket + static_cast<size_t>((duration + EVENT_DECAYINTERVAL / 2) / 1000)) % EVENT_DECAY_BUCKETS;
if (newBucket == bucket) {
internalDecayItem(item);
ReleaseItem(item);
Expand Down
5 changes: 5 additions & 0 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,11 @@ void LuaScriptInterface::registerFunctions()
registerEnum(DECAYING_TRUE);
registerEnum(DECAYING_PENDING);

registerEnum(VARIANT_NUMBER);
registerEnum(VARIANT_POSITION);
registerEnum(VARIANT_TARGETPOSITION);
registerEnum(VARIANT_STRING);

// _G
registerGlobalVariable("INDEX_WHEREEVER", INDEX_WHEREEVER);
registerGlobalBoolean("VIRTUAL_PARENT", true);
Expand Down
2 changes: 1 addition & 1 deletion src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ void Monster::death(Creature*)

for (Creature* summon : summons) {
summon->changeHealth(-summon->getHealth());
summon->removeMaster();
//summon->removeMaster();
}
summons.clear();

Expand Down
12 changes: 6 additions & 6 deletions src/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Spells::Spells() { scriptInterface.initState(); }

Spells::~Spells() { clear(false); }

TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words)
TalkActionResult Spells::playerSaySpell(Player* player, std::string& words)
{
std::string str_words = words;

Expand All @@ -31,7 +31,7 @@ TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words)

InstantSpell* instantSpell = getInstantSpell(str_words);
if (!instantSpell) {
return TALKACTION_CONTINUE;
return TalkActionResult::CONTINUE;
}

std::string param;
Expand All @@ -47,7 +47,7 @@ TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words)
if (loc2 == std::string::npos) {
loc2 = paramText.length();
} else if (paramText.find_last_not_of(' ') != loc2) {
return TALKACTION_CONTINUE;
return TalkActionResult::CONTINUE;
}

param = paramText.substr(loc1 + 1, loc2 - loc1 - 1);
Expand All @@ -57,7 +57,7 @@ TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words)
if (loc1 == std::string::npos) {
param = paramText;
} else {
return TALKACTION_CONTINUE;
return TalkActionResult::CONTINUE;
}
}
}
Expand All @@ -70,10 +70,10 @@ TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words)
words += " \"" + param + "\"";
}

return TALKACTION_BREAK;
return TalkActionResult::BREAK;
}

return TALKACTION_FAILED;
return TalkActionResult::FAILED;
}

void Spells::clearMaps(bool fromLua)
Expand Down
2 changes: 1 addition & 1 deletion src/spells.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Spells final : public BaseEvents
InstantSpell* getInstantSpell(std::string_view words);
InstantSpell* getInstantSpellByName(std::string_view name);

TalkActionResult_t playerSaySpell(Player* player, std::string& words);
TalkActionResult playerSaySpell(Player* player, std::string& words);

static Position getCasterPosition(Creature* creature, Direction dir);
std::string_view getScriptBaseName() const override;
Expand Down
15 changes: 6 additions & 9 deletions src/talkaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool TalkActions::registerLuaEvent(TalkAction* event)
return true;
}

TalkActionResult_t TalkActions::playerSaySpell(Player* player, SpeakClasses type, std::string_view words) const
TalkActionResult TalkActions::playerSaySpell(Player* player, SpeakClasses type, std::string_view words) const
{
size_t wordsLength = words.length();
for (auto it = talkActions.begin(); it != talkActions.end();) {
Expand Down Expand Up @@ -97,23 +97,20 @@ TalkActionResult_t TalkActions::playerSaySpell(Player* player, SpeakClasses type
}

if (it->second.getNeedAccess() && !player->isAccessPlayer()) {
std::cout << player->getGroup()->access << std::endl;
return TALKACTION_CONTINUE;
return TalkActionResult::CONTINUE;
}

if (player->getAccountType() < it->second.getRequiredAccountType()) {
std::cout << static_cast<uint16_t>(player->getAccountType()) << " - "
<< static_cast<uint16_t>(it->second.getRequiredAccountType()) << std::endl;
return TALKACTION_CONTINUE;
return TalkActionResult::CONTINUE;
}

if (it->second.executeSay(player, words, param, type)) {
return TALKACTION_CONTINUE;
return TalkActionResult::CONTINUE;
} else {
return TALKACTION_BREAK;
return TalkActionResult::BREAK;
}
}
return TALKACTION_CONTINUE;
return TalkActionResult::CONTINUE;
}

bool TalkAction::configureEvent(const pugi::xml_node& node)
Expand Down
10 changes: 5 additions & 5 deletions src/talkaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
class TalkAction;
using TalkAction_ptr = std::unique_ptr<TalkAction>;

enum TalkActionResult_t
enum class TalkActionResult
{
TALKACTION_CONTINUE,
TALKACTION_BREAK,
TALKACTION_FAILED,
CONTINUE,
BREAK,
FAILED,
};

class TalkAction : public Event
Expand Down Expand Up @@ -71,7 +71,7 @@ class TalkActions final : public BaseEvents
TalkActions(const TalkActions&) = delete;
TalkActions& operator=(const TalkActions&) = delete;

TalkActionResult_t playerSaySpell(Player* player, SpeakClasses type, std::string_view words) const;
TalkActionResult playerSaySpell(Player* player, SpeakClasses type, std::string_view words) const;

bool registerLuaEvent(TalkAction* event);
void clear(bool fromLua) override final;
Expand Down

0 comments on commit 62f3615

Please sign in to comment.