SceneObject* CraftingStationImplementation::findCraftingTool(CreatureObject* player) { ManagedReference<SceneObject*> inventory = player->getSlottedObject( "inventory"); Locker inventoryLocker(inventory); SceneObject* craftingTool = NULL; for (int i = 0; i < inventory->getContainerObjectsSize(); ++i) { SceneObject* object = inventory->getContainerObject(i); if (object != NULL && object->isCraftingTool()) { CraftingTool* tool = cast<CraftingTool*>( object); if(!tool->isReady()) continue; int toolType = tool->getToolType(); if (toolType == type) { return object; } if (toolType == CraftingTool::JEDI && type == CraftingTool::WEAPON) { craftingTool = object; } } } return craftingTool; }
bool CraftingManager::HandleRequestCraftingSession(Object* object,Object* target,Message* message,ObjectControllerCmdProperties* cmdProperties) { PlayerObject* playerObject = dynamic_cast<PlayerObject*>(object); CraftingTool* tool = dynamic_cast<CraftingTool*>(target); CraftingStation* station = dynamic_cast<CraftingStation*>(target); uint32 expFlag = 2;//needs to be >1 !!!!! message->setIndex(24); /*uint32 counter = */ message->getUint32(); //get nearest crafting station ObjectSet inRangeObjects; float range = 25.0; // the player clicked directly on a station if(station) { tool = getCraftingStationTool(playerObject, station); } if(!tool) { gMessageLib->SendSystemMessage(common::OutOfBand("ui_craft","err_no_crafting_tool"),playerObject); gMessageLib->sendCraftAcknowledge(opCraftCancelResponse,0,0,playerObject); return false; } // if we haven't come in through a station if(!station) { // get the tangible objects in range gCraftingManager->mSI->getObjectsInRange(playerObject,&inRangeObjects,(ObjType_Tangible),range); //and see if a fitting crafting station is near station = playerObject->getCraftingStation(&inRangeObjects,(ItemType) tool->getItemType()); } if(!station) { expFlag = false; } if(tool->getAttribute<std::string>("craft_tool_status") == "@crafting:tool_status_working") { if(tool->getCurrentItem()) gMessageLib->SendSystemMessage(::common::OutOfBand("system_msg", "crafting_tool_creating_prototype"), playerObject); // TODO: put the right message for practice else gMessageLib->SendSystemMessage(::common::OutOfBand("system_msg", "crafting_tool_creating_prototype"), playerObject); gMessageLib->sendCraftAcknowledge(opCraftCancelResponse, 0, 0, playerObject); return false; } playerObject->setCraftingSession(gCraftingSessionFactory->createSession(Anh_Utils::Clock::getSingleton(), playerObject, tool, station, expFlag)); return true; }
//====================================================================================================================== // // update busy crafting tools, called every 2 seconds // bool WorldManager::_handleCraftToolTimers(uint64 callTime,void* ref) { CraftTools::iterator it = mBusyCraftTools.begin(); while(it != mBusyCraftTools.end()) { CraftingTool* tool = dynamic_cast<CraftingTool*>(getObjectById((*it))); if(!tool) { LOG(error) << "Missing crafting tool"; it = mBusyCraftTools.erase(it); continue; } PlayerObject* player = dynamic_cast<PlayerObject*>(getObjectById(tool->getParentId() - 1)); Item* item = tool->getCurrentItem(); if(player) { // we done, create the item if(!tool->updateTimer(callTime)) { // add it to the world, if it holds an item if(item) { Inventory* temp = dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); if(!temp) continue; item->setParentId(temp->getId()); dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->addObject(item); gWorldManager->addObject(item,true); gMessageLib->sendCreateTano(item,player); gMessageLib->SendSystemMessage(::common::OutOfBand("system_msg", "prototype_transferred"), player); tool->setCurrentItem(NULL); } //in case of logout/in interplanetary travel it will be in the inventory already gMessageLib->sendUpdateTimer(tool,player); it = mBusyCraftTools.erase(it); tool->setAttribute("craft_tool_status","@crafting:tool_status_ready"); mDatabase->executeSqlAsync(0,0,"UPDATE %s.item_attributes SET value='@crafting:tool_status_ready' WHERE item_id=%" PRIu64 " AND attribute_id=18",mDatabase->galaxy(),tool->getId()); tool->setAttribute("craft_tool_time",boost::lexical_cast<std::string>(tool->getTimer())); gWorldManager->getDatabase()->executeSqlAsync(0,0,"UPDATE %s.item_attributes SET value='%i' WHERE item_id=%" PRIu64 " AND attribute_id=%u",mDatabase->galaxy(),tool->getId(),tool->getTimer(),AttrType_CraftToolTime); continue; } // update the time display gMessageLib->sendUpdateTimer(tool,player); tool->setAttribute("craft_tool_time",boost::lexical_cast<std::string>(tool->getTimer())); //gLogger->log(LogManager::DEBUG,"timer : %i",tool->getTimer()); mDatabase->executeSqlAsync(0,0,"UPDATE %s.item_attributes SET value='%i' WHERE item_id=%" PRIu64 " AND attribute_id=%u",mDatabase->galaxy(),tool->getId(),tool->getTimer(),AttrType_CraftToolTime); } ++it; } return(true); }