void DestroyMissionObjectiveImplementation::abort() {
	MissionObjectiveImplementation::abort();

	if (hasObservers()) {
		ManagedReference<MissionObserver*> observer = getObserver(0);

		ManagedReference<CreatureObject*> player = getPlayerOwner();

		ManagedReference<LairObject*> lair = lairObject;

		if (lair != NULL) {
			Locker locker(lair);

			lair->dropObserver(ObserverEventType::OBJECTDESTRUCTION, observer);
			lair->destroyObjectFromWorld(true);

			lair = NULL;

			dropObserver(observer, true);
		}
			//spawnActiveArea->destroyObjectFromDatabase(true);
	}

	ManagedReference<MissionSpawnActiveArea* > spawnActiveArea = this->spawnActiveArea;

	if (spawnActiveArea != NULL) {
		Locker locker(spawnActiveArea);

		spawnActiveArea->destroyObjectFromWorld(true);
	}
}
int CraftingSessionImplementation::clearSession() {
	Locker slocker(_this.get());

	ManagedReference<CraftingTool*> craftingTool = this->craftingTool.get();
	ManagedReference<CreatureObject*> crafter = this->crafter.get();
	ManagedReference<PlayerObject*> crafterGhost = this->crafterGhost.get();
	ManagedReference<CraftingStation*> craftingStation = this->craftingStation.get();
	ManagedReference<ManufactureSchematic*> manufactureSchematic = this->manufactureSchematic.get();
	ManagedReference<TangibleObject*> prototype = this->prototype.get();

	if (manufactureSchematic != NULL) {

		Locker locker(manufactureSchematic);

		if (manufactureSchematic->getParent() == craftingTool) {
			manufactureSchematic->setDraftSchematic(NULL);
			manufactureSchematic->cleanupIngredientSlots(crafter);
			manufactureSchematic->destroyObjectFromWorld(true);
		}

		this->manufactureSchematic = NULL;
	}

	if (craftingTool != NULL) {
		Locker locker2(craftingTool);

		// Remove all items that aren't the prototype
		while (craftingTool->getContainerObjectsSize() > 1) {
			craftingTool->getContainerObject(1)->destroyObjectFromWorld(true);
		}

		craftingTool->dropSlottedObject("crafted_components");

		if (prototype != NULL) {

			Locker locker3(prototype);

			if (craftingTool->isReady()) {

				if (prototype->getParent() == craftingTool) {
					prototype->destroyObjectFromWorld(true);
				}

				this->prototype = NULL;
			}
		}
	}

	if(crafterGhost != NULL && crafterGhost->getDebug()) {
		crafter->sendSystemMessage("*** Clearing crafting session ***");
	}

	return 0;
}
Example #3
0
TangibleObject* ImageDesignManager::updateHairObject(CreatureObject* creo, TangibleObject* hairObject) {
	if (creo == NULL)
		return NULL;

	ManagedReference<TangibleObject*> hair = creo->getSlottedObject("hair").castTo<TangibleObject*>();

	if (hair == hairObject) {
		return hairObject;
	}

	if (hair != NULL) {
		Locker locker(hair);
		hair->destroyObjectFromWorld(true);
		hair->destroyObjectFromDatabase(true);
	}

	if (hairObject == NULL)
		return NULL;

	// Some race condition in the client prevents both the destroy and transfer from happening too close together
	// Without it placing a hair object in the inventory.
	ManagedReference<CreatureObject*> strongCreo = creo;
	ManagedReference<TangibleObject*> strongHair = hairObject;
	Core::getTaskManager()->scheduleTask([strongCreo, strongHair]{
		Locker locker(strongCreo);
		Locker cLocker(strongCreo, strongHair);
		strongCreo->transferObject(strongHair, 4);
		strongCreo->broadcastObject(strongHair, true);
	}, "TransferHairTask", 100);

	return hair;
}
void ShipControlDeviceImplementation::storeObject(CreatureObject* player, bool force) {
	player->clearState(CreatureState::PILOTINGSHIP);

	ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();

	if (controlledObject == NULL)
		return;

	Locker clocker(controlledObject, player);

	if (!controlledObject->isInQuadTree())
		return;

	Zone* zone = player->getZone();

	if (zone == NULL)
		return;

	zone->transferObject(player, -1, false);
	
	controlledObject->destroyObjectFromWorld(true);

	transferObject(controlledObject, 4, true);
	
	updateStatus(0);
}
bool SlicingSessionImplementation::hasArmorUpgradeKit() {
	ManagedReference<CreatureObject*> player = this->player.get();
	ManagedReference<TangibleObject*> tangibleObject = this->tangibleObject.get();


	if (player == NULL)
		return false;

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

	if (inventory == NULL)
		return false;

	for (int i = 0; i < inventory->getContainerObjectsSize(); ++i) {
		ManagedReference<SceneObject*> sceno = inventory->getContainerObject(i);

		uint32 objType = sceno->getGameObjectType();

		if (objType == SceneObjectType::ARMORUPGRADEKIT) {
			Locker locker(sceno);
			sceno->destroyObjectFromWorld(true);
			sceno->destroyObjectFromDatabase(true);
			return true;
		}
	}

	return false;

}
void VehicleControlDeviceImplementation::storeObject(CreatureObject* player, bool force) {
	ManagedReference<TangibleObject*> controlledObject = this->controlledObject.get();

	if (controlledObject == NULL)
		return;

	/*if (!controlledObject->isInQuadTree())
		return;*/

	if (player->isRidingMount() && player->getParent() == controlledObject) {

		if (!force && !player->checkCooldownRecovery("mount_dismount"))
			return;

		player->executeObjectControllerAction(STRING_HASHCODE("dismount"));

		if (player->isRidingMount())
			return;
	}

	Locker crossLocker(controlledObject, player);

	controlledObject->destroyObjectFromWorld(true);

	if (controlledObject->isCreatureObject())
		(cast<CreatureObject*>(controlledObject.get()))->setCreatureLink(NULL);

	updateStatus(0);
}
void SlicingSessionImplementation::handleUseClamp() {
	ManagedReference<CreatureObject*> player = this->player.get();
	ManagedReference<TangibleObject*> tangibleObject = this->tangibleObject.get();


	if (player == NULL || tangibleObject == NULL)
		return;

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

	Locker inventoryLocker(inventory);

	for (int i = 0; i < inventory->getContainerObjectsSize(); ++i) {
		ManagedReference<SceneObject*> sceno = inventory->getContainerObject(i);

		uint32 objType = sceno->getGameObjectType();

		if (objType == SceneObjectType::MOLECULARCLAMP) {
			Locker locker(sceno);
			sceno->destroyObjectFromWorld(true);
			sceno->destroyObjectFromDatabase(true);

			player->sendSystemMessage("@slicing/slicing:used_clamp");
			usedClamp = true;
			return;
		}
	}

	player->sendSystemMessage("@slicing/slicing:no_clamp");
}
void CellObjectImplementation::destroyAllPlayerItems() {
	ManagedReference<SceneObject*> strongParent = getParent().get();

	if (strongParent == NULL)
		return;

	int containerSize = getContainerObjectsSize();

	for (int j = containerSize - 1; j >= 0; --j) {
		ReadLocker rlocker(getContainerLock());
		ManagedReference<SceneObject*> containerObject = getContainerObject(j);
		rlocker.release();

		if (strongParent->containsChildObject(containerObject))
			continue;

		if (containerObject->isCreatureObject())
			continue;

		containerObject->destroyObjectFromWorld(true);
		//containerObject->broadcastDestroy(containerObject, false);
		//removeObject(containerObject, false);

		containerObject->destroyObjectFromDatabase(true);
	}
}
int WeaponObjectMenuComponent::handleObjectMenuSelect(SceneObject* sceneObject, CreatureObject* player, byte selectedID) {
    if (!sceneObject->isTangibleObject())
        return 0;

    ManagedReference<WeaponObject*> weapon = cast<WeaponObject*>(sceneObject);
    if(weapon == NULL)
        return 1;

    if(weapon->isASubChildOf(player)) {

        if (selectedID == 69 && player->hasSkill("combat_smuggler_slicing_02")) {
            if (weapon->isSliced()) {
                player->sendSystemMessage("@slicing/slicing:already_sliced");
                return 0;
            }

            ManagedReference<Facade*> facade = player->getActiveSession(SessionFacadeType::SLICING);
            ManagedReference<SlicingSession*> session = dynamic_cast<SlicingSession*>(facade.get());

            if (session != NULL) {
                player->sendSystemMessage("@slicing/slicing:already_slicing");
                return 0;
            }

            //Create Session
            session = new SlicingSession(player);
            session->initalizeSlicingMenu(player, weapon);

            return 0;

        }

        if(selectedID == 70) {

            weapon->repair(player);
            return 1;
        }

        if(selectedID == 71) {

            ManagedReference<PowerupObject*> pup = weapon->removePowerup();
            if(pup == NULL)
                return 1;

            Locker locker(pup);

            pup->destroyObjectFromWorld( true );
            pup->destroyObjectFromDatabase( true );

            StringIdChatParameter message("powerup", "prose_remove_powerup"); //You detach your powerup from %TT.
            message.setTT(weapon->getDisplayedName());
            player->sendSystemMessage(message);

            return 1;
        }
    }

    return TangibleObjectMenuComponent::handleObjectMenuSelect(sceneObject, player, selectedID);
}
bool CreatureManagerImplementation::addWearableItem(CreatureObject* creature, TangibleObject* clothing) {

	if (!clothing->isWearableObject() && !clothing->isWeaponObject())
		return false;

	ChatManager* chatMan = zoneServer->getChatManager();

	SharedTangibleObjectTemplate* tanoData = dynamic_cast<SharedTangibleObjectTemplate*>(clothing->getObjectTemplate());
	Vector<uint32>* races = tanoData->getPlayerRaces();
	String race = creature->getObjectTemplate()->getFullTemplateString();

	if(clothing->isWearableObject()) {
		if (!races->contains(race.hashCode())) {
			UnicodeString message;

			if(creature->getObjectTemplate()->getFullTemplateString().contains("ithorian"))
				message = "@player_structure:wear_not_ithorian";
			else
				message = "@player_structure:wear_no";

			chatMan->broadcastMessage(creature, message, clothing->getObjectID(), creature->getMoodID(), 0);

			return false;
		}
	}

	ManagedReference<SceneObject*> clothingParent = clothing->getParent();

	if (clothingParent == NULL)
		return false;

	for (int i = 0; i < clothing->getArrangementDescriptorSize(); ++i) {
		Vector<String> descriptors = clothing->getArrangementDescriptor(i);

		for (int j = 0; j < descriptors.size(); ++j) {
			ManagedReference<SceneObject*> slot = creature->getSlottedObject(descriptors.get(j));

			if (slot != NULL) {
				slot->destroyObjectFromWorld(true);
				slot->destroyObjectFromDatabase(true);
			}
		}
	}

	creature->transferObject(clothing, 4, false);
	creature->doAnimation("pose_proudly");
	creature->broadcastObject(clothing, true);

	UnicodeString message;
	if(clothing->isWeaponObject())
		message = "@player_structure:wear_yes_weapon";
	else
		message = "@player_structure:wear_yes";

	chatMan->broadcastMessage(creature, message, clothing->getObjectID(), creature->getMoodID(), 0);

	return true;
}
void CraftingSessionImplementation::createManufactureSchematic(int clientCounter) {
	ManagedReference<CraftingTool*> craftingTool = this->craftingTool.get();
	ManagedReference<CreatureObject*> crafter = this->crafter.get();
	ManagedReference<PlayerObject*> crafterGhost = this->crafterGhost.get();
	ManagedReference<CraftingStation*> craftingStation = this->craftingStation.get();
	ManagedReference<ManufactureSchematic*> manufactureSchematic = this->manufactureSchematic.get();
	ManagedReference<TangibleObject*> prototype = this->prototype.get();
	ManagedReference<CraftingManager*> craftingManager = this->craftingManager.get();

	if (manufactureSchematic == NULL) {
		sendSlotMessage(0, IngredientSlot::NOSCHEMATIC);
		return;
	}

	if (prototype == NULL) {
		sendSlotMessage(0, IngredientSlot::PROTOTYPENOTFOUND);
		return;
	}

	if (!craftingManager.get()->allowManufactureSchematic(manufactureSchematic)){
		sendSlotMessage(0, IngredientSlot::NOSCHEMATIC);
		return;
	}

	Locker locker(_this.get());

	if (manufactureSchematic->isAssembled()
			&& !manufactureSchematic->isCompleted()) {

		//Object Controller
		ObjectControllerMessage* objMsg = new ObjectControllerMessage(
				crafter->getObjectID(), 0x1B, 0x010C);
		objMsg->insertInt(0x10B);
		objMsg->insertInt(1);
		objMsg->insertByte(clientCounter);

		crafter->sendMessage(objMsg);

		ManagedReference<SceneObject*> datapad = crafter->getSlottedObject("datapad");

		prototype->destroyObjectFromWorld(0);

		manufactureSchematic->setPersistent(2);
		prototype->setPersistent(2);

		datapad->transferObject(manufactureSchematic, -1, true);
		manufactureSchematic->setPrototype(prototype);

	} else {

		closeCraftingWindow(clientCounter);

		sendSlotMessage(clientCounter, IngredientSlot::WEIRDFAILEDMESSAGE);
	}

	cancelSession();
}
void PetManagerImplementation::killPet(TangibleObject* attacker, AiAgent* pet) {

	// TODO REMOVE AFTER TESTING
	bool attackerIsAdmin = false;
	// END REMOVE

	StringIdChatParameter stringId;

	if (attacker->isPlayerCreature()) {
		stringId.setStringId("base_player", "prose_target_dead");
		stringId.setTT(pet->getObjectID());
		(cast<CreatureObject*>(attacker))->sendSystemMessage(stringId);

		// TODO REMOVE AFTER TESTING
		//ManagedReference<PlayerObject*> ghost = (cast<CreatureObject*>(attacker))->getPlayerObject();
		//if (ghost != NULL && ghost->isPrivileged())
		//	attackerIsAdmin = true;
		// END REMOVE
	}

	pet->setCurrentSpeed(0);
	pet->clearCombatState(true);
	pet->setPosture(CreaturePosture::DEAD, true);
	pet->updateLocomotion();

	pet->updateTimeOfDeath();
	pet->clearBuffs(false);



	ManagedReference<PetControlDevice*> petControlDevice = pet->getControlDevice().get().castTo<PetControlDevice*>();

	if (petControlDevice != NULL) {

		if (petControlDevice->getPetType() == FACTIONPET) {
			ManagedReference<CreatureObject*> owner = zoneServer->getObject(pet->getCreatureLinkID()).castTo<CreatureObject*>();

			if (owner != NULL)
				petControlDevice->storeObject(owner, true);

			petControlDevice->destroyObjectFromWorld(true);
			petControlDevice->destroyObjectFromDatabase(true);

		} else if ( (!attacker->isPlayerCreature() && !attacker->isPet()) || attackerIsAdmin) { // TODO REMOVE attackerIsAdmin AFTER TESTING

			if (pet->getCooldownTimerMap() != NULL && pet->getCooldownTimerMap()->isPast("vitalityLossCooldown")) {

				petControlDevice->setVitality(petControlDevice->getVitality() - 2);
				pet->getCooldownTimerMap()->updateToCurrentAndAddMili("vitalityLossCooldown", 300000);
			}
		}

	}

	pet->notifyObjectKillObservers(attacker);

}
int InstrumentObserverImplementation::notifyObserverEvent(unsigned int eventType, Observable* observable, ManagedObject* arg1, int64 arg2) {
	if (eventType != ObserverEventType::POSITIONCHANGED && eventType != ObserverEventType::OBJECTREMOVEDFROMZONE) {
		return 0;
	}

	SceneObject* creature = cast<SceneObject*>(observable);

	if (creature == NULL) {
		return 0;
	}

	ManagedReference<Instrument* > instrument = this->instrument.get();

	if (instrument == NULL || instrument->getZone() == NULL) {
		if (eventType == ObserverEventType::OBJECTREMOVEDFROMZONE) {
			creature->dropObserver(ObserverEventType::POSITIONCHANGED, _this.getReferenceUnsafeStaticCast());
		} else if (eventType == ObserverEventType::POSITIONCHANGED) {
			creature->dropObserver(ObserverEventType::OBJECTREMOVEDFROMZONE, _this.getReferenceUnsafeStaticCast());
		}

		return 1;
	} else {
		Locker locker(instrument);

		if (eventType == ObserverEventType::POSITIONCHANGED) {
			if (creature->getDistanceTo(instrument) > 8) {
				instrument->destroyObjectFromWorld(true);

				creature->dropObserver(ObserverEventType::OBJECTREMOVEDFROMZONE, _this.getReferenceUnsafeStaticCast());

				return 1;
			}
		} else if (eventType == ObserverEventType::OBJECTREMOVEDFROMZONE) {
			instrument->destroyObjectFromWorld(true);

			creature->dropObserver(ObserverEventType::POSITIONCHANGED, _this.getReferenceUnsafeStaticCast());

			return 1;
		}
	}

	return 0;
}
void CityRegionImplementation::destroyActiveAreas() {
	for (int i = 0; i < regions.size(); ++i) {
		ManagedReference<Region*> aa = regions.get(i);

		if (aa != NULL) {
			Locker clocker(aa, _this.getReferenceUnsafeStaticCast());
			aa->destroyObjectFromWorld(false);
			aa->destroyObjectFromDatabase(true);
		}
	}

	regions.removeAll();
}
void FireworkObjectImplementation::beginShowLaunch(CreatureObject* player) {
	if (player == NULL || player->getParent() != NULL)
		return;

	ManagedReference<FireworkObject*> fireworkShow = _this.getReferenceUnsafeStaticCast();

	if (fireworkShow == NULL)
		return;

	DataObjectComponent* data = fireworkShow->getDataObjectComponent()->get();

	if(data == NULL || !data->isFireworkShowData())
		return;

	FireworkShowDataComponent* fireworkShowData = cast<FireworkShowDataComponent*>(data);

	if (fireworkShowData->getTotalFireworkCount() == 0)
		return;

	ManagedReference<StaticObject*> showLauncherObject = (getZoneServer()->createObject(fireworkObject.hashCode(), 0)).castTo<StaticObject*>();

	if (showLauncherObject == NULL)
		return;

	player->setPosture(CreaturePosture::CROUCHED);
	player->doAnimation("manipulate_low");

	float angle = player->getDirectionAngle();

	if (angle > 360)
		angle = angle - 360;

	float distance = 2.0;

	angle = 2 * M_PI * angle / 360;

	int x = player->getPositionX() + sin(angle) * (distance);
	int y = player->getPositionY() + cos(angle) * (distance);
	int z = player->getZone()->getHeight(x, y);
	Locker locker(showLauncherObject);
	showLauncherObject->initializePosition(x, z, y);
	player->getZone()->transferObject(showLauncherObject, -1, true);

	fireworkShow->destroyObjectFromWorld(true);

	int launchDelay = fireworkShowData->getFireworkDelay(0);
	Reference<FireworkShowLaunchFireworkEvent*> fireworkShowLaunchFireworkEvent = new FireworkShowLaunchFireworkEvent(player, fireworkShow, fireworkShowData, showLauncherObject);
	fireworkShowLaunchFireworkEvent->schedule(launchDelay);

}
void DestroyMissionObjectiveImplementation::destroyObjectFromDatabase() {
	MissionObjectiveImplementation::destroyObjectFromDatabase();

	ManagedReference<MissionSpawnActiveArea* > spawnActiveArea = this->spawnActiveArea;

	if (spawnActiveArea != NULL) {
		Locker locker(spawnActiveArea);

		spawnActiveArea->destroyObjectFromWorld(true);
		spawnActiveArea->destroyObjectFromDatabase(true);

		this->spawnActiveArea = NULL;
	}
}
void CityRegionImplementation::removeAllDecorations() {
	Locker slocker(&structureListMutex);

	for (int i = cityDecorations.size() - 1; i >= 0 ; --i) {
		ManagedReference<SceneObject*> dec = cityDecorations.get(i);
		if(dec->isStructureObject()) {
			StructureManager::instance()->destroyStructure(cast<StructureObject*>(dec.get()));
		} else {
			dec->destroyObjectFromWorld(false);
			dec->destroyObjectFromDatabase(true);
		}
	}

	cityDecorations.removeAll();
}
void SceneObjectImplementation::destroyChildObjects() {
	int size = childObjects.size();

	for (int i = 0; i < size; i++) {
		ManagedReference<SceneObject*> child = childObjects.get(0);

		if (child == NULL)
			continue;

		Locker clocker(child, asSceneObject());

		childObjects.drop(child);
		child->destroyObjectFromDatabase(true);
		child->destroyObjectFromWorld(true);
	}
}
void WeaponObjectImplementation::decreasePowerupUses(CreatureObject* player) {
	if (hasPowerup()) {
		powerupObject->decreaseUses();
		if (powerupObject->getUses() < 1) {
			Locker locker(_this.getReferenceUnsafeStaticCast());
			StringIdChatParameter message("powerup", "prose_pup_expire"); //The powerup on your %TT has expired.
			message.setTT(getDisplayedName());

			player->sendSystemMessage(message);

			ManagedReference<PowerupObject*> pup = removePowerup();
			if(pup != NULL) {
				Locker plocker(pup);

				pup->destroyObjectFromWorld( true );
				pup->destroyObjectFromDatabase( true );
			}
		}
		sendAttributeListTo(player);
	}
}
void SlicingSessionImplementation::handleUseFlowAnalyzer() {
	ManagedReference<CreatureObject*> player = this->player.get();
	ManagedReference<TangibleObject*> tangibleObject = this->tangibleObject.get();


	if (player == NULL || tangibleObject == NULL)
		return;

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

	Locker inventoryLocker(inventory);

	for (int i = 0; i < inventory->getContainerObjectsSize(); ++i) {
		ManagedReference<SceneObject*> sceno = inventory->getContainerObject(i);

		uint32 objType = sceno->getGameObjectType();

		if (objType == SceneObjectType::FLOWANALYZER) {
			SlicingTool* node = cast<SlicingTool*>( sceno.get());
			nodeCable = node->calculateSuccessRate();

			if (nodeCable) // PASSED
				nodeCable = firstCable;
			else if (nodeCable == firstCable) { // Failed but the cables are Correct
				if (firstCable)
					nodeCable = 0; // Failed - Make the Cable incorrect
			}

			Locker locker(sceno);
			sceno->destroyObjectFromWorld(true);
			sceno->destroyObjectFromDatabase(true);

			player->sendSystemMessage("@slicing/slicing:used_node");
			usedNode = true;
			return;
		}
	}

	player->sendSystemMessage("@slicing/slicing:no_node");
}
Example #21
0
TangibleObject* ImageDesignManager::updateHairObject(CreatureObject* creo, TangibleObject* hairObject) {
	if (creo == NULL)
		return NULL;

	ManagedReference<TangibleObject*> hair = creo->getSlottedObject("hair").castTo<TangibleObject*>();

	if (hair != NULL) {
		Locker locker(hair);
		hair->destroyObjectFromWorld(true);
		hair->destroyObjectFromDatabase(true);
	}

	if (hairObject == NULL)
		return NULL;

	Locker locker(hairObject);

	creo->transferObject(hairObject, 4);
	creo->broadcastObject(hairObject, true);

	return hair;
}
void CreateVendorSessionImplementation::randomizeVendorClothing(CreatureObject* vendor, VendorCreatureTemplate* vendorTempl) {

	String randomOutfit = vendorTempl->getOutfitName(System::random(vendorTempl->getOutfitsSize() -1));
	if (randomOutfit.isEmpty())
		return;

	Reference<Outfit*> outfit = VendorOutfitManager::instance()->getOutfit(randomOutfit);
	if (outfit == NULL)
		return;

	Vector<uint32>* clothing = outfit->getClothing();

	for (int i = 0; i < clothing->size(); ++i) {
		ManagedReference<SceneObject*> obj = player->getZoneServer()->createObject(clothing->get(i), 1);
		if (obj == NULL)
			continue;

		for (int j = 0; j < obj->getArrangementDescriptorSize(); ++j) {
			const Vector<String>* descriptors = obj->getArrangementDescriptor(j);

			for (int k = 0; k < descriptors->size(); ++k) {
				ManagedReference<SceneObject*> slot = vendor->getSlottedObject(descriptors->get(k));

				if (slot != NULL) {
					slot->destroyObjectFromWorld(true);
					slot->destroyObjectFromDatabase(true);
				}
			}
		}

		if (!vendor->transferObject(obj, 4)) {
			obj->destroyObjectFromDatabase(true);
		}
	}

}
bool ZoneContainerComponent::removeObject(SceneObject* sceneObject, SceneObject* object, SceneObject* destination, bool notifyClient) {
	Zone* zone = dynamic_cast<Zone*>(sceneObject);

	if (object->isActiveArea())
		return removeActiveArea(zone, dynamic_cast<ActiveArea*>(object));

	ManagedReference<SceneObject*> parent = object->getParent();
	//SortedVector<ManagedReference<SceneObject*> >* notifiedSentObjects = sceneObject->getNotifiedSentObjects();

	try {
		Locker locker(object);

		if (zone == NULL)
			return false;

		object->info("removing from zone");

		Locker zoneLocker(zone);

		if (parent != NULL) {
			parent->removeObject(object, NULL, false);
		} else
			zone->remove(object);
			
		Zone* oldZone = zone;
			
//		oldZone->dropSceneObject(object);
		
//		zoneLocker.release();

		SortedVector<ManagedReference<QuadTreeEntry*> >* closeObjects = object->getCloseObjects();

		if (closeObjects != NULL) {
			try {
				while (closeObjects->size() > 0) {
					ManagedReference<QuadTreeEntry*> obj = closeObjects->get(0);

					if (obj != NULL && obj != object && obj->getCloseObjects() != NULL)
						obj->removeInRangeObject(object);

					object->removeInRangeObject((int) 0);
				}
			} catch (...) {
			}
		} else {
			object->info("Null closeobjects vector in ZoneContainerComponent::removeObject", true);
			SortedVector<ManagedReference<QuadTreeEntry*> > closeSceneObjects;

			zone->getInRangeObjects(object->getPositionX(), object->getPositionY(), 512, &closeSceneObjects, false);

			for (int i = 0; i < closeSceneObjects.size(); ++i) {
				QuadTreeEntry* obj = closeSceneObjects.get(i);

				if (obj != NULL && obj != object && obj->getCloseObjects() != NULL)
					obj->removeInRangeObject(object);
			}
		}

//		Zone* oldZone = zone;
		zone = NULL;

		oldZone->dropSceneObject(object);

		SharedBuildingObjectTemplate* objtemplate = dynamic_cast<SharedBuildingObjectTemplate*>(object->getObjectTemplate());

		if (objtemplate != NULL) {
			String modFile = objtemplate->getTerrainModificationFile();

			if (!modFile.isEmpty()) {
				oldZone->getPlanetManager()->getTerrainManager()->removeTerrainModification(object->getObjectID());
			}
		}

		zoneLocker.release();

		if (object->isTangibleObject()) {
			TangibleObject* tano = cast<TangibleObject*>(object);
			Vector<ManagedReference<ActiveArea*> >* activeAreas = tano->getActiveAreas();

			while (activeAreas->size() > 0) {
				Locker _alocker(object->getContainerLock());

				ManagedReference<ActiveArea*> area = activeAreas->get(0);
				activeAreas->remove(0);

				_alocker.release();

				area->enqueueExitEvent(object);
			}
		}

		SortedVector<ManagedReference<SceneObject*> >* childObjects = object->getChildObjects();

		//Remove all outdoor child objects from zone
		for (int i = 0; i < childObjects->size(); ++i) {
			ManagedReference<SceneObject*> outdoorChild = childObjects->get(i);

			if (outdoorChild == NULL)
				continue;

			if (outdoorChild->isInQuadTree()) {
				Locker locker(outdoorChild);

				outdoorChild->destroyObjectFromWorld(true);
			}
		}

	} catch (Exception& e) {

	}

	object->notifyObservers(ObserverEventType::OBJECTREMOVEDFROMZONE, NULL, 0);

	VectorMap<uint32, ManagedReference<Facade*> >* objectActiveSessions = object->getObjectActiveSessions();

	while (objectActiveSessions->size()) {
		ManagedReference<Facade*> facade = objectActiveSessions->remove(0).getValue();

		if (facade == NULL)
			continue;

		facade->cancelSession();
	}

	//activeAreas.removeAll();

	object->info("removed from zone");

	object->notifyRemoveFromZone();

	object->setZone(NULL);

	return true;
}
void DroidDeedImplementation::updateCraftingValues(CraftingValues* values, bool firstUpdate) {
	/*
	 * Values available:	Range:
	 *
	 */
	String key;
	ManagedReference<DroidComponent*> comp = NULL;
	HashTableIterator<String, ManagedReference<DroidComponent*> > iterator = modules.iterator();
	for(int i = 0; i < modules.size(); ++i) {
		iterator.getNextKeyAndValue(key, comp);
		if (comp) {
			comp->destroyObjectFromWorld(true);
			comp->destroyObjectFromDatabase(true);
		}
	}
	modules.removeAll();

	overallQuality = values->getCurrentPercentage("power_level"); // effectiveness
	if (overallQuality < 0)
		overallQuality = 0.1;

	combatRating = values->getCurrentValue("cmbt_module");
	if (combatRating < 0)
		combatRating = 0;
	// @TODO Add crafting values, this should adjust toHit and Speed based on droid ham, also

	// we need to stack modules if they are stackable.
	// walk all components and ensure we have all modules that are stackable there.

	ManagedReference<ManufactureSchematic*> manufact = values->getManufactureSchematic();
	for (int i = 0; i < manufact->getSlotCount(); ++i) {
		// Droid Component Slots
		Reference<IngredientSlot* > iSlot = manufact->getSlot(i);
		if (iSlot->isComponentSlot()) {
			ComponentSlot* cSlot = cast<ComponentSlot*>(iSlot.get());
			ManagedReference<TangibleObject*> tano = cSlot->getPrototype();
			ManagedReference<DroidComponent*> component = cast<DroidComponent*>( tano.get());
			// only check modules
			if (component != NULL) {
				if (component->isSocketCluster()) {
					// pull out the objects
					ManagedReference<SceneObject*> craftingComponents = component->getSlottedObject("crafted_components");
					if(craftingComponents != NULL) {
						SceneObject* satchel = craftingComponents->getContainerObject(0);
						for (int i = 0; i < satchel->getContainerObjectsSize(); ++i) {
							ManagedReference<SceneObject*> sceno = satchel->getContainerObject(i);
							if (sceno != NULL) {
								// now we have the componet used in this socket item
								ManagedReference<DroidComponent*> sub = cast<DroidComponent*>( sceno.get());
								if (sub != NULL) {
									DataObjectComponentReference* data = sub->getDataObjectComponent();
									BaseDroidModuleComponent* module = NULL;
									if(data != NULL && data->get() != NULL && data->get()->isDroidModuleData() ){
										module = cast<BaseDroidModuleComponent*>(data->get());
									}
									if (module == NULL) {
										continue;
									}
									processModule(module,sceno->getServerObjectCRC());
								}
							}
						}
					}
				} else {
					DataObjectComponentReference* data = component->getDataObjectComponent();
					BaseDroidModuleComponent* module = NULL;
					if(data != NULL && data->get() != NULL && data->get()->isDroidModuleData() ){
						module = cast<BaseDroidModuleComponent*>(data->get());
					}
					if (module == NULL) {
						continue;
					}
					processModule(module,tano->getServerObjectCRC());
				}
			}
		}
	}
	// module stacking is completed!
}
void SlicingSessionImplementation::handleContainerSlice() {
	ManagedReference<CreatureObject*> player = this->player.get();
	ManagedReference<TangibleObject*> tangibleObject = this->tangibleObject.get();

	if (tangibleObject == NULL || player == NULL)
		return;

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

	if (inventory == NULL)
		return;

	Locker inventoryLocker(inventory);

	LootManager* lootManager = player->getZoneServer()->getLootManager();

	if (tangibleObject->getGameObjectType() == SceneObjectType::PLAYERLOOTCRATE) {
		Reference<SceneObject*> containerSceno = player->getZoneServer()->createObject(STRING_HASHCODE("object/tangible/container/loot/loot_crate.iff"), 1);

		if (containerSceno == NULL)
			return;

		Locker clocker(containerSceno, player);

		Container* container = dynamic_cast<Container*>(containerSceno.get());

		if (container == NULL) {
			containerSceno->destroyObjectFromDatabase(true);
			return;
		}

		if (System::random(10) != 4)
			lootManager->createLoot(container, "looted_container");

		inventory->transferObject(container, -1);
		container->sendTo(player, true);

		if (inventory->hasObjectInContainer(tangibleObject->getObjectID())) {
			//inventory->removeObject(tangibleObject, true);
			tangibleObject->destroyObjectFromWorld(true);
		}

		tangibleObject->destroyObjectFromDatabase(true);

	} else if (tangibleObject->isContainerObject()) {
       
		Container* container = dynamic_cast<Container*>(tangibleObject.get());
        if (container == NULL)
			return;

		container->setSliced(true);
		container->setLockedStatus(false);

		if(!container->isRelocking())
		{
			relockEvent = new RelockLootContainerEvent(container);
			relockEvent->schedule(container->getLockTime());
		}
	} else
		return;

	player->sendSystemMessage("@slicing/slicing:container_success");
}
void DestroyMissionObjectiveImplementation::spawnLair() {
	ManagedReference<MissionObject* > mission = this->mission.get();

	ManagedReference<MissionSpawnActiveArea* > spawnActiveArea = this->spawnActiveArea;

	if (spawnActiveArea == NULL)
		return;

	if (lairObject != NULL && lairObject->getZone() != NULL)
		return;

	Zone* zone = spawnActiveArea->getZone();

	Locker locker(spawnActiveArea);

	spawnActiveArea->destroyObjectFromWorld(true);

	Vector3 pos = findValidSpawnPosition(zone);

	ManagedReference<WaypointObject*> waypoint = mission->getWaypointToMission();

	if (waypoint == NULL) {
		waypoint = mission->createWaypoint();
	}

	waypoint->setPosition(pos.getX(), 0, pos.getY());
	mission->updateMissionLocation();

	mission->setStartPosition(pos.getX(), pos.getY());

	//TODO: find correct string id
	ManagedReference<CreatureObject*> player = getPlayerOwner();

	if (player != NULL) {
		player->sendSystemMessage("Transmission Received: Mission Target has been located.  Mission waypoint has been updated to exact location");
	}

	LairTemplate* lair = CreatureTemplateManager::instance()->getLairTemplate(lairTemplate.hashCode());

	if (lair == NULL) {
		error("incorrect lair template in destroy mission objective " + lairTemplate);
		abort();
		return;
	}

	if (lairObject == NULL) {
		String buildingToSpawn = lair->getMissionBuilding(difficulty);

	 	if (buildingToSpawn.isEmpty()) {
	 		error("error spawning " + buildingToSpawn);
	 		abort();
	 		return;
	 	}

		lairObject = zone->getZoneServer()->createObject(buildingToSpawn.hashCode(), 0).castTo<LairObject*>();

	 	if (lairObject == NULL) {
	 		error("error spawning " + buildingToSpawn);
	 		abort();
	 		return;
	 	}

	 	Locker locker(lairObject);

	 	lairObject->setFaction(lair->getFaction());
	 	lairObject->setPvpStatusBitmask(CreatureFlag::ATTACKABLE);
	 	lairObject->setOptionsBitmask(0, false);
	 	lairObject->setMaxCondition(difficultyLevel * (900 + System::random(200)));
	 	lairObject->setConditionDamage(0, false);
	 	lairObject->initializePosition(pos.getX(), pos.getZ(), pos.getY());
	 	lairObject->setDespawnOnNoPlayersInRange(false);

		ManagedReference<MissionObserver*> observer = new MissionObserver(_this.get());
		addObserver(observer, true);

		lairObject->registerObserver(ObserverEventType::OBJECTDESTRUCTION, observer);

	 	ManagedReference<DestroyMissionLairObserver*> lairObserver = new DestroyMissionLairObserver();
	 	lairObserver->deploy();
	 	lairObserver->setLairTemplate(lair);
	 	lairObserver->setDifficulty(difficulty);
	 	lairObserver->setObserverType(ObserverType::LAIR);
	 	lairObserver->setSize(mission->getSize());

	 	lairObject->registerObserver(ObserverEventType::OBJECTDESTRUCTION, lairObserver);
	 	lairObject->registerObserver(ObserverEventType::DAMAGERECEIVED, lairObserver);
	 	lairObject->registerObserver(ObserverEventType::AIMESSAGE, lairObserver);
	 	lairObject->registerObserver(ObserverEventType::OBJECTREMOVEDFROMZONE, lairObserver);

		zone->transferObject(lairObject, -1, true);

		lairObserver->checkForNewSpawns(lairObject, NULL, true);
	}

	if (lairObject != NULL && lairObject->getZone() == NULL) {
		zone->transferObject(lairObject, -1, true);
	}
}
void TangibleObjectImplementation::repair(CreatureObject* player) {

	if(player == NULL || player->getZoneServer() == NULL)
		return;

	if(!isASubChildOf(player))
		return;

	if (getConditionDamage() == 0) {
		player->sendSystemMessage("That item is not in need of repair.");
		return;
	}

	//Condition is unrepairable
	if ((getMaxCondition() - getConditionDamage()) <= 0) {
		StringIdChatParameter cantrepair("error_message", "sys_repair_unrepairable");
		cantrepair.setTT(getDisplayedName());
		player->sendSystemMessage(cantrepair); //%TT's condition is beyond repair even for your skills.
		return;
	}

	SceneObject* inventory = player->getSlottedObject("inventory");
	if(inventory == NULL)
		return;

	ManagedReference<RepairTool*> repairTool = NULL;
	Reference<RepairToolTemplate*> repairTemplate = NULL;

	for(int i = 0; i < inventory->getContainerObjectsSize(); ++i) {
		ManagedReference<SceneObject*> item = inventory->getContainerObject(i);
		if(item->isRepairTool()) {
			repairTemplate = cast<RepairToolTemplate*>(item->getObjectTemplate());

			if (repairTemplate == NULL) {
				error("No RepairToolTemplate for: " + String::valueOf(item->getServerObjectCRC()));
				return;
			}

			if(repairTemplate->getRepairType() & getGameObjectType()) {
				repairTool = cast<RepairTool*>(item.get());
				break;
			}
			repairTemplate = NULL;
		}
	}

	if(repairTool == NULL)
		return;

	/// Luck Roll + Profession Mod(25) + Luck Tapes
	/// + Station Mod - BF

	/// Luck Roll
	int roll = System::random(100);
	int repairChance = roll;

	/// Profession Bonus
	if(player->hasSkill(repairTemplate->getSkill()))
		repairChance += 35;

	/// Get Skill mods
	repairChance += player->getSkillMod(repairTemplate->getSkillMod());
	repairChance += player->getSkillMod("crafting_repair");
	repairChance += player->getSkillMod("force_repair_bonus");

	/// use tool quality to lower chances if bad tool
	float quality = 1.f - (((100.f - repairTool->getQuality()) / 2) / 100.f);
	repairChance *= quality;

	ManagedReference<PlayerManager*> playerMan = player->getZoneServer()->getPlayerManager();

	/// Increase if near station
	if(playerMan->getNearbyCraftingStation(player, repairTemplate->getStationType()) != NULL) {
		repairChance += 15;
	}

	/// Subtract battle fatigue
	repairChance -= (player->getShockWounds() / 2);

	/// Subtract complexity
	repairChance -= (getComplexity() / 3);

	/// 5% random failure
	if(getMaxCondition() < 20 || roll < 5)
		repairChance = 0;

	if(roll > 95)
		repairChance = 100;

	String result = repairAttempt(repairChance);

	Locker locker(repairTool);

	repairTool->destroyObjectFromWorld(true);
	repairTool->destroyObjectFromDatabase(true);

	player->sendSystemMessage(result);
}