Elin Decompiled Documentation EA 23.289 Nightly
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 {
82 owner.PlaySound(idSound);
83 }
84 else if (!(EClass.pc.ai is AI_Trolley))
85 {
86 owner.PlaySound(idSound);
87 EClass.Sound.Stop(idSound, Mathf.Max(1f, trolley.FadeDuration));
88 }
89 foreach (Chara item in point.ListCharas().ToList())
90 {
91 owner.Kick(item, ignoreSelf: true, karmaLoss: false);
92 }
93 EClass._map.MoveCard(point, owner);
96 running = true;
97 yield return KeepRunning();
98 }
99 }
100
101 public Point GetPoint(int d, bool onlyValid = true)
102 {
103 Point point = new Point();
104 Point pos = trolley.owner.pos;
105 point.Set(pos.x + VecList[d].x, pos.z + VecList[d].y);
106 if (!point.IsValid || !point.IsInBounds || !point.HasRail || point.IsBlocked)
107 {
108 return null;
109 }
110 foreach (Thing thing in point.Things)
111 {
112 if (!thing.IsMultisize)
113 {
114 return null;
115 }
116 }
117 if (EClass.pc.pos.Equals(point))
118 {
119 return null;
120 }
121 return point;
122 }
123
124 public int GetNextDir()
125 {
126 int[] array = DirList[dir];
127 for (int i = 0; i < 3 + ((!running) ? 1 : 0); i++)
128 {
129 int num = array[i];
130 if (GetPoint(num) != null)
131 {
132 return num;
133 }
134 }
135 return -1;
136 }
137
138 public Status Stop(Action action = null)
139 {
141 if (owner != null)
142 {
143 owner.Say("ride_unride", owner, trolley.owner);
144 }
145 return Success();
146 }
147
148 public override void OnCancel()
149 {
150 Stop();
151 }
152}
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:148
override bool CancelOnAggro
Definition: AI_Trolley.cs:48
Status Stop(Action action=null)
Definition: AI_Trolley.cs:138
static Vector2Int[] VecList
Definition: AI_Trolley.cs:16
bool running
Definition: AI_Trolley.cs:26
int GetNextDir()
Definition: AI_Trolley.cs:124
override IEnumerable< Status > Run()
Definition: AI_Trolley.cs:57
Point GetPoint(int d, bool onlyValid=true)
Definition: AI_Trolley.cs:101
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:2198
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:6375
void Talk(string idTopic, string ref1=null, string ref2=null, bool forceSync=false)
Definition: Card.cs:6935
Rarity rarity
Definition: Card.cs:315
bool ExistsOnMap
Definition: Card.cs:2123
void Kick(Point p, bool ignoreSelf=false, bool checkWall=true)
Definition: Card.cs:6057
Point pos
Definition: Card.cs:60
void MoveImmediate(Point p, bool focus=true, bool cancelAI=true)
Definition: Card.cs:5935
int dir
Definition: Card.cs:147
void PlayAnime(AnimeID id, bool force=false)
Definition: Card.cs:6394
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:7052
Definition: Chara.cs:10
AIAct ai
Definition: Chara.cs:204
override bool IsPC
Definition: Chara.cs:626
override void SetDir(int d)
Definition: Chara.cs:3576
bool FindNearestNewEnemy()
Definition: Chara.cs:6656
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:841
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:960
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:28