root/trunk/src/bindings/interface/ScriptMgr.h @ 2

Revision 2, 5.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef SCRIPTMGR_H
20#define SCRIPTMGR_H
21
22//Only required includes
23#include "../../game/CreatureAI.h"
24#include "../../game/Creature.h"
25#include "../../game/InstanceData.h"
26
27class Player;
28class Creature;
29class Quest;
30class Item;
31class GameObject;
32class SpellCastTargets;
33class Map;
34
35#define MAX_SCRIPTS 1000
36#define MAX_INSTANCE_SCRIPTS 1000
37
38struct Script
39{
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)
45        {}
46
47    std::string Name;
48
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);
67
68    CreatureAI* (*GetAI)(Creature *_Creature);
69    // -----------------------------------------
70
71};
72
73class InstanceDataScript
74{
75    public:
76        InstanceDataScript() : GetInstanceData(NULL) {};
77
78        std::string name;
79        InstanceData* (*GetInstanceData)(Map *_Map);
80};
81
82extern int nrscripts;
83extern Script *m_scripts[MAX_SCRIPTS];
84extern InstanceDataScript *m_instance_scripts[MAX_INSTANCE_SCRIPTS];
85extern int num_inst_scripts;
86
87#define VISIBLE_RANGE (50.0f)
88
89struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI
90{
91    ScriptedAI(Creature* creature) : m_creature(creature) {}
92    ~ScriptedAI() {}
93
94    // Called if IsVisible(Unit *who) is true at each *who move
95    void MoveInLineOfSight(Unit *) {}
96
97    // Called at each attack of m_creature by any victim
98    void AttackStart(Unit *) {}
99
100    // Called at stopping attack by any attacker
101    void EnterEvadeMode();
102
103    // Called at any heal cast/item used (call non implemented)
104    void HealBy(Unit* /*healer*/, uint32 /*amount_healed*/) {}
105
106    // Called at any Damage to any victim (before damage apply)
107    void DamageDeal(Unit* /*done_to*/, uint32& /*damage*/) {}
108
109    // Called at any Damage from any attacker (before damage apply)
110    void DamageTaken(Unit* /*done_by*/, uint32& /*damage*/) {}
111
112    // Is unit visible for MoveInLineOfSight
113    bool IsVisible(Unit* who) const
114    {
115        return !who->HasStealthAura() && m_creature->GetDistance(who) <= VISIBLE_RANGE;
116    }
117
118    // Called at World update tick
119    void UpdateAI(const uint32);
120
121    // Called when the creature is killed
122    void JustDied(Unit *){}
123
124    // Called when the creature kills a unit
125    void KilledUnit(Unit *){}
126
127    // Called when hit by a spell
128    void SpellHit(Unit *, const SpellEntry*){}
129
130    Creature* m_creature;
131
132    //= Some useful helpers =========================
133
134    // Start attack of victim and go to him
135    void DoStartAttack(Unit* victim);
136
137    // Stop attack of current victim
138    void DoStopAttack();
139
140    // Cast spell
141    void DoCast(Unit* victim, uint32 spelId)
142    {
143        m_creature->CastSpell(victim,spelId,true);
144    }
145
146    void DoCastSpell(Unit* who,SpellEntry *spellInfo)
147    {
148        m_creature->CastSpell(who,spellInfo,true);
149    }
150
151    void DoSay(char const* text, uint32 language)
152    {
153        m_creature->Say(text,language,0);
154    }
155
156    void DoGoHome();
157};
158
159#endif
Note: See TracBrowser for help on using the browser.