enderalse/source/scripts/_sag_dicesgame_mainscript.psc

188 lines
5.4 KiB
Plaintext
Raw Normal View History

Scriptname _SAG_DicesGame_MainScript extends Quest
Message Property PlaceYourBet Auto
String s_chargeninitialtext
GlobalVariable Property _SAG_ProphDiceLostGames Auto
GlobalVariable Property _SAG_ProphDiceWonGames Auto
GlobalVariable Property _SAG_ProphDiceLostGold Auto
GlobalVariable Property _SAG_ProphDiceWonGold Auto
GlobalVariable Property _00E_AchievementsEnabled Auto
Actor Property Commentator Auto
ReferenceAlias Property Opponent Auto
Actor Property PlayerRef Auto
ObjectReference[] Property PlayerDicesLeft Auto
ObjectReference[] Property OpponentDicesLeft Auto
ObjectReference[] Property PlayerDicesRight Auto
ObjectReference[] Property OpponentDicesRight Auto
ObjectReference Property Marker Auto
ObjectReference InitialFurn
ObjectReference Property PlayerPosition Auto
Int PlayerBet
Int OpponentBet
Int MaxBet
Int PlayerScore
Int OpponentScore
ObjectReference PRandomDice1
ObjectReference PRandomDice2
ObjectReference ORandomDice1
ObjectReference ORandomDice2
MiscObject Property Gold001 Auto
Message Property Question Auto
int Choice
Function InitiateGame()
s_chargeninitialtext = Game.GetGameSettingString("sCharGenControlsDisabled")
Game.SetGameSettingString("sCharGenControlsDisabled","")
Commentator.GetActorBase().SetVoiceType(Opponent.GetActorReference().GetVoiceType())
Commentator.SetDisplayName(Opponent.GetReference().GetDisplayName(), true)
initialFurn = PlayerRef.GetFurnitureReference()
game.DisablePlayerControls(true, true, true, true, true, false, true, false, 0)
game.ForceFirstPerson()
game.SetInChargen(true, true, true)
PlayerPosition.MoveTo(PlayerRef as objectreference, 0.000000, 0.000000, 0.000000, true)
utility.Wait(0.300000)
PlayerRef.MoveTo(Marker, 0.000000, 0.000000, 0.000000, true)
if Opponent.GetReference().IsDisabled()
Opponent.GetReference().Enable(false)
endIf
Utility.Wait(3.0)
Step01()
EndFunction
Function Step01()
ORandomDice1.Disable()
ORandomDice2.Disable()
PRandomDice1.Disable()
PRandomDice2.Disable()
if PlayerRef.GetItemCount(Gold001) <= Opponent.GetReference().GetItemCount(Gold001)
MaxBet = (PlayerRef.GetItemCount(Gold001)/2) as INT
elseif PlayerRef.GetItemCount(Gold001) > Opponent.GetReference().GetItemCount(Gold001)
MaxBet = (Opponent.GetReference().GetItemCount(Gold001)/2) as INT
endif
PlayerBet = (((self as Quest) as form) as uilib_1).ShowTextInput(PlaceYourBet.GetName() + MaxBet as String, MaxBet as String) as Int
if PlayerBet > MaxBet || PlayerBet == 0
Step01()
Return
endif
OpponentBet = PlayerBet
Step02()
EndFunction
Function Step02()
Int diceplayer = Utility.RandomInt(0,5)
Int diceplayer2 = Utility.RandomInt(0,5)
PRandomDice1 = PlayerDicesLeft[diceplayer]
PRandomDice2 = PlayerDicesRight[diceplayer2]
PRandomDice1.Enable(true)
PRandomDice2.Enable(true)
PlayerScore = diceplayer + diceplayer2 + 2
Utility.Wait(2.0)
Step03()
EndFunction
Function Step03()
Choice = Question.Show(playerscore) ; 0 =less, 1 = more, 2 = equal
if Choice == 2
PlayerBet = PlayerBet*3
endif
PickOpponentDice()
EndFunction
Function PickOpponentDice()
Int diceopponent = Utility.RandomInt(0,5)
Int diceopponent2 = Utility.RandomInt(0,5)
ORandomDice1 = OpponentDicesLeft[diceopponent]
ORandomDice2 = OpponentDicesRight[diceopponent2]
ORandomDice1.Enable(true)
ORandomDice2.Enable(true)
OpponentScore = diceopponent + diceopponent2 +2
Utility.Wait(3.0)
CheckResult()
EndFunction
Function CheckResult()
if Choice == 0 ; we bet on less
if PlayerScore <= OpponentScore
PlayerLost()
else
PlayerWon()
endif
elseif Choice == 1 ; more
if PlayerScore < OpponentScore
PlayerWon()
else
PlayerLost()
endif
elseif Choice == 2
if PlayerScore == OpponentScore
PlayerWon()
else
PlayerLost()
endif
endif
EndFunction
Function PlayerLost()
Utility.Wait(2.0)
PlayerLost.Show(playerscore, opponentscore,playerbet)
PlayerRef.RemoveItem(Gold001, playerbet, false, Opponent.GetReference())
_SAG_ProphDiceLostGames.Value += 1
_SAG_ProphDiceLostGold.Value += playerbet
PlayAgain()
EndFunction
Function PlayerWon()
Utility.Wait(2.0)
PlayerWon.Show(playerscore, opponentscore,playerbet)
PlayerRef.AddItem(Gold001, playerbet)
Opponent.GetReference().RemoveItem(Gold001, playerbet)
_SAG_ProphDiceWonGames.Value += 1
_SAG_ProphDiceWonGold.Value += playerbet
If _SAG_ProphDiceWonGames.GetValueInt() == 10 && _00E_AchievementsEnabled.GetValueInt() == 1
Steam.UnlockAchievement("END_DICEGOD_01")
EndIf
PlayAgain()
EndFunction
Function PlayAgain()
if PlayerRef.GetItemCount(Gold001) < 10
;Debug.Notification("You do not have enough gold to play again.")
QuitGame()
elseif Opponent.GetReference().GetItemCount(Gold001) < 10
;Debug.Notification(Opponent.GetReference().GetDisplayName()+" does not have enough gold to play again.")
QuitGame()
else
int play = PlayAgain.Show(PlayerRef.GetItemCount(Gold001), Opponent.GetReference().GetItemCount(GOld001))
if play == 0
Step01()
else
QuitGame()
endif
endif
EndFunction
Function QuitGame()
Game.SetGameSettingString("sCharGenControlsDisabled", s_chargeninitialtext)
ORandomDice1.Disable()
ORandomDice2.Disable()
PRandomDice1.Disable()
PRandomDice2.Disable()
if Opponent.GetReference().IsDisabled()
Opponent.GetReference().Enable()
endif
if initialFurn
PlayerRef.MoveTo(initialFurn)
else
PlayerRef.MoveTo(PlayerPosition)
endif
Game.EnablePlayerControls()
game.SetInChargen(false, false, false)
Opponent.Clear()
EndFunction
Message Property PlayAgain Auto
Message Property PlayerLost Auto
Message Property PlayerWon Auto