mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
112 lines
2.9 KiB
Plaintext
112 lines
2.9 KiB
Plaintext
/**
|
|
* Title: furniture.scriptlib
|
|
* Description: base functions for furniture handling
|
|
*/
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
|
|
include library.utils;
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
|
|
const string VAR_CHAIR_OCCUPIED_BASE = "occupied";
|
|
const string VAR_CHAIR_OCCUPIED_IDS = "occupied.ids"; //obj_id array
|
|
const string VAR_CHAIR_OCCUPIED_LIMIT = "occupied.limit"; //int
|
|
|
|
const string VAR_PLAYER_SEAT_BASE = "seat";
|
|
const string VAR_PLAYER_SEAT_ID = "seat.id";
|
|
|
|
const string SCRIPT_CHAIR = "item.furniture.chair";
|
|
const string SCRIPT_PLAYER_SEATED = "player.player_seated";
|
|
|
|
const string_id SID_SEAT_FULL = new string_id("error_message","seat_full");
|
|
|
|
/***** FUNCTIONS *******************************************************/
|
|
/***********************************************************************
|
|
* @brief tries to seat a player in the specified chair
|
|
*
|
|
* @param obj_id player
|
|
* @param obj_id chair
|
|
*
|
|
* @return boolean; false on unable to seat player
|
|
***********************************************************************/
|
|
boolean sit(obj_id player, obj_id chair)
|
|
{
|
|
if ( (player == null) || (chair == null) )
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if ( !hasObjVar(chair, VAR_CHAIR_OCCUPIED_LIMIT) )
|
|
{
|
|
return false;
|
|
}
|
|
|
|
resizeable obj_id[] occupants = getResizeableObjIdArrayObjVar(chair, VAR_CHAIR_OCCUPIED_IDS);
|
|
|
|
int pos = 0; //default
|
|
if ( (occupants != null) && (occupants.length != 0) )
|
|
{
|
|
pos = occupants.length;
|
|
if ( pos >= getIntObjVar(chair, VAR_CHAIR_OCCUPIED_LIMIT) )
|
|
{
|
|
sendSystemMessage(player, SID_SEAT_FULL);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if ( sitOnObject(player, chair, pos) )
|
|
{
|
|
occupants = utils.addElement(occupants, player);
|
|
|
|
setObjVar(chair, VAR_CHAIR_OCCUPIED_IDS, occupants);
|
|
setObjVar(player, VAR_PLAYER_SEAT_ID, chair);
|
|
attachScript(player, SCRIPT_PLAYER_SEATED);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* @brief tries to unseat a player
|
|
*
|
|
* @param obj_id player
|
|
*
|
|
* @return boolean; false on unable to seat player
|
|
***********************************************************************/
|
|
boolean unseat(obj_id player)
|
|
{
|
|
if ( player == null )
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if ( !hasObjVar(player, VAR_PLAYER_SEAT_ID) )
|
|
{
|
|
return false;
|
|
}
|
|
|
|
obj_id chair = getObjIdObjVar(player, VAR_PLAYER_SEAT_ID);
|
|
|
|
resizeable obj_id[] occupants = getResizeableObjIdArrayObjVar(chair, VAR_CHAIR_OCCUPIED_IDS);
|
|
occupants = utils.removeElement(occupants, player);
|
|
|
|
if(occupants == null || occupants.length == 0) {
|
|
|
|
return false;
|
|
}
|
|
|
|
boolean litmus = setObjVar(chair, VAR_CHAIR_OCCUPIED_IDS, occupants);
|
|
|
|
removeObjVar(player, VAR_PLAYER_SEAT_BASE);
|
|
detachScript(player, SCRIPT_PLAYER_SEATED);
|
|
|
|
return litmus;
|
|
}
|
|
|
|
|