void StructureManager::promptMaintenanceDroid(StructureObject* structure, CreatureObject* creature) { ManagedReference<PlayerObject*> ghost = creature->getPlayerObject(); if (ghost == NULL) return; Vector<DroidObject*> droids; ManagedReference<SceneObject*> datapad = creature->getSlottedObject("datapad"); if(datapad == NULL) { return; } for (int i = 0; i < datapad->getContainerObjectsSize(); ++i) { ManagedReference<SceneObject*> object = datapad->getContainerObject(i); if (object != NULL && object->isPetControlDevice()) { PetControlDevice* device = cast<PetControlDevice*>( object.get()); if (device->getPetType() == PetManager::DROIDPET) { DroidObject* pet = cast<DroidObject*>(device->getControlledObject()); if (pet->isMaintenanceDroid()) { droids.add(pet); } } } } if (droids.size() == 0) { creature->sendSystemMessage("@player_structure:no_droids"); return; } ManagedReference<SuiListBox*> box = new SuiListBox(creature,SuiWindowType::STRUCTURE_ASSIGN_DROID); box->setCallback(new StructureAssignDroidSuiCallback(creature->getZoneServer())); box->setPromptText("@sui:assign_droid_prompt"); box->setPromptTitle("@sui:assign_droid_title"); // Configure Effects box->setOkButton(true, "@ok"); // Check if player has a droid called with a maintenance module installed for (int i = 0; i < droids.size(); ++i) { DroidObject* droidObject = droids.elementAt(i); box->addMenuItem(droidObject->getDisplayedName(),droidObject->getObjectID()); } box->setUsingObject(structure); ghost->addSuiBox(box); creature->sendMessage(box->generateMessage()); }
void InstallationObjectMenuComponent::fillObjectMenuResponse(SceneObject* sceneObject, ObjectMenuResponse* menuResponse, CreatureObject* player) { if (!sceneObject->isInstallationObject()) return; InstallationObject* installation = cast<InstallationObject*>(sceneObject); if (!installation->isOnAdminList(player)) return; menuResponse->addRadialMenuItem(118, 3, "@player_structure:management"); menuResponse->addRadialMenuItemToRadialID(118, 128, 3, "@player_structure:permission_destroy"); //Destroy Structure menuResponse->addRadialMenuItemToRadialID(118, 124, 3, "@player_structure:management_status"); //Status menuResponse->addRadialMenuItemToRadialID(118, 129, 3, "@player_structure:management_pay"); //Pay Maintenance ManagedReference<SceneObject*> datapad = player->getSlottedObject("datapad"); if(datapad != NULL) { for (int i = 0; i < datapad->getContainerObjectsSize(); ++i) { ManagedReference<SceneObject*> object = datapad->getContainerObject(i); if (object != NULL && object->isPetControlDevice()) { PetControlDevice* device = cast<PetControlDevice*>( object.get()); if (device->getPetType() == PetManager::DROIDPET) { menuResponse->addRadialMenuItemToRadialID(118, 131, 3, "@player_structure:assign_droid"); //Assign Droid break; } } } } menuResponse->addRadialMenuItemToRadialID(118, 50, 3, "@base_player:set_name"); //Set Name if (!installation->isGeneratorObject()) { menuResponse->addRadialMenuItemToRadialID(118, 51, 3, "@player_structure:management_power"); //Deposit Power } menuResponse->addRadialMenuItem(117, 3, "@player_structure:permissions"); //Structure Permissions menuResponse->addRadialMenuItemToRadialID(117, 121, 3, "@player_structure:permission_admin"); //Administrator List menuResponse->addRadialMenuItemToRadialID(117, 123, 3, "@player_structure:permission_hopper"); //Hopper List }
int PetDeedImplementation::handleObjectMenuSelect(CreatureObject* player, byte selectedID) { if (selectedID == 21) { if(generated || !player->hasSkill("outdoors_bio_engineer_novice") || !isASubChildOf(player)) return 1; if (player->isRidingMount()) { player->sendSystemMessage("You cannot sample DNA while mounted"); return 1; } if(player->getPendingTask("sampledeed") != NULL) { player->sendSystemMessage("@bio_engineer:harvest_dna_already_harvesting"); return 1; } int skillMod = player->getSkillMod("dna_harvesting"); if (skillMod < 1 || level > skillMod + 15) { player->sendSystemMessage("@bio_engineer:harvest_dna_skill_too_low"); return 1; } Locker clocker(_this.get()); ManagedReference<SampleDeedTask*> task = new SampleDeedTask(_this.get(), player); player->addPendingTask("sampledeed",task,0); return 0; } if (selectedID == 20) { if (generated || !isASubChildOf(player)) return 1; if (player->isInCombat() || player->getParentRecursively(SceneObjectType::BUILDING) != NULL) { player->sendSystemMessage("@pet/pet_menu:cant_call"); //You can only unpack vehicles while Outside and not in Combat. return 1; } ManagedReference<SceneObject*> datapad = player->getSlottedObject("datapad"); if (datapad == NULL) { player->sendSystemMessage("Datapad doesn't exist when trying to call pet"); return 1; } if (datapad->getContainerObjectsSize() >= datapad->getContainerVolumeLimit()) { player->sendSystemMessage("@faction_recruiter:datapad_full"); // Your datapad is full. You must first free some space. return 1; } // Does the player have room ManagedReference<PlayerManager*> playerManager = player->getZoneServer()->getPlayerManager(); int numberStored = 0; int maxStoredPets = playerManager->getBaseStoredCreaturePets() + player->getSkillMod("stored_pets"); for (int i = 0; i < datapad->getContainerObjectsSize(); ++i) { ManagedReference<SceneObject*> object = datapad->getContainerObject(i); if (object != NULL && object->isPetControlDevice()) { PetControlDevice* device = cast<PetControlDevice*>( object.get()); if (device->getPetType() == PetManager::CREATUREPET) { if (++numberStored >= maxStoredPets) { player->sendSystemMessage("@pet/pet_menu:sys_too_many_stored"); // There are too many pets stored in this container. Release some of them to make room for more. return 1; } } } } // Can the player control it ManagedReference<PlayerObject*> ghost = player->getPlayerObject(); int currentlySpawned = 0; int spawnedLevel = 0; int cLevel = level; int maxPets = player->getSkillMod("keep_creature"); int maxLevelofPets = player->getSkillMod("tame_level"); for (int i = 0; i < ghost->getActivePetsSize(); ++i) { ManagedReference<AiAgent*> object = ghost->getActivePet(i); if (object != NULL && object->isCreature()) { if (++currentlySpawned >= maxPets) { player->sendSystemMessage("@pet/pet_menu:too_many"); // You can't control any more pets. Store one first return 1; } spawnedLevel += object->getLevel(); if ((spawnedLevel + cLevel) > maxLevelofPets) { player->sendSystemMessage("Taming this pet would exceed your control level ability."); return 1; } } } Reference<CreatureManager*> creatureManager = player->getZone()->getCreatureManager(); if( creatureManager == NULL ){ player->sendSystemMessage("Internal Pet Deed Error #307"); return 1; } CreatureTemplateManager* creatureTemplateManager = CreatureTemplateManager::instance(); ManagedReference<CreatureTemplate*> petTemplate = creatureTemplateManager->getTemplate( mobileTemplate.hashCode() ); if (petTemplate == NULL) { player->sendSystemMessage("wrong pet template;mobileTemplate=[" + mobileTemplate + "]" ); return 1; } bool isVicious = petTemplate->getPvpBitmask() & CreatureFlag::AGGRESSIVE; if (level > 10 || isVicious) { if (!player->hasSkill("outdoors_creaturehandler_novice") || (level > maxLevelofPets)) { player->sendSystemMessage("@pet/pet_menu:sys_lack_skill"); // You lack the skill to be able to tame that creature. return 1; } if (isVicious && player->getSkillMod("tame_aggro") < 1) { player->sendSystemMessage("@pet/pet_menu:sys_lack_skill"); // You lack the skill to be able to tame that creature. return 1; } } // All checks complete, lets setup the control device and do it. ManagedReference<PetControlDevice*> controlDevice = (server->getZoneServer()->createObject(controlDeviceObjectTemplate.hashCode(), 1)).castTo<PetControlDevice*>(); if (controlDevice == NULL) { player->sendSystemMessage("wrong pet control device;controlDevice=[" + controlDeviceObjectTemplate + "]" ); return 1; } Locker locker(controlDevice); String templateToSpawn = creatureManager->getTemplateToSpawn(mobileTemplate.hashCode()); ManagedReference<CreatureObject*> creatureObject = creatureManager->createCreature(templateToSpawn.hashCode(), true, 0 ); if( creatureObject == NULL ) { controlDevice->destroyObjectFromDatabase(true); player->sendSystemMessage("wrong pet template;mobileTemplate=[" + mobileTemplate + "]" ); return 1; } Locker clocker(creatureObject, player); ManagedReference<Creature*> pet = creatureObject.castTo<Creature*>(); if( pet == NULL ) { controlDevice->destroyObjectFromDatabase(true); creatureObject->destroyObjectFromDatabase(true); player->sendSystemMessage("Internal Pet Deed Error #348" ); return 1; } ObjectManager* objectManager = server->getZoneServer()->getObjectManager(); pet->setPetDeed(_this.get()); pet->loadTemplateData( petTemplate ); pet->setCustomObjectName(StringIdManager::instance()->getStringId(*pet->getObjectName()), true); pet->createChildObjects(); pet->setBaby(false); // update base stats on the pet now // We will store the deed pointer to the aiagent before serialization // Copy color customization from deed to pet CustomizationVariables* customVars = getCustomizationVariables(); if( customVars != NULL ){ for (int i = 0; i < customVars->size(); ++i) { uint8 id = customVars->elementAt(i).getKey(); int16 val = customVars->elementAt(i).getValue(); String name = CustomizationIdManager::instance()->getCustomizationVariable(id); pet->setCustomizationVariable( name, val, true ); } } // then this is complete StringId s; s.setStringId(pet->getObjectName()->getFullPath()); controlDevice->setControlledObject(pet); controlDevice->setObjectName(s); controlDevice->setPetType(PetManager::CREATUREPET); controlDevice->setMaxVitality(100); controlDevice->setVitality(100); controlDevice->setGrowthStage(1); controlDevice->updateStatus(1); if (!datapad->transferObject(controlDevice, -1)) { controlDevice->destroyObjectFromDatabase(true); return 1; } datapad->broadcastObject(controlDevice, true); controlDevice->growPet(player,true); controlDevice->callObject(player); //Remove the deed from it's container. ManagedReference<SceneObject*> deedContainer = getParent().get(); if (deedContainer != NULL) { destroyObjectFromWorld(true); } generated = true; player->sendSystemMessage("@pet/pet_menu:device_added"); // "A control device has been added to your datapad." return 0; } return DeedImplementation::handleObjectMenuSelect(player, selectedID); }
void CreatureManagerImplementation::tame(Creature* creature, CreatureObject* player, bool force) { Zone* zone = creature->getZone(); if (zone == NULL || !creature->isCreature()) return; if(player->getPendingTask("tame_pet") != NULL) { player->sendSystemMessage("You are already taming a pet"); return; } if(player->getPendingTask("call_pet") != NULL) { player->sendSystemMessage("You cannot tame a pet while another is being called"); return; } if (!creature->canTameMe(player) || !creature->isAttackableBy(player)) { player->sendSystemMessage("@pet/pet_menu:sys_cant_tame"); // You can't tame that return; } CreatureTemplate* creatureTemplate = creature->getCreatureTemplate(); if (creatureTemplate == NULL) return; int templateLevel = creatureTemplate->getLevel(); int maxLevelofPets = player->getSkillMod("tame_level"); if (!player->hasSkill("outdoors_creaturehandler_novice") || (templateLevel > maxLevelofPets)) { player->sendSystemMessage("@pet/pet_menu:sys_lack_skill"); // You lack the skill to be able to tame that creature. return; } if ((creature->isVicious() && player->getSkillMod("tame_aggro") < 1) || creature->getChanceToTame(player) <= 0) { player->sendSystemMessage("@pet/pet_menu:sys_lack_skill"); // You lack the skill to be able to tame that creature. return; } ManagedReference<SceneObject*> datapad = player->getSlottedObject("datapad"); if (datapad == NULL) return; if (datapad->getContainerObjectsSize() >= datapad->getContainerVolumeLimit()) { player->sendSystemMessage("@faction_recruiter:datapad_full"); // Your datapad is full. You must first free some space. return; } ManagedReference<PlayerManager*> playerManager = zoneServer->getPlayerManager(); int numberStored = 0; int maxStoredPets = playerManager->getBaseStoredCreaturePets() + player->getSkillMod("stored_pets"); for (int i = 0; i < datapad->getContainerObjectsSize(); ++i) { ManagedReference<SceneObject*> object = datapad->getContainerObject(i); if (object != NULL && object->isPetControlDevice()) { PetControlDevice* device = cast<PetControlDevice*>( object.get()); if (device->getPetType() == PetManager::CREATUREPET) { if (++numberStored >= maxStoredPets) { player->sendSystemMessage("@pet/pet_menu:sys_too_many_stored"); // There are too many pets stored in this container. Release some of them to make room for more. return; } } } } ManagedReference<PlayerObject*> ghost = player->getPlayerObject(); int currentlySpawned = 0; int spawnedLevel = 0; int level = creature->getLevel(); int maxPets = player->getSkillMod("keep_creature"); for (int i = 0; i < ghost->getActivePetsSize(); ++i) { ManagedReference<AiAgent*> object = ghost->getActivePet(i); if (object != NULL) { ManagedReference<PetControlDevice*> pcd = object->getControlDevice().get().castTo<PetControlDevice*>(); if (pcd == NULL || pcd->getPetType() != PetManager::CREATUREPET) { continue; } if (++currentlySpawned >= maxPets) { player->sendSystemMessage("@pet/pet_menu:too_many"); // You can't control any more pets. Store one first return; } spawnedLevel += object->getLevel(); if ((spawnedLevel + level) >= maxLevelofPets) { player->sendSystemMessage("Taming this pet would exceed your control level ability."); return; } } } if (force && !ghost->isPrivileged()) force = false; ChatManager* chatManager = player->getZoneServer()->getChatManager(); chatManager->broadcastMessage(player, "@hireling/hireling:taming_1"); // Easy. Locker clocker(creature); int mask = creature->getPvpStatusBitmask(); creature->setPvpStatusBitmask(0, true); if (creature->isAiAgent()) { AiAgent* agent = cast<AiAgent*>(creature); agent->activateLoad("wait"); } ManagedReference<TameCreatureTask*> task = new TameCreatureTask(creature, player, mask, force); player->addPendingTask("tame_pet", task, 8000); }
bool PetControlDeviceImplementation::canBeTradedTo(CreatureObject* player, CreatureObject* receiver, int numberInTrade) { ManagedReference<SceneObject*> datapad = receiver->getSlottedObject("datapad"); if (datapad == NULL) return false; if (petType == PetManager::FACTIONPET) { player->sendSystemMessage("@pet/pet_menu:bad_type"); // You cannot trade a pet of that type. Transfer failed. return false; } else if (petType == PetManager::DROIDPET) { ManagedReference<PlayerManager*> playerManager = player->getZoneServer()->getPlayerManager(); int droidsInDatapad = numberInTrade; int maxStoredDroids = playerManager->getBaseStoredDroids(); for (int i = 0; i < datapad->getContainerObjectsSize(); i++) { Reference<SceneObject*> obj = datapad->getContainerObject(i).castTo<SceneObject*>(); if (obj != NULL && obj->isPetControlDevice() ){ Reference<PetControlDevice*> petDevice = cast<PetControlDevice*>(obj.get()); if( petDevice != NULL && petDevice->getPetType() == PetManager::DROIDPET){ droidsInDatapad++; } } } if( droidsInDatapad >= maxStoredDroids){ player->sendSystemMessage("That person has too many droids in their datapad"); return false; } return true; } else if (petType == PetManager::CREATUREPET) { ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get(); if (controlledObject == NULL || !controlledObject->isCreature()) return false; ManagedReference<Creature*> pet = cast<Creature*>(controlledObject.get()); ManagedReference<PlayerManager*> playerManager = player->getZoneServer()->getPlayerManager(); int numberStored = numberInTrade; int maxStoredPets = playerManager->getBaseStoredCreaturePets(); int maxLevelofPets = 10; int level = pet->getAdultLevel(); bool ch = receiver->hasSkill("outdoors_creaturehandler_novice"); if (ch) { maxStoredPets += receiver->getSkillMod("stored_pets"); maxLevelofPets = receiver->getSkillMod("tame_level"); } if (level > maxLevelofPets) { player->sendSystemMessage("@pet/pet_menu:no_chance"); // That person has no chance of controlling this creature. Transfer failed. receiver->sendSystemMessage("@pet/pet_menu:cannot_control"); // You have no chance of controlling that creature. return false; } if (pet->isVicious() && (receiver->getSkillMod("tame_aggro") <= 0 || !ch)) { player->sendSystemMessage("@pet/pet_menu:no_chance"); // That person has no chance of controlling this creature. Transfer failed. receiver->sendSystemMessage("@pet/pet_menu:cannot_control"); // You have no chance of controlling that creature. return false; } if (numberStored >= maxStoredPets) { player->sendSystemMessage("@pet/pet_menu:targ_too_many_stored"); // That person has too many stored pets. Transfer failed. receiver->sendSystemMessage("@pet/pet_menu:sys_too_many_stored"); // There are too many pets stored in this container. Release some of them to make room for more. return false; } for (int i = 0; i < datapad->getContainerObjectsSize(); ++i) { ManagedReference<SceneObject*> object = datapad->getContainerObject(i); if (object != NULL && object->isPetControlDevice()) { PetControlDevice* device = cast<PetControlDevice*>( object.get()); if (device->getPetType() == PetManager::CREATUREPET) { if (++numberStored >= maxStoredPets) { player->sendSystemMessage("@pet/pet_menu:targ_too_many_stored"); // That person has too many stored pets. Transfer failed. receiver->sendSystemMessage("@pet/pet_menu:sys_too_many_stored"); // There are too many pets stored in this container. Release some of them to make room for more. return false; } } } } return true; } return false; }