Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: take screenshot #2116

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c5f4a58
Update player.hpp
luanluciano93 Jan 16, 2024
1d9fcab
Update protocolgame.hpp
luanluciano93 Jan 16, 2024
bf31895
Update protocolgame.cpp
luanluciano93 Jan 16, 2024
74283b6
Update player_functions.cpp
luanluciano93 Jan 16, 2024
89ba528
Update player_functions.hpp
luanluciano93 Jan 16, 2024
e0aa364
Update src/lua/functions/creatures/player/player_functions.cpp
luanluciano93 Jan 17, 2024
c128489
Update src/lua/functions/creatures/player/player_functions.hpp
luanluciano93 Jan 17, 2024
5819b72
Update src/lua/functions/creatures/player/player_functions.hpp
luanluciano93 Jan 17, 2024
221fcdf
Update src/server/network/protocol/protocolgame.cpp
luanluciano93 Jan 17, 2024
ca2b3bc
Code format - (Clang-format)
github-actions[bot] Jan 17, 2024
9393a9f
Merge branch 'main' into take-screenshot
luanluciano93 Jan 18, 2024
8785930
Update protocolgame.cpp
luanluciano93 Jan 18, 2024
34e6175
Code format - (Clang-format)
github-actions[bot] Jan 18, 2024
1053279
Update utils_definitions.hpp
luanluciano93 Jan 18, 2024
f29cd8c
Code format - (Clang-format)
github-actions[bot] Jan 18, 2024
355c2e6
Update lua_enums.cpp
luanluciano93 Jan 18, 2024
216355c
Update utils_definitions.hpp
luanluciano93 Jan 18, 2024
6e11444
Code format - (Clang-format)
github-actions[bot] Jan 18, 2024
6da0ba1
Update player.hpp
luanluciano93 Jan 18, 2024
6d829be
Update player_functions.cpp
luanluciano93 Jan 18, 2024
306ef07
Update protocolgame.cpp
luanluciano93 Jan 18, 2024
6e61601
Update protocolgame.hpp
luanluciano93 Jan 18, 2024
e5a0b4b
Update player_functions.cpp
luanluciano93 Jan 20, 2024
36ff8b6
Update achievements_lib.lua
luanluciano93 Jan 20, 2024
97ea6cf
Merge branch 'main' into take-screenshot
luanluciano93 Jan 31, 2024
fbea9d2
Code format - (Clang-format)
github-actions[bot] Jan 31, 2024
6f53578
Merge remote-tracking branch 'upstream/main' into take-screenshot
luanluciano93 Feb 14, 2024
1471198
Merge remote-tracking branch 'upstream/main' into take-screenshot
luanluciano93 Mar 10, 2024
be2fb77
update
luanluciano93 Mar 10, 2024
0bad989
Code format - (Clang-format)
github-actions[bot] Mar 10, 2024
34e920d
UPDATE
luanluciano93 Mar 10, 2024
d784829
Merge branch 'take-screenshot' of https://github.com/luanluciano93/ca…
luanluciano93 Mar 10, 2024
150dd96
Update player.cpp
luanluciano93 Mar 10, 2024
370b27a
update
luanluciano93 Apr 8, 2024
bb019aa
Merge branch 'main' into take-screenshot
luanluciano93 Apr 8, 2024
4d66d13
update
luanluciano93 Apr 8, 2024
03bac3e
Merge branch 'take-screenshot' of https://github.com/luanluciano93/ca…
luanluciano93 Apr 9, 2024
76b1a33
Update player_functions.hpp
luanluciano93 Apr 10, 2024
1b53945
Update bosslever_death.lua
luanluciano93 Apr 16, 2024
2d51907
Merge branch 'main' into take-screenshot
luanluciano93 Apr 16, 2024
9d562f7
Merge branch 'main' into take-screenshot
luanluciano93 Apr 29, 2024
8951d31
Code format - (Clang-format)
github-actions[bot] Apr 29, 2024
89a3fda
Merge branch 'main' into take-screenshot
luanluciano93 May 9, 2024
8955a5d
Code format - (Clang-format)
github-actions[bot] May 9, 2024
df00cf0
Merge branch 'main' into take-screenshot
luanluciano93 May 14, 2024
6315999
Code format - (Clang-format)
github-actions[bot] May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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
onBossDeath:register()
14 changes: 14 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,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 @@ -2314,8 +2319,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 @@ -2453,6 +2460,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 @@ -6075,6 +6083,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 @@ -6131,6 +6140,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 @@ -1720,6 +1720,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 @@ -4215,6 +4215,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 @@ -4348,3 +4349,17 @@ int PlayerFunctions::luaPlayerSetCurrentTitle(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 @@ -372,6 +372,8 @@ class PlayerFunctions final : LuaScriptInterface {
registerMethod(L, "Player", "getTitles", PlayerFunctions::luaPlayerGetTitles);
registerMethod(L, "Player", "setCurrentTitle", PlayerFunctions::luaPlayerSetCurrentTitle);

registerMethod(L, "Player", "takeScreenshot", PlayerFunctions::luaPlayerTakeScreenshot);
luanluciano93 marked this conversation as resolved.
Show resolved Hide resolved

GroupFunctions::init(L);
GuildFunctions::init(L);
MountFunctions::init(L);
Expand Down Expand Up @@ -732,5 +734,7 @@ class PlayerFunctions final : LuaScriptInterface {
static int luaPlayerGetTitles(lua_State* L);
static int luaPlayerSetCurrentTitle(lua_State* L);

static int luaPlayerTakeScreenshot(lua_State* L);
luanluciano93 marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -8955,3 +8955,14 @@ void ProtocolGame::sendDisableLoginMusic() {
msg.addByte(0x00);
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 @@ -509,6 +509,7 @@ class ProtocolGame final : public Protocol {
void sendSingleSoundEffect(const Position &pos, SoundEffect_t id, SourceEffect_t source);
void sendDoubleSoundEffect(const Position &pos, SoundEffect_t mainSoundId, SourceEffect_t mainSource, SoundEffect_t secondarySoundId, SourceEffect_t secondarySource);

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 @@ -762,3 +762,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
};