Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentPickableGatherer.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
9
11
13
15
17
19
20 public virtual bool IsPickableInAttractRange(Pickable pickable, float distanceToTargetSquare) {
21 if (pickable.StuckMatrix.HasValue) {
22 return false;
23 }
24 return distanceToTargetSquare < pickable.DistanceToFlyToTarget * pickable.DistanceToFlyToTarget;
25 }
26
27 public virtual bool IsPickableInGatherRange(Pickable pickable, float distanceToTargetSquare) =>
28 distanceToTargetSquare < pickable.DistanceToPick * pickable.DistanceToPick;
29
30 public virtual bool CanGatherPickable(Pickable pickable) {
31 double pickableTimeExisted = m_subsystemGameInfo.TotalElapsedGameTime - pickable.CreationTime;
32 if (pickableTimeExisted < pickable.TimeWaitToAutoPick) { }
33 return false;
34 }
35
36 public virtual void GatherPickable(Pickable pickable) { }
37
38 public virtual void Update(float dt) {
39 if (m_componentBody != null) {
40 Position = m_componentBody.Position + new Vector3(0f, 0.75f, 0f);
41 }
42 for (int i = 0; i < m_subsystemPickables.Pickables.Count; i++) {
43 Pickable pickable = m_subsystemPickables.Pickables[i];
44 float distanceToTargetSquare = (Position - pickable.Position).LengthSquared();
45 if (IsPickableInGatherRange(pickable, distanceToTargetSquare)) {
46 if (CanGatherPickable(pickable)) {
47 lock (pickable) {
48 GatherPickable(pickable);
49 if (!pickable.ToRemove && pickable.Count == 0) {
50 pickable.ToRemove = true;
51 }
52 }
53 }
54 }
55 else if (IsPickableInAttractRange(pickable, distanceToTargetSquare)) {
56 if (CanGatherPickable(pickable)) {
57 lock (pickable) {
58 pickable.FlyToPosition = Position + 0.1f * MathF.Sqrt(distanceToTargetSquare) * m_componentBody.Velocity;
59 pickable.FlyToGatherer = this;
60 }
61 }
62 }
63 }
64 }
65
66 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
67 base.Load(valuesDictionary, idToEntityMap);
68 m_subsystemPickables = Project.FindSubsystem<SubsystemPickables>(true);
70 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
71 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
72 m_componentBody = Entity.FindComponent<ComponentBody>();
73 }
74 }
75}
Engine.Vector3 Vector3
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
virtual bool IsPickableInAttractRange(Pickable pickable, float distanceToTargetSquare)
virtual void GatherPickable(Pickable pickable)
virtual bool CanGatherPickable(Pickable pickable)
virtual bool IsPickableInGatherRange(Pickable pickable, float distanceToTargetSquare)
virtual float DistanceToPick
virtual float DistanceToFlyToTarget
Matrix? StuckMatrix
virtual double TimeWaitToAutoPick
ValuesDictionary ValuesDictionary