mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
358 lines
7.2 KiB
Plaintext
358 lines
7.2 KiB
Plaintext
/********************************************************************************************
|
|
* Copyright (c) ©2000,2001 Sony Online Entertainment Inc.
|
|
* All Rights Reserved
|
|
********************************************************************************************
|
|
* Title: player_stomachs.scriptlib
|
|
* Description:
|
|
*
|
|
*
|
|
* @author $Author: Matthew Kwid$
|
|
* @version $Revision: $
|
|
*
|
|
********************************************************************************************/
|
|
|
|
const int STOMACH_FOOD = 0;
|
|
const int STOMACH_DRINK = 1;
|
|
const int STOMACH_MAX = 2;
|
|
|
|
const string DATATABLE_STOMACH = "datatables/player/stomach.iff";
|
|
|
|
const string COL_NAME = "STOMACH_NAME";
|
|
const string COL_MAX_VALUE = "MAX_STOMACH_VALUE";
|
|
const string COL_DIGEST_RATE = "DIGEST_RATE";
|
|
const string COL_DIGEST_VALUE = "DIGEST_VALUE";
|
|
|
|
const string COL_STOMACH_VAR = "STOMACH_VAR";
|
|
const string COL_STAMP_VAR = "STAMP_VAR";
|
|
|
|
const string COL_MSG_FULL = "MSG_FULL";
|
|
const string COL_TARGET_FULL = "MSG_TARGET_FULL";
|
|
|
|
const string VAR_STOMACH_BASE = "stomach";
|
|
|
|
const string_id SID_STOMACH_UNKNOWN = new string_id("error_message","stomach_unknown");
|
|
const string SCRIPT_TOXIC_BLOOD = "item.comestible.toxic_blood";
|
|
|
|
boolean resetStomachs( obj_id player )
|
|
{
|
|
boolean isActive = true;
|
|
|
|
for ( int i = 0; i < STOMACH_MAX; i++ )
|
|
{
|
|
if ( setStomach( player, i, 0, getGameTime()) < 0 )
|
|
isActive &= false;
|
|
}
|
|
|
|
return isActive;
|
|
}
|
|
|
|
boolean isValidStomach( int idx )
|
|
{
|
|
if ( (idx >= STOMACH_FOOD) && (idx < STOMACH_MAX) )
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
string getStomachVar( int stomach )
|
|
{
|
|
return dataTableGetString( DATATABLE_STOMACH, stomach, COL_STOMACH_VAR );
|
|
}
|
|
|
|
string getStampVar( int stomach )
|
|
{
|
|
return dataTableGetString( DATATABLE_STOMACH, stomach, COL_STAMP_VAR );
|
|
}
|
|
|
|
string_id getStomachFullMsg( int stomach )
|
|
{
|
|
string lookup = dataTableGetString( DATATABLE_STOMACH, stomach, COL_MSG_FULL );
|
|
return new string_id( "error_message", lookup );
|
|
}
|
|
|
|
string_id getTargetFullMsg( int stomach )
|
|
{
|
|
string lookup = dataTableGetString( DATATABLE_STOMACH, stomach, COL_TARGET_FULL );
|
|
return new string_id( "error_message", lookup );
|
|
}
|
|
|
|
int setStomach( obj_id player, int stomach, int vol, int stamp )
|
|
{
|
|
if ( player == null )
|
|
return -1;
|
|
|
|
if ( vol < 0 )
|
|
vol = 0;
|
|
|
|
if ( !isValidStomach(stomach) )
|
|
return -1;
|
|
|
|
boolean litmus = true;
|
|
int maxSize = getStomachMaxSize( stomach );
|
|
|
|
if ( vol > maxSize )
|
|
vol = maxSize;
|
|
|
|
litmus &= setObjVar( player, getStomachVar(stomach), vol );
|
|
litmus &= setObjVar( player, getStampVar(stomach), stamp );
|
|
|
|
if ( litmus )
|
|
return vol;
|
|
else
|
|
return -1;
|
|
}
|
|
|
|
boolean canAddToStomach(obj_id player, int stomach, int vol)
|
|
{
|
|
/* if(!isIdValid(player))
|
|
return false;
|
|
|
|
if(!isValidStomach(stomach))
|
|
return false;
|
|
|
|
int curVal = getStomach(player, stomach);
|
|
if(curVal < 0)
|
|
return false;
|
|
|
|
int endVal = curVal + vol;
|
|
if(endVal > getStomachMaxSize(stomach))
|
|
return false;
|
|
*/
|
|
return true;
|
|
}
|
|
|
|
boolean canAddToStomach(obj_id player, int[] vol)
|
|
{
|
|
/* if(!isIdValid(player))
|
|
return false;
|
|
|
|
if(vol == null || vol.length == 0)
|
|
return false;
|
|
*/
|
|
boolean result = true;
|
|
/*
|
|
for(int i = 0; i < vol.length; i++)
|
|
{
|
|
if(i >= STOMACH_MAX)
|
|
break;
|
|
|
|
result &= canAddToStomach(player, i, vol[i]);
|
|
}
|
|
*/
|
|
return result;
|
|
}
|
|
|
|
boolean addToStomach( obj_id player, int stomach, int vol )
|
|
{
|
|
/* if ( player == null )
|
|
return false;
|
|
|
|
if ( !isValidStomach(stomach) )
|
|
return false;
|
|
|
|
if ( !hasObjVar(player, VAR_STOMACH_BASE) )
|
|
{
|
|
resetStomachs( player );
|
|
|
|
obj_id self = getSelf();
|
|
if ( player == self )
|
|
return addToStomach(player, stomach, vol);
|
|
else
|
|
{
|
|
dictionary d = new dictionary();
|
|
d.put( "stomach", stomach );
|
|
d.put( "vol", vol );
|
|
messageTo( player, "handleAddToStomach", d, 1, false );
|
|
return true;
|
|
}
|
|
}
|
|
|
|
int curVal = getStomach( player, stomach );
|
|
if ( curVal < 0 )
|
|
return false;
|
|
|
|
int endVal = curVal + vol;
|
|
if ( endVal > getStomachMaxSize(stomach) )
|
|
{
|
|
sendSystemMessage( player, getStomachFullMsg(stomach) );
|
|
return false;
|
|
}
|
|
if ( endVal < 0 )
|
|
endVal = 0;
|
|
|
|
if ( setStomach(player, stomach, endVal, getGameTime()) == -1 )
|
|
return false;
|
|
*/
|
|
return true;
|
|
}
|
|
|
|
boolean addToStomach( obj_id player, obj_id target, int stomach, int vol )
|
|
{
|
|
/* if ( (player == null) || (target == null) )
|
|
return false;
|
|
|
|
if ( !isValidStomach(stomach) )
|
|
return false;
|
|
|
|
if ( !addToStomach(target, stomach, vol) )
|
|
{
|
|
if ( player != target )
|
|
sendSystemMessage(player, getTargetFullMsg(stomach));
|
|
return false;
|
|
} */
|
|
return true;
|
|
}
|
|
|
|
boolean addToStomach( obj_id player, obj_id target, int[] vol )
|
|
{
|
|
/* if ( (player == null) || (target == null) || (vol == null) || (vol.length == 0) )
|
|
return false;
|
|
*/
|
|
boolean litmus = true;
|
|
|
|
/* for ( int i = 0; i < vol.length; i++ )
|
|
{
|
|
if ( i < STOMACH_MAX )
|
|
{
|
|
litmus &= addToStomach(player, target, i, vol[i]);
|
|
if ( !litmus )
|
|
{
|
|
for ( int n = 0; n < i; n++ )
|
|
{
|
|
addToStomach( target, n, -vol[n] );
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
} */
|
|
return litmus;
|
|
}
|
|
|
|
boolean addToStomach( obj_id player, int[] vol )
|
|
{
|
|
return addToStomach( player, player, vol );
|
|
}
|
|
|
|
int getStomach( obj_id player, int stomach )
|
|
{
|
|
if ( player == null )
|
|
return -1;
|
|
|
|
if ( !isValidStomach(stomach) )
|
|
return -1;
|
|
|
|
int curVol = 0;
|
|
int stamp = 0;
|
|
int curTime = getGameTime();
|
|
int deltaTime = 0;
|
|
int digestRate = getStomachDigestRate(stomach);
|
|
int digestCycles = 0;
|
|
int digested = 0;
|
|
|
|
curVol = getIntObjVar(player, getStomachVar(stomach));
|
|
stamp = getIntObjVar(player, getStampVar(stomach));
|
|
deltaTime = curTime - stamp;
|
|
digestCycles = deltaTime / digestRate;
|
|
digested = digestCycles * getStomachDigestValue(stomach);
|
|
curVol -= digested;
|
|
|
|
if ( curVol < 0 )
|
|
curVol = 0;
|
|
|
|
// update the stamp value based on how many whole
|
|
// units of digestion time actually elapsed
|
|
curVol = setStomach( player, stomach, curVol, stamp + (digestCycles * digestRate));
|
|
|
|
if ( curVol < 0 )
|
|
return -1;
|
|
|
|
return curVol;
|
|
}
|
|
|
|
boolean digestAll( obj_id player )
|
|
{
|
|
boolean litmus = true;
|
|
|
|
for ( int i = 0; i < STOMACH_MAX; i++ )
|
|
{
|
|
if ( getStomach(player, i) < 0 )
|
|
litmus = false;
|
|
}
|
|
|
|
return litmus;
|
|
}
|
|
|
|
boolean isStomachFull( obj_id player, int stomach )
|
|
{
|
|
/* if ( player == null )
|
|
return false;
|
|
|
|
if ( getStomach(player, stomach) >= getStomachMaxSize(stomach) )
|
|
return true;
|
|
*/
|
|
return false;
|
|
}
|
|
|
|
boolean deactivateStomachs( obj_id player )
|
|
{
|
|
if ( player == null )
|
|
return false;
|
|
|
|
removeObjVar(player, VAR_STOMACH_BASE);
|
|
return true;
|
|
}
|
|
|
|
string[] getStomachName()
|
|
{
|
|
return dataTableGetStringColumn( DATATABLE_STOMACH, COL_NAME );
|
|
}
|
|
|
|
string getStomachName( int idx )
|
|
{
|
|
string[] s = getStomachName();
|
|
if ( s != null )
|
|
return s[idx];
|
|
return "";
|
|
}
|
|
|
|
int[] getStomachMaxSize()
|
|
{
|
|
return dataTableGetIntColumn( DATATABLE_STOMACH, COL_MAX_VALUE );
|
|
}
|
|
|
|
int getStomachMaxSize( int idx )
|
|
{
|
|
int[] i = getStomachMaxSize();
|
|
if ( i != null )
|
|
return i[idx];
|
|
return -1;
|
|
}
|
|
|
|
int[] getStomachDigestRate()
|
|
{
|
|
return dataTableGetIntColumn( DATATABLE_STOMACH, COL_DIGEST_RATE );
|
|
}
|
|
|
|
int getStomachDigestRate( int idx )
|
|
{
|
|
int[] i = getStomachDigestRate();
|
|
if ( i != null )
|
|
return i[idx];
|
|
return -1;
|
|
}
|
|
|
|
int[] getStomachDigestValue()
|
|
{
|
|
return dataTableGetIntColumn( DATATABLE_STOMACH, COL_DIGEST_VALUE );
|
|
}
|
|
|
|
int getStomachDigestValue( int idx )
|
|
{
|
|
int[] i = getStomachDigestValue();
|
|
if ( i != null )
|
|
return i[idx];
|
|
return -1;
|
|
}
|
|
|
|
|