TrinityCore
garrison_generic.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "AreaTrigger.h"
19#include "AreaTriggerAI.h"
20#include "Garrison.h"
21#include "Map.h"
22#include "Player.h"
23#include "ScriptMgr.h"
24#include "Unit.h"
25
26// XX - Garrison enter AreaTrigger
28{
29 at_garrison_enter(AreaTrigger* areatrigger) : AreaTriggerAI(areatrigger) { }
30
31 void OnInitialize() override
32 {
33 at->setActive(true); // has to be active, otherwise the at is no longer updated before we are able to leave it
34 }
35
36 void OnUnitEnter(Unit* unit) override
37 {
38 Player* player = unit->ToPlayer();
39 if (!player)
40 return;
41
42 Garrison* garrison = player->GetGarrison();
43 if (!garrison)
44 return;
45
46 garrison->Enter();
47 }
48};
49
50// XX - Garrison exit AreaTrigger
52{
53 at_garrison_exit(AreaTrigger* areatrigger) : AreaTriggerAI(areatrigger) { }
54
55 void OnInitialize() override
56 {
57 at->setActive(true); // has to be active, otherwise the at is no longer updated before we are able to leave it
58 }
59
60 void OnUnitExit(Unit* unit) override
61 {
62 Player* player = unit->ToPlayer();
63 if (!player)
64 return;
65
66 Garrison* garrison = player->GetGarrison();
67 if (!garrison)
68 return;
69
70 garrison->Leave();
71 }
72};
73
75{
76 // AreaTrigger
79}
#define RegisterAreaTriggerAI(ai_name)
Definition: ScriptMgr.h:1416
AreaTrigger *const at
Definition: AreaTriggerAI.h:33
void Enter() const
Definition: Garrison.cpp:287
void Leave() const
Definition: Garrison.cpp:300
static Player * ToPlayer(Object *o)
Definition: Object.h:213
Garrison * GetGarrison() const
Definition: Player.h:2710
Definition: Unit.h:627
void setActive(bool isActiveObject)
Definition: Object.cpp:922
void AddSC_garrison_generic()
void OnInitialize() override
void OnUnitEnter(Unit *unit) override
at_garrison_enter(AreaTrigger *areatrigger)
at_garrison_exit(AreaTrigger *areatrigger)
void OnUnitExit(Unit *unit) override
void OnInitialize() override