YAPOG  0.0.1
Yet Another Pokemon Online Game
TriggerBattleMapEventAction.cpp
Go to the documentation of this file.
7 
8 #include "YAPOG/Log.hpp"
9 namespace yap
10 {
12  "ObjectEntering";
13 
15  BattleSpawnerArea& source)
17  , source_ (source)
18  {
19  }
20 
22  {
23  }
24 
26  const TriggerBattleMapEventAction& copy)
27  : BaseMapEventAction (copy)
28  , source_ (copy.source_)
29  {
30  }
31 
33  {
34  return new TriggerBattleMapEventAction (*this);
35  }
36 
38  {
40 
41  switch (GetContextType ())
42  {
44 
45  visitable.OnMovedEvent ().AddHandler (
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 
65 
66  break;
67 
69 
70  visitable.OnMovedEvent ().RemoveHandler (
73  source_.GetWorldID ().GetValue ()));
74 
75  break;
76 
77  default: break;
78  }
79  }
80 
84  {
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