void BountyMissionObjectiveImplementation::handlePlayerKilled(ManagedObject* arg1) {
	CreatureObject* killer = NULL;

	killer = cast<CreatureObject*>(arg1);

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

	if (owner != NULL && killer != NULL) {
		if (owner->getObjectID() == killer->getObjectID()) {
			//Target killed by player, complete mission.
			ZoneServer* zoneServer = owner->getZoneServer();
			if (zoneServer != NULL) {
				ManagedReference<CreatureObject*> target = zoneServer->getObject(mission->getTargetObjectId()).castTo<CreatureObject*>();
				if (target != NULL) {
					VisibilityManager::instance()->clearVisibility(target);
					owner->getZoneServer()->getPlayerManager()->awardExperience(target, "jedi_general", -30000, true);

				}
			}

			complete();
		} else if (mission->getTargetObjectId() == killer->getObjectID() ||
				(npcTarget != NULL && npcTarget->getObjectID() == killer->getObjectID())) {
			//Player killed by target, fail mission.
			owner->sendSystemMessage("@mission/mission_generic:failed"); // Mission failed
			killer->sendSystemMessage("You have defeated a bounty hunter, ruining his mission against you!");
			fail();
		}
	}
}
Ejemplo n.º 2
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;
}
void BountyMissionObjectiveImplementation::handleDefenderDropped(ManagedObject* arg1) {
	CreatureObject* defender = NULL;

	defender = cast<CreatureObject*>(arg1);

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

	if (owner != NULL && defender != NULL) {
		if (owner->getObjectID() == defender->getObjectID() ||
				mission->getTargetObjectId() == defender->getObjectID()) {
			removeFromBountyLock(false);
		}
	}
}
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();
	}
}
void BountyMissionObjectiveImplementation::handlePlayerKilled(ManagedObject* arg1) {
	CreatureObject* killer = NULL;

	killer = cast<CreatureObject*>(arg1);

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

	if(mission == NULL)
		return;

	if (owner != NULL && killer != NULL) {
		if (owner->getObjectID() == killer->getObjectID()) {
			//Target killed by player, complete mission.
			ZoneServer* zoneServer = owner->getZoneServer();
			if (zoneServer != NULL) {
				ManagedReference<CreatureObject*> target = zoneServer->getObject(mission->getTargetObjectId()).castTo<CreatureObject*>();
				if (target != NULL) {
					int minXpLoss = -50000;
					int maxXpLoss = -500000;

					VisibilityManager::instance()->clearVisibility(target);
					int xpLoss = mission->getRewardCredits() * -2;

					if (xpLoss > minXpLoss)
						xpLoss = minXpLoss;
					else if (xpLoss < maxXpLoss)
						xpLoss = maxXpLoss;

					owner->getZoneServer()->getPlayerManager()->awardExperience(target, "jedi_general", xpLoss, true);
					StringIdChatParameter message("base_player","prose_revoke_xp");
					message.setDI(xpLoss * -1);
					message.setTO("exp_n", "jedi_general");
					target->sendSystemMessage(message);
				}
			}

			complete();
		} else if (mission->getTargetObjectId() == killer->getObjectID() ||
				(npcTarget != NULL && npcTarget->getObjectID() == killer->getObjectID())) {
			//Player killed by target, fail mission.
			owner->sendSystemMessage("@mission/mission_generic:failed"); // Mission failed
			killer->sendSystemMessage("You have defeated a bounty hunter, ruining his mission against you!");
			fail();
		}
	}
}
bool GroupObjectImplementation::hasMember(uint64 member) {
	for (int i = 0; i < groupMembers.size(); i++) {
		CreatureObject* play = groupMembers.get(i).get().get();

		if (play->getObjectID() == member)
			return true;
	}

	return false;
}
void GroupObjectImplementation::removeMember(SceneObject* member) {
	ManagedReference<SceneObject*> obj = member;

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

		if (scno == member) {
			GroupObjectDeltaMessage6* grp = new GroupObjectDeltaMessage6(_this.getReferenceUnsafeStaticCast());
			grp->startUpdate(1);
			groupMembers.remove(i, grp);
			grp->close();

			broadcastMessage(grp);
		}
	}

	if (member->isPlayerCreature()) {
		// Remove member's pets
		CreatureObject* playerCreature = cast<CreatureObject*>(member);
		RemovePetsFromGroupTask* task = new RemovePetsFromGroupTask(playerCreature, _this.getReferenceUnsafeStaticCast());
		task->execute();

		//Close any open Group SUIs.
		ManagedReference<PlayerObject*> ghost = playerCreature->getPlayerObject();
		if (ghost != NULL) {
			ghost->closeSuiWindowType(SuiWindowType::GROUP_LOOT_RULE);
			ghost->closeSuiWindowType(SuiWindowType::GROUP_LOOT_CHANGED);
			ghost->closeSuiWindowType(SuiWindowType::GROUP_LOOT_PICK_LOOTER);
		}

		//Reset Master Looter if needed.
		if (getMasterLooterID() == playerCreature->getObjectID()) {
			ManagedReference<CreatureObject*> groupLeader = (getLeader()).castTo<CreatureObject*>();
			GroupManager::instance()->changeMasterLooter(_this.getReferenceUnsafeStaticCast(), groupLeader, false);
		}

		if (hasSquadLeader()) {
			removeGroupModifiers(playerCreature);
		}

		if (playerCreature->getPlayerObject() != NULL) {
			PlayerObject* ghost = playerCreature->getPlayerObject();
			ghost->removeWaypointBySpecialType(WaypointObject::SPECIALTYPE_NEARESTMISSIONFORGROUP);
		}

		Zone* zone = playerCreature->getZone();

		if (zone != NULL) {
			scheduleUpdateNearestMissionForGroup(zone->getPlanetCRC());
		}
	}

	calcGroupLevel();
}
Ejemplo n.º 8
0
int LuaCreatureObject::setLootRights(lua_State* L) {
    CreatureObject* player = (CreatureObject*) lua_touserdata(L, -1);

    if (realObject == NULL)
        return 0;

    uint64 ownerID = 0;

    if (player != NULL) {
        ownerID = player->getObjectID();
    }

    SceneObject* inventory = realObject->getSlottedObject("inventory");

    if (inventory == NULL)
        return 0;

    Locker locker(inventory);

    inventory->setContainerOwnerID(ownerID);
    return 1;
}
Ejemplo n.º 9
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;
}
void ChatManagerImplementation::broadcastMessage(CreatureObject* player, const UnicodeString& message,  uint64 target, uint32 moodid, uint32 mood2) {
	Zone* zone = player->getZone();
	PlayerObject* myGhost = NULL;
	bool godMode = false;

	if (zone == NULL)
		return;

	int language = 0;
	String firstName;

	if (player->isPlayerCreature() /*|| !((Player *)player)->isChatMuted() */) {
		CreatureObject* playerCreature = cast<CreatureObject*>(player);
		if (playerCreature)
		{
			firstName = playerCreature->getFirstName().toLowerCase();
			myGhost = playerCreature->getPlayerObject();
		}

		if (myGhost)
			language = myGhost->getLanguageID();
	}

	if (myGhost)
	{
		if (myGhost->hasGodMode())
			godMode = true;
	}

	StringIdChatParameter* param = NULL;

	if (message[0] == '@' && message.indexOf(":") != -1) {
		param = new StringIdChatParameter(message.toString());
	}

	CloseObjectsVector* closeObjects = (CloseObjectsVector*) player->getCloseObjects();

	SortedVector<QuadTreeEntry*> closeEntryObjects(200, 50);

	if (closeObjects != NULL) {
		closeObjects->safeCopyTo(closeEntryObjects);
	} else {
		player->info("Null closeobjects vector in ChatManager::broadcastMessage", true);
		zone->getInRangeObjects(player->getWorldPositionX(), player->getWorldPositionY(), 128, &closeEntryObjects, true);
	}

	float range = defaultSpatialChatDistance;

	float specialRange = spatialChatDistances.get(mood2);
	if (specialRange != -1) {
		range = specialRange;
	}

	try {
		for (int i = 0; i < closeEntryObjects.size(); ++i) {
			SceneObject* object = cast<SceneObject*>(closeEntryObjects.get(i));

			if (player->isInRange(object, range)) {

				//Notify observers that are expecting spatial chat.
				if (object->getObserverCount(ObserverEventType::SPATIALCHATRECEIVED)) {
					ManagedReference<ChatMessage*> chatMessage = new ChatMessage();
					chatMessage->setString(message.toString());

					EXECUTE_TASK_3(object, chatMessage, player, {
						if (player_p == NULL || object_p == NULL)
							return;

						Locker locker(object_p);

						SortedVector<ManagedReference<Observer*> > observers = object_p->getObservers(ObserverEventType::SPATIALCHATRECEIVED);
						for (int oc = 0; oc < observers.size(); oc++) {
							Observer* observer = observers.get(oc);
							Locker clocker(observer, object_p);
							if (observer->notifyObserverEvent(ObserverEventType::SPATIALCHATRECEIVED, object_p, chatMessage_p, player_p->getObjectID()) == 1)
								object_p->dropObserver(ObserverEventType::SPATIALCHATRECEIVED, observer);
						}
					});
				}

				if (object->isPlayerCreature()) {
					CreatureObject* creature = cast<CreatureObject*>(object);
					PlayerObject* ghost = creature->getPlayerObject();

					if (ghost == NULL)
						continue;

					if (!ghost->isIgnoring(firstName) || godMode) {
						SpatialChat* cmsg = NULL;

						if (param == NULL) {
							cmsg = new SpatialChat(player->getObjectID(), creature->getObjectID(), message, target, moodid, mood2, language);
						} else {
							cmsg = new SpatialChat(player->getObjectID(), creature->getObjectID(), *param, target, moodid, mood2);
						}

						creature->sendMessage(cmsg);
					}
				}
				else if( object->isPet() ){
					AiAgent* pet = cast<AiAgent*>(object);

					if (pet == NULL )
						continue;

					if( pet->isDead() || pet->isIncapacitated() )
						continue;

					PetManager* petManager = server->getPetManager();
					Locker clocker(pet, player);
					petManager->handleChat( player, pet, message.toString() );

				}
			}
		}
void ImageDesignSessionImplementation::updateImageDesign(CreatureObject* updater, uint64 designer, uint64 targetPlayer, uint64 tent, int type, const ImageDesignData& data) {
	ManagedReference<CreatureObject*> strongReferenceTarget = targetCreature.get();
	ManagedReference<CreatureObject*> strongReferenceDesigner = designerCreature.get();

	if (strongReferenceTarget == NULL || strongReferenceDesigner == NULL)
		return;

	Locker locker(strongReferenceDesigner);
	Locker clocker(strongReferenceTarget, strongReferenceDesigner);

	imageDesignData = data;

	CreatureObject* targetObject = NULL;

	if (updater == strongReferenceDesigner)
		targetObject = strongReferenceTarget;
	else
		targetObject = strongReferenceDesigner;

	//ManagedReference<SceneObject*> obj = targetObject->getParentRecursively(SceneObjectType::SALONBUILDING);
	//tent = obj != NULL ? obj->getObjectID()

	ImageDesignChangeMessage* message = new ImageDesignChangeMessage(targetObject->getObjectID(), designer, targetPlayer, tent, type);

	imageDesignData.insertToMessage(message);

	bool commitChanges = false;

	if (imageDesignData.isAcceptedByDesigner()) {
		commitChanges = true;

		if (strongReferenceDesigner != strongReferenceTarget && !imageDesignData.isAcceptedByTarget()) {
			commitChanges = false;

			if (idTimeoutEvent == NULL)
				idTimeoutEvent = new ImageDesignTimeoutEvent(_this.get());

			if (!idTimeoutEvent->isScheduled())
				idTimeoutEvent->schedule(120000); //2 minutes
		} else {
			commitChanges = doPayment();
		}
	}

	//System::out << h << endl;
	if (commitChanges) {
		//TODO: set XP Values

		int xpGranted = 0; // Minimum Image Design XP granted (base amount).

		//if (imageDesignData.mi)

		String hairTemplate = imageDesignData.getHairTemplate();

		bool statMig = imageDesignData.isStatMigrationRequested();

		if (statMig && strongReferenceDesigner->getParentRecursively(SceneObjectType::SALONBUILDING).get().get()
				&& strongReferenceDesigner->getParentRecursively(SceneObjectType::SALONBUILDING).get().get() && strongReferenceDesigner != strongReferenceTarget) {

			ManagedReference<Facade*> facade = strongReferenceTarget->getActiveSession(SessionFacadeType::MIGRATESTATS);
			ManagedReference<MigrateStatsSession*> session = dynamic_cast<MigrateStatsSession*>(facade.get());

			if (session != NULL) {
				session->migrateStats();
				xpGranted = 2000;
			}
		}

		VectorMap<String, float>* bodyAttributes = imageDesignData.getBodyAttributesMap();
		VectorMap<String, uint32>* colorAttributes = imageDesignData.getColorAttributesMap();

		ImageDesignManager* imageDesignManager = ImageDesignManager::instance();

		hairObject = strongReferenceTarget->getSlottedObject("hair").castTo<TangibleObject*>();

		if (type == 1) {
			String oldCustomization;

			if (hairObject != NULL)
				hairObject->getCustomizationString(oldCustomization);

			hairObject = imageDesignManager->createHairObject(strongReferenceDesigner, strongReferenceTarget, imageDesignData.getHairTemplate(), imageDesignData.getHairCustomizationString());

			if (hairObject != NULL)
				hairObject->setCustomizationString(oldCustomization);

			if (xpGranted < 100)
				xpGranted = 100;
		}

		if (bodyAttributes->size() > 0) {
			if (xpGranted < 300)
				xpGranted = 300;
			for (int i = 0; i < bodyAttributes->size(); ++i) {
				VectorMapEntry<String, float>* entry = &bodyAttributes->elementAt(i);
				imageDesignManager->updateCustomization(strongReferenceDesigner, entry->getKey(), entry->getValue(), strongReferenceTarget);
			}
		}


		if (colorAttributes->size() > 0) {
			if(xpGranted < 100)
				xpGranted = 100;
			for (int i = 0; i < colorAttributes->size(); ++i) {
				VectorMapEntry<String, uint32>* entry = &colorAttributes->elementAt(i);
				imageDesignManager->updateColorCustomization(strongReferenceDesigner, entry->getKey(), entry->getValue(), hairObject, strongReferenceTarget);
			}
		}

		imageDesignManager->updateHairObject(strongReferenceTarget, hairObject);

		// Add holo emote
		String holoemote = imageDesignData.getHoloEmote();
		if( !holoemote.isEmpty() ){

			PlayerObject* ghost = strongReferenceTarget->getPlayerObject();
			ghost->setInstalledHoloEmote( holoemote );  // Also resets number of uses available

			strongReferenceTarget->sendSystemMessage("@image_designer:new_holoemote"); //"Congratulations! You have purchased a new Holo-Emote generator. Type '/holoemote help' for instructions."

			if(xpGranted < 100)
				xpGranted = 100;

		}

		// Drop the Session for both the designer and the targetCreature;
		strongReferenceDesigner->dropActiveSession(SessionFacadeType::IMAGEDESIGN);
		strongReferenceTarget->dropActiveSession(SessionFacadeType::IMAGEDESIGN);

		// Award XP.
		PlayerManager* playerManager = strongReferenceDesigner->getZoneServer()->getPlayerManager();

		if (playerManager != NULL && xpGranted > 0) {
			if(strongReferenceDesigner == strongReferenceTarget)
				xpGranted /= 2;
			playerManager->awardExperience(strongReferenceDesigner, "imagedesigner", xpGranted, true);
		}

		if (idTimeoutEvent != NULL && idTimeoutEvent->isScheduled())
			dequeueIdTimeoutEvent();
	}

	targetObject->sendMessage(message);
}