Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentCreatureModel.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
16
17 public float m_injuryColorFactor;
18
20
21 public Random m_random = new();
22 public float Bob { get; set; }
23
24 public float MovementAnimationPhase { get; set; }
25
26 public float DeathPhase { get; set; }
27
28 public Vector3 DeathCauseOffset { get; set; }
29
30 public Vector3? LookAtOrder { get; set; }
31
32 public bool LookRandomOrder { get; set; }
33
34 public float HeadShakeOrder { get; set; }
35
36 public bool AttackOrder { get; set; }
37
38 public bool FeedOrder { get; set; }
39
40 public bool RowLeftOrder { get; set; }
41
42 public bool RowRightOrder { get; set; }
43
44 public float AimHandAngleOrder { get; set; }
45
46 public Vector3 InHandItemOffsetOrder { get; set; }
47
48 public Vector3 InHandItemRotationOrder { get; set; }
49
50 public bool IsAttackHitMoment { get; set; }
51 public virtual float AttackPhase { get; set; }
52 public virtual float AttackFactor { get; set; }
53
55 get {
56 if (!m_eyePosition.HasValue) {
58 }
59 return m_eyePosition.Value;
60 }
61 }
62
64 get {
65 if (!m_eyeRotation.HasValue) {
67 }
68 return m_eyeRotation.Value;
69 }
70 }
71
73 get {
74 ComponentBody parentBody = m_componentCreature.ComponentBody.ParentBody;
75 if (parentBody != null) {
76 ComponentCreatureModel componentCreatureModel = parentBody.Entity.FindComponent<ComponentCreatureModel>();
77 if (componentCreatureModel != null) {
78 return componentCreatureModel.UpdateOrder + 1;
79 }
80 }
81 return UpdateOrder.CreatureModels;
82 }
83 }
84
85 public override void Animate() {
86 base.Animate();
87 if (!Animated) {
88 bool flag = false;
90 "OnModelAnimate",
91 loader => {
92#pragma warning disable CS0618
93 loader.OnModelAnimate(this, out bool skip);
94#pragma warning restore CS0618
95 flag = flag | skip;
96 return false;
97 }
98 );
99 if (!flag) {
101 }
102 }
103 float opacity = m_componentCreature.ComponentSpawn.SpawnDuration > 0f
104 ? (float)MathUtils.Saturate(
105 (m_subsystemGameInfo.TotalElapsedGameTime - m_componentCreature.ComponentSpawn.SpawnTime)
106 / m_componentCreature.ComponentSpawn.SpawnDuration
107 )
108 : 1f;
109 Opacity = MathUtils.Min(opacity, Transparent);
110 if (m_componentCreature.ComponentSpawn.DespawnTime.HasValue) {
112 Opacity.Value,
113 (float)MathUtils.Saturate(
114 1.0
115 - (m_subsystemGameInfo.TotalElapsedGameTime - m_componentCreature.ComponentSpawn.DespawnTime.Value)
116 / m_componentCreature.ComponentSpawn.DespawnDuration
117 )
118 );
119 }
121 if (Opacity.HasValue
122 && Opacity.Value < 1f) {
123 bool num = m_componentCreature.ComponentBody.ImmersionFactor >= 1f;
124 bool flag = m_subsystemSky.ViewUnderWaterDepth > 0f;
125 RenderingMode = num == flag ? ModelRenderingMode.TransparentAfterWater : ModelRenderingMode.TransparentBeforeWater;
126 }
127 else {
129 }
130 }
131
132 public abstract void AnimateCreature();
133
134 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
135 base.Load(valuesDictionary, idToEntityMap);
136 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
137 m_subsystemSky = Project.FindSubsystem<SubsystemSky>(true);
138 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
139 m_componentCreature = Entity.FindComponent<ComponentCreature>(true);
140 m_componentCreature.ComponentHealth.Injured += delegate(Injury injury) {
141 ComponentCreature attacker = injury.Attacker;
142 if (attacker == null) {
143 return;
144 }
145 if (DeathPhase == 0f
146 && m_componentCreature.ComponentHealth.Health == 0f) {
147 DeathCauseOffset = attacker.ComponentBody.BoundingBox.Center() - m_componentCreature.ComponentBody.BoundingBox.Center();
148 }
149 };
150 }
151
152 public override void OnEntityAdded() {
153 m_componentCreature.ComponentBody.PositionChanged += delegate { m_eyePosition = null; };
154 m_componentCreature.ComponentBody.RotationChanged += delegate { m_eyeRotation = null; };
155 }
156
157 public virtual void Update(float dt) {
158 if (LookRandomOrder) {
159 Matrix matrix = m_componentCreature.ComponentBody.Matrix;
160 Vector3 v = Vector3.Normalize(m_randomLookPoint - m_componentCreature.ComponentCreatureModel.EyePosition);
161 if (m_random.Float(0f, 1f) < 0.25f * dt
162 || Vector3.Dot(matrix.Forward, v) < 0.2f) {
163 float s = m_random.Float(-5f, 5f);
164 float s2 = m_random.Float(-1f, 1f);
165 float s3 = m_random.Float(3f, 8f);
166 m_randomLookPoint = m_componentCreature.ComponentCreatureModel.EyePosition
167 + s3 * matrix.Forward
168 + s2 * matrix.Up
169 + s * matrix.Right;
170 }
172 }
173 if (LookAtOrder.HasValue) {
174 Vector3 forward = m_componentCreature.ComponentBody.Matrix.Forward;
175 Vector3 v2 = LookAtOrder.Value - m_componentCreature.ComponentCreatureModel.EyePosition;
176 float x = Vector2.Angle(new Vector2(forward.X, forward.Z), new Vector2(v2.X, v2.Z));
177 float y = MathF.Asin(0.99f * Vector3.Normalize(v2).Y);
178 m_componentCreature.ComponentLocomotion.LookOrder = new Vector2(x, y) - m_componentCreature.ComponentLocomotion.LookAngles;
179 }
180 if (HeadShakeOrder > 0f) {
182 float num = 1f * MathUtils.Saturate(4f * HeadShakeOrder);
183 m_componentCreature.ComponentLocomotion.LookOrder = new Vector2(
184 num * (float)Math.Sin(16.0 * m_subsystemTime.GameTime + 0.01f * GetHashCode()),
185 0f
186 )
187 - m_componentCreature.ComponentLocomotion.LookAngles;
188 }
189 if (m_componentCreature.ComponentHealth.Health == 0f) {
190 DeathPhase = MathUtils.Min(DeathPhase + 3f * dt, 1f);
191 }
192 m_eyePosition = null;
193 m_eyeRotation = null;
194 LookRandomOrder = false;
195 LookAtOrder = null;
196 }
197
198 public virtual Vector3 CalculateEyePosition() {
199 Matrix matrix = m_componentCreature.ComponentBody.Matrix;
200 Vector3 result = m_componentCreature.ComponentBody.Position
201 + matrix.Up * 0.95f * m_componentCreature.ComponentBody.BoxSize.Y
202 + matrix.Forward * 0.45f * m_componentCreature.ComponentBody.BoxSize.Z;
204 "RecalculateModelEyePosition",
205 loader => {
206 loader.RecalculateModelEyePosition(this, ref result);
207 return false;
208 }
209 );
210 return result;
211 }
212
214 Quaternion result = m_componentCreature.ComponentBody.Rotation
216 0f - m_componentCreature.ComponentLocomotion.LookAngles.X,
217 m_componentCreature.ComponentLocomotion.LookAngles.Y,
218 0f
219 );
221 "RecalculateModelEyeRotation",
222 loader => {
223 loader.RecalculateModelEyeRotation(this, ref result);
224 return false;
225 }
226 );
227 return result;
228 }
229 }
230}
static int Min(int x1, int x2)
static float Saturate(float x)
static int Max(int x1, int x2)
virtual BoundingBox BoundingBox
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
virtual ModelRenderingMode RenderingMode
float Transparent
模型透明度
virtual ComponentCreature Attacker
ValuesDictionary ValuesDictionary
Component FindComponent(Type type, string name, bool throwOnError)
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
Vector3 Forward
static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll)
static float Angle(Vector2 v1, Vector2 v2)
static readonly Vector3 One
static Vector3 Lerp(Vector3 v1, Vector3 v2, float f)
static Vector3 Normalize(Vector3 v)
static float Dot(Vector3 v1, Vector3 v2)