-
Notifications
You must be signed in to change notification settings - Fork 324
/
DaggerfallGuildServiceDonation.cs
120 lines (101 loc) · 4.31 KB
/
DaggerfallGuildServiceDonation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Project: Daggerfall Unity
// Copyright: Copyright (C) 2009-2023 Daggerfall Workshop
// Web Site: http://www.dfworkshop.net
// License: MIT License (http://www.opensource.org/licenses/mit-license.php)
// Source Code: https://github.com/Interkarma/daggerfall-unity
// Original Author: Hazelnut
// Contributors:
//
// Notes:
//
using System;
using DaggerfallWorkshop.Utility;
using DaggerfallWorkshop.Game.Entity;
using DaggerfallWorkshop.Game.Guilds;
using DaggerfallWorkshop.Game.UserInterface;
using DaggerfallWorkshop.Game.Utility;
namespace DaggerfallWorkshop.Game.UserInterfaceWindows
{
/**
* Guild service UI for temple donations.
*/
public class DaggerfallGuildServiceDonation : DaggerfallInputMessageBox, IMacroContextProvider
{
public const int TooGenerousId = 702;
public const int DonationThanksId = 703;
// Based on the building faction id rather than guild object so it works for non-members as well
protected int BuildingFactionId { get; private set; }
protected PlayerEntity playerEntity;
public DaggerfallGuildServiceDonation(IUserInterfaceManager uiManager, int buildingFactionId)
: base(uiManager)
{
BuildingFactionId = buildingFactionId;
playerEntity = GameManager.Instance.PlayerEntity;
DonationService();
}
protected virtual void DonationService()
{
SetTextBoxLabel(TextManager.Instance.GetLocalizedText("serviceDonateHowMuch"));
TextPanelDistanceX = 6;
TextPanelDistanceY = 6;
TextBox.Numeric = true;
TextBox.MaxCharacters = 8;
TextBox.Text = "1000";
OnGotUserInput += DonationMsgBox_OnGotUserInput;
}
protected virtual void DonationMsgBox_OnGotUserInput(DaggerfallInputMessageBox sender, string input)
{
int amount = 0;
if (int.TryParse(input, out amount))
{
if (playerEntity.GetGoldAmount() >= amount)
{
// Deduct gold, and apply blessing
playerEntity.DeductGoldAmount(amount);
int factionId = (int)Temple.GetDivine(BuildingFactionId);
// Change reputation
int rep = Math.Abs(playerEntity.FactionData.GetReputation(factionId));
if (Dice100.SuccessRoll((2 * amount / Math.Max(rep, 1)) + 1))
playerEntity.FactionData.ChangeReputation(factionId, 1); // Does not propagate in classic
// Show thanks message
DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, uiManager.TopWindow);
messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRandomTokens(DonationThanksId), this);
messageBox.ClickAnywhereToClose = true;
messageBox.Show();
}
else
{
DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, uiManager.TopWindow);
messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRandomTokens(TooGenerousId), this);
messageBox.ClickAnywhereToClose = true;
messageBox.Show();
}
}
}
#region Macro handling
public MacroDataSource GetMacroDataSource()
{
return new GuildServiceDonationMacroDataSource(this);
}
/// <summary>
/// MacroDataSource context sensitive methods for guild service donation UI.
/// </summary>
private class GuildServiceDonationMacroDataSource : MacroDataSource
{
private DaggerfallGuildServiceDonation parent;
public GuildServiceDonationMacroDataSource(DaggerfallGuildServiceDonation guildServiceWindow)
{
this.parent = guildServiceWindow;
}
public override string God()
{
return Temple.GetDivineLocalized(parent.BuildingFactionId);
}
public override string GodDesc()
{
return Temple.GetDeityDesc((Temple.Divines)parent.BuildingFactionId);
}
}
#endregion
}
}