[TrinityCore] DuelReset Script

03/13/2018 16:59 Lucky_Patcher#1
Sollte bei der aktuellen Core funktionieren.

PHP Code:
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
*
* 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 <http://www.gnu.org/licenses/>.
*/

/* --[[ Coded by CoC / Lucky_Patcher 2018 || Do not remove this Copyright || You are allowed to modify this script.]]-- */

#include "ScriptMgr.h"
#include "Config.h"
#include "Player.h"
#include "World.h"

class duel_reset : public PlayerScript
{
public:
    
duel_reset() : PlayerScript("duel_reset") { }

    
void OnDuelEnd(PlayerwinnerPlayerlooserDuelCompleteType type)
    {
        if (
sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_ON_FINISH))
        {
            if (
sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_ONLY_IN_ELWYNN_AND_DUROTAR))
            {
                if (
winner->GetZoneId() == 14 || winner->GetZoneId() == 12)
                {
                    if (
type == DUEL_WON)
                    {
                        
winner->RemoveArenaSpellCooldowns();
                        
looser->RemoveArenaSpellCooldowns();
                        
winner->SetHealth(winner->GetMaxHealth());
                        
looser->SetHealth(looser->GetMaxHealth());

                        if (
winner->getPowerType() == POWER_MANA)
                            
winner->SetPower(POWER_MANAwinner->GetMaxPower(POWER_MANA));

                        if (
looser->getPowerType() == POWER_MANA)
                            
looser->SetPower(POWER_MANAlooser->GetMaxPower(POWER_MANA));
                    }

                    
winner->HandleEmoteCommand(EMOTE_ONESHOT_DANCE);
                    
looser->HandleEmoteCommand(EMOTE_ONESHOT_SALUTE);
                }
            }
            else
            {
                if (
type == DUEL_WON)
                {
                    
winner->RemoveArenaSpellCooldowns();
                    
looser->RemoveArenaSpellCooldowns();
                    
winner->SetHealth(winner->GetMaxHealth());
                    
looser->SetHealth(looser->GetMaxHealth());

                    if (
winner->getPowerType() == POWER_MANA)
                        
winner->SetPower(POWER_MANAwinner->GetMaxPower(POWER_MANA));

                    if (
looser->getPowerType() == POWER_MANA)
                        
looser->SetPower(POWER_MANAlooser->GetMaxPower(POWER_MANA));
                }

                
winner->HandleEmoteCommand(EMOTE_ONESHOT_DANCE);
                
looser->HandleEmoteCommand(EMOTE_ONESHOT_SALUTE);
            }
        }
    }

    
void OnDuelStart(Playerplayer1Playerplayer2)
    {
        if (
sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_ON_START))
        {
            if (
sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_ONLY_IN_ELWYNN_AND_DUROTAR))
            {
                if (
player1->GetZoneId() == 14 || player1->GetZoneId() == 12)
                {
                    
player1->RemoveArenaSpellCooldowns();
                    
player2->RemoveArenaSpellCooldowns();
                    
player1->SetHealth(player1->GetMaxHealth());
                    
player2->SetHealth(player2->GetMaxHealth());

                    if (
sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_RESET_ENERGY_ON_START))
                    {
                        switch (
player1->getPowerType())
                        {
                        case 
POWER_MANA:
                            
player1->SetPower(POWER_MANA0);
                            break;
                        case 
POWER_RAGE:
                            
player1->SetPower(POWER_RAGE0);
                            break;
                        case 
POWER_RUNIC_POWER:
                            
player1->SetPower(POWER_RUNIC_POWER0);
                            break;
                        case 
POWER_FOCUS:
                            
player1->SetPower(POWER_FOCUS0);
                            break;
                        case 
POWER_ENERGY:
                            
player1->SetPower(POWER_ENERGY0);
                            break;
                        default:
                            break;
                        }

                        switch (
player2->getPowerType())
                        {
                        case 
POWER_MANA:
                            
player2->SetPower(POWER_MANA0);
                            break;
                        case 
POWER_RAGE:
                            
player2->SetPower(POWER_RAGE0);
                            break;
                        case 
POWER_RUNIC_POWER:
                            
player2->SetPower(POWER_RUNIC_POWER0);
                            break;
                        case 
POWER_FOCUS:
                            
player2->SetPower(POWER_FOCUS0);
                            break;
                        case 
POWER_ENERGY:
                            
player2->SetPower(POWER_ENERGY0);
                            break;
                        default:
                            break;
                        }
                    }

                    if (
sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_MAX_ENERGY_ON_START))
                    {
                        switch (
player1->getPowerType())
                        {
                        case 
POWER_MANA:
                            
player1->SetPower(POWER_MANAplayer1->GetMaxPower(POWER_MANA));
                            break;
                        case 
POWER_RAGE:
                            
player1->SetPower(POWER_RAGEplayer1->GetMaxPower(POWER_RAGE));
                            break;
                        case 
POWER_RUNIC_POWER:
                            
player1->SetPower(POWER_RUNIC_POWERplayer1->GetMaxPower(POWER_RUNIC_POWER));
                            break;
                        case 
POWER_FOCUS:
                            
player1->SetPower(POWER_FOCUSplayer1->GetMaxPower(POWER_FOCUS));
                            break;
                        case 
POWER_ENERGY:
                            
player1->SetPower(POWER_ENERGYplayer1->GetMaxPower(POWER_ENERGY));
                            break;
                        default:
                            break;
                        }

                        switch (
player2->getPowerType())
                        {
                        case 
POWER_MANA:
                            
player2->SetPower(POWER_MANAplayer2->GetMaxPower(POWER_MANA));
                            break;
                        case 
POWER_RAGE:
                            
player2->SetPower(POWER_RAGEplayer2->GetMaxPower(POWER_RAGE));
                            break;
                        case 
POWER_RUNIC_POWER:
                            
player2->SetPower(POWER_RUNIC_POWERplayer2->GetMaxPower(POWER_RUNIC_POWER));
                            break;
                        case 
POWER_FOCUS:
                            
player2->SetPower(POWER_FOCUSplayer2->GetMaxPower(POWER_FOCUS));
                            break;
                        case 
POWER_ENERGY:
                            
player2->SetPower(POWER_ENERGYplayer2->GetMaxPower(POWER_ENERGY));
                            break;
                        default:
                            break;
                        }
                    }
                }
            }
        }
    }
};

