HoS_PRC8/_mod/_module/nss/area_decay_lair.nss
Jaysyn904 04165202c0 Initial upload
Initial upload
2024-11-25 19:36:07 -05:00

135 lines
3.9 KiB
Plaintext

// Area decaying system - keep items cleaned up
int fnIsManaObject(object oItem)
{ // return true if mana crystal
int nRet=FALSE;
string sRes=GetResRef(oItem);
if (sRes=="mana_crystal_5"||sRes=="mana_crystal_2"||sRes=="mana_crystal_1") nRet=TRUE;
return nRet;
} // fnIsManaObject()
int fnIsSoulObject(object oItem)
{ // return true if is soul token
int nRet=FALSE;
string sRes=GetResRef(oItem);
if (sRes=="soultoken") nRet=TRUE;
return nRet;
} // fnIsSoulObject()
int fnFilterMineable(object oItem)
{ // return true if is a mineable resource
int nRet=FALSE;
string sTag=GetTag(oItem);
if (sTag=="x2_it_cmat_adam"||sTag=="x2_it_cmat_iron"||sTag=="x2_it_cmat_mith"||sTag=="NW_IT_GOLD001"||sTag=="rts_it_report") nRet=TRUE;
return nRet;
} // fnFilterMineable()
void fnDestroyContainer(object oContainer)
{ // empty items
object oItem=GetFirstItemInInventory(oContainer);
while(oItem!=OBJECT_INVALID)
{
DelayCommand(0.2,DestroyObject(oItem));
oItem=GetNextItemInInventory(oContainer);
}
DelayCommand(0.3,DestroyObject(oContainer));
} // fnDestroyContainer()
int fnItemIsImportant(object oItem)
{
// don't destroy mana, resource, or plot objects except for soul tokens
int nReturn=FALSE;
if(fnIsManaObject(oItem)==TRUE) nReturn=TRUE;
else if(fnIsSoulObject(oItem)==TRUE) nReturn=FALSE;
else if(fnFilterMineable(oItem)==TRUE) nReturn=TRUE;
else if(GetPlotFlag(oItem)==TRUE) nReturn=TRUE;
return nReturn;
}
int fnContainerIsImportant(object oContainer)
{
object oMe=OBJECT_SELF;
string sID=GetLocalString(oMe,"sTeamID");
string sTag=GetTag(oContainer);
if(sTag==(sID+"_CHEST")) return TRUE;
if(sTag==(sID+"_STORAGE")) return TRUE;
if(sTag=="vamp_coffin") return TRUE;
if (GetStringLeft(sTag,4)=="rts_") return TRUE;
return FALSE;
}
void fnDecayContainers()
{
object oMe=OBJECT_SELF;
object oCenter=GetFirstObjectInArea(oMe);
object oItem;
int nC=1;
object oBody;
object oStart;
object oMod=GetModule();
string sID=GetLocalString(oMe,"sTeamID");
object oLeader=GetLocalObject(oMod,"oTeamLead"+sID);
if (oLeader==OBJECT_INVALID||GetIsPC(oLeader)!=TRUE)
{ // NOT PC controlled lair
if (GetObjectType(oCenter)!=OBJECT_TYPE_WAYPOINT) oCenter=GetNearestObject(OBJECT_TYPE_WAYPOINT,oCenter,1);
oBody=GetNearestObject(OBJECT_TYPE_PLACEABLE,oCenter,nC);
while(oBody!=OBJECT_INVALID)
{ //!OI
if(GetLocalInt(oBody,"bNoClean")!=TRUE&&GetHasInventory(oBody)==TRUE&&GetTag(oBody)!="pileogold"&&fnContainerIsImportant(oBody)==FALSE)
{ // destroy
if (GetLocalInt(oBody,"nDecay")==1)
fnDestroyContainer(oBody);
else { SetLocalInt(oBody,"nDecay",1); }
} // destroy
nC++;
oBody=GetNearestObject(OBJECT_TYPE_PLACEABLE,oCenter,nC);
} //!OI
} // NOT PC CONTROLLED LAIR
}
void fnDecay()
{
object oMe=OBJECT_SELF;
object oCenter=GetFirstObjectInArea(oMe);
object oItem;
int nC=1;
if (GetObjectType(oCenter)!=OBJECT_TYPE_WAYPOINT) oCenter=GetNearestObject(OBJECT_TYPE_WAYPOINT,oCenter,1);
oItem=GetNearestObject(OBJECT_TYPE_ITEM,oCenter,nC);
while(oItem!=OBJECT_INVALID)
{ // decay items
if(fnItemIsImportant(oItem)==FALSE)
{
if (GetLocalInt(oItem,"nDecay")==1)
DestroyObject(oItem);
else { SetLocalInt(oItem,"nDecay",1); }
}
nC++;
oItem=GetNearestObject(OBJECT_TYPE_ITEM,oCenter,nC);
} // decay items
DelayCommand(5.0,fnDecayContainers());
}
void main()
{
object oMe=OBJECT_SELF;
int nCC=GetLocalInt(oMe,"nCC");
float fF=HoursToSeconds(6);
int nH=FloatToInt(fF);
object oMod=GetModule();
string sID=GetLocalString(oMe,"sTeamID");
object oLeader=GetLocalObject(oMod,"oTeamLead"+sID);
if (GetIsPC(oLeader)!=TRUE)
{ // okay to clean
if (GetLocalInt(oMod,"nAISetting")==1)
{ // only active with challenging AI setting
nH=nH/6;
nCC++;
if (nCC>=nH)
{
nCC=0;
DelayCommand(1.0,fnDecay());
}
SetLocalInt(oMe,"nCC",nCC);
} // only active with challenging AI setting
} // okay to clean
}