From 0888f3703ebf5e21ab23feec051f5b8412c03e83 Mon Sep 17 00:00:00 2001 From: anzz1 Date: Wed, 27 Mar 2024 06:58:14 +0200 Subject: [PATCH] Fix crashes and make options work (#21) * Fix crashes and make options work * Setting option Buff.MessageTimer = 0 actually disables the timed emotes and phrases now * Fix crash on setting Buff.NumWhispers = 0 (disable whispers) * Fix crash on setting Buff.NumPhrases = 0 (disable random talk) * Update npc_buffer.conf.dist * Remove InhabitType to work with latest core As per commit azerothcore-wotlk@2d4e17f InhabitType was removed from creature_template table * Replace deprecated config api, add enable/disable * Replaced deprecated config api to fix build * add enable/disable option * Update npc_buffer.conf.dist Add enable/disable option * chore. Add files and fix build --------- Co-authored-by: Pagani Walter --- .gitattributes | 10 +-- .github/ISSUE_TEMPLATE/bug_report.yml | 16 ++--- .github/ISSUE_TEMPLATE/feature_request.yml | 4 +- .github/README.md | 6 +- .github/pull_request_template.md | 25 +++++++ conf/conf.sh.dist | 9 --- conf/npc_buffer.conf.dist | 9 +++ .../base => data/sql/db-world}/npc_buffer.sql | 0 include.sh | 9 --- sql/world/updates/2022_05_24_00.sql | 3 - src/NB_loader.cpp | 3 +- src/npc_buffer.cpp | 70 ++++++++++++------- 12 files changed, 97 insertions(+), 67 deletions(-) create mode 100644 .github/pull_request_template.md delete mode 100644 conf/conf.sh.dist rename {sql/world/base => data/sql/db-world}/npc_buffer.sql (100%) delete mode 100644 sql/world/updates/2022_05_24_00.sql diff --git a/.gitattributes b/.gitattributes index 7ef9001..a20e449 100644 --- a/.gitattributes +++ b/.gitattributes @@ -32,16 +32,16 @@ ## For documentation # Documents -*.doc diff=astextplain -*.DOC 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 +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain ## DOCUMENTATION *.markdown text diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 444315b..6927214 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -4,8 +4,8 @@ body: - type: markdown attributes: value: | - Thank you for taking the time to fill out a bug report. Remember to fill out all fields including the title above. - An issue that is not properly filled out will be closed. + Thank you for taking the time to fill out a bug report. Remember to fill out all fields including the title above. + An issue that is not properly filled out will be closed. You can read more about the standards for a bug report [here](https://www.azerothcore.org/wiki/issue-tracker-standards). - type: textarea id: current @@ -15,6 +15,7 @@ body: 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 @@ -25,14 +26,6 @@ body: Tell us what should happen instead. validations: required: true - - type: textarea - id: source - attributes: - label: Source - description: | - If you have a source that proves how it is supposed to work, please add that to make it easier for devs to fix the issue. - validations: - required: false - type: textarea id: reproduce attributes: @@ -68,7 +61,8 @@ body: attributes: label: Operating system description: | - Operating System, i.e. Windows 10 x64, Debian 10 x64, etc + 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 diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 70bbbbc..4700616 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -6,8 +6,8 @@ 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. + 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: diff --git a/.github/README.md b/.github/README.md index dba374f..f5c57c9 100644 --- a/.github/README.md +++ b/.github/README.md @@ -1,6 +1,10 @@ # ![logo](https://raw.githubusercontent.com/azerothcore/azerothcore.github.io/master/images/logo-github.png) AzerothCore + ## Buffer NPC -- Latest build status with azerothcore: [![Build Status](https://github.com/azerothcore/mod-npc-buffer/workflows/core-build/badge.svg?branch=master&event=push)](https://github.com/azerothcore/mod-npc-buffer) + +- Latest build status with azerothcore: + +[![Build Status](https://github.com/azerothcore/mod-npc-buffer/workflows/core-build/badge.svg)](https://github.com/azerothcore/mod-npc-buffer) _This module was created for [StygianCore](https://rebrand.ly/stygiancoreproject). A World of Warcraft 3.3.5a Solo/LAN repack by StygianTheBest | [GitHub](https://rebrand.ly/stygiangithub) | [Website](https://rebrand.ly/stygianthebest))_ _This module has now being ported to AzerothCore by gtao725 (https://github.com/gtao725/)._ 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/conf/conf.sh.dist b/conf/conf.sh.dist deleted file mode 100644 index f460a19..0000000 --- a/conf/conf.sh.dist +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -# -# CUSTOM -# - -DB_WORLD_CUSTOM_PATHS+=( - "$MOD_NPCBUFFER_ROOT/sql/world/" -) \ No newline at end of file diff --git a/conf/npc_buffer.conf.dist b/conf/npc_buffer.conf.dist index 31bc94d..554b8a4 100644 --- a/conf/npc_buffer.conf.dist +++ b/conf/npc_buffer.conf.dist @@ -3,6 +3,13 @@ # BUFFER NPC ################################################################################################### +# ------------------------------------------------------------------------------------- +# Enable the module +# Enable : 1 +# Disable: 0 +# ------------------------------------------------------------------------------------- +Buff.Enable = 1 + # ------------------------------------------------------------------------------------- # Announce the module when the player logs in? # Enable : 1 @@ -51,6 +58,7 @@ Buff.MessageTimer = 60000 # ------------------------------------------------------------------------------------- # How many pharases does the NPC have? # Default: 3 +# Disable: 0 # ------------------------------------------------------------------------------------- Buff.NumPhrases = 4 @@ -66,6 +74,7 @@ BF.P4 = "Those trolls sure now how to dance! I hear they like to party in the mo # ------------------------------------------------------------------------------------- # How many whispers does the NPC have? # Default: 3 +# Disable: 0 # ------------------------------------------------------------------------------------- Buff.NumWhispers = 10 diff --git a/sql/world/base/npc_buffer.sql b/data/sql/db-world/npc_buffer.sql similarity index 100% rename from sql/world/base/npc_buffer.sql rename to data/sql/db-world/npc_buffer.sql diff --git a/include.sh b/include.sh index 6c20726..e69de29 100644 --- a/include.sh +++ b/include.sh @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -MOD_NPCBUFFER_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd )" - -source "$MOD_NPCBUFFER_ROOT/conf/conf.sh.dist" - -if [ -f "$MOD_NPCBUFFER_ROOT/conf/conf.sh" ]; then - source "$MOD_NPCBUFFER_ROOT/conf/conf.sh" -fi \ No newline at end of file diff --git a/sql/world/updates/2022_05_24_00.sql b/sql/world/updates/2022_05_24_00.sql deleted file mode 100644 index 8f3bdbf..0000000 --- a/sql/world/updates/2022_05_24_00.sql +++ /dev/null @@ -1,3 +0,0 @@ - -SET @Entry:=601016; -UPDATE `creature_template` SET `npcflag`=`npcflag`|1, `flags_extra`=`flags_extra`|16777216 WHERE `entry`=@Entry; diff --git a/src/NB_loader.cpp b/src/NB_loader.cpp index 8d37fa3..922d41c 100644 --- a/src/NB_loader.cpp +++ b/src/NB_loader.cpp @@ -1,5 +1,6 @@ void AddNPCBufferScripts(); -void Addmod_npc_bufferScripts() { +void Addmod_npc_bufferScripts() +{ AddNPCBufferScripts(); } diff --git a/src/npc_buffer.cpp b/src/npc_buffer.cpp index 9e5196f..3bdef06 100644 --- a/src/npc_buffer.cpp +++ b/src/npc_buffer.cpp @@ -70,6 +70,7 @@ This code and content is released under the [GNU AGPL v3](https://github.com/aze #include "ScriptedCreature.h" #include "ScriptedGossip.h" +static bool BFEnableModule; static bool BFAnnounceModule; static bool BuffByLevel; static bool BuffCureRes; @@ -86,14 +87,15 @@ class BufferConfig : public WorldScript void OnBeforeConfigLoad(bool /*reload*/) override { + BFEnableModule = sConfigMgr->GetOption("Buff.Enable", 1); BFAnnounceModule = sConfigMgr->GetOption("Buff.Announce", 1); BuffByLevel = sConfigMgr->GetOption("Buff.ByLevel", 1); BuffCureRes = sConfigMgr->GetOption("Buff.CureRes", 1); - BuffNumPhrases = sConfigMgr->GetOption("Buff.NumPhrases", 3); - BuffNumWhispers = sConfigMgr->GetOption("Buff.NumWhispers", 3); - BuffMessageTimer = sConfigMgr->GetOption("Buff.MessageTimer", 60000); - BuffEmoteSpell = sConfigMgr->GetOption("Buff.EmoteSpell", 44940); - BuffEmoteCommand = sConfigMgr->GetOption("Buff.EmoteCommand", 3); + BuffNumPhrases = sConfigMgr->GetOption("Buff.NumPhrases", 3); + BuffNumWhispers = sConfigMgr->GetOption("Buff.NumWhispers", 3); + BuffMessageTimer = sConfigMgr->GetOption("Buff.MessageTimer", 60000); + BuffEmoteSpell = sConfigMgr->GetOption("Buff.EmoteSpell", 44940); + BuffEmoteCommand = sConfigMgr->GetOption("Buff.EmoteCommand", 3); // Enforce Min/Max Time if (BuffMessageTimer != 0) @@ -108,14 +110,13 @@ class BufferConfig : public WorldScript class BufferAnnounce : public PlayerScript { - public: BufferAnnounce() : PlayerScript("BufferAnnounce") {} void OnLogin(Player *player) { // Announce Module - if (BFAnnounceModule) + if (BFEnableModule && BFAnnounceModule) { ChatHandler(player->GetSession()).SendSysMessage("This server is running the |cff4CFF00BufferNPC |rmodule."); } @@ -124,7 +125,6 @@ class BufferAnnounce : public PlayerScript class buff_npc : public CreatureScript { - public: buff_npc() : CreatureScript("buff_npc") {} @@ -176,6 +176,11 @@ class buff_npc : public CreatureScript bool OnGossipSelect(Player *player, Creature *creature, uint32 /*uiSender*/, uint32 /* uiAction */) { + if (!BFEnableModule) + { + return false; + } + // Who are we dealing with? std::string CreatureWhisper = "Init"; std::string PlayerName = player->GetName(); @@ -296,7 +301,11 @@ class buff_npc : public CreatureScript // Choose and speak a random phrase to the player // Phrases are stored in the config file - creature->Whisper(PickWhisper(PlayerName).c_str(), LANG_UNIVERSAL, player); + + if (BuffNumWhispers > 0) + { + creature->Whisper(PickWhisper(PlayerName).c_str(), LANG_UNIVERSAL, player); + } // Emote and Close creature->HandleEmoteCommand(EMOTE_ONESHOT_FLEX); @@ -309,35 +318,44 @@ class buff_npc : public CreatureScript { NPC_PassiveAI(Creature *creature) : ScriptedAI(creature) {} - uint32 MessageTimer; + uint32 MessageTimer = 0; // Called once when client is loaded void Reset() { - MessageTimer = urand(BuffMessageTimer, 300000); // 1-5 minutes + if (BuffMessageTimer != 0) { + MessageTimer = urand(BuffMessageTimer, 300000); // 1-5 minutes + } } // Called at World update tick void UpdateAI(const uint32 diff) { - if (MessageTimer <= diff) + if (BFEnableModule && BuffMessageTimer != 0) { - std::string Message = PickPhrase(); - me->Say(Message.c_str(), LANG_UNIVERSAL, NULL); - - // Use gesture? - if (BuffEmoteCommand != 0) + if (MessageTimer <= diff) { - me->HandleEmoteCommand(BuffEmoteCommand); + if (BuffNumPhrases > 0) + { + std::string Message = PickPhrase(); + me->Say(Message.c_str(), LANG_UNIVERSAL, NULL); + } + + // Use gesture? + if (BuffEmoteCommand != 0) + { + me->HandleEmoteCommand(BuffEmoteCommand); + } + + // Alert players? + if (BuffEmoteSpell != 0) + { + me->CastSpell(me, BuffEmoteSpell); + } + + MessageTimer = urand(BuffMessageTimer, 300000); } - - // Alert players? - if (BuffEmoteSpell != 0) - { - me->CastSpell(me, BuffEmoteSpell); - } - - MessageTimer = urand(BuffMessageTimer, 300000); + else { MessageTimer -= diff; } } else {