void AddSC_DuelReset()
{
    new 
duel_reset();

In der Datei World.h noch folgendes direkt über BOOL_CONFIG_VALUE_COUNT : hinzufügen.

PHP Code:
    CONFIG_DUEL_RESET_COOLDOWN_ON_START,
    
CONFIG_DUEL_RESET_COOLDOWN_ON_FINISH,
    
CONFIG_DUEL_RESET_COOLDOWN_ONLY_IN_ELWYNN_AND_DUROTAR,
    
CONFIG_DUEL_RESET_COOLDOWN_RESET_ENERGY_ON_START,
    
CONFIG_DUEL_RESET_COOLDOWN_MAX_ENERGY_ON_START
Viel Spaß damit.
03/13/2018 17:13 Ghost_1013#2
Code:
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
*
* 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 <http://www.gnu.org/licenses/>.
*/

/* --[[ Improved by Ghost_1013 || Coded by CoC / Lucky_Patcher 2018 || Do not remove this Copyright || You are allowed to modify this script.]]-- */

#include "ScriptMgr.h"
#include "Config.h"
#include "Player.h"
#include "World.h"

class duel_reset : public PlayerScript
{
public:
    duel_reset() : PlayerScript("duel_reset") { }

    void OnDuelEnd(Player* winner, Player* looser, DuelCompleteType type)
    {
        if (!sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_ON_FINISH))
        {
            return;
        }

        if (sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_ONLY_IN_ELWYNN_AND_DUROTAR) && (winner->GetZoneId() != 14 || winner->GetZoneId() != 12))
        {
            return;
        }
     
        if (type == DUEL_WON)
        {
            winner->RemoveArenaSpellCooldowns();
            looser->RemoveArenaSpellCooldowns();
            winner->SetHealth(winner->GetMaxHealth());
            looser->SetHealth(looser->GetMaxHealth());

            if (winner->getPowerType() == POWER_MANA)
                winner->SetPower(POWER_MANA, winner->GetMaxPower(POWER_MANA));

            if (looser->getPowerType() == POWER_MANA)
                looser->SetPower(POWER_MANA, looser->GetMaxPower(POWER_MANA));
        }

        winner->HandleEmoteCommand(EMOTE_ONESHOT_DANCE);
        looser->HandleEmoteCommand(EMOTE_ONESHOT_SALUTE);
    }

    void OnDuelStart(Player* player1, Player* player2)
    {
        if (!sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_ON_START))
        {
            return;
        }

        if (sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_ONLY_IN_ELWYNN_AND_DUROTAR) && (player1->GetZoneId() != 14 || player1->GetZoneId() != 12))
        {
            return;
        }

        Player* players[2] = {player1, player2};

        for(Player* player : players)
        {
            player->RemoveArenaSpellCooldowns();
            player->SetHealth(player->GetMaxHealth());

            if (sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_RESET_ENERGY_ON_START))
            {
                switch (player->getPowerType())
                {
                case POWER_MANA:
                    player->SetPower(POWER_MANA, 0);
                    break;
                case POWER_RAGE:
                    player->SetPower(POWER_RAGE, 0);
                    break;
                case POWER_RUNIC_POWER:
                    player->SetPower(POWER_RUNIC_POWER, 0);
                    break;
                case POWER_FOCUS:
                    player->SetPower(POWER_FOCUS, 0);
                    break;
                case POWER_ENERGY:
                    player->SetPower(POWER_ENERGY, 0);
                    break;
                default:
                    break;
                }
            }

            if (sWorld->getBoolConfig(CONFIG_DUEL_RESET_COOLDOWN_MAX_ENERGY_ON_START))
            {
                switch (player->getPowerType())
                {
                case POWER_MANA:
                    player->SetPower(POWER_MANA, player->GetMaxPower(POWER_MANA));
                    break;
                case POWER_RAGE:
                    player->SetPower(POWER_RAGE, player->GetMaxPower(POWER_RAGE));
                    break;
                case POWER_RUNIC_POWER:
                    player->SetPower(POWER_RUNIC_POWER, player->GetMaxPower(POWER_RUNIC_POWER));
                    break;
                case POWER_FOCUS:
                    player->SetPower(POWER_FOCUS, player->GetMaxPower(POWER_FOCUS));
                    break;
                case POWER_ENERGY:
                    player->SetPower(POWER_ENERGY, player->GetMaxPower(POWER_ENERGY));
                    break;
                default:
                    break;
                }
            }
        }
   
        
    }
};

void AddSC_DuelReset()
{
    new duel_reset();
}
Der Code sollte äquivalent sein, ist aber leserlicher.
03/13/2018 17:21 Lucky_Patcher#3
Und das ganze nochmal erneut eingerückt entsprechend den Code Richtlinien für TrinityCore von Ghost_1013

03/15/2018 18:28 Kaev <3#4
Statt den Switches könntest du auch einfach player->SetPower(player->getPowerType(), 0); usw. machen. Macht den Code wesentlich kürzer. :)