Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentSummonBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
15 public float m_importanceLevel;
16
17 public Random m_random = new();
18
19 public bool m_isEnabled;
20
21 public double m_summonedTime;
22
23 public double m_stoppedTime;
24
25 public ComponentBody SummonTarget { get; set; }
26
27 public bool IsEnabled => m_isEnabled;
28
30
31 public override float ImportanceLevel => m_importanceLevel;
32
33 public virtual void Update(float dt) {
34 m_stateMachine.Update();
35 }
36
37 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
38 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
39 m_componentCreature = Entity.FindComponent<ComponentCreature>(true);
41 m_isEnabled = valuesDictionary.GetValue<bool>("IsEnabled");
42 m_stateMachine.AddState(
43 "Inactive",
44 delegate {
46 SummonTarget = null;
47 m_summonedTime = 0.0;
48 },
49 delegate {
50 if (m_isEnabled
51 && SummonTarget != null
52 && m_summonedTime == 0.0) {
53 m_subsystemTime.QueueGameTimeDelayedExecution(
54 m_subsystemTime.GameTime + 0.5,
55 delegate {
56 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(true);
57 m_importanceLevel = 270f;
58 m_summonedTime = m_subsystemTime.GameTime;
59 }
60 );
61 }
62 if (IsActive) {
63 m_stateMachine.TransitionTo("FollowTarget");
64 }
65 },
66 null
67 );
68 m_stateMachine.AddState(
69 "FollowTarget",
70 delegate { FollowTarget(true); },
71 delegate {
72 if (!IsActive) {
73 m_stateMachine.TransitionTo("Inactive");
74 }
75 else if (SummonTarget == null
76 || m_componentPathfinding.IsStuck
77 || m_subsystemTime.GameTime - m_summonedTime > 30.0) {
79 }
80 else if (!m_componentPathfinding.Destination.HasValue) {
81 if (m_stoppedTime < 0.0) {
83 }
84 if (m_subsystemTime.GameTime - m_stoppedTime > 6.0) {
86 }
87 }
88 FollowTarget(false);
89 m_componentCreature.ComponentCreatureModel.LookRandomOrder = true;
90 },
91 null
92 );
93 m_stateMachine.TransitionTo("Inactive");
94 }
95
96 public virtual void FollowTarget(bool noDelay) {
97 if (SummonTarget != null
98 && (noDelay || m_random.Float(0f, 1f) < 5f * m_subsystemTime.GameTimeDelta)) {
99 float num = Vector3.Distance(m_componentCreature.ComponentBody.Position, SummonTarget.Position);
100 if (num > 4f) {
101 Vector3 v = Vector3.Normalize(Vector3.Cross(Vector3.UnitY, SummonTarget.Position - m_componentCreature.ComponentBody.Position));
102 v *= 0.75f * (GetHashCode() % 2 != 0 ? 1 : -1) * (1 + GetHashCode() % 3);
103 float speed = MathUtils.Lerp(0.4f, 1f, MathUtils.Saturate(0.25f * (num - 5f)));
104 m_componentPathfinding.SetDestination(
105 SummonTarget.Position + v,
106 speed,
107 3.75f,
108 2000,
109 true,
110 false,
111 true,
112 null
113 );
114 m_stoppedTime = -1.0;
115 }
116 }
117 }
118 }
119}
static float Saturate(float x)
static float Lerp(float x1, float x2, float f)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
ValuesDictionary ValuesDictionary
static Vector3 Cross(Vector3 v1, Vector3 v2)
static Vector3 Normalize(Vector3 v)
static float Distance(Vector3 v1, Vector3 v2)
static readonly Vector3 UnitY