Skip to content

Commit

Permalink
mod-custom-deserter
Browse files Browse the repository at this point in the history
  • Loading branch information
Nefertumm committed Oct 7, 2024
1 parent 2cb4023 commit 7a9a0ce
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 59 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ![logo](https://raw.githubusercontent.com/azerothcore/azerothcore.github.io/master/images/logo-github.png) AzerothCore

## mod-custom-deserter

For each time a player abandons a bg, it will give them a progressive deserter time.
The duration of the deserter is given by the following formula:
duration = base_duration + deserter_count * base_duration

Written by Nefertumm
https://github.com/Nefertumm
29 changes: 29 additions & 0 deletions conf/mod-custom-deserter.conf.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPLv2+ license
* Written by Nefertumm : https://github.com/Nefertumm
*/


[worldserver]

########################################
# Custom Deserter Module Configuration file
########################################
#
# DeserterBaseDuration
# Description: Base duration for the deserter, in minutes.
# Default: 30 - 30 minutes
#
#

DeserterBaseDuration = 30

########################################
#
# DeserterDays
# Description: From how many days the script will start to count the amount of deserters the player had. Leave it at 0 so it counts all of them independently of time.
# Default: 7 days
#
#

DeserterDays = 7
17 changes: 0 additions & 17 deletions conf/my_custom.conf.dist

This file was deleted.

Empty file removed data/sql/db-auth/base/.gitkeep
Empty file.
Empty file removed data/sql/db-auth/updates/.gitkeep
Empty file.
11 changes: 11 additions & 0 deletions data/sql/db-characters/base/mod-custom-deserter.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
DROP TABLE IF EXISTS `custom_deserter`;

CREATE TABLE IF NOT EXISTS `custom_deserter`
(
`ID` INT unsigned AUTO_INCREMENT,
`Guid` INT unsigned NOT NULL,
`Time` INT unsigned NOT NULL,
`Duration` INT NOT NULL,
CONSTRAINT `PK_custom_deserter` PRIMARY KEY(`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Empty file removed data/sql/db-world/base/.gitkeep
Empty file.
4 changes: 0 additions & 4 deletions data/sql/db-world/base/skeleton_module_acore_string.sql

This file was deleted.

Empty file removed data/sql/db-world/updates/.gitkeep
Empty file.
10 changes: 6 additions & 4 deletions src/MP_loader.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPLv2+ license
* Written by Nefertumm : https://github.com/Nefertumm
*/


// From SC
void AddMyPlayerScripts();
void AddCustomDeserterScripts();

// Add all
// cf. the naming convention https://github.com/azerothcore/azerothcore-wotlk/blob/master/doc/changelog/master.md#how-to-upgrade-4
// additionally replace all '-' in the module folder name with '_' here
void Addskeleton_moduleScripts()
void Addmod_custom_deserterScripts()
{
AddMyPlayerScripts();
AddCustomDeserterScripts();
}

34 changes: 0 additions & 34 deletions src/MyPlayer.cpp

This file was deleted.

76 changes: 76 additions & 0 deletions src/custom_deserter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPLv2+ license
* Written by Nefertumm : https://github.com/Nefertumm
*/

#include "ScriptMgr.h"
#include "CharacterDatabase.h"
#include "GameTime.h"
#include "Player.h"
#include "Config.h"
#include "Chat.h"

enum SpellIds
{
SPELL_DESERTER = 26013
};

class CustomDeserter : public BGScript
{
public:
CustomDeserter() : BGScript("CustomDeserter") { }

uint32 GetDeserterCount(ObjectGuid::LowType const guid, time_t time)
{
uint32 const days = sConfigMgr->GetOption<uint32>("DeserterDays", 7);
time_t from = days != 0 ? time - static_cast<time_t>(days) * DAY : 0;
QueryResult result = CharacterDatabase.Query("SELECT COUNT(DISTINCT Time) FROM custom_deserter WHERE Guid = {} AND Time BETWEEN {} AND {}", guid, from, time); // Fixme: OnBattlegroundRemovePlayerAtLeave is calling twice
if (result)
return (*result)[0].Get<uint32>();
else return 0;
}

void OnBattlegroundRemovePlayerAtLeave(Battleground* bg, Player* player) override
{
if (!player)
return;

if (bg->isBattleground() && !player->IsGameMaster())
{
BattlegroundStatus status = bg->GetStatus();
if (status == STATUS_IN_PROGRESS || status == STATUS_WAIT_JOIN)
{
int32 const baseDuration = sConfigMgr->GetOption<int32>("DeserterBaseDuration", 30) * MINUTE * IN_MILLISECONDS;

time_t now = GameTime::GetGameTime().count();
ObjectGuid::LowType const guid = player->GetGUID().GetCounter();
// First we get the amount of deserters from db
uint32 deserterCount = GetDeserterCount(guid, now);
// Calculate deserter duration
int32 duration = baseDuration + (deserterCount * baseDuration);

// After that we check if the player already has deserter debuff
if (Aura* deserterAura = player->GetAura(SPELL_DESERTER))
{
int32 auraDuration = deserterAura->GetDuration();
deserterAura->SetDuration(duration);
}
else
{
Aura* aura = player->AddAura(SPELL_DESERTER, player);
if (!aura)
return;
aura->SetDuration(duration);
}
// Save deserter to db
CharacterDatabase.DirectExecute("INSERT INTO custom_deserter (Guid, Time, Duration) VALUES ({}, {}, {})", guid, now, duration);
}
}
}
};

// Add all scripts in one
void AddCustomDeserterScripts()
{
new CustomDeserter();
}

0 comments on commit 7a9a0ce

Please sign in to comment.