void LightsaberCrystalComponentImplementation::tuneCrystal(CreatureObject* player) {

	if(!player->hasSkill("force_title_jedi_rank_01") || !hasPlayerAsParent(player)) {
		return;
	}

	if ((owner == "")){
		String name = player->getDisplayedName();
		setOwner(name);

		// Color code is lime green.
		String tuneName;
		if (getCustomObjectName().toString().contains("(Exceptional)"))
			tuneName = "\\#00FF00" + postTuneName + " (Exceptional) (tuned)";
		else if (getCustomObjectName().toString().contains("(Legendary)"))
			tuneName = "\\#00FF00" + postTuneName + " (Legendary) (tuned)";
		else
			tuneName = "\\#00FF00" + postTuneName + " (tuned)";

		setCustomObjectName(tuneName, true);
		player->sendSystemMessage("@jedi_spam:crystal_tune_success");
	} else {
		player->sendSystemMessage("This crystal has already been tuned.");
	}
}
void LightsaberCrystalComponentImplementation::tuneCrystal(CreatureObject* player) {

	if ((owner == "") && player->hasSkill("force_title_jedi_rank_01")){
			
			String name = player->getDisplayedName();
			setOwner(name);

			// Color code is lime green.
			String tuneName = "\\#00FF00" + postTuneName + " (tuned)";
			setCustomObjectName(tuneName, true);
			player->sendSystemMessage("@jedi_spam:crystal_tune_success");
		} else {
			player->sendSystemMessage("This crystal has already been successfully tuned.");
		
	}	
		
}
void CreatureImplementation::loadTemplateDataForBaby(CreatureTemplate* templateData) {
	loadTemplateData(templateData);

	setCustomObjectName(getDisplayedName() + " (baby)", false);

	setHeight(templateData->getScale() * 0.46, false);

	int newLevel = level / 10;
	if (newLevel < 1)
		newLevel = 1;

	setLevel(newLevel, false);

	setBaby(true);

	clearPvpStatusBit(CreatureFlag::AGGRESSIVE, false);
	clearPvpStatusBit(CreatureFlag::ENEMY, false);
	setCreatureBitmask(getCreatureBitmask() + CreatureFlag::BABY);
}
void LightsaberCrystalComponentImplementation::tuneCrystal(CreatureObject* player) {
	if(!player->hasSkill("force_title_jedi_rank_01") || !hasPlayerAsParent(player)) {
		return;
	}

	if (getColor() == 31) {
		ManagedReference<PlayerObject*> ghost = player->getPlayerObject();

		if (ghost == NULL)
			return;

		int tuningCost = 100 + (quality * 75);

		if (ghost->getForcePower() <= tuningCost) {
			player->sendSystemMessage("@jedi_spam:no_force_power");
			return;
		}

		ghost->setForcePower(ghost->getForcePower() - tuningCost);
	}

	if (ownerID == 0) {
		validateCrystalStats();

		ownerID = player->getObjectID();
		ownerName = player->getDisplayedName();

		// Color code is lime green.
		String tuneName = StringIdManager::instance()->getStringId(objectName.getFullPath().hashCode()).toString();
		if (getCustomObjectName().toString().contains("(Exceptional)"))
			tuneName = "\\#00FF00" + tuneName + " (Exceptional) (tuned)\\#.";
		else if (getCustomObjectName().toString().contains("(Legendary)"))
			tuneName = "\\#00FF00" + tuneName + " (Legendary) (tuned)\\#.";
		else
			tuneName = "\\#00FF00" + tuneName + " (tuned)\\#.";

		setCustomObjectName(tuneName, true);
		player->notifyObservers(ObserverEventType::TUNEDCRYSTAL, _this.getReferenceUnsafeStaticCast(), 0);
		player->sendSystemMessage("@jedi_spam:crystal_tune_success");
	}
}
void PowerupObjectImplementation::updateCraftingValues(CraftingValues* values, bool firstUpdate) {
	/// effect 1-100

	Reference<PowerupTemplate*> pup = cast<PowerupTemplate*>(templateObject.get());
	if(pup == NULL) {
		return;
	}

	if(firstUpdate) {

		String key;
		String value;

		if(pup->hasPrimaryAttribute()) {
			PowerupStat stat = pup->getRandomPrimaryAttribute();
			modifiers.add(stat);

			StringBuffer name;
			name << "A " << stat.getName() << " " << pup->getBaseName();

			setCustomObjectName(name.toString(), true);
		}

		type = pup->getType().toLowerCase();
		uses = 100; // Powerups are always 100 uses

	} else {

		if(pup->hasSecondaryAttribute()) {

			PowerupStat stat = pup->getRandomSecondaryAttribute();

			if(System::random(3) == 1) {
				for(int i = 0; i < modifiers.size(); ++i) {
					if(stat == modifiers.get(i))  {
						return;
					}
				}

				if(modifiers.size() == 1) {
					StringBuffer name;
					name << getCustomObjectName().toString() << " of " << stat.getName();

					setCustomObjectName(name.toString(), true);
				}

				modifiers.add(stat);
			}
		}
	}

	float val = values->getCurrentValue("effect");

	for(int i  = 0; i < modifiers.size(); ++i) {
		PowerupStat* stat = &modifiers.get(i);

		// Primary Stat always increases
		if(i == 0) {
			stat->setValue((val / values->getMaxValue("effect")) * MAXPRIMARY);
			continue;
		}

		// First secondary stat has weird rules
		if(i == 1) {

			/// If there is only 1 secondary stat, it increases as expected
			if(modifiers.size() == 2) {

				stat->setValue((val / values->getMaxValue("effect")) * MAXSECONDARY);
				continue;

			/// If there are more than 1 secondary stat, and the values
			/// is less than 10, the first secondary stat doesn't increase
			} else if(modifiers.size() >= 2 && stat->getValue() < 10) {

				continue;
			}
		}

		/// It seems like we divide the change in values between the
		/// Remaining stats
		float statsLeft = modifiers.size() - i;

		float newValue = (val / values->getMaxValue("effect")) * MAXSECONDARY;
		float valueChange = (newValue - stat->getValue()) / statsLeft;

		stat->setValue(stat->getValue() + valueChange);
	}
}
Ejemplo n.º 6
0
TangibleObject* LootManagerImplementation::createLootObject(LootItemTemplate* templateObject, int level, bool maxCondition) {

	if(level < 1)
		level = 1;

	if(level > 300)
		level = 300;

	String directTemplateObject = templateObject->getDirectObjectTemplate();

	ManagedReference<TangibleObject*> prototype = zoneServer->createObject(directTemplateObject.hashCode(), 2).castTo<TangibleObject*>();

	if (prototype == NULL) {
		error("could not create loot object: " + directTemplateObject);
		return NULL;
	}

	prototype->createChildObjects();

	String serial = craftingManager->generateSerial();
	prototype->setSerialNumber(serial);
	prototype->setJunkDealerNeeded(templateObject->getJunkDealerTypeNeeded());
	float junkMinValue = templateObject->getJunkMinValue() * junkValueModifier;
	float junkMaxValue = templateObject->getJunkMaxValue() * junkValueModifier;
	float fJunkValue = junkMinValue+System::random(junkMaxValue-junkMinValue);

	if (level>0 && templateObject->getJunkDealerTypeNeeded()>1){
		fJunkValue=fJunkValue + (fJunkValue * ((float)level / 100)); // This is the loot value calculation if the item has a level
	}
	CraftingValues craftingValues = templateObject->getCraftingValuesCopy();

	setInitialObjectStats(templateObject, &craftingValues, prototype);

	setCustomObjectName(prototype, templateObject);

	float excMod = 1.0;

	if (System::random(legendaryChance) == legendaryChance) {
			uint32 bitmask = prototype->getOptionsBitmask() | OptionBitmask::YELLOW;

			UnicodeString newName = prototype->getDisplayedName() + " (Legendary)";
			prototype->setCustomObjectName(newName, false);

			excMod = legendaryModifier;

			prototype->setOptionsBitmask(bitmask, false);
	} else if (System::random(exceptionalChance) == exceptionalChance) {
		uint32 bitmask = prototype->getOptionsBitmask() | OptionBitmask::YELLOW;

		UnicodeString newName = prototype->getDisplayedName() + " (Exceptional)";
		prototype->setCustomObjectName(newName, false);

		excMod = exceptionalModifier;

		prototype->setOptionsBitmask(bitmask, false);
	}
	String subtitle;
	bool yellow = false;

	for (int i = 0; i < craftingValues.getExperimentalPropertySubtitleSize(); ++i) {
		subtitle = craftingValues.getExperimentalPropertySubtitle(i);

		if (subtitle == "hitpoints" || subtitle == "maxrange") {
			if(!(prototype->isComponent())) {
				continue;
			}
		}

		float min = craftingValues.getMinValue(subtitle);
		float max = craftingValues.getMaxValue(subtitle);

		if (min == max)
			continue;

		if (subtitle != "useCount" &&
				subtitle != "quantity" &&
				subtitle != "charges" &&
				subtitle != "uses" &&
				subtitle != "charge") {

			float minMod = (max > min) ? 2000.f : -2000.f;
			float maxMod = (max > min) ? 500.f : -500.f;

			if (max > min && min >= 0) { // Both max and min non-negative, max is higher
				min = ((min * level / minMod) + min) * excMod;
				max = ((max * level / maxMod) + max) * excMod;

			} else if (max > min && max <= 0) { // Both max and min are non-positive, max is higher
				minMod *= -1;
				maxMod *= -1;
				min = ((min * level / minMod) + min) / excMod;
				max = ((max * level / maxMod) + max) / excMod;

			} else if (max > min) { // max is positive, min is negative
				minMod *= -1;
				min = ((min * level / minMod) + min) / excMod;
				max = ((max * level / maxMod) + max) * excMod;

			} else if (max < min && max >= 0) { // Both max and min are non-negative, min is higher
				min = ((min * level / minMod) + min) / excMod;
				max = ((max * level / maxMod) + max) / excMod;

			} else if (max < min && min <= 0) { // Both max and min are non-positive, min is higher
				minMod *= -1;
				maxMod *= -1;
				min = ((min * level / minMod) + min) * excMod;
				max = ((max * level / maxMod) + max) * excMod;

			} else { // max is negative, min is positive
				maxMod *= -1;
				min = ((min * level / minMod) + min) / excMod;
				max = ((max * level / maxMod) + max) * excMod;
			}
		} else {
			if (excMod != 1.0) {
				min *= yellowModifier;
				max *= yellowModifier;
			}
		}

		if (excMod == 1.0 && (yellowChance == 0 || System::random(yellowChance) == 0)) {
			if (max > min && min >= 0) {
				min *= yellowModifier;
				max *= yellowModifier;
			} else if (max > min && max <= 0) {
				min /= yellowModifier;
				max /= yellowModifier;
			} else if (max > min) {
				min /= yellowModifier;
				max *= yellowModifier;
			} else if (max < min && max >= 0) {
				min /= yellowModifier;
				max /= yellowModifier;
			} else if (max < min && min <= 0) {
				min *= yellowModifier;
				max *= yellowModifier;
			} else {
				min /= yellowModifier;
				max *= yellowModifier;
			}

			yellow = true;
		}

		craftingValues.setMinValue(subtitle, min);
		craftingValues.setMaxValue(subtitle, max);

		float percentage = System::random(10000) / 10000.f;

		craftingValues.setCurrentPercentage(subtitle, percentage);
	}

	if (yellow) {
		uint32 bitmask = prototype->getOptionsBitmask() | OptionBitmask::YELLOW;
		prototype->setOptionsBitmask(bitmask, false);
		prototype->setJunkValue((int)(fJunkValue * 1.25));
	}else{
		if (excMod==1){
			prototype->setJunkValue((int)(fJunkValue));
		}else{
			prototype->setJunkValue((int)(fJunkValue * (excMod/2)));
		}
	}

	// Use percentages to recalculate the values
	craftingValues.recalculateValues(false);

	craftingValues.addExperimentalProperty("creatureLevel", "creatureLevel", level, level, 0, false, CraftingManager::LINEARCOMBINE);
	craftingValues.setHidden("creatureLevel");

	//check weapons and weapon components for min damage > max damage
	if (prototype->isComponent() || prototype->isWeaponObject()) {
		if (craftingValues.hasProperty("mindamage") && craftingValues.hasProperty("maxdamage")) {
			float oldMin = craftingValues.getCurrentValue("mindamage");
			float oldMax = craftingValues.getCurrentValue("maxdamage");

			if (oldMin > oldMax) {
				craftingValues.setCurrentValue("mindamage", oldMax);
				craftingValues.setCurrentValue("maxdamage", oldMin);
			}
		}
	}

	// Add Dots to weapon objects.
	addStaticDots(prototype, templateObject, level);
	addRandomDots(prototype, templateObject, level, excMod);

	setSkillMods(prototype, templateObject, level, excMod);

	setSockets(prototype, &craftingValues);

	// Update the Tano with new values
	prototype->updateCraftingValues(&craftingValues, true);

	//add some condition damage where appropriate
	if (!maxCondition)
		addConditionDamage(prototype, &craftingValues);

	return prototype;
}