Elin Decompiled Documentation EA 23.321 Nightly Patch 1
Loading...
Searching...
No Matches
AI_Trolley.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEngine;
5
6public class AI_Trolley : AIAct
7{
8 public static int[][] DirList = new int[4][]
9 {
10 new int[4] { 0, 1, 3, 2 },
11 new int[4] { 1, 0, 2, 3 },
12 new int[4] { 2, 1, 3, 0 },
13 new int[4] { 3, 2, 0, 1 }
14 };
15
16 public static Vector2Int[] VecList = new Vector2Int[4]
17 {
18 new Vector2Int(0, -1),
19 new Vector2Int(1, 0),
20 new Vector2Int(0, 1),
21 new Vector2Int(-1, 0)
22 };
23
25
26 public bool running;
27
28 public int dir => trolley.owner.dir;
29
30 public override bool CancelWhenDamaged
31 {
32 get
33 {
34 if (owner != null)
35 {
36 if (owner.IsPC)
37 {
38 return owner.hp < owner.MaxHP / 3;
39 }
40 return true;
41 }
42 return false;
43 }
44 }
45
46 public override bool CancelWhenMoved => true;
47
48 public override bool CancelOnAggro => false;
49
50 public override bool ShowCursor => false;
51
52 public override bool CanManualCancel()
53 {
54 return true;
55 }
56
57 public override IEnumerable<Status> Run()
58 {
59 owner.Say("ride", owner, trolley.owner);
60 if (!trolley.HideChara)
61 {
62 owner.Talk("ride2");
63 }
64 while (true)
65 {
66 int nextDir = GetNextDir();
67 if (!trolley.owner.ExistsOnMap || nextDir == -1)
68 {
69 yield return Stop();
70 }
71 if (owner.rarity >= Rarity.Legendary && owner.FindNearestNewEnemy())
72 {
73 yield return Stop();
74 }
75 trolley.owner.dir = nextDir;
76 Point point = GetPoint(dir);
77 owner.SetDir(nextDir);
78 owner.PlayAnime(AnimeID.Truck);
79 string idSound = trolley.GetIdSound();
80 if (owner.IsPC)
81 {
83 {
84 owner.PlaySound(idSound);
85 }
86 else
87 {
88 EClass.Sound.Stop(idSound, Mathf.Max(1f, trolley.FadeDuration));
89 }
90 }
91 else if (!(EClass.pc.ai is AI_Trolley))
92 {
94 {
95 owner.PlaySound(idSound);
96 }
97 EClass.Sound.Stop(idSound, Mathf.Max(1f, trolley.FadeDuration));
98 }
99 foreach (Chara item in point.ListCharas().ToList())
100 {
101 owner.Kick(item, ignoreSelf: true, karmaLoss: false);
102 }
103 EClass._map.MoveCard(point, owner);
106 running = true;
107 yield return KeepRunning();
108 }
109 }
110
111 public Point GetPoint(int d, bool onlyValid = true)
112 {
113 Point point = new Point();
114 Point pos = trolley.owner.pos;
115 point.Set(pos.x + VecList[d].x, pos.z + VecList[d].y);
116 if (!point.IsValid || !point.IsInBounds || !point.HasRail || point.IsBlocked)
117 {
118 return null;
119 }
120 foreach (Thing thing in point.Things)
121 {
122 if (!thing.IsMultisize)
123 {
124 return null;
125 }
126 }
127 if (EClass.pc.pos.Equals(point))
128 {
129 return null;
130 }
131 return point;
132 }
133
134 public int GetNextDir()
135 {
136 int[] array = DirList[dir];
137 for (int i = 0; i < 3 + ((!running) ? 1 : 0); i++)
138 {
139 int num = array[i];
140 if (GetPoint(num) != null)
141 {
142 return num;
143 }
144 }
145 return -1;
146 }
147
148 public Status Stop(Action action = null)
149 {
151 if (owner != null)
152 {
153 owner.Say("ride_unride", owner, trolley.owner);
154 }
155 return Success();
156 }
157
158 public override void OnCancel()
159 {
160 Stop();
161 }
162}
AnimeID
Definition: AnimeID.cs:2
Rarity
Definition: Rarity.cs:2
Definition: AIAct.cs:6
new Chara owner
Definition: AIAct.cs:14
Status
Definition: AIAct.cs:8
Status KeepRunning()
Definition: AIAct.cs:335
override void OnCancel()
Definition: AI_Trolley.cs:158
override bool CancelOnAggro
Definition: AI_Trolley.cs:48
Status Stop(Action action=null)
Definition: AI_Trolley.cs:148
static Vector2Int[] VecList
Definition: AI_Trolley.cs:16
bool running
Definition: AI_Trolley.cs:26
int GetNextDir()
Definition: AI_Trolley.cs:134
override IEnumerable< Status > Run()
Definition: AI_Trolley.cs:57
Point GetPoint(int d, bool onlyValid=true)
Definition: AI_Trolley.cs:111
override bool CanManualCancel()
Definition: AI_Trolley.cs:52
override bool CancelWhenMoved
Definition: AI_Trolley.cs:46
override bool ShowCursor
Definition: AI_Trolley.cs:50
static int[][] DirList
Definition: AI_Trolley.cs:8
TraitTrolley trolley
Definition: AI_Trolley.cs:24
override bool CancelWhenDamaged
Definition: AI_Trolley.cs:31
virtual bool IsMultisize
Definition: Card.cs:2212
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:6578
void Talk(string idTopic, string ref1=null, string ref2=null, bool forceSync=false)
Definition: Card.cs:7138
Rarity rarity
Definition: Card.cs:317
bool ExistsOnMap
Definition: Card.cs:2137
void Kick(Point p, bool ignoreSelf=false, bool checkWall=true)
Definition: Card.cs:6252
Point pos
Definition: Card.cs:60
void MoveImmediate(Point p, bool focus=true, bool cancelAI=true)
Definition: Card.cs:6112
int dir
Definition: Card.cs:149
void PlayAnime(AnimeID id, bool force=false)
Definition: Card.cs:6597
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:7256
Definition: Chara.cs:10
AIAct ai
Definition: Chara.cs:206
override bool IsPC
Definition: Chara.cs:630
override void SetDir(int d)
Definition: Chara.cs:3704
bool FindNearestNewEnemy()
Definition: Chara.cs:6797
Definition: EClass.cs:6
static Map _map
Definition: EClass.cs:19
static Chara pc
Definition: EClass.cs:15
static SoundManager Sound
Definition: EClass.cs:47
void MoveCard(Point p, Card t)
Definition: Map.cs:853
Definition: Point.cs:9
Point Set(int _x, int _z)
Definition: Point.cs:503
bool HasRail
Definition: Point.cs:133
bool IsBlocked
Definition: Point.cs:363
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
bool Equals(int _x, int _z)
Definition: Point.cs:966
bool IsValid
Definition: Point.cs:88
bool IsInBounds
Definition: Point.cs:104
Definition: Thing.cs:8
virtual bool ShouldPlaySound(Point p)
Definition: TraitTrolley.cs:95
virtual string GetIdSound()
Definition: TraitTrolley.cs:65
virtual float FadeDuration
Definition: TraitTrolley.cs:18
virtual bool HideChara
Definition: TraitTrolley.cs:3
Card owner
Definition: Trait.cs:28