Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentFlyAroundBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
15 public float m_angle;
16
17 public float m_importanceLevel = 1f;
18
19 public Random m_random = new();
20
22
23 public override float ImportanceLevel => m_importanceLevel;
24
25 public virtual void Update(float dt) {
26 if (string.IsNullOrEmpty(m_stateMachine.CurrentState)) {
27 m_stateMachine.TransitionTo("Inactive");
28 }
29 if (m_random.Float(0f, 1f) < 0.05f * dt) {
30 m_importanceLevel = m_random.Float(1f, 2f);
31 }
32 if (IsActive) {
33 m_stateMachine.Update();
34 }
35 else {
36 m_stateMachine.TransitionTo("Inactive");
37 }
38 }
39
40 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
41 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
42 m_componentCreature = Entity.FindComponent<ComponentCreature>(true);
44 m_stateMachine.AddState(
45 "Inactive",
46 null,
47 delegate {
48 if (IsActive) {
49 m_stateMachine.TransitionTo("Fly");
50 }
51 },
52 null
53 );
54 m_stateMachine.AddState(
55 "Stuck",
56 delegate {
57 m_stateMachine.TransitionTo("Fly");
58 if (m_random.Float(0f, 1f) < 0.5f) {
59 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(false);
61 }
62 },
63 null,
64 null
65 );
66 m_stateMachine.AddState(
67 "Fly",
68 delegate {
69 m_angle = m_random.Float(0f, (float)Math.PI * 2f);
71 },
72 delegate {
73 Vector3 position = m_componentCreature.ComponentBody.Position;
74 if (!m_componentPathfinding.Destination.HasValue) {
75 float num = m_random.Float(0f, 1f) < 0.2f ? m_random.Float(0.4f, 0.6f) : 0f - m_random.Float(0.4f, 0.6f);
78 Vector3 value = position + new Vector3(vector.X, 0f, vector.Y) * 10f;
79 value.Y = EstimateHeight(new Vector2(value.X, value.Z), 8) + m_random.Float(3f, 5f);
80 m_componentPathfinding.SetDestination(
81 value,
82 m_random.Float(0.6f, 1.05f),
83 6f,
84 0,
85 false,
86 true,
87 false,
88 null
89 );
90 if (m_random.Float(0f, 1f) < 0.15f) {
91 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(false);
92 }
93 }
94 else if (m_componentPathfinding.IsStuck) {
95 m_stateMachine.TransitionTo("Stuck");
96 }
97 },
98 null
99 );
100 }
101
102 public virtual float EstimateHeight(Vector2 position, int radius) {
103 int num = 0;
104 for (int i = 0; i < 15; i++) {
105 int x = Terrain.ToCell(position.X) + m_random.Int(-radius, radius);
106 int z = Terrain.ToCell(position.Y) + m_random.Int(-radius, radius);
107 num = MathUtils.Max(num, m_subsystemTerrain.Terrain.GetTopHeight(x, z));
108 }
109 return num;
110 }
111 }
112}
Engine.Vector3 Vector3
static float NormalizeAngle(float angle)
static int Max(int x1, int x2)
virtual float EstimateHeight(Vector2 position, int radius)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
static int ToCell(float x)
ValuesDictionary ValuesDictionary
static Vector2 CreateFromAngle(float angle)