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

182 lines
7.0 KiB
Plaintext

///////////////////////////////////////////////////////////////////////////////
// powres_hb - Power Reservoir Heartbeat
// By Deva Bryson Winblood.
///////////////////////////////////////////////////////////////////////////////
#include "powres_h"
#include "color_header"
///////////////////////////
// PROTOTYPE
///////////////////////////
void fnMakePoint(string sTeam);
void fnConnection(object oOb);
void fnBadPosition();
void fnPVFX(int nNum);
void fnBadLocation();
//////////////////////////////////////////////////////////// MAIN
void main()
{
object oMe=OBJECT_SELF;
int nState=GetLocalInt(oMe,"nState");
string sTID=GetLocalString(oMe,"sTeamID");
object oOb;
string sS;
string sID;
int nSound;
PrintString("powerres_hb State:"+IntToString(nState));
oOb=GetObjectByTag("RTS_POWER_RES",0);
if (oOb==oMe) oOb=GetObjectByTag("RTS_POWER_RES",1);
if (GetIsObjectValid(oOb)&&GetLocalInt(oOb,"bExistedFirst")==FALSE) DestroyObject(oOb);
SetLocalInt(oMe,"bExistedFirst",TRUE);
oOb=GetObjectByTag("rts_powerres");
if (GetIsObjectValid(oOb))
{ // item exists same time as placeable
if (GetLocalInt(oOb,"bPlaceableExists")) DestroyObject(oOb);
SetLocalInt(oOb,"bPlaceableExists",TRUE);
} // item exists same time as placeable
if(nState==0)
{ // newly placed Power Reservoir determine state
if (GetNearestObjectByTag("LAIR")!=OBJECT_INVALID)
{ // in a lair
oOb=GetNearestObjectByTag("DWF");
if (oOb!=OBJECT_INVALID&&GetObjectType(oOb)==OBJECT_TYPE_PLACEABLE&&GetDistanceBetween(oOb,OBJECT_SELF)<=5.0)
{ // dwarves
SetLocalString(oMe,"sTeamID","DWF");
DelayCommand(HoursToSeconds(1),fnMakePoint("DWF"));
sS=ColorString("The Power Reservoir is being used in "+GetName(GetArea(oMe))+"!",COLOR_GREEN);
//fnSoundMessage(sS,"NA","as_sw_x2gong2");
fnPowerNotify(3,sS);
fnConnection(oOb);
nState=1;
} // dwarves
oOb=GetNearestObjectByTag("SPID");
if (oOb!=OBJECT_INVALID&&GetObjectType(oOb)==OBJECT_TYPE_PLACEABLE&&GetDistanceBetween(oOb,OBJECT_SELF)<=5.0)
{ // spiders
SetLocalString(oMe,"sTeamID","SPID");
DelayCommand(HoursToSeconds(1),fnMakePoint("SPID"));
sS=ColorString("The Power Reservoir is being used in "+GetName(GetArea(oMe))+"!",COLOR_GREEN);
//fnSoundMessage(sS,"NA","as_sw_x2gong2");
fnPowerNotify(4,sS);
fnConnection(oOb);
nState=1;
} // spiders
oOb=GetNearestObjectByTag("UNC");
if (oOb!=OBJECT_INVALID&&GetObjectType(oOb)==OBJECT_TYPE_PLACEABLE&&GetDistanceBetween(oOb,OBJECT_SELF)<=5.0)
{ // unclean
SetLocalString(oMe,"sTeamID","UNC");
DelayCommand(HoursToSeconds(1),fnMakePoint("UNC"));
sS=ColorString("The Power Reservoir is being used in "+GetName(GetArea(oMe))+"!",COLOR_GREEN);
//fnSoundMessage(sS,"NA","as_sw_x2gong2");
fnPowerNotify(2,sS);
fnConnection(oOb);
nState=1;
} // unclean
oOb=GetNearestObjectByTag("UND");
if (oOb!=OBJECT_INVALID&&GetObjectType(oOb)==OBJECT_TYPE_PLACEABLE&&GetDistanceBetween(oOb,OBJECT_SELF)<=5.0)
{ // undead
SetLocalString(oMe,"sTeamID","UND");
DelayCommand(HoursToSeconds(1),fnMakePoint("UND"));
sS=ColorString("The Power Reservoir is being used in "+GetName(GetArea(oMe))+"!",COLOR_GREEN);
//fnSoundMessage(sS,"NA","as_sw_x2gong2");
fnPowerNotify(1,sS);
fnConnection(oOb);
nState=1;
} // undead
if (nState==0)
{ // not correctly positioned
DelayCommand(HoursToSeconds(1),fnBadPosition());
fnPVFX(VFX_IMP_BREACH);
nState=2;
} // not correctly positioned
SetLocalInt(oMe,"nState",nState);
} // in a lair
else
{ // in the world
sTID=GetTag(GetArea(oMe));
if (sTID!="AGC"&&sTID!="AGNW"&&sTID!="AGNE"&&sTID!="AGSW"&&sTID!="AGSE"&&sTID!="BGC"&&sTID!="BGNW"&&sTID!="BGNE"&&sTID!="BGSE"&&sTID!="BGSW")
{ // bad area
DelayCommand(HoursToSeconds(1),fnBadLocation());
SetLocalInt(oMe,"nState",3);
} // bad area
else
{
SetLocalInt(oMe,"nState",1);
}
} // in the world
} // newly placed Power Reservoir determine state
PrintString("powerres_hb exit");
}
///////////////////////////////////////////////////////////// MAIN
////////////////////////////////
// FUNCTIONS
////////////////////////////////
void fnMakePoint(string sTeam)
{
object oMod=GetModule();
int nPow=GetLocalInt(oMod,"n"+sTeam+"Power");
effect eFX=EffectVisualEffect(VFX_IMP_LIGHTNING_M);
nPow++;
SetLocalInt(oMod,"n"+sTeam+"Power",nPow);
ApplyEffectToObject(DURATION_TYPE_INSTANT,eFX,OBJECT_SELF,3.0);
DelayCommand(HoursToSeconds(1),fnMakePoint(sTeam));
} // fnMakePoint()
void fnConnection(object oOb)
{ // beam effect between power res and throne
effect eBeam=EffectBeam(VFX_BEAM_SILENT_LIGHTNING,OBJECT_SELF,BODY_NODE_CHEST);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eBeam,oOb,8.0);
DelayCommand(8.0,fnConnection(oOb));
} // fnConnection()
void fnPVFX(int nNum)
{ // persistent visual effect
effect eVFX=EffectVisualEffect(nNum);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eVFX,OBJECT_SELF,5.0);
DelayCommand(10.0,fnPVFX(nNum));
} // fnPVFX()
void fnBadPosition()
{ // positioned in a bad location in the lair
object oMe=OBJECT_SELF;
object oMon1=GetLocalObject(oMe,"oMon1");
object oMon2=GetLocalObject(oMe,"oMon2");
int nCount=GetLocalInt(oMe,"nCount");
int nR;
if (oMon1==OBJECT_INVALID||GetIsDead(oMon1))
{ // spawn Monster 1
nR=d4();
if (nR<4) oMon1=CreateObject(OBJECT_TYPE_CREATURE,"nw_shfiend1",GetLocation(oMe),TRUE);
else { oMon1=CreateObject(OBJECT_TYPE_CREATURE,"nw_bodak1",GetLocation(oMe),TRUE); }
SetLocalObject(oMe,"oMon1",oMon1);
DelayCommand(10.0,AssignCommand(oMon1,ActionRandomWalk()));
DelayCommand(10.0,AssignCommand(oMon1,DelayCommand(HoursToSeconds(2),DestroyObject(oMon1))));
} // spawn Monster 1
if (oMon2==OBJECT_INVALID||GetIsDead(oMon2))
{ // spawn Monster 2
nR=d8();
if (nR<8) oMon2=CreateObject(OBJECT_TYPE_CREATURE,"nw_shfiend1",GetLocation(oMe),TRUE);
else { oMon2=CreateObject(OBJECT_TYPE_CREATURE,"nightwalker",GetLocation(oMe),TRUE); }
SetLocalObject(oMe,"oMon2",oMon2);
DelayCommand(10.0,AssignCommand(oMon2,ActionRandomWalk()));
DelayCommand(10.0,AssignCommand(oMon2,DelayCommand(HoursToSeconds(2),DestroyObject(oMon2))));
} // spawn Monster 2
nCount++;
SetLocalInt(oMe,"nCount",nCount);
if (nCount>6) DelayCommand(1.0,DestroyObject(oMe));
DelayCommand(HoursToSeconds(1),fnBadPosition());
} // fnBadPosition()
void fnBadLocation()
{ // not a good area
int nCount=GetLocalInt(OBJECT_SELF,"nCount");
nCount++;
if (nCount>3) DestroyObject(OBJECT_SELF);
else
{
SetLocalInt(OBJECT_SELF,"nCount",nCount);
DelayCommand(HoursToSeconds(1),fnBadLocation());
}
} // fnBadLocation()