Elin Decompiled Documentation EA 23.262 Nightly Patch 1
Loading...
Searching...
No Matches
TraitBaseSpellbook.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using UnityEngine;
4
6{
7 public enum Type
8 {
10 Spell,
12 Ero,
13 Dojin
14 }
15
17 {
18 type = "B",
19 useDomain = true
20 };
21
22 public virtual Type BookType => Type.Spell;
23
24 public virtual int Difficulty => (10 + owner.LV) * (100 + owner.Evalue(765) / 2) / 100;
25
26 public override bool CanStack => false;
27
28 public override bool HasCharges => true;
29
30 public override float MTPValue => 10f;
31
32 public override bool CanRead(Chara c)
33 {
34 return !c.isBlind;
35 }
36
37 public override int GetActDuration(Chara c)
38 {
39 return Mathf.Max(Difficulty, 100) * Mathf.Max(100 - (int)Mathf.Sqrt(c.Evalue(285)) * 7, 10) / 400;
40 }
41
42 public override void OnCreate(int lv)
43 {
44 owner.c_charges = 1 + EClass.rnd(4) + EClass.rnd(EClass.rnd(4) + 1);
45 switch (BookType)
46 {
47 case Type.RandomSpell:
49 break;
50 case Type.Ancient:
51 {
52 int max = Lang.GetList("ancientbook").Length;
53 owner.refVal = EClass.rnd(Mathf.Clamp(EClass.rnd(lv / 5 + 5), 1, max));
54 break;
55 }
56 case Type.Ero:
57 {
58 IEnumerable<SourceChara.Row> ie = EClass.sources.charas.rows.Where((SourceChara.Row a) => !a.name.IsEmpty() && a.name.Length > 2 && a.name[0] != '<' && a.race != "god" && !a.HasTag(CTAG.noRandomProduct));
59 owner.c_idRefName = ie.RandomItem().id;
60 break;
61 }
62 case Type.Dojin:
63 owner.c_idRefName = EClass.game.religions.dictAll.RandomItem().id;
64 break;
65 case Type.Spell:
66 break;
67 }
68 }
69
70 public override bool TryProgress(AIProgress p)
71 {
72 Chara c = p.owner;
73 if (BookType == Type.Ancient && owner.isOn)
74 {
75 if (c.IsPC)
76 {
77 c.Say("alreadyDecoded");
78 }
79 return false;
80 }
81 if (c.isBlind)
82 {
83 c.Say("blinded", c);
84 return false;
85 }
86 int diff = Mathf.Max(1, Difficulty * ((owner.blessedState >= BlessedState.Blessed) ? 75 : ((owner.blessedState <= BlessedState.Cursed) ? 300 : 100)) / 100);
87 long num = (long)c.Evalue(eleParent) * (long)(100 + c.Evalue(285) * 10) / 100;
88 int check = Mathf.Max(1, (int)((num >= 21474836) ? 21474836 : num));
89 if (ReadCheck() || EClass.debug.godMode || owner.HasEditorTag(EditorTag.NoReadFail))
90 {
91 return true;
92 }
94 ModCharge(c);
95 return false;
96 bool ReadCheck()
97 {
98 if (EClass.rnd(4) != 0 && (c.isConfused || c.HasCondition<ConDim>()))
99 {
100 return false;
101 }
102 if (check > diff * 3)
103 {
104 return true;
105 }
106 if (EClass.rnd(check * 30) < diff)
107 {
108 return false;
109 }
110 return true;
111 }
112 }
113
114 public static void ReadFailEffect(Chara c)
115 {
116 if (EClass.rnd(2) == 0)
117 {
118 c.Say("spell_fail_mana", c);
119 c.mana.Mod(-c.mana.max / (c.IsPC ? 2 : 5));
120 }
121 else if (EClass.rnd(3) == 0)
122 {
123 c.Say("spell_fail_confuse", c);
125 }
126 else if (((c.IsPCFaction && c.memberType == FactionMemberType.Default) || !EClass._zone.IsPCFaction) && EClass.rnd(3) == 0)
127 {
128 c.Say("spell_fail_monster", c);
129 c.PlaySound("spell_funnel");
130 for (int i = 0; i < Mathf.Clamp(1 + EClass._zone.DangerLv / 15 + EClass.rnd(3 + EClass._zone.DangerLv / 15), 1, 8); i++)
131 {
132 Chara chara = CharaGen.CreateFromFilter("c_readFail", EClass._zone.DangerLv);
133 EClass._zone.AddCard(chara, c.pos.GetNearestPoint(allowBlock: false, allowChara: false));
134 chara.pos.PlayEffect("teleport");
135 }
136 }
137 else
138 {
139 c.Say("spell_fail_teleport", c);
140 if (c.IsPCFaction && !c.IsPC)
141 {
143 }
144 else
145 {
146 ActEffect.Proc(EffectId.Teleport, c);
147 }
148 }
149 }
150
151 public override void OnRead(Chara c)
152 {
153 bool flag = BookType == Type.Spell || BookType == Type.RandomSpell;
154 int a = -1;
155 string name = owner.Name;
156 if (c.IsPCParty)
157 {
158 owner.Thing?.Identify(show: true, IDTSource.SuperiorIdentify);
159 owner.isOn = true;
160 }
161 switch (BookType)
162 {
163 case Type.Ancient:
164 c.Say("book_decode", c, name);
165 if (!c.IsPC)
166 {
168 }
169 if (c.IsPC)
170 {
172 }
173 break;
174 case Type.Spell:
175 case Type.RandomSpell:
176 if (c.IsPC)
177 {
178 c.GainAbility(source.id, 100, owner.Thing);
179 }
180 ModCharge(c);
181 break;
182 case Type.Ero:
183 case Type.Dojin:
184 c.PlaySound("wow");
185 c.Say("book_decode", c, owner);
186 if (!c.IsPC)
187 {
188 c.Talk("wow");
189 }
190 switch (BookType)
191 {
192 case Type.Ero:
193 if (c.IsPC)
194 {
195 EClass.pc.SAN.Mod(-(EClass.rnd(5) + 1));
196 }
197 if (!owner.c_idRefName.IsEmpty())
198 {
199 CardRow cardRow = EClass.sources.cards.map.TryGetValue(owner.c_idRefName, "putty");
200 c.Say("learn_weakspot", c, cardRow.GetName());
201 if (c.IsPC)
202 {
204 }
205 }
206 if (c.conSleep != null)
207 {
208 ActEffect.Proc(EffectId.Sleep, c);
209 }
210 break;
211 case Type.Dojin:
212 {
214 if (c.IsPC)
215 {
217 }
218 c.AddCondition<ConInsane>(500);
220 if (!c.IsPC && c.faith != religion)
221 {
222 if (!c.source.faith.IsEmpty() && c.source.faith == c.faith.id)
223 {
224 c.Say("faith_stands", c);
225 break;
226 }
227 religion.JoinFaith(c);
228 a = -owner.c_charges;
229 }
230 break;
231 }
232 }
233 ModCharge(c, a);
234 break;
235 }
236 c.ModExp(285, 180);
237 if (flag)
238 {
239 c.ModExp(307, 200);
240 }
241 if (c.IsPC)
242 {
244 }
245 }
246
247 public void ModCharge(Chara c, int a = -1)
248 {
249 owner.ModCharge(a);
251 if (owner.c_charges <= 0)
252 {
253 c.Say("spellbookCrumble", owner);
254 owner.ModNum(-1);
255 }
256 }
257
258 public override void SetName(ref string s)
259 {
260 if (!owner.IsIdentified)
261 {
262 return;
263 }
264 switch (BookType)
265 {
266 case Type.Ancient:
267 s = "_titled".lang(Lang.GetList("ancientbook")[owner.refVal], s);
268 if (owner.isOn)
269 {
270 s = "_deciphered ".lang(s);
271 }
272 break;
273 case Type.Ero:
274 case Type.Dojin:
275 {
276 string c_idRefName = owner.c_idRefName;
277 if (!c_idRefName.IsEmpty())
278 {
279 string @ref = ((BookType == Type.Dojin) ? EClass.game.religions.dictAll.TryGetValue(c_idRefName, EClass.game.religions.Eyth).Name : EClass.sources.charas.map.TryGetValue(c_idRefName, "putty").GetName());
280 s = "_'s".lang(@ref, s);
281 }
282 break;
283 }
284 }
285 }
286}
BlessedState
Definition: BlessedState.cs:2
CTAG
Definition: CTAG.cs:2
EditorTag
Definition: EditorTag.cs:2
EffectId
Definition: EffectId.cs:2
FactionMemberType
IDTSource
Definition: IDTSource.cs:2
new Chara owner
Definition: AIAct.cs:14
static void Proc(EffectId id, Card cc, Card tc=null, int power=100, ActRef actRef=default(ActRef))
Definition: ActEffect.cs:1028
virtual string GetName(int i)
Definition: CardRow.cs:95
string id
Definition: CardRow.cs:7
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:6214
void Talk(string idTopic, string ref1=null, string ref2=null, bool forceSync=false)
Definition: Card.cs:6774
string Name
Definition: Card.cs:2140
Point pos
Definition: Card.cs:60
int refVal
Definition: Card.cs:207
void SayNothingHappans()
Definition: Card.cs:6886
void ModCharge(int a, bool destroy=false)
Definition: Card.cs:3975
bool HasEditorTag(EditorTag tag)
Definition: Card.cs:2603
virtual Thing Thing
Definition: Card.cs:2059
int Evalue(int ele)
Definition: Card.cs:2574
bool isOn
Definition: Card.cs:543
BlessedState blessedState
Definition: Card.cs:279
void ModExp(string alias, int a)
Definition: Card.cs:2651
string c_idRefName
Definition: Card.cs:1642
void ModNum(int a, bool notify=true)
Definition: Card.cs:3540
bool IsIdentified
Definition: Card.cs:2380
int c_charges
Definition: Card.cs:1270
int LV
Definition: Card.cs:387
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:6891
static Chara CreateFromFilter(string id, int lv=-1, int levelRange=-1)
Definition: CharaGen.cs:22
Definition: Chara.cs:10
Condition AddCondition(string id, int p=100, bool force=false)
Definition: Chara.cs:9326
override bool IsPC
Definition: Chara.cs:614
override bool IsPCParty
Definition: Chara.cs:617
bool HasCondition(string alias)
Definition: Chara.cs:9487
override bool IsPCFaction
Definition: Chara.cs:673
ConSleep conSleep
Definition: Chara.cs:102
Stats SAN
Definition: Chara.cs:1160
SourceChara.Row source
Definition: Chara.cs:160
void GainAbility(int ele, int mtp=100, Thing origin=null)
Definition: Chara.cs:10165
Stats mana
Definition: Chara.cs:1156
FactionMemberType memberType
Definition: Chara.cs:46
Religion faith
Definition: Chara.cs:441
bool isBlind
Definition: Chara.cs:132
bool isConfused
Definition: Chara.cs:128
void AddWeakspot(string id)
Definition: CodexManager.cs:60
Definition: ConDim.cs:2
Definition: EClass.cs:6
static Game game
Definition: EClass.cs:9
static Zone _zone
Definition: EClass.cs:21
static int rnd(long a)
Definition: EClass.cs:59
static SourceManager sources
Definition: EClass.cs:43
static Player player
Definition: EClass.cs:13
static Chara pc
Definition: EClass.cs:15
int Select(int lv)
void AddContribution(int a)
Definition: FACTION.cs:318
ReligionManager religions
Definition: Game.cs:159
Definition: Guild.cs:2
static GuildMage Mage
Definition: Guild.cs:58
Definition: Lang.cs:6
static string[] GetList(string id)
Definition: Lang.cs:114
static void Redraw()
static void SetDirtyAll(bool immediate=false)
CodexManager codex
Definition: Player.cs:1115
void ModKarma(int a)
Definition: Player.cs:2518
Point GetNearestPoint(bool allowBlock=false, bool allowChara=true, bool allowInstalled=true, bool ignoreCenter=false, int minRadius=0)
Definition: Point.cs:619
Effect PlayEffect(string id)
Definition: Point.cs:1248
ReligionEyth Eyth
Dictionary< string, Religion > dictAll
virtual string id
Definition: Religion.cs:26
Dictionary< string, CardRow > map
Definition: SourceCard.cs:8
SourceCard cards
SourceChara charas
virtual void Mod(int a)
Definition: Stats.cs:135
virtual int max
Definition: Stats.cs:68
Thing Identify(bool show=true, IDTSource idtSource=IDTSource.Identify)
Definition: Thing.cs:2087
override bool CanRead(Chara c)
static ElementSelecter selecter
void ModCharge(Chara c, int a=-1)
override bool CanStack
static void ReadFailEffect(Chara c)
override void OnCreate(int lv)
override bool HasCharges
override bool TryProgress(AIProgress p)
override void OnRead(Chara c)
override float MTPValue
override int GetActDuration(Chara c)
override void SetName(ref string s)
virtual SourceElement.Row source
Definition: TraitScroll.cs:5
virtual int eleParent
Definition: TraitScroll.cs:8
static void Create(Card owner, int ele)
Card owner
Definition: Trait.cs:28
override int DangerLv
Definition: Zone.cs:110
bool IsPCFaction
Definition: Zone.cs:473
Card AddCard(Card t, Point point)
Definition: Zone.cs:1998