Skip to content

Commit

Permalink
11072014
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyx14 committed Jul 12, 2024
1 parent a81413e commit 3e02ced
Show file tree
Hide file tree
Showing 29 changed files with 266 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
local loginEvents = CreatureEvent("LoginEvents")
function loginEvents.onLogin(player)
local events = {
"AdvanceSave",
"RookgaardAdvance",
"FamiliarLogin",
"FamiliarAdvance",
--Quests
--Cults Of Tibia Quest
"HealthPillar",
Expand Down
4 changes: 4 additions & 0 deletions data/libs/functions/revscriptsys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ do
self:type("periodchange")
self:onPeriodChange(value)
return
elseif key == "onSave" then
self:type("save")
self:onSave(value)
return
end
rawset(self, key, value)
end
Expand Down
1 change: 1 addition & 0 deletions data/scripts/creaturescripts/familiar/on_login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function familiarOnLogin.onLogin(player)
return false
end

player:registerEvent("FamiliarAdvance")
local vocation = FAMILIAR_ID[player:getVocation():getBaseId()]

local familiarName
Expand Down
1 change: 1 addition & 0 deletions data/scripts/creaturescripts/player/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function playerLoginGlobal.onLogin(player)
player:registerEvent("PlayerDeath")
player:registerEvent("DropLoot")
player:registerEvent("BossParticipation")
player:registerEvent("UpdatePlayerOnAdvancedLevel")
return true
end

Expand Down
29 changes: 16 additions & 13 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ CombatDamage Combat::getCombatDamage(std::shared_ptr<Creature> creature, std::sh
return damage;
}

void Combat::getCombatArea(const Position &centerPos, const Position &targetPos, const std::unique_ptr<AreaCombat> &area, std::forward_list<std::shared_ptr<Tile>> &list) {
void Combat::getCombatArea(const Position &centerPos, const Position &targetPos, const std::unique_ptr<AreaCombat> &area, std::vector<std::shared_ptr<Tile>> &list) {
if (targetPos.z >= MAP_MAX_LAYERS) {
return;
}

if (area) {
area->getList(centerPos, targetPos, list);
} else {
list.push_front(g_game().map.getOrCreateTile(targetPos));
list.emplace_back(g_game().map.getOrCreateTile(targetPos));
}
}

Expand Down Expand Up @@ -1119,7 +1119,7 @@ bool Combat::doCombat(std::shared_ptr<Creature> caster, const Position &position
}

void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin, const Position &pos, const std::unique_ptr<AreaCombat> &area, const CombatParams &params, CombatFunction func, CombatDamage* data) {
std::forward_list<std::shared_ptr<Tile>> tileList;
std::vector<std::shared_ptr<Tile>> tileList;

if (caster) {
getCombatArea(caster->getPosition(), pos, area, tileList);
Expand Down Expand Up @@ -1827,26 +1827,29 @@ AreaCombat::AreaCombat(const AreaCombat &rhs) {
}
}

void AreaCombat::getList(const Position &centerPos, const Position &targetPos, std::forward_list<std::shared_ptr<Tile>> &list) const {
void AreaCombat::getList(const Position &centerPos, const Position &targetPos, std::vector<std::shared_ptr<Tile>> &list) const {
const std::unique_ptr<MatrixArea> &area = getArea(centerPos, targetPos);
if (!area) {
return;
}

uint32_t centerY, centerX;
uint32_t centerY;
uint32_t centerX;
area->getCenter(centerY, centerX);

const uint32_t rows = area->getRows();
const uint32_t cols = area->getCols();
list.reserve(rows * cols);

Position tmpPos(targetPos.x - centerX, targetPos.y - centerY, targetPos.z);
uint32_t cols = area->getCols();
for (uint32_t y = 0, rows = area->getRows(); y < rows; ++y) {
for (uint32_t x = 0; x < cols; ++x) {
if (area->getValue(y, x) != 0 && g_game().isSightClear(targetPos, tmpPos, true)) {
list.push_front(g_game().map.getOrCreateTile(tmpPos));
for (uint32_t y = 0; y < rows; ++y, ++tmpPos.y, tmpPos.x -= cols) {
for (uint32_t x = 0; x < cols; ++x, ++tmpPos.x) {
if (area->getValue(y, x) != 0) {
if (g_game().isSightClear(targetPos, tmpPos, true)) {
list.emplace_back(g_game().map.getOrCreateTile(tmpPos));
}
}
tmpPos.x++;
}
tmpPos.x -= cols;
tmpPos.y++;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/creatures/combat/combat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ChainPickerCallback final : public CallBack {
};

struct CombatParams {
std::forward_list<std::shared_ptr<Condition>> conditionList;
std::vector<std::shared_ptr<Condition>> conditionList;

std::unique_ptr<ValueCallback> valueCallback;
std::unique_ptr<TileCallback> tileCallback;
Expand Down Expand Up @@ -218,7 +218,7 @@ class AreaCombat {
// non-assignable
AreaCombat &operator=(const AreaCombat &) = delete;

void getList(const Position &centerPos, const Position &targetPos, std::forward_list<std::shared_ptr<Tile>> &list) const;
void getList(const Position &centerPos, const Position &targetPos, std::vector<std::shared_ptr<Tile>> &list) const;

void setupArea(const std::list<uint32_t> &list, uint32_t rows);
void setupArea(int32_t length, int32_t spread);
Expand Down Expand Up @@ -290,7 +290,7 @@ class Combat {
static void doCombatDispel(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const CombatParams &params);
static void doCombatDispel(std::shared_ptr<Creature> caster, const Position &position, const std::unique_ptr<AreaCombat> &area, const CombatParams &params);

static void getCombatArea(const Position &centerPos, const Position &targetPos, const std::unique_ptr<AreaCombat> &area, std::forward_list<std::shared_ptr<Tile>> &list);
static void getCombatArea(const Position &centerPos, const Position &targetPos, const std::unique_ptr<AreaCombat> &area, std::vector<std::shared_ptr<Tile>> &list);

static bool isInPvpZone(std::shared_ptr<Creature> attacker, std::shared_ptr<Creature> target);
static bool isProtected(std::shared_ptr<Player> attacker, std::shared_ptr<Player> target);
Expand Down Expand Up @@ -320,7 +320,7 @@ class Combat {
return area != nullptr;
}
void addCondition(const std::shared_ptr<Condition> condition) {
params.conditionList.emplace_front(condition);
params.conditionList.emplace_back(condition);
}
void setPlayerCombatValues(formulaType_t formulaType, double mina, double minb, double maxa, double maxb);
void postCombatEffects(std::shared_ptr<Creature> caster, const Position &origin, const Position &pos) const {
Expand Down
4 changes: 4 additions & 0 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,10 @@ void Creature::goToFollowCreature_async(std::function<void()> &&onComplete) {

pathfinderRunning.store(true);
g_dispatcher().asyncEvent([self = getCreature()] {
if (!self || self->isRemoved()) {
return;
}

self->goToFollowCreature();
self->pathfinderRunning.store(false);
});
Expand Down
3 changes: 1 addition & 2 deletions src/creatures/monsters/spawns/spawn_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ bool SpawnsMonster::loadFromXML(const std::string &filemonstername) {
continue;
}

spawnMonsterList.emplace_front(centerPos, radius);
SpawnMonster &spawnMonster = spawnMonsterList.front();
SpawnMonster &spawnMonster = spawnMonsterList.emplace_back(centerPos, radius);

for (auto childMonsterNode : spawnMonsterNode.children()) {
if (strcasecmp(childMonsterNode.name(), "monster") == 0) {
Expand Down
27 changes: 21 additions & 6 deletions src/creatures/monsters/spawns/spawn_monster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ class SpawnMonster {
SpawnMonster(const SpawnMonster &) = delete;
SpawnMonster &operator=(const SpawnMonster &) = delete;

// moveable
SpawnMonster(SpawnMonster &&rhs) noexcept :
spawnMonsterMap(std::move(rhs.spawnMonsterMap)),
spawnedMonsterMap(std::move(rhs.spawnedMonsterMap)),
checkSpawnMonsterEvent(rhs.checkSpawnMonsterEvent), centerPos(rhs.centerPos), radius(rhs.radius), interval(rhs.interval) { }

SpawnMonster &operator=(SpawnMonster &&rhs) noexcept {
if (this != &rhs) {
spawnMonsterMap = std::move(rhs.spawnMonsterMap);
spawnedMonsterMap = std::move(rhs.spawnedMonsterMap);

checkSpawnMonsterEvent = rhs.checkSpawnMonsterEvent;
centerPos = rhs.centerPos;
radius = rhs.radius;
interval = rhs.interval;
}
return *this;
}

bool addMonster(const std::string &name, const Position &pos, Direction dir, uint32_t interval, uint32_t weight = 1);
void removeMonster(std::shared_ptr<Monster> monster);
void removeMonsters();
Expand Down Expand Up @@ -83,23 +102,19 @@ class SpawnsMonster {
bool loadFromXML(const std::string &filemonstername);
void startup();
void clear();
SpawnMonster &addSpawnMonster(const Position &pos, int32_t radius) {
spawnMonsterList.emplace_front(pos, radius);
return spawnMonsterList.front();
}

bool isStarted() const {
return started;
}
bool isLoaded() const {
return loaded;
}
std::forward_list<SpawnMonster> &getspawnMonsterList() {
std::vector<SpawnMonster> &getspawnMonsterList() {
return spawnMonsterList;
}

private:
std::forward_list<SpawnMonster> spawnMonsterList;
std::vector<SpawnMonster> spawnMonsterList;
std::string filemonstername;
bool loaded = false;
bool started = false;
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/npcs/spawns/spawn_npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool SpawnsNpc::loadFromXml(const std::string &fileNpcName) {
continue;
}

const auto &spawnNpc = spawnNpcList.emplace_front(std::make_shared<SpawnNpc>(centerPos, radius));
const auto &spawnNpc = spawnNpcList.emplace_back(std::make_shared<SpawnNpc>(centerPos, radius));

for (auto childNode : spawnNode.children()) {
if (strcasecmp(childNode.name(), "npc") == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/npcs/spawns/spawn_npc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ class SpawnsNpc {
return fileName = std::move(setName);
}

std::forward_list<std::shared_ptr<SpawnNpc>> &getSpawnNpcList() {
std::vector<std::shared_ptr<SpawnNpc>> &getSpawnNpcList() {
return spawnNpcList;
}

private:
std::forward_list<std::shared_ptr<SpawnNpc>> spawnNpcList;
std::vector<std::shared_ptr<SpawnNpc>> spawnNpcList;
std::string fileName;
bool loaded = false;
bool started = false;
Expand Down
20 changes: 11 additions & 9 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5289,12 +5289,12 @@ double Player::getLostPercent() const {

void Player::learnInstantSpell(const std::string &spellName) {
if (!hasLearnedInstantSpell(spellName)) {
learnedInstantSpellList.push_front(spellName);
learnedInstantSpellList.emplace_back(spellName);
}
}

void Player::forgetInstantSpell(const std::string &spellName) {
learnedInstantSpellList.remove(spellName);
std::erase(learnedInstantSpellList, spellName);
}

bool Player::hasLearnedInstantSpell(const std::string &spellName) const {
Expand Down Expand Up @@ -5700,12 +5700,12 @@ bool Player::addPartyInvitation(std::shared_ptr<Party> newParty) {
return false;
}

invitePartyList.push_front(newParty);
invitePartyList.emplace_back(newParty);
return true;
}

void Player::removePartyInvitation(std::shared_ptr<Party> remParty) {
invitePartyList.remove(remParty);
std::erase(invitePartyList, remParty);
}

void Player::clearPartyInvitations() {
Expand Down Expand Up @@ -6124,15 +6124,15 @@ bool Player::hasModalWindowOpen(uint32_t modalWindowId) const {
}

void Player::onModalWindowHandled(uint32_t modalWindowId) {
modalWindows.remove(modalWindowId);
std::erase(modalWindows, modalWindowId);
}

void Player::sendModalWindow(const ModalWindow &modalWindow) {
if (!client) {
return;
}

modalWindows.push_front(modalWindow.id);
modalWindows.emplace_back(modalWindow.id);
client->sendModalWindow(modalWindow);
}

Expand Down Expand Up @@ -6251,8 +6251,10 @@ size_t Player::getMaxDepotItems() const {
return g_configManager().getNumber(FREE_DEPOT_LIMIT, __FUNCTION__);
}

std::forward_list<std::shared_ptr<Condition>> Player::getMuteConditions() const {
std::forward_list<std::shared_ptr<Condition>> muteConditions;
std::vector<std::shared_ptr<Condition>> Player::getMuteConditions() const {
std::vector<std::shared_ptr<Condition>> muteConditions;
muteConditions.reserve(conditions.size());

for (const std::shared_ptr<Condition> &condition : conditions) {
if (condition->getTicks() <= 0) {
continue;
Expand All @@ -6263,7 +6265,7 @@ std::forward_list<std::shared_ptr<Condition>> Player::getMuteConditions() const
continue;
}

muteConditions.push_front(condition);
muteConditions.emplace_back(condition);
}
return muteConditions;
}
Expand Down
10 changes: 5 additions & 5 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
static uint32_t playerFirstID;
static uint32_t playerLastID;

std::forward_list<std::shared_ptr<Condition>> getMuteConditions() const;
std::vector<std::shared_ptr<Condition>> getMuteConditions() const;

void checkTradeState(std::shared_ptr<Item> item);
bool hasCapacity(std::shared_ptr<Item> item, uint32_t count) const;
Expand Down Expand Up @@ -2760,11 +2760,11 @@ class Player final : public Creature, public Cylinder, public Bankable {

GuildWarVector guildWarVector;

std::forward_list<std::shared_ptr<Party>> invitePartyList;
std::forward_list<uint32_t> modalWindows;
std::forward_list<std::string> learnedInstantSpellList;
std::vector<std::shared_ptr<Party>> invitePartyList;
std::vector<uint32_t> modalWindows;
std::vector<std::string> learnedInstantSpellList;
// TODO: This variable is only temporarily used when logging in, get rid of it somehow.
std::forward_list<std::shared_ptr<Condition>> storedConditionList;
std::vector<std::shared_ptr<Condition>> storedConditionList;

std::unordered_set<std::shared_ptr<MonsterType>> m_bestiaryMonsterTracker;
std::unordered_set<std::shared_ptr<MonsterType>> m_bosstiaryMonsterTracker;
Expand Down
Loading

0 comments on commit 3e02ced

Please sign in to comment.