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