diff options
| author | Trazom62 <none@none> | 2010-02-07 13:06:03 +0100 | 
|---|---|---|
| committer | Trazom62 <none@none> | 2010-02-07 13:06:03 +0100 | 
| commit | 5bdbb5e6d140d2daa4cff483fa574117f42fb2ec (patch) | |
| tree | 9277964234bfa34f8ef1e2acd665538d89e30a09 /src | |
| parent | 32ef5836163bc2d4f6270edf0a449d8e3d08a5cd (diff) | |
Fix creature script example to be conform to Trinity code standards.
--HG--
branch : trunk
Diffstat (limited to 'src')
| -rw-r--r-- | src/scripts/examples/example_creature.cpp | 160 | 
1 files changed, 94 insertions, 66 deletions
| diff --git a/src/scripts/examples/example_creature.cpp b/src/scripts/examples/example_creature.cpp index 3bce98e30ea..41cc0217132 100644 --- a/src/scripts/examples/example_creature.cpp +++ b/src/scripts/examples/example_creature.cpp @@ -22,6 +22,7 @@ SDCategory: Script Examples  EndScriptData */  #include "ScriptedPch.h" +#include "SpellId.h"  // **** This script is designed as an example for others to build on ****  // **** Please modify whatever you'd like to as this script is only for developement **** @@ -35,32 +36,41 @@ EndScriptData */  // Functions with Handled Function marked above them are functions that are called automatically by the core  // Functions that are marked Custom Function are functions I've created to simplify code -enum eEnums +enum Yells  {      //List of text id's. The text is stored in database, also in a localized version      //(if translation not exist for the textId, default english text will be used)      //Not required to define in this way, but simplify if changes are needed. -    SAY_AGGRO       = -1999900, -    SAY_RANDOM_0    = -1999901, -    SAY_RANDOM_1    = -1999902, -    SAY_RANDOM_2    = -1999903, -    SAY_RANDOM_3    = -1999904, -    SAY_RANDOM_4    = -1999905, -    SAY_BESERK      = -1999906, -    SAY_PHASE       = -1999907, -    SAY_DANCE       = -1999908, -    SAY_SALUTE      = -1999909, - -    //List of spells. Not required to define them in this way, but will make it easier to maintain in case spellId change -    SPELL_BUFF      = 25661, -    SPELL_ONE       = 12555, -    SPELL_ONE_ALT   = 24099, -    SPELL_TWO       = 10017, -    SPELL_THREE     = 26027, -    SPELL_ENRAGE    = 23537, -    SPELL_BESERK    = 32309, - -    FACTION_WORGEN  = 24 +    SAY_AGGRO                                   = -1999900, +    SAY_RANDOM_0                                = -1999901, +    SAY_RANDOM_1                                = -1999902, +    SAY_RANDOM_2                                = -1999903, +    SAY_RANDOM_3                                = -1999904, +    SAY_RANDOM_4                                = -1999905, +    SAY_BERSERK                                 = -1999906, +    SAY_PHASE                                   = -1999907, +    SAY_DANCE                                   = -1999908, +    SAY_SALUTE                                  = -1999909, +    SAY_EVADE                                   = -1999910, +}; + +enum Spells +{ +    // List of spells.  +    // Not required to define them in this way, but will make it easier to maintain in case spellId change +    SPELL_BUFF                                  = SPELL_INCREASED_STAMINA_25661, +    SPELL_ONE                                   = SPELL_PUMMEL_12555, +    SPELL_ONE_ALT                               = SPELL_POISON_BOLT_VOLLEY_24099, +    SPELL_TWO                                   = SPELL_FROST_HOLD_10017, +    SPELL_THREE                                 = SPELL_KNOCKBACK_26027, +    SPELL_FRENZY                                = SPELL_FRENZY_23537, +    SPELL_BERSERK                               = SPELL_BERSERK_32965, +}; + +enum eEnums +{ +    // any other constants +    FACTION_WORGEN                              = 24  };  //List of gossip item texts. Items will appear in the gossip window. @@ -70,42 +80,60 @@ struct example_creatureAI : public ScriptedAI  {      //*** HANDLED FUNCTION ***      //This is the constructor, called only once when the Creature is first created -    example_creatureAI(Creature *c) : ScriptedAI(c) {Reset();} +    example_creatureAI(Creature *c) : ScriptedAI(c) {}      //*** CUSTOM VARIABLES ****      //These variables are for use only by this individual script.      //Nothing else will ever call them but us. -    uint32 m_uiSay_Timer;                                   //Timer for random chat -    uint32 m_uiRebuff_Timer;                                //Timer for rebuffing -    uint32 m_uiSpell_1_Timer;                               //Timer for spell 1 when in combat -    uint32 m_uiSpell_2_Timer;                               //Timer for spell 1 when in combat -    uint32 m_uiSpell_3_Timer;                               //Timer for spell 1 when in combat -    uint32 m_uiBeserk_Timer;                                //Timer until we go into Beserk (enraged) mode -    uint32 m_uiPhase;                                       //The current battle phase we are in -    uint32 m_uiPhase_Timer;                                 //Timer until phase transition +    uint32 m_uiSayTimer;                                    // Timer for random chat +    uint32 m_uiRebuffTimer;                                 // Timer for rebuffing +    uint32 m_uiSpell1Timer;                                 // Timer for spell 1 when in combat +    uint32 m_uiSpell2Timer;                                 // Timer for spell 1 when in combat +    uint32 m_uiSpell3Timer;                                 // Timer for spell 1 when in combat +    uint32 m_uiBeserkTimer;                                 // Timer until we go into Beserk (enraged) mode +    uint32 m_uiPhase;                                       // The current battle phase we are in +    uint32 m_uiPhaseTimer;                                  // Timer until phase transition      //*** HANDLED FUNCTION *** -    //This is called whenever the core decides we need to evade +    //This is called after spawn and whenever the core decides we need to evade      void Reset()      { -        m_uiPhase = 1;                                      //Start in phase 1 -        m_uiPhase_Timer = 60000;                            //60 seconds -        m_uiSpell_1_Timer = 5000;                           //5 seconds -        m_uiSpell_2_Timer = 37000;                          //37 seconds -        m_uiSpell_3_Timer = 19000;                          //19 seconds -        m_uiBeserk_Timer = 120000;                          //2 minutes +        m_uiPhase = 1;                                      // Start in phase 1 +        m_uiPhaseTimer = 60000;                             // 60 seconds +        m_uiSpell1Timer = 5000;                             //  5 seconds +        m_uiSpell2Timer = urand(10000,20000);               // between 10 and 20 seconds +        m_uiSpell3Timer = 19000;                            // 19 seconds +        m_uiBeserkTimer = 120000;                           //  2 minutes + +        m_creature->RestoreFaction();      }      //*** HANDLED FUNCTION *** -    //Attack Start is called whenever someone hits us. +    // Enter Combat called once per combat      void EnterCombat(Unit* pWho)      {          //Say some stuff          DoScriptText(SAY_AGGRO, m_creature, pWho);      } -    //Our Recive emote function +    //*** HANDLED FUNCTION *** +    // Attack Start is called when victim change (including at start of combat) +    // By default, attack pWho and start movement toward the victim. +    //void AttackStart(Unit* pWho) +    //{ +    //    ScriptedAI::AttackStart(pWho); +    //} + +    //*** HANDLED FUNCTION *** +    // Called when going out of combat. Reset is called just after. +    void EnterEvadeMode() +    { +        DoScriptText(SAY_EVADE, m_creature); +    } + +    //*** HANDLED FUNCTION *** +    //Our Receive emote function      void ReceiveEmote(Player* pPlayer, uint32 uiTextEmote)      {          m_creature->HandleEmoteCommand(uiTextEmote); @@ -122,31 +150,31 @@ struct example_creatureAI : public ScriptedAI       }      //*** HANDLED FUNCTION *** -    //Update AI is called Every single map update (roughly once every 100ms if a player is within the grid) +    //Update AI is called Every single map update (roughly once every 50ms if a player is within the grid)      void UpdateAI(const uint32 uiDiff)      {          //Out of combat timers          if (!m_creature->getVictim())          {              //Random Say timer -            if (m_uiSay_Timer <= uiDiff) +            if (m_uiSayTimer <= uiDiff)              {                  //Random switch between 5 outcomes                  DoScriptText(RAND(SAY_RANDOM_0,SAY_RANDOM_1,SAY_RANDOM_2,SAY_RANDOM_3,SAY_RANDOM_4), m_creature); -                m_uiSay_Timer = 45000;                      //Say something agian in 45 seconds +                m_uiSayTimer = 45000;                      //Say something agian in 45 seconds              }              else -                m_uiSay_Timer -= uiDiff; +                m_uiSayTimer -= uiDiff;              //Rebuff timer -            if (m_uiRebuff_Timer <= uiDiff) +            if (m_uiRebuffTimer <= uiDiff)              {                  DoCast(m_creature, SPELL_BUFF); -                m_uiRebuff_Timer = 900000;                  //Rebuff agian in 15 minutes +                m_uiRebuffTimer = 900000;                  //Rebuff agian in 15 minutes              }              else -                m_uiRebuff_Timer -= uiDiff; +                m_uiRebuffTimer -= uiDiff;          }          //Return since we have no target @@ -154,7 +182,7 @@ struct example_creatureAI : public ScriptedAI              return;          //Spell 1 timer -        if (m_uiSpell_1_Timer <= uiDiff) +        if (m_uiSpell1Timer <= uiDiff)          {              //Cast spell one on our current target.              if (rand()%50 > 10) @@ -162,58 +190,58 @@ struct example_creatureAI : public ScriptedAI              else if (m_creature->IsWithinDist(m_creature->getVictim(), 25.0f))                  DoCast(m_creature->getVictim(), SPELL_ONE); -            m_uiSpell_1_Timer = 5000; +            m_uiSpell1Timer = 5000;          }          else -            m_uiSpell_1_Timer -= uiDiff; +            m_uiSpell1Timer -= uiDiff;          //Spell 2 timer -        if (m_uiSpell_2_Timer <= uiDiff) +        if (m_uiSpell2Timer <= uiDiff)          { -            //Cast spell one on our current target. +            //Cast spell two on our current target.              DoCast(m_creature->getVictim(), SPELL_TWO); -            m_uiSpell_2_Timer = 37000; +            m_uiSpell2Timer = 37000;          }          else -            m_uiSpell_2_Timer -= uiDiff; +            m_uiSpell2Timer -= uiDiff;          //Beserk timer          if (m_uiPhase > 1)          {              //Spell 3 timer -            if (m_uiSpell_3_Timer <= uiDiff) +            if (m_uiSpell3Timer <= uiDiff)              {                  //Cast spell one on our current target.                  DoCast(m_creature->getVictim(), SPELL_THREE); -                m_uiSpell_3_Timer = 19000; +                m_uiSpell3Timer = 19000;              }              else -                m_uiSpell_3_Timer -= uiDiff; +                m_uiSpell3Timer -= uiDiff; -            if (m_uiBeserk_Timer <= uiDiff) +            if (m_uiBeserkTimer <= uiDiff)              {                  //Say our line then cast uber death spell -                DoScriptText(SAY_BESERK, m_creature, m_creature->getVictim()); -                DoCast(m_creature->getVictim(), SPELL_BESERK); +                DoScriptText(SAY_BERSERK, m_creature, m_creature->getVictim()); +                DoCast(m_creature->getVictim(), SPELL_BERSERK);                  //Cast our beserk spell agian in 12 seconds if we didn't kill everyone -                m_uiBeserk_Timer = 12000; +                m_uiBeserkTimer = 12000;              }              else -                m_uiBeserk_Timer -= uiDiff; +                m_uiBeserkTimer -= uiDiff;          }          else if (m_uiPhase == 1)                            //Phase timer          { -            if (m_uiPhase_Timer <= uiDiff) +            if (m_uiPhaseTimer <= uiDiff)              {                  //Go to next phase                  ++m_uiPhase;                  DoScriptText(SAY_PHASE, m_creature); -                DoCast(m_creature, SPELL_ENRAGE); +                DoCast(m_creature, SPELL_FRENZY);              }              else -                m_uiPhase_Timer -= uiDiff; +                m_uiPhaseTimer -= uiDiff;          }          DoMeleeAttackIfReady(); @@ -233,7 +261,7 @@ bool GossipSelect_example_creature(Player* pPlayer, Creature* pCreature, uint32      if (uiAction == GOSSIP_ACTION_INFO_DEF+1)      {          pPlayer->CLOSE_GOSSIP_MENU(); -        //Set our faction to hostile twoards all +        //Set our faction to hostile towards all          pCreature->setFaction(FACTION_WORGEN);          pCreature->AI()->AttackStart(pPlayer);      } | 
