bool WorldManager::_handlePlayerMovementUpdateTimers(uint64 callTime, void* ref) { PlayerMovementUpdateMap::iterator it = mPlayerMovementUpdateMap.begin(); while (it != mPlayerMovementUpdateMap.end()) { PlayerObject* player = dynamic_cast<PlayerObject*>(getObjectById((*it).first)); if (player) { if (player->isConnected()) { // The timer has expired? if (callTime >= ((*it).second)) { // Yes, handle it. ObjectController* ObjCtl = player->getController(); uint64 next = ObjCtl->playerWorldUpdate(false); mPlayerMovementUpdateMap.erase(it++); if (next) { // Add next scheduled update. addPlayerMovementUpdateTime(player, next); } } else { ++it; } } else { // Remove the disconnected... mPlayerMovementUpdateMap.erase(it++); } } else { // Remove the disconnected... mPlayerMovementUpdateMap.erase(it++); } } return (true); }
void Food::handleFoodUse(Object* srcObject) { toDelete = true; PlayerObject* playerObject = dynamic_cast<PlayerObject*>(srcObject); if(!playerObject) { return; } if(playerObject->isDead() || playerObject->isIncapacitated()) { gMessageLib->SendSystemMessage(::common::OutOfBand("error_message", "wrong_state"), playerObject); return; } //we need to start by checking whether our stomach isnt full //we need to update our stomach float filling = 0; if(this->hasInternalAttribute("food_icon")) { mIcon = 0; mIcon = this->getInternalAttribute<uint32>("food_icon"); } else { LOG(WARNING) << "Food/Drink found with no buff icon"; } if(this->hasAttribute("counter_uses_remaining")) { _handleUses_Remaining(playerObject); } bool drink = (this->hasAttribute("stomach_drink")); bool food = (this->hasAttribute("stomach_food")); if(food) { filling = this->getAttribute<float>("stomach_food"); //do we still have place for it ? if(!playerObject->getStomach()->checkFood(filling)) { gMessageLib->SendSystemMessage(OutOfBand("error_message", "full_food"), playerObject); return; } gMessageLib->SendSystemMessage(OutOfBand("base_player", "prose_consume_item", 0, this->getId(), 0), playerObject); playerObject->getStomach()->incFood(filling); } if(drink) { float filling = 0; filling = this->getAttribute<float>("stomach_drink"); //do we still have place for it ? if(!playerObject->getStomach()->checkDrink(filling)) { gMessageLib->SendSystemMessage(OutOfBand("error_message","full_drink"), playerObject); return; } gMessageLib->SendSystemMessage(OutOfBand("base_player", "prose_consume_item", 0, this->getId(), 0), playerObject); playerObject->getStomach()->incDrink(filling); } if(this->hasAttribute("duration")) { mDuration= static_cast<uint32>(this->getAttribute<float>("duration")); } if(mDuration >0) { _handleBuff(playerObject); } else { _handleInstant(playerObject); } // play sounds playerObject->playFoodSound(food, drink); //when empty delete if(toDelete) { //the db gObjectFactory->deleteObjectFromDB(this); //destroy it in the client gMessageLib->sendDestroyObject(this->getId(),playerObject); //delete it out of the inventory uint64 now = Anh_Utils::Clock::getSingleton()->getLocalTime(); playerObject->getController()->addEvent(new ItemDeleteEvent(now+100,this->getId()),100); return; } return; }
void ObjectController::_handleTransferItemMisc(uint64 targetId,Message* message,ObjectControllerCmdProperties* cmdProperties) { //we need to make sure that ONLY equipped items are contained by the player //all other items are contained by the inventory!!!!!!!! PlayerObject* playerObject = dynamic_cast<PlayerObject*>(mObject); Object* itemObject = gWorldManager->getObjectById(targetId); Inventory* inventory = dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); BString dataStr; uint64 targetContainerId; uint32 linkType; float x,y,z; CellObject* cell; message->getStringUnicode16(dataStr); if(swscanf(dataStr.getUnicode16(),L"%" WidePRIu64 L" %u %f %f %f",&targetContainerId,&linkType,&x,&y,&z) != 5) { DLOG(info) << "ObjController::_handleTransferItemMisc: Error in parameters"; return; } if (!itemObject) { DLOG(warning) << "ObjController::_handleTransferItemMisc: No Object to transfer :("; return; } TangibleObject* tangible = dynamic_cast<TangibleObject*>(itemObject); if(!tangible) { //no tagible - get out of here DLOG(warning) << "ObjController::_handleTransferItemMisc: No tangible to transfer :("; return; } //get our containers Object* newContainer = gWorldManager->getObjectById(targetContainerId); Object* oldContainer = gWorldManager->getObjectById(tangible->getParentId()); DLOG(info) << "ObjController::_handleTransferItemMisc: parameters"; DLOG(info) << "ObjController::_handleTransferItemMisc: newcontainer : " << targetContainerId; DLOG(info) << "ObjController::_handleTransferItemMisc: oldcontainer : " << tangible->getParentId(); DLOG(info) << "ObjController::_handleTransferItemMisc: linktype : " << linkType; // We may want to transfer other things than items...basically tangibleObjects! // resourcecontainers / factory crates // first check whether its an instrument with persistant copy - thats a special case! Item* item = dynamic_cast<Item*>(itemObject); if (item) { //check if its only temporarily placed if(item->getItemFamily() == ItemFamily_Instrument) { if(item->getPersistantCopy()) { // gMessageLib->sendSystemMessage(playerObject,L"you cannot pick this up"); // You bet, I can! Remove the temp instrument from the world. // Do I have access to this instrument? if (item->getOwner() == playerObject->getId()) { playerObject->getController()->destroyObject(targetId); } return; } } } // A FYI: When we drop items, we use player pos. itemObject->mPosition = glm::vec3(x,y,z); if (!targetContainerId) { DLOG(info) << "ObjController::_handleTransferItemMisc:TargetContainer is 0 :("; //return; } //ok how to tackle this ... : //basically I want to use ObjectContainer as standard access point for item handling! //so far we have different accesses for Objects on the player and for the inventory and for ContainerObjects and for cells ... //lets begin by getting the target Object if(!checkTargetContainer(targetContainerId,itemObject)) { DLOG(info) << "ObjController::_handleTransferItemMisc:TargetContainer is not valid :("; return; } if(!checkContainingContainer(tangible->getParentId(), playerObject->getId())) { DLOG(info) << "ObjController::_handleTransferItemMisc:ContainingContainer is not allowing the transfer :("; return; } // Remove the object from whatever contains it. if(!removeFromContainer(targetContainerId, targetId)) { DLOG(info) << "ObjectController::_handleTransferItemMisc: removeFromContainer failed :( this might be caused by looting a corpse though"; return; } //we need to destroy the old radial ... our item now gets a new one //delete(itemObject->getRadialMenu()); itemObject->ResetRadialMenu(); itemObject->setParentId(targetContainerId); //Now update the registered watchers!! gContainerManager->updateObjectPlayerRegistrations(newContainer, oldContainer, tangible, linkType); //now go and move it to wherever it belongs cell = dynamic_cast<CellObject*>(newContainer); if (cell) { // drop in a cell //special case temp instrument if (item&&item->getItemFamily() == ItemFamily_Instrument) { if (playerObject->getPlacedInstrumentId()) { // We do have a placed instrument. uint32 instrumentType = item->getItemType(); if ((instrumentType == ItemType_Nalargon) || (instrumentType == ItemType_omni_box) || (instrumentType == ItemType_nalargon_max_reebo)) { // We are about to drop the real thing, remove any copied instrument. // item->setOwner(playerObject->getId(); playerObject->getController()->destroyObject(playerObject->getPlacedInstrumentId()); } } } itemObject->mPosition = playerObject->mPosition; //do the db update manually because of the position - unless we get an automated position save in itemObject->setParentId(targetContainerId); ResourceContainer* rc = dynamic_cast<ResourceContainer*>(itemObject); if(rc) mDatabase->executeSqlAsync(0,0,"UPDATE %s.resource_containers SET parent_id ='%I64u', oX='%f', oY='%f', oZ='%f', oW='%f', x='%f', y='%f', z='%f' WHERE id='%I64u'",mDatabase->galaxy(),itemObject->getParentId(), itemObject->mDirection.x, itemObject->mDirection.y, itemObject->mDirection.z, itemObject->mDirection.w, itemObject->mPosition.x, itemObject->mPosition.y, itemObject->mPosition.z, itemObject->getId()); else mDatabase->executeSqlAsync(0,0,"UPDATE %s.items SET parent_id ='%I64u', oX='%f', oY='%f', oZ='%f', oW='%f', x='%f', y='%f', z='%f' WHERE id='%I64u'",mDatabase->galaxy(),itemObject->getParentId(), itemObject->mDirection.x, itemObject->mDirection.y, itemObject->mDirection.z, itemObject->mDirection.w, itemObject->mPosition.x, itemObject->mPosition.y, itemObject->mPosition.z, itemObject->getId()); cell->addObjectSecure(itemObject); gMessageLib->sendDataTransformWithParent053(itemObject); itemObject->updateWorldPosition(); return; } PlayerObject* player = dynamic_cast<PlayerObject*>(newContainer); if(player) { //equip / unequip handles the db side, too if(!player->getEquipManager()->EquipItem(item)) { LOG(warning) << "ObjectController::_handleTransferItemMisc: Error equipping " << item->getId(); //panik!!!!!! } itemObject->setParentIdIncDB(newContainer->getId()); return; } //***************************************************************** //All special cases have been handled - now its just our generic ObjectContainer Type //some other container ... hopper backpack chest inventory etc if(newContainer) { newContainer->addObjectSecure(itemObject); itemObject->setParentIdIncDB(newContainer->getId()); return; } }