bool EVWeapon::validate(uint32 &reply1, uint32 &reply2, uint64 targetId, uint32 opcode, ObjectControllerCmdProperties*& cmdProperties) { CreatureObject* creature = dynamic_cast<CreatureObject*>(mController->getObject()); // check our equipped weapon uint32 weaponGroup = WeaponGroup_Unarmed; if(Item* weapon = dynamic_cast<Item*>(creature->getEquipManager()->getEquippedObject(CreatureEquipSlot_Hold_Left))) { // could be an instrument if(weapon->getItemFamily() == ItemFamily_Weapon) { weaponGroup = dynamic_cast<Weapon*>(weapon)->getGroup(); } } if(cmdProperties->mRequiredWeaponGroup && (weaponGroup & cmdProperties->mRequiredWeaponGroup) != weaponGroup) { reply1 = 0; reply2 = 1; if(PlayerObject* player = dynamic_cast<PlayerObject*>(creature)) { gMessageLib->SendSystemMessage(::common::OutOfBand("cbt_spam", "no_attack_wrong_weapon"), player); } return(false); } return(true); }
void Food::prepareCustomRadialMenu(CreatureObject* creatureObject, uint8 itemCount) { RadialMenu* radial = new RadialMenu(); CreatureObject* unknownCreature; Inventory* creatureInventory; if (this->getParentId() && (unknownCreature = dynamic_cast<CreatureObject*>(gWorldManager->getObjectById(this->getParentId() - 1))) && (creatureInventory = dynamic_cast<Inventory*>(unknownCreature->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))) && (creatureInventory->getId() == this->getParentId())) { // Its an object in an inventory NPCObject* npcObject = dynamic_cast<NPCObject*>(unknownCreature); if (npcObject) { if ((npcObject->getNpcFamily() == NpcFamily_AttackableCreatures) && npcObject->isDead()) { // I'm pretty sure we are a loot item. radial->addItem(1,0,radId_itemPickup,radAction_ObjCallback,"@ui_radial:loot"); radial->addItem(2,0,radId_examine,radAction_Default); mRadialMenu = RadialMenuPtr(radial); return; } } } // Note: If we are to never use the default "Eat", THEN remove the isTutorial()-condition test. if (gWorldConfig->isTutorial()) { // Tutorial clearly states that we shall use the "Use"-option. radial->addItem(1,0,radId_itemUse,radAction_ObjCallback,"Use"); } else { radial->addItem(1,0,radId_itemUse,radAction_ObjCallback,""); // Default. } radial->addItem(2,0,radId_examine,radAction_ObjCallback,""); radial->addItem(3,0,radId_itemDestroy,radAction_ObjCallback,""); mRadialMenu = RadialMenuPtr(radial); }
// TODO: Fix this void ScriptSupport::itemPopulateInventory(uint64 itemId, uint64 npcId, uint64 playerId) { // NOTE: For now we only check and validates TangibleObject. CreatureObject* creature = dynamic_cast<CreatureObject*>(gWorldManager->getObjectById(npcId)); Object* itemObject = gWorldManager->getObjectById(itemId); PlayerObject* playerObject = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(playerId)); if (creature && itemObject && playerObject) { Inventory* inventory = dynamic_cast<Inventory*>(creature->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); if (inventory) { // and (tutorial:getRoom() < 7) inventory->addObjectSecure(itemObject); itemObject->setParentId(npcId+1); } } }
bool ObjectController::removeFromContainer(uint64 targetContainerId, uint64 targetId) { PlayerObject* playerObject = dynamic_cast<PlayerObject*>(mObject); Object* itemObject = gWorldManager->getObjectById(targetId); Inventory* inventory = dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); TangibleObject* targetContainer = dynamic_cast<TangibleObject*>(gWorldManager->getObjectById(targetContainerId)); TangibleObject* tangible = dynamic_cast<TangibleObject*>(itemObject); Item* item = dynamic_cast<Item*>(itemObject); // its us if (tangible->getParentId() == playerObject->getId()) { // unequip it return playerObject->getEquipManager()->unEquipItem(itemObject); } //the containerObject is the container used in the tutorial or some random dungeon container Container* container = dynamic_cast<Container*>(gWorldManager->getObjectById(tangible->getParentId())); if (container) { container->removeObject(itemObject); //gContainerManager->destroyObjectToRegisteredPlayers(container, tangible->getId()); if (gWorldConfig->isTutorial()) { playerObject->getTutorial()->transferedItemFromContainer(targetId, tangible->getParentId()); // If object is owned by player (private owned for instancing), we remove the owner from the object. // what is this used for ??? if (itemObject->getPrivateOwner() == playerObject->getId()) { itemObject->setPrivateOwner(0); } } return true; } //creature inventories are a special case - their items are temporary!!! we cannot loot them directly CreatureObject* unknownCreature; Inventory* creatureInventory; if (itemObject->getParentId() && (unknownCreature = dynamic_cast<CreatureObject*>(gWorldManager->getObjectById(itemObject->getParentId() - INVENTORY_OFFSET))) && (creatureInventory = dynamic_cast<Inventory*>(unknownCreature->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))) && (creatureInventory->getId() == itemObject->getParentId()) && (creatureInventory->getId() != inventory->getId())) { if(!creatureInventory->removeObject(itemObject)) { LOG(warning) << "ObjectController::removeFromContainer: Internal Error could not remove " << itemObject->getId() << " from creature inventory " << creatureInventory->getId(); return false; } // we destroy the item in this case as its a temporary!! // we do not want to clog the db with unlooted items gContainerManager->destroyObjectToRegisteredPlayers(creatureInventory, tangible->getId()); ObjectIDList* invObjList = creatureInventory->getObjects(); if (invObjList->size() == 0) { // Put this creature in the pool of delayed destruction and remove the corpse from scene. gWorldManager->addCreatureObjectForTimedDeletion(creatureInventory->getParentId(), LootedCorpseTimeout); } if (gWorldConfig->isTutorial()) { // TODO: Update tutorial about the loot. playerObject->getTutorial()->transferedItemFromContainer(targetId, creatureInventory->getId()); } //bail out here and request the item over the db - as the item in the NPC has a temporary id and we dont want that in the db // This ensure that we do not use/store any of the temp id's in the database. gObjectFactory->requestNewDefaultItem(inventory, item->getItemFamily(), item->getItemType(), inventory->getId(), 99, glm::vec3(), ""); return false; } //cells are NOT tangibles - thei are static Objects CellObject* cell; if(cell = dynamic_cast<CellObject*>(gWorldManager->getObjectById(itemObject->getParentId()))) { // Stop playing if we pick up the (permanently placed) instrument we are playing if (item && (item->getItemFamily() == ItemFamily_Instrument)) { uint32 instrumentType = item->getItemType(); if ((instrumentType == ItemType_Nalargon) || (instrumentType == ItemType_omni_box) || (instrumentType == ItemType_nalargon_max_reebo)) { // It's a placeable original instrument. // Are we targeting the instrument we actually play on? if (playerObject->getActiveInstrumentId() == item->getId()) { gEntertainerManager->stopEntertaining(playerObject); } } } //we *cannot* remove static tangibles like the structureterminal!!!! if(tangible->getStatic()) { return false; } // Remove object from cell. cell->removeObject(itemObject); return true; } //some other container ... hopper backpack chest etc TangibleObject* containingContainer = dynamic_cast<TangibleObject*>(gWorldManager->getObjectById(tangible->getParentId())); if(containingContainer && containingContainer->removeObject(itemObject)) { return true; } return false; }
void ObjectController::destroyObject(uint64 objectId) { PlayerObject* playerObject = dynamic_cast<PlayerObject*>(mObject); Datapad* datapad = playerObject->getDataPad(); Object* object = gWorldManager->getObjectById(objectId); //could be a schematic! ManufacturingSchematic* schem = datapad->getManufacturingSchematicById(objectId); if(schem != NULL) { //delete schematic datapad->removeManufacturingSchematic(objectId); //delete schematic object gObjectFactory->deleteObjectFromDB(schem); gMessageLib->sendDestroyObject(objectId,playerObject); return; } // could be a waypoint if(object == NULL) { object = datapad->getWaypointById(objectId); } // or something else if(object == NULL) { gLogger->log(LogManager::DEBUG,"ObjController::destroyObject: could not find object %"PRIu64"",objectId); return; } // waypoint if(object->getType() == ObjType_Waypoint) { // update our datapad if(!(datapad->removeWaypoint(objectId))) { gLogger->log(LogManager::DEBUG,"ObjController::handleDestroyObject: Error removing Waypoint from datapad %"PRIu64"",objectId); } gMessageLib->sendUpdateWaypoint(dynamic_cast<WaypointObject*>(object),ObjectUpdateDelete,playerObject); // delete from db gObjectFactory->deleteObjectFromDB(object); delete(object); } //Inangible Objects if(object->getType() == ObjType_Intangible) { //update the datapad if(!(datapad->removeData(objectId))) { gLogger->log(LogManager::DEBUG,"ObjController::handleDestroyObject: Error removing Data from datapad %"PRIu64"",objectId); } if(VehicleController* vehicle = dynamic_cast<VehicleController*>(object)) { vehicle->Store(); } gObjectFactory->deleteObjectFromDB(object); gMessageLib->sendDestroyObject(objectId,playerObject); delete(object); } // tangible else if(object->getType() == ObjType_Tangible) { TangibleObject* tangibleObject = dynamic_cast<TangibleObject*>(object); BuildingObject* building = dynamic_cast<BuildingObject*>(tangibleObject->getObjectMainParent(tangibleObject)); if(building) { if(!building->hasAdminRights(playerObject->getId())) { return; } } if(tangibleObject->getParentId() == 0) { return; } Inventory* inventory = dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); // items if(Item* item = dynamic_cast<Item*>(tangibleObject)) { // handle any family specifics switch(item->getItemFamily()) { case ItemFamily_CraftingTools: _handleDestroyCraftingTool(dynamic_cast<CraftingTool*>(item)); break; case ItemFamily_Instrument: _handleDestroyInstrument(item); break; default: break; } // update the equiplist, if its an equipable item CreatureObject* creature = dynamic_cast<CreatureObject*>(gWorldManager->getObjectById(item->getParentId())); if(creature) { // remove from creatures slotmap creature->getEquipManager()->removeEquippedObject(object); //unequip it object->setParentId(inventory->getId()); gMessageLib->sendContainmentMessage_InRange(object->getId(),inventory->getId(),0xffffffff,creature); // send out the new equiplist gMessageLib->sendEquippedListUpdate_InRange(creature); } } //tangible includes items and resourcecontainers if(tangibleObject) { //if(tangible->getObjectMainParent(object) != inventory->getId()) if(tangibleObject->getKnownPlayers()->size()) { //this automatically destroys the object for the players in its vicinity tangibleObject->destroyKnownObjects(); } else { // destroy it for the player gMessageLib->sendDestroyObject(objectId,playerObject); } } // reset pending ui callbacks playerObject->resetUICallbacks(object); // delete from db CAVE :: mark if its an Object saved in the db!!!! // temporary placed instruments are not saved in the db gObjectFactory->deleteObjectFromDB(object); //it might be in a cell or in a container or in the inventory :) ObjectContainer* oc = dynamic_cast<ObjectContainer*>(gWorldManager->getObjectById(object->getParentId())); if(oc) { oc->deleteObject(object); } else { gWorldManager->destroyObject(object); } } }