EN4_PRC8/_module/nss/rd_advzones.nss

579 lines
16 KiB
Plaintext
Raw Permalink Normal View History

#include "rd_spawn"
object SetupAdventureZones(int iLevel, int iAdventureType = 0, string sSpawn = "", string sItem = "");
void ClearAdventureZones();
int GetHasAdvZone(int iArea, int iZones,string sPrefix);
object PopulateArea(string sArea,string sCampType,int iSpawnType, int iLevel, int iBase,int iBaseStart,int iBaseMax,int iCampType, int iBoss = TRUE,int iWander = FALSE);
void PopArea(string sArea,string sCampType,int iSpawnType, int iLevel, int iBase,int iBaseStart,int iBaseMax,int iCampType, int iBoss = TRUE,int iWander = FALSE);
void ClearArea(string sArea);
void RemoveLootFromAdvArea(object oArea);
void RemoveLootFromRemains(object oContainer);
int AZDifficulty();
void ZoneToArea(object oPC,int iArea);
object SetupAdventureZones(int iLevel, int iAdventureType = 0, string sSpawn = "", string sItem = "")
{
int iLand;
int iLE;
int iLair;
int iZones;
int iIndex;
int iIndexCheck;
int iArea;
int iFlag;
int iBase;
int iBaseStart;
int iBaseMax;
int iCampType;
int iAreas;
int iDungeonLair;
int iDungeon;
int iCampSize;
int iBoss;
string sTreasure;
string sCampType;
string sArea;
string sAreas;
string sCD;
object oChest;
object oBoss;
object oMod;
//SendMessageToPC(GetFirstPC(),"Level=" + IntToString(iLevel));
iLand = 10;
iLE = 2;
iLair = 2;
iDungeonLair = 2;
iDungeon = 16;
if (iAdventureType == 0)
iZones = Random(4)+1;
else
iZones = Random(2);
if (iAdventureType == 1)
DelayCommand(0.1f,SetCreatureTags(iLevel,1));
//iZones = 0;
ClearAdventureZones();
SetLocalInt(GetModule(),"AdventureZone",1);
SetLocalInt(GetModule(),"AdvZones",iZones + 2);
if (iAdventureType == 0)
SetupCampTypes(iLevel,1,1,0);
else
SetupCampTypes(iLevel,0,1,0);
if (sSpawn == "" || iAdventureType > 0)
sCampType = GetCampType();
else
sCampType = GetSpecificCampType(sSpawn);
oMod = GetModule();
iBase = GetLocalInt(oMod,"iBase");
iBaseStart = GetLocalInt(oMod,"iBaseStart");
iBaseMax = GetLocalInt(oMod,"iBaseMax");
iCampType = GetLocalInt(oMod,"iCampType");
sCD = GetLocalString(oMod,"sCD");
SetLocalInt(oMod,"iBase",0);
SetLocalInt(oMod,"iBaseStart",0);
SetLocalInt(oMod,"iBaseMax",0);
SetLocalInt(oMod,"iCampType",0);
iIndex = 1;
iIndexCheck = 1;
while (iIndex <= iZones)
{
iArea = Random(iLand)+1;
//iArea=1;
iFlag = GetHasAdvZone(iArea,iIndex,"Land");
if (iFlag == FALSE)
{
sArea = "Land" + IntToString(iArea);
//PopulateArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType);
DelayCommand(0.1f,PopArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType));
SetLocalString(GetModule(),"AZArea" + IntToString(iIndex),sArea);
iIndexCheck = 0;
iIndex++;
}
if (iFlag == TRUE && iIndexCheck > 12)
{
//SendMessageToPC(GetFirstPC(),"ForceNewArea");
iArea = 1;
while (GetHasAdvZone(iArea,iIndex,"Land") == TRUE)
iArea++;
sArea = "Land" + IntToString(iArea);
//PopulateArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType);
DelayCommand(0.1f,PopArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType));
SetLocalString(GetModule(),"AZArea" + IntToString(iIndex),sArea);
iIndexCheck = 0;
iIndex++;
}
iIndexCheck++;
}
//GetLocalString(GetModule(),"AZArea" + IntToString(iIndex)
if (iAdventureType == 0)
{
iArea = Random(iLE)+1;
sArea = "LE" + IntToString(iArea);
SetLocalString(GetModule(),"AZArea" + IntToString(iIndex),sArea);
//PopulateArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType);
DelayCommand(0.1f,PopArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType,FALSE));
iIndex++;
iArea = Random(iLair)+1;
sArea = "Lair" + IntToString(iArea);
SetLocalString(GetModule(),"AZArea" + IntToString(iIndex),sArea);
oBoss=PopulateArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType);
SetLocalString(oBoss,"sCD",sCD);
sTreasure = "Lair" + IntToString(iArea) + "_Treasure";
oChest = GetObjectByTag(sTreasure);
SetLocalInt(oChest,"EN4_DoOnce",0);
if (sItem != "")
CreateItemOnObject(sItem,oChest);
if (!GetIsObjectValid(oChest))
{
WriteTimestampedLogEntry("ERROR: Could not find lair chest : " + sTreasure);
if (sItem != "")
CreateItemOnObject(sItem,oBoss);
}
}
if (iAdventureType == 1)
{
iArea = Random(iLE)+1;
sArea = "LE" + IntToString(iArea);
SetLocalString(GetModule(),"AZArea" + IntToString(iIndex),sArea);
//PopulateArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType);
DelayCommand(0.1f,PopArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType,TRUE));
iIndex++;
//Get Dungeon Areas
iZones = Random(3)+2+iIndex;
//iZones = 2+iIndex;
iCampSize = Random(2)+1;
sCampType = "";
//iIndex = 1;
iIndexCheck = 1;
while (iIndex <= iZones)
{
if (sCampType == "")
{
if (iIndex < iZones-iCampSize)
sCampType = GetCampType();
else
{
SetupCampTypes(iLevel,1,1,0);
if (sSpawn == "")
sCampType = GetCampType();
else
sCampType = GetSpecificCampType(sSpawn);
}
iBase = GetLocalInt(oMod,"iBase");
iBaseStart = GetLocalInt(oMod,"iBaseStart");
iBaseMax = GetLocalInt(oMod,"iBaseMax");
iCampType = GetLocalInt(oMod,"iCampType");
sCD = GetLocalString(oMod,"sCD");
SetLocalInt(oMod,"iBase",0);
SetLocalInt(oMod,"iBaseStart",0);
SetLocalInt(oMod,"iBaseMax",0);
SetLocalInt(oMod,"iCampType",0);
}
if (Random(2)==0)
iBoss = TRUE;
else
iBoss = FALSE;
if (iIndex >= iZones-iCampSize)
iBoss = FALSE;
if (iIndex == iZones-iCampSize-1 && sCampType != sSpawn)
iBoss = TRUE;
iArea = Random(iDungeon)+1;
//iArea=15;
iFlag = GetHasAdvZone(iArea,iIndex,"DNG");
if (iFlag == FALSE)
{
sArea = "DNG" + IntToString(iArea);
//PopulateArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType);
DelayCommand(0.1f,PopArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType,iBoss,TRUE));
SetLocalString(GetModule(),"AZArea" + IntToString(iIndex),sArea);
if (iBoss == TRUE)
sCampType = "";
iIndexCheck = 0;
iIndex++;
}
if (iFlag == TRUE && iIndexCheck > 12)
{
//SendMessageToPC(GetFirstPC(),"ForceNewArea");
iArea = 1;
while (GetHasAdvZone(iArea,iIndex,"DNG") == TRUE)
iArea++;
sArea = "DNG" + IntToString(iArea);
//PopulateArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType);
DelayCommand(0.1f,PopArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType,iBoss,TRUE));
SetLocalString(GetModule(),"AZArea" + IntToString(iIndex),sArea);
if (iBoss == TRUE)
sCampType = "";
iIndexCheck = 0;
iIndex++;
}
iIndexCheck++;
}
//Get Dungeon Lair
//iIndex++;
iArea = Random(iDungeonLair)+1;
//iArea = 2;
sArea = "DL" + IntToString(iArea);
SetLocalString(GetModule(),"AZArea" + IntToString(iIndex),sArea);
oBoss=PopulateArea(sArea,sCampType,0,iLevel,iBase,iBaseStart,iBaseMax,iCampType);
SetLocalString(oBoss,"sCD",sCD);
sTreasure = "DL" + IntToString(iArea) + "_Treasure";
oChest = GetObjectByTag(sTreasure);
SetLocalInt(oChest,"EN4_DoOnce",0);
if (sItem != "")
CreateItemOnObject(sItem,oChest);
if (!GetIsObjectValid(oChest))
{
WriteTimestampedLogEntry("ERROR: Could not find lair chest : " + sTreasure);
if (sItem != "")
CreateItemOnObject(sItem,oBoss);
}
}
iAreas = iIndex;
iIndex = 1;
while (iIndex <= iAreas)
{
if (iIndex > 1)
sAreas=sAreas + " - ";
sAreas = sAreas + GetLocalString(GetModule(),"AZArea" + IntToString(iIndex));
iIndex ++;
}
WriteTimestampedLogEntry("Random Area Generated: " + sAreas);
return oBoss;
}
int GetHasAdvZone(int iArea, int iZones,string sPrefix)
{
int iResult;
int iIndex;
iResult = FALSE;
iIndex = 1;
while (iIndex <= iZones)
{
//SendMessageToPC(GetFirstPC(),"Compare1 : Land" + IntToString(iArea));
//SendMessageToPC(GetFirstPC(),"Compare2 : " + GetLocalString(GetModule(),"AZArea" + IntToString(iIndex)));
if (sPrefix + IntToString(iArea) == GetLocalString(GetModule(),"AZArea" + IntToString(iIndex)))
iResult = TRUE;
iIndex++;
}
return iResult;
}
void ClearAdventureZones()
{
int iIndex;
int iZones;
iZones = GetLocalInt(GetModule(),"AdvZones");
iIndex = 1;
while (iIndex <= iZones)
{
SetLocalString(GetModule(),"AZArea" + IntToString(iIndex),"");
iIndex++;
}
}
void ZoneToArea(object oPC,int iArea)
{
int iOldArea;
string sZone;
string sTagMod;
object oEnter;
location lLoc;
iOldArea = GetLocalInt(oPC,"AZCurrentArea");
if (iOldArea < iArea)
sTagMod = "_Enter";
else
sTagMod = "_Exit";
SetLocalInt(oPC,"AZCurrentArea",iArea);
if (iArea>0)
{
sZone = GetLocalString(GetModule(),"AZArea" + IntToString(iArea));
sZone = sZone + sTagMod;
} else {
sZone = GetLocalString(oPC,"AZRespawn");
}
oEnter = GetObjectByTag(sZone);
if (GetIsObjectValid(oEnter))
{
lLoc = GetLocation(oEnter);
AssignCommand(oPC,JumpToLocation(lLoc));
} else {
SendMessageToPC(oPC,"ERROR: Cannot Find Zone Waypoint " + sZone + ".");
}
}
void PopArea(string sArea,string sCampType,int iSpawnType, int iLevel, int iBase,int iBaseStart,int iBaseMax,int iCampType, int iBoss = TRUE,int iWander = FALSE)
{
PopulateArea(sArea,sCampType,iSpawnType,iLevel,iBase,iBaseStart,iBaseMax,iCampType,iBoss,iWander);
}
object PopulateArea(string sArea,string sCampType,int iSpawnType, int iLevel, int iBase,int iBaseStart,int iBaseMax,int iCampType, int iBoss = TRUE,int iWander = FALSE)
{
int iIndex;
int iType;
int iRandom;
int iHardCore;
int iSpawn;
int iSpawnNumber;
string sWP;
object oWP;
object oCreature;
ClearArea(sArea);
iHardCore = CheckHardcore();
iIndex = 1;
sWP = sArea + "_" + IntToString(iIndex);
oWP = GetObjectByTag(sWP);
while (GetIsObjectValid(oWP))
{
//oCreature = GetCampMob(iSpawnType,sWP,sCampType,iLevel,iBaseStart,iBase,iBaseMax,iCampType);
if (iSpawnType > 0)
iType = iSpawnType;
else {
iRandom = Random(10);
if (iRandom < 6)
iType = 1;
else if (iRandom < 9)
iType = 2;
else
iType = 3;
}
iSpawn = TRUE;
if (iHardCore)
{
if (iLevel < 5)
iRandom = Random(3);
else if (iLevel < 10)
iRandom = Random(4);
else if (iLevel < 15)
iRandom = Random(5);
if (iRandom == 0)
iSpawn = FALSE;
}
if (Random(12)==0 && iWander == TRUE)
{
iSpawn = FALSE;
DelayCommand(1.0f,SpawnMob(sWP));
}
if (iSpawn)
{
iSpawnNumber = 1;
if (iLevel>10 && iLevel < 20 && iHardCore == FALSE)
{
if (Random(4) == 0)
iSpawnNumber = 2;
}
if (iLevel>19 && iHardCore == FALSE)
{
iSpawnNumber = Random(3)+1;
if (iType == 3 && iSpawnNumber == 3)
iSpawnNumber = 2;
}
if (iLevel>19 && iHardCore == TRUE)
{
if (Random(4) == 0)
iSpawnNumber = 2;
}
DelayCommand(0.2f,SpawnCampMob(iType,sWP,sCampType,iLevel,iBaseStart,iBase,iBaseMax,iCampType));
if (iSpawnNumber > 1)
DelayCommand(0.2f,SpawnCampMob(iType,sWP,sCampType,iLevel,iBaseStart,iBase,iBaseMax,iCampType,1,1));
if (iSpawnNumber > 2)
DelayCommand(0.2f,SpawnCampMob(iType,sWP,sCampType,iLevel,iBaseStart,iBase,iBaseMax,iCampType,1,2));
}
iIndex++;
sWP = sArea + "_" + IntToString(iIndex);
oWP = GetObjectByTag(sWP);
}
if (iBoss == TRUE)
{
sWP = sArea + "_Boss";
oWP = GetObjectByTag(sWP);
if (GetIsObjectValid(oWP))
{
oCreature = GetCampMob(99,sWP,sCampType,iLevel,iBaseStart,iBase,iBaseMax,iCampType);
iType = Random(2)+2;
iSpawnNumber = 1;
if (iLevel>10 && iLevel < 20 && iHardCore == FALSE)
{
if (Random(4) == 0)
iSpawnNumber = 2;
}
if (iLevel>19 && iHardCore == FALSE)
{
iSpawnNumber = Random(3)+1;
if (iType == 3 && iSpawnNumber == 3)
iSpawnNumber = 2;
}
if (iLevel>19 && iHardCore == TRUE)
{
if (Random(4) == 0)
iSpawnNumber = 2;
}
if (iSpawnNumber > 1)
DelayCommand(0.2f,SpawnCampMob(iType,sWP,sCampType,iLevel,iBaseStart,iBase,iBaseMax,iCampType,1,1));
if (iSpawnNumber > 2)
DelayCommand(0.2f,SpawnCampMob(iType,sWP,sCampType,iLevel,iBaseStart,iBase,iBaseMax,iCampType,1,2));
}
}
return oCreature;
}
void ClearArea(string sArea)
{
int iIndex;
object oWaypoint;
object oCreature;
object oArea;
iIndex = 1;
oWaypoint = GetObjectByTag(sArea + "_" + IntToString(iIndex));
while (GetIsObjectValid(oWaypoint))
{
oCreature = GetObjectByTag(sArea + "_" + IntToString(iIndex) + "_S");
if (GetIsObjectValid(oCreature))
{
AssignCommand(oCreature,SetIsDestroyable(TRUE));
DestroyObject(oCreature,0.5);
}
oCreature = GetObjectByTag(sArea + "_" + IntToString(iIndex) + "_S1");
if (GetIsObjectValid(oCreature))
{
AssignCommand(oCreature,SetIsDestroyable(TRUE));
DestroyObject(oCreature,0.5);
}
oCreature = GetObjectByTag(sArea + "_" + IntToString(iIndex) + "_S2");
if (GetIsObjectValid(oCreature))
{
AssignCommand(oCreature,SetIsDestroyable(TRUE));
DestroyObject(oCreature,0.5);
}
iIndex++;
oWaypoint = GetObjectByTag(sArea + "_" + IntToString(iIndex));
}
oCreature = GetObjectByTag(sArea + "_Boss_S");
if (GetIsObjectValid(oCreature))
{
AssignCommand(oCreature,SetIsDestroyable(TRUE));
DestroyObject(oCreature,0.5);
}
oCreature = GetObjectByTag(sArea + "_Boss_S1");
if (GetIsObjectValid(oCreature))
{
AssignCommand(oCreature,SetIsDestroyable(TRUE));
DestroyObject(oCreature,0.5);
}
oCreature = GetObjectByTag(sArea + "_Boss_S2");
if (GetIsObjectValid(oCreature))
{
AssignCommand(oCreature,SetIsDestroyable(TRUE));
DestroyObject(oCreature,0.5);
}
oWaypoint = GetObjectByTag(sArea + "_Enter");
oArea = GetArea(oWaypoint);
DelayCommand(0.5f,RemoveLootFromAdvArea(oArea));
}
void RemoveLootFromAdvArea(object oArea)
{
object oItem;
oItem = GetFirstObjectInArea(oArea);
while (GetIsObjectValid(oItem))
{
if (GetName(oItem) == "Remains")
{
RemoveLootFromRemains(oItem);
DestroyObject(oItem);
}
oItem = GetNextObjectInArea(oArea);
}
}
void RemoveLootFromRemains(object oContainer)
{
object oItem;
object oLastItem;
int iFlag;
int iDeleteFlag;
iFlag = 0;
oItem = GetFirstItemInInventory(oContainer);
while (iFlag == 0)
{
DestroyObject(oItem);
oLastItem = oItem;
oItem = GetNextItemInInventory(oContainer);
if (oLastItem == oItem)
iFlag = 1;
}
}
int AZDifficulty()
{
int iZones;
int iDifficulty;
iZones = GetLocalInt(GetModule(),"AdvZones");
if (iZones < 3)
iDifficulty = 2;
else if (iZones < 5)
iDifficulty = 3;
else
iDifficulty = 4;
return iDifficulty;
}