Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentSwimAroundBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
15 public float m_importanceLevel = 1f;
16
17 public Random m_random = new();
18
20
21 public override float ImportanceLevel => m_importanceLevel;
22
23 public virtual void Update(float dt) {
24 if (string.IsNullOrEmpty(m_stateMachine.CurrentState)) {
25 m_stateMachine.TransitionTo("Inactive");
26 }
27 if (m_random.Float(0f, 1f) < 0.05f * dt) {
28 m_importanceLevel = m_random.Float(1f, 3f);
29 }
30 if (IsActive) {
31 m_stateMachine.Update();
32 }
33 else {
34 m_stateMachine.TransitionTo("Inactive");
35 }
36 }
37
38 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
39 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
40 m_componentCreature = Entity.FindComponent<ComponentCreature>(true);
42 m_stateMachine.AddState(
43 "Inactive",
44 null,
45 delegate {
46 if (IsActive) {
47 m_stateMachine.TransitionTo("Swim");
48 }
49 },
50 null
51 );
52 m_stateMachine.AddState(
53 "Stuck",
54 delegate {
55 if (m_random.Float(0f, 1f) < 0.5f) {
57 }
58 m_stateMachine.TransitionTo("Swim");
59 },
60 null,
61 null
62 );
63 m_stateMachine.AddState(
64 "Swim",
65 delegate { m_componentPathfinding.Stop(); },
66 delegate {
67 _ = m_componentCreature.ComponentBody.Position;
68 if (!m_componentPathfinding.Destination.HasValue) {
69 Vector3? destination = FindDestination();
70 if (destination.HasValue) {
71 m_componentPathfinding.SetDestination(
72 destination,
73 m_random.Float(0.3f, 0.4f),
74 1f,
75 0,
76 false,
77 true,
78 false,
79 null
80 );
81 }
82 else {
84 }
85 }
86 else if (m_componentPathfinding.IsStuck) {
87 m_stateMachine.TransitionTo("Stuck");
88 }
89 },
90 null
91 );
92 }
93
94 public virtual Vector3? FindDestination() {
95 Vector3 vector = 0.5f * (m_componentCreature.ComponentBody.BoundingBox.Min + m_componentCreature.ComponentBody.BoundingBox.Max);
96 float num = 2f;
97 Vector3? result = null;
98 float num2 = m_random.Float(10f, 16f);
99 for (int i = 0; i < 16; i++) {
100 Vector2 vector2 = m_random.Vector2(1f, 1f);
101 float y = 0.3f * m_random.Float(-0.9f, 1f);
102 Vector3 v = Vector3.Normalize(new Vector3(vector2.X, y, vector2.Y));
103 Vector3 vector3 = vector + num2 * v;
104 TerrainRaycastResult? terrainRaycastResult = m_subsystemTerrain.Raycast(
105 vector,
106 vector3,
107 false,
108 false,
109 delegate(int value, float _) {
110 int num3 = Terrain.ExtractContents(value);
111 return !(BlocksManager.Blocks[num3] is WaterBlock);
112 }
113 );
114 if (!terrainRaycastResult.HasValue) {
115 if (num2 > num) {
116 result = vector3;
117 num = num2;
118 }
119 }
120 else if (terrainRaycastResult.Value.Distance > num) {
121 result = vector + v * terrainRaycastResult.Value.Distance;
122 num = terrainRaycastResult.Value.Distance;
123 }
124 }
125 return result;
126 }
127 }
128}
Engine.Vector3 Vector3
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
static int ExtractContents(int value)
ValuesDictionary ValuesDictionary
static Vector3 Normalize(Vector3 v)