Elin Decompiled Documentation EA 23.350.1 Nightly
Loading...
Searching...
No Matches
AI_Goto.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using Algorithms;
3
4public class AI_Goto : AIAct
5{
6 public Card destCard;
7
8 public Point dest = new Point();
9
10 public int destDist;
11
12 public int waitCount;
13
14 public bool ignoreConnection;
15
16 public bool interaction;
17
18 public bool repath;
19
20 public override bool UseTurbo => false;
21
22 public override bool CancelWhenDamaged => !EClass._zone.IsRegion;
23
24 public override bool CancelWhenMoved => true;
25
26 public override bool InformCancel => false;
27
28 public override bool PushChara => parent?.PushChara ?? true;
29
30 public override bool ShouldEndMimicry => false;
31
32 public override bool CanManualCancel()
33 {
34 return true;
35 }
36
37 public override Point GetDestination()
38 {
39 if (destCard != null)
40 {
41 return destCard.pos;
42 }
43 return dest;
44 }
45
46 public AI_Goto(Point _dest, int dist, bool _ignoreConnection = false, bool _interaction = false)
47 {
48 dest.Set(_dest);
49 destDist = dist;
50 ignoreConnection = _ignoreConnection;
51 interaction = _interaction;
52 }
53
54 public AI_Goto(Card _card, int dist, bool _ignoreConnection = false, bool _interaction = false)
55 {
56 destCard = _card;
57 destDist = dist;
58 ignoreConnection = _ignoreConnection;
59 interaction = _interaction;
60 }
61
62 public override void OnReset()
63 {
64 owner.path.state = PathProgress.State.Idle;
65 }
66
67 public Status TryGoTo()
68 {
69 PathProgress path = owner.path;
70 Point pos = owner.pos;
71 if (owner.IsPC)
72 {
73 if (dest.x > EClass._map.bounds.maxX + 1)
74 {
75 dest.x = EClass._map.bounds.maxX + 1;
76 }
77 else if (dest.x < EClass._map.bounds.x - 1)
78 {
79 dest.x = EClass._map.bounds.x - 1;
80 }
81 if (dest.z > EClass._map.bounds.maxZ + 1)
82 {
83 dest.z = EClass._map.bounds.maxZ + 1;
84 }
85 else if (dest.z < EClass._map.bounds.z - 1)
86 {
87 dest.z = EClass._map.bounds.z - 1;
88 }
89 }
90 if ((repath || (owner.IsPC && ActionMode.IsAdv)) && path.state == PathProgress.State.Idle)
91 {
93 repath = false;
94 }
95 switch (path.state)
96 {
97 case PathProgress.State.Idle:
99 break;
100 case PathProgress.State.Fail:
101 return Cancel();
102 case PathProgress.State.PathReady:
103 {
104 if (path.nodeIndex < 0)
105 {
106 return Cancel();
107 }
108 PathFinderNode pathFinderNode = path.nodes[path.nodeIndex];
109 if (owner.IsPC && ActionMode.IsAdv && path.nodeIndex > 2)
110 {
112 }
113 Point shared = Point.GetShared(pathFinderNode.X, pathFinderNode.Z);
114 if (shared.x == owner.pos.x && shared.z == owner.pos.z && path.nodeIndex > 0 && !shared.cell.HasLadder && !owner.Cell.HasLadder)
115 {
116 path.nodeIndex--;
117 pathFinderNode = path.nodes[path.nodeIndex];
118 shared.Set(pathFinderNode.X, pathFinderNode.Z);
119 }
120 if (!shared.IsValid)
121 {
122 return Cancel();
123 }
124 if (shared.HasChara && !owner.IsPC)
125 {
126 waitCount++;
127 if (waitCount < 3 || EClass.rnd(5) != 0)
128 {
129 return Status.Running;
130 }
131 }
132 waitCount = 0;
133 Card.MoveResult moveResult = owner.TryMove(shared);
134 if (owner == null)
135 {
136 return Status.Running;
137 }
138 if (moveResult == Card.MoveResult.Fail || (uint)(moveResult - 2) <= 1u)
139 {
140 if (owner.IsPC && ActionMode.IsAdv)
141 {
142 return Cancel();
143 }
144 return Restart();
145 }
146 if (!owner.pos.Equals(shared))
147 {
148 path.state = PathProgress.State.Idle;
149 repath = true;
150 }
151 path.nodeIndex--;
153 {
154 return Success();
155 }
156 break;
157 }
158 }
159 return Status.Running;
160 }
161
163 {
164 if (destCard != null)
165 {
166 int num = destCard.pos.Distance(owner.pos);
167 if (interaction && num == 1 && owner.CanInteractTo(owner.pos))
168 {
169 return true;
170 }
171 return num <= destDist;
172 }
173 int num2 = Util.Distance(owner.pos.x, owner.pos.z, dest.x, dest.z);
174 if (interaction && num2 == 1 && owner.CanInteractTo(dest))
175 {
176 return true;
177 }
178 return num2 <= destDist;
179 }
180
181 public override IEnumerable<Status> Run()
182 {
183 if (owner.host != null)
184 {
185 yield return Cancel();
186 }
187 while (true)
188 {
189 if (destCard != null)
190 {
192 }
193 while (owner.path.state == PathProgress.State.Searching)
194 {
195 yield return Status.Running;
196 }
197 owner.path.state = PathProgress.State.Idle;
199 {
200 yield return Success();
201 }
202 EClass.player.enemySpotted = false;
203 while (true)
204 {
205 if (owner.IsPC)
206 {
208 {
209 yield return Cancel();
210 }
212 {
213 EClass.player.enemySpotted = false;
214 Msg.Say("enemy_spotted");
215 yield return Cancel();
216 }
217 }
218 yield return TryGoTo();
219 if (destCard != null)
220 {
221 Point destination = GetDestination();
222 int num = dest.Distance(destination);
223 if (num > 3 && num < 20)
224 {
225 break;
226 }
227 }
228 }
229 repath = true;
230 owner.path.state = PathProgress.State.Idle;
231 }
232 }
233}
Definition: AIAct.cs:6
virtual bool PushChara
Definition: AIAct.cs:82
virtual Status Cancel()
Definition: AIAct.cs:305
new Chara owner
Definition: AIAct.cs:14
Status
Definition: AIAct.cs:8
AIAct parent
Definition: AIAct.cs:22
Status Restart()
Definition: AIAct.cs:251
bool interaction
Definition: AI_Goto.cs:16
override Point GetDestination()
Definition: AI_Goto.cs:37
int waitCount
Definition: AI_Goto.cs:12
bool IsDestinationReached()
Definition: AI_Goto.cs:162
override bool PushChara
Definition: AI_Goto.cs:28
AI_Goto(Card _card, int dist, bool _ignoreConnection=false, bool _interaction=false)
Definition: AI_Goto.cs:54
bool ignoreConnection
Definition: AI_Goto.cs:14
Point dest
Definition: AI_Goto.cs:8
override bool ShouldEndMimicry
Definition: AI_Goto.cs:30
int destDist
Definition: AI_Goto.cs:10
AI_Goto(Point _dest, int dist, bool _ignoreConnection=false, bool _interaction=false)
Definition: AI_Goto.cs:46
override bool UseTurbo
Definition: AI_Goto.cs:20
override void OnReset()
Definition: AI_Goto.cs:62
Card destCard
Definition: AI_Goto.cs:6
bool repath
Definition: AI_Goto.cs:18
override bool CancelWhenMoved
Definition: AI_Goto.cs:24
override bool InformCancel
Definition: AI_Goto.cs:26
override bool CancelWhenDamaged
Definition: AI_Goto.cs:22
override bool CanManualCancel()
Definition: AI_Goto.cs:32
override IEnumerable< Status > Run()
Definition: AI_Goto.cs:181
Status TryGoTo()
Definition: AI_Goto.cs:67
void SetTurbo(int mtp=-1)
Definition: AM_Adv.cs:1091
static bool IsAdv
Definition: ActionMode.cs:117
static AM_Adv Adv
Definition: ActionMode.cs:15
Definition: Card.cs:11
Point pos
Definition: Card.cs:60
MoveResult
Definition: Card.cs:13
Cell Cell
Definition: Card.cs:2107
bool HasLadder
Definition: Cell.cs:875
override bool IsPC
Definition: Chara.cs:630
Chara host
Definition: Chara.cs:33
override MoveResult TryMove(Point newPoint, bool allowDestroyPath=true)
Definition: Chara.cs:2940
PathProgress path
Definition: Chara.cs:92
bool CanInteractTo(Card c)
Definition: Chara.cs:2779
Definition: EClass.cs:6
static Zone _zone
Definition: EClass.cs:21
static Map _map
Definition: EClass.cs:19
static int rnd(long a)
Definition: EClass.cs:59
static Player player
Definition: EClass.cs:13
int maxZ
Definition: MapBounds.cs:17
int maxX
Definition: MapBounds.cs:14
int x
Definition: MapBounds.cs:8
MapBounds bounds
Definition: Map.cs:55
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
void RequestPath(Point _startPoint, Point _destPoint, int _destDist, bool _ignoreConnection, int _searchLimit=-1)
Definition: PathProgress.cs:51
List< PathFinderNode > nodes
Definition: PathProgress.cs:16
void RequestPathImmediate(Point _startPoint, Point _destPoint, int _destDist, bool _ignoreConnection, int _searchLimit=-1)
Definition: PathProgress.cs:61
bool TooHeavyToMove()
Definition: Player.cs:2679
bool enemySpotted
Definition: Player.cs:1256
Definition: Point.cs:9
static Point GetShared(int x, int z)
Definition: Point.cs:390
Point Set(int _x, int _z)
Definition: Point.cs:503
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
int Distance(Point p)
Definition: Point.cs:995
Cell cell
Definition: Point.cs:51
bool HasChara
Definition: Point.cs:238
virtual bool IsRegion
Definition: Spatial.cs:515