コード例 #1
0
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);
}
コード例 #2
0
int DroidObjectImplementation::rechargeFromBattery(CreatureObject* player){

	// Find droid battery in player inventory
	ManagedReference<SceneObject*> inventory = player->getSlottedObject("inventory");
	if (inventory == NULL){
		player->sendSystemMessage("Player inventory not found");
		return 0;
	}

	ManagedReference<SceneObject*> batterySceno = NULL;
	for (int i = 0; i < inventory->getContainerObjectsSize(); ++i) {
		ManagedReference<SceneObject*> sceno = inventory->getContainerObject(i);
		if( sceno->getObjectTemplate()->getFullTemplateString() == "object/tangible/droid_battery/battery.iff" ){
			batterySceno = sceno;
		}
	}

	// Battery not found
	if( batterySceno == NULL ){
		showFlyText("npc_reaction/flytext","nobattery", 204, 0, 0); // "You don't have a power storage device."
		return 0;
	}

	// Battery found
	ManagedReference<TangibleObject*> batteryTano = cast<TangibleObject*>(batterySceno.get());
	if( batteryTano == NULL ){
		player->sendSystemMessage("Error with droid battery object");
		return 0;
	}

	// Reset power to max
	power = MAX_POWER;

	// Consume battery
	Locker locker(batteryTano);

	batteryTano->decreaseUseCount();

	showFlyText("npc_reaction/flytext","recharged", 0, 153, 0);  // "*Recharged*"
	doAnimation("power_up");
	return 0;

}