Example #1
0
void TreeNode::xPathQuery(const String& xPath, const Enumerator<TreeNode*>& enumerator, bool includeHiddenChildren, const NumberFormat* numberFormat)
{
	// Get tokens of xPath:
	Array<String> tokens;
	StringTokenizer(xPath, "/").tokenizeTo(tokens);

	int tokenIndex = 0;

	// If we have tokens:
	if (tokens.isEmpty() == false)
	{
		TreeNode* currentNode;
		if (xPath.beginsWith('/') == true)
		{
			currentNode = &getRootNode();
			if (currentNode->getName() == tokens[0])
			{
				++tokenIndex;
			}
			else
			{
				return;
			}
		}
		else
		{
			currentNode = this;
		}
		currentNode->xPathTestNode(tokens, tokenIndex, enumerator, includeHiddenChildren, numberFormat);
	}
}
void VendorDataComponent::performVendorBark(SceneObject* target) {
	if (isOnStrike()) {
		return;
	}

	ManagedReference<CreatureObject*> vendor = cast<CreatureObject*>(parent.get().get());
	if (vendor == NULL)
		return;

	ManagedReference<CreatureObject*> player = cast<CreatureObject*>(target);
	if (player == NULL || !player->isPlayerCreature())
		return;

	resetLastBark();
	addBarkTarget(target);

	EXECUTE_TASK_2(vendor, player, {
			Locker locker(vendor_p);

			VendorDataComponent* data = cast<VendorDataComponent*>(vendor_p->getDataObjectComponent()->get());

			if (data == NULL)
				return;

			vendor_p->faceObject(player_p);
			vendor_p->updateDirection(Math::deg2rad(vendor_p->getDirectionAngle()));

			SpatialChat* chatMessage = NULL;
			String barkMessage = data->getAdPhrase();

			if (barkMessage.beginsWith("@")) {
				StringIdChatParameter message;
				message.setStringId(barkMessage);
				message.setTT(player_p->getObjectID());
				chatMessage = new SpatialChat(vendor_p->getObjectID(), player_p->getObjectID(), player_p->getObjectID(), message, 50, 0, Races::getMoodID(data->getAdMood()), 0, 0);

			} else {
				UnicodeString uniMessage(barkMessage);
				chatMessage = new SpatialChat(vendor_p->getObjectID(), player_p->getObjectID(), player_p->getObjectID(), uniMessage, 50, 0, Races::getMoodID(data->getAdMood()), 0, 0);
			}

			vendor_p->broadcastMessage(chatMessage, true);
			vendor_p->doAnimation(data->getAdAnimation());

			Reference<VendorReturnToPositionTask*> returnTask = new VendorReturnToPositionTask(vendor_p, data->getOriginalDirection());
			vendor_p->addPendingTask("vendorreturn", returnTask, 3000);
		});
Example #3
0
    void findPartialPath(String const &path, FoundFiles &found) const
    {
        String baseName = path.fileName().lower();
        String dir      = path.fileNamePath().lower();

        if(!dir.empty() && !dir.beginsWith("/"))
        {
            // Always begin with a slash. We don't want to match partial folder names.
            dir = "/" + dir;
        }

        DENG2_GUARD_READ(this);

        ConstIndexRange range = index.equal_range(baseName);
        for(Index::const_iterator i = range.first; i != range.second; ++i)
        {
            File *file = i->second;
            if(file->path().fileNamePath().endsWith(dir, Qt::CaseInsensitive))
            {
                found.push_back(file);
            }
        }
    }
Example #4
0
void SuiManager::handleCharacterBuilderSelectItem(CreatureObject* player, SuiBox* suiBox, uint32 cancel, Vector<UnicodeString>* args) {
	ZoneServer* zserv = player->getZoneServer();

	if (args->size() < 1)
		return;

	bool otherPressed = false;
	int index = 0;

	if(args->size() > 1) {
		otherPressed = Bool::valueOf(args->get(0).toString());
		index = Integer::valueOf(args->get(1).toString());
	} else {
		index = Integer::valueOf(args->get(0).toString());
	}

	if (!suiBox->isCharacterBuilderBox())
		return;

	ManagedReference<SuiCharacterBuilderBox*> cbSui = cast<SuiCharacterBuilderBox*>( suiBox);

	CharacterBuilderMenuNode* currentNode = cbSui->getCurrentNode();

	PlayerObject* ghost = player->getPlayerObject();

	//If cancel was pressed then we kill the box/menu.
	if (cancel != 0)
		return;

	//Back was pressed. Send the node above it.
	if (otherPressed) {
		CharacterBuilderMenuNode* parentNode = currentNode->getParentNode();

		if(parentNode == NULL)
			return;

		cbSui->setCurrentNode(parentNode);

		ghost->addSuiBox(cbSui);
		player->sendMessage(cbSui->generateMessage());
		return;
	}

	CharacterBuilderMenuNode* node = currentNode->getChildNodeAt(index);

	//Node doesn't exist or the index was out of bounds. Should probably resend the menu here.
	if (node == NULL) {
		ghost->addSuiBox(cbSui);
		player->sendMessage(cbSui->generateMessage());
		return;
	}

	if (node->hasChildNodes()) {
		//If it has child nodes, display them.
		cbSui->setCurrentNode(node);
		ghost->addSuiBox(cbSui);
		player->sendMessage(cbSui->generateMessage());
	} else {

		String templatePath = node->getTemplatePath();

		if (templatePath.indexOf(".iff") < 0) { // Non-item selections

			if (templatePath == "unlearn_all_skills") {

				SkillManager::instance()->surrenderAllSkills(player);
				player->sendSystemMessage("All skills unlearned.");

			} else if (templatePath == "cleanse_character") {

				if (!player->isInCombat()) {
					player->sendSystemMessage("You have been cleansed from the signs of previous battles.");

					for (int i = 0; i < 9; ++i) {
						player->setWounds(i, 0);
					}

					player->setShockWounds(0);
				} else {
					player->sendSystemMessage("Not within combat.");
				}

			} else if (templatePath == "reset_buffs") {

				if (!player->isInCombat()) {
					player->sendSystemMessage("Your buffs have been reset.");

					player->clearBuffs(true);

					ghost->setFoodFilling(0);
					ghost->setDrinkFilling(0);
				} else {
					player->sendSystemMessage("Not within combat.");
				}

			} else if (templatePath.beginsWith("crafting_apron_")) {

				//"object/tangible/wearables/apron/apron_chef_s01.iff"
				//"object/tangible/wearables/ithorian/apron_chef_jacket_s01_ith.iff"

				uint32 itemCrc = ( player->getSpecies() != CreatureObject::ITHORIAN ) ? 0x5DDC4E5D : 0x6C191FBB;

				ManagedReference<WearableObject*> apron = zserv->createObject(itemCrc, 2).castTo<WearableObject*>();

				if (apron == NULL) {
					player->sendSystemMessage("There was an error creating the requested item. Please contact customer support with this issue.");
					ghost->addSuiBox(cbSui);
					player->sendMessage(cbSui->generateMessage());

					error("could not create frog crafting apron");
					return;
				}

				apron->createChildObjects();

				if (apron->isWearableObject()) {
					uint32 bitmask = apron->getOptionsBitmask() | OptionBitmask::YELLOW;
					apron->setOptionsBitmask(bitmask, false);

					UnicodeString modName = "(General)";
					apron->addSkillMod(SkillModManager::WEARABLE, "general_assembly", 25);
					apron->addSkillMod(SkillModManager::WEARABLE, "general_experimentation", 25);

					if(templatePath == "crafting_apron_armorsmith") {
						modName = "(Armorsmith)";
						apron->addSkillMod(SkillModManager::WEARABLE, "armor_assembly", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "armor_experimentation", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "armor_repair", 25);
					} else if(templatePath == "crafting_apron_weaponsmith") {
						modName = "(Weaponsmith)";
						apron->addSkillMod(SkillModManager::WEARABLE, "weapon_assembly", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "weapon_experimentation", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "weapon_repair", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "grenade_assembly", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "grenade_experimentation", 25);
					} else if(templatePath == "crafting_apron_tailor") {
						modName = "(Tailor)";
						apron->addSkillMod(SkillModManager::WEARABLE, "clothing_assembly", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "clothing_experimentation", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "clothing_repair", 25);
					} else if(templatePath == "crafting_apron_chef") {
						modName = "(Chef)";
						apron->addSkillMod(SkillModManager::WEARABLE, "food_assembly", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "food_experimentation", 25);
					} else if(templatePath == "crafting_apron_architect") {
						modName = "(Architect)";
						apron->addSkillMod(SkillModManager::WEARABLE, "structure_assembly", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "structure_experimentation", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "structure_complexity", 25);
					} else if(templatePath == "crafting_apron_droid_engineer") {
						modName = "(Droid Engineer)";
						apron->addSkillMod(SkillModManager::WEARABLE, "droid_assembly", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "droid_experimentation", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "droid_complexity", 25);
					} else if(templatePath == "crafting_apron_doctor") {
						modName = "(Doctor)";
						apron->addSkillMod(SkillModManager::WEARABLE, "medicine_assembly", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "medicine_experimentation", 25);
					} else if(templatePath == "crafting_apron_combat_medic") {
						modName = "(Combat Medic)";
						apron->addSkillMod(SkillModManager::WEARABLE, "combat_medicine_assembly", 25);
						apron->addSkillMod(SkillModManager::WEARABLE, "combat_medicine_experimentation", 25);
					}

					UnicodeString apronName = "Crafting Apron " + modName;
					apron->setCustomObjectName(apronName, false);
				}

				ManagedReference<SceneObject*> inventory = player->getSlottedObject("inventory");
				apron->sendTo(player, true);
				inventory->transferObject(apron, -1, true);

				StringIdChatParameter stringId;
				stringId.setStringId("@faction_perk:bonus_base_name"); //You received a: %TO.
				stringId.setTO(apron);
				player->sendSystemMessage(stringId);

			} else if (templatePath == "enhance_character") {

				ManagedReference<SceneObject*> scob = cbSui->getUsingObject();
				if (scob != NULL) {

					if (scob->getGameObjectType() == SceneObjectType::CHARACTERBUILDERTERMINAL) {
						CharacterBuilderTerminal* bluefrog = cast<CharacterBuilderTerminal*>( scob.get());
						bluefrog->enhanceCharacter(player);
					}
				}

			} else if (templatePath == "credits") {

				player->addCashCredits(50000, true);
				player->sendSystemMessage("You have received 50.000 Credits");

			} else if (templatePath == "faction_rebel") {

				ghost->increaseFactionStanding("rebel", 100000);

			} else if (templatePath == "faction_imperial") {

				ghost->increaseFactionStanding("imperial", 100000);

			} else if (templatePath == "language") {

				ManagedReference<SceneObject*> scob = cbSui->getUsingObject();
				if (scob != NULL) {

					if (scob->getGameObjectType() == SceneObjectType::CHARACTERBUILDERTERMINAL) {
						CharacterBuilderTerminal* bluefrog = cast<CharacterBuilderTerminal*>( scob.get());
						bluefrog->giveLanguages(player);
					}
				}

			} else if (templatePath == "apply_dots") {
				ManagedReference<SceneObject*> scob = cbSui->getUsingObject();
				player->addDotState(CreatureState::POISONED, scob->getObjectID(), 100, CreatureAttribute::HEALTH, 60, 80, 0);
				player->addDotState(CreatureState::BLEEDING, scob->getObjectID(), 100, CreatureAttribute::ACTION, 60, 80, 0);
				player->addDotState(CreatureState::DISEASED, scob->getObjectID(), 100, CreatureAttribute::ACTION, 60, 80, 0);
				player->addDotState(CreatureState::ONFIRE, scob->getObjectID(), 100, CreatureAttribute::HEALTH, 60, 80, 0);
			} else if (templatePath == "clear_dots") {
				player->clearDots();
			} else if (templatePath == "max_xp") {
				ghost->maximizeExperience();
				player->sendSystemMessage("You have maximized all xp types.");
			} else {

				if (templatePath.length() > 0) {

					SkillManager::instance()->awardSkill(templatePath, player, true, true, true);
					if (player->hasSkill(templatePath))
						player->sendSystemMessage("You have learned a skill.");

				} else {

					player->sendSystemMessage("Unknown selection.");

				}
			}

			ghost->addSuiBox(cbSui);
			player->sendMessage(cbSui->generateMessage());
		} else { // Items

			if (templatePath.contains("event_perk")) {
				if (ghost->getEventPerkCount() >= 5) {
					player->sendSystemMessage("@event_perk:pro_too_many_perks"); // You cannot rent any more items right now.
					ghost->addSuiBox(cbSui);
					player->sendMessage(cbSui->generateMessage());
					return;
				}
			}

			ManagedReference<SceneObject*> item = zserv->createObject(node->getTemplateCRC(), 1);

			if (item == NULL) {
				player->sendSystemMessage("There was an error creating the requested item. Please contact customer support with this issue.");
				ghost->addSuiBox(cbSui);
				player->sendMessage(cbSui->generateMessage());

				error("could not create frog item: " + node->getDisplayName());
				return;
			}

			item->createChildObjects();

			if (item->isEventPerkDeed()) {
				EventPerkDeed* deed = cast<EventPerkDeed*>(item.get());
				deed->setOwner(player);
				ghost->addEventPerk(deed);
			}

			ManagedReference<SceneObject*> inventory = player->getSlottedObject("inventory");
			item->sendTo(player, true);
			inventory->transferObject(item, -1, true);

			StringIdChatParameter stringId;
			stringId.setStringId("@faction_perk:bonus_base_name"); //You received a: %TO.
			stringId.setTO(item);
			player->sendSystemMessage(stringId);

			ghost->addSuiBox(cbSui);
			player->sendMessage(cbSui->generateMessage());
		}
	}
}
Example #5
0
void TreeNode::xPathTestNode(const Array<String>& tokens, int tokenIndex, const Enumerator<TreeNode*>& enumerator, bool includeHiddenChildren, const NumberFormat* numberFormat)
{
	if (tokenIndex == tokens.getCount())
	{
		// If no further path-tokens are available, we are at the end of the path,
		// and have found a target-node to add to the result:
		enumerator.enumerate(this);
	}
	else
	{
		int nextTokenIndex = tokenIndex + 1;
		const String& token = tokens[tokenIndex];
		if (token == "..")
		{
			if (parent != NULL)
			{
				parent->xPathTestNode(tokens, nextTokenIndex, enumerator, includeHiddenChildren, numberFormat);
			}
			else
			{
				argumentError("XPath invalid for current tree!" ERROR_AT);
				return;
			}
		}
		else if (token == '.')
		{
			xPathTestNode(tokens, nextTokenIndex, enumerator, includeHiddenChildren, numberFormat);
		}
		else
		{
			int where = token.findFirst('[');
			if (where == String::END)
			{
				// If no [ was found:
				// For every child-node:
				int childCount = includeHiddenChildren == true ? getChildCountIncludingHiddenChildren() : getChildCount();
				for (int i = 0; i < childCount; ++i)
				{
					TreeNode* childNode = getChild(i);
					if (childNode->getName() == token || token == '*')
					{
						// If name of child-node is valid for the next path-token:
						childNode->xPathTestNode(tokens, nextTokenIndex, enumerator, includeHiddenChildren, numberFormat);
					}
				}
			}
			else
			{
				// If [ was found:
				String name = token.subString(0, where).trimTail();
				int countOfNodesWithMatchingName = 0;
				// For every child-node:
				int childCount = includeHiddenChildren == true ? getChildCountIncludingHiddenChildren() : getChildCount();
				for (int i = 0; i < childCount; ++i)
				{
					TreeNode* childNode = getChild(i);
					if (childNode->getName() == name || name == '*')
					{
						++countOfNodesWithMatchingName;

						// If name of child-node is valid for the next path-token,
						// get expression between [ and ]:
						String expression = token.subString(where + 1, token.findLast(']') - (where + 1));
						if (expression.beginsWith('@') == true)
						{
							// If we are dealing with an attribute:
							int equalPos = expression.findFirst('=');
							if (equalPos == String::END)
							{
								String attributeName = expression.subString(1);
								if (childNode->hasAttribute(attributeName) == true)
								{
									childNode->xPathTestNode(tokens, nextTokenIndex, enumerator, includeHiddenChildren, numberFormat);
								}
							}
							else
							{
								String attributeName = expression.subString(1, equalPos-1).trimTail();
								String value = expression.subString(equalPos + 1).trimFront();
								String attribute;
								if (getAttributeIfAvailable(attributeName, attribute, numberFormat) == true && attribute == value)
								{
									childNode->xPathTestNode(tokens, nextTokenIndex, enumerator, includeHiddenChildren, numberFormat);
								}
							}
						}
						else if (expression.isDec() == true)
						{
							// If we are dealing with a node-indexer:
							if (expression.parseInt() == countOfNodesWithMatchingName)
							{
								childNode->xPathTestNode(tokens, nextTokenIndex, enumerator, includeHiddenChildren, numberFormat);
							}
						}
						else
						{
							argumentError("Unsupported XPath expression: " + token + ERROR_AT);
						}

					} // if (childNode->getName() == name || name == '*')

				} // for (int i = 0; i < childCount; ++i)

			} // else if (where == String::END)

		} // else if (token == "..") else if if (token == '.')

	} // else if (tokenIndex == tokens.getLength())

}