Esempio n. 1
0
/*static*/
void CGameBrowser::UnpackRecievedInGamePresenceString(CryFixedStringT<MAX_PRESENCE_STRING_SIZE> &out, const CryFixedStringT<MAX_PRESENCE_STRING_SIZE>& inString)
{
#if USE_CRYLOBBY_GAMESPY

	const int firstIntStart = inString.find(':');
	const int lastIntStart = inString.rfind(':');

	CryFixedStringT<MAX_PRESENCE_STRING_SIZE> stringId( inString.substr(0, firstIntStart) );
	CryFixedStringT<MAX_PRESENCE_STRING_SIZE> sGameModeId(inString.substr(firstIntStart+1, lastIntStart));
	CryFixedStringT<MAX_PRESENCE_STRING_SIZE> sMapId(inString.substr(lastIntStart+1, inString.length()));

	const uint32 gameModeId = atoi(sGameModeId.c_str());
	const uint32 mapId = atoi(sMapId.c_str());

	const char* gamemodeStringId = GetGameModeStringFromId(gameModeId);
	const char* mapIDString = GetMapStringFromId(mapId);
	ILocalizationManager* pLocMgr = gEnv->pSystem->GetLocalizationManager();
	wstring translated;
	pLocMgr->LocalizeString( mapIDString, translated );
	const bool haveMapString = (translated.length()) && (translated[0] != '@');
	if(haveMapString)
	{
		out = inString;//CHUDUtils::LocalizeString(stringId.c_str(), gamemodeStringId, mapIDString);
	}
	else
	{
		out = inString;//CHUDUtils::LocalizeString("@mp_rp_gameplay_unknownmap", gamemodeStringId);
	}

#else
	out = inString;
#endif
}
void MissionObjectiveImplementation::awardReward() {
	Vector<ManagedReference<CreatureObject*> > players;
	PlayMusicMessage* pmm = new PlayMusicMessage("sound/music_mission_complete.snd");

	Vector3 missionEndPoint = getEndPosition();

	ManagedReference<CreatureObject*> owner = getPlayerOwner();

	ManagedReference<GroupObject*> group = owner->getGroup();

	if (group != NULL) {
		Locker lockerGroup(group, _this.get());

		for(int i = 0; i < group->getGroupSize(); i++) {
			Reference<CreatureObject*> groupMember = group->getGroupMember(i)->isPlayerCreature() ? (group->getGroupMember(i)).castTo<CreatureObject*>() : NULL;

			if (groupMember != NULL) {
				//Play mission complete sound.
				groupMember->sendMessage(pmm->clone());

				if (groupMember->getWorldPosition().distanceTo(missionEndPoint) < 128) {
					players.add(groupMember);
				}
			}
		}

		delete pmm;
	} else {
		//Play mission complete sound.
		owner->sendMessage(pmm);
		players.add(owner);
	}

	if (players.size() == 0) {
		players.add(owner);
	}

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

	int dividedReward = mission->getRewardCredits() / players.size();

	for (int i = 0; i < players.size(); i++) {
		ManagedReference<CreatureObject*> player = players.get(i);
		StringIdChatParameter stringId("mission/mission_generic", "success_w_amount");
		stringId.setDI(dividedReward);
		player->sendSystemMessage(stringId);

		Locker lockerPl(player, _this.get());
		player->addBankCredits(dividedReward, true);
	}

	StatisticsManager::instance()->completeMission(mission->getTypeCRC() ,mission->getRewardCredits());
}
void LootManagerImplementation::setCustomObjectName(TangibleObject* object, LootItemTemplate* templateObject) {
	String customName = templateObject->getCustomObjectName();

	if (!customName.isEmpty()) {
		if (customName.charAt(0) == '@') {
			StringId stringId(customName);

			object->setObjectName(stringId);
		} else {
			object->setCustomObjectName(customName, false);
		}
	}
}
int SkillBuffObjectMenuComponent::handleObjectMenuSelect(SceneObject* sceneObject, CreatureObject* player, byte selectedID) {

	if (!sceneObject->isASubChildOf(player))
		return 0;

	if (selectedID != 20) {
		return TangibleObjectMenuComponent::handleObjectMenuSelect(sceneObject, player, selectedID);
	}

	if (player->isDead() || player->isIncapacitated())
		return 0;

	if(!sceneObject->isTangibleObject())
		return 0;

	ManagedReference<TangibleObject*> tano = cast<TangibleObject*>(sceneObject);

	ManagedReference<SkillBuffTemplate*> skillBuff = cast<SkillBuffTemplate*>(sceneObject->getObjectTemplate());
	if (skillBuff == NULL) {
		error("No SkillBuffTemplate for: " + String::valueOf(sceneObject->getServerObjectCRC()));
		return 1;
	}

	unsigned int buffCRC = skillBuff->getBuffCRC();
	int duration = skillBuff->getDuration();
	VectorMap<String, float>* modifiers = skillBuff->getModifiers();

	// Check if buff of same type is already active
	if ( player->hasBuff(buffCRC) ) {
		player->sendSystemMessage("@skill_buff_n:already_have"); //You already have that skill modifier active.
		return 0;
	}


	// Submit buff
	player->addBuff(buffCRC);

	// Send message to player
	StringIdChatParameter stringId("skill_buff_d", "consume"); // You feel enhanced!
	player->sendSystemMessage(stringId);

	//Consume a charge from the item, destroy it if it reaches 0 charges remaining.
	tano->decreaseUseCount();

	return TangibleObjectMenuComponent::handleObjectMenuSelect(sceneObject, player, selectedID);
}
int SurveyMissionObjectiveImplementation::notifyObserverEvent(MissionObserver* observer, uint32 eventType, Observable* observable, ManagedObject* arg1, int64 arg2) {
	if (eventType == ObserverEventType::SURVEY) {
		ManagedReference<CreatureObject*> player = getPlayerOwner();
		ManagedReference<MissionObject*> mission = this->mission.get();

		if (player == NULL || mission == NULL) {
			return 0;
		}

		ResourceSpawn* sampledSpawn = cast<ResourceSpawn*>( arg1);

		if (sampledSpawn == NULL) {
			return 0;
		}

		int sampledDensity = (int)arg2;
		if (sampledSpawn->getSurveyMissionSpawnFamilyName() == spawnFamily && (sampledDensity >= efficiency)) {
			Vector3 startPosition;
			startPosition.setX(mission->getStartPositionX());
			startPosition.setY(mission->getStartPositionY());
			float distance = startPosition.distanceTo(player->getWorldPosition());
			if (distance > 1024.0f) {
				complete();

				return 1;
			} else {
				StringIdChatParameter stringId("mission/mission_generic", "survey_too_close");
				stringId.setDI(1024);
				stringId.setDF(distance);
				player->sendSystemMessage(stringId);

				return 0;
			}
		} else {
			return 0;
		}
	}

	dropObserver(observer, true);

	updateToDatabase();

	return 1;
}
void InstallationObjectImplementation::setOperating(bool value, bool notifyClient) {
	//updateInstallationWork();

	if (operating == value)
		return;

	if (value) {

		if(currentSpawn == NULL)
			return;

		spawnDensity = currentSpawn->getDensityAt(getZone()->getZoneName(), getPositionX(), getPositionY());

		if(spawnDensity < .10) {
			return;
		}

		if (basePowerRate != 0 && surplusPower <= 0) {
			StringIdChatParameter stringId("player_structure", "power_deposit_incomplete");
			ChatSystemMessage* msg = new ChatSystemMessage(stringId);

			broadcastToOperators(msg);
			return;
		}

		if (getMaintenanceRate() != 0 && surplusMaintenance <= 0) {
			StringIdChatParameter stringId("shared", "harvester_no_maint_4");
			ChatSystemMessage* msg = new ChatSystemMessage(stringId);

			broadcastToOperators(msg);
			return;
		}
	}

	Time timeToWorkTill;

	operating = value;
	extractionRemainder = 0;

	if (operating) {
		setOptionBit(OptionBitmask::ACTIVATED, false);

		lastStartTime.updateToCurrentTime();
	} else {
		clearOptionBit(OptionBitmask::ACTIVATED, false);

		lastStopTime.updateToCurrentTime();
	}

	InstallationObjectDeltaMessage3* delta = new InstallationObjectDeltaMessage3(_this.get());
	delta->updateOperating(value);
	delta->updateOptionsBitmask();
	delta->close();

	InstallationObjectDeltaMessage7* delta7 = new InstallationObjectDeltaMessage7(_this.get());
	delta7->updateOperating(value);
	delta7->close();

	Vector<BasePacket*> messages;
	messages.add(delta);
	messages.add(delta7);

	broadcastMessages(&messages, true);

	if (value) {
		resourceHopperTimestamp.updateToCurrentTime();
	}

	InstallationObjectDeltaMessage7* inso7 = new InstallationObjectDeltaMessage7( _this.get());
	inso7->updateExtractionRate(getActualRate());
	inso7->close();

	broadcastToOperators(inso7);
}
int ConsumableImplementation::handleObjectMenuSelect(CreatureObject* player, byte selectedID) {
	if (!isASubChildOf(player))
		return 0;

	if (selectedID != 20) {
		return TangibleObjectImplementation::handleObjectMenuSelect(player, selectedID);
	}

	if (speciesRestriction == "pets") {
		player->sendSystemMessage("@error_message:pets_only"); //That food is only suitable for pets.
		return 0;
	}

	PlayerObject* ghost = player->getPlayerObject();

	String raceName = player->getSpeciesName();

	if ((speciesRestriction == "2" && raceName != "trandoshan") || (speciesRestriction == "4" && raceName != "wookiee")) {
		player->sendSystemMessage("@error_message:race_restriction"); //That food isn't edible by your species.
		return 0;
	}

	if (isSpice() && player->hasSpice()) {
		player->sendSystemMessage("@spice/spice:sys_already_spiced"); //You are already under the influence of spices.
		return 0;
	}

	if (player->hasBuff(buffCRC)  && (!isAttributeEffect() || isForagedFood())) {
		player->sendSystemMessage("@combat_effects:already_affected"); //You are already under the influence of that food. Eating more won't enhance the effect.
		return 0;
	}

	if (player->isDead() || player->isIncapacitated())
		return 0;

	int availfill = 0;

	if (ghost == NULL)
		return 1;

	if (isFood())
		availfill = ghost->getFoodFillingMax() - ghost->getFoodFilling();

	if (isDrink())
		availfill = ghost->getDrinkFillingMax() - ghost->getDrinkFilling();

	if (filling > availfill) {
		if (isFood())
			player->sendSystemMessage("@error_message:full_food"); //You are too full to eat that.

		if (isDrink())
			player->sendSystemMessage("@error_message:full_drink"); //You are too full to drink that.

		return 1;
	}


	ManagedReference<Buff*> buff = NULL;

	switch (effectType) {
	case EFFECT_ATTRIBUTE: {
		buff = new Buff(player, buffName.hashCode(), duration, BuffType::FOOD);
		setModifiers(buff, false);
		break;
	}

	case EFFECT_SKILL: {
		buff = new Buff(player, buffName.hashCode(), duration, BuffType::FOOD);
		setModifiers(buff, true);
		break;
	}

	case EFFECT_SPICE: {
		buff = new SpiceBuff(player, buffName, String("spice." + buffName + ".up").hashCode(), duration);
		setModifiers(buff, false);
		//buff->parseAttributeModifierString(modifierString);
		player->addBuff(buff);
		//useCharge(player);
		decreaseUseCount();
		return 1;
	}

	case EFFECT_HEALING: {
		int dmghealed = player->healDamage(player, 6, nutrition);

		if (dmghealed <= 0) {
			player->sendSystemMessage("@healing:no_mind_to_heal_self"); //You have no mind to heal.
			return 0;
		}

		StringIdChatParameter stringId("combat_effects", "food_mind_heal");
		stringId.setDI(dmghealed);

		player->sendSystemMessage(stringId);

		break;
	}

	case EFFECT_DURATION: {
		buff = new DurationBuff(player, buffName.hashCode(), duration);
		setModifiers(buff, true);
		//buff->parseSkillModifierString(generateModifierString());
		break;
	}

	case EFFECT_DELAYED: {
		buff = new DelayedBuff(player, buffName.hashCode(), duration);
		setModifiers(buff, true);

		DelayedBuff* delayedBuff = cast<DelayedBuff*>(buff.get());
		delayedBuff->init(&eventTypes);

		break;
	}

	case EFFECT_INSTANT: {
		if (modifiers.isEmpty())
			return 0;

		//TODO: Handle each instant effect on its own...
		String effect = modifiers.elementAt(0).getKey();

		if (effect == "burst_run") {
			//We need to reduce the cooldown and efficiency.
			player->executeObjectControllerAction(String("burstrun").hashCode());

			if (player->hasBuff(String("burstrun").hashCode())) {
				float reduction = 1.f - ((float)nutrition / 100.f);
				player->updateCooldownTimer("burstrun", ((300 * reduction) + duration) * 1000);
				player->sendSystemMessage("@combat_effects:instant_burst_run"); //You instantly burst run at increased efficiency!

				Reference<Task*> task = player->getPendingTask("burst_run_notify");

				if (task != NULL)
					task->reschedule(((300 * reduction) + duration) * 1000);
				else {
					task = new BurstRunNotifyAvailableEvent(player);
					player->addPendingTask("burst_run_notify", task, ((300 * reduction) + duration) * 1000);
				}

			} else {
				//Couldnt burst run yet.
				return 0;
			}
		} else if (effect == "food_reduce") {
			//Tilla till reduces food stomach filling by a percentage
			int currentfilling = ghost->getFoodFilling();
			ghost->setFoodFilling(round(currentfilling * (100 - nutrition) / 100.0f), true);
		}
	}
	}

	if (buff != NULL)
		player->addBuff(buff);

	if (isFood())
		ghost->setFoodFilling(ghost->getFoodFilling() + filling, true);

	if (isDrink())
		ghost->setDrinkFilling(ghost->getDrinkFilling() + filling, true);

	StringIdChatParameter stringId("base_player", "prose_consume_item");
	stringId.setTT(getObjectID());
	player->sendSystemMessage(stringId);//player->sendSystemMessage("base_player", "prose_consume_item", objectID);;

	// Play the client effect sound depending on species/gender.

	// Get the species.
	int species = player->getSpecies();

	switch (species) {
	case 0:
		// Human
		if (player->getGender() == 0)
			player->playEffect("clienteffect/human_male_eat.cef");
		else if (player->getGender() == 1)
			player->playEffect("clienteffect/human_female_eat.cef");
		break;
	case 2: // Trandoshan
		if (player->getGender() == 0)
			player->playEffect("clienteffect/reptile_male_eat.cef");
		else if (player->getGender() == 1)
			player->playEffect("clienteffect/reptile_female_eat.cef");
		break;
	case 4: // Wookiee
		if (player->getGender() == 0)
			player->playEffect("clienteffect/wookiee_male_eat.cef");
		else if (player->getGender() == 1)
			player->playEffect("clienteffect/wookiee_female_eat.cef");
		break;
	default:
		break;

	}

	//Consume a charge from the item, destroy it if it reaches 0 charges remaining.
	//useCharge(player);
	decreaseUseCount();

	return 0;
}