From 538c5b86873a4c57e1eb37f0c81c2a7b4552ebc1 Mon Sep 17 00:00:00 2001 From: Aokromes Date: Wed, 28 Nov 2018 16:44:28 +0100 Subject: Core/GameEvent: weekend xp rate (#17782) * Core/GameEvent: weekend xp rate by kline * Update to recent code * compile fix try things of copy and paste 4 years old code xd * more code update * forgot to change this * Update worldserver.conf.dist * Added function to calculate weekend event xp rates By greenbagels * Cleaning using scripts * Implement daymask and rename variables etc. * Rename script file weekend -> boosted * Update src/server/game/World/World.cpp Co-Authored-By: Aokromes * Fix xp multiplier not applying to quest rewards * Disable xp boost script when no boosted days selected --- src/server/scripts/World/boosted_xp.cpp | 51 ++++++++++++++++++++++++ src/server/scripts/World/world_script_loader.cpp | 3 ++ 2 files changed, 54 insertions(+) create mode 100644 src/server/scripts/World/boosted_xp.cpp (limited to 'src/server/scripts') diff --git a/src/server/scripts/World/boosted_xp.cpp b/src/server/scripts/World/boosted_xp.cpp new file mode 100644 index 00000000000..df03dab4a81 --- /dev/null +++ b/src/server/scripts/World/boosted_xp.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2008-2017 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "GameTime.h" +#include "ScriptMgr.h" +#include "World.h" + +#include + +namespace +{ + bool IsXPBoostActive() + { + auto now = boost::posix_time::to_tm(boost::posix_time::from_time_t(GameTime::GetGameTime())); + uint32 weekdayMaskBoosted = sWorld->getIntConfig(CONFIG_XP_BOOST_DAYMASK); + uint32 weekdayMask = (1 << now.tm_wday); + bool currentDayBoosted = (weekdayMask & weekdayMaskBoosted) != 0; + return currentDayBoosted; + } +} + +class xp_boost_PlayerScript : public PlayerScript +{ +public: + xp_boost_PlayerScript() : PlayerScript("xp_boost_PlayerScript") { } + + void OnGiveXP(Player* /*player*/, uint32& amount, Unit* /*unit*/) override + { + if (IsXPBoostActive()) + amount *= sWorld->getRate(RATE_XP_BOOST); + } +}; + +void AddSC_xp_boost() +{ + new xp_boost_PlayerScript(); +} diff --git a/src/server/scripts/World/world_script_loader.cpp b/src/server/scripts/World/world_script_loader.cpp index 53c19bbc3a1..352f62265c2 100644 --- a/src/server/scripts/World/world_script_loader.cpp +++ b/src/server/scripts/World/world_script_loader.cpp @@ -31,6 +31,7 @@ void AddSC_npcs_special(); void AddSC_achievement_scripts(); void AddSC_action_ip_logger(); void AddSC_duel_reset(); +void AddSC_xp_boost(); // player void AddSC_chat_log(); void AddSC_action_ip_logger(); @@ -56,4 +57,6 @@ void AddWorldScripts() if (sWorld->getBoolConfig(CONFIG_IP_BASED_ACTION_LOGGING)) AddSC_action_ip_logger(); // location: scripts\World\action_ip_logger.cpp AddSC_duel_reset(); + if (sWorld->getIntConfig(CONFIG_XP_BOOST_DAYMASK) != 0) + AddSC_xp_boost(); } -- cgit v1.2.3