Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyx14 committed Apr 26, 2024
1 parent c19103a commit ebae39d
Show file tree
Hide file tree
Showing 23 changed files with 261 additions and 122 deletions.
2 changes: 1 addition & 1 deletion data-otxserver/scripts/weapons/scripts/diamond_arrow.lua
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
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
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()
1 change: 1 addition & 0 deletions data/scripts/talkactions/god/reload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ local reloadTypes = {
["scripts"] = RELOAD_TYPE_SCRIPTS,
["stage"] = RELOAD_TYPE_CORE,
["stages"] = RELOAD_TYPE_CORE,
["vocations"] = RELOAD_TYPE_VOCATIONS,
}

local reload = TalkAction("/reload")
Expand Down
1 change: 1 addition & 0 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,5 @@ void CanaryServer::shutdown() {
g_dispatcher().shutdown();
g_metrics().shutdown();
inject<ThreadPool>().shutdown();
std::exit(0);
}
61 changes: 24 additions & 37 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Player::~Player() {
}

bool Player::setVocation(uint16_t vocId) {
Vocation* voc = g_vocations().getVocation(vocId);
const auto &voc = g_vocations().getVocation(vocId);
if (!voc) {
return false;
}
Expand Down 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 @@ -2393,7 +2395,7 @@ void Player::addExperience(std::shared_ptr<Creature> target, uint64_t exp, bool
++level;
// Player stats gain for vocations level <= 8
if (vocation->getId() != VOCATION_NONE && level <= 8) {
const Vocation* noneVocation = g_vocations().getVocation(VOCATION_NONE);
const auto &noneVocation = g_vocations().getVocation(VOCATION_NONE);
healthMax += noneVocation->getHPGain();
health += noneVocation->getHPGain();
manaMax += noneVocation->getManaGain();
Expand Down Expand Up @@ -2488,7 +2490,7 @@ void Player::removeExperience(uint64_t exp, bool sendText /* = false*/) {
--level;
// Player stats loss for vocations level <= 8
if (vocation->getId() != VOCATION_NONE && level <= 8) {
const Vocation* noneVocation = g_vocations().getVocation(VOCATION_NONE);
const auto &noneVocation = g_vocations().getVocation(VOCATION_NONE);
healthMax = std::max<int32_t>(0, healthMax - noneVocation->getHPGain());
manaMax = std::max<int32_t>(0, manaMax - noneVocation->getManaGain());
capacity = std::max<int32_t>(0, capacity - noneVocation->getCapGain());
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 @@ -6905,8 +6910,9 @@ std::shared_ptr<Item> Player::getItemFromDepotSearch(uint16_t itemId, const Posi
return nullptr;
}

std::pair<std::vector<std::shared_ptr<Item>>, std::map<uint16_t, std::map<uint8_t, uint32_t>>> Player::requestLockerItems(std::shared_ptr<DepotLocker> depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const {
if (depotLocker == nullptr) {
std::pair<std::vector<std::shared_ptr<Item>>, std::map<uint16_t, std::map<uint8_t, uint32_t>>>
Player::requestLockerItems(std::shared_ptr<DepotLocker> depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const {
if (!depotLocker) {
g_logger().error("{} - Depot locker is nullptr", __FUNCTION__);
return {};
}
Expand All @@ -6915,62 +6921,43 @@ std::pair<std::vector<std::shared_ptr<Item>>, std::map<uint16_t, std::map<uint8_
std::vector<std::shared_ptr<Item>> itemVector;
std::vector<std::shared_ptr<Container>> containers { depotLocker };

size_t size = 0;
do {
std::shared_ptr<Container> container = containers[size];
size++;
for (size_t i = 0; i < containers.size(); ++i) {
std::shared_ptr<Container> container = containers[i];

for (std::shared_ptr<Item> item : container->getItemList()) {
for (const auto &item : container->getItemList()) {
std::shared_ptr<Container> lockerContainers = item->getContainer();
if (lockerContainers && !lockerContainers->empty()) {
containers.push_back(lockerContainers);
continue;
}

if (item->isStoreItem()) {
continue;
}

const ItemType &itemType = Item::items[item->getID()];
if (itemType.wareId == 0) {
if (item->isStoreItem() || itemType.wareId == 0) {
continue;
}

if (lockerContainers && (!itemType.isContainer() || lockerContainers->capacity() != itemType.maxItems)) {
continue;
}

if (!item->hasMarketAttributes()) {
continue;
}

if (!sendToClient && item->getTier() != tier) {
if (!item->hasMarketAttributes() || (!sendToClient && item->getTier() != tier)) {
continue;
}

(lockerItems[itemType.wareId])[item->getTier()] += Item::countByType(item, -1);
lockerItems[itemType.wareId][item->getTier()] += Item::countByType(item, -1);
itemVector.push_back(item);
}
} while (size < containers.size());
StashItemList stashToSend = getStashItems();
uint32_t countSize = 0;
for (auto [itemId, itemCount] : stashToSend) {
countSize += itemCount;
}

do {
for (auto [itemId, itemCount] : stashToSend) {
const ItemType &itemType = Item::items[itemId];
if (itemType.wareId == 0) {
continue;
}

countSize = countSize - itemCount;
(lockerItems[itemType.wareId])[0] += itemCount;
StashItemList stashToSend = getStashItems();
for (const auto &[itemId, itemCount] : stashToSend) {
const ItemType &itemType = Item::items[itemId];
if (itemType.wareId != 0) {
lockerItems[itemType.wareId][0] += itemCount;
}
} while (countSize > 0);
}

return std::make_pair(itemVector, lockerItems);
return { itemVector, lockerItems };
}

std::pair<std::vector<std::shared_ptr<Item>>, uint16_t> Player::getLockerItemsAndCountById(const std::shared_ptr<DepotLocker> &depotLocker, uint8_t tier, uint16_t itemId) {
Expand Down
6 changes: 3 additions & 3 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class Player final : public Creature, public Cylinder, public Bankable {

bool isBossOnBosstiaryTracker(const std::shared_ptr<MonsterType> &monsterType) const;

Vocation* getVocation() const {
std::shared_ptr<Vocation> getVocation() const {
return vocation;
}

Expand Down Expand Up @@ -2522,7 +2522,7 @@ class Player final : public Creature, public Cylinder, public Bankable {

// Concoction system
void updateConcoction(uint16_t itemId, uint16_t timeLeft) {
if (timeLeft < 0) {
if (timeLeft == 0) {
activeConcoctions.erase(itemId);
} else {
activeConcoctions[itemId] = timeLeft;
Expand Down Expand Up @@ -2773,7 +2773,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
ProtocolGame_ptr client;
std::shared_ptr<Task> walkTask;
std::shared_ptr<Town> town;
Vocation* vocation = nullptr;
std::shared_ptr<Vocation> vocation = nullptr;
std::shared_ptr<RewardChest> rewardChest = nullptr;

uint32_t inventoryWeight = 0;
Expand Down
Loading

0 comments on commit ebae39d

Please sign in to comment.