private void ConfirmSummon_OnButtonClick(DaggerfallMessageBox sender, DaggerfallMessageBox.MessageBoxButtons messageBoxButton) { sender.CloseWindow(); if (messageBoxButton == DaggerfallMessageBox.MessageBoxButtons.Yes) { PlayerEntity playerEntity = GameManager.Instance.PlayerEntity; int summonCost = FormulaHelper.CalculateDaedraSummoningCost(summonerFactionData.rep); if (playerEntity.GetGoldAmount() >= summonCost) { playerEntity.DeductGoldAmount(summonCost); WeatherManager weatherManager = GameManager.Instance.WeatherManager; // Sheogorath has a 5% (15% if stormy) chance to replace selected daedra. int sheoChance = (weatherManager.IsStorming) ? 15 : 5; if (Dice100.Roll() <= sheoChance) { daedraToSummon = daedraData[8]; } // Default 30% bonus is only applicable to some Daedra in specific weather conditions. int bonus = 0; if (daedraToSummon.bonusCond == Weather.WeatherType.Rain && weatherManager.IsRaining || daedraToSummon.bonusCond == Weather.WeatherType.Thunder && weatherManager.IsStorming || daedraToSummon.bonusCond == Weather.WeatherType.None) { bonus = 30; } // Get summoning chance for selected daedra and roll. int chance = FormulaHelper.CalculateDaedraSummoningChance(playerEntity.FactionData.GetReputation(daedraToSummon.factionId), bonus); int roll = Dice100.Roll(); Debug.LogFormat("Summoning {0} with chance = {1}%, Sheogorath chance = {2}%, roll = {3}, summoner rep = {4}, cost: {5}", daedraToSummon.vidFile.Substring(0, daedraToSummon.vidFile.Length - 4), chance, sheoChance, roll, summonerFactionData.rep, summonCost); if (roll > chance) { // Daedra stood you up! DaggerfallUI.MessageBox(SummonFailed, this); // Spawn daedric foes if failed at a witches coven. if (summonerFactionData.ggroup == (int)FactionFile.GuildGroups.Witches) { GameObjectHelper.CreateFoeSpawner(true, daedricFoes[Random.Range(0, 5)], Random.Range(1, 4), 4, 64); } return; } // Has this Daedra already been summoned by the player? if (playerEntity.FactionData.GetFlag(daedraToSummon.factionId, FactionFile.Flags.Summoned)) { // Close menu and push DaggerfallDaedraSummoningWindow here for video and dismissal.. CloseWindow(); uiManager.PushWindow(UIWindowFactory.GetInstanceWithArgs(UIWindowType.DaedraSummoned, new object[] { uiManager, daedraToSummon, SummonBefore, this })); } else { // Record the summoning. playerEntity.FactionData.SetFlag(daedraToSummon.factionId, FactionFile.Flags.Summoned); // Offer the quest to player. offeredQuest = GameManager.Instance.QuestListsManager.GetQuest(daedraToSummon.quest, summonerFactionData.id); if (offeredQuest != null) { // Close menu and push DaggerfallDaedraSummoningWindow here for video and custom quest offer.. CloseWindow(); uiManager.PushWindow(UIWindowFactory.GetInstanceWithArgs(UIWindowType.DaedraSummoned, new object[] { uiManager, daedraToSummon, offeredQuest })); } } } else { // Display customised not enough gold message so players don't need to guess the cost. TextFile.Token[] notEnoughGold = DaggerfallUnity.Instance.TextProvider.GetRSCTokens(DaggerfallTradeWindow.NotEnoughGoldId); TextFile.Token[] msg = new TextFile.Token[] { new TextFile.Token() { formatting = TextFile.Formatting.Text, text = TextManager.Instance.GetLocalizedText("serviceSummonCost1") }, new TextFile.Token() { formatting = TextFile.Formatting.JustifyCenter }, new TextFile.Token() { formatting = TextFile.Formatting.Text, text = TextManager.Instance.GetLocalizedText("serviceSummonCost2") + summonCost + TextManager.Instance.GetLocalizedText("serviceSummonCost3") }, new TextFile.Token() { formatting = TextFile.Formatting.JustifyCenter }, new TextFile.Token() { formatting = TextFile.Formatting.NewLine }, notEnoughGold[0], new TextFile.Token() { formatting = TextFile.Formatting.JustifyCenter }, }; DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, uiManager.TopWindow); messageBox.SetTextTokens(msg, this); messageBox.ClickAnywhereToClose = false; messageBox.Show(); } } }