Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentCattleDriveBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
16
18
19 public Random m_random = new();
20
21 public float m_importanceLevel;
22
24
26
27 public override float ImportanceLevel => m_importanceLevel;
28
29 public virtual void HearNoise(ComponentBody sourceBody, Vector3 sourcePosition, float loudness) {
30 if (loudness >= 0.5f) {
31 Vector3 v = m_componentCreature.ComponentBody.Position - sourcePosition;
32 m_driveVector += Vector3.Normalize(v) * MathUtils.Max(8f - 0.25f * v.Length(), 1f);
33 float num = 12f + m_random.Float(0f, 3f);
34 if (m_driveVector.Length() > num) {
36 }
37 }
38 }
39
40 public virtual void Update(float dt) {
41 m_stateMachine.Update();
42 }
43
44 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
45 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
47 m_componentCreature = Entity.FindComponent<ComponentCreature>(true);
50 m_stateMachine.AddState(
51 "Inactive",
52 delegate {
55 },
56 delegate {
57 if (IsActive) {
58 m_stateMachine.TransitionTo("Drive");
59 }
60 if (m_driveVector.Length() > 3f) {
62 }
64 },
65 null
66 );
67 m_stateMachine.AddState(
68 "Drive",
69 delegate { },
70 delegate {
71 if (!IsActive) {
72 m_stateMachine.TransitionTo("Inactive");
73 }
74 if (m_driveVector.LengthSquared() < 1f
75 || m_componentPathfinding.IsStuck) {
77 }
78 if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta) {
79 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(true);
80 }
81 if (m_random.Float(0f, 1f) < 3f * m_subsystemTime.GameTimeDelta) {
83 float speed = MathUtils.Saturate(0.2f * v.Length());
84 m_componentPathfinding.SetDestination(
85 m_componentCreature.ComponentBody.Position + 15f * Vector3.Normalize(v),
86 speed,
87 5f,
88 0,
89 false,
90 true,
91 false,
92 null
93 );
94 }
96 },
97 null
98 );
99 m_stateMachine.TransitionTo("Inactive");
100 }
101
102 public virtual void FadeDriveVector() {
103 float num = m_driveVector.Length();
104 if (num > 0.1f) {
105 m_driveVector -= m_subsystemTime.GameTimeDelta * m_driveVector / num;
106 }
107 }
108
110 int num = 1;
111 Vector3 position = m_componentCreature.ComponentBody.Position;
112 Vector3 v = position;
113 Vector3 driveVector = m_driveVector;
114 foreach (ComponentCreature creature in m_subsystemCreatureSpawn.Creatures) {
115 if (creature != m_componentCreature
116 && creature.ComponentHealth.Health > 0f) {
117 ComponentCattleDriveBehavior componentCattleDriveBehavior = creature.Entity.FindComponent<ComponentCattleDriveBehavior>();
118 if (componentCattleDriveBehavior != null
119 && componentCattleDriveBehavior.m_componentHerdBehavior.HerdName == m_componentHerdBehavior.HerdName) {
120 Vector3 position2 = creature.ComponentBody.Position;
121 if (Vector3.DistanceSquared(position, position2) < 625f) {
122 v += position2;
123 driveVector += componentCattleDriveBehavior.m_driveVector;
124 num++;
125 }
126 }
127 }
128 }
129 v /= num;
130 driveVector /= num;
131 Vector3 v2 = v - position;
132 float s = MathUtils.Max(1.5f * v2.Length() - 3f, 0f);
133 return 0.33f * m_driveVector + 0.66f * driveVector + s * Vector3.Normalize(v2);
134 }
135 }
136}
static float Saturate(float x)
static int Max(int x1, int x2)
virtual void HearNoise(ComponentBody sourceBody, Vector3 sourcePosition, float loudness)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
ValuesDictionary ValuesDictionary
Component FindComponent(Type type, string name, bool throwOnError)
static float DistanceSquared(Vector3 v1, Vector3 v2)
static Vector3 Normalize(Vector3 v)
static readonly Vector3 Zero