Files
dsrc/sku.0/sys.server/compiled/game/script/item/target_buff.script
T

144 lines
3.4 KiB
Plaintext

include library.buff;
include library.dot;
include library.prose;
include library.utils;
const string_id SID_BUFF_NPC_ONLY = new string_id("spam", "item_buff_npc_only");
const string_id SID_BUFF_WONT_STACK = new string_id("spam", "item_buff_no_stack");
const string_id SID_BUFF_PLAYER_ONLY = new string_id("spam", "item_buff_player_only");
const string_id USED_EFFECT = new string_id("spam", "item_buff_used_other_player");
const string_id BUFF_OUT_OF_RANGE = new string_id("spam", "item_buff_out_of_range");
//This script is used for items that can buff (or debuff) other players, as well as the player himself or other npc's.
trigger OnInitialize()
{
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
if (!isIdValid(player))
return SCRIPT_OVERRIDE;
mi.addRootMenu (menu_info_types.ITEM_USE, null);
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuSelect(obj_id player, int item)
{
if (isDead(player) || isIncapacitated(player))
return SCRIPT_CONTINUE;
if (buff.hasBuff(player, "feign_death"))
return SCRIPT_CONTINUE;
obj_id target = getIntendedTarget(player);
if (!isIdValid(target))
{
target = getLookAtTarget(player);
if (!isIdValid(target))
target = null;
}
if(item == menu_info_types.ITEM_USE)
buff(self, player, target);
return SCRIPT_CONTINUE;
}
void buff(obj_id self, obj_id player, obj_id target)
{
if (!isIdValid(self) || !isIdValid(player))
return;
string buff_name = getStringObjVar(self, "buff_name");
if (buff_name == null || buff_name.equals(""))
return;
float eff = 1f;
float dur = 1f;
if (hasObjVar(self, "effectiveness"))
eff = getFloatObjVar(self, "effectiveness");
if (hasObjVar(self, "duration"))
dur = getFloatObjVar(self, "duration");
boolean success = true;
//Buff only allowed on npc's.
if (hasObjVar(self, "npc_only"))
{
if(isPlayer(target) || !isIdValid(target))
{
sendSystemMessage(player, SID_BUFF_NPC_ONLY);
return;
}
}
//Buff only allowed on the player that has the item.
if (hasObjVar(self, "self_only") || !isIdValid(target))
target = player;
//Buff can only be used on a player.
if (hasObjVar(self, "player_only") && !isPlayer(target))
{
sendSystemMessage(player, SID_BUFF_PLAYER_ONLY);
return;
}
if (buff.hasBuff(target, buff_name) && !hasObjVar(self, "can_stack"))
{
sendSystemMessage(player, SID_BUFF_WONT_STACK);
return;
}
//Buff can only be used up to a certain range.
if (hasObjVar(self, "max_range"))
{
if (isIdValid(target))
{
float maxRange = getFloatObjVar(self, "max_range");
location selfLoc = getLocation(player);
location targetLoc = getLocation(target);
float fltDistance = getDistance(selfLoc, targetLoc);
if (fltDistance > maxRange)
{
prose_package pp = prose.getPackage(BUFF_OUT_OF_RANGE);
prose.setDF(pp, maxRange);
sendSystemMessageProse(player, pp);
return;
}
}
}
float value = buff.getEffectValue(buff_name, 1);
float duration = buff.getDuration(buff_name);
value *= eff;
duration *= dur;
success = buff.applyBuff(target, buff_name, duration, value);
if (success)
{
if (isPlayer(target) && target != player)
{
prose_package pp = prose.getPackage(USED_EFFECT);
prose.setTT(pp, player);
prose.setTU(pp, "@ui_buff:" + buff_name);
sendSystemMessageProse(target, pp);
}
int count = getCount(self);
count--;
if(count <= 0)
destroyObject(self);
else
setCount(self, count);
}
}