예제 #1
0
void VendorManager::promptRenameVendorTo(CreatureObject* player, TangibleObject* vendor) {
	SuiInputBox* input = new SuiInputBox(player, SuiWindowType::STRUCTURE_NAME_VENDOR);
	input->setCallback(new RenameVendorSuiCallback(player->getZoneServer()));
	input->setUsingObject(vendor);
	input->setCancelButton(true, "@cancel");
	input->setPromptTitle("@player_structure:name_t");
	input->setPromptText("@player_structure:name_d");

	player->sendMessage(input->generateMessage());
	player->getPlayerObject()->addSuiBox(input);
}
void CreateVendorSessionImplementation::handleVendorSelection(byte menuID) {
	ManagedReference<CreatureObject*> player = this->player.get();

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

	VendorSelectionNode* node = currentNode->getNode(menuID);

	// Set the title and text off the parent node.
	suiSelectVendor->setPromptTitle(node->getSuiDisplay() + "t");
	suiSelectVendor->setPromptText(node->getSuiDisplay()+ "d");
	templatePath = templatePath + node->getTemplatePath();

	if (node->hasChildNode()) {
		currentNode = node;
		node->addChildrenToListBox(suiSelectVendor, hiringMod);

		/// If there are selections available for vendors
		if(suiSelectVendor->getMenuSize() != 0) {
			player->sendMessage(suiSelectVendor->generateMessage());
			player->getPlayerObject()->addSuiBox(suiSelectVendor);
			return;
		}

		templatePath = templatePath + node->getRandomTemplate(hiringMod);
		const char* path = templatePath.toCharArray();
		if (path[strlen(path) - 1] == '_')
			templatePath = templatePath + (System::random(1) == 0 ? "male.iff" : "female.iff");
	}
	SuiInputBox* input = new SuiInputBox(player, SuiWindowType::STRUCTURE_NAME_VENDOR);
	input->setCallback(new NameVendorSuiCallback(player->getZoneServer()));
	input->setCancelButton(true, "@cancel");
	input->setPromptTitle("@player_structure:name_t");
	input->setPromptText("@player_structure:name_d");

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

}
void CreateVendorSessionImplementation::createVendor(String& name) {
	ManagedReference<CreatureObject*> player = this->player.get();

	Locker locker(player);

	if (!VendorManager::instance()->isValidVendorName(name)) {
		player->sendSystemMessage("@player_structure:obscene");
		SuiInputBox* input = new SuiInputBox(player, SuiWindowType::STRUCTURE_NAME_VENDOR);
		input->setCallback(new NameVendorSuiCallback(player->getZoneServer()));
		input->setCancelButton(true, "@cancel");
		input->setPromptTitle("@player_structure:name_t");
		input->setPromptText("@player_structure:name_d");

		player->sendMessage(input->generateMessage());
		player->getPlayerObject()->addSuiBox(input);
		return;
	}

	ManagedReference<SceneObject*> inventory = player->getSlottedObject("inventory");
	if (inventory == NULL) {
		cancelSession();
		return;
	}

	ManagedReference<TangibleObject*> vendor;

	try {
		vendor = (player->getZoneServer()->createObject(templatePath.hashCode())).castTo<TangibleObject*>();
	} catch (Exception& e) {
		error(e.getMessage());
	}

	if (vendor == NULL) {
		error("could not create vendor " + templatePath);
		cancelSession();
		return;
	}

	Locker clocker(vendor, player);

	if (!vendor->isVendor()) {
		error("could not create vendor " + templatePath);
		vendor->destroyObjectFromDatabase(true);
		cancelSession();
		return;
	}

	vendor->createChildObjects();

	if (inventory->isContainerFullRecursive()) {
		player->sendSystemMessage("@player_structure:create_failed");
		vendor->destroyObjectFromDatabase(true);
		cancelSession();
		return;
	}

	DataObjectComponentReference* data = vendor->getDataObjectComponent();
	if(data == NULL || data->get() == NULL || !data->get()->isVendorData()) {
		error("Invalid vendor, no data component: " + templatePath);
		player->sendSystemMessage("@player_structure:create_failed");
		vendor->destroyObjectFromDatabase(true);
		cancelSession();
		return;
	}

	VendorDataComponent* vendorData = cast<VendorDataComponent*>(data->get());
	if(vendorData == NULL) {
		error("Invalid vendor, no data component: " + templatePath);
		player->sendSystemMessage("@player_structure:create_failed");
		vendor->destroyObjectFromDatabase(true);
		cancelSession();
		return ;
	}

	vendorData->setOwnerId(player->getObjectID());

	vendor->setCustomObjectName("Vendor: " + name, false);
	vendor->setContainerOwnerID(player->getObjectID());

	vendor->setMaxCondition(1000, false);
	vendor->setConditionDamage(0, false);

	if(vendor->isCreatureObject()) {
		randomizeVendorLooks(cast<CreatureObject*>(vendor.get()));
	}

	if(!inventory->transferObject(vendor, -1, false)) {
		player->sendSystemMessage("@player_structure:create_failed");
		vendor->destroyObjectFromDatabase(true);
		cancelSession();
		return;
	}

	inventory->broadcastObject(vendor, true);
	player->getPlayerObject()->addVendor(vendor);

	player->sendSystemMessage("@player_structure:create_success");
	cancelSession();
}