Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentDumpRiderBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
16
17 public float m_importanceLevel;
18
19 public bool m_isEnabled;
20
21 public Random m_random = new();
22
24
25 public double m_dumpStartTime;
26
28
30
32
34
35 public override float ImportanceLevel => m_importanceLevel;
36
37 public virtual void Update(float dt) {
38 m_stateMachine.Update();
39 }
40
41 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
42 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
43 m_componentCreature = Entity.FindComponent<ComponentCreature>(true);
45 m_componentMount = Entity.FindComponent<ComponentMount>(true);
46 m_isEnabled = !Entity.ValuesDictionary.DatabaseObject.Name.EndsWith("_Saddled");
47 m_stateMachine.AddState(
48 "Inactive",
49 delegate {
51 m_rider = null;
52 },
53 delegate {
54 if (m_isEnabled
55 && m_random.Float(0f, 1f) < 1f * m_subsystemTime.GameTimeDelta
56 && m_componentMount.Rider != null) {
57 m_importanceLevel = 220f;
60 }
61 if (IsActive) {
62 m_stateMachine.TransitionTo("WildJumping");
63 }
64 },
65 null
66 );
67 m_stateMachine.AddState(
68 "WildJumping",
69 delegate {
70 m_componentCreature.ComponentCreatureSounds.PlayPainSound();
72 },
73 delegate {
74 if (!IsActive) {
75 m_stateMachine.TransitionTo("Inactive");
76 }
77 else if (m_componentMount.Rider == null) {
79 RunAway();
80 }
81 if (m_random.Float(0f, 1f) < 1f * m_subsystemTime.GameTimeDelta) {
82 m_componentCreature.ComponentCreatureSounds.PlayPainSound();
83 }
84 if (m_random.Float(0f, 1f) < 3f * m_subsystemTime.GameTimeDelta) {
85 m_walkOrder = new Vector2(m_random.Float(-0.5f, 0.5f), m_random.Float(-0.5f, 1.5f));
86 }
87 if (m_random.Float(0f, 1f) < 2.5f * m_subsystemTime.GameTimeDelta) {
88 m_turnOrder.X = m_random.Float(-1f, 1f);
89 }
90 if (m_random.Float(0f, 1f) < 2f * m_subsystemTime.GameTimeDelta) {
91 m_componentCreature.ComponentLocomotion.JumpOrder = m_random.Float(0.9f, 1f);
92 if (m_componentMount.Rider != null
93 && m_subsystemTime.GameTime - m_dumpStartTime > 3.0) {
94 if (m_random.Float(0f, 1f) < 0.05f) {
95 m_componentMount.Rider.StartDismounting();
96 m_componentMount.Rider.ComponentCreature.ComponentHealth.Injure(
97 m_random.Float(0.05f, 0.2f),
99 false,
100 "Thrown from a mount"
101 );
102 }
103 if (m_random.Float(0f, 1f) < 0.25f) {
104 m_componentMount.Rider.ComponentCreature.ComponentHealth.Injure(
105 0.05f,
107 false,
108 "Thrown from a mount"
109 );
110 }
111 }
112 }
113 if (m_random.Float(0f, 1f) < 4f * m_subsystemTime.GameTimeDelta) {
114 m_lookOrder = new Vector2(m_random.Float(-3f, 3f), m_lookOrder.Y);
115 }
116 if (m_random.Float(0f, 1f) < 0.25f * m_subsystemTime.GameTimeDelta) {
118 }
119 m_componentCreature.ComponentLocomotion.WalkOrder = m_walkOrder;
120 m_componentCreature.ComponentLocomotion.TurnOrder = m_turnOrder;
121 m_componentCreature.ComponentLocomotion.LookOrder = m_lookOrder;
122 },
123 null
124 );
125 m_stateMachine.AddState(
126 "BlindRacing",
127 delegate {
128 m_componentCreature.ComponentCreatureSounds.PlayPainSound();
129 m_componentPathfinding.SetDestination(
130 m_componentCreature.ComponentBody.Position + new Vector3(m_random.Float(-15f, 15f), 0f, m_random.Float(-15f, 15f)),
131 1f,
132 2f,
133 0,
134 false,
135 true,
136 false,
137 null
138 );
139 },
140 delegate {
141 if (!IsActive) {
142 m_stateMachine.TransitionTo("Inactive");
143 }
144 else if (m_componentMount.Rider == null) {
146 RunAway();
147 }
148 else if (!m_componentPathfinding.Destination.HasValue
149 || m_componentPathfinding.IsStuck) {
151 }
152 if (m_random.Float(0f, 1f) < 0.5f * m_subsystemTime.GameTimeDelta) {
153 m_componentCreature.ComponentLocomotion.JumpOrder = 1f;
154 m_componentCreature.ComponentCreatureSounds.PlayPainSound();
155 }
156 },
157 null
158 );
159 m_stateMachine.AddState(
160 "Stupor",
161 delegate {
162 m_componentCreature.ComponentCreatureSounds.PlayPainSound();
164 },
165 delegate {
166 if (!IsActive) {
167 m_stateMachine.TransitionTo("Inactive");
168 }
169 else if (m_componentMount.Rider == null) {
171 }
172 if (m_subsystemTime.PeriodicGameTimeEvent(2.0, 0.0)) {
174 }
175 },
176 null
177 );
178 m_stateMachine.TransitionTo("Inactive");
179 }
180
181 public virtual void TransitionToRandomDumpingBehavior() {
182 float num = m_random.Float(0f, 1f);
183 if (num < 0.5f) {
184 m_stateMachine.TransitionTo("WildJumping");
185 }
186 else if (num < 0.8f) {
187 m_stateMachine.TransitionTo("BlindRacing");
188 }
189 else {
190 m_stateMachine.TransitionTo("Stupor");
191 }
192 }
193
194 public virtual void RunAway() {
195 if (m_rider != null) {
196 Entity.FindComponent<ComponentRunAwayBehavior>()?.RunAwayFrom(m_rider.ComponentCreature.ComponentBody);
197 }
198 }
199 }
200}
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
ValuesDictionary ValuesDictionary