Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / src / bindings / universal / ScriptMgr.h
blobf374f1db961215a99b6ee0a92cd7feec34241097
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef SCRIPTMGR_H
20 #define SCRIPTMGR_H
22 //Only required includes
23 #include "../../game/CreatureAI.h"
24 #include "../../game/Creature.h"
25 #include "../../game/InstanceData.h"
27 class Player;
28 class Creature;
29 class Quest;
30 class Item;
31 class GameObject;
32 class SpellCastTargets;
33 class Map;
35 #define MAX_SCRIPTS 1000
36 #define MAX_INSTANCE_SCRIPTS 1000
38 struct Script
40 Script() :
41 pGossipHello(NULL), pQuestAccept(NULL), pGossipSelect(NULL), pGossipSelectWithCode(NULL),
42 pQuestSelect(NULL), pQuestComplete(NULL), pNPCDialogStatus(NULL), pGODialogStatus(NULL), pChooseReward(NULL),
43 pItemHello(NULL), pGOHello(NULL), pAreaTrigger(NULL), pItemQuestAccept(NULL), pGOQuestAccept(NULL),
44 pGOChooseReward(NULL), pReceiveEmote(NULL), pItemUse(NULL), GetAI(NULL)
47 std::string Name;
49 // -- Quest/gossip Methods to be scripted --
50 bool (*pGossipHello )(Player *player, Creature *_Creature);
51 bool (*pQuestAccept )(Player *player, Creature *_Creature, Quest const*_Quest );
52 bool (*pGossipSelect )(Player *player, Creature *_Creature, uint32 sender, uint32 action );
53 bool (*pGossipSelectWithCode)(Player *player, Creature *_Creature, uint32 sender, uint32 action, const char* sCode );
54 bool (*pQuestSelect )(Player *player, Creature *_Creature, Quest const*_Quest );
55 bool (*pQuestComplete )(Player *player, Creature *_Creature, Quest const*_Quest );
56 uint32 (*pNPCDialogStatus )(Player *player, Creature *_Creature );
57 uint32 (*pGODialogStatus )(Player *player, GameObject * _GO );
58 bool (*pChooseReward )(Player *player, Creature *_Creature, Quest const*_Quest, uint32 opt );
59 bool (*pItemHello )(Player *player, Item *_Item, Quest const*_Quest );
60 bool (*pGOHello )(Player *player, GameObject *_GO );
61 bool (*pAreaTrigger )(Player *player, AreaTriggerEntry* at);
62 bool (*pItemQuestAccept )(Player *player, Item *_Item, Quest const*_Quest );
63 bool (*pGOQuestAccept )(Player *player, GameObject *_GO, Quest const*_Quest );
64 bool (*pGOChooseReward )(Player *player, GameObject *_GO, Quest const*_Quest, uint32 opt );
65 bool (*pReceiveEmote )(Player *player, Creature *_Creature, uint32 emote );
66 bool (*pItemUse )(Player *player, Item* _Item, SpellCastTargets const& targets);
68 CreatureAI* (*GetAI)(Creature *_Creature);
69 // -----------------------------------------
73 class InstanceDataScript
75 public:
76 InstanceDataScript() : GetInstanceData(NULL) {};
78 std::string name;
79 InstanceData* (*GetInstanceData)(Map *_Map);
82 extern int nrscripts;
83 extern Script *m_scripts[MAX_SCRIPTS];
84 extern InstanceDataScript *m_instance_scripts[MAX_INSTANCE_SCRIPTS];
85 extern int num_inst_scripts;
87 #define VISIBLE_RANGE (50.0f)
89 struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI
91 ScriptedAI(Creature* creature) : m_creature(creature) {}
92 ~ScriptedAI() {}
94 // Called if IsVisible(Unit *who) is true at each *who move
95 void MoveInLineOfSight(Unit *) {}
97 // Called at each attack of m_creature by any victim
98 void AttackStart(Unit *) {}
100 // Called at stopping attack by any attacker
101 void EnterEvadeMode();
103 // Called at any heal cast/item used (call non implemented)
104 void HealBy(Unit* /*healer*/, uint32 /*amount_healed*/) {}
106 // Called at any Damage to any victim (before damage apply)
107 void DamageDeal(Unit* /*done_to*/, uint32& /*damage*/) {}
109 // Called at any Damage from any attacker (before damage apply)
110 void DamageTaken(Unit* /*done_by*/, uint32& /*damage*/) {}
112 // Is unit visible for MoveInLineOfSight
113 bool IsVisible(Unit* who) const
115 return !who->HasStealthAura() && m_creature->GetDistance(who) <= VISIBLE_RANGE;
118 // Called at World update tick
119 void UpdateAI(const uint32);
121 // Called when the creature is killed
122 void JustDied(Unit *){}
124 // Called when the creature kills a unit
125 void KilledUnit(Unit *){}
127 // Called when hit by a spell
128 void SpellHit(Unit *, const SpellEntry*){}
130 Creature* m_creature;
132 //= Some useful helpers =========================
134 // Start attack of victim and go to him
135 void DoStartAttack(Unit* victim);
137 // Stop attack of current victim
138 void DoStopAttack();
140 // Cast spell
141 void DoCast(Unit* victim, uint32 spelId)
143 m_creature->CastSpell(victim,spelId,true);
146 void DoCastSpell(Unit* who,SpellEntry *spellInfo)
148 m_creature->CastSpell(who,spellInfo,true);
151 void DoSay(char const* text, uint32 language)
153 m_creature->Say(text,language,0);
156 void DoGoHome();
159 #endif