public override void Update() { base.Update(); if (state == 0) // Starting { regionIndex = GameManager.Instance.PlayerGPS.CurrentRegionIndex; int crimeType = (int)playerEntity.CrimeCommitted - 1; int legalRep = playerEntity.RegionData[regionIndex].LegalRep; // Get whether punishment is normal (fine/prison) or a severe punishment (banishment/execution) int threshold1 = 0; int threshold2 = 0; if (legalRep < 0) { threshold1 = -legalRep; if (threshold1 > 75) { threshold1 = 75; } threshold2 = -legalRep / 2; if (threshold2 > 75) { threshold2 = 75; } } if (UnityEngine.Random.Range(1, 101) > threshold2 && UnityEngine.Random.Range(1, 101) > threshold1) { punishmentType = 2; // fine/prison } else { punishmentType = 0; // banishment or execution } // Calculate penalty amount int penaltyAmount = 0; if (legalRep >= 0) { penaltyAmount = PenaltyPerLegalRepPoint[crimeType] * legalRep + BasePenaltyAmounts[crimeType]; } else { penaltyAmount = BasePenaltyAmounts[crimeType] - PenaltyPerLegalRepPoint[crimeType] * legalRep; } if (penaltyAmount > MaximumPenaltyAmounts[crimeType]) { penaltyAmount = MaximumPenaltyAmounts[crimeType]; } else if (penaltyAmount < MinimumPenaltyAmounts[crimeType]) { penaltyAmount = MinimumPenaltyAmounts[crimeType]; } penaltyAmount /= 40; // Calculate days of prison and fine daysInPrison = 0; fine = 0; for (int i = 0; i < penaltyAmount; i++) { if ((DFRandom.rand() & 1) != 0) { fine += 40; } else { daysInPrison += 3; } } // If player can't pay fine, limit fine and add to prison sentence int playerGold = playerEntity.GetGoldAmount(); if (playerGold < fine) { daysInPrison += (fine - playerGold) / 40; fine = playerGold; } DaggerfallMessageBox messageBox; if (crimeType == 4 || crimeType == 3) // Assault or murder { // If player is a member of the Dark Brotherhood, they may be rescued for a violent crime Guilds.Guild guild = GameManager.Instance.GuildManager.GetGuild((int)FactionFile.FactionIDs.The_Dark_Brotherhood); if (guild.IsMember()) { if (guild.Rank >= UnityEngine.Random.Range(0, 20)) { messageBox = new DaggerfallMessageBox(uiManager, this, false, 149); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextDB)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; messageBox.ClickAnywhereToClose = true; uiManager.PushWindow(messageBox); playerEntity.FillVitalSigns(); playerEntity.RaiseReputationForDoingSentence(); state = 100; return; } } } if (crimeType <= 2 || crimeType == 11) // Attempted breaking and entering, trespassing, breaking and entering, pickpocketing { // If player is a member of the Thieves Guild, they may be rescued for a thieving crime Guilds.Guild guild = GameManager.Instance.GuildManager.GetGuild((int)FactionFile.FactionIDs.The_Thieves_Guild); if (guild.IsMember()) { if (guild.Rank >= UnityEngine.Random.Range(0, 20)) { messageBox = new DaggerfallMessageBox(uiManager, this, false, 149); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextTG)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; messageBox.ClickAnywhereToClose = true; uiManager.PushWindow(messageBox); playerEntity.FillVitalSigns(); playerEntity.RaiseReputationForDoingSentence(); state = 100; return; } } } messageBox = new DaggerfallMessageBox(uiManager, this, false, 105); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextStart)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Guilty); messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.NotGuilty); messageBox.OnButtonClick += GuiltyNotGuilty_OnButtonClick; messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; uiManager.PushWindow(messageBox); state = 1; // Done with initial message } else if (state == 2) // Found guilty { DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextFoundGuilty)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; messageBox.ClickAnywhereToClose = true; uiManager.PushWindow(messageBox); state = 3; } else if (state == 3) // Serve prison sentence { PositionPlayerAtLocationEntrance(); ServeTime(daysInPrison); playerEntity.RaiseReputationForDoingSentence(); state = 100; } else if (state == 4) // Banished { DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextBanished)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; messageBox.ClickAnywhereToClose = true; uiManager.PushWindow(messageBox); playerEntity.RegionData[regionIndex].SeverePunishmentFlags |= 1; PositionPlayerAtLocationEntrance(); state = 100; } // Note: Seems like an execution sentence can't be given in classic. It can't be given here, either. else if (state == 5) // Execution { DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextExecuted)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; messageBox.ClickAnywhereToClose = true; uiManager.PushWindow(messageBox); playerEntity.RegionData[regionIndex].SeverePunishmentFlags |= 2; state = 6; } else if (state == 6) // Reposition player at entrance { PositionPlayerAtLocationEntrance(); state = 100; } else if (state == 100) // Done { ReleaseFromJail(); } }
public override void Update() { base.Update(); // Close immediately if no crime assigned to player if (playerEntity.CrimeCommitted == Entity.PlayerEntity.Crimes.None) { CloseWindow(); return; } if (state == 0) // Starting { regionIndex = GameManager.Instance.PlayerGPS.CurrentRegionIndex; int crimeType = (int)playerEntity.CrimeCommitted - 1; int legalRep = playerEntity.RegionData[regionIndex].LegalRep; // Get whether punishment is normal (fine/prison) or a severe punishment (banishment/execution) int threshold1 = 0; int threshold2 = 0; if (legalRep < 0) { threshold1 = -legalRep; if (threshold1 > 75) { threshold1 = 75; } threshold2 = -legalRep / 2; if (threshold2 > 75) { threshold2 = 75; } } if (Dice100.FailedRoll(threshold2) && Dice100.FailedRoll(threshold1)) { punishmentType = 2; // fine/prison } else { punishmentType = 0; // banishment or execution } // Calculate penalty amount int penaltyAmount = 0; if (legalRep >= 0) { penaltyAmount = PenaltyPerLegalRepPoint[crimeType] * legalRep + BasePenaltyAmounts[crimeType]; } else { penaltyAmount = BasePenaltyAmounts[crimeType] - PenaltyPerLegalRepPoint[crimeType] * legalRep; } if (penaltyAmount > MaximumPenaltyAmounts[crimeType]) { penaltyAmount = MaximumPenaltyAmounts[crimeType]; } else if (penaltyAmount < MinimumPenaltyAmounts[crimeType]) { penaltyAmount = MinimumPenaltyAmounts[crimeType]; } penaltyAmount /= 40; // Calculate days of prison and fine daysInPrison = 0; fine = 0; for (int i = 0; i < penaltyAmount; i++) { if ((DFRandom.rand() & 1) != 0) { fine += 40; } else { daysInPrison += 3; } } // If player can't pay fine, limit fine and add to prison sentence int playerGold = playerEntity.GetGoldAmount(); if (playerGold < fine) { daysInPrison += (fine - playerGold) / 40; fine = playerGold; } DaggerfallMessageBox messageBox; if (crimeType == 4 || crimeType == 3) // Assault or murder { // If player is a member of the Dark Brotherhood, they may be rescued for a violent crime Guilds.IGuild guild = GameManager.Instance.GuildManager.GetGuild((int)FactionFile.FactionIDs.The_Dark_Brotherhood); if (guild.IsMember()) { if (guild.Rank >= UnityEngine.Random.Range(0, 20)) { messageBox = new DaggerfallMessageBox(uiManager, this, false, 149); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextDB)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; messageBox.ClickAnywhereToClose = true; uiManager.PushWindow(messageBox); playerEntity.FillVitalSigns(); playerEntity.RaiseReputationForDoingSentence(); state = 100; return; } } } if (crimeType <= 2 || crimeType == 11) // Attempted breaking and entering, trespassing, breaking and entering, pickpocketing { // If player is a member of the Thieves Guild, they may be rescued for a thieving crime Guilds.IGuild guild = GameManager.Instance.GuildManager.GetGuild((int)FactionFile.FactionIDs.The_Thieves_Guild); if (guild.IsMember()) { if (guild.Rank >= UnityEngine.Random.Range(0, 20)) { messageBox = new DaggerfallMessageBox(uiManager, this, false, 149); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextTG)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; messageBox.ClickAnywhereToClose = true; messageBox.AllowCancel = false; uiManager.PushWindow(messageBox); playerEntity.FillVitalSigns(); playerEntity.RaiseReputationForDoingSentence(); state = 100; return; } } } messageBox = new DaggerfallMessageBox(uiManager, this, false, 105); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextStart)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Guilty); messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.NotGuilty); messageBox.OnButtonClick += GuiltyNotGuilty_OnButtonClick; messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; messageBox.AllowCancel = false; uiManager.PushWindow(messageBox); state = 1; // Done with initial message } else if (state == 2) // Found guilty { DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextFoundGuilty)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; messageBox.ClickAnywhereToClose = true; messageBox.AllowCancel = false; uiManager.PushWindow(messageBox); if (daysInPrison > 0) { state = 3; } else { // Give the reputation raise here if no prison time will be served. playerEntity.RaiseReputationForDoingSentence(); repositionPlayer = true; playerEntity.FillVitalSigns(); ReleaseFromPrison(); state = 100; } } else if (state == 3) // Serve prison sentence { playerEntity.InPrison = true; SwitchToPrisonScreen(); daysInPrisonLeft = daysInPrison; playerEntity.RaiseReputationForDoingSentence(); repositionPlayer = true; state = 100; } else if (state == 4) // Banished { DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextBanished)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; messageBox.ClickAnywhereToClose = true; messageBox.AllowCancel = false; uiManager.PushWindow(messageBox); playerEntity.RegionData[regionIndex].SeverePunishmentFlags |= 1; repositionPlayer = true; // Refill player vitals after banishment, otherwise player left with 1HP outside city gates playerEntity.FillVitalSigns(); state = 100; } // Note: Seems like an execution sentence can't be given in classic. It can't be given here, either. else if (state == 5) // Execution { DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149); messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextExecuted)); messageBox.ScreenDimColor = new Color32(0, 0, 0, 0); messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom; messageBox.ClickAnywhereToClose = true; messageBox.AllowCancel = false; uiManager.PushWindow(messageBox); playerEntity.RegionData[regionIndex].SeverePunishmentFlags |= 2; state = 6; } else if (state == 6) // Reposition player at entrance { repositionPlayer = true; state = 100; } else if (state == 100) // Done { if (playerEntity.InPrison) { if (Input.GetKey(exitKey)) // Speed up prison day countdown. Not in classic. { prisonUpdateInterval = 0.001f; } else { prisonUpdateInterval = 0.3f; } if (prisonUpdateTimer == 0) { prisonUpdateTimer = Time.realtimeSinceStartup; } if (Time.realtimeSinceStartup < prisonUpdateTimer + prisonUpdateInterval) { return; } else { prisonUpdateTimer = Time.realtimeSinceStartup; UpdatePrisonScreen(); } } else { ReleaseFromPrison(); } } }