mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-08-01 01:15:59 -04:00
185 lines
5.5 KiB
Plaintext
185 lines
5.5 KiB
Plaintext
/**********************************************************************
|
|
|
|
*
|
|
* Title: biolink_item_non_faction
|
|
* Description: Implements bio-linked objects.
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
|
|
include library.sui;
|
|
include library.utils;
|
|
include library.combat;
|
|
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
|
|
const string VAR_TEMP_BASE = "biotemp";
|
|
|
|
const string_id SID_ITEM_BIO_LINKED = new string_id("base_player", "item_bio_linked");
|
|
const string_id SID_MUST_USE_FROM_INVENTORY = new string_id("base_player", "must_biolink_to_use_from_inventory");
|
|
const string_id SID_MUST_BIO_LINK_FROM_INVENTORY = new string_id("base_player", "must_bio_link_from_inventory");
|
|
const string_id SID_BIO_LINK = new string_id("ui_radial", "bio_link");
|
|
const string_id SID_BIO_LINK_MSG_PROMPT = new string_id("sui", "bio_link_item_prompt");
|
|
const string_id SID_BIO_LINK_MSG_TITLE = new string_id("sui", "bio_link_item_title");
|
|
const string_id SID_SPECIES_CANNOT_EQUIP = new string_id("base_player", "species_cannot_equip");
|
|
const string_id SID_NO_DROP_TRADE_BIOLINKED_ITEM = new string_id("base_player", "bio_link_no_drop_trade");
|
|
|
|
/***** TRIGGERS ********************************************************/
|
|
|
|
trigger OnAttach()
|
|
{
|
|
// set us to the bio-link pending state
|
|
obj_id biolink = getBioLink(self);
|
|
if (biolink == null || biolink == utils.OBJ_ID_BIO_LINK_PENDING)
|
|
setBioLink(self, null);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnInitialize()
|
|
{
|
|
// verify that we are bio-linked
|
|
obj_id biolink = getBioLink(self);
|
|
if ( biolink == null )
|
|
setBioLink(self, null);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnAboutToBeTransferred(obj_id destContainer, obj_id transferer)
|
|
{
|
|
// if we are about to be equipped, see if we are bio-linked pending
|
|
obj_id biolink = getBioLink(self);
|
|
if ( biolink == null )
|
|
{
|
|
setBioLink(self, null);
|
|
biolink = utils.OBJ_ID_BIO_LINK_PENDING;
|
|
}
|
|
if ( biolink == utils.OBJ_ID_BIO_LINK_PENDING && isPlayer(destContainer) )
|
|
{
|
|
// verify that we are in the player's inventory
|
|
if ( utils.getContainingPlayer(self) != destContainer )
|
|
{
|
|
sendSystemMessage(destContainer, SID_MUST_USE_FROM_INVENTORY);
|
|
return SCRIPT_OVERRIDE;
|
|
}
|
|
|
|
int pid = sui.msgbox(self, destContainer, "@" + SID_BIO_LINK_MSG_PROMPT, sui.YES_NO, "@" + SID_BIO_LINK_MSG_TITLE, "handleEquipBioLinkSui");
|
|
return SCRIPT_OVERRIDE;
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectMenuRequest(obj_id player, menu_info item)
|
|
{
|
|
// if we are bio-linked pending, add option for the player to bio-link us to them
|
|
obj_id biolink = getBioLink(self);
|
|
if ( biolink == utils.OBJ_ID_BIO_LINK_PENDING )
|
|
{
|
|
// make sure we are in the player's inventory
|
|
if ( isIdValid(player) && utils.getContainingPlayer(self) == player )
|
|
{
|
|
item.addRootMenu(menu_info_types.BIO_LINK, SID_BIO_LINK);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectMenuSelect(obj_id player, int item)
|
|
{
|
|
if ( item == menu_info_types.BIO_LINK )
|
|
{
|
|
obj_id biolink = getBioLink(self);
|
|
if ( biolink == utils.OBJ_ID_BIO_LINK_PENDING )
|
|
{
|
|
// make sure we are in the player's inventory
|
|
if ( isIdValid(player) && utils.getContainingPlayer(self) == player )
|
|
{
|
|
_bioLinkItem(self, player, false, true);
|
|
}
|
|
}
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/***** CALLBACK FUNCTIONS **********************************************/
|
|
|
|
/**
|
|
* Callback from the message box when a player tries to equip a bio-link pending object.
|
|
*/
|
|
messageHandler handleEquipBioLinkSui()
|
|
{
|
|
int bp = sui.getIntButtonPressed(params);
|
|
if ( bp == sui.BP_CANCEL )
|
|
return SCRIPT_CONTINUE;
|
|
|
|
obj_id player = sui.getPlayerId(params);
|
|
_bioLinkItem(self, player, true, true);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
|
|
/***** SUPPORT FUNCTIONS ***********************************************/
|
|
|
|
/**
|
|
* Verifies that the player can use the item. The player is then asked to verify that they want to equip it.
|
|
*/
|
|
boolean _bioLinkItem(obj_id self, obj_id player, boolean equipAfterLink, boolean queryPlayer)
|
|
{
|
|
if ( !isIdValid(self) || !isIdValid(player) )
|
|
{
|
|
CustomerServiceLog("NonFaction", "WARNING: biolink_item._bioLinkItem called with invalid player (%TU) or item (" + self + ")", player);
|
|
return false;
|
|
}
|
|
|
|
// verify that we're bio-linked pending
|
|
obj_id biolink = getBioLink(self);
|
|
if ( biolink != utils.OBJ_ID_BIO_LINK_PENDING )
|
|
{
|
|
CustomerServiceLog("NonFaction", "WARNING: Player %TU trying to bio-link item " + self + " that has link id " + biolink, player);
|
|
return false;
|
|
}
|
|
|
|
// verify that the item is in the player's inventory
|
|
if ( utils.getContainingPlayer(self) != player )
|
|
{
|
|
sendSystemMessage(player, SID_MUST_BIO_LINK_FROM_INVENTORY);
|
|
return false;
|
|
}
|
|
|
|
//verify that we can be equipped by player's species
|
|
string template = getTemplateName(self);
|
|
if ( (template.startsWith("object/tangible/wearables/") ) && (!canEquipWearable(player, self) ) )
|
|
{
|
|
sendSystemMessage(player, SID_SPECIES_CANNOT_EQUIP);
|
|
return false;
|
|
}
|
|
|
|
//dont let them bio link if they cant equip the weapon
|
|
if (isWeapon(self))
|
|
{
|
|
if(!combat.hasCertification(player, self))
|
|
{
|
|
sendSystemMessage(player, SID_SPECIES_CANNOT_EQUIP);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// do the bio-link
|
|
setBioLink(self, player);
|
|
prose_package pp = new prose_package();
|
|
pp.stringId = SID_ITEM_BIO_LINKED;
|
|
sendSystemMessageProse(player, pp);
|
|
sendDirtyObjectMenuNotification(self);
|
|
|
|
// we've been bio-linked, go ahead and equip us
|
|
if ( equipAfterLink )
|
|
equip(self, player);
|
|
|
|
return true;
|
|
}
|
|
|