Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
QuestDeliver.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using Newtonsoft.Json;
3using UnityEngine;
4
6{
7 [JsonProperty]
8 public string idThing;
9
10 [JsonProperty]
11 public int num;
12
13 private static List<SourceCategory.Row> _listDeliver = new List<SourceCategory.Row>();
14
15 public virtual bool ConsumeGoods => true;
16
17 public SourceThing.Row sourceThing => EClass.sources.things.map[idThing.IsEmpty("generator_snowman")];
18
19 public override string NameDeliver => sourceThing.GetName();
20
21 public override string RefDrama2 => NameDeliver;
22
23 public override int KarmaOnFail
24 {
25 get
26 {
27 if (!IsDeliver)
28 {
29 return base.KarmaOnFail;
30 }
31 return -15;
32 }
33 }
34
35 public override DifficultyType difficultyType => DifficultyType.Deliver;
36
37 public override bool ForbidTeleport => true;
38
39 public override int GetExtraMoney()
40 {
41 if (base.DestZone == null)
42 {
43 return 0;
44 }
45 return base.DestZone.Dist(base.ClientZone) * 6;
46 }
47
48 public override void OnInit()
49 {
50 num = GetDestNum();
51 SetIdThing();
52 }
53
54 public virtual int GetDestNum()
55 {
56 return 1;
57 }
58
59 public virtual void SetIdThing()
60 {
61 CardRow cardRow;
62 do
63 {
65 cardRow = SpawnListThing.Get("cat_" + r.id, (SourceThing.Row s) => EClass.sources.categories.map[s.category].IsChildOf(r.id)).Select();
66 }
67 while (cardRow == null);
68 idThing = cardRow.id;
69 }
70
72 {
73 if (_listDeliver.Count == 0)
74 {
75 foreach (SourceCategory.Row row in EClass.sources.categories.rows)
76 {
77 if (row.deliver > 0)
78 {
79 _listDeliver.Add(row);
80 }
81 }
82 }
83 return _listDeliver.RandomItem();
84 }
85
86 public override void OnStart()
87 {
88 if (IsDeliver)
89 {
91 thing.Identify(show: false, IDTSource.SuperiorIdentify);
92 Msg.Say("get_quest_item");
93 EClass.pc.Pick(thing);
94 }
95 }
96
97 public virtual bool IsDestThing(Thing t)
98 {
99 if (t.parentCard != null && !t.parentCard.trait.CanUseContent)
100 {
101 return false;
102 }
103 if (!t.c_isImportant && t.Num >= num && t.IsIdentified && (!t.IsContainer || t.things.Count == 0) && !t.isEquipped)
104 {
105 if (t.id == idThing)
106 {
107 return true;
108 }
109 if (t.c_altName.IsEmpty())
110 {
111 string name = sourceThing.GetName();
112 if (t.source.GetName() == name || t.GetName(NameStyle.Simple, 1) == name)
113 {
114 return true;
115 }
116 }
117 }
118 return false;
119 }
120
121 public List<Thing> ListDestThing(bool onlyFirst = false)
122 {
123 List<Thing> list = EClass.pc.things.List((Thing t) => IsDestThing(t), onlyAccessible: true);
124 if (onlyFirst && list.Count > 0)
125 {
126 return list;
127 }
129 {
130 foreach (Thing thing in EClass._map.props.stocked.things)
131 {
132 if (IsDestThing(thing))
133 {
134 list.Add(thing);
135 if (onlyFirst)
136 {
137 return list;
138 }
139 }
140 }
141 }
142 return list;
143 }
144
145 public override Thing GetDestThing()
146 {
147 List<Thing> list = ListDestThing(onlyFirst: true);
148 if (list.Count <= 0)
149 {
150 return null;
151 }
152 return list[0];
153 }
154
155 public override bool IsDeliverTarget(Chara c)
156 {
157 if (IsDeliver)
158 {
159 if (EClass._zone == base.DestZone)
160 {
161 return c.uid == uidTarget;
162 }
163 return false;
164 }
165 if (c.quest != null)
166 {
167 return c.quest.uid == uid;
168 }
169 return false;
170 }
171
172 public override bool CanDeliverToClient(Chara c)
173 {
174 if (GetDestThing() == null && !EClass.debug.autoAdvanceQuest)
175 {
176 return false;
177 }
178 if (IsDeliver)
179 {
180 if (EClass._zone == base.DestZone)
181 {
182 return c.uid == uidTarget;
183 }
184 return false;
185 }
186 if (person.chara?.uid == c.uid)
187 {
188 return true;
189 }
190 if (c.quest != null)
191 {
192 return c.quest.uid == uid;
193 }
194 return false;
195 }
196
197 public override bool CanDeliverToBox(Thing t)
198 {
199 return false;
200 }
201
202 public override bool Deliver(Chara c, Thing t = null)
203 {
204 if (t == null)
205 {
206 t = GetDestThing();
207 if (t == null && EClass.debug.autoAdvanceQuest)
208 {
209 Debug.Log("[error] creating " + idThing);
211 }
212 }
213 if (t != null)
214 {
215 Thing thing = t.Split(num);
216 bonusMoney += GetBonus(thing);
217 Msg.Say("deliverItem", thing);
218 if (ConsumeGoods)
219 {
220 thing.Destroy();
221 }
222 else
223 {
224 c.Pick(thing);
225 }
227 c.quest = null;
228 return true;
229 }
230 return false;
231 }
232
233 public virtual int GetBonus(Thing t)
234 {
235 return 0;
236 }
237
238 public override string GetTextProgress()
239 {
240 string text = ((GetDestThing() != null) ? "supplyInInv".lang().TagColor(FontColor.Good) : "supplyNotInInv".lang());
241 if (IsDeliver)
242 {
243 string @ref = (base.DestZone.dictCitizen.TryGetValue(uidTarget) ?? "???") + " (" + base.DestZone.Name + ")";
244 return "progressDeliver".lang(sourceThing.GetName(num), @ref, text);
245 }
246 return "progressSupply".lang(sourceThing.GetName(num) + Lang.space + TextExtra2.IsEmpty(""), text);
247 }
248
249 public override void OnEnterZone()
250 {
251 if (!IsDeliver || EClass._zone != base.DestZone)
252 {
253 return;
254 }
255 Chara chara = EClass._map.charas.Find((Chara c) => c.uid == uidTarget);
256 if (chara == null)
257 {
258 chara = EClass._map.deadCharas.Find((Chara c) => c.uid == uidTarget);
259 }
260 if (chara == null)
261 {
262 Msg.Say("deliver_funny");
263 Complete();
264 }
265 }
266}
FontColor
Definition: FontColor.cs:2
IDTSource
Definition: IDTSource.cs:2
NameStyle
Definition: NameStyle.cs:2
void Add(Act a, string s="")
Definition: ActPlan.cs:11
string id
Definition: CardRow.cs:7
Thing Split(int a)
Definition: Card.cs:3231
string id
Definition: Card.cs:31
string c_altName
Definition: Card.cs:1493
int uid
Definition: Card.cs:118
Trait trait
Definition: Card.cs:49
void Destroy()
Definition: Card.cs:4538
bool c_isImportant
Definition: Card.cs:984
ThingContainer things
Definition: Card.cs:34
Card parentCard
Definition: Card.cs:99
int Num
Definition: Card.cs:154
bool IsIdentified
Definition: Card.cs:2237
bool IsContainer
Definition: Card.cs:1965
Definition: Chara.cs:10
Quest quest
Definition: Chara.cs:24
Thing Pick(Thing t, bool msg=true, bool tryStack=true)
Definition: Chara.cs:3920
bool autoAdvanceQuest
Definition: CoreDebug.cs:210
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
static SourceManager sources
Definition: EClass.cs:42
static Chara pc
Definition: EClass.cs:14
static CoreDebug debug
Definition: EClass.cs:48
QuestManager quests
Definition: Game.cs:179
List< Chara > deadCharas
Definition: Map.cs:46
PropsManager props
Definition: Map.cs:91
List< Chara > charas
Definition: Map.cs:81
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
Chara chara
Definition: Person.cs:36
PropsStocked stocked
Definition: PropsManager.cs:6
List< Thing > things
Definition: Props.cs:20
virtual int GetDestNum()
Definition: QuestDeliver.cs:54
List< Thing > ListDestThing(bool onlyFirst=false)
override string NameDeliver
Definition: QuestDeliver.cs:19
override void OnInit()
Definition: QuestDeliver.cs:48
string idThing
Definition: QuestDeliver.cs:8
virtual void SetIdThing()
Definition: QuestDeliver.cs:59
static List< SourceCategory.Row > _listDeliver
Definition: QuestDeliver.cs:13
override DifficultyType difficultyType
Definition: QuestDeliver.cs:35
SourceThing.Row sourceThing
Definition: QuestDeliver.cs:17
override void OnStart()
Definition: QuestDeliver.cs:86
override string GetTextProgress()
override void OnEnterZone()
override bool IsDeliverTarget(Chara c)
override bool CanDeliverToBox(Thing t)
virtual bool IsDestThing(Thing t)
Definition: QuestDeliver.cs:97
override bool ForbidTeleport
Definition: QuestDeliver.cs:37
override string RefDrama2
Definition: QuestDeliver.cs:21
override int GetExtraMoney()
Definition: QuestDeliver.cs:39
virtual int GetBonus(Thing t)
SourceCategory.Row GetDeliverCat()
Definition: QuestDeliver.cs:71
override bool Deliver(Chara c, Thing t=null)
override int KarmaOnFail
Definition: QuestDeliver.cs:24
virtual bool ConsumeGoods
Definition: QuestDeliver.cs:15
override Thing GetDestThing()
override bool CanDeliverToClient(Chara c)
virtual bool IsDeliver
void Complete(Quest q)
Definition: QuestManager.cs:98
int uid
Definition: Quest.cs:34
Person person
Definition: Quest.cs:73
int bonusMoney
Definition: Quest.cs:55
Chara chara
Definition: Quest.cs:105
virtual string TextExtra2
Definition: Quest.cs:158
void Complete()
Definition: Quest.cs:468
DifficultyType
Definition: Quest.cs:9
SourceThing things
SourceCategory categories
static SpawnList Get(string id, Func< SourceThing.Row, bool > func)
CardRow Select(int lv=-1, int levelRange=-1)
Definition: SpawnList.cs:139
List< Thing > List(Func< Thing, bool > func, bool onlyAccessible=false)
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
SourceThing.Row source
Definition: Thing.cs:11
bool isEquipped
Definition: Thing.cs:17
override string GetName(NameStyle style, int _num=-1)
Definition: Thing.cs:494
Thing Identify(bool show=true, IDTSource idtSource=IDTSource.Identify)
Definition: Thing.cs:1959
virtual bool CanUseContent
Definition: Trait.cs:207
bool IsPCFaction
Definition: Zone.cs:464