generated from Jaysyn/ModuleTemplate
170 lines
5.0 KiB
Plaintext
170 lines
5.0 KiB
Plaintext
//::///////////////////////////////////////////////
|
|
//:: Name corpse_open
|
|
//:: FileName
|
|
//::
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
Responds to the onopen event of the placeable.
|
|
Performs a test to get the number of objects found
|
|
by the player and put them in the placeable inventory.
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Alexandre Brunel
|
|
//:: Created On: 21/04/2003
|
|
//:://////////////////////////////////////////////
|
|
#include "corpse_lib"
|
|
int searchTest(object player)
|
|
{
|
|
int retval = -1;
|
|
|
|
if( !GetLocalInt(OBJECT_SELF,CorpseFindAttemptRoot+GetPCID(player)))
|
|
{
|
|
int dice;
|
|
int level = GetLevelByClass(CLASS_TYPE_ROGUE,player);
|
|
int score = 0;
|
|
|
|
string suffix = GetPCID(player);
|
|
|
|
SetLocalInt(OBJECT_SELF,CorpseFindAttemptRoot+suffix,TRUE);
|
|
|
|
int attemptNumber = GetLocalInt(OBJECT_SELF,CorpseFindAttemptNumber);
|
|
|
|
SetLocalInt(OBJECT_SELF,CorpseFindAttemptNumber,attemptNumber+1);
|
|
|
|
SetLocalString(OBJECT_SELF,CorpseFindAttemptRoot+IntToString(attemptNumber),suffix);
|
|
|
|
if(level > 0)
|
|
{
|
|
int rank = GetSkillRank(SKILL_PICK_POCKET,player);
|
|
int try = 0;
|
|
int success = FALSE;
|
|
|
|
while(try < level && !success)
|
|
{
|
|
dice = d20();
|
|
score = dice + rank;
|
|
int value = score - GetLocalInt(OBJECT_SELF,CorpseFindDifficultyVarName);
|
|
|
|
if(dice == 1)
|
|
{
|
|
level--;
|
|
}
|
|
else if(value >= 0 || (score >= GetMaxDD(OBJECT_SELF) && getFindDifficulty() < GetMaxDD(OBJECT_SELF)) || dice == 20)
|
|
{
|
|
success = TRUE;
|
|
retval = value;
|
|
}
|
|
|
|
try++;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
dice = d20();
|
|
int rank = GetSkillRank(SKILL_SEARCH,player);
|
|
score = dice + rank;
|
|
int value = score - GetLocalInt(OBJECT_SELF,CorpseFindDifficultyVarName);
|
|
|
|
if(value >=0)
|
|
{
|
|
retval = value;
|
|
}
|
|
}
|
|
|
|
//Score is high enought to find all items
|
|
if(score >= GetMaxDD(OBJECT_SELF) && getFindDifficulty() < GetMaxDD(OBJECT_SELF))
|
|
{
|
|
SetLocalInt(OBJECT_SELF,CorpseCriticalResult,3);
|
|
}
|
|
|
|
|
|
switch(dice)
|
|
{
|
|
|
|
case 1: SetLocalInt(OBJECT_SELF,CorpseCriticalResult,2);
|
|
break;
|
|
case 20: SetLocalInt(OBJECT_SELF,CorpseCriticalResult,1);
|
|
break;
|
|
default: //SetLocalInt(OBJECT_SELF,CorpseCriticalResult,0);
|
|
break;
|
|
}
|
|
|
|
//WriteTimestampedLogEntry("searchTest dice value = "+IntToString(dice)); //debug
|
|
//WriteTimestampedLogEntry("searchTest score value = "+IntToString(score)); //debug
|
|
|
|
}
|
|
//WriteTimestampedLogEntry("searchTest return value = "+IntToString(retval)); //debug
|
|
//WriteTimestampedLogEntry("searchTest DD value = "+IntToString(getFindDifficulty())); //debug
|
|
|
|
return retval;
|
|
}
|
|
void main()
|
|
{
|
|
|
|
SetLocalInt(OBJECT_SELF,CorpseCriticalResult,0);
|
|
|
|
object opener = GetLastOpenedBy();
|
|
object target = GetLocalObject(OBJECT_SELF,CorpseCreatureCorpse);
|
|
object pc = GetLocalObject(target,CorpsePCCorpse);
|
|
|
|
if(GetIsObjectValid(pc))
|
|
{
|
|
target = pc;
|
|
}
|
|
|
|
if(GetLocalInt(OBJECT_SELF,CorpseFindDifficultyVarName) > 0 && !GetIsDM(opener))
|
|
{
|
|
|
|
int value = searchTest(opener);
|
|
|
|
if(value >= 0)
|
|
{
|
|
if(GetLocalInt(OBJECT_SELF,CorpseCriticalResult) == 1 )
|
|
{
|
|
//WriteTimestampedLogEntry("Getting objects, critical success...");
|
|
|
|
GetItemsInInventory(target,0,TRUE,opener);
|
|
SetCorpseDialogFound(TRUE);
|
|
}
|
|
else if(GetLocalInt(OBJECT_SELF,CorpseCriticalResult) == 3)
|
|
{
|
|
|
|
GetItemsInInventory(target,0,TRUE,opener);
|
|
SetCorpseDialogFound(TRUE);
|
|
}
|
|
else if(GetLocalInt(OBJECT_SELF,CorpseCriticalResult) == 0)
|
|
{
|
|
int itemNumber = (value/5) + 1;
|
|
//WriteTimestampedLogEntry("Getting objects...");
|
|
|
|
GetItemsInInventory(target,itemNumber,TRUE,opener);
|
|
|
|
SetCorpseDialogFound(TRUE);
|
|
}
|
|
SetCommandable(TRUE);
|
|
ActionDoCommand(SpeakOneLinerConversation(CorpseOneLinerDialogName,opener));
|
|
ActionDoCommand(SetCommandable(TRUE));
|
|
SetCommandable(FALSE);
|
|
}
|
|
else
|
|
{
|
|
//WriteTimestampedLogEntry("Getting allready found objects...");
|
|
|
|
GetFoundItemsInInventory(target,opener);
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
//WriteTimestampedLogEntry("Getting allready found objects...");
|
|
GetItemsInInventory(target);
|
|
//SetCorpseDialogFound(TRUE);
|
|
//WriteTimestampedLogEntry("searchTest DD value = "+IntToString(getFindDifficulty())); //debug
|
|
}
|
|
|
|
DeleteLocalInt(OBJECT_SELF,CorpseCriticalResult);
|
|
|
|
}
|