Code:
Group Common
Actor Property Player Auto Const Mandatory
WorkShopScript Property MyWorkShop Auto Const Mandatory
GlobalVariable Property GameDaysPassed Auto Const Mandatory
GlobalVariable Property GameHour Auto Const Mandatory
EndGroup
Group Unlock
Bool Property UnlockWhenCleared = true Auto Const
ObjectReference[] Property ActorRefsToKill Auto Const Mandatory
Quest[] Property QuestsToComplete Auto Const Mandatory
EndGroup
Group Annoyance
Float Property AnnoyanceIntervalDays = 0.3 Auto Const
ActorBase[] Property AnnoyanceActors Auto Const
ObjectReference[] Property AnnoyanceMarker Auto Const Mandatory
EndGroup
Group Enemies
Float Property EnemyIntervalDays = 1.5 Auto Const
ActorBase[] Property EnemyActorsBoss Auto Const
ActorBase[] Property EnemyActorsKnight Auto Const
ActorBase[] Property EnemyActorsGeneral Auto Const
ActorBase[] Property EnemyActorsPet Auto Const
ObjectReference[] Property SpawnEnemyMarker Auto Const
EndGroup
bool sysInitialized = false
bool workShopInitialized = false
float sysInterval = 60.0
int updateTimerId = 1
float updateInterval = 0.1
int annoyanceTimerId = 2
float minAnnoyanceDay = 0.2
float maxAnnoyanceDay = 0.5
float annoyanceDay = 0.0
int attackTimerId = 3
float minAttackDay = 1.5
float maxAttackDay = 3.0
float attackDay = 0.0
bool actorRefsKilled = false
bool questsCompleted = false
bool locationCleared = false
Event OnLoad()
DebugTrace("Workshop Controller loaded")
if sysInitialized == false
sysInitialized = true
DebugTrace("Workshop Controller initialized")
MonitorWorkshop()
endif
if workShopInitialized == true
; Do something
endif
EndEvent
Event OnTimer(int aiTimerID)
MonitorWorkshop()
EndEvent
Event OnTimerGameTime(int aiTimerID)
if aiTimerId == updateTimerId
UpdateWorkshop()
elseif aiTimerId == annoyanceTimerId
SpawnAnnoyance()
elseif aiTimerId == attackTimerId
SpawnEnemy()
endif
EndEvent
; Monitor workshop location until all conditions are met
Function MonitorWorkshop()
if workShopInitialized == false && WorkshopCanBeInitialized()
DebugTrace("Workshop unlocked")
workShopInitialized = true
StartTimerGameTime(updateInterval, updateTimerId)
StartTimerGameTime(Utility.RandomFloat(minAnnoyanceDay, maxAnnoyanceDay), annoyanceTimerId)
StartTimerGameTime(Utility.RandomFloat(minAttackDay, maxAttackDay), attackTimerId)
else
StartTimer(sysInterval)
endif
EndFunction
Function UpdateWorkshop()
; Do something
StartTimerGameTime(updateInterval, updateTimerId)
EndFunction
Function SpawnAnnoyance()
debugTrace("Annoyance spawned")
if AnnoyanceActors.Length > 0
int spawnType = 0
if AnnoyanceActors.Length > 1
spawnType = Utility.RandomInt(0, AnnoyanceActors.Length - 1)
endif
ObjectReference spawnedActor
ObjectReference spawnMarker = GetSpawnMarker()
spawnedActor = spawnMarker.PlaceAtMe(AnnoyanceActors[spawnType], 1)
spawnedActor.SetLinkedRef(self)
endif
StartTimerGameTime(Utility.RandomFloat(minAnnoyanceDay, maxAnnoyanceDay), annoyanceTimerId)
EndFunction
Function SpawnEnemy()
debugTrace("Enemies spawned")
; To Do
StartTimerGameTime(Utility.RandomFloat(minAttackDay, maxAttackDay), attackTimerId)
EndFunction
Bool Function PlayerIsNearby()
bool nearBy = GetDistance(Game.GetPlayer()) < 2500
return nearBy
EndFunction
Bool Function WorkshopCanBeInitialized()
if actorRefsKilled == false
if ActorRefsToKill.Length > 0
int killCount = 0
while (c < ActorRefsToKill.Length)
if (ActorRefsToKill[c] as Actor).IsDead()
killCount += 1
endif
c += 1
endwhile
if killCount == ActorRefsToKill.Length
DebugTrace("All actors killed")
actorRefsKilled = true
endif
else
DebugTrace("No actor to kill")
actorRefsKilled = true
endif
endif
if questsCompleted == false
if QuestsToComplete.Length > 0
int questCount = 0
while (c < QuestsToComplete.Length)
if QuestsToComplete[c].IsCompleted()
questCount += 1
endif
c += 1
endwhile
if questCount == QuestsToComplete.Length
DebugTrace("All quests completed")
questsCompleted = true
endif
else
DebugTrace("No quest to complete")
questsCompleted = true
endif
endif
if UnlockWhenCleared
if GetCurrentLocation().IsCleared()
DebugTrace("Location cleared")
locationCleared = true
endif
else
DebugTrace("No location to clear")
locationCleared = true
endif
if actorRefsKilled && questsCompleted && locationCleared
DebugTrace("All quests completed, all actors killed, location cleared")
return true
else
return false
endif
EndFunction
ObjectReference Function GetSpawnMarker()
int c = 0
float highestDistance = 0
ObjectReference spawnMarker
while (c < SpawnMarkerList.Length)
if SpawnMarkerList[c].GetDistance(Game.GetPlayer()) > highestDistance
highestDistance = SpawnMarkerList[c].GetDistance(Game.GetPlayer())
spawnMarker = SpawnMarkerList[c]
endif
c += 1
endwhile
return spawnMarker
EndFunction
Function DebugTrace(string text)
Debug.Trace("THEW DEBUG - Workshop Controller - Workshop: " + MyWorkShop + " - " + text)
EndFunction