Guest User

Untitled

a guest
Dec 15th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.76 KB | None | 0 0
  1. #include "ScriptMgr.h"
  2. #include "ScriptedCreature.h"
  3. #include "ScriptedGossip.h"
  4.  
  5. // **** This script is designed as an example for others to build on ****
  6. // **** Please modify whatever you'd like to as this script is only for developement ****
  7.  
  8. // **** Script Info* ***
  9. // This script is written in a way that it can be used for both friendly and hostile monsters
  10. // Its primary purpose is to show just how much you can really do with scripts
  11. // I recommend trying it out on both an agressive NPC and on friendly npc
  12.  
  13. // **** Quick Info* ***
  14. // Functions with Handled Function marked above them are functions that are called automatically by the core
  15. // Functions that are marked Custom Function are functions I've created to simplify code
  16.  
  17. enum Yells
  18. {
  19. //List of text id's. The text is stored in database, also in a localized version
  20. //(if translation not exist for the textId, default english text will be used)
  21. //Not required to define in this way, but simplify if changes are needed.
  22. SAY_AGGRO = -1999900,
  23. SAY_RANDOM_0 = -1999901,
  24. SAY_RANDOM_1 = -1999902,
  25. SAY_RANDOM_2 = -1999903,
  26. SAY_RANDOM_3 = -1999904,
  27. SAY_RANDOM_4 = -1999905,
  28. SAY_BERSERK = -1999906,
  29. SAY_PHASE = -1999907,
  30. SAY_DANCE = -1999908,
  31. SAY_SALUTE = -1999909,
  32. SAY_EVADE = -1999910,
  33. };
  34.  
  35. enum Spells
  36. {
  37. // List of spells.
  38. // Not required to define them in this way, but will make it easier to maintain in case spellId change
  39. SPELL_BUFF = 25661,
  40. SPELL_ONE = 12555,
  41. SPELL_ONE_ALT = 24099,
  42. SPELL_TWO = 10017,
  43. SPELL_THREE = 26027,
  44. SPELL_FRENZY = 23537,
  45. SPELL_BERSERK = 32965,
  46. };
  47.  
  48. enum eEnums
  49. {
  50. // any other constants
  51. FACTION_WORGEN = 24
  52. };
  53.  
  54. //List of gossip item texts. Items will appear in the gossip window.
  55. #define GOSSIP_ITEM "I'm looking for a fight"
  56.  
  57. class example_creature : public CreatureScript
  58. {
  59. public:
  60.  
  61. example_creature()
  62. : CreatureScript("example_creature")
  63. {
  64. }
  65.  
  66. struct example_creatureAI : public ScriptedAI
  67. {
  68. // *** HANDLED FUNCTION ***
  69. //This is the constructor, called only once when the Creature is first created
  70. example_creatureAI(Creature* creature) : ScriptedAI(creature) {}
  71.  
  72. // *** CUSTOM VARIABLES ****
  73. //These variables are for use only by this individual script.
  74. //Nothing else will ever call them but us.
  75.  
  76. uint32 m_uiSayTimer; // Timer for random chat
  77. uint32 m_uiRebuffTimer; // Timer for rebuffing
  78. uint32 m_uiSpell1Timer; // Timer for spell 1 when in combat
  79. uint32 m_uiSpell2Timer; // Timer for spell 1 when in combat
  80. uint32 m_uiSpell3Timer; // Timer for spell 1 when in combat
  81. uint32 m_uiBeserkTimer; // Timer until we go into Beserk (enraged) mode
  82. uint32 m_uiPhase; // The current battle phase we are in
  83. uint32 m_uiPhaseTimer; // Timer until phase transition
  84.  
  85. // *** HANDLED FUNCTION ***
  86. //This is called after spawn and whenever the core decides we need to evade
  87. void Reset()
  88. {
  89. m_uiPhase = 1; // Start in phase 1
  90. m_uiPhaseTimer = 60000; // 60 seconds
  91. m_uiSpell1Timer = 5000; // 5 seconds
  92. m_uiSpell2Timer = urand(10000, 20000); // between 10 and 20 seconds
  93. m_uiSpell3Timer = 19000; // 19 seconds
  94. m_uiBeserkTimer = 120000; // 2 minutes
  95.  
  96. me->RestoreFaction();
  97. }
  98.  
  99. // *** HANDLED FUNCTION ***
  100. // Enter Combat called once per combat
  101. void EnterCombat(Unit* who)
  102. {
  103. //Say some stuff
  104. DoScriptText(SAY_AGGRO, me, who);
  105. }
  106.  
  107. // *** HANDLED FUNCTION ***
  108. // Attack Start is called when victim change (including at start of combat)
  109. // By default, attack who and start movement toward the victim.
  110. //void AttackStart(Unit* who)
  111. //{
  112. // ScriptedAI::AttackStart(who);
  113. //}
  114.  
  115. // *** HANDLED FUNCTION ***
  116. // Called when going out of combat. Reset is called just after.
  117. void EnterEvadeMode()
  118. {
  119. DoScriptText(SAY_EVADE, me);
  120. }
  121.  
  122. // *** HANDLED FUNCTION ***
  123. //Our Receive emote function
  124. void ReceiveEmote(Player* /*player*/, uint32 uiTextEmote)
  125. {
  126. me->HandleEmoteCommand(uiTextEmote);
  127.  
  128. switch (uiTextEmote)
  129. {
  130. case TEXT_EMOTE_DANCE:
  131. DoScriptText(SAY_DANCE, me);
  132. break;
  133. case TEXT_EMOTE_SALUTE:
  134. DoScriptText(SAY_SALUTE, me);
  135. break;
  136. }
  137. }
  138.  
  139. // *** HANDLED FUNCTION ***
  140. //Update AI is called Every single map update (roughly once every 50ms if a player is within the grid)
  141. void UpdateAI(const uint32 uiDiff)
  142. {
  143. //Out of combat timers
  144. if (!me->getVictim())
  145. {
  146. //Random Say timer
  147. if (m_uiSayTimer <= uiDiff)
  148. {
  149. //Random switch between 5 outcomes
  150. DoScriptText(RAND(SAY_RANDOM_0, SAY_RANDOM_1, SAY_RANDOM_2, SAY_RANDOM_3, SAY_RANDOM_4), me);
  151.  
  152. m_uiSayTimer = 45000; //Say something agian in 45 seconds
  153. }
  154. else
  155. m_uiSayTimer -= uiDiff;
  156.  
  157. //Rebuff timer
  158. if (m_uiRebuffTimer <= uiDiff)
  159. {
  160. DoCast(me, SPELL_BUFF);
  161. m_uiRebuffTimer = 900000; //Rebuff agian in 15 minutes
  162. }
  163. else
  164. m_uiRebuffTimer -= uiDiff;
  165. }
  166.  
  167. //Return since we have no target
  168. if (!UpdateVictim())
  169. return;
  170.  
  171. //Spell 1 timer
  172. if (m_uiSpell1Timer <= uiDiff)
  173. {
  174. //Cast spell one on our current target.
  175. if (rand()%50 > 10)
  176. DoCast(me->getVictim(), SPELL_ONE_ALT);
  177. else if (me->IsWithinDist(me->getVictim(), 25.0f))
  178. DoCast(me->getVictim(), SPELL_ONE);
  179.  
  180. m_uiSpell1Timer = 5000;
  181. }
  182. else
  183. m_uiSpell1Timer -= uiDiff;
  184.  
  185. //Spell 2 timer
  186. if (m_uiSpell2Timer <= uiDiff)
  187. {
  188. //Cast spell two on our current target.
  189. DoCast(me->getVictim(), SPELL_TWO);
  190. m_uiSpell2Timer = 37000;
  191. }
  192. else
  193. m_uiSpell2Timer -= uiDiff;
  194.  
  195. //Beserk timer
  196. if (m_uiPhase > 1)
  197. {
  198. //Spell 3 timer
  199. if (m_uiSpell3Timer <= uiDiff)
  200. {
  201. //Cast spell one on our current target.
  202. DoCast(me->getVictim(), SPELL_THREE);
  203.  
  204. m_uiSpell3Timer = 19000;
  205. }
  206. else
  207. m_uiSpell3Timer -= uiDiff;
  208.  
  209. if (m_uiBeserkTimer <= uiDiff)
  210. {
  211. //Say our line then cast uber death spell
  212. DoScriptText(SAY_BERSERK, me, me->getVictim());
  213. DoCast(me->getVictim(), SPELL_BERSERK);
  214.  
  215. //Cast our beserk spell agian in 12 seconds if we didn't kill everyone
  216. m_uiBeserkTimer = 12000;
  217. }
  218. else
  219. m_uiBeserkTimer -= uiDiff;
  220. }
  221. else if (m_uiPhase == 1) //Phase timer
  222. {
  223. if (m_uiPhaseTimer <= uiDiff)
  224. {
  225. //Go to next phase
  226. ++m_uiPhase;
  227. DoScriptText(SAY_PHASE, me);
  228. DoCast(me, SPELL_FRENZY);
  229. }
  230. else
  231. m_uiPhaseTimer -= uiDiff;
  232. }
  233.  
  234. DoMeleeAttackIfReady();
  235. }
  236. };
  237.  
  238. CreatureAI* GetAI(Creature* creature) const
  239. {
  240. return new example_creatureAI(creature);
  241. }
  242.  
  243. bool OnGossipHello(Player* player, Creature* creature)
  244. {
  245. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_ITEM, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
  246. player->SEND_GOSSIP_MENU(907, creature->GetGUID());
  247.  
  248. return true;
  249. }
  250.  
  251. bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 action)
  252. {
  253. player->PlayerTalkClass->ClearMenus();
  254. if (action == GOSSIP_ACTION_INFO_DEF+1)
  255. {
  256. player->CLOSE_GOSSIP_MENU();
  257. //Set our faction to hostile towards all
  258. creature->setFaction(FACTION_WORGEN);
  259. creature->AI()->AttackStart(player);
  260. }
  261.  
  262. return true;
  263. }
  264. };
  265.  
  266. //This is the actual function called only once durring InitScripts()
  267. //It must define all handled functions that are to be run in this script
  268. void AddSC_example_creature()
  269. {
  270. new example_creature();
  271. }
Add Comment
Please, Sign In to add comment