Elin Decompiled Documentation EA 23.102 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 CanManualCancel()
31 {
32 return true;
33 }
34
35 public override Point GetDestination()
36 {
37 if (destCard != null)
38 {
39 return destCard.pos;
40 }
41 return dest;
42 }
43
44 public AI_Goto(Point _dest, int dist, bool _ignoreConnection = false, bool _interaction = false)
45 {
46 dest.Set(_dest);
47 destDist = dist;
48 ignoreConnection = _ignoreConnection;
49 interaction = _interaction;
50 }
51
52 public AI_Goto(Card _card, int dist, bool _ignoreConnection = false, bool _interaction = false)
53 {
54 destCard = _card;
55 destDist = dist;
56 ignoreConnection = _ignoreConnection;
57 interaction = _interaction;
58 }
59
60 public override void OnReset()
61 {
62 owner.path.state = PathProgress.State.Idle;
63 }
64
65 public Status TryGoTo()
66 {
67 PathProgress path = owner.path;
68 Point pos = owner.pos;
69 if (owner.IsPC)
70 {
71 if (dest.x > EClass._map.bounds.maxX + 1)
72 {
73 dest.x = EClass._map.bounds.maxX + 1;
74 }
75 else if (dest.x < EClass._map.bounds.x - 1)
76 {
77 dest.x = EClass._map.bounds.x - 1;
78 }
79 if (dest.z > EClass._map.bounds.maxZ + 1)
80 {
81 dest.z = EClass._map.bounds.maxZ + 1;
82 }
83 else if (dest.z < EClass._map.bounds.z - 1)
84 {
85 dest.z = EClass._map.bounds.z - 1;
86 }
87 }
88 if ((repath || (owner.IsPC && ActionMode.IsAdv)) && path.state == PathProgress.State.Idle)
89 {
91 repath = false;
92 }
93 switch (path.state)
94 {
95 case PathProgress.State.Idle:
97 break;
98 case PathProgress.State.Fail:
99 return Cancel();
100 case PathProgress.State.PathReady:
101 {
102 if (path.nodeIndex < 0)
103 {
104 return Cancel();
105 }
106 PathFinderNode pathFinderNode = path.nodes[path.nodeIndex];
107 if (owner.IsPC && ActionMode.IsAdv && path.nodeIndex > 2)
108 {
110 }
111 Point shared = Point.GetShared(pathFinderNode.X, pathFinderNode.Z);
112 if (shared.x == owner.pos.x && shared.z == owner.pos.z && path.nodeIndex > 0 && !shared.cell.HasLadder && !owner.Cell.HasLadder)
113 {
114 path.nodeIndex--;
115 pathFinderNode = path.nodes[path.nodeIndex];
116 shared.Set(pathFinderNode.X, pathFinderNode.Z);
117 }
118 if (shared.HasChara && !owner.IsPC)
119 {
120 waitCount++;
121 if (waitCount < 3 || EClass.rnd(5) != 0)
122 {
123 return Status.Running;
124 }
125 }
126 waitCount = 0;
127 Card.MoveResult moveResult = owner.TryMove(shared);
128 if (owner == null)
129 {
130 return Status.Running;
131 }
132 if (moveResult == Card.MoveResult.Fail || moveResult == Card.MoveResult.Door)
133 {
134 if (owner.IsPC && ActionMode.IsAdv)
135 {
136 return Cancel();
137 }
138 return Restart();
139 }
140 if (!owner.pos.Equals(shared))
141 {
142 path.state = PathProgress.State.Idle;
143 repath = true;
144 }
145 path.nodeIndex--;
147 {
148 return Success();
149 }
150 break;
151 }
152 }
153 return Status.Running;
154 }
155
157 {
158 if (destCard != null)
159 {
160 int num = destCard.pos.Distance(owner.pos);
161 if (interaction && num == 1 && owner.CanInteractTo(owner.pos))
162 {
163 return true;
164 }
165 return num <= destDist;
166 }
167 int num2 = Util.Distance(owner.pos.x, owner.pos.z, dest.x, dest.z);
168 if (interaction && num2 == 1 && owner.CanInteractTo(dest))
169 {
170 return true;
171 }
172 return num2 <= destDist;
173 }
174
175 public override IEnumerable<Status> Run()
176 {
177 if (owner.host != null)
178 {
179 yield return Cancel();
180 }
181 while (true)
182 {
183 if (destCard != null)
184 {
186 }
187 while (owner.path.state == PathProgress.State.Searching)
188 {
189 yield return Status.Running;
190 }
191 owner.path.state = PathProgress.State.Idle;
193 {
194 yield return Success();
195 }
196 EClass.player.enemySpotted = false;
197 while (true)
198 {
199 if (owner.IsPC)
200 {
202 {
203 yield return Cancel();
204 }
206 {
207 EClass.player.enemySpotted = false;
208 Msg.Say("enemy_spotted");
209 yield return Cancel();
210 }
211 }
212 yield return TryGoTo();
213 if (destCard != null)
214 {
215 Point destination = GetDestination();
216 int num = dest.Distance(destination);
217 if (num > 3 && num < 20)
218 {
219 break;
220 }
221 }
222 }
223 repath = true;
224 owner.path.state = PathProgress.State.Idle;
225 }
226 }
227}
Definition: AIAct.cs:6
virtual bool PushChara
Definition: AIAct.cs:82
virtual Status Cancel()
Definition: AIAct.cs:291
new Chara owner
Definition: AIAct.cs:14
Status
Definition: AIAct.cs:8
AIAct parent
Definition: AIAct.cs:22
Status Restart()
Definition: AIAct.cs:237
bool interaction
Definition: AI_Goto.cs:16
override Point GetDestination()
Definition: AI_Goto.cs:35
int waitCount
Definition: AI_Goto.cs:12
bool IsDestinationReached()
Definition: AI_Goto.cs:156
override bool PushChara
Definition: AI_Goto.cs:28
AI_Goto(Card _card, int dist, bool _ignoreConnection=false, bool _interaction=false)
Definition: AI_Goto.cs:52
bool ignoreConnection
Definition: AI_Goto.cs:14
Point dest
Definition: AI_Goto.cs:8
int destDist
Definition: AI_Goto.cs:10
AI_Goto(Point _dest, int dist, bool _ignoreConnection=false, bool _interaction=false)
Definition: AI_Goto.cs:44
override bool UseTurbo
Definition: AI_Goto.cs:20
override void OnReset()
Definition: AI_Goto.cs:60
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:30
override IEnumerable< Status > Run()
Definition: AI_Goto.cs:175
Status TryGoTo()
Definition: AI_Goto.cs:65
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:55
MoveResult
Definition: Card.cs:13
Cell Cell
Definition: Card.cs:1931
bool HasLadder
Definition: Cell.cs:839
override bool IsPC
Definition: Chara.cs:597
Chara host
Definition: Chara.cs:33
PathProgress path
Definition: Chara.cs:89
MoveResult TryMove(Point newPoint, bool allowDestroyPath=true)
Definition: Chara.cs:2422
bool CanInteractTo(Card c)
Definition: Chara.cs:2225
Definition: EClass.cs:5
static int rnd(int a)
Definition: EClass.cs:50
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
static Player player
Definition: EClass.cs:12
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:2331
bool enemySpotted
Definition: Player.cs:984
Definition: Point.cs:9
static Point GetShared(int x, int z)
Definition: Point.cs:366
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
int Distance(Point p)
Definition: Point.cs:953
Cell cell
Definition: Point.cs:51
bool HasChara
Definition: Point.cs:226
virtual bool IsRegion
Definition: Spatial.cs:501