Permalink
Browse files

Added the possibility to trigger events when opening a treasure chest.

And used it to trigger a battle when opening the chest near the cave entrance.
  • Loading branch information...
1 parent 0b6e2c3 commit 49ef8b5936e40d69defa72cbd59f06f3fbccb078 Yohann Ferreira committed Nov 1, 2012
View
14 dat/maps/layna_forest/layna_forest_north_west.lua
@@ -504,14 +504,26 @@ function _CreateObjects()
chest2:AddObject(1, 1); -- small potion
Map:AddGroundObject(chest2);
end
+
+ event = hoa_map.BattleEncounterEvent("Monster trap in chest");
+ event:SetMusic("mus/Battle_Jazz.ogg");
+ event:SetBackground("img/backdrops/battle/forest_background.png");
+ event:AddScript("dat/battles/tutorial_battle_dialogs.lua");
+ event:AddEnemy(2, 0, 0);
+ event:AddEnemy(2, 0, 0);
+ event:AddEnemy(2, 0, 0);
+ event:AddEnemy(2, 0, 0);
+ EventManager:RegisterEvent(event);
local chest3 = CreateTreasure(Map, "layna_forest_nw_chest3", "Wood_Chest1", 26, 42);
if (chest3 ~= nil) then
chest3:AddObject(40001, 1); -- prismatic ring
+ chest3:AddEvent("Monster trap in chest");
Map:AddGroundObject(chest3);
end
+
local chest4 = CreateTreasure(Map, "layna_forest_nw_chest4", "Wood_Chest1", 122, 5);
if (chest4 ~= nil) then
- -- Empty chest, it's a trap!
+ -- Empty chest, just to bother the player
Map:AddGroundObject(chest4);
end
View
12 src/modes/map/map_events.cpp
@@ -905,6 +905,12 @@ TreasureEvent::TreasureEvent(const std::string &event_id) :
void TreasureEvent::_Start()
{
+ if (_events.size() > 0) {
+ for (uint32 i = 0; i < _events.size(); ++i) {
+ MapMode::CurrentInstance()->GetEventSupervisor()->StartEvent(_events[i]);
+ }
+ }
+
MapMode::CurrentInstance()->GetTreasureSupervisor()->Initialize(_treasure);
}
@@ -921,6 +927,12 @@ bool TreasureEvent::AddObject(uint32 id, uint32 quantity)
return _treasure->AddObject(id, quantity);
}
+void TreasureEvent::AddEvent(const std::string& event_id)
+{
+ if (!event_id.empty())
+ _events.push_back(event_id);
+}
+
// -----------------------------------------------------------------------------
// ---------- EventSupervisor Class Methods
// -----------------------------------------------------------------------------
View
8 src/modes/map/map_events.h
@@ -925,10 +925,18 @@ class TreasureEvent : public MapEvent
**/
bool AddObject(uint32 id, uint32 quantity = 1);
+ /** \brief Adds an event triggered at start of the treasure event.
+ *** \param event_id The id of the event to add
+ **/
+ void AddEvent(const std::string& event_id);
+
protected:
//! \brief A pointer to the treasure content, used by the TreasureSupervisor.
MapTreasure *_treasure;
+ //! \brief Events triggered at the start of the treasure event.
+ std::vector<std::string> _events;
+
/** \brief Starts a sprite event.
***
*** This method will open the treasure dialog with the treasure content set for this event.
View
14 src/modes/map/map_objects.cpp
@@ -19,6 +19,7 @@
#include "modes/map/map.h"
#include "modes/map/map_sprites.h"
+#include "modes/map/map_events.h"
#include "common/global/global.h"
@@ -683,6 +684,13 @@ void TreasureObject::Update()
if((current_animation == TREASURE_OPENING_ANIM) && (animations[TREASURE_OPENING_ANIM].IsLoopsFinished())) {
SetCurrentAnimation(TREASURE_OPEN_ANIM);
+
+ // Trigger potential events on opening
+ if (_events.size() > 0) {
+ for (uint32 i = 0; i < _events.size(); ++i) {
+ MapMode::CurrentInstance()->GetEventSupervisor()->StartEvent(_events[i]);
+ }
+ }
MapMode::CurrentInstance()->GetTreasureSupervisor()->Initialize(this);
}
}
@@ -694,6 +702,12 @@ bool TreasureObject::AddObject(uint32 id, uint32 quantity)
return _treasure->AddObject(id, quantity);
}
+void TreasureObject::AddEvent(const std::string& event_id)
+{
+ if (!event_id.empty())
+ _events.push_back(event_id);
+}
+
// ----------------------------------------------------------------------------
// ---------- ObjectSupervisor Class Functions
// ----------------------------------------------------------------------------
View
8 src/modes/map/map_objects.h
@@ -670,12 +670,20 @@ class TreasureObject : public PhysicalObject
**/
bool AddObject(uint32 id, uint32 quantity = 1);
+ /** \brief Adds an event triggered at start of the treasure event.
+ *** \param event_id The id of the event to add
+ **/
+ void AddEvent(const std::string& event_id);
+
private:
//! \brief Stores the contents of the treasure which will be processed by the treasure supervisor
MapTreasure *_treasure;
//! \brief The treasure object name
std::string _treasure_name;
+
+ //! \brief Events triggered at the start of the treasure event.
+ std::vector<std::string> _events;
}; // class TreasureObject : public PhysicalObject
View
2 src/modes/mode_bindings.cpp
@@ -257,6 +257,7 @@ void BindModeCode()
.def(luabind::constructor<const std::string &, const std::string &, const std::string &, const std::string &>())
.def("SetDrunes", &TreasureObject::SetDrunes)
.def("AddObject", &TreasureObject::AddObject)
+ .def("AddEvent", &TreasureObject::AddEvent)
];
luabind::module(hoa_script::ScriptManager->GetGlobalState(), "hoa_map")
@@ -571,6 +572,7 @@ void BindModeCode()
.def(luabind::constructor<std::string>())
.def("SetDrunes", &TreasureEvent::SetDrunes)
.def("AddObject", &TreasureEvent::AddObject)
+ .def("AddEvent", &TreasureEvent::AddEvent)
];
} // End using map mode namespaces

0 comments on commit 49ef8b5

Please sign in to comment.