diff --git a/.git_commit_template.txt b/.git_commit_template.txt
deleted file mode 100644
index 708b551..0000000
--- a/.git_commit_template.txt
+++ /dev/null
@@ -1,49 +0,0 @@
-### TITLE
-## Type(Scope/Subscope): Commit ultra short explanation
-## |---- Write below the examples with a maximum of 50 characters ----|
-## Example 1: fix(DB/SAI): Missing spell to NPC Hogger
-## Example 2: fix(CORE/Raid): Phase 2 of Ragnaros
-## Example 3: feat(CORE/Commands): New GM command to do something
-
-
-### DESCRIPTION
-## Explain why this change is being made, what does it fix etc...
-## |---- Write below the examples with a maximum of 72 characters per lines ----|
-## Example: Hogger (id: 492) was not charging player when being engaged.
-
-
-## Provide links to any issue, commit, pull request or other resource
-## Example 1: Closes issue #23
-## Example 2: Ported from other project's commit (link)
-## Example 3: References taken from wowpedia / wowhead / wowwiki / https://wowgaming.altervista.org/aowow/
-
-
-
-## =======================================================
-## EXTRA INFOS
-## =======================================================
-## "Type" can be:
-## feat (new feature)
-## fix (bug fix)
-## refactor (refactoring production code)
-## style (formatting, missing semi colons, etc; no code change)
-## docs (changes to documentation)
-## test (adding or refactoring tests; no production code change)
-## chore (updating bash scripts, git files etc; no production code change)
-## --------------------
-## Remember to
-## Capitalize the subject line
-## Use the imperative mood in the subject line
-## Do not end the subject line with a period
-## Separate subject from body with a blank line
-## Use the body to explain what and why rather than how
-## Can use multiple lines with "-" for bullet points in body
-## --------------------
-## More info here https://www.conventionalcommits.org/en/v1.0.0-beta.2/
-## =======================================================
-## "Scope" can be:
-## CORE (core related, c++)
-## DB (database related, sql)
-## =======================================================
-## "Subscope" is optional and depends on the nature of the commit.
-## =======================================================
diff --git a/.gitattributes b/.gitattributes
index 7ef9001..6667b6a 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -2,7 +2,7 @@
## Handle line endings automatically for files detected as
## text and leave all files detected as binary untouched.
## This will handle all files NOT defined below.
-* text=auto eol=lf
+* text eol=lf
# Text
*.conf text
@@ -28,20 +28,19 @@
*.h++ text
*.hh text
-
## For documentation
# Documents
-*.doc diff=astextplain
-*.DOC diff=astextplain
-*.docx diff=astextplain
-*.DOCX diff=astextplain
-*.dot diff=astextplain
-*.DOT diff=astextplain
-*.pdf diff=astextplain
-*.PDF diff=astextplain
-*.rtf diff=astextplain
-*.RTF diff=astextplain
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
## DOCUMENTATION
*.markdown text
@@ -59,13 +58,13 @@ CHANGES text
CONTRIBUTING text
COPYING text
copyright text
-*COPYRIGHT* text
+COPYRIGHT text
INSTALL text
license text
LICENSE text
NEWS text
readme text
-*README* text
+README text
TODO text
## GRAPHICS
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
new file mode 100644
index 0000000..5610d2b
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -0,0 +1,72 @@
+name: Bug report
+description: Create a bug report to help us improve.
+title: "Bug: "
+body:
+ - type: textarea
+ id: current
+ attributes:
+ label: Current Behaviour
+ description: |
+ Description of the problem or issue here.
+ Include entries of affected creatures / items / quests / spells etc.
+ If this is a crash, post the crashlog (upload to https://gist.github.com/) and include the link here.
+ Never upload files! Use GIST for text and YouTube for videos!
+ validations:
+ required: true
+ - type: textarea
+ id: expected
+ attributes:
+ label: Expected Behaviour
+ description: |
+ Tell us what should happen instead.
+ validations:
+ required: true
+ - type: textarea
+ id: reproduce
+ attributes:
+ label: Steps to reproduce the problem
+ description: |
+ What does someone else need to do to encounter the same bug?
+ placeholder: |
+ 1. Step 1
+ 2. Step 2
+ 3. Step 3
+ validations:
+ required: true
+ - type: textarea
+ id: extra
+ attributes:
+ label: Extra Notes
+ description: |
+ Do you have any extra notes that can help solve the issue that does not fit any other field?
+ placeholder: |
+ None
+ validations:
+ required: false
+ - type: textarea
+ id: commit
+ attributes:
+ label: AC rev. hash/commit
+ description: |
+ Copy the result of the `.server debug` command (if you need to run it from the client get a prat addon)
+ validations:
+ required: true
+ - type: input
+ id: os
+ attributes:
+ label: Operating system
+ description: |
+ The Operating System the Server is running on.
+ i.e. Windows 11 x64, Debian 10 x64, macOS 12, Ubuntu 20.04
+ validations:
+ required: true
+ - type: textarea
+ id: custom
+ attributes:
+ label: Custom changes or Modules
+ description: |
+ List which custom changes or modules you have applied, i.e. Eluna module, etc.
+ placeholder: |
+ None
+ validations:
+ required: false
diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml
new file mode 100644
index 0000000..58f79dd
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.yml
@@ -0,0 +1,33 @@
+name: Feature request
+description: Suggest an idea for this project
+title: "Feature: "
+body:
+ - type: markdown
+ attributes:
+ value: |
+ Thank you for taking your time to fill out a feature request. Remember to fill out all fields including the title above.
+ An issue that is not properly filled out will be closed.
+ - type: textarea
+ id: description
+ attributes:
+ label: Describe your feature request or suggestion in detail
+ description: |
+ A clear and concise description of what you want to happen.
+ validations:
+ required: true
+ - type: textarea
+ id: solution
+ attributes:
+ label: Describe a possible solution to your feature or suggestion in detail
+ description: |
+ A clear and concise description of any alternative solutions or features you've considered.
+ validations:
+ required: false
+ - type: textarea
+ id: additional
+ attributes:
+ label: Additional context
+ description: |
+ Add any other context or screenshots about the feature request here.
+ validations:
+ required: false
diff --git a/.github/README.md b/.github/README.md
new file mode 100644
index 0000000..10b6295
--- /dev/null
+++ b/.github/README.md
@@ -0,0 +1,23 @@
+# ![logo](https://raw.githubusercontent.com/azerothcore/azerothcore.github.io/master/images/logo-github.png) AzerothCore
+
+## RandomEnchantsModule
+
+- Latest build status with azerothcore:
+
+[![Build Status](https://github.com/azerothcore/mod-random-enchants/workflows/core-build/badge.svg?branch=master&event=push)](https://github.com/azerothcore/mod-random-enchants)
+
+- Make sure to support the main project:
+
+https://github.com/azerothcore/azerothcore-wotlk/
+
+- This is a "fun" script/module converted from an LUA script I found, credits to whoever did this originally
+
+## What this does
+
+- Will sometimes add random enchantments on any item Looted, Quest Rewarded or Profession created
+
+## Configurable
+
+- Login message for the module (on, off and what to display)
+- Select if you want to enchant loot, quest reward, profession or all
+- Modify the source to mess with the chances of enchantment
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 0000000..21c9245
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,25 @@
+
+
+## Changes Proposed:
+-
+-
+
+## Issues Addressed:
+
+- Closes
+
+## SOURCE:
+
+
+## Tests Performed:
+
+-
+-
+
+
+## How to Test the Changes:
+
+
+1.
+2.
+3.
diff --git a/.gitignore b/.gitignore
index c6e1299..4ba5dd3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,28 +3,27 @@
#
#Generic
#
-
.directory
.mailmap
-*.orig
-*.rej
-*.*~
-.hg/
-*.kdev*
+* .orig
+* .rej
+* .*~
+.hg /
+*.kdev *
.DS_Store
CMakeLists.txt.user
-*.bak
-*.patch
-*.diff
-*.REMOTE.*
-*.BACKUP.*
-*.BASE.*
-*.LOCAL.*
+* .bak
+* .patch
+* .diff
+* .REMOTE.*
+* .BACKUP.*
+* .BASE.*
+* .LOCAL.*
#
# IDE & other softwares
#
-/.settings/
+/ .settings/
/.externalToolBuilders/*
# exclude in all levels
nbproject/
diff --git a/README.md b/README.md
deleted file mode 100644
index 5726cf2..0000000
--- a/README.md
+++ /dev/null
@@ -1,15 +0,0 @@
-# ![logo](https://raw.githubusercontent.com/azerothcore/azerothcore.github.io/master/images/logo-github.png) AzerothCore
-## RandomEnchantsModule
-- Latest build status with azerothcore: [![Build Status](https://github.com/azerothcore/mod-random-enchants/workflows/core-build/badge.svg?branch=master&event=push)](https://github.com/azerothcore/mod-random-enchants)
-
-Make sure to support the main project:
-https://github.com/azerothcore/azerothcore-wotlk/
-
-* !!BEFORE RUNNING!!: Execute the included "conf/SQL/item_enchantment_random_tiers.sql" file on your world database. This creates a necessary table for this module.
-* This is a "fun" script/module converted from an LUA script I found, credits to whoever did this originally
-* What this does:
-* Will sometimes add random enchantments on any item Looted, Quest Rewarded or Profession created
-* Configurable:
-* Login message for the module (on, off and what to display)
-* Select if you want to enchant loot, quest reward, profession or all
-* Modify the source to mess with the chances of enchantment
diff --git a/conf/.gitkeep b/conf/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/conf/conf.sh.dist b/conf/conf.sh.dist
deleted file mode 100644
index 571e6bf..0000000
--- a/conf/conf.sh.dist
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/env bash
-
-#
-# CUSTOM
-#
-
-DB_WORLD_CUSTOM_PATHS+=(
- "$MOD_RANDOMENCHANTS_ROOT/sql/world/"
-)
diff --git a/conf/RandomEnchants.conf.dist b/conf/random_enchants.conf.dist
similarity index 100%
rename from conf/RandomEnchants.conf.dist
rename to conf/random_enchants.conf.dist
diff --git a/data/.gitkeep b/data/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/sql/world/item_enchatment_random_tiers.sql b/data/sql/db-world/item_enchatment_random_tiers.sql
similarity index 100%
rename from sql/world/item_enchatment_random_tiers.sql
rename to data/sql/db-world/item_enchatment_random_tiers.sql
diff --git a/include.sh b/include.sh
index ecc57ce..e69de29 100644
--- a/include.sh
+++ b/include.sh
@@ -1,9 +0,0 @@
-#!/usr/bin/env bash
-
-MOD_RANDOMENCHANTS_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd )"
-
-source "$MOD_RANDOMENCHANTS_ROOT/conf/conf.sh.dist"
-
-if [ -f "$MOD_RANDOMENCHANTS_ROOT/conf/conf.sh" ]; then
- source "$MOD_RANDOMENCHANTS_ROOT/conf/conf.sh"
-fi
diff --git a/setup_git_commit_template.sh b/setup_git_commit_template.sh
deleted file mode 100644
index 7b52062..0000000
--- a/setup_git_commit_template.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env bash
-
-## Set a local git commit template
-git config --local commit.template ".git_commit_template.txt" ;
diff --git a/src/RandomEnchants.cpp b/src/RandomEnchants.cpp
deleted file mode 100644
index f9d8fc0..0000000
--- a/src/RandomEnchants.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
-* Converted from the original LUA script to a module for Azerothcore(Sunwell) :D
-*/
-#include "ScriptMgr.h"
-#include "Player.h"
-#include "Configuration/Config.h"
-#include "Chat.h"
-
-// Enum for item qualities
-enum ItemQuality {
- GREY = 0,
- WHITE,
- GREEN,
- BLUE,
- PURPLE,
- ORANGE
-};
-
-class RandomEnchantsPlayer : public PlayerScript {
-public:
- RandomEnchantsPlayer() : PlayerScript("RandomEnchantsPlayer") { }
-
- void OnLogin(Player* player) override {
- if (sConfigMgr->GetOption("RandomEnchants.AnnounceOnLogin", true) && sConfigMgr->GetOption("RandomEnchants.Enable", true))
- ChatHandler(player->GetSession()).SendSysMessage(sConfigMgr->GetOption("RandomEnchants.OnLoginMessage", "This server is running a RandomEnchants Module.").c_str());
- }
-
- void OnLootItem(Player* player, Item* item, uint32 /*count*/, ObjectGuid /*lootguid*/) override {
- if (sConfigMgr->GetOption("RandomEnchants.OnLoot", true) && sConfigMgr->GetOption("RandomEnchants.Enable", true))
- RollPossibleEnchant(player, item);
- }
-
- void OnCreateItem(Player* player, Item* item, uint32 /*count*/) override {
- if (sConfigMgr->GetOption("RandomEnchants.OnCreate", true) && sConfigMgr->GetOption("RandomEnchants.Enable", true))
- RollPossibleEnchant(player, item);
- }
-
- void OnQuestRewardItem(Player* player, Item* item, uint32 /*count*/) override {
- if (sConfigMgr->GetOption("RandomEnchants.OnQuestReward", true) && sConfigMgr->GetOption("RandomEnchants.Enable", true))
- RollPossibleEnchant(player, item);
- }
-
- void OnGroupRollRewardItem(Player* player, Item* item, uint32 /*count*/, RollVote /*voteType*/, Roll* /*roll*/) override {
- if (sConfigMgr->GetOption("RandomEnchants.OnGroupRoll", true) && sConfigMgr->GetOption("RandomEnchants.Enable", true))
- RollPossibleEnchant(player, item);
- }
-
- void RollPossibleEnchant(Player* player, Item* item) {
- // Check global enable option
- if (!sConfigMgr->GetOption("RandomEnchants.Enable", true)) {
- return;
- }
- uint32 Quality = item->GetTemplate()->Quality;
- uint32 Class = item->GetTemplate()->Class;
-
- if (
- (Quality > 5 || Quality < 1) /* eliminates enchanting anything that isn't a recognized quality */ ||
- (Class != 2 && Class != 4) /* eliminates enchanting anything but weapons/armor */) {
- return;
- }
-
- int slotRand[3] = { -1, -1, -1 };
- uint32 slotEnch[3] = { 0, 1, 5 };
-
- // Fetching the configuration values as float
- float enchantChance1 = sConfigMgr->GetOption("RandomEnchants.EnchantChance1", 70.0f);
- float enchantChance2 = sConfigMgr->GetOption("RandomEnchants.EnchantChance2", 65.0f);
- float enchantChance3 = sConfigMgr->GetOption("RandomEnchants.EnchantChance3", 60.0f);
-
- if (rand_chance() < enchantChance1)
- slotRand[0] = getRandEnchantment(item);
- if (slotRand[0] != -1 && rand_chance() < enchantChance2)
- slotRand[1] = getRandEnchantment(item);
- if (slotRand[1] != -1 && rand_chance() < enchantChance3)
- slotRand[2] = getRandEnchantment(item);
-
- for (int i = 0; i < 3; i++) {
- if (slotRand[i] != -1) {
- if (sSpellItemEnchantmentStore.LookupEntry(slotRand[i])) { //Make sure enchantment id exists
- player->ApplyEnchantment(item, EnchantmentSlot(slotEnch[i]), false);
- item->SetEnchantment(EnchantmentSlot(slotEnch[i]), slotRand[i], 0, 0);
- player->ApplyEnchantment(item, EnchantmentSlot(slotEnch[i]), true);
- }
- }
- }
- ChatHandler chathandle = ChatHandler(player->GetSession());
- if (slotRand[2] != -1)
- chathandle.PSendSysMessage("Newly Acquired |cffFF0000 %s |rhas received|cffFF0000 3 |rrandom enchantments!", item->GetTemplate()->Name1.c_str());
- else if (slotRand[1] != -1)
- chathandle.PSendSysMessage("Newly Acquired |cffFF0000 %s |rhas received|cffFF0000 2 |rrandom enchantments!", item->GetTemplate()->Name1.c_str());
- else if (slotRand[0] != -1)
- chathandle.PSendSysMessage("Newly Acquired |cffFF0000 %s |rhas received|cffFF0000 1 |rrandom enchantment!", item->GetTemplate()->Name1.c_str());
- }
-
- int getRandEnchantment(Item* item) {
- uint32 Class = item->GetTemplate()->Class;
- std::string ClassQueryString = "";
- switch (Class) {
- case 2:
- ClassQueryString = "WEAPON";
- break;
- case 4:
- ClassQueryString = "ARMOR";
- break;
- }
- if (ClassQueryString == "")
- return -1;
- uint32 Quality = item->GetTemplate()->Quality;
- int rarityRoll = -1;
- switch (Quality) {
- case GREY:
- rarityRoll = rand_norm() * 25;
- break;
- case WHITE:
- rarityRoll = rand_norm() * 50;
- break;
- case GREEN:
- rarityRoll = 45 + (rand_norm() * 20);
- break;
- case BLUE:
- rarityRoll = 65 + (rand_norm() * 15);
- break;
- case PURPLE:
- rarityRoll = 80 + (rand_norm() * 14);
- break;
- case ORANGE:
- rarityRoll = 93;
- break;
- }
- if (rarityRoll < 0)
- return -1;
- int tier = 0;
- if (rarityRoll <= 44)
- tier = 1;
- else if (rarityRoll <= 64)
- tier = 2;
- else if (rarityRoll <= 79)
- tier = 3;
- else if (rarityRoll <= 92)
- tier = 4;
- else
- tier = 5;
-
- QueryResult qr = WorldDatabase.Query("SELECT enchantID FROM item_enchantment_random_tiers WHERE tier='{}' AND exclusiveSubClass=NULL AND class='{}' OR exclusiveSubClass='{}' OR class='ANY' ORDER BY RAND() LIMIT 1", tier, ClassQueryString, item->GetTemplate()->SubClass);
- return qr->Fetch()[0].Get();
- }
-};
-
-void AddRandomEnchantsScripts() {
- new RandomEnchantsPlayer();
-}
-
-
diff --git a/src/random_enchants.cpp b/src/random_enchants.cpp
new file mode 100644
index 0000000..cd38fa0
--- /dev/null
+++ b/src/random_enchants.cpp
@@ -0,0 +1,159 @@
+#include "random_enchants.h"
+
+void rollPossibleEnchant(Player* player, Item* item)
+{
+ // Check global enable option
+ if (!sConfigMgr->GetOption("RandomEnchants.Enable", true))
+ {
+ return;
+ }
+
+ uint32 itemQuality = item->GetTemplate()->Quality;
+ uint32 itemClass = item->GetTemplate()->Class;
+
+ /* eliminates enchanting anything that isn't a recognized quality */
+ /* eliminates enchanting anything but weapons/armor */
+ if ((itemQuality > 5 || itemQuality < 1) || (itemClass != 2 && itemClass != 4))
+ {
+ return;
+ }
+
+ int slotRand[3] = { -1, -1, -1 };
+ uint32 slotEnch[3] = { 0, 1, 5 };
+
+ // Fetching the configuration values as float
+ float enchantChance1 = sConfigMgr->GetOption("RandomEnchants.EnchantChance1", 70.0f);
+ float enchantChance2 = sConfigMgr->GetOption("RandomEnchants.EnchantChance2", 65.0f);
+ float enchantChance3 = sConfigMgr->GetOption("RandomEnchants.EnchantChance3", 60.0f);
+
+ if (rand_chance() < enchantChance1)
+ slotRand[0] = getRandEnchantment(item);
+ if (slotRand[0] != -1 && rand_chance() < enchantChance2)
+ slotRand[1] = getRandEnchantment(item);
+ if (slotRand[1] != -1 && rand_chance() < enchantChance3)
+ slotRand[2] = getRandEnchantment(item);
+
+ for (int i = 0; i < 3; i++)
+ {
+ if (slotRand[i] != -1)
+ {
+ if (sSpellItemEnchantmentStore.LookupEntry(slotRand[i]))
+ { //Make sure enchantment id exists
+ player->ApplyEnchantment(item, EnchantmentSlot(slotEnch[i]), false);
+ item->SetEnchantment(EnchantmentSlot(slotEnch[i]), slotRand[i], 0, 0);
+ player->ApplyEnchantment(item, EnchantmentSlot(slotEnch[i]), true);
+ }
+ }
+ }
+
+ ChatHandler chathandle = ChatHandler(player->GetSession());
+
+ uint8 loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
+ const ItemTemplate* temp = item->GetTemplate();
+ std::string name = temp->Name1;
+ if (ItemLocale const* il = sObjectMgr->GetItemLocale(temp->ItemId))
+ ObjectMgr::GetLocaleString(il->Name, loc_idx, name);
+
+
+ if (slotRand[2] != -1)
+ chathandle.PSendSysMessage("Newly Acquired |cffFF0000 %s |rhas received|cffFF0000 3 |rrandom enchantments!", name);
+ else if (slotRand[1] != -1)
+ chathandle.PSendSysMessage("Newly Acquired |cffFF0000 %s |rhas received|cffFF0000 2 |rrandom enchantments!", name);
+ else if (slotRand[0] != -1)
+ chathandle.PSendSysMessage("Newly Acquired |cffFF0000 %s |rhas received|cffFF0000 1 |rrandom enchantment!", name);
+}
+
+uint32 getRandEnchantment(Item* item)
+{
+ uint32 itemClass = item->GetTemplate()->Class;
+ uint32 itemQuality = item->GetTemplate()->Quality;
+ std::string classQueryString = "";
+ int rarityRoll = -1;
+ uint8 tier = 0;
+
+ switch (itemClass)
+ {
+ case 2:
+ classQueryString = "WEAPON";
+ break;
+ case 4:
+ classQueryString = "ARMOR";
+ break;
+ }
+
+ if (classQueryString == "")
+ return -1;
+
+ switch (itemQuality)
+ {
+ case GREY:
+ rarityRoll = rand_norm() * 25;
+ break;
+ case WHITE:
+ rarityRoll = rand_norm() * 50;
+ break;
+ case GREEN:
+ rarityRoll = 45 + (rand_norm() * 20);
+ break;
+ case BLUE:
+ rarityRoll = 65 + (rand_norm() * 15);
+ break;
+ case PURPLE:
+ rarityRoll = 80 + (rand_norm() * 14);
+ break;
+ case ORANGE:
+ rarityRoll = 93;
+ break;
+ }
+
+ if (rarityRoll < 0)
+ return -1;
+
+ if (rarityRoll <= 44)
+ tier = 1;
+ else if (rarityRoll <= 64)
+ tier = 2;
+ else if (rarityRoll <= 79)
+ tier = 3;
+ else if (rarityRoll <= 92)
+ tier = 4;
+ else
+ tier = 5;
+
+ QueryResult result = WorldDatabase.Query("SELECT `enchantID` FROM `item_enchantment_random_tiers` WHERE `tier`={} AND `exclusiveSubClass`=NULL AND exclusiveSubClass='{}' OR `class`='{}' OR `class`='ANY' ORDER BY RAND() LIMIT 1", tier, item->GetTemplate()->SubClass, classQueryString, classQueryString);
+
+ if (!result)
+ return 0;
+
+ return result->Fetch()[0].Get();
+}
+
+void RandomEnchantsPlayer::OnLogin(Player* player)
+{
+ if (sConfigMgr->GetOption("RandomEnchants.AnnounceOnLogin", true) && (sConfigMgr->GetOption("RandomEnchants.Enable", true)))
+ ChatHandler(player->GetSession()).SendSysMessage(sConfigMgr->GetOption("RandomEnchants.OnLoginMessage", "This server is running a RandomEnchants Module.").c_str());
+}
+
+void RandomEnchantsPlayer::OnLootItem(Player* player, Item* item, uint32 /*count*/, ObjectGuid /*lootguid*/)
+{
+ if (sConfigMgr->GetOption("RandomEnchants.OnLoot", true) && sConfigMgr->GetOption("RandomEnchants.Enable", true))
+ rollPossibleEnchant(player, item);
+}
+
+void RandomEnchantsPlayer::OnCreateItem(Player* player, Item* item, uint32 /*count*/)
+{
+ if (sConfigMgr->GetOption("RandomEnchants.OnCreate", true) && (sConfigMgr->GetOption("RandomEnchants.Enable", true)))
+ rollPossibleEnchant(player, item);
+}
+
+void RandomEnchantsPlayer::OnQuestRewardItem(Player* player, Item* item, uint32 /*count*/)
+{
+ if (sConfigMgr->GetOption("RandomEnchants.OnQuestReward", true) && (sConfigMgr->GetOption("RandomEnchants.Enable", true)))
+ rollPossibleEnchant(player, item);
+}
+
+void RandomEnchantsPlayer::OnGroupRollRewardItem(Player* player, Item* item, uint32 /*count*/, RollVote /*voteType*/, Roll* /*roll*/)
+{
+ if (sConfigMgr->GetOption("RandomEnchants.OnGroupRoll", true) && (sConfigMgr->GetOption("RandomEnchants.Enable", true)))
+ rollPossibleEnchant(player, item);
+}
diff --git a/src/random_enchants.h b/src/random_enchants.h
new file mode 100644
index 0000000..ab12089
--- /dev/null
+++ b/src/random_enchants.h
@@ -0,0 +1,38 @@
+/*
+* Converted from the original LUA script to a module for Azerothcore (Sunwell)
+*/
+
+#include "ScriptMgr.h"
+#include "Player.h"
+#include "Configuration/Config.h"
+#include "Chat.h"
+
+enum ItemQuality
+{
+ GREY = 0,
+ WHITE,
+ GREEN,
+ BLUE,
+ PURPLE,
+ ORANGE
+};
+
+void rollPossibleEnchant(Player* player, Item* item);
+[[nodiscard]] uint32 getRandEnchantment(Item* item);
+
+class RandomEnchantsPlayer : public PlayerScript
+{
+public:
+ RandomEnchantsPlayer() : PlayerScript("RandomEnchantsPlayer") { }
+
+ void OnLogin(Player* player) override;
+ void OnLootItem(Player* player, Item* item, uint32 /*count*/, ObjectGuid /*lootguid*/) override;
+ void OnCreateItem(Player* player, Item* item, uint32 /*count*/) override;
+ void OnQuestRewardItem(Player* player, Item* item, uint32 /*count*/) override;
+ void OnGroupRollRewardItem(Player* player, Item* item, uint32 /*count*/, RollVote /*voteType*/, Roll* /*roll*/) override;
+};
+
+void AddRandomEnchantsScripts()
+{
+ new RandomEnchantsPlayer();
+}