Skip to content

Commit

Permalink
Merge branch 'main' into fix/support-outfit-crashs
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored Apr 25, 2024
2 parents 2509fa9 + 0998429 commit d4f237f
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function deathEvent.onDeath(creature, _corpse, _lastHitKiller, mostDamageKiller)
end
end
-- Minotaurs
killCheck(player, targetName, Storage.KillingInTheNameOf.BudrikMinos, 0, tasks.Budrik[1].creatures, nil, Storage.Quest.U8_5.KillingInTheNameOf.MonsterKillCount.MinotaurCount)
killCheck(player, targetName, Storage.KillingInTheNameOf.BudrikMinos, 0, tasks.Budrik[1].creatures, Storage.Quest.U8_5.KillingInTheNameOf.AltKillCount.MinotaurCount, Storage.Quest.U8_5.KillingInTheNameOf.MonsterKillCount.MinotaurCount)
-- Necromancers and Priestesses
killCheck(player, targetName, Storage.KillingInTheNameOf.LugriNecromancers, 0, tasks.Lugri[1].creatures, Storage.Quest.U8_5.KillingInTheNameOf.AltKillCount.NecromancerCount, Storage.Quest.U8_5.KillingInTheNameOf.MonsterKillCount.NecromancerCount)
killCheck(player, targetName, Storage.KillingInTheNameOf.LugriNecromancers, 3, tasks.Lugri[1].creatures, Storage.Quest.U8_5.KillingInTheNameOf.AltKillCount.NecromancerCount, Storage.Quest.U8_5.KillingInTheNameOf.MonsterKillCount.NecromancerCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
function onGetFormulaValues(player, skill, attack, factor)
local distanceSkill = player:getEffectiveSkillLevel(SKILL_DISTANCE)
local min = (player:getLevel() / 5)
local max = (0.09 * factor) * distanceSkill * 37 + (player:getLevel() / 5)
local max = (0.09 * factor) * distanceSkill * attack + (player:getLevel() / 5)
return -min, -max
end

Expand Down
3 changes: 3 additions & 0 deletions data/items/items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53105,6 +53105,9 @@ hands of its owner. Granted by TibiaRoyal.com"/>
<attribute key="showAttributes" value="1"/>
<attribute key="absorbpercentlifedrain" value="5"/>
<attribute key="weight" value="3800"/>
<attribute key="script" value="moveevent">
<attribute key="slot" value="ammo"/>
</attribute>
</item>
<item id="28494" article="a" name="silver chimes">
<attribute key="primarytype" value="shields"/>
Expand Down
15 changes: 13 additions & 2 deletions data/libs/functions/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,38 @@ end

function getTimeInWords(secsParam)
local secs = tonumber(secsParam)
local days = math.floor(secs / (24 * 3600))
secs = secs - (days * 24 * 3600)
local hours, minutes, seconds = getHours(secs), getMinutes(secs), getSeconds(secs)
local timeStr = ""

if days > 0 then
timeStr = days .. (days > 1 and " days" or " day")
end

if hours > 0 then
timeStr = hours .. (hours > 1 and " hours" or " hour")
if timeStr ~= "" then
timeStr = timeStr .. ", "
end

timeStr = timeStr .. hours .. (hours > 1 and " hours" or " hour")
end

if minutes > 0 then
if timeStr ~= "" then
timeStr = timeStr .. ", "
end

timeStr = timeStr .. minutes .. (minutes > 1 and " minutes" or " minute")
end

if seconds > 0 then
if timeStr ~= "" then
timeStr = timeStr .. " and "
end

timeStr = timeStr .. seconds .. (seconds > 1 and " seconds" or " second")
end

return timeStr
end

Expand Down
1 change: 1 addition & 0 deletions data/scripts/eventcallbacks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Event callbacks are available for several categories of game entities, such as `
- `(void)` `playerOnCombat`
- `(void)` `playerOnInventoryUpdate`
- `(bool)` `playerOnRotateItem`
- `(void)` `playerOnWalk`
- `(void)` `monsterOnDropLoot`
- `(void)` `monsterPostDropLoot`
- `(void)` `monsterOnSpawn`
Expand Down
7 changes: 7 additions & 0 deletions data/scripts/runes/destroy_field_rune.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ local fields = { 105, 2118, 2119, 2120, 2121, 2122, 2123, 2124, 2125, 2126, 2132
local rune = Spell("rune")

function rune.onCastSpell(creature, variant, isHotkey)
local inPz = creature:getTile():hasFlag(TILESTATE_PROTECTIONZONE)
if inPz then
creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
creature:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end

local position = Variant.getPosition(variant)
local tile = Tile(position)
local field = tile and tile:getItemByType(ITEM_TYPE_MAGICFIELD)
Expand Down
8 changes: 8 additions & 0 deletions data/scripts/spells/house/kick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ function spell.onCastSpell(player, variant)
local targetPlayer = Player(variant:getString()) or player
local guest = targetPlayer:getTile():getHouse()
local owner = player:getTile():getHouse()

-- Owner kick yourself from house
if targetPlayer == player then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:teleportTo(owner:getExitPosition())
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
return true
end

if not owner:canEditAccessList(GUEST_LIST, player) then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
player:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end

if not owner or not guest or not guest:kickPlayer(player, targetPlayer) then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
player:getPosition():sendMagicEffect(CONST_ME_POFF)
Expand Down
94 changes: 94 additions & 0 deletions data/scripts/talkactions/gm/afk.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
local afk = TalkAction("/afk")

playersAFKs = {}

local function checkIsAFK(id)
for index, item in pairs(playersAFKs) do
if id == item.id then
return { afk = true, index = index }
end
end
return { afk = false }
end

local function showAfkMessage(playerPosition)
local spectators = Game.getSpectators(playerPosition, false, true, 8, 8, 8, 8)
if #spectators > 0 then
for _, spectator in ipairs(spectators) do
spectator:say("AFK !", TALKTYPE_MONSTER_SAY, false, spectator, playerPosition)
end
end
end

function afk.onSay(player, words, param)
if param == "" then
player:sendCancelMessage("You need to specify on/off param.")
return true
end

local id, playerPosition = player:getId(), player:getPosition()
local isAfk = checkIsAFK(id)
if param == "on" then
if isAfk.afk then
player:sendCancelMessage("You are already AFK!")
return true
end

table.insert(playersAFKs, { id = id, position = playerPosition })
if player:isInGhostMode() then
player:setGhostMode(false)
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are now AFK!")
playerPosition:sendMagicEffect(CONST_ME_REDSMOKE)
showAfkMessage(playerPosition)
elseif param == "off" then
if isAfk.afk then
table.remove(playersAFKs, isAfk.index)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are no longer AFK!")
playerPosition:sendMagicEffect(CONST_ME_REDSMOKE)
end
end

return true
end

afk:separator(" ")
afk:groupType("gamemaster")
afk:register()

------------------ AFK Effect Message ------------------
local afkEffect = GlobalEvent("GodAfkEffect")
function afkEffect.onThink(interval)
for _, player in ipairs(playersAFKs) do
showAfkMessage(player.position)
end
return true
end

afkEffect:interval(5000)
afkEffect:register()

------------------ Stop AFK Message when moves ------------------
local callback = EventCallback()
function callback.playerOnWalk(player, creature, creaturePos, toPos)
local isAfk = checkIsAFK(player:getId())
if isAfk.afk then
table.remove(playersAFKs, isAfk.index)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are no longer AFK!")
end
return true
end

callback:register()

------------------ Player Logout ------------------
local godAfkLogout = CreatureEvent("GodAfkLogout")
function godAfkLogout.onLogout(player)
local isAfk = checkIsAFK(player:getId())
if isAfk.afk then
table.remove(playersAFKs, isAfk.index)
end
return true
end

godAfkLogout:register()
7 changes: 6 additions & 1 deletion src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,8 @@ void Player::onWalk(Direction &dir) {
Creature::onWalk(dir);
setNextActionTask(nullptr);
setNextAction(OTSYS_TIME() + getStepDuration(dir));

g_callbacks().executeCallback(EventCallback_t::playerOnWalk, &EventCallback::playerOnWalk, getPlayer(), dir);
}

void Player::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) {
Expand Down Expand Up @@ -2918,6 +2920,7 @@ bool Player::spawn() {
getParent()->postAddNotification(static_self_cast<Player>(), nullptr, 0);
g_game().addCreatureCheck(static_self_cast<Player>());
g_game().addPlayer(static_self_cast<Player>());
static_self_cast<Player>()->onChangeZone(static_self_cast<Player>()->getZoneType());
return true;
}

Expand Down Expand Up @@ -4673,6 +4676,8 @@ void Player::onPlacedCreature() {
removePlayer(true);
}

this->onChangeZone(this->getZoneType());

sendUnjustifiedPoints();
}

Expand Down Expand Up @@ -6692,7 +6697,7 @@ void Player::triggerTranscendance() {
outfit.lookType = getVocation()->getAvatarLookType();
outfitCondition->setOutfit(outfit);
addCondition(outfitCondition);
wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR, OTSYS_TIME() + duration);
wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR_FORGE, OTSYS_TIME() + duration);
g_game().addMagicEffect(getPosition(), CONST_ME_AVATAR_APPEAR);
sendTextMessage(MESSAGE_ATTENTION, "Transcendance was triggered.");
sendSkills();
Expand Down
24 changes: 14 additions & 10 deletions src/creatures/players/wheel/player_wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2410,21 +2410,25 @@ int32_t PlayerWheel::checkBattleHealingAmount() const {
}

int32_t PlayerWheel::checkAvatarSkill(WheelAvatarSkill_t skill) const {
if (skill == WheelAvatarSkill_t::NONE || getOnThinkTimer(WheelOnThink_t::AVATAR) <= OTSYS_TIME()) {
if (skill == WheelAvatarSkill_t::NONE || (getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL) <= OTSYS_TIME() && getOnThinkTimer(WheelOnThink_t::AVATAR_FORGE) <= OTSYS_TIME())) {
return 0;
}

uint8_t stage = 0;
if (getInstant("Avatar of Light")) {
stage = getStage(WheelStage_t::AVATAR_OF_LIGHT);
} else if (getInstant("Avatar of Steel")) {
stage = getStage(WheelStage_t::AVATAR_OF_STEEL);
} else if (getInstant("Avatar of Nature")) {
stage = getStage(WheelStage_t::AVATAR_OF_NATURE);
} else if (getInstant("Avatar of Storm")) {
stage = getStage(WheelStage_t::AVATAR_OF_STORM);
if (getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL) > OTSYS_TIME()) {
if (getInstant("Avatar of Light")) {
stage = getStage(WheelStage_t::AVATAR_OF_LIGHT);
} else if (getInstant("Avatar of Steel")) {
stage = getStage(WheelStage_t::AVATAR_OF_STEEL);
} else if (getInstant("Avatar of Nature")) {
stage = getStage(WheelStage_t::AVATAR_OF_NATURE);
} else if (getInstant("Avatar of Storm")) {
stage = getStage(WheelStage_t::AVATAR_OF_STORM);
} else {
return 0;
}
} else {
return 0;
stage = 3;
}

if (skill == WheelAvatarSkill_t::DAMAGE_REDUCTION) {
Expand Down
5 changes: 3 additions & 2 deletions src/creatures/players/wheel/wheel_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ enum class WheelOnThink_t : uint8_t {
FOCUS_MASTERY = 4,
GIFT_OF_LIFE = 5,
DIVINE_EMPOWERMENT = 6,
AVATAR = 7,
AVATAR_SPELL = 7,
AVATAR_FORGE = 8,

TOTAL_COUNT = 8
TOTAL_COUNT = 9
};

enum class WheelStat_t : uint8_t {
Expand Down
1 change: 1 addition & 0 deletions src/lua/callbacks/callbacks_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum class EventCallback_t : uint16_t {
playerOnCombat,
playerOnInventoryUpdate,
playerOnRotateItem,
playerOnWalk,
// Monster
monsterOnDropLoot,
monsterPostDropLoot,
Expand Down
23 changes: 23 additions & 0 deletions src/lua/callbacks/event_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,29 @@ bool EventCallback::playerOnRotateItem(std::shared_ptr<Player> player, std::shar
return getScriptInterface()->callFunction(3);
}

void EventCallback::playerOnWalk(std::shared_ptr<Player> player, Direction &dir) const {
if (!getScriptInterface()->reserveScriptEnv()) {
g_logger().error("[EventCallback::eventOnWalk - "
"Player {}] "
"Call stack overflow. Too many lua script calls being nested.",
player->getName());
return;
}

ScriptEnvironment* scriptEnvironment = getScriptInterface()->getScriptEnv();
scriptEnvironment->setScriptId(getScriptId(), getScriptInterface());

lua_State* L = getScriptInterface()->getLuaState();
getScriptInterface()->pushFunction(getScriptId());

LuaScriptInterface::pushUserdata<Player>(L, player);
LuaScriptInterface::setMetatable(L, -1, "Player");

lua_pushnumber(L, dir);

getScriptInterface()->callVoidFunction(2);
}

void EventCallback::playerOnStorageUpdate(std::shared_ptr<Player> player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const {
if (!getScriptInterface()->reserveScriptEnv()) {
g_logger().error("[EventCallback::eventOnStorageUpdate - "
Expand Down
1 change: 1 addition & 0 deletions src/lua/callbacks/event_callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class EventCallback : public Script {
void playerOnCombat(std::shared_ptr<Player> player, std::shared_ptr<Creature> target, std::shared_ptr<Item> item, CombatDamage &damage) const;
void playerOnInventoryUpdate(std::shared_ptr<Player> player, std::shared_ptr<Item> item, Slots_t slot, bool equip) const;
bool playerOnRotateItem(std::shared_ptr<Player> player, std::shared_ptr<Item> item, const Position &position) const;
void playerOnWalk(std::shared_ptr<Player> player, Direction &dir) const;

// Monster
void monsterOnDropLoot(std::shared_ptr<Monster> monster, std::shared_ptr<Container> corpse) const;
Expand Down
4 changes: 2 additions & 2 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3997,9 +3997,9 @@ int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) {
}

if (lua_gettop(L) == 1) {
lua_pushnumber(L, (lua_Number)player->wheel()->getOnThinkTimer(WheelOnThink_t::AVATAR));
lua_pushnumber(L, (lua_Number)player->wheel()->getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL));
} else {
player->wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR, getNumber<int64_t>(L, 2));
player->wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR_SPELL, getNumber<int64_t>(L, 2));
pushBoolean(L, true);
}
return 1;
Expand Down

0 comments on commit d4f237f

Please sign in to comment.