void LootManagerImplementation::addStaticDots(TangibleObject* object, LootItemTemplate* templateObject, int level) {

	if (object == NULL)
		return;

	if (!object->isWeaponObject())
		return;

	ManagedReference<WeaponObject*> weapon = cast<WeaponObject*>(object);

	bool shouldGenerateDots = false;

	float dotChance = templateObject->getStaticDotChance();

	if (dotChance < 0)
		return;

	// Apply the Dot if the chance roll equals the number or is zero.
	if (dotChance == 0 || System::random(dotChance) == 0) { // Defined in loot item script.
		shouldGenerateDots = true;
	}

	if (shouldGenerateDots) {

		int dotType = templateObject->getStaticDotType();

		if (dotType < 1 || dotType > 4)
			return;

		VectorMap<String, SortedVector<int> >* dotValues = templateObject->getStaticDotValues();
		int size = dotValues->size();

		// Check if they specified correct vals.
		if (size > 0) {
			weapon->addDotType(dotType);

			for (int i = 0; i < size; i++) {

				String property = dotValues->elementAt(i).getKey();
				SortedVector<int> theseValues = dotValues->elementAt(i).getValue();
				int min = theseValues.elementAt(0);
				int max = theseValues.elementAt(1);
				float value = 0;

				if (max != min) {
					value = calculateDotValue(min, max, level);
				}
				else { value = max; }

				if(property == "attribute") {
					if (min != max)
						value = System::random(max - min) + min;

					if (dotType != 2 && (value != 0 && value != 3 && value != 6)) {
						int numbers[] = { 0, 3, 6 }; // The main pool attributes.
						int choose = System::random(2);
						value = numbers[choose];
					}

					weapon->addDotAttribute(value);
				} else if (property == "strength") {
					weapon->addDotStrength(value);
				} else if (property == "duration") {
					weapon->addDotDuration(value);
				} else if (property == "potency") {
					weapon->addDotPotency(value);
				} else if (property == "uses") {
					weapon->addDotUses(value);
				}
			}
		}
	}
}
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;
}
Exemple #3
0
int main()
{
  Vector<int> v;

  v.addElement(4);
  v.addElement(5);
  v.addElement(6);

  assert(v.elementAt(0) == 4);
  assert(v.elementAt(2) == 6);

  v.removeElement(5);

  assert(v.elementAt(1) == 6);

  v.insertElementAt(100, 2);

  assert(v.elementAt(2) == 100);

  printf("passed: Vector\n");

  
  
  SortedVector<int> sv;

  sv.addElement(7);
  assert(sv.elementAt(0) == 7);

  sv.addElement(6);
  assert(sv.elementAt(0) == 6);
  assert(sv.elementAt(1) == 7);

  sv.addElement(9);
  assert(sv.elementAt(2) == 9);

  sv.addElement(3);
  assert(sv.elementAt(0) == 3);
  assert(sv.elementAt(3) == 9);

  sv.addElement(1);

  sv.removeElement(6);

  assert(sv.size() == 4);
  assert(sv.elementAt(3) == 9);
  assert(sv.indexOf(9) == 3);
  assert(sv.indexOf(1) == 0);

  int numbers = 100;
  while(numbers--){
    sv.addElement(numbers%2 ? -numbers : numbers);
  }

  int maxel = -1000000;
  for (int idx = 0; idx < sv.size(); idx++) {
    //printf("%d, ", sv.elementAt(idx));
    if (sv.elementAt(idx) < maxel) assert(!"sv order failed");
    maxel = sv.elementAt(idx);
  }

  assert(sv.indexOf(10000) == -1);
  assert(sv.indexOf(-10000) == -1);
  
  sv.clear();

  assert(sv.size() == 0);

  sv.addElement(0);
  sv.addElement(2);
  sv.addElement(2);
  sv.addElement(2);

  assert(sv.size() == 4);
  // undefined assert(sv.indexOf(2) == 1);

  assert(sv.elementAt(0) == 0);
  assert(sv.elementAt(3) == 2);


  printf("passed: SortedVector\n");

}