Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentRandomFeedBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
16
17 public Random m_random = new();
18
19 public float m_importanceLevel;
20
21 public float m_feedTime;
22
23 public float m_waitTime;
24
26
27 public bool m_autoFeed;
28
30
31 public override float ImportanceLevel => m_importanceLevel;
32
33 public void Feed(Vector3 feedPosition) {
35 m_feedPosition = feedPosition;
36 }
37
38 public virtual void Update(float dt) {
39 m_stateMachine.Update();
40 }
41
42 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
43 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
44 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
45 m_componentCreature = Entity.FindComponent<ComponentCreature>(true);
47 m_autoFeed = valuesDictionary.GetValue<bool>("AutoFeed");
48 m_stateMachine.AddState(
49 "Inactive",
50 delegate { m_importanceLevel = m_random.Float(0f, 1f); },
51 delegate {
52 if (m_random.Float(0f, 1f) < 0.05f * m_subsystemTime.GameTimeDelta) {
53 m_importanceLevel = m_random.Float(1f, 3f);
54 }
55 if (IsActive) {
56 m_stateMachine.TransitionTo("Move");
57 }
58 },
59 null
60 );
61 m_stateMachine.AddState(
62 "Move",
63 delegate {
64 Vector3 value;
65 if (m_feedPosition.HasValue) {
66 value = m_feedPosition.Value;
67 }
68 else {
69 Vector3 position = m_componentCreature.ComponentBody.Position;
70 Vector3 forward = m_componentCreature.ComponentBody.Matrix.Forward;
71 float num4 = m_random.Float(0f, 1f) < 0.2f ? 5f : 1.5f;
72 value = position + num4 * forward + 0.5f * num4 * new Vector3(m_random.Float(-1f, 1f), 0f, m_random.Float(-1f, 1f));
73 }
74 value.Y = m_subsystemTerrain.Terrain.GetTopHeight(Terrain.ToCell(value.X), Terrain.ToCell(value.Z)) + 1;
75 m_componentPathfinding.SetDestination(
76 value,
77 m_random.Float(0.25f, 0.35f),
78 1f,
79 0,
80 false,
81 true,
82 false,
83 null
84 );
85 },
86 delegate {
87 if (!m_componentPathfinding.Destination.HasValue) {
88 float num3 = m_random.Float(0f, 1f);
89 if (num3 < 0.33f) {
90 m_stateMachine.TransitionTo("Inactive");
91 }
92 else if (num3 < 0.66f) {
93 m_stateMachine.TransitionTo("LookAround");
94 }
95 else {
96 m_stateMachine.TransitionTo("Feed");
97 }
98 }
99 else if (!IsActive
100 || m_componentPathfinding.IsStuck) {
101 m_stateMachine.TransitionTo("Inactive");
102 }
103 },
104 delegate { m_feedPosition = null; }
105 );
106 m_stateMachine.AddState(
107 "LookAround",
108 delegate { m_waitTime = m_random.Float(1f, 2f); },
109 delegate {
110 m_componentCreature.ComponentCreatureModel.LookRandomOrder = true;
111 m_waitTime -= m_subsystemTime.GameTimeDelta;
112 if (m_waitTime <= 0f) {
113 float num2 = m_random.Float(0f, 1f);
114 if (num2 < 0.25f) {
115 m_stateMachine.TransitionTo("Inactive");
116 }
117 if (num2 < 0.5f) {
118 m_stateMachine.TransitionTo(null);
119 m_stateMachine.TransitionTo("LookAround");
120 }
121 else if (num2 < 0.75f) {
122 m_stateMachine.TransitionTo("Move");
123 if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta) {
124 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(false);
125 }
126 }
127 else {
128 m_stateMachine.TransitionTo("Feed");
129 }
130 }
131 if (!IsActive) {
132 m_stateMachine.TransitionTo("Inactive");
133 }
134 },
135 null
136 );
137 m_stateMachine.AddState(
138 "Feed",
139 delegate { m_feedTime = m_random.Float(4f, 6f); },
140 delegate {
141 m_feedTime -= m_subsystemTime.GameTimeDelta;
142 if (m_componentCreature.ComponentBody.StandingOnValue.HasValue) {
143 m_componentCreature.ComponentCreatureModel.FeedOrder = true;
144 if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta) {
145 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(false);
146 }
147 if (m_random.Float(0f, 1f) < 1.5f * m_subsystemTime.GameTimeDelta) {
148 m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(2f);
149 }
150 }
151 if (m_feedTime <= 0f) {
152 if (m_autoFeed) {
153 float num = m_random.Float(0f, 1f);
154 if (num < 0.33f) {
155 m_stateMachine.TransitionTo("Inactive");
156 }
157 if (num < 0.66f) {
158 m_stateMachine.TransitionTo("Move");
159 }
160 else {
161 m_stateMachine.TransitionTo("LookAround");
162 }
163 }
164 else {
166 }
167 }
168 if (!IsActive) {
169 m_stateMachine.TransitionTo("Inactive");
170 }
171 },
172 null
173 );
174 m_stateMachine.TransitionTo("Inactive");
175 }
176 }
177}
Engine.Vector3 Vector3
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
static int ToCell(float x)
ValuesDictionary ValuesDictionary