int VetHarvesterDeedImplementation::useObject(CreatureObject* creature) {

	ManagedReference<PlayerObject*> ghost = creature->getPlayerObject();

	ZoneServer *zone = creature->getZoneServer();

	if(ghost == NULL || zone == NULL)
		return 0;

	if (!isASubChildOf(creature))
		return 0;

	uint64 targetID = creature->getTargetID();

	ManagedReference<TangibleObject*> targetObject = zone->getObject(targetID).castTo<TangibleObject*>();

	if (targetObject == NULL || !targetObject->isHarvesterObject())
		return 0;

	HarvesterObject *harvester = targetObject.castTo<HarvesterObject*>();

	if(harvester == NULL || !harvester->isOwnerOf(creature))
		return 0;

	if(harvester->isSelfPowered()) {
		creature->sendSystemMessage("@veteran:harvester_already_selfpowered");
		return 0;
	}

	StringIdChatParameter messageBody("veteran", "harvester_converted"); // Your harvester %TT has been converted to use 0 power.
	messageBody.setTT(harvester);

	ManagedReference<ChatManager*> cman = zone->getChatManager();

	cman->sendMail("system", "@veteran:harvester_converted_subject", messageBody, creature->getFirstName());

  	EXECUTE_TASK_1(harvester, {
          Locker locker(harvester_p);
          harvester_p->setSelfPowered(true);
        });
Example #2
0
int StructureManager::redeedStructure(CreatureObject* creature) {
	ManagedReference<DestroyStructureSession*> session = creature->getActiveSession(SessionFacadeType::DESTROYSTRUCTURE).castTo<DestroyStructureSession*>();

	if (session == NULL)
		return 0;

	ManagedReference<StructureObject*> structureObject =
			session->getStructureObject();

	if (structureObject == NULL)
		return 0;

	Locker _locker(structureObject);

	ManagedReference<StructureDeed*> deed =
			server->getObject(
					structureObject->getDeedObjectID()).castTo<StructureDeed*>();

	int maint = structureObject->getSurplusMaintenance();
	int redeedCost = structureObject->getRedeedCost();

	if (deed != NULL && structureObject->isRedeedable()) {
		Locker _lock(deed, structureObject);

		ManagedReference<SceneObject*> inventory = creature->getSlottedObject(
				"inventory");

		bool isSelfPoweredHarvester = false;
		HarvesterObject* harvester = structureObject.castTo<HarvesterObject*>();

		if(harvester != NULL)
			isSelfPoweredHarvester = harvester->isSelfPowered();

		if (inventory == NULL || inventory->getCountableObjectsRecursive() > (inventory->getContainerVolumeLimit() - (isSelfPoweredHarvester ? 2 : 1))) {

			if(isSelfPoweredHarvester) {
				//This installation can not be destroyed because there is no room for the Self Powered Harvester Kit in your inventory.
				creature->sendSystemMessage("@player_structure:inventory_full_selfpowered");
			} else {
				//This installation can not be redeeded because your inventory does not have room to put the deed.
				creature->sendSystemMessage("@player_structure:inventory_full");
			}

			creature->sendSystemMessage("@player_structure:deed_reclaimed_failed"); //Structure destroy and deed reclaimed FAILED!
			return session->cancelSession();
		} else {

			if(isSelfPoweredHarvester) {

				Reference<SceneObject*> rewardSceno = server->createObject(STRING_HASHCODE("object/tangible/veteran_reward/harvester.iff"), 1);
				if( rewardSceno == NULL ){
					creature->sendSystemMessage("@player_structure:deed_reclaimed_failed"); //Structure destroy and deed reclaimed FAILED!
					return session->cancelSession();
				}

				// Transfer to player
				if( !inventory->transferObject(rewardSceno, -1, false, true) ){ // Allow overflow
					creature->sendSystemMessage("@player_structure:deed_reclaimed_failed"); //Structure destroy and deed reclaimed FAILED!
					rewardSceno->destroyObjectFromDatabase(true);
					return session->cancelSession();
				}

				harvester->setSelfPowered(false);

				inventory->broadcastObject(rewardSceno, true);
				creature->sendSystemMessage("@player_structure:selfpowered");
			}

			deed->setSurplusMaintenance(maint - redeedCost);
			deed->setSurplusPower(structureObject->getSurplusPower());

			structureObject->setDeedObjectID(0); //Set this to 0 so the deed doesn't get destroyed with the structure.

			destroyStructure(structureObject);

			inventory->transferObject(deed, -1, true);
			inventory->broadcastObject(deed, true);
			creature->sendSystemMessage("@player_structure:deed_reclaimed"); //Structure destroyed and deed reclaimed.
		}
	} else {
		destroyStructure(structureObject);
		creature->sendSystemMessage("@player_structure:structure_destroyed"); //Structured destroyed.
	}

	return session->cancelSession();
}