Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentRandomPeckBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
16
17 public float m_importanceLevel = 1f;
18
19 public float m_dt;
20
21 public float m_peckTime;
22
23 public float m_waitTime;
24
25 public Random m_random = new();
26
28
29 public override float ImportanceLevel => m_importanceLevel;
30
31 public virtual void Update(float dt) {
32 if (string.IsNullOrEmpty(m_stateMachine.CurrentState)) {
33 m_stateMachine.TransitionTo("Move");
34 }
35 if (m_random.Float(0f, 1f) < 0.033f * dt) {
36 m_importanceLevel = m_random.Float(1f, 2.5f);
37 }
38 m_dt = dt;
39 if (IsActive) {
40 m_stateMachine.Update();
41 }
42 else {
43 m_stateMachine.TransitionTo("Inactive");
44 }
45 }
46
47 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
48 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
49 m_componentCreature = Entity.FindComponent<ComponentCreature>(true);
50 m_componentBirdModel = Entity.FindComponent<ComponentBirdModel>(true);
52 m_stateMachine.AddState(
53 "Inactive",
54 null,
55 delegate {
56 if (IsActive) {
57 m_stateMachine.TransitionTo("Move");
58 }
59 },
60 null
61 );
62 m_stateMachine.AddState("Stuck", delegate { m_stateMachine.TransitionTo("Move"); }, null, null);
63 m_stateMachine.AddState(
64 "Move",
65 delegate {
66 Vector3 position = m_componentCreature.ComponentBody.Position;
67 float num = m_random.Float(0f, 1f) < 0.2f ? 8f : 3f;
68 Vector3 value = position + new Vector3(num * m_random.Float(-1f, 1f), 0f, num * m_random.Float(-1f, 1f));
69 value.Y = m_subsystemTerrain.Terrain.GetTopHeight(Terrain.ToCell(value.X), Terrain.ToCell(value.Z)) + 1;
70 m_componentPathfinding.SetDestination(
71 value,
72 m_random.Float(0.5f, 0.7f),
73 1f,
74 0,
75 false,
76 true,
77 false,
78 null
79 );
80 },
81 delegate {
82 if (!m_componentPathfinding.Destination.HasValue) {
83 if (m_random.Float(0f, 1f) < 0.33f) {
84 m_stateMachine.TransitionTo("Wait");
85 }
86 else {
87 m_stateMachine.TransitionTo("Peck");
88 }
89 }
90 else if (m_componentPathfinding.IsStuck) {
91 m_stateMachine.TransitionTo("Stuck");
92 }
93 },
94 null
95 );
96 m_stateMachine.AddState(
97 "Wait",
98 delegate { m_waitTime = m_random.Float(0.75f, 1f); },
99 delegate {
100 m_waitTime -= m_dt;
101 if (m_waitTime <= 0f) {
102 if (m_random.Float(0f, 1f) < 0.25f) {
103 m_stateMachine.TransitionTo("Move");
104 if (m_random.Float(0f, 1f) < 0.33f) {
105 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(false);
106 }
107 }
108 else {
109 m_stateMachine.TransitionTo("Peck");
110 }
111 }
112 },
113 null
114 );
115 m_stateMachine.AddState(
116 "Peck",
117 delegate { m_peckTime = m_random.Float(2f, 6f); },
118 delegate {
119 m_peckTime -= m_dt;
120 if (m_componentCreature.ComponentBody.StandingOnValue.HasValue) {
121 m_componentBirdModel.FeedOrder = true;
122 }
123 if (m_peckTime <= 0f) {
124 if (m_random.Float(0f, 1f) < 0.25f) {
125 m_stateMachine.TransitionTo("Move");
126 }
127 else {
128 m_stateMachine.TransitionTo("Wait");
129 }
130 }
131 },
132 null
133 );
134 }
135 }
136}
Engine.Vector3 Vector3
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
static int ToCell(float x)
ValuesDictionary ValuesDictionary