Beispiel #1
0
CreatureObject* ThreatMap::getHighestDamagePlayer() {
	Locker locker(&lockMutex);

	uint32 maxDamage = 0;
	VectorMap<uint64,uint32> damageMap;
	CreatureObject* player = NULL;

	for (int i = 0; i < size(); ++i) {
		ThreatMapEntry* entry = &elementAt(i).getValue();

		uint32 totalDamage = 0;

		for (int j = 0; j < entry->size(); ++j) {
			uint32 damage = entry->elementAt(j).getValue();

			totalDamage += damage;
		}

		CreatureObject* creature = elementAt(i).getKey();

		if (creature->isPlayerCreature()) {
			if(!damageMap.contains(creature->getObjectID())){
				damageMap.put(creature->getObjectID(),totalDamage);
			} else {
				damageMap.get(creature->getObjectID()) += totalDamage;
			}

			if (damageMap.get(creature->getObjectID()) > maxDamage) {
				maxDamage = damageMap.get(creature->getObjectID());
				player = cast<CreatureObject*>(creature);
			}
		} else if (creature->isPet()) {
			CreatureObject* owner = creature->getLinkedCreature().get();

			if (owner != NULL && owner->isPlayerCreature()) {
				if(!damageMap.contains(owner->getObjectID())){
					damageMap.put(owner->getObjectID(),totalDamage);
				} else {
					damageMap.get(owner->getObjectID()) += totalDamage;
				}

				if (damageMap.get(owner->getObjectID()) > maxDamage) {
					maxDamage = damageMap.get(owner->getObjectID());
					player = cast<CreatureObject*>(owner);
				}
			}
		}
	}

	return player;
}
int BountyMissionObjectiveImplementation::handleNpcTargetReceivesDamage(ManagedObject* arg1) {
	CreatureObject* target = NULL;

	target = cast<CreatureObject*>(arg1);

	ManagedReference<MissionObject* > mission = this->mission.get();
	ManagedReference<CreatureObject*> owner = getPlayerOwner();

	if (owner != NULL && target != NULL && target->getFirstName() == owner->getFirstName() &&
			target->isPlayerCreature() && objectiveStatus == HASBIOSIGNATURESTATUS) {
		updateMissionStatus(mission->getMissionLevel());

		String diffString = "easy";
		if (mission->getMissionLevel() == 3) {
			diffString = "hard";
		} else if (mission->getMissionLevel() == 2) {
			diffString = "medium";
		}

		target->getZoneServer()->getChatManager()->broadcastMessage(npcTarget, "@mission/mission_bounty_neutral_" + diffString + ":m" + String::valueOf(mission->getMissionNumber()) + "v", 0, 0, 0);
		return 1;
	}

	return 0;
}
void BountyMissionObjectiveImplementation::handleNpcTargetKilled(ManagedObject* arg1) {
	CreatureObject* attacker = NULL;

	attacker = cast<CreatureObject*>(arg1);

	ManagedReference<MissionObject* > mission = this->mission.get();
	ManagedReference<CreatureObject*> owner = getPlayerOwner();

	if (owner == NULL)
		return;

	if (attacker != NULL && attacker->getObjectID() == owner->getObjectID() && attacker->isPlayerCreature()) {
		//Target killed by player, complete mission.
		complete();
	} else if (attacker != NULL && attacker->isPet()) {
		// Target killed by pet
		ManagedReference<CreatureObject*> petOwner = attacker->getLinkedCreature().get();

		if (petOwner != NULL && petOwner->getObjectID() == owner->getObjectID()) {
			// Pet is owned by mission owner, complete mission.
			complete();
		}
	} else {
		//Target killed by other player, fail mission.
		owner->sendSystemMessage("@mission/mission_generic:failed"); // Mission failed
		abort();
		removeMissionFromPlayer();
	}
}
CreatureObject* CreatureManagerImplementation::spawnCreature(uint32 templateCRC, uint32 objectCRC, float x, float z, float y, uint64 parentID, bool persistent) {
	CreatureTemplate* creoTempl = creatureTemplateManager->getTemplate(templateCRC);

	if (creoTempl == NULL)
		return spawnCreature(objectCRC, x, z, y, parentID);

	CreatureObject* creature = NULL;

	String templateToSpawn;

	if (objectCRC == 0) {
		templateToSpawn = getTemplateToSpawn(templateCRC);
		objectCRC = templateToSpawn.hashCode();
	}

	creature = createCreature(objectCRC, persistent, templateCRC);

	if (creature != NULL && creature->isAiAgent()) {
		AiAgent* npc = cast<AiAgent*>(creature);
		npc->loadTemplateData(creoTempl);
	} else if (creature == NULL) {
		error("could not spawn template " + templateToSpawn);
	}

	placeCreature(creature, x, z, y, parentID);

	// ensuring the combat level and max HAM is correct.
	if( creature->isPlayerCreature() )
		creature->getPlayerObject()->recalculateCombatLevel(creature);
	return creature;
}
void GroupObjectImplementation::broadcastMessage(BaseMessage* msg) {
	for (int i = 0; i < groupMembers.size(); i++) {
		CreatureObject* member = groupMembers.get(i).get().get();

		if (member->isPlayerCreature())
			member->sendMessage(msg->clone());
	}

	delete msg;
}
void GroupObjectImplementation::removeGroupModifiers() {
	for (int i = 0; i < groupMembers.size(); i++) {
		CreatureObject* player = getGroupMember(i);

		if (!player->isPlayerCreature())
			continue;

		removeGroupModifiers(player);
	}
}
void GroupObjectImplementation::sendSystemMessage(StringIdChatParameter& param, CreatureObject* excluded) {
	Locker lock(_this.getReferenceUnsafeStaticCast());

	for (int i = 0; i < groupMembers.size(); ++i) {
		CreatureObject* member = groupMembers.get(i).get().get();

		if (!member->isPlayerCreature() || member == excluded)
			continue;

		member->sendSystemMessage(param);
	}
}
void GroupObjectImplementation::sendSystemMessage(const String& fullPath, bool sendLeader) {
	Locker lock(_this.getReferenceUnsafeStaticCast());

	for (int i = 0; i < groupMembers.size(); ++i) {
		CreatureObject* member = groupMembers.get(i).get().get();

		if (!member->isPlayerCreature() || (!sendLeader && member == getLeader()))
			continue;

		member->sendSystemMessage(fullPath);
	}
}
void GroupObjectImplementation::broadcastMessage(CreatureObject* player, BaseMessage* msg, bool sendSelf) {
	for (int i = 0; i < groupMembers.size(); i++) {
		CreatureObject* member = groupMembers.get(i).get().get();

		if(!sendSelf && member == player)
			continue;

		if (member->isPlayerCreature())
			member->sendMessage(msg->clone());
	}

	delete msg;
}
void GroupObjectImplementation::removeGroupModifiers() {
	for (int i = 0; i < groupMembers.size(); i++) {
		CreatureObject* crea = getGroupMember(i).castTo<CreatureObject*>().get();

		if (crea == NULL)
			continue;

		if (!crea->isPlayerCreature())
			continue;

		ManagedReference<CreatureObject*> player = cast<CreatureObject*>( crea);
		removeGroupModifiers(player);
	}
}
void GroupObjectImplementation::addGroupModifiers() {
	ManagedReference<GroupObject*> thisGroup = _this.getReferenceUnsafeStaticCast();

	Locker glocker(thisGroup);

	for (int i = 0; i < groupMembers.size(); i++) {
		CreatureObject* player = getGroupMember(i);

		if (!player->isPlayerCreature())
			continue;

		Locker clocker(player, thisGroup);

		addGroupModifiers(player);
	}
}
void GroupObjectImplementation::updatePvPStatusNearCreature(CreatureObject* creature) {
	CloseObjectsVector* creatureCloseObjects = (CloseObjectsVector*) creature->getCloseObjects();
	SortedVector<QuadTreeEntry*> closeObjectsVector;

	creatureCloseObjects->safeCopyReceiversTo(closeObjectsVector, CloseObjectsVector::CREOTYPE);

	for (int i = 0; i < groupMembers.size(); i++) {
		CreatureObject* member = groupMembers.get(i).get().get();

		if (closeObjectsVector.contains(member)) {

			if (creature->isPlayerCreature())
				member->sendPvpStatusTo(creature);

			if (member->isPlayerCreature())
				creature->sendPvpStatusTo(member);
		}
	}
}
void GroupObjectImplementation::addGroupModifiers() {
	ManagedReference<GroupObject*> thisGroup = _this.get();

	Locker glocker(thisGroup);

	for (int i = 0; i < groupMembers.size(); i++) {
		CreatureObject* crea = getGroupMember(i).castTo<CreatureObject*>().get();

		if (crea == NULL)
			continue;

		if (!crea->isPlayerCreature())
			continue;

		ManagedReference<CreatureObject*> player = cast<CreatureObject*>( crea);

		Locker clocker(player, thisGroup);

		addGroupModifiers(player);
	}
}
Beispiel #14
0
CreatureObject* ThreatMap::getHighestDamageGroupLeader() {

	Locker locker(&lockMutex);

	VectorMap<uint64,uint32> groupDamageMap;
	int64 highestGroupDmg = 0;

	//Logger::Logger tlog("Threat");

	ManagedReference<CreatureObject*> leaderCreature = NULL;

	for (int i = 0; i < size(); ++i) {
		ThreatMapEntry* entry = &elementAt(i).getValue();

		uint32 totalDamage = entry->getTotalDamage();

		CreatureObject* creature = elementAt(i).getKey();
		//tlog.info("Group id is " + String::valueOf(creature->getGroupID()),true);
		if (creature->isGrouped()) {

			Reference<CreatureObject*> thisleader = creature->getGroup()->getLeader();
			//tlog.info("leader is " + thisleader->getFirstName(),true);

			if (thisleader == NULL || !thisleader->isPlayerCreature())
				break;

			if (!groupDamageMap.contains(creature->getGroupID())) {
				//tlog.info("first dmg for group " + String::valueOf(creature->getGroupID()) + " dmg: " + String::valueOf(totalDamage), true);
				groupDamageMap.put(creature->getGroupID(),totalDamage);

			} else {
				groupDamageMap.get(creature->getGroupID()) += totalDamage;
				//tlog.info("adding to group " + String::valueOf(creature->getGroupID()) + "  dmg total: " + String::valueOf(groupDamageMap.get(creature->getGroupID())) + " this player dmg: " + String::valueOf(totalDamage),true);
			}

			if (groupDamageMap.get(creature->getGroupID()) > highestGroupDmg) {
				highestGroupDmg = groupDamageMap.get(creature->getGroupID());
				leaderCreature = thisleader;
			}
		} else if (creature->isPet()) {
			CreatureObject* owner = creature->getLinkedCreature().get();

			if (owner != NULL && owner->isPlayerCreature()) {
				if (owner->isGrouped()) {
					Reference<CreatureObject*> thisleader = owner->getGroup()->getLeader();

					if (thisleader == NULL || !thisleader->isPlayerCreature())
						break;

					if (!groupDamageMap.contains(owner->getGroupID())) {
						groupDamageMap.put(owner->getGroupID(),totalDamage);
					} else {
						groupDamageMap.get(owner->getGroupID()) += totalDamage;
					}

					if (groupDamageMap.get(owner->getGroupID()) > highestGroupDmg) {
						highestGroupDmg = groupDamageMap.get(owner->getGroupID());
						leaderCreature = thisleader;
					}
				} else {
					if (!groupDamageMap.contains(owner->getObjectID())) {
						groupDamageMap.put(owner->getObjectID(),totalDamage);
					} else {
						groupDamageMap.get(owner->getObjectID()) += totalDamage;
					}

					if (totalDamage > highestGroupDmg) {
						highestGroupDmg = totalDamage;
						leaderCreature = owner;
					}
				}
			}
		} else {
			//tlog.info("adding single creature damage " + String::valueOf(totalDamage),true);
			groupDamageMap.put(creature->getObjectID(),totalDamage);

			if (totalDamage > highestGroupDmg) {
				highestGroupDmg = totalDamage;
				leaderCreature = creature;
			}

		}
	}
	//tlog.info("highest group is " + leaderCreature->getFirstName() + " damage of " + String::valueOf(highestGroupDmg),true);
	return leaderCreature;
}
int PlayerContainerComponent::canAddObject(SceneObject* sceneObject, SceneObject* object, int containmentType, String& errorDescription) {
	CreatureObject* creo = dynamic_cast<CreatureObject*>(sceneObject);

	if (object->isTangibleObject() && containmentType == 4) {
		TangibleObject* wearable = cast<TangibleObject*>( object);

		SharedTangibleObjectTemplate* tanoData = dynamic_cast<SharedTangibleObjectTemplate*>(wearable->getObjectTemplate());
		Vector<uint32>* races = tanoData->getPlayerRaces();
		String race = creo->getObjectTemplate()->getFullTemplateString();

		if (!races->contains(race.hashCode())) {
			errorDescription = "You lack the necessary requirements to wear this object";

			return TransferErrorCode::PLAYERUSEMASKERROR;
		}

		if (creo->isPlayerCreature()) {
			if (!wearable->isNeutral()) {
				ManagedReference<PlayerObject*> playerObject = creo->getPlayerObject();

				if (wearable->isImperial() && (playerObject->getFactionStatus() == FactionStatus::ONLEAVE || !creo->isImperial())) {
					errorDescription = "You lack the necessary requirements to wear this object";

					return TransferErrorCode::PLAYERUSEMASKERROR;
				}

				if (wearable->isRebel() && (playerObject->getFactionStatus() == FactionStatus::ONLEAVE || !creo->isRebel())) {
					errorDescription = "You lack the necessary requirements to wear this object";

					return TransferErrorCode::PLAYERUSEMASKERROR;
				}
			}
		}
	}

	if (object->isArmorObject() && containmentType == 4) {
		PlayerManager* playerManager = sceneObject->getZoneServer()->getPlayerManager();

		if (!playerManager->checkEncumbrancies(dynamic_cast<CreatureObject*>(sceneObject), cast<ArmorObject*>( object))) {
			errorDescription = "You lack the necessary secondary stats to equip this item";

			return TransferErrorCode::NOTENOUGHENCUMBRANCE;
		}
	}

	if (object->isRobeObject() && containmentType == 4) {
		ManagedReference<RobeObject*> robe = cast<RobeObject*>( object);
		String skillRequired = robe->getSkillRequired();

		if (!creo->hasSkill(skillRequired) && skillRequired != ""){
			errorDescription = "You are not eligible to wear this robe.";

			return TransferErrorCode::PLAYERUSEMASKERROR;
		}


	}

	if (object->isWeaponObject() && containmentType == 4) {
		ManagedReference<WeaponObject*> weapon = cast<WeaponObject*>( object);
		int bladeColor = weapon->getBladeColor();

		if (weapon->isJediWeapon()){
			if (bladeColor == 31) {
				errorDescription = "@jedi_spam:lightsaber_no_color";
				return TransferErrorCode::PLAYERUSEMASKERROR;
			}
			if (weapon->getCraftersName() != creo->getFirstName()) {
				errorDescription = "@jedi_spam:not_your_lightsaber";
				return TransferErrorCode::PLAYERUSEMASKERROR;
			}
		}
	}

	return ContainerComponent::canAddObject(sceneObject, object, containmentType, errorDescription);
}
int PlayerContainerComponent::canAddObject(SceneObject* sceneObject, SceneObject* object, int containmentType, String& errorDescription) {
	CreatureObject* creo = dynamic_cast<CreatureObject*>(sceneObject);

	if (object->isTangibleObject() && containmentType == 4) {
		TangibleObject* wearable = cast<TangibleObject*>( object);

		SharedTangibleObjectTemplate* tanoData = dynamic_cast<SharedTangibleObjectTemplate*>(wearable->getObjectTemplate());
		Vector<uint32>* races = tanoData->getPlayerRaces();
		String race = creo->getObjectTemplate()->getFullTemplateString();

		if (!races->contains(race.hashCode())) {
			errorDescription = "You lack the necessary requirements to wear this object";

			return TransferErrorCode::PLAYERUSEMASKERROR;
		}

		if (creo->isPlayerCreature()) {
			if (!wearable->isNeutral()) {
				ManagedReference<PlayerObject*> playerObject = creo->getPlayerObject();

				if (wearable->isImperial() && (playerObject->getFactionStatus() == FactionStatus::ONLEAVE || !creo->isImperial())) {
					errorDescription = "You lack the necessary requirements to wear this object";

					return TransferErrorCode::PLAYERUSEMASKERROR;
				}

				if (wearable->isRebel() && (playerObject->getFactionStatus() == FactionStatus::ONLEAVE || !creo->isRebel())) {
					errorDescription = "You lack the necessary requirements to wear this object";

					return TransferErrorCode::PLAYERUSEMASKERROR;
				}
			}
		}
	}

	if (object->isArmorObject() && containmentType == 4) {
		PlayerManager* playerManager = sceneObject->getZoneServer()->getPlayerManager();

		if (!playerManager->checkEncumbrancies(dynamic_cast<CreatureObject*>(sceneObject), cast<ArmorObject*>( object))) {
			errorDescription = "You lack the necessary secondary stats to equip this item";

			return TransferErrorCode::NOTENOUGHENCUMBRANCE;
		}
	}

	if (object->isWearableObject() && containmentType == 4) {
		ManagedReference<WearableObject*> wearable = cast<WearableObject*>( object);
		SharedTangibleObjectTemplate* wearableData = dynamic_cast<SharedTangibleObjectTemplate*>(wearable->getObjectTemplate());

		Vector<String> skillsRequired = wearableData->getCertificationsRequired();

		if (skillsRequired.size() > 0) {
			bool hasSkill = false;
			for (int i = 0; i < skillsRequired.size(); i++) {
				String skill = skillsRequired.get(i);
				if (!skill.isEmpty() && creo->hasSkill(skill)) {
					hasSkill = true;
					break;
				}
			}

			if (!hasSkill) {
				errorDescription = "@error_message:insufficient_skill"; // You lack the skill to use this item.

				return TransferErrorCode::PLAYERUSEMASKERROR;
			}
		}
	}

	if (object->isWeaponObject() && containmentType == 4) {
		ManagedReference<WeaponObject*> weapon = cast<WeaponObject*>( object);
		int bladeColor = weapon->getBladeColor();

		if (weapon->isJediWeapon()){
			if (bladeColor == 31) {
				errorDescription = "@jedi_spam:lightsaber_no_color";
				return TransferErrorCode::PLAYERUSEMASKERROR;
			}
			if (weapon->getCraftersName() != creo->getFirstName()) {
				errorDescription = "@jedi_spam:not_your_lightsaber";
				return TransferErrorCode::PLAYERUSEMASKERROR;
			}
		}
	}

	return ContainerComponent::canAddObject(sceneObject, object, containmentType, errorDescription);
}