Elin Decompiled Documentation EA 23.272 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.HasChara && !owner.IsPC)
121 {
122 waitCount++;
123 if (waitCount < 3 || EClass.rnd(5) != 0)
124 {
125 return Status.Running;
126 }
127 }
128 waitCount = 0;
129 Card.MoveResult moveResult = owner.TryMove(shared);
130 if (owner == null)
131 {
132 return Status.Running;
133 }
134 if (moveResult == Card.MoveResult.Fail || (uint)(moveResult - 2) <= 1u)
135 {
136 if (owner.IsPC && ActionMode.IsAdv)
137 {
138 return Cancel();
139 }
140 return Restart();
141 }
142 if (!owner.pos.Equals(shared))
143 {
144 path.state = PathProgress.State.Idle;
145 repath = true;
146 }
147 path.nodeIndex--;
149 {
150 return Success();
151 }
152 break;
153 }
154 }
155 return Status.Running;
156 }
157
159 {
160 if (destCard != null)
161 {
162 int num = destCard.pos.Distance(owner.pos);
163 if (interaction && num == 1 && owner.CanInteractTo(owner.pos))
164 {
165 return true;
166 }
167 return num <= destDist;
168 }
169 int num2 = Util.Distance(owner.pos.x, owner.pos.z, dest.x, dest.z);
170 if (interaction && num2 == 1 && owner.CanInteractTo(dest))
171 {
172 return true;
173 }
174 return num2 <= destDist;
175 }
176
177 public override IEnumerable<Status> Run()
178 {
179 if (owner.host != null)
180 {
181 yield return Cancel();
182 }
183 while (true)
184 {
185 if (destCard != null)
186 {
188 }
189 while (owner.path.state == PathProgress.State.Searching)
190 {
191 yield return Status.Running;
192 }
193 owner.path.state = PathProgress.State.Idle;
195 {
196 yield return Success();
197 }
198 EClass.player.enemySpotted = false;
199 while (true)
200 {
201 if (owner.IsPC)
202 {
204 {
205 yield return Cancel();
206 }
208 {
209 EClass.player.enemySpotted = false;
210 Msg.Say("enemy_spotted");
211 yield return Cancel();
212 }
213 }
214 yield return TryGoTo();
215 if (destCard != null)
216 {
217 Point destination = GetDestination();
218 int num = dest.Distance(destination);
219 if (num > 3 && num < 20)
220 {
221 break;
222 }
223 }
224 }
225 repath = true;
226 owner.path.state = PathProgress.State.Idle;
227 }
228 }
229}
Definition: AIAct.cs:6
virtual bool PushChara
Definition: AIAct.cs:82
virtual Status Cancel()
Definition: AIAct.cs:295
new Chara owner
Definition: AIAct.cs:14
Status
Definition: AIAct.cs:8
AIAct parent
Definition: AIAct.cs:22
Status Restart()
Definition: AIAct.cs:241
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:158
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:177
Status TryGoTo()
Definition: AI_Goto.cs:67
void SetTurbo(int mtp=-1)
Definition: AM_Adv.cs:1040
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:2056
bool HasLadder
Definition: Cell.cs:839
override bool IsPC
Definition: Chara.cs:614
Chara host
Definition: Chara.cs:33
override MoveResult TryMove(Point newPoint, bool allowDestroyPath=true)
Definition: Chara.cs:2712
PathProgress path
Definition: Chara.cs:92
bool CanInteractTo(Card c)
Definition: Chara.cs:2551
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:52
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:2560
bool enemySpotted
Definition: Player.cs:1183
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:960
int Distance(Point p)
Definition: Point.cs:989
Cell cell
Definition: Point.cs:51
bool HasChara
Definition: Point.cs:238
virtual bool IsRegion
Definition: Spatial.cs:515