Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentLayEggBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
16
18
20
21 public float m_layFrequency;
22
24
25 public float m_importanceLevel;
26
27 public float m_dt;
28
29 public float m_layTime;
30
31 public Random m_random = new();
32
34
35 public override float ImportanceLevel => m_importanceLevel;
36
37 public virtual void Update(float dt) {
38 if (string.IsNullOrEmpty(m_stateMachine.CurrentState)) {
39 m_stateMachine.TransitionTo("Move");
40 }
41 if (m_eggType != null
42 && m_random.Float(0f, 1f) < m_layFrequency * dt) {
43 m_importanceLevel = m_random.Float(1f, 2f);
44 }
45 m_dt = dt;
46 if (IsActive) {
47 m_stateMachine.Update();
48 }
49 else {
50 m_stateMachine.TransitionTo("Inactive");
51 }
52 }
53
54 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
55 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
56 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
57 m_subsystemPickables = Project.FindSubsystem<SubsystemPickables>(true);
58 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
59 m_componentCreature = Entity.FindComponent<ComponentCreature>(true);
61 EggBlock eggBlock = (EggBlock)BlocksManager.Blocks[118];
62 m_layFrequency = valuesDictionary.GetValue<float>("LayFrequency");
63 m_eggType = eggBlock.GetEggTypeByCreatureTemplateName(Entity.ValuesDictionary.DatabaseObject.Name);
64 m_stateMachine.AddState(
65 "Inactive",
66 null,
67 delegate {
68 if (IsActive) {
69 m_stateMachine.TransitionTo("Move");
70 }
71 },
72 null
73 );
74 m_stateMachine.AddState("Stuck", delegate { m_stateMachine.TransitionTo("Move"); }, null, null);
75 m_stateMachine.AddState(
76 "Move",
77 delegate {
78 Vector3 position2 = m_componentCreature.ComponentBody.Position;
79 float num = 5f;
80 Vector3 value3 = position2 + new Vector3(num * m_random.Float(-1f, 1f), 0f, num * m_random.Float(-1f, 1f));
81 value3.Y = m_subsystemTerrain.Terrain.GetTopHeight(Terrain.ToCell(value3.X), Terrain.ToCell(value3.Z)) + 1;
82 m_componentPathfinding.SetDestination(
83 value3,
84 m_random.Float(0.4f, 0.6f),
85 0.5f,
86 0,
87 false,
88 true,
89 false,
90 null
91 );
92 },
93 delegate {
94 if (!m_componentPathfinding.Destination.HasValue) {
95 m_stateMachine.TransitionTo("Lay");
96 }
97 else if (m_componentPathfinding.IsStuck) {
98 if (m_random.Float(0f, 1f) < 0.5f) {
99 m_stateMachine.TransitionTo("Stuck");
100 }
101 else {
103 }
104 }
105 },
106 null
107 );
108 m_stateMachine.AddState(
109 "Lay",
110 delegate { m_layTime = 0f; },
111 delegate {
112 if (m_eggType != null) {
113 m_layTime += m_dt;
114 if (m_componentCreature.ComponentBody.StandingOnValue.HasValue) {
115 m_componentCreature.ComponentLocomotion.LookOrder = new Vector2(
116 0f,
117 0.25f * (float)Math.Sin(20.0 * m_subsystemTime.GameTime) + m_layTime / 3f
118 )
119 - m_componentCreature.ComponentLocomotion.LookAngles;
120 if (m_layTime >= 3f) {
122 int value = Terrain.MakeBlockValue(118, 0, EggBlock.SetIsLaid(EggBlock.SetEggType(0, m_eggType.EggTypeIndex), true));
123 Matrix matrix = m_componentCreature.ComponentBody.Matrix;
124 Vector3 position = 0.5f
125 * (m_componentCreature.ComponentBody.BoundingBox.Min + m_componentCreature.ComponentBody.BoundingBox.Max);
126 Vector3 value2 = 3f
127 * Vector3.Normalize(-matrix.Forward + 0.1f * matrix.Up + 0.2f * m_random.Float(-1f, 1f) * matrix.Right);
128 m_subsystemPickables.AddPickable(value, 1, position, value2, null, Entity);
129 m_subsystemAudio.PlaySound("Audio/EggLaid", 1f, m_random.Float(-0.1f, 0.1f), position, 2f, true);
130 }
131 }
132 else if (m_layTime >= 3f) {
134 }
135 }
136 else {
138 }
139 },
140 null
141 );
142 }
143 }
144}
Engine.Vector3 Vector3
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
static int SetIsLaid(int data, bool isLaid)
static int SetEggType(int data, int eggTypeIndex)
static int ToCell(float x)
static int MakeBlockValue(int contents)
ValuesDictionary ValuesDictionary
Vector3 Forward
static Vector3 Normalize(Vector3 v)