Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
HotItemHeld.cs
Go to the documentation of this file.
1using UnityEngine;
2
4{
5 public static Thing lastHeld;
6
7 public static TaskBuild taskBuild;
8
9 public static Recipe recipe;
10
11 public static bool disableTool;
12
13 public override Act act => GetAct();
14
15 public static bool CanChangeHeightByWheel()
16 {
18 {
19 return false;
20 }
22 {
23 return taskBuild.CanPerform();
24 }
25 return false;
26 }
27
28 public static bool CanRotate()
29 {
30 if (EClass._zone.IsRegion || EClass.pc.held == null)
31 {
32 return false;
33 }
35 {
36 return false;
37 }
39 {
40 return false;
41 }
42 if (taskBuild == null)
43 {
44 return false;
45 }
47 {
48 return true;
49 }
50 if (!taskBuild.CanPerform())
51 {
52 return false;
53 }
56 }
57
58 public HotItemHeld()
59 {
60 }
61
63 {
64 thing = t;
65 }
66
67 public override void OnSetCurrentItem()
68 {
69 ActionMode.Build.altitude = 0;
70 disableTool = false;
71 if (EClass.pc.held != thing)
72 {
74 }
75 taskBuild = null;
79 {
80 _act = (thing.trait as TraitCatalyst).CreateAct();
81 }
82 if (lastHeld != thing)
83 {
85 }
88 {
89 EClass.pc.ranged = thing;
90 }
91 }
92
93 public override void OnUnselect()
94 {
95 taskBuild = null;
96 recipe = null;
97 if (EClass.pc.held == thing)
98 {
100 }
101 }
102
103 public Act GetAct()
104 {
105 if (thing.trait is TraitRod)
106 {
107 return new ActZap();
108 }
110 {
111 return ACT.Ranged;
112 }
113 if (thing.HasElement(241))
114 {
115 return new AI_PlayMusic();
116 }
117 if (thing.HasElement(225))
118 {
119 return new TaskCut();
120 }
121 if (thing.HasElement(220))
122 {
123 return new TaskMine();
124 }
125 if (thing.HasElement(230))
126 {
127 return new TaskDig
128 {
129 mode = TaskDig.Mode.RemoveFloor
130 };
131 }
132 if (thing.HasElement(286))
133 {
134 return new TaskPlow();
135 }
136 if (thing.HasElement(245))
137 {
138 return new AI_Fish();
139 }
140 if (thing.HasElement(237))
141 {
142 return new AI_TendAnimal();
143 }
144 return _act;
145 }
146
148 {
149 if (lost)
150 {
151 return null;
152 }
154 {
155 return new AI_Drink
156 {
157 target = thing
158 };
159 }
161 {
162 return new AI_Eat
163 {
164 cook = false
165 };
166 }
168 {
169 return new AI_Read
170 {
171 target = thing
172 };
173 }
174 return null;
175 }
176
177 public override bool TrySetAct(ActPlan p)
178 {
179 taskBuild = null;
180 if (!disableTool)
181 {
182 if (p.IsSelf && thing.trait.CanUse(EClass.pc))
183 {
184 return p.TrySetAct(thing.trait.LangUse, () => thing.trait.OnUse(p.cc), thing, null, -1);
185 }
187 {
188 return p.TrySetAct(thing.trait.LangUse, () => thing.trait.OnUse(p.cc, EClass.scene.mouseTarget.target as Card), thing, null, -1);
189 }
190 if (thing.trait.CanUse(EClass.pc, p.pos))
191 {
192 return p.TrySetAct(thing.trait.LangUse, () => thing.trait.OnUse(p.cc, p.pos), thing, null, -1);
193 }
194 if (thing.trait.IsTool)
195 {
196 if (TrySetToolAct(p))
197 {
198 return true;
199 }
200 }
201 else
202 {
204 }
205 if (p.HasAct || thing.trait.IsTool)
206 {
207 return true;
208 }
209 }
210 if (p.pos.Equals(EClass.pc.pos))
211 {
212 Act selfAct = GetSelfAct();
213 if (selfAct != null)
214 {
215 p.TrySetAct(selfAct, thing);
216 return true;
217 }
218 }
219 bool flag = true;
221 {
222 flag = false;
223 }
225 {
226 flag = false;
227 }
228 Chara tg;
229 if (flag)
230 {
231 if (p.IsSelfOrNeighbor)
232 {
233 _ = p.pos.Installed?.trait;
234 tg = p.pos.FirstVisibleChara();
235 if (tg != null && tg != EClass.pc && !tg.IsDisabled && tg.IsNeutralOrAbove() && EClass.pc.held != null && tg.CanAcceptGift(EClass.pc, EClass.pc.held))
236 {
237 string lang = "actGive";
238 if (tg.Evalue(1232) > 0 && EClass.pc.held.trait is TraitDrinkMilkMother)
239 {
240 lang = "actMilk";
241 }
242 p.TrySetAct(lang, delegate
243 {
244 if (!tg.IsValidGiftWeight(EClass.pc.held, 1))
245 {
246 tg.Talk("tooHeavy");
247 return true;
248 }
250 {
251 Dialog.YesNo("dialogGive".lang(EClass.pc.held.GetName(NameStyle.Full, 1)), func);
252 }
253 else
254 {
255 func();
256 }
257 return true;
258 }, thing);
259 }
260 }
261 if (p.HasAct)
262 {
263 return true;
264 }
266 {
267 Chara chara = p.pos.FirstVisibleChara();
268 if ((chara == null || chara == EClass.pc || chara.IsNeutralOrAbove()) && recipe != null && (!thing.trait.IsThrowMainAction || EInput.isShiftDown || disableTool))
269 {
270 taskBuild = new TaskBuild
271 {
272 recipe = recipe,
273 held = EClass.pc.held,
274 pos = p.pos.Copy()
275 };
277 build.bridgeHeight = -1;
278 build.recipe = taskBuild.recipe;
279 build.mold = taskBuild;
280 build.SetAltitude(recipe.tileType.AltitudeAsDir ? recipe._dir : build.altitude);
282 }
283 }
284 }
285 if (p.HasAct)
286 {
287 return true;
288 }
289 if (ActThrow.CanThrow(EClass.pc, thing, null, p.pos) && p.TrySetAct(new ActThrow
290 {
291 target = thing,
292 pcTarget = p.pos.FindAttackTarget()?.Chara
293 }, thing))
294 {
295 return true;
296 }
297 return false;
298 void func()
299 {
301 }
302 }
303
304 public bool TrySetToolAct(ActPlan p)
305 {
307 if (p.HasAct)
308 {
309 return true;
310 }
311 Cell cell = p.pos.cell;
312 Point pos = p.pos;
313 if (cell.HasBlock && (!cell.HasObj || cell.sourceObj.tileType.IsMountBlock) && TaskMine.CanMine(pos, thing) && p.TrySetAct(new TaskMine
314 {
315 pos = pos.Copy()
316 }))
317 {
318 return true;
319 }
320 if (pos.IsHidden)
321 {
322 return true;
323 }
325 {
326 if (!EClass.pc.CanSeeSimple(pos))
327 {
328 return true;
329 }
330 Card tc = null;
331 foreach (Chara item in pos.ListVisibleCharas())
332 {
333 if (item.isSynced && item.IsAliveInCurrentZone)
334 {
335 tc = item;
336 break;
337 }
338 }
339 EClass.pc.ranged = thing;
340 p.TrySetAct(ACT.Ranged, tc);
341 return true;
342 }
343 if (cell.IsTopWaterAndNoSnow && thing.HasElement(245) && p.TrySetAct(new AI_Fish
344 {
345 pos = pos.Copy()
346 }))
347 {
348 return true;
349 }
350 if (p.IsNeighborBlocked)
351 {
352 return true;
353 }
354 TaskHarvest taskHarvest = TaskHarvest.TryGetAct(EClass.pc, pos);
355 if (taskHarvest != null && p.TrySetAct(taskHarvest))
356 {
357 return true;
358 }
359 TraitToolWaterPot traitToolWaterPot = thing.trait as TraitToolWaterPot;
360 if (cell.IsTopWaterAndNoSnow)
361 {
362 if (traitToolWaterPot != null && traitToolWaterPot.owner.c_charges < traitToolWaterPot.MaxCharge && p.TrySetAct(new TaskDrawWater
363 {
364 pot = traitToolWaterPot,
365 pos = pos.Copy()
366 }))
367 {
368 return true;
369 }
370 }
371 else
372 {
373 if (traitToolWaterPot != null && !p.pos.HasBridge && traitToolWaterPot.owner.c_charges > 0 && pos.cell.sourceSurface.tag.Contains("soil") && p.TrySetAct(new TaskPourWater
374 {
375 pot = traitToolWaterPot,
376 pos = pos.Copy()
377 }))
378 {
379 return true;
380 }
381 if (thing.HasElement(230) && p.TrySetAct(new TaskDig
382 {
383 pos = pos.Copy(),
384 mode = TaskDig.Mode.RemoveFloor
385 }))
386 {
387 return true;
388 }
389 if (thing.HasElement(286) && p.TrySetAct(new TaskPlow
390 {
391 pos = pos.Copy()
392 }))
393 {
394 return true;
395 }
396 }
397 if (TaskMine.CanMine(pos, thing) && p.TrySetAct(new TaskMine
398 {
399 pos = pos.Copy()
400 }))
401 {
402 return true;
403 }
404 if (thing.HasElement(225) && p.TrySetAct(new TaskChopWood
405 {
406 pos = pos.Copy()
407 }))
408 {
409 return true;
410 }
411 if (pos.HasChara)
412 {
413 _ = pos.FirstChara;
414 _ = EClass.pc;
415 }
416 if (thing.HasTag(CTAG.throwWeapon) && ActThrow.CanThrow(EClass.pc, thing, null, p.pos) && p.TrySetAct(new ActThrow
417 {
418 target = thing,
419 pcTarget = p.pos.FindAttackTarget()?.Chara
420 }, thing))
421 {
422 return true;
423 }
424 return false;
425 }
426
427 public override void OnRenderTile(Point point, HitResult result, int dir)
428 {
430 {
431 for (int i = point.z - 1; i < point.z + 2; i++)
432 {
433 for (int j = point.x - 1; j < point.x + 2; j++)
434 {
436 }
437 }
438 }
439 if (taskBuild == null || !taskBuild.IsRunning || (!recipe.MultiSize && !taskBuild.CanProgress()) || !taskBuild.CanPerform(EClass.pc, null, point))
440 {
441 return;
442 }
443 EClass.screen.guide.isActive = false;
445 EClass.screen.guide.isActive = true;
446 if (recipe.MultiSize)
447 {
448 point.ForeachMultiSize(recipe.W, recipe.H, delegate(Point pos, bool main)
449 {
450 Vector3 v = pos.Position();
451 v.z -= 0.01f;
453 });
454 }
455 }
456}
CTAG
Definition: CTAG.cs:2
@ build
@ cook
HitResult
Definition: HitResult.cs:2
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
Definition: ACT.cs:6
static ActRanged Ranged
Definition: ACT.cs:17
virtual bool IsRunning
Definition: AIAct.cs:31
Definition: AI_Eat.cs:5
ActPlan planAll
Definition: AM_Adv.cs:147
override void OnRenderTile(Point point, HitResult result, int dir)
Definition: AM_Build.cs:239
Chara cc
Definition: ActPlan.cs:201
bool IsNeighborBlocked
Definition: ActPlan.cs:178
Point pos
Definition: ActPlan.cs:149
void Update(PointTarget target)
Definition: ActPlan.cs:411
bool IsSelfOrNeighbor
Definition: ActPlan.cs:175
bool IsSelf
Definition: ActPlan.cs:173
bool TrySetAct(string lang, Func< bool > onPerform, Card tc, CursorInfo cursor=null, int dist=1, bool isHostileAct=false, bool localAct=true, bool canRepeat=false)
Definition: ActPlan.cs:344
bool HasAct
Definition: ActPlan.cs:243
static bool CanThrow(Chara c, Thing t, Card target, Point p=null)
Definition: ActThrow.cs:60
Definition: ActZap.cs:2
Definition: ACT.cs:62
static AM_Build Build
Definition: ActionMode.cs:49
virtual bool IsBuildMode
Definition: ActionMode.cs:181
static AM_Adv Adv
Definition: ActionMode.cs:15
ScreenGuide guide
Definition: Card.cs:11
bool HasElement(int ele, int req=1)
Definition: Card.cs:5214
bool HasTag(CTAG tag)
Definition: Card.cs:2455
Point pos
Definition: Card.cs:55
Trait trait
Definition: Card.cs:49
bool c_isImportant
Definition: Card.cs:984
int Evalue(int ele)
Definition: Card.cs:2431
int c_charges
Definition: Card.cs:1205
Definition: Cell.cs:7
bool HasBlock
Definition: Cell.cs:643
bool IsTopWaterAndNoSnow
Definition: Cell.cs:712
SourceObj.Row sourceObj
Definition: Cell.cs:1072
bool HasObj
Definition: Cell.cs:641
SourceFloor.Row sourceSurface
Definition: Cell.cs:1059
Definition: Chara.cs:10
Card held
Definition: Chara.cs:67
bool CanAcceptGift(Chara c, Card t)
Definition: Chara.cs:7455
bool IsValidGiftWeight(Card t, int num=-1)
Definition: Chara.cs:7424
void HoldCard(Card t, int num=-1)
Definition: Chara.cs:4084
void PickHeld(bool msg=false)
Definition: Chara.cs:4136
override bool IsDisabled
Definition: Chara.cs:570
bool IsNeutralOrAbove()
Definition: Chara.cs:5928
void GiveGift(Chara c, Thing t)
Definition: Chara.cs:7480
bool CanSeeSimple(Point p)
Definition: Chara.cs:1010
Card SplitHeld(int a)
Definition: Chara.cs:4196
new GameConfig game
Definition: CoreConfig.cs:596
InputSetting input
Definition: CoreConfig.cs:602
CoreConfig config
Definition: Core.cs:70
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
static Scene scene
Definition: EClass.cs:30
static Core core
Definition: EClass.cs:6
static Zone _zone
Definition: EClass.cs:20
static BaseGameScreen screen
Definition: EClass.cs:32
static Chara pc
Definition: EClass.cs:14
Definition: EInput.cs:8
static bool isShiftDown
Definition: EInput.cs:261
bool showGuideGrid
Definition: Game.cs:45
Config config
Definition: Game.cs:215
static Thing lastHeld
Definition: HotItemHeld.cs:5
override void OnUnselect()
Definition: HotItemHeld.cs:93
HotItemHeld(Thing t)
Definition: HotItemHeld.cs:62
static bool CanRotate()
Definition: HotItemHeld.cs:28
static Recipe recipe
Definition: HotItemHeld.cs:9
bool TrySetToolAct(ActPlan p)
Definition: HotItemHeld.cs:304
static bool CanChangeHeightByWheel()
Definition: HotItemHeld.cs:15
Act GetAct()
Definition: HotItemHeld.cs:103
override void OnRenderTile(Point point, HitResult result, int dir)
Definition: HotItemHeld.cs:427
static TaskBuild taskBuild
Definition: HotItemHeld.cs:7
Act GetSelfAct()
Definition: HotItemHeld.cs:147
static bool disableTool
Definition: HotItemHeld.cs:11
override bool TrySetAct(ActPlan p)
Definition: HotItemHeld.cs:177
override Act act
Definition: HotItemHeld.cs:13
override void OnSetCurrentItem()
Definition: HotItemHeld.cs:67
void Add(Point point, float tile=0f, float color=0f)
Definition: MeshPass.cs:122
IInspect target
Definition: PointTarget.cs:16
Definition: Point.cs:9
Thing Installed
Definition: Point.cs:303
static Point shared
Definition: Point.cs:20
void ForeachMultiSize(int w, int h, Action< Point, bool > action)
Definition: Point.cs:1349
ref Vector3 Position(int height)
Definition: Point.cs:524
bool HasBridge
Definition: Point.cs:209
Point Copy()
Definition: Point.cs:467
Point Set(int _x, int _z)
Definition: Point.cs:479
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
bool Equals(int _x, int _z)
Definition: Point.cs:924
Chara FirstVisibleChara()
Definition: Point.cs:382
bool IsHidden
Definition: Point.cs:323
Chara FirstChara
Definition: Point.cs:264
Cell cell
Definition: Point.cs:51
List< Chara > ListVisibleCharas()
Definition: Point.cs:1148
bool HasChara
Definition: Point.cs:226
static void BuildList()
Definition: Recipe.cs:7
virtual TileType tileType
Definition: Recipe.cs:198
virtual int H
Definition: Recipe.cs:252
int MaxAltitude
Definition: Recipe.cs:212
bool MultiSize
Definition: Recipe.cs:266
int _dir
Definition: Recipe.cs:175
virtual int W
Definition: Recipe.cs:240
ActionMode actionMode
Definition: Scene.cs:77
PointTarget mouseTarget
Definition: Scene.cs:129
MeshPass passGuideFloor
Definition: ScreenGuide.cs:7
virtual bool IsRegion
Definition: Spatial.cs:501
Recipe recipe
Definition: TaskBuild.cs:8
static TaskHarvest TryGetAct(Chara c, Point p)
Definition: TaskHarvest.cs:114
static bool CanMine(Point pos, Card t)
Definition: TaskMine.cs:31
override bool CanPerform()
Definition: TaskPoint.cs:42
override bool CanProgress()
Definition: Task.cs:68
Definition: Thing.cs:8
virtual bool AltitudeAsDir
Definition: TileType.cs:205
virtual bool CanExtendBuild
Definition: Trait.cs:161
virtual bool CanUse(Chara c)
Definition: Trait.cs:950
virtual Recipe GetRecipe()
Definition: Trait.cs:758
virtual void OnHeld()
Definition: Trait.cs:996
virtual bool IsTool
Definition: Trait.cs:355
virtual bool CanChangeHeight
Definition: Trait.cs:143
virtual void TrySetHeldAct(ActPlan p)
Definition: Trait.cs:992
virtual bool CanRead(Chara c)
Definition: Trait.cs:919
virtual bool CanBuildInTown
Definition: Trait.cs:258
virtual bool CanEat(Chara c)
Definition: Trait.cs:928
virtual bool IsThrowMainAction
Definition: Trait.cs:174
virtual bool OnUse(Chara c)
Definition: Trait.cs:965
Card owner
Definition: Trait.cs:26
virtual string LangUse
Definition: Trait.cs:357
virtual bool CanBeOnlyBuiltInHome
Definition: Trait.cs:255
virtual bool CanDrink(Chara c)
Definition: Trait.cs:937
bool IsPCFactionOrTent
Definition: Zone.cs:467
virtual bool RestrictBuild
Definition: Zone.cs:283