void TreasureSupervisor::Initialize(MapTreasure* treasure) { if (!treasure) { IF_PRINT_WARNING(MAP_DEBUG) << "function argument was NULL" << std::endl; return; } _treasure = treasure; MapMode::CurrentInstance()->PushState(STATE_TREASURE); // Construct the object list, including any drunes that were contained within the treasure if (_treasure->_drunes != 0) { _list_options.AddOption(MakeUnicodeString("<img/icons/drunes.png> Drunes<R>" + NumberToString(_treasure->_drunes))); _coins_snd.Play(); } else { _items_snd.Play(); } for (uint32 i = 0; i < _treasure->_objects_list.size(); i++) { if (_treasure->_objects_list[i]->GetCount() > 1) { _list_options.AddOption(MakeUnicodeString("<" + _treasure->_objects_list[i]->GetIconImage().GetFilename() + "> ") + _treasure->_objects_list[i]->GetName() + MakeUnicodeString("<R>x" + NumberToString(_treasure->_objects_list[i]->GetCount()))); } else { _list_options.AddOption(MakeUnicodeString("<" + _treasure->_objects_list[i]->GetIconImage().GetFilename() + "> ") + _treasure->_objects_list[i]->GetName()); } } for (uint32 i = 0; i < _list_options.GetNumberOptions(); i++) { _list_options.GetEmbeddedImage(i)->SetDimensions(30.0f, 30.0f); } _action_options.SetSelection(0); _action_options.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE); _list_options.SetSelection(0); _list_options.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN); _selection = ACTION_SELECTED; _action_window.Show(); _list_window.Show(); // Immediately add the drunes and objects to the player's inventory GlobalManager->AddDrunes(_treasure->_drunes); for (uint32 i = 0; i < _treasure->_objects_list.size(); ++i) { GlobalObject* obj = _treasure->_objects_list[i]; if (!obj) continue; if (!GlobalManager->IsObjectInInventory(obj->GetID())) { // Pass a copy to the inventory, the treasure object will delete its content on destruction. hoa_global::GlobalObject* obj_copy = GlobalCreateNewObject(obj->GetID(), obj->GetCount()); GlobalManager->AddToInventory(obj_copy); } else { GlobalManager->IncrementObjectCount(obj->GetID(), obj->GetCount()); } } } // void TreasureSupervisor::Initialize(MapTreasure* treasure)
void TreasureSupervisor::Initialize(MapTreasure *treasure) { if(!treasure) { IF_PRINT_WARNING(MAP_DEBUG) << "function argument was nullptr" << std::endl; return; } _treasure = treasure; MapMode::CurrentInstance()->PushState(STATE_TREASURE); // Construct the object list, including any drunes that were contained within the treasure if(_treasure->_drunes != 0) { _list_options.AddOption(MakeUnicodeString("<data/inventory/drunes.png> ") + UTranslate("Drunes") + MakeUnicodeString("<R>" + NumberToString(_treasure->_drunes))); GlobalManager->Media().PlaySound("coins"); } else { GlobalManager->Media().PlaySound("item_pickup"); } for(uint32_t i = 0; i < _treasure->_items_list.size(); i++) { if(_treasure->_items_list[i]->GetCount() > 1) { _list_options.AddOption(MakeUnicodeString("<" + _treasure->_items_list[i]->GetIconImage().GetFilename() + "> ") + _treasure->_items_list[i]->GetName() + MakeUnicodeString("<R>x" + NumberToString(_treasure->_items_list[i]->GetCount()))); } else { _list_options.AddOption(MakeUnicodeString("<" + _treasure->_items_list[i]->GetIconImage().GetFilename() + "> ") + _treasure->_items_list[i]->GetName()); } } for(uint32_t i = 0; i < _list_options.GetNumberOptions(); i++) { _list_options.GetEmbeddedImage(i)->SetDimensions(30.0f, 30.0f); } _action_options.SetSelection(0); _action_options.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE); _list_options.SetSelection(0); _list_options.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN); _selection = ACTION_SELECTED; _action_window.Show(); _list_window.Show(); // Immediately add the drunes and objects to the player's inventory GlobalManager->AddDrunes(_treasure->_drunes); for (uint32_t i = 0; i < _treasure->_items_list.size(); ++i) { std::shared_ptr<GlobalObject> obj = _treasure->_items_list[i]; if (!obj) continue; if (!GlobalManager->IsItemInInventory(obj->GetID())) { std::shared_ptr<vt_global::GlobalObject> obj_copy = GlobalCreateNewObject(obj->GetID(), obj->GetCount()); GlobalManager->AddToInventory(obj_copy); } else { GlobalManager->IncrementItemCount(obj->GetID(), obj->GetCount()); } } }
bool MapTreasure::AddObject(uint32 id, uint32 quantity) { hoa_global::GlobalObject* obj = GlobalCreateNewObject(id, quantity); if (obj == NULL) { IF_PRINT_WARNING(MAP_DEBUG) << "invalid object id argument passed to function: " << id << std::endl; return false; } _objects_list.push_back(obj); return true; }
bool MapTreasure::AddItem(uint32_t id, uint32_t quantity) { std::shared_ptr<vt_global::GlobalObject> obj = GlobalCreateNewObject(id, quantity); if (obj == nullptr) { IF_PRINT_WARNING(MAP_DEBUG) << "invalid object id argument passed to function: " << id << std::endl; return false; } _items_list.push_back(obj); return true; }
std::vector<std::shared_ptr<GlobalObject>> GlobalEnemy::DetermineDroppedObjects() { std::vector<std::shared_ptr<GlobalObject>> result; for (uint32_t i = 0; i < _dropped_objects.size(); ++i) { if (RandomFloat() < _dropped_chance[i]) { std::shared_ptr<GlobalObject> global_object = GlobalCreateNewObject(_dropped_objects[i]); result.push_back(global_object); } } return result; }