Skip to content

Commit

Permalink
feat: take screenshot (#2116)
Browse files Browse the repository at this point in the history
  • Loading branch information
luanluciano93 committed Jul 8, 2024
1 parent 9825f4c commit 9490111
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Before [creating a pull request](https://github.com/opentibiabr/canary/pulls) pl
* our crew (majesty, gpedro, eduardo dantas, foot)
* [our contributors](https://github.com/opentibiabr/canary/graphs/contributors)
* [fear lucien](https://github.com/FearLucien)
* [cjaker](https://github.com/Eternal-Scripts)
* [cjaker](https://github.com/Cjaker)
* [slavidodo](https://github.com/slavidodo)
* [mignari and our awesome tools](https://github.com/ottools)
* [mattyx14/otxserver](https://github.com/mattyx14/otxserver) and contributors
Expand Down
7 changes: 7 additions & 0 deletions data-canary/scripts/creaturescripts/player_death.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ function playerDeath.onDeath(player, corpse, killer, mostDamageKiller, unjustifi
mostDamageName = "field item"
end

player:takeScreenshot(byPlayer and SCREENSHOT_TYPE_DEATHPVP or SCREENSHOT_TYPE_DEATHPVE)

if mostDamageKiller and mostDamageKiller:isPlayer() and killer ~= mostDamageKiller then
mostDamageKiller:takeScreenshot(SCREENSHOT_TYPE_PLAYERKILL)
end

local playerGuid = player:getGuid()
db.query(
"INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`) VALUES ("
Expand Down Expand Up @@ -83,6 +89,7 @@ function playerDeath.onDeath(player, corpse, killer, mostDamageKiller, unjustifi
end

if byPlayer == 1 then
killer:takeScreenshot(SCREENSHOT_TYPE_PLAYERKILL)
local targetGuild = player:getGuild()
targetGuild = targetGuild and targetGuild:getId() or 0
if targetGuild ~= 0 then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function rapierQuest.onUse(player, item, fromPosition, target, toPosition, isHot
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a rapier.")
player:addItem(rewardId, 1)
player:questKV("rapier"):set("completed", true)
player:takeScreenshot(SCREENSHOT_TYPE_TREASUREFOUND)
return true
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ function playerDeath.onDeath(player, corpse, killer, mostDamageKiller, unjustifi
mostDamageName = "field item"
end

player:takeScreenshot(byPlayer and SCREENSHOT_TYPE_DEATHPVP or SCREENSHOT_TYPE_DEATHPVE)

if mostDamageKiller and mostDamageKiller:isPlayer() then
mostDamageKiller:takeScreenshot(SCREENSHOT_TYPE_PLAYERKILL)
end

local playerGuid = player:getGuid()
db.query(
"INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`) VALUES ("
Expand Down Expand Up @@ -83,6 +89,7 @@ function playerDeath.onDeath(player, corpse, killer, mostDamageKiller, unjustifi
end

if byPlayer == 1 then
killer:takeScreenshot(SCREENSHOT_TYPE_PLAYERKILL)
local targetGuild = player:getGuild()
local targetGuildId = targetGuild and targetGuild:getId() or 0
if targetGuildId ~= 0 then
Expand Down
3 changes: 3 additions & 0 deletions data/scripts/creaturescripts/monster/boss_lever_death.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ function onBossDeath.onDeath(creature)
zn:removePlayers()
end, bossLever.timeAfterKill * 1000, zone)
end
onDeathForDamagingPlayers(creature, function(creature, player)
player:takeScreenshot(SCREENSHOT_TYPE_BOSSDEFEATED)
end)
return true
end

Expand Down
14 changes: 14 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,11 @@ void Player::addSkillAdvance(skills_t skill, uint64_t count) {
std::ostringstream ss;
ss << "You advanced to " << getSkillName(skill) << " level " << skills[skill].level << '.';
sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str());
if (skill == SKILL_LEVEL) {
sendTakeScreenshot(SCREENSHOT_TYPE_LEVELUP);
} else {
sendTakeScreenshot(SCREENSHOT_TYPE_SKILLUP);
}

g_creatureEvents().playerAdvance(static_self_cast<Player>(), skill, (skills[skill].level - 1), skills[skill].level);

Expand Down Expand Up @@ -2325,8 +2330,10 @@ void Player::addManaSpent(uint64_t amount) {
std::ostringstream ss;
ss << "You advanced to magic level " << magLevel << '.';
sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str());
sendTakeScreenshot(SCREENSHOT_TYPE_SKILLUP);

g_creatureEvents().playerAdvance(static_self_cast<Player>(), SKILL_MAGLEVEL, magLevel - 1, magLevel);
sendTakeScreenshot(SCREENSHOT_TYPE_SKILLUP);

sendUpdateStats = true;
currReqMana = nextReqMana;
Expand Down Expand Up @@ -2464,6 +2471,7 @@ void Player::addExperience(std::shared_ptr<Creature> target, uint64_t exp, bool
std::ostringstream ss;
ss << "You advanced from Level " << prevLevel << " to Level " << level << '.';
sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str());
sendTakeScreenshot(SCREENSHOT_TYPE_LEVELUP);
}

if (nextLevelExp > currLevelExp) {
Expand Down Expand Up @@ -6010,6 +6018,7 @@ bool Player::addOfflineTrainingTries(skills_t skill, uint64_t tries) {
std::ostringstream ss;
ss << "You advanced to magic level " << magLevel << '.';
sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str());
sendTakeScreenshot(SCREENSHOT_TYPE_SKILLUP);
}

uint8_t newPercent;
Expand Down Expand Up @@ -6066,6 +6075,11 @@ bool Player::addOfflineTrainingTries(skills_t skill, uint64_t tries) {
std::ostringstream ss;
ss << "You advanced to " << getSkillName(skill) << " level " << skills[skill].level << '.';
sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str());
if (skill == SKILL_LEVEL) {
sendTakeScreenshot(SCREENSHOT_TYPE_LEVELUP);
} else {
sendTakeScreenshot(SCREENSHOT_TYPE_SKILLUP);
}
}

uint8_t newPercent;
Expand Down
6 changes: 6 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,12 @@ class Player final : public Creature, public Cylinder, public Bankable {
}
}

void sendTakeScreenshot(Screenshot_t screenshotType) {
if (client) {
client->sendTakeScreenshot(screenshotType);
}
}

void onThink(uint32_t interval) override;

void postAddNotification(std::shared_ptr<Thing> thing, std::shared_ptr<Cylinder> oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override;
Expand Down
14 changes: 14 additions & 0 deletions src/lua/functions/core/game/lua_enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@ void LuaEnums::initOthersEnums(lua_State* L) {
registerEnum(L, WEAPON_WAND);
registerEnum(L, WEAPON_AMMO);
registerEnum(L, WEAPON_MISSILE);

registerEnum(L, SCREENSHOT_TYPE_NONE);
registerEnum(L, SCREENSHOT_TYPE_ACHIEVEMENT);
registerEnum(L, SCREENSHOT_TYPE_BESTIARYENTRYCOMPLETED);
registerEnum(L, SCREENSHOT_TYPE_BESTIARYENTRYUNLOCKED);
registerEnum(L, SCREENSHOT_TYPE_BOSSDEFEATED);
registerEnum(L, SCREENSHOT_TYPE_DEATHPVE);
registerEnum(L, SCREENSHOT_TYPE_DEATHPVP);
registerEnum(L, SCREENSHOT_TYPE_LEVELUP);
registerEnum(L, SCREENSHOT_TYPE_PLAYERKILLASSIST);
registerEnum(L, SCREENSHOT_TYPE_PLAYERKILL);
registerEnum(L, SCREENSHOT_TYPE_PLAYERATTACKING);
registerEnum(L, SCREENSHOT_TYPE_TREASUREFOUND);
registerEnum(L, SCREENSHOT_TYPE_SKILLUP);
}

void LuaEnums::initAccountEnums(lua_State* L) {
Expand Down
15 changes: 15 additions & 0 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4223,6 +4223,7 @@ int PlayerFunctions::luaPlayerAddAchievement(lua_State* L) {
achievementId = g_game().getAchievementByName(getString(L, 2)).id;
}

player->sendTakeScreenshot(SCREENSHOT_TYPE_ACHIEVEMENT);
pushBoolean(L, player->achiev()->add(achievementId, getBoolean(L, 3, true)));
return 1;
}
Expand Down Expand Up @@ -4378,3 +4379,17 @@ int PlayerFunctions::luaPlayerCreateTransactionSummary(lua_State* L) {
pushBoolean(L, true);
return 1;
}

int PlayerFunctions::luaPlayerTakeScreenshot(lua_State* L) {
// player:takeScreenshot(screenshotType)
const auto &player = getUserdataShared<Player>(L, 1);
if (!player) {
lua_pushnil(L);
return 1;
}

auto screenshotType = getNumber<Screenshot_t>(L, 2);
player->sendTakeScreenshot(screenshotType);
pushBoolean(L, true);
return 1;
}
4 changes: 4 additions & 0 deletions src/lua/functions/creatures/player/player_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ class PlayerFunctions final : LuaScriptInterface {
// Store Summary
registerMethod(L, "Player", "createTransactionSummary", PlayerFunctions::luaPlayerCreateTransactionSummary);

registerMethod(L, "Player", "takeScreenshot", PlayerFunctions::luaPlayerTakeScreenshot);

GroupFunctions::init(L);
GuildFunctions::init(L);
MountFunctions::init(L);
Expand Down Expand Up @@ -737,5 +739,7 @@ class PlayerFunctions final : LuaScriptInterface {

static int luaPlayerCreateTransactionSummary(lua_State* L);

static int luaPlayerTakeScreenshot(lua_State* L);

friend class CreatureFunctions;
};
11 changes: 11 additions & 0 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9156,3 +9156,14 @@ void ProtocolGame::sendHotkeyPreset() {
writeToOutputBuffer(msg);
}
}

void ProtocolGame::sendTakeScreenshot(Screenshot_t screenshotType) {
if (screenshotType == SCREENSHOT_TYPE_NONE || oldProtocol) {
return;
}

NetworkMessage msg;
msg.addByte(0x75);
msg.addByte(screenshotType);
writeToOutputBuffer(msg);
}
1 change: 1 addition & 0 deletions src/server/network/protocol/protocolgame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ class ProtocolGame final : public Protocol {
void sendDoubleSoundEffect(const Position &pos, SoundEffect_t mainSoundId, SourceEffect_t mainSource, SoundEffect_t secondarySoundId, SourceEffect_t secondarySource);

void sendHotkeyPreset();
void sendTakeScreenshot(Screenshot_t screenshotType);
void sendDisableLoginMusic();

uint8_t m_playerDeathTime = 0;
Expand Down
16 changes: 16 additions & 0 deletions src/utils/utils_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,19 @@ enum Concoction_t : uint16_t {
DeathAmplification = 36741,
PhysicalAmplification = 36742,
};

enum Screenshot_t : uint8_t {
SCREENSHOT_TYPE_NONE = 0,
SCREENSHOT_TYPE_ACHIEVEMENT = 1,
SCREENSHOT_TYPE_BESTIARYENTRYCOMPLETED = 2,
SCREENSHOT_TYPE_BESTIARYENTRYUNLOCKED = 3,
SCREENSHOT_TYPE_BOSSDEFEATED = 4,
SCREENSHOT_TYPE_DEATHPVE = 5,
SCREENSHOT_TYPE_DEATHPVP = 6,
SCREENSHOT_TYPE_LEVELUP = 7,
SCREENSHOT_TYPE_PLAYERKILLASSIST = 8,
SCREENSHOT_TYPE_PLAYERKILL = 9,
SCREENSHOT_TYPE_PLAYERATTACKING = 10,
SCREENSHOT_TYPE_TREASUREFOUND = 11,
SCREENSHOT_TYPE_SKILLUP = 12
};

0 comments on commit 9490111

Please sign in to comment.