Elin Decompiled Documentation EA 23.130 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
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;
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 int check = Mathf.Max(1, (int)((long)c.Evalue(eleParent) * (long)(100 + c.Evalue(285) * 10) / 100));
88 if (ReadCheck() || EClass.debug.godMode || owner.HasEditorTag(EditorTag.NoReadFail))
89 {
90 return true;
91 }
93 ModCharge(c);
94 return false;
95 bool ReadCheck()
96 {
97 if (EClass.rnd(4) != 0 && (c.isConfused || c.HasCondition<ConDim>()))
98 {
99 return false;
100 }
101 if (check > diff * 3)
102 {
103 return true;
104 }
105 if (EClass.rnd(check * 30) < diff)
106 {
107 return false;
108 }
109 return true;
110 }
111 }
112
113 public static void ReadFailEffect(Chara c)
114 {
115 if (EClass.rnd(2) == 0)
116 {
117 c.Say("spell_fail_mana", c);
118 c.mana.Mod(-c.mana.max / (c.IsPC ? 2 : 5));
119 }
120 else if (EClass.rnd(3) == 0)
121 {
122 c.Say("spell_fail_confuse", c);
124 }
125 else if (((c.IsPCFaction && c.memberType == FactionMemberType.Default) || !EClass._zone.IsPCFaction) && EClass.rnd(3) == 0)
126 {
127 c.Say("spell_fail_monster", c);
128 c.PlaySound("spell_funnel");
129 for (int i = 0; i < Mathf.Clamp(1 + EClass._zone.DangerLv / 15 + EClass.rnd(3 + EClass._zone.DangerLv / 15), 1, 8); i++)
130 {
131 Chara chara = CharaGen.CreateFromFilter("c_readFail", EClass._zone.DangerLv);
132 EClass._zone.AddCard(chara, c.pos.GetNearestPoint(allowBlock: false, allowChara: false));
133 chara.pos.PlayEffect("teleport");
134 }
135 }
136 else
137 {
138 c.Say("spell_fail_teleport", c);
139 if (c.IsPCFaction && !c.IsPC)
140 {
142 }
143 else
144 {
145 ActEffect.Proc(EffectId.Teleport, c);
146 }
147 }
148 }
149
150 public override void OnRead(Chara c)
151 {
152 bool flag = BookType == Type.Spell || BookType == Type.RandomSpell;
153 int a = -1;
154 string name = owner.Name;
155 if (c.IsPCParty)
156 {
157 owner.Thing?.Identify(show: true, IDTSource.SuperiorIdentify);
158 owner.isOn = true;
159 }
160 switch (BookType)
161 {
162 case Type.Ancient:
163 c.Say("book_decode", c, name);
164 if (!c.IsPC)
165 {
167 }
168 if (c.IsPC)
169 {
171 }
172 break;
173 case Type.Spell:
174 case Type.RandomSpell:
175 if (c.IsPC)
176 {
177 c.GainAbility(source.id);
178 }
179 ModCharge(c);
180 break;
181 case Type.Ero:
182 case Type.Dojin:
183 c.PlaySound("wow");
184 c.Say("book_decode", c, owner);
185 if (!c.IsPC)
186 {
187 c.Talk("wow");
188 }
189 switch (BookType)
190 {
191 case Type.Ero:
192 if (c.IsPC)
193 {
194 EClass.pc.SAN.Mod(-(EClass.rnd(5) + 1));
195 }
196 if (!owner.c_idRefName.IsEmpty())
197 {
199 c.Say("learn_weakspot", c, cardRow.GetName());
200 if (c.IsPC)
201 {
203 }
204 }
205 if (c.conSleep != null)
206 {
207 ActEffect.Proc(EffectId.Sleep, c);
208 }
209 break;
210 case Type.Dojin:
211 {
213 if (c.IsPC)
214 {
216 }
217 c.AddCondition<ConInsane>(500);
219 if (!c.IsPC && c.faith != religion)
220 {
221 if (!c.source.faith.IsEmpty())
222 {
223 c.Say("faith_stands", c);
224 break;
225 }
226 religion.JoinFaith(c);
227 a = -owner.c_charges;
228 }
229 break;
230 }
231 }
232 ModCharge(c, a);
233 break;
234 }
235 c.ModExp(285, 180);
236 if (flag)
237 {
238 c.ModExp(307, 200);
239 }
240 if (c.IsPC)
241 {
243 }
244 }
245
246 public void ModCharge(Chara c, int a = -1)
247 {
248 owner.ModCharge(a);
250 if (owner.c_charges <= 0)
251 {
252 c.Say("spellbookCrumble", owner);
253 owner.ModNum(-1);
254 }
255 }
256
257 public override void SetName(ref string s)
258 {
259 if (!owner.IsIdentified)
260 {
261 return;
262 }
263 switch (BookType)
264 {
265 case Type.Ancient:
266 s = "_titled".lang(Lang.GetList("ancientbook")[owner.refVal], s);
267 if (owner.isOn)
268 {
269 s = "_deciphered ".lang(s);
270 }
271 break;
272 case Type.Ero:
273 case Type.Dojin:
274 {
275 string c_idRefName = owner.c_idRefName;
276 if (!c_idRefName.IsEmpty())
277 {
278 string @ref = ((BookType == Type.Dojin) ? EClass.game.religions.dictAll[c_idRefName].Name : EClass.sources.charas.map.TryGetValue(c_idRefName, "putty").GetName());
279 s = "_'s".lang(@ref, s);
280 }
281 break;
282 }
283 }
284 }
285}
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:824
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:5585
void Talk(string idTopic, string ref1=null, string ref2=null, bool forceSync=false)
Definition: Card.cs:6135
string Name
Definition: Card.cs:2037
Point pos
Definition: Card.cs:55
int refVal
Definition: Card.cs:190
void SayNothingHappans()
Definition: Card.cs:6227
void ModCharge(int a, bool destroy=false)
Definition: Card.cs:3697
bool HasEditorTag(EditorTag tag)
Definition: Card.cs:2500
virtual Thing Thing
Definition: Card.cs:1958
int Evalue(int ele)
Definition: Card.cs:2471
bool isOn
Definition: Card.cs:514
BlessedState blessedState
Definition: Card.cs:262
void ModExp(string alias, int a)
Definition: Card.cs:2548
string c_idRefName
Definition: Card.cs:1565
void ModNum(int a, bool notify=true)
Definition: Card.cs:3306
bool IsIdentified
Definition: Card.cs:2277
int c_charges
Definition: Card.cs:1229
int LV
Definition: Card.cs:370
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:6232
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:8513
override bool IsPC
Definition: Chara.cs:602
override bool IsPCParty
Definition: Chara.cs:605
bool HasCondition(string alias)
Definition: Chara.cs:8666
override bool IsPCFaction
Definition: Chara.cs:661
ConSleep conSleep
Definition: Chara.cs:102
Stats SAN
Definition: Chara.cs:972
SourceChara.Row source
Definition: Chara.cs:148
Stats mana
Definition: Chara.cs:968
FactionMemberType memberType
Definition: Chara.cs:46
void GainAbility(int ele, int mtp=100)
Definition: Chara.cs:9210
Religion faith
Definition: Chara.cs:429
bool isBlind
Definition: Chara.cs:128
bool isConfused
Definition: Chara.cs:124
void AddWeakspot(string id)
Definition: CodexManager.cs:60
Definition: ConDim.cs:2
bool godMode
Definition: CoreDebug.cs:172
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
static int rnd(int a)
Definition: EClass.cs:58
static Zone _zone
Definition: EClass.cs:20
static SourceManager sources
Definition: EClass.cs:42
static Player player
Definition: EClass.cs:12
static Chara pc
Definition: EClass.cs:14
static CoreDebug debug
Definition: EClass.cs:48
int Select(int lv)
void AddContribution(int a)
Definition: FACTION.cs:316
ReligionManager religions
Definition: Game.cs:158
Definition: Guild.cs:2
static GuildMage Mage
Definition: Guild.cs:25
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:931
void ModKarma(int a)
Definition: Player.cs:2306
Effect PlayEffect(string id)
Definition: Point.cs:1224
Point GetNearestPoint(bool allowBlock=false, bool allowChara=true, bool allowInstalled=true, bool ignoreCenter=false)
Definition: Point.cs:607
ReligionEyth Eyth
Dictionary< string, Religion > dictAll
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:1976
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:26
override int DangerLv
Definition: Zone.cs:107
bool IsPCFaction
Definition: Zone.cs:464
Card AddCard(Card t, Point point)
Definition: Zone.cs:1893