enderalse/scripts/source/_00e_playerhousingmaster.psc

247 lines
8.7 KiB
Plaintext

scriptname _00E_PlayerhousingMaster extends Quest
EffectShader Property shaderActive Auto
{Shader that is applied while the object is being manipulated}
Actor Property player Auto
GlobalVariable Property continueTranslateToPlayerLoop Auto
{Controls the translateTo player loop while being in Translation mode. This variable is used to communicate with _00E_PlayerhousingCurrentOTranslation}
ReferenceAlias Property currentHousingObjectInTranslation Auto
ReferenceAlias Property currentHousingObjectInManipulation Auto
Message Property cannotPlaceObjectHere auto
_00E_Playerhousing_Furniture currentHousingObject
float timeToHoldActivateToFinish = 2.0
Event onBeginState()
currentHousingObject = None ; prevent persistence
EndEvent
bool function canPlaceItem()
return false
Endfunction
Event onControlUp(String control, float holdTime)
if holdTime > timeToHoldActivateToFinish
activateLongPressed()
else
activatePressed()
Endif
EndEvent
function enableBuildmode()
{Enables the player to choose housing objects for manipulation or translation; should be called when the player enters one of his houses}
((Self as Quest) as _00E_PlayerhousingTutorial).onStartBuildmode()
GoToState("Buildmode")
ENDfunction
function playerItemDropped(_00E_Playerhousing_FurnitureItem akItemReference)
{Tests if this item drop by the player triggers an entering into buildmode and performs this change if necessary}
ENDfunction
function enterBuildmode()
{Enables the player to translate the current housing object and change to manipulation mode}
GoToState("Translation")
ENDfunction
function toggleMode()
{Switches between tranlation and manipulation buildmode}
ENDfunction
function leaveBuildmode()
{Disables the player to translate or manipulate a housing object; the player can still enter buildmode again}
ENDfunction
function disableBuildmode()
{Disables the player to enter buildmode}
ENDfunction
function activatePressed()
{updates the buildmode as necessary when the activation control has been pressed}
Endfunction
function activateLongPressed()
{updates the buildmode as necessary when the activation control has been pressed long}
Endfunction
function translateCurrentHousingObjectLoop()
{translates the current housing object before the player in a recursive loop}
ENDfunction
function pickUp()
{deletes the current housing object and adds the appropriate item to the player's inventory}
Player.addItem(currentHousingObject.getFurnitureItem().getBaseObject(), 1)
currentHousingObject.disable()
currentHousingObject.delete()
Endfunction
;==================================================================== STATE Buildmode ===================================================================================================
STATE Buildmode
;the player can enter the manipulation or translation mode by choosing a housing object or dropping a housing item
Event onBeginState()
currentHousingObject = None ; prevent persistence
RegisterForControl("activate")
EndEvent
bool function canPlaceItem()
return True
Endfunction
Event onEndState()
unRegisterForControl("activate")
EndEvent
function playerItemDropped(_00E_Playerhousing_FurnitureItem akItemReference)
{Tests if this item drop by the player triggers an entering into buildmode and performs this change if necessary}
currentHousingObject = akItemReference.placeFurnitureAtMe()
akItemReference.delete()
GoToState("Translation")
ENDfunction
function activateLongPressed()
{updates the buildmode as necessary when the activation control has been pressed long}
ObjectReference targetRef = Game.GetCurrentCrosshairRef()
if targetRef as _00E_Playerhousing_Furniture
currentHousingObject = targetRef as _00E_Playerhousing_Furniture
GoToState("Translation")
Endif
Endfunction
function activatePressed()
{updates the buildmode as necessary when the activation control has been pressed}
ObjectReference targetRef = Game.GetCurrentCrosshairRef()
if !(targetRef as _00E_Phasmalist_Workbench) && (targetRef as _00E_Playerhousing_Furniture) && (targetRef as _00E_Playerhousing_Furniture).shouldActivateBePossible()
targetRef.activate(player, true)
Endif
Endfunction
function disableBuildmode()
{Disables the player to enter buildmode}
GoToState("null")
ENDfunction
ENDSTATE
;==================================================================== STATE Translation ===================================================================================================
STATE Translation
;the selected housing object is moved with the player
Event onBeginState()
Game.DisablePlayerControls(abMovement = false, abFighting = true, abCamSwitch = false, abLooking = false, abSneaking = false, abMenu = false, abActivate = true)
((Self as Quest) as _00E_PlayerhousingTutorial).onTranslationMode()
continueTranslateToPlayerLoop.setValue(1)
currentHousingObjectInTranslation.forceRefTo(currentHousingObject)
currentHousingObject.disable()
currentHousingObject.enable() ;disable - enable reloads the 3d so onLoad of the object is invoked; this will start the translateToPlayer-loop
RegisterForControl("activate")
while !currentHousingObject.is3DLoaded()
Utility.wait(0.1)
Endwhile
shaderActive.Play(currentHousingObject)
EndEvent
Event onEndState()
shaderActive.Stop(currentHousingObject)
continueTranslateToPlayerLoop.setValue(0)
currentHousingObjectInTranslation.clear()
unRegisterForControl("activate")
Game.EnablePlayerControls(abMovement = true, abFighting = true, abCamSwitch = true, abLooking = true, abSneaking = true, abMenu = true, abActivate = true)
EndEvent
function activatePressed()
{updates the buildmode as necessary when the activation control has been pressed}
toggleMode()
Endfunction
function activateLongPressed()
{updates the buildmode as necessary when the activation control has been pressed long}
pickUp()
leaveBuildmode()
Endfunction
function toggleMode()
{Switches between tranlation and manipulation buildmode}
GoToState("Manipulation")
ENDfunction
function disableBuildmode()
{Disables the player to enter buildmode}
GoToState("null")
ENDfunction
function leaveBuildmode()
{Disables the player to translate or manipulate a housing object; the player can still enter buildmode again}
GoToState("Buildmode")
ENDfunction
ENDSTATE
;==================================================================== STATE Manipulation ===================================================================================================
STATE Manipulation
;the player can change orientation or height of the selected housing object by using the keys
Event onBeginState()
Game.DisablePlayerControls(abMovement = false, abFighting = true, abCamSwitch = false, abLooking = false, abSneaking = false, abMenu = false, abActivate = true)
Game.SetPlayerAIDriven(True)
((Self as Quest) as _00E_PlayerhousingTutorial).onManipulationMode()
currentHousingObjectInManipulation.forceRefTo(currentHousingObject)
currentHousingObjectInManipulation.RegisterForControl("forward")
currentHousingObjectInManipulation.RegisterForControl("back")
currentHousingObjectInManipulation.RegisterForControl("strafe left")
currentHousingObjectInManipulation.RegisterForControl("strafe right")
RegisterForControl("activate")
;we do not have to wait until the 3d is loaded since the manipulation mode is only entered from the translation mode
shaderActive.Play(currentHousingObject)
EndEvent
Event onEndState()
shaderActive.Stop(currentHousingObject)
unRegisterForControl("activate")
currentHousingObjectInManipulation.unRegisterForControl("forward")
currentHousingObjectInManipulation.unRegisterForControl("back")
currentHousingObjectInManipulation.unRegisterForControl("strafe left")
currentHousingObjectInManipulation.unRegisterForControl("strafe right")
currentHousingObjectInManipulation.clear()
Game.SetPlayerAIDriven(False)
Game.EnablePlayerControls(abMovement = true, abFighting = true, abCamSwitch = true, abLooking = true, abSneaking = true, abMenu = true, abActivate = true)
EndEvent
function activatePressed()
{updates the buildmode as necessary when the activation control has been pressed}
toggleMode()
Endfunction
function activateLongPressed()
{updates the buildmode as necessary when the activation control has been pressed long}
currentHousingObject.finishPlacement()
leaveBuildmode()
Endfunction
function toggleMode()
{Switches between tranlation and manipulation buildmode}
GoToState("Translation")
ENDfunction
function disableBuildmode()
{Disables the player to enter buildmode}
GoToState("null")
ENDfunction
function leaveBuildmode()
{Disables the player to translate or manipulate a housing object; the player can still enter buildmode again}
GoToState("Buildmode")
ENDfunction
ENDSTATE