Elin Decompiled Documentation EA 23.356.1 Nightly
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,
15 }
16
18 {
19 type = "B",
20 useDomain = true
21 };
22
23 public virtual Type BookType => Type.Spell;
24
25 public virtual int Difficulty => (10 + owner.LV) * (100 + owner.Evalue(765) / 2) / 100;
26
27 public override bool CanStack => false;
28
29 public override bool HasCharges => true;
30
31 public override float MTPValue => 10f;
32
33 public override bool CanRead(Chara c)
34 {
35 return !c.isBlind;
36 }
37
38 public override int GetActDuration(Chara c)
39 {
40 return Mathf.Max(Difficulty, 100) * Mathf.Max(100 - (int)Mathf.Sqrt(c.Evalue(285)) * 7, 10) / 400;
41 }
42
43 public override void OnCreate(int lv)
44 {
45 owner.c_charges = 1 + EClass.rnd(4) + EClass.rnd(EClass.rnd(4) + 1);
46 switch (BookType)
47 {
48 case Type.RandomSpell:
50 break;
51 case Type.Ancient:
52 {
53 int max = Lang.GetList("ancientbook").Length;
54 owner.refVal = EClass.rnd(Mathf.Clamp(EClass.rnd(lv / 5 + 5), 1, max));
55 break;
56 }
57 case Type.Ero:
58 {
59 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));
60 owner.c_idRefName = ie.RandomItem().id;
61 break;
62 }
63 case Type.Dojin:
64 owner.c_idRefName = EClass.game.religions.dictAll.RandomItem().id;
65 break;
66 case Type.Spell:
67 break;
68 }
69 }
70
71 public override bool TryProgress(AIProgress p)
72 {
73 Chara c = p.owner;
74 Type bookType = BookType;
75 if ((bookType == Type.Ancient || bookType == Type.BlackNote) && owner.isOn)
76 {
77 if (c.IsPC)
78 {
79 c.Say("alreadyDecoded");
80 }
81 return false;
82 }
83 if (c.isBlind)
84 {
85 c.Say("blinded", c);
86 return false;
87 }
88 int diff = Mathf.Max(1, Difficulty * ((owner.blessedState >= BlessedState.Blessed) ? 75 : ((owner.blessedState <= BlessedState.Cursed) ? 300 : 100)) / 100);
89 long num = (long)c.Evalue(eleParent) * (long)(100 + c.Evalue(285) * 10) / 100;
90 int check = Mathf.Max(1, (int)((num >= 21474836) ? 21474836 : num));
91 if (ReadCheck() || EClass.debug.godMode || owner.HasEditorTag(EditorTag.NoReadFail))
92 {
93 return true;
94 }
96 if (HasCharges)
97 {
98 ModCharge(c);
99 }
100 return false;
101 bool ReadCheck()
102 {
103 if (EClass.rnd(4) != 0 && (c.isConfused || c.HasCondition<ConDim>()))
104 {
105 return false;
106 }
107 if (check > diff * 3)
108 {
109 return true;
110 }
111 if (EClass.rnd(check * 30) < diff)
112 {
113 return false;
114 }
115 return true;
116 }
117 }
118
119 public static void ReadFailEffect(Chara c)
120 {
121 if (EClass.rnd(2) == 0)
122 {
123 c.Say("spell_fail_mana", c);
124 c.mana.Mod(-c.mana.max / (c.IsPC ? 2 : 5));
125 }
126 else if (EClass.rnd(3) == 0)
127 {
128 c.Say("spell_fail_confuse", c);
130 }
131 else if (((c.IsPCFaction && c.memberType == FactionMemberType.Default) || !EClass._zone.IsPCFaction) && EClass.rnd(3) == 0)
132 {
133 c.Say("spell_fail_monster", c);
134 c.PlaySound("spell_funnel");
135 for (int i = 0; i < Mathf.Clamp(1 + EClass._zone.DangerLv / 15 + EClass.rnd(3 + EClass._zone.DangerLv / 15), 1, 8); i++)
136 {
137 Chara chara = CharaGen.CreateFromFilter("c_readFail", EClass._zone.DangerLv);
138 EClass._zone.AddCard(chara, c.pos.GetNearestPoint(allowBlock: false, allowChara: false));
139 chara.pos.PlayEffect("teleport");
140 }
141 }
142 else
143 {
144 c.Say("spell_fail_teleport", c);
145 if (c.IsPCFaction && !c.IsPC)
146 {
148 }
149 else
150 {
151 ActEffect.Proc(EffectId.Teleport, c);
152 }
153 }
154 }
155
156 public override void OnRead(Chara c)
157 {
158 bool flag = BookType == Type.Spell || BookType == Type.RandomSpell;
159 int a = -1;
160 string name = owner.Name;
161 if (c.IsPCParty)
162 {
163 owner.Thing?.Identify(show: true, IDTSource.SuperiorIdentify);
164 owner.isOn = true;
165 }
166 switch (BookType)
167 {
168 case Type.BlackNote:
169 {
170 c.Say("book_decode", c, name);
171 c.Say("dingExp", c);
172 c.feat += (c.IsPC ? 1 : 4);
173 c.PlaySound("godbless");
174 c.PlayEffect("aura_heaven");
175 Chara chara = (owner.c_idRefName.IsEmpty() ? EClass.pc : EClass._map.FindChara(owner.c_idRefName));
176 if (chara != null && (c.IsPC || chara != EClass.pc))
177 {
178 chara.Die();
179 }
180 break;
181 }
182 case Type.Ancient:
183 c.Say("book_decode", c, name);
184 if (!c.IsPC)
185 {
187 }
188 if (c.IsPC)
189 {
191 }
192 break;
193 case Type.Spell:
194 case Type.RandomSpell:
195 if (c.IsPC)
196 {
197 c.GainAbility(source.id, 100, owner.Thing);
198 }
199 ModCharge(c);
200 break;
201 case Type.Ero:
202 case Type.Dojin:
203 c.PlaySound("wow");
204 c.Say("book_decode", c, owner);
205 if (!c.IsPC)
206 {
207 c.Talk("wow");
208 }
209 switch (BookType)
210 {
211 case Type.Ero:
212 if (c.IsPC)
213 {
214 EClass.pc.SAN.Mod(-(EClass.rnd(5) + 1));
215 }
216 if (!owner.c_idRefName.IsEmpty())
217 {
218 CardRow cardRow = EClass.sources.cards.map.TryGetValue(owner.c_idRefName, "putty");
219 c.Say("learn_weakspot", c, cardRow.GetName());
220 if (c.IsPC)
221 {
223 }
224 }
225 if (c.conSleep != null)
226 {
227 ActEffect.Proc(EffectId.Sleep, c);
228 }
229 break;
230 case Type.Dojin:
231 {
233 if (c.IsPC)
234 {
236 }
237 c.AddCondition<ConInsane>(500);
239 if (!c.IsPC && c.faith != religion)
240 {
241 if (!c.source.faith.IsEmpty() && c.source.faith == c.faith.id)
242 {
243 c.Say("faith_stands", c);
244 break;
245 }
246 religion.JoinFaith(c);
247 a = -owner.c_charges;
248 }
249 break;
250 }
251 }
252 ModCharge(c, a);
253 break;
254 }
255 c.ModExp(285, 180);
256 if (flag)
257 {
258 c.ModExp(307, 200);
259 }
260 if (c.IsPC)
261 {
263 }
264 }
265
266 public void ModCharge(Chara c, int a = -1)
267 {
268 owner.ModCharge(a);
270 if (owner.c_charges <= 0)
271 {
272 c.Say("spellbookCrumble", owner);
273 owner.ModNum(-1);
274 }
275 }
276
277 public override void SetName(ref string s)
278 {
279 if (!owner.IsIdentified)
280 {
281 return;
282 }
283 switch (BookType)
284 {
285 case Type.Ancient:
286 s = "_titled".lang(Lang.GetList("ancientbook")[owner.refVal], s);
287 if (owner.isOn)
288 {
289 s = "_deciphered".lang(s);
290 }
291 break;
292 case Type.Ero:
293 case Type.Dojin:
294 case Type.BlackNote:
295 {
296 string c_idRefName = owner.c_idRefName;
297 if (!c_idRefName.IsEmpty())
298 {
299 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());
300 s = "_'s".lang(@ref, s);
301 }
302 if (BookType == Type.BlackNote && owner.isOn)
303 {
304 s = "_deciphered".lang(s);
305 }
306 break;
307 }
308 }
309 }
310}
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:1125
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:6645
void Talk(string idTopic, string ref1=null, string ref2=null, bool forceSync=false)
Definition: Card.cs:7206
string Name
Definition: Card.cs:2191
Point pos
Definition: Card.cs:60
Effect PlayEffect(string id, bool useRenderPos=true, float range=0f, Vector3 fix=default(Vector3))
Definition: Card.cs:6679
int refVal
Definition: Card.cs:209
void SayNothingHappans()
Definition: Card.cs:7319
void ModCharge(int a, bool destroy=false)
Definition: Card.cs:4131
bool HasEditorTag(EditorTag tag)
Definition: Card.cs:2733
virtual Thing Thing
Definition: Card.cs:2110
int Evalue(int ele)
Definition: Card.cs:2704
bool isOn
Definition: Card.cs:545
BlessedState blessedState
Definition: Card.cs:281
void ModExp(string alias, int a)
Definition: Card.cs:2781
string c_idRefName
Definition: Card.cs:1681
void ModNum(int a, bool notify=true)
Definition: Card.cs:3696
bool IsIdentified
Definition: Card.cs:2447
int c_charges
Definition: Card.cs:1309
int LV
Definition: Card.cs:389
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:7324
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:9881
override bool IsPC
Definition: Chara.cs:632
override bool IsPCParty
Definition: Chara.cs:635
bool HasCondition(string alias)
Definition: Chara.cs:10053
override bool IsPCFaction
Definition: Chara.cs:691
ConSleep conSleep
Definition: Chara.cs:104
override void Die(Element e=null, Card origin=null, AttackSource attackSource=AttackSource.None, Chara originalTarget=null)
Definition: Chara.cs:5672
Stats SAN
Definition: Chara.cs:1219
SourceChara.Row source
Definition: Chara.cs:164
void GainAbility(int ele, int mtp=100, Thing origin=null)
Definition: Chara.cs:10763
Stats mana
Definition: Chara.cs:1215
FactionMemberType memberType
Definition: Chara.cs:48
Religion faith
Definition: Chara.cs:445
bool isBlind
Definition: Chara.cs:134
bool isConfused
Definition: Chara.cs:130
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 Map _map
Definition: EClass.cs:19
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:7
static string[] GetList(string id)
Definition: Lang.cs:113
static void Redraw()
static void SetDirtyAll(bool immediate=false)
Chara FindChara(string id)
Definition: Map.cs:2768
CodexManager codex
Definition: Player.cs:1185
void ModKarma(int a)
Definition: Player.cs:2636
Point GetNearestPoint(bool allowBlock=false, bool allowChara=true, bool allowInstalled=true, bool ignoreCenter=false, int minRadius=0)
Definition: Point.cs:620
Effect PlayEffect(string id)
Definition: Point.cs:1250
ReligionEyth Eyth
Dictionary< string, Religion > dictAll
virtual string id
Definition: Religion.cs:33
Dictionary< string, CardRow > map
Definition: SourceCard.cs:9
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:2159
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:115
bool IsPCFaction
Definition: Zone.cs:480
Card AddCard(Card t, Point point)
Definition: Zone.cs:2159