-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibrarianGiveAllBooks.cs
110 lines (106 loc) · 3.48 KB
/
LibrarianGiveAllBooks.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
using System;
using System.Collections.Generic;
using ConsoleLib.Console;
using Qud.API;
using XRL;
using XRL.UI;
using XRL.World;
using XRL.World.Parts;
using XRL.World.Conversations;
using XRL.World.Conversations.Parts;
namespace GiveAllBooks.Conversations.Parts
{
public class LibrarianGiveAllBooks : IConversationPart
{
public override bool WantEvent(int ID, int Propagation)
{
if (!base.WantEvent(ID, Propagation) && ID != GetChoiceTagEvent.ID)
{
return ID == EnterElementEvent.ID;
}
return true;
}
public static bool IsAwardableBook(GameObject Object)
{
if (Object.HasIntProperty("LibrarianAwarded"))
{
return false;
}
if (Object.HasPart("Book"))
{
return true;
}
if (Object.HasPart("VillageHistoryBook"))
{
return true;
}
if (Object.HasPart("MarkovBook"))
{
return true;
}
if (Object.HasPart("Cookbook"))
{
return true;
}
return false;
}
public override bool HandleEvent(GetChoiceTagEvent E)
{
E.Tag = "{{g|[Give All Books]}}";
return false;
}
public override bool HandleEvent(EnterElementEvent E)
{
Inventory inventory = The.Player.Inventory;
bool terse = Options.GetOption("OptionGiveAllBooksTerse") == "Yes";
int bookCount = 0;
int xpTotal = 0;
string displayName = The.Speaker.GetDisplayName(int.MaxValue, null, null, AsIfKnown: false, Single: false, NoConfusion: true, NoColor: false, Stripped: true, ColorOnly: false, WithoutEpithet: true, Short: false, BaseOnly: true);
string definiteArticle = The.Speaker.DefiniteArticle(capital: true, displayName, forBase: true);
string indefiniteArticle = The.Speaker.IndefiniteArticle(capital: true, displayName, forBase: true);
foreach (GameObject currentObject in inventory.GetObjects(IsAwardableBook))
{
if (currentObject.IsImportant())
{
continue;
}
if (!inventory.FireEvent(Event.New("CommandRemoveObject", "Object", currentObject)))
{
continue;
}
bookCount += currentObject.Count;
int xpAward = (int)(currentObject.ValueEach * currentObject.ValueEach / 25.0);
xpTotal += currentObject.Count * xpAward;
for (int i = 0; i < currentObject.Count; i++)
{
if (!terse)
{
Popup.Show("Sheba Hagadias provides some insightful commentary on '" + currentObject.DisplayNameSingle + "'.");
Popup.Show("You gain {{C|" + xpAward + "}} XP.", CopyScrap: true, Capitalize: true, DimBackground: true, LogMessage: false);
}
JournalAPI.AddAccomplishment(indefiniteArticle + displayName + " provided you with insightful commentary on " + currentObject.DisplayName + ".", "Remember the kindness of =name=, who patiently taught " + currentObject.DisplayName + " to " + The.Player.its + " simple pupil, " + indefiniteArticle + displayName + ".", "general", JournalAccomplishment.MuralCategory.LearnsSecret, JournalAccomplishment.MuralWeight.Low, null, -1L);
}
if (The.Speaker != null)
{
The.Speaker.ReceiveObject(currentObject);
}
else
{
currentObject.Destroy();
}
currentObject.SetIntProperty("LibrarianAwarded", 1);
}
if (bookCount == 0)
{
Popup.Show("You don't have any suitable books to give.");
return false;
}
if (terse)
{
Popup.Show("You give " + definiteArticle + displayName + " " + bookCount + " books, and gain {{C|" + xpTotal + "}} XP.", CopyScrap: true, Capitalize: true, DimBackground: true);
}
The.Player.AwardXP(xpTotal, -1, 0, int.MaxValue, null, The.Speaker);
return base.HandleEvent(E);
}
}
}