Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemSpikesBlockBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
7 public static Random m_random = new();
8
10
12
14
15 public Dictionary<ComponentCreature, double> m_lastInjuryTimes = [];
16
18
20
21 public virtual void Update(float dt) {
22 if (m_closestSoundToPlay.HasValue) {
23 m_subsystemAudio.PlaySound("Audio/Spikes", 0.7f, m_random.Float(-0.1f, 0.1f), m_closestSoundToPlay.Value, 4f, true);
25 }
26 }
27
28 public bool RetractExtendSpikes(int x, int y, int z, bool extend) {
29 int cellValue = SubsystemTerrain.Terrain.GetCellValue(x, y, z);
30 int num = Terrain.ExtractContents(cellValue);
32 int data = SpikedPlankBlock.SetSpikesState(Terrain.ExtractData(cellValue), extend);
33 int value = Terrain.ReplaceData(cellValue, data);
34 SubsystemTerrain.ChangeCell(x, y, z, value);
35 Vector3 vector = new(x, y, z);
36 float num2 = m_subsystemAudio.CalculateListenerDistance(vector);
37 if (!m_closestSoundToPlay.HasValue
38 || num2 < m_subsystemAudio.CalculateListenerDistance(m_closestSoundToPlay.Value)) {
39 m_closestSoundToPlay = vector;
40 }
41 return true;
42 }
43 return false;
44 }
45
46 public override void OnCollide(CellFace cellFace, float velocity, ComponentBody componentBody) {
47 int data = Terrain.ExtractData(SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z));
49 return;
50 }
51 int mountingFace = SpikedPlankBlock.GetMountingFace(data);
52 if (cellFace.Face != mountingFace) {
53 return;
54 }
55 ComponentCreature componentCreature = componentBody.Entity.FindComponent<ComponentCreature>();
56 if (componentCreature != null) {
57 m_lastInjuryTimes.TryGetValue(componentCreature, out double value);
58 if (m_subsystemTime.GameTime - value > 1.0) {
59 m_lastInjuryTimes[componentCreature] = m_subsystemTime.GameTime;
60 componentCreature.ComponentHealth.OnSpiked(
61 this,
62 1f / componentCreature.ComponentHealth.SpikeResilience,
63 cellFace,
64 velocity,
65 componentBody,
66 "Spiked by a trap"
67 );
68 }
69 }
70 }
71
72 public override void Load(ValuesDictionary valuesDictionary) {
73 base.Load(valuesDictionary);
74 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
75 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
76 }
77
78 public override void OnEntityRemoved(Entity entity) {
79 ComponentCreature componentCreature = entity.FindComponent<ComponentCreature>();
80 if (componentCreature != null) {
81 m_lastInjuryTimes.Remove(componentCreature);
82 }
83 }
84 }
85}
static int GetBlockIndex(string BlockName, bool throwIfNotFound=false)
通过方块名称来获取方块的Index
virtual void OnSpiked(SubsystemBlockBehavior spikeBlockBehavior, float damage, CellFace cellFace, float velocity, ComponentBody componentBody, string causeOfDeath)
static int GetMountingFace(int data)
static int SetSpikesState(int data, bool spikesState)
static bool GetSpikesState(int data)
override void OnCollide(CellFace cellFace, float velocity, ComponentBody componentBody)
bool RetractExtendSpikes(int x, int y, int z, bool extend)
override void Load(ValuesDictionary valuesDictionary)
Dictionary< ComponentCreature, double > m_lastInjuryTimes
static int ExtractContents(int value)
static int ReplaceData(int value, int data)
static int ExtractData(int value)
Component FindComponent(Type type, string name, bool throwOnError)
ValuesDictionary ValuesDictionary