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); // Default 30% bonus is only applicable to some Daedra in specific weather conditions. WeatherManager weatherManager = GameManager.Instance.WeatherManager; 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; } // Sheogorath has a 5% (15% if stormy) chance to replace selected daedra. int sheoChance = (weatherManager.IsStorming) ? 15 : 5; // Get summoning chance for selected daedra and roll. int chance = FormulaHelper.CalculateDaedraSummoningChance(playerEntity.FactionData.GetReputation(daedraToSummon.factionId), bonus); int roll = Random.Range(1, 101); 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 + sheoChance) { // 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; } else if (roll > chance) { // Sheogorath appears instead. daedraToSummon = daedraData[8]; } // 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(new DaggerfallDaedraSummonedWindow(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(new DaggerfallDaedraSummonedWindow(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(NotEnoughGoldId); TextFile.Token[] msg = new TextFile.Token[] { new TextFile.Token() { formatting = TextFile.Formatting.Text, text = HardStrings.serviceSummonCost1 }, new TextFile.Token() { formatting = TextFile.Formatting.JustifyCenter }, new TextFile.Token() { formatting = TextFile.Formatting.Text, text = HardStrings.serviceSummonCost2 + summonCost + HardStrings.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 = true; uiManager.PushWindow(messageBox); } } }