Scriptname s7oSOS01actiSuiteMasterSCRIPT extends ObjectReference Conditional
import Debug
import Utility
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; - - - - - - - - - - - - - - - - - - - - - - - - - - P R O P E R T I E S - - - - - - - - - - - - - - - - - - - - - - - - - -
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Actor [] Property SuiteUsersLocal Auto
Actor Property PlayerRef Auto
Actor Property Innkeeper Auto
Faction Property SuiteFactionLocal Auto
Faction Property SuiteGuests Auto
Key Property SuiteKeyLocal Auto
MiscObject Property Gold Auto
Quest Property AUXinnkeeperFinder Auto
Keyword Property WIRentRoomWalkToStart Auto
s7oSOS01questSuitesMasterSCRIPT Property SOS01masterSCRIPT Auto
QF_s7oSOS01questAux00innkeeperFinder Property AuxInnkeeperFinderSCRIPT Auto
ObjectReference Property SelfRef Auto Hidden
ObjectReference Property SuiteService Auto Hidden
ObjectReference Property DoorMaster Auto Hidden ;;;;; linked from suite master
ObjectReference Property SuiteSpot Auto Hidden ;;;;; linked from door master
Location Property SuiteLocation Auto Hidden
Bool Property Rented Auto Hidden Conditional
Bool Property RentOverdueLocked Auto Hidden Conditional
Bool Property BusyFinder = false Auto Hidden
Bool Property Busy = false Auto Hidden
Bool Property RentDue = false Auto Hidden
Bool Property RentOverdue = false Auto Hidden
Bool Property RentWarning = false Auto Hidden
Bool Property Update20 Auto Hidden
Float Property RentTime Auto Hidden
Int Property SuiteRentDue Auto Hidden
Int Property SuiteRentLocal = 300 Auto
Bool Property NoRentRoom = false Auto
Int Counter = 0
Int CounterAux = 0
Bool SelfInit
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - E V E N T S - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event OnCellLoad ()
if ( InitSelf () && InitInnkeeper ( None ) )
WelcomeHome ()
endif
endEvent
Event OnCellDetach ()
if BusyFinder
if AuxInnkeeperFinder.IsRunning ()
AuxInnkeeperFinder. Stop ()
AuxInnkeeperFinder. Reset ()
endif
BusyFinder = false
endif
endEvent
Event OnUpdateGameTime () ;;;;; check if rent due, if not repeat next day
UnregisterForUpdateGameTime ()
if ProcessSuiteRentDue ()
if !RentDue
RegisterForSingleUpdateGameTime ( 24 )
endif
endif
endEvent
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; - - - - - - - - - - - - - - - - - - - - - - - - - - - F U N C T I O N S - - - - - - - - - - - - - - - - - - - - - - - - - - -
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function WelcomeHome () ;;;;; will also be called by suite scout (if present)
While Busy
Wait ( 0.1 )
endWhile
if CheckDue ()
Busy = true
if RentDue
SOS01masterSCRIPT. UpdateRentGlobal ( SuiteRentDue )
if RentWarning
if Rented
if RentOverdueLocked
Notification ( "Rent overdue - Suite locked." )
elseif RentOverdue
Notification ( "Your rent is overdue." )
elseif RentDue
Notification ( "Your rent is due." )
endif
else
Notification ( "You owe the Innkeeper " + SuiteRentDue + " gold." )
endif
RentWarning = false
endif
else
if Rented
SOS01masterSCRIPT. UpdateRentGlobal ( SuiteRentDue )
else
SOS01masterSCRIPT. UpdateRentGlobal ( SuiteRentLocal )
endif
endif
SOS01masterSCRIPT. UpdateSuiteDataLocal ( SelfRef, Innkeeper, true, Rented, RentDue, RentOverdue, RentOverdueLocked )
CheckInnkeeperNoRentRoom ()
Busy = false
endif
endFunction
Bool Function InitSelf ()
if !SelfInit
SelfInit = true
CheckUpdate20 ()
SelfRef = ( Self as ObjectReference )
SetFactionOwner ( SuiteFactionLocal )
SuiteLocation = ( GetCurrentLocation () as Location )
DoorMaster = ( GetNthLinkedRef ( 1 ) as ObjectReference )
SuiteSpot = ( GetNthLinkedRef ( 2 ) as ObjectReference )
if ( !Innkeeper || Innkeeper.IsDead () )
InitInnkeeper ( None )
else
ResetSuiteUsers ()
endif
endif
Return SelfInit
endFunction
Bool Function InitInnkeeper ( Actor ThisInnkeeper = None )
While BusyFinder
Wait ( 0.1 )
endWhile
if ( !ThisInnkeeper && ( Innkeeper && !Innkeeper.IsDead () ) )
CheckInnkeeperNoRentRoom ()
Return true
else
if ThisInnkeeper
Innkeeper = ThisInnkeeper
ThisInnkeeper = None
else
BusyFinder = true
Innkeeper = None
AuxInnkeeperFinder. Stop ()
AuxInnkeeperFinder. Reset ()
AuxInnkeeperFinder. Start ()
AuxInnkeeperFinderSCRIPT. SuiteMasterLocal = SelfRef
While BusyFinder ;;;;; waits for finder quest to finish
Wait ( 0.1 )
endWhile
endif
if Innkeeper
Innkeeper. SetFactionRank ( SuiteFactionLocal, 1 )
Innkeeper. SetFactionRank ( SuiteGuests, 1 )
if ( SuiteKeyLocal && ( Innkeeper.GetItemCount ( SuiteKeyLocal ) <= 0 ) )
Innkeeper. AddItem ( SuiteKeyLocal, 1 )
endif
CheckInnkeeperNoRentRoom ()
ResetSuiteUsers ()
Return true
else
Return false
endif
endif
endFunction
Function CheckInnkeeperNoRentRoom ()
if ( ( NoRentRoom && Innkeeper ) && ( Innkeeper.GetActorValue ( "Variable09" ) == 0 ) )
Innkeeper.SetActorValue ( "Variable09", -1 ) ;;;;; "variable 09" -1 prevents "rent room" dialogue for non-vanilla innkeepers
endif
endFunction
Function RentSuite ()
While Busy
Wait ( 0.1 )
endWhile
Busy = true
if ( RentTime == 0 )
WIRentRoomWalkToStart. SendStoryEvent ( SuiteLocation, Innkeeper, SuiteSpot )
endif
RentTime = GetCurrentGameTime ()
Rented = true
RegisterForSingleUpdateGameTime ( 8736 )
if ( PlayerRef.GetItemCount ( SuiteKeyLocal ) <= 0 )
PlayerRef. AddItem ( SuiteKeyLocal, 1, false )
endif
PlayerRef. AddToFaction ( SuiteFactionLocal )
PlayerRef. SetFactionRank ( SuiteFactionLocal, 2 )
PlayerRef. RemoveItem ( Gold, SuiteRentLocal, false, Innkeeper )
SOS01masterSCRIPT. FlashObjective ( 10 )
SOS01masterSCRIPT. UpdateSuiteDataLocal ( SelfRef, Innkeeper, true, Rented, RentDue, RentOverdue, RentOverdueLocked )
SOS01masterSCRIPT. UpdateRentGlobal ( 0 )
Doormaster. EnableNoWait ( false )
SuiteService. BlockActivation ( false )
Innkeeper. SetActorValue ( "Variable09", 2.0 )
Busy = false
endFunction
Function UnrentSuite ()
While Busy
Wait ( 0.1 )
endWhile
Busy = true
Rented = false
if ProcessSuiteRentDue ()
SuiteRentDue -= SuiteRentLocal
if ( SuiteRentDue <= 0 )
if ( SuiteRentDue < 0 )
PlayerRef. AddItem ( Gold, -SuiteRentDue, false )
SuiteRentDue = 0
endif
SOS01masterSCRIPT. UpdateRentGlobal ( SuiteRentLocal )
UnlockSuite ()
else
SOS01masterSCRIPT. UpdateRentGlobal ( SuiteRentDue )
endif
endif
PlayerRef. RemoveItem ( SuiteKeyLocal, PlayerRef.GetItemCount ( SuiteKeyLocal ), false )
SOS01masterSCRIPT. FlashObjective ( 9 )
SOS01masterSCRIPT. UpdateSuiteDataLocal ( SelfRef, Innkeeper, true, Rented, RentDue, RentOverdue, RentOverdueLocked )
ResetSuite ()
Busy = false
endFunction
Function PayRent ()
if Rented
UnregisterForUpdateGameTime ()
if ProcessSuiteRentDue ()
RentTime = GetCurrentGameTime ()
SOS01masterSCRIPT. UpdateRentGlobal ( 0 )
RegisterForSingleUpdateGameTime ( 8736 )
endif
else
SOS01masterSCRIPT. UpdateRentGlobal ( SuiteRentLocal )
endif
UnlockSuite ()
SOS01masterSCRIPT. UpdateSuiteDataLocal ( SelfRef, Innkeeper, true, Rented, RentDue, RentOverdue, RentOverdueLocked )
PlayerRef. RemoveItem ( Gold, SuiteRentDue, false, Innkeeper )
endFunction
Bool Function ProcessSuiteRentDue ()
if ( RentTime > 0 )
SuiteRentDue = ( ( ( SuiteRentLocal / 364 ) * ( GetCurrentGameTime () - RentTime ) as Int ) )
if ( SuiteRentDue >= SuiteRentLocal )
RentDue = true
endif
endif
Return true
endFunction
Bool Function CheckDue ()
if Rented
ProcessSuiteRentDue ()
endif
if ( !RentDue && ( SuiteRentDue > SuiteRentLocal ) )
RentDue = true
RentWarning = true
elseif RentDue
if ( !RentOverdue && ( SuiteRentDue > ( SuiteRentLocal * 1.5 ) ) )
RentOverdue = true
RentWarning = true
elseif RentOverdue
if ( !RentOverdueLocked && ( SuiteRentDue > ( SuiteRentLocal * 2 ) ) )
RentoverdueLocked = true
RentWarning = true
LockSuite ()
elseif RentOverdueLocked
RentWarning = true
endif
endif
endif
Return true
endFunction
Function CheckStuffOut ()
if RentOverdueLocked
DoorMaster. DisableNoWait ()
PlayerRef. SetFactionRank ( SuiteFactionLocal, -1 )
endif
endFunction
Function StuffOut ()
PlayerRef. SetFactionRank ( SuiteFactionLocal, 2 )
DoorMaster. EnableNoWait ()
endFunction
Function UnlockSuite ()
if Rented
PlayerRef. SetFactionRank ( SuiteFactionLocal, 2 )
else
PlayerRef. RemoveFromFaction ( SuiteFactionLocal )
ResetSuite ()
endif
SuiteService. BlockActivation ( false )
DoorMaster. EnableNoWait ()
RentDue = false
RentOverdue = false
RentOverdueLocked = false
RentWarning = false
SuiteRentDue = 0
endFunction
Function LockSuite ()
PlayerRef. SetFactionRank ( SuiteFactionLocal, -1 )
SuiteService. BlockActivation ( true )
DoorMaster. DisableNoWait ()
endFunction
Function ResetSuite ()
Innkeeper. SetActorValue ( "Variable09", ( 0 - ( NoRentRoom as Float ) ) ) ;;;;; "variable 09" -1 prevents "rent room" dialogue for non-vanilla innkeepers
RentTime = 0.0
ResetSuiteUsers ()
endFunction
Function ResetSuiteUsers ()
While Busy
Wait ( 0.1 )
endWhile
Busy = true
Counter = SuiteUsersLocal.Length
CounterAux = -1
Actor SuiteUserTemp = None
While ( Counter > 0 )
Counter -= 1
SuiteUserTemp = SuiteUsersLocal [ Counter ]
if ( SuiteUserTemp && ( ( SuiteUserTemp as Actor ) && !SuiteUserTemp.IsDead () ) )
ResetSuiteUser ( SuiteUserTemp )
if ( Innkeeper && ( SuiteUserTemp == Innkeeper ) )
CounterAux = Counter
endif
elseif ( CounterAux == -1 )
CounterAux = Counter
endif
SuiteUserTemp = None
endWhile
if ( Innkeeper && ( ( CounterAux > -1 ) && ( CounterAux < SuiteUsersLocal.Length ) ) )
SuiteUsersLocal [ CounterAux ] = Innkeeper
endif
Busy = false
endFunction
Function ResetSuiteUser ( Actor ResetMe )
ResetMe. SetFactionRank ( SuiteFactionLocal, 1 )
ResetMe. SetFactionRank ( SuiteGuests, 1 )
Int SuiteKeyCount = ResetMe.GetItemCount ( SuiteKeyLocal )
if ( SuiteKeyCount <= 0 )
ResetMe. AddItem ( SuiteKeyLocal, 1 )
else
ResetMe. RemoveItem ( SuiteKeyLocal, ( SuiteKeyCount - 1 ) )
endif
endFunction
Function CheckUpdate20 ()
if !Update20
While Busy
Wait ( 0.1 )
endWhile
Busy = true
if PlayerRef.IsInFaction ( SuiteFactionLocal )
Rented = true
endif
if ( Innkeeper && ( Innkeeper.GetActorValue ( "Variable09" ) > 2 ) )
Innkeeper. SetActorValue ( "Variable09", ( 2 * ( Rented as Float ) ) )
endif
Update20 = true
Busy = false
endif
endFunction