Files
dsrc/sku.0/sys.server/compiled/game/script/poi/twoliars/mediator.script
T

240 lines
5.5 KiB
Plaintext

/**
*
* Title: mediator.script
* Description: mediator object script: POI = twoliars
*/
//------------------------
// Includes
//------------------------
include library.npc;
include library.ai_lib;
include library.scenario;
include library.poi;
include library.utils;
include library.prose;
include ai.ai_combat;
//-----------------------
// Inherits
//-----------------------
inherits poi.base.scenario_actor;
//------------------------
// Constants
//------------------------
const string SCRIPT_CONVERSE = "npc.converse.npc_converse_menu";
const string LOG_NAME = "poiTwoLiars Mediator";
// Conversation states.
const int CONV_GREET = 0; // Player hasn't spoken to anyone and needs a greeting.
const int CONV_LOOKING = 1; // Player is looking for the mark.
const int CONV_LOSS = 2; // Player guessed wrong.
const int CONV_WIN = 3; // Player guessed right.
const string agitateEmotes[] = { "scratch", "yawn", "fidget", "cough" };
//------------------------
// Methods
//------------------------
//------------------------
// OnAttach
//------------------------
trigger OnAttach()
{
attachScript( self, SCRIPT_CONVERSE );
// Set an agitation timer.
messageTo( self, "doAgitation", null, rand(40,60), true );
return SCRIPT_CONTINUE;
}
//------------------------
// OnInitialize
//------------------------
trigger OnInitialize()
{
attachScript( self, SCRIPT_CONVERSE );
return SCRIPT_CONTINUE;
}
//------------------------
// OnStartNpcConversation
//------------------------
trigger OnStartNpcConversation( obj_id speaker )
{
// Ignore conversation in combat.
if ( ai_lib.isInCombat(self) )
return SCRIPT_CONTINUE;
// Get conversation.
string convo = scenario.getConvo();
if ( convo.equals("") )
{
npcEndConversation( speaker );
return SCRIPT_CONTINUE;
}
// Look up our progress.
int progress = scenario.getPlayerProgress( speaker );
//------------------------------------------------
// Mediator chatter.
//------------------------------------------------
// Msg/response vars.
string_id msg = new string_id( convo, "a_greet" );
resizeable string_id[] responses = new string_id[0];
// Choose something to say based on this player's progrss.
int m_index = getIntObjVar( self, "m_index" );
int s_index = getIntObjVar( self, "s_index" );
switch ( progress )
{
case CONV_GREET:
case CONV_LOSS:
// Normal chatter.
poi.quickSay( self, "m_chatter_" + s_index );
npcEndConversation( speaker );
break;
case CONV_WIN:
// Victory chatter.
poi.quickSay( self, "m_chatter_v_" + rand(0,2) );
npcEndConversation( speaker );
break;
case CONV_LOOKING:
// Greet the player.
msg = new string_id( convo, "m_chatter_" + s_index );
responses = utils.addElement( responses, new string_id(convo, "r_m_chatter_knowabouttheft") );
npcStartConversation( speaker, self, convo, msg, responses );
break;
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// OnNpcConversationResponse
//------------------------------------------------
trigger OnNpcConversationResponse( string convoName, obj_id speaker, string_id response )
{
// Ignore conversation in combat.
if ( ai_lib.isInCombat(self) )
{
return SCRIPT_CONTINUE;
}
// Get reference to conversation.
string convo = scenario.getConvo();
if ( convo.equals("") )
{
npcEndConversation( speaker );
return SCRIPT_CONTINUE;
}
// Validate our conversation.
if ( !convoName.equals(convo) )
return SCRIPT_CONTINUE;
// Look up the player's progress.
int progress = scenario.getPlayerProgress( speaker );
// Respond to the player's comment.
string aId = response.getAsciiId();
string_id[] responses = new string_id[0];
// Zero out responses.
npcSetConversationResponses( speaker, responses );
// Speak our response.
if ( ( aId.equals("r_m_chatter_knowabouttheft") ) )
{
// Look up our line.
int m_index = getIntObjVar( self, "m_index" );
string_id lineId = new string_id( convo, "prose_m_line_" + m_index );
prose_package pp;
switch ( m_index )
{
case 0:
npcSpeak( speaker, lineId );
break;
case 1:
pp = prose.getPackage( lineId, getLiarName( 5 ) );
npcSpeak( speaker, pp );
break;
case 2:
pp = prose.getPackage( lineId, getLiarName( 1 ), getLiarName( 3 ) );
npcSpeak( speaker, pp );
break;
case 3:
pp = prose.getPackage( lineId, getLiarName( 1 ), getLiarName( 2 ) );
npcSpeak( speaker, pp );
break;
case 4:
pp = prose.getPackage( lineId, getLiarName( 3 ), getLiarName( 1 ), getLiarName( 2 ) );
npcSpeak( speaker, pp );
break;
case 5:
pp = prose.getPackage( lineId, getLiarName( 4 ) );
npcSpeak( speaker, pp );
break;
}
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// getLiarName
//------------------------------------------------
string getLiarName( int liarIndex )
{
obj_id self = getSelf();
obj_id poiMaster = poi.getBaseObject(self);
if ( (poiMaster == null) || (poiMaster == obj_id.NULL_ID) )
return "";
return getStringObjVar( poiMaster, "m_" + liarIndex );
}
//------------------------------------------------
// doAgitation
//------------------------------------------------
messageHandler doAgitation()
{
// Chance we might emote.
if ( rand(1,5) == 3 )
{
int whichsocial = rand( 0, 3 );
queueCommand( self, ##"social", null, agitateEmotes[whichsocial], COMMAND_PRIORITY_DEFAULT );
}
// Set new agitation timer.
messageTo( self, "doAgitation", null, rand(40,60), true );
return SCRIPT_CONTINUE;
}