Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyx14 committed Jul 8, 2024
1 parent 6410b20 commit a81413e
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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 @@ -79,6 +85,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
2 changes: 1 addition & 1 deletion src/lua/functions/core/game/global_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int GlobalFunctions::luaGetWorldLight(lua_State* L) {

int GlobalFunctions::luaGetWorldUpTime(lua_State* L) {
// getWorldUpTime()
uint64_t uptime = (OTSYS_TIME() - ProtocolStatus::start) / 1000;
uint64_t uptime = (OTSYS_TIME(true) - ProtocolStatus::start) / 1000;
lua_pushnumber(L, uptime);
return 1;
}
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
2 changes: 1 addition & 1 deletion src/server/network/protocol/protocolstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ std::string ProtocolStatus::SERVER_VERSION = "6";
std::string ProtocolStatus::SERVER_DEVELOPERS = "OpenTibiaBR Organization. Based on: Canary (3.1.2). And data edited by: Mattyx14";

std::map<uint32_t, int64_t> ProtocolStatus::ipConnectMap;
const uint64_t ProtocolStatus::start = OTSYS_TIME();
const uint64_t ProtocolStatus::start = OTSYS_TIME(true);

void ProtocolStatus::onRecvFirstMessage(NetworkMessage &msg) {
uint32_t ip = getIP();
Expand Down
5 changes: 4 additions & 1 deletion src/utils/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,10 @@ void UPDATE_OTSYS_TIME() {
OTSYSTIME = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}

int64_t OTSYS_TIME() {
int64_t OTSYS_TIME(bool useTime) {
if (useTime) {
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
return OTSYSTIME;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool isCaskItem(uint16_t itemId);
std::string getObjectCategoryName(ObjectCategory_t category);
bool isValidObjectCategory(ObjectCategory_t category);

int64_t OTSYS_TIME();
int64_t OTSYS_TIME(bool useTime = false);
void UPDATE_OTSYS_TIME();

SpellGroup_t stringToSpellGroup(const std::string &value);
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 a81413e

Please sign in to comment.