YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
TriggerBattleMapEventAction.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Game/World/Map/TriggerBattleMapEventAction.hpp
"
2
#include "
YAPOG/Game/World/Map/BattleSpawnerArea.hpp
"
3
#include "
YAPOG/Game/World/Map/MapEventArgs.hpp
"
4
#include "
YAPOG/Game/World/Map/IPlayer.hpp
"
5
#include "
YAPOG/System/StringHelper.hpp
"
6
#include "
YAPOG/System/RandomHelper.hpp
"
7
8
#include "
YAPOG/Log.hpp
"
9
namespace
yap
10
{
11
const
String
TriggerBattleMapEventAction::OBJECT_ENTERING_HANDLER_NAME
=
12
"ObjectEntering"
;
13
14
TriggerBattleMapEventAction::TriggerBattleMapEventAction
(
15
BattleSpawnerArea
& source)
16
:
BaseMapEventAction
()
17
, source_ (source)
18
{
19
}
20
21
TriggerBattleMapEventAction::~TriggerBattleMapEventAction
()
22
{
23
}
24
25
TriggerBattleMapEventAction::TriggerBattleMapEventAction
(
26
const
TriggerBattleMapEventAction
& copy)
27
:
BaseMapEventAction
(copy)
28
, source_ (copy.source_)
29
{
30
}
31
32
TriggerBattleMapEventAction
*
TriggerBattleMapEventAction::Clone
()
const
33
{
34
return
new
TriggerBattleMapEventAction
(*
this
);
35
}
36
37
void
TriggerBattleMapEventAction::VisitPlayer
(
IPlayer
& visitable)
38
{
39
yap::BaseMapEventAction::VisitPlayer
(visitable);
40
41
switch
(
GetContextType
())
42
{
43
case
MapEventActionType::Enter
:
44
45
visitable.
OnMovedEvent
().
AddHandler
(
46
OBJECT_ENTERING_HANDLER_NAME
+
47
yap::StringHelper::ToString
(
48
source_
.
GetWorldID
().
GetValue
()),
49
[&] (
50
DynamicWorldObject
& sender,
51
const
Vector2
& args)
52
{
53
if
(!
TriggerBattle
(args))
54
return
false
;
55
56
GetArgs
().
AbortEvents
();
57
visitable.
TriggerBattle
();
58
59
return
true
;
60
});
61
62
break
;
63
64
case
MapEventActionType::In
:
65
66
break
;
67
68
case
MapEventActionType::Leave
:
69
70
visitable.
OnMovedEvent
().
RemoveHandler
(
71
OBJECT_ENTERING_HANDLER_NAME
+
72
yap::StringHelper::ToString
(
73
source_
.
GetWorldID
().
GetValue
()));
74
75
break
;
76
77
default
:
break
;
78
}
79
}
80
81
const
int
BATTLE_TRIGGERING_RANDOM_RANGE
= 2550;
82
const
int
BATTLE_TRIGGERING_RANDOM_DRANGE
= 400;
83
bool
TriggerBattleMapEventAction::TriggerBattle
(
const
Vector2
& offset)
84
{
85
int
dRange =
RandomHelper::GetNext
(1,
BATTLE_TRIGGERING_RANDOM_DRANGE
);
86
int
range =
RandomHelper::GetNext
(1,
BATTLE_TRIGGERING_RANDOM_RANGE
);
87
88
int
gRange = range + dRange;
89
90
gRange *= offset.x + offset.y;
91
92
return
93
RandomHelper::GetNext
(1, gRange) ==
94
RandomHelper::GetNext
(1, gRange);
95
}
96
}
// namespace yap
YAPOG
src
YAPOG
Game
World
Map
TriggerBattleMapEventAction.cpp
Generated on Mon Sep 17 2012 22:24:25 for YAPOG by
1.8.1.1