Elin Decompiled Documentation EA 23.315 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 => false;
16
17 public SourceThing.Row sourceThing => EClass.sources.things.map.TryGetValue(idThing.IsEmpty("generator_snowman"), "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) && (IsDeliver || s.model.trait.CanStack)).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 try
113 {
114 if (t.source.GetName() == name || t.GetName(NameStyle.Simple, 1) == name)
115 {
116 return true;
117 }
118 }
119 catch
120 {
121 return false;
122 }
123 }
124 }
125 return false;
126 }
127
128 public List<Thing> ListDestThing(bool onlyFirst = false)
129 {
130 List<Thing> list = EClass.pc.things.List((Thing t) => IsDestThing(t), onlyAccessible: true);
131 if (onlyFirst && list.Count > 0)
132 {
133 return list;
134 }
136 {
137 foreach (Thing thing in EClass._map.props.stocked.things)
138 {
139 if (IsDestThing(thing))
140 {
141 list.Add(thing);
142 if (onlyFirst)
143 {
144 return list;
145 }
146 }
147 }
148 }
149 return list;
150 }
151
152 public override Thing GetDestThing()
153 {
154 List<Thing> list = ListDestThing(onlyFirst: true);
155 if (list.Count <= 0)
156 {
157 return null;
158 }
159 return list[0];
160 }
161
162 public override bool IsDeliverTarget(Chara c)
163 {
164 if (IsDeliver)
165 {
166 if (EClass._zone == base.DestZone)
167 {
168 return c.uid == uidTarget;
169 }
170 return false;
171 }
172 if (c.quest != null)
173 {
174 return c.quest.uid == uid;
175 }
176 return false;
177 }
178
179 public override bool CanDeliverToClient(Chara c)
180 {
181 if (GetDestThing() == null && !EClass.debug.autoAdvanceQuest)
182 {
183 return false;
184 }
185 if (IsDeliver)
186 {
187 if (EClass._zone == base.DestZone)
188 {
189 return c.uid == uidTarget;
190 }
191 return false;
192 }
193 if (person.chara?.uid == c.uid)
194 {
195 return true;
196 }
197 if (c.quest != null)
198 {
199 return c.quest.uid == uid;
200 }
201 return false;
202 }
203
204 public override bool CanDeliverToBox(Thing t)
205 {
206 return false;
207 }
208
209 public override bool Deliver(Chara c, Thing t = null)
210 {
211 if (t == null)
212 {
213 t = GetDestThing();
214 if (t == null && EClass.debug.autoAdvanceQuest)
215 {
216 Debug.Log("[error] creating " + idThing);
218 }
219 }
220 if (t != null)
221 {
222 Thing thing = t.Split(num);
223 bonusMoney += GetBonus(thing);
224 Msg.Say("deliverItem", thing);
225 if (ConsumeGoods || c.things.IsFull())
226 {
227 thing.Destroy();
228 }
229 else
230 {
231 thing.isGifted = true;
232 thing = c.Pick(thing);
233 if (c.CanEat(thing))
234 {
236 {
237 target = thing
238 });
239 }
240 else
241 {
242 c.TryUse(thing);
243 }
244 }
246 c.quest = null;
247 return true;
248 }
249 return false;
250 }
251
252 public virtual int GetBonus(Thing t)
253 {
254 return 0;
255 }
256
257 public override string GetTextProgress()
258 {
259 string text = ((GetDestThing() != null) ? "supplyInInv".lang().TagColor(FontColor.Good) : "supplyNotInInv".lang());
260 if (IsDeliver)
261 {
262 string @ref = (base.DestZone.dictCitizen.TryGetValue(uidTarget) ?? "???") + " (" + base.DestZone.Name + ")";
263 return "progressDeliver".lang(sourceThing.GetName(num), @ref, text);
264 }
265 return "progressSupply".lang(sourceThing.GetName(num) + Lang.space + TextExtra2.IsEmpty(""), text);
266 }
267
268 public override void OnEnterZone()
269 {
270 if (!IsDeliver || EClass._zone != base.DestZone)
271 {
272 return;
273 }
274 Chara chara = EClass._map.charas.Find((Chara c) => c.uid == uidTarget);
275 if (chara == null)
276 {
277 chara = EClass._map.deadCharas.Find((Chara c) => c.uid == uidTarget);
278 }
279 if (chara == null)
280 {
281 Msg.Say("deliver_funny");
282 Complete();
283 }
284 }
285}
FontColor
Definition: FontColor.cs:2
IDTSource
Definition: IDTSource.cs:2
NameStyle
Definition: NameStyle.cs:2
Definition: AI_Eat.cs:5
void Add(Act a, string s="")
Definition: ActPlan.cs:11
string id
Definition: CardRow.cs:7
Thing Split(int a)
Definition: Card.cs:3642
string id
Definition: Card.cs:36
string c_altName
Definition: Card.cs:1633
int uid
Definition: Card.cs:125
Trait trait
Definition: Card.cs:54
void Destroy()
Definition: Card.cs:5268
bool c_isImportant
Definition: Card.cs:1051
ThingContainer things
Definition: Card.cs:39
Card parentCard
Definition: Card.cs:106
int Num
Definition: Card.cs:161
bool IsIdentified
Definition: Card.cs:2431
bool IsContainer
Definition: Card.cs:2141
Definition: Chara.cs:10
bool TryUse(Thing t)
Definition: Chara.cs:8175
bool CanEat(Thing t, bool shouldEat=false)
Definition: Chara.cs:7893
void SetAIImmediate(AIAct g)
Definition: Chara.cs:9294
Quest quest
Definition: Chara.cs:24
Thing Pick(Thing t, bool msg=true, bool tryStack=true)
Definition: Chara.cs:4460
bool autoAdvanceQuest
Definition: CoreDebug.cs:226
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 SourceManager sources
Definition: EClass.cs:43
static Chara pc
Definition: EClass.cs:15
static CoreDebug debug
Definition: EClass.cs:49
QuestManager quests
Definition: Game.cs:183
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:473
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)
bool IsFull(int y=0)
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:532
Thing Identify(bool show=true, IDTSource idtSource=IDTSource.Identify)
Definition: Thing.cs:2128
virtual bool CanUseContent
Definition: Trait.cs:227
bool IsPCFaction
Definition: Zone.cs:477