Skip to content

Commit

Permalink
Fix crashes and make options work (#21)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
anzz1 and pangolp authored Mar 27, 2024
1 parent 6adbad1 commit 0888f37
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 67 deletions.
10 changes: 5 additions & 5 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 5 additions & 11 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
@@ -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/)._
Expand Down
25 changes: 25 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- First of all, THANK YOU for your contribution. -->

## Changes Proposed:
-
-

## Issues Addressed:
<!-- If your fix has a relating issue, link it below -->
- Closes

## SOURCE:
<!-- If you can, include a source that can strengthen your claim -->

## Tests Performed:
<!-- Does it build without errors? Did you test in-game? What did you test? On which OS did you test? Describe any other tests performed -->
-
-


## How to Test the Changes:
<!-- Describe in a detailed step-by-step order how to test the changes -->

1.
2.
3.
9 changes: 0 additions & 9 deletions conf/conf.sh.dist

This file was deleted.

9 changes: 9 additions & 0 deletions conf/npc_buffer.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,6 +58,7 @@ Buff.MessageTimer = 60000
# -------------------------------------------------------------------------------------
# How many pharases does the NPC have?
# Default: 3
# Disable: 0
# -------------------------------------------------------------------------------------
Buff.NumPhrases = 4

Expand All @@ -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

Expand Down
File renamed without changes.
9 changes: 0 additions & 9 deletions include.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions sql/world/updates/2022_05_24_00.sql

This file was deleted.

3 changes: 2 additions & 1 deletion src/NB_loader.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
void AddNPCBufferScripts();

void Addmod_npc_bufferScripts() {
void Addmod_npc_bufferScripts()
{
AddNPCBufferScripts();
}
70 changes: 44 additions & 26 deletions src/npc_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -86,14 +87,15 @@ class BufferConfig : public WorldScript

void OnBeforeConfigLoad(bool /*reload*/) override
{
BFEnableModule = sConfigMgr->GetOption<bool>("Buff.Enable", 1);
BFAnnounceModule = sConfigMgr->GetOption<bool>("Buff.Announce", 1);
BuffByLevel = sConfigMgr->GetOption<bool>("Buff.ByLevel", 1);
BuffCureRes = sConfigMgr->GetOption<bool>("Buff.CureRes", 1);
BuffNumPhrases = sConfigMgr->GetOption<int>("Buff.NumPhrases", 3);
BuffNumWhispers = sConfigMgr->GetOption<int>("Buff.NumWhispers", 3);
BuffMessageTimer = sConfigMgr->GetOption<int>("Buff.MessageTimer", 60000);
BuffEmoteSpell = sConfigMgr->GetOption<int>("Buff.EmoteSpell", 44940);
BuffEmoteCommand = sConfigMgr->GetOption<int>("Buff.EmoteCommand", 3);
BuffNumPhrases = sConfigMgr->GetOption<uint32>("Buff.NumPhrases", 3);
BuffNumWhispers = sConfigMgr->GetOption<uint32>("Buff.NumWhispers", 3);
BuffMessageTimer = sConfigMgr->GetOption<uint32>("Buff.MessageTimer", 60000);
BuffEmoteSpell = sConfigMgr->GetOption<uint32>("Buff.EmoteSpell", 44940);
BuffEmoteCommand = sConfigMgr->GetOption<uint32>("Buff.EmoteCommand", 3);

// Enforce Min/Max Time
if (BuffMessageTimer != 0)
Expand All @@ -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.");
}
Expand All @@ -124,7 +125,6 @@ class BufferAnnounce : public PlayerScript

class buff_npc : public CreatureScript
{

public:
buff_npc() : CreatureScript("buff_npc") {}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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
{
Expand Down

0 comments on commit 0888f37

Please sign in to comment.