Esempio n. 1
0
int LuaPlayerObject::startSlicingSession(lua_State* L) {
	TangibleObject* objToSlice = (TangibleObject*) lua_touserdata(L, -2);
	bool isKeypadSlice = lua_toboolean(L, -1);

	if (objToSlice == nullptr)
		return 0;

	ManagedReference<CreatureObject*> player = realObject->getParentRecursively(SceneObjectType::PLAYERCREATURE).castTo<CreatureObject*>();

	if (player == nullptr)
		return 0;

	if (player->containsActiveSession(SessionFacadeType::SLICING)) {
		player->sendSystemMessage("@slicing/slicing:already_slicing");
		return 0;
	}

	//Create Session
	ManagedReference<SlicingSession*> session = new SlicingSession(player);
	session->setKeypadSlice(isKeypadSlice);
	session->initalizeSlicingMenu(player, objToSlice);

	return 0;
}
void SlicingSessionImplementation::initalizeSlicingMenu(CreatureObject* pl, TangibleObject* obj) {
	player = pl;
	tangibleObject = obj;

	ManagedReference<CreatureObject*> player = pl;
	ManagedReference<TangibleObject*> tangibleObject = obj;

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

	if (!tangibleObject->isSliceable() && !isBaseSlice())
		return;

	if (tangibleObject->containsActiveSession(SessionFacadeType::SLICING)) {
		player->sendSystemMessage("@slicing/slicing:slicing_underway");
		return;
	}

	if (!hasPrecisionLaserKnife(false)) { // do not remove the item on inital window
		player->sendSystemMessage("@slicing/slicing:no_knife");
		return;
	}

	//bugfix 814,819
	ManagedReference<SceneObject*> inventory = player->getSlottedObject("inventory");
	if (inventory == NULL)
		return;

	if(!isBaseSlice()){
		if (!inventory->hasObjectInContainer(tangibleObject->getObjectID()) && tangibleObject->getGameObjectType() != SceneObjectType::STATICLOOTCONTAINER
				&& tangibleObject->getGameObjectType() != SceneObjectType::MISSIONTERMINAL ) {
			player->sendSystemMessage("The object must be in your inventory in order to perform the slice.");
			return;
		}

		if (tangibleObject->isWeaponObject() && !hasWeaponUpgradeKit()) {
			player->sendSystemMessage("@slicing/slicing:no_weapon_kit");
			return;
		}

		if (tangibleObject->isArmorObject() && !hasArmorUpgradeKit()) {
			player->sendSystemMessage("@slicing/slicing:no_armor_kit");
			return;
		}
	}

	slicingSuiBox = new SuiListBox(player, SuiWindowType::SLICING_MENU, 2);
	slicingSuiBox->setCallback(new SlicingSessionSuiCallback(player->getZoneServer()));

	if (tangibleObject->getGameObjectType() == SceneObjectType::PLAYERLOOTCRATE)
		// Don't close the window when we remove PlayerLootContainer from the player's inventory.
		slicingSuiBox->setForceCloseDisabled();

	slicingSuiBox->setPromptTitle("@slicing/slicing:title");
	slicingSuiBox->setUsingObject(tangibleObject);
	slicingSuiBox->setCancelButton(true, "@cancel");
	generateSliceMenu(slicingSuiBox);

	player->getPlayerObject()->addSuiBox(slicingSuiBox);

	player->addActiveSession(SessionFacadeType::SLICING, _this.getReferenceUnsafeStaticCast());
	tangibleObject->addActiveSession(SessionFacadeType::SLICING, _this.getReferenceUnsafeStaticCast());

}
int CreateVendorSessionImplementation::initializeSession() {

	ManagedReference<CreatureObject*> player = this->player.get();

	if (player == NULL)
		return 0;

	if (player->containsActiveSession(SessionFacadeType::CREATEVENDOR)) {
		player->sendSystemMessage("@player_structure:already_creating"); // You are already creating a vendor.
		return 0;

	}

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

	if (ghost == NULL) {
		cancelSession();
		return 0;
	}

	if (ghost->getVendorCount() >= player->getSkillMod("manage_vendor")) {
		player->sendSystemMessage("@player_structure:full_vendors"); // You are already managing your maximum number of vendors. Fire someone or remove a terminal first!
		cancelSession();
		return 0;
	}

	SortedVector<unsigned long long>* ownedVendors = ghost->getOwnedVendors();
	for (int i = 0; i < ownedVendors->size(); i++) {
		ManagedReference<SceneObject*> vendor = player->getZoneServer()->getObject(ownedVendors->elementAt(i));

		if (vendor == NULL)
			continue;

		DataObjectComponentReference* data = vendor->getDataObjectComponent();
		if(data == NULL || data->get() == NULL || !data->get()->isVendorData())
			continue;

		VendorDataComponent* vendorData = cast<VendorDataComponent*>(data->get());
		if(vendorData == NULL)
			continue;

		if (!vendorData->isInitialized()) {
			player->sendSystemMessage("@player_structure:already_creating"); // You are already creating a vendor.
			cancelSession();
			return 0;
		}
	}

	currentNode = VendorManager::instance()->getRootNode();
	templatePath = "";

	if (!currentNode->hasChildNode()) {
		cancelSession();
		error("Vendor Root node has no children");
		return 0;
	}

	int hiringMod = player->getSkillMod("hiring");

	suiSelectVendor = new SuiListBox(player, SuiWindowType::STRUCTURE_CREATE_VENDOR);
	suiSelectVendor->setCallback(new CreateVendorSuiCallback(player->getZoneServer()));
	suiSelectVendor->setCancelButton(true, "@cancel");

	suiSelectVendor->setPromptTitle(currentNode->getSuiDisplay() + "t");
	suiSelectVendor->setPromptText(currentNode->getSuiDisplay() + "d");

	currentNode->addChildrenToListBox(suiSelectVendor, hiringMod);

	player->getPlayerObject()->addSuiBox(suiSelectVendor);
	player->sendMessage(suiSelectVendor->generateMessage());

	player->addActiveSession(SessionFacadeType::CREATEVENDOR, _this.getReferenceUnsafeStaticCast());

	return 0;
}