Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemFireworksBlockBehavior.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
7
9
11
13
15
17
19
21
22 public Random m_random = new();
23
25
26 public const string fName = "SubsystemFireworksBlockBehavior";
27
28 public override int[] HandledBlocks => [];
29
31
32 public void ExplodeFireworks(Vector3 position, int data) {
33 for (int i = 0; i < 3; i++) {
34 Vector3 v = new(m_random.Float(-3f, 3f), -15f, m_random.Float(-3f, 3f));
35 if (m_subsystemTerrain.Raycast(position, position + v, false, true, null).HasValue) {
36 return;
37 }
38 }
40 float flickering = FireworksBlock.GetFlickering(data) ? 0.66f : 0f;
41 float particleSize = FireworksBlock.GetAltitude(data) > 0 ? 1.1f : 1f;
43 m_subsystemParticles.AddParticleSystem(new FireworksParticleSystem(position, color, shape, flickering, particleSize));
44 m_subsystemAudio.PlayRandomSound("Audio/FireworksPop", 1f, m_random.Float(-0.4f, 0f), position, 80f, true);
45 m_subsystemNoise.MakeNoise(position, 1f, 60f);
46 }
47
48 public override void OnFiredAsProjectile(Projectile projectile) {
49 int data = Terrain.ExtractData(projectile.Value);
50 float num = FireworksBlock.GetAltitude(data) == 0 ? 0.8f : 1.3f;
52 m_subsystemAudio.PlayRandomSound("Audio/FireworksWhoosh", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 8f, true);
53 m_subsystemNoise.MakeNoise(projectile.Position, 1f, 10f);
54 m_subsystemTime.QueueGameTimeDelayedExecution(
55 m_subsystemTime.GameTime + num,
56 delegate {
57 if (!projectile.ToRemove) {
58 projectile.ToRemove = true;
59 ExplodeFireworks(projectile.Position, data);
60 }
61 }
62 );
63 }
64
65 public override bool OnHitAsProjectile(CellFace? cellFace, ComponentBody componentBody, WorldItem worldItem) => true;
66
67 public override void Load(ValuesDictionary valuesDictionary) {
68 base.Load(valuesDictionary);
69 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
71 m_subsystemParticles = Project.FindSubsystem<SubsystemParticles>(true);
72 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
73 m_subsystemNoise = Project.FindSubsystem<SubsystemNoise>(true);
74 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
75 m_subsystemSky = Project.FindSubsystem<SubsystemSky>(true);
76 m_subsystemPlayers = Project.FindSubsystem<SubsystemPlayers>(true);
77 }
78
79 public virtual void Update(float dt) {
80 ComponentPlayer componentPlayer = m_subsystemPlayers.ComponentPlayers.Count > 0 ? m_subsystemPlayers.ComponentPlayers[0] : null;
81 if (componentPlayer == null) {
82 return;
83 }
85 && Time.PeriodicEvent(5.0, 0.0)
86 && m_subsystemSky.SkyLightIntensity == 0f
87 && !componentPlayer.ComponentSleep.IsSleeping) {
88 DateTime now = DateTime.Now;
90 && now.Month == 1
91 && now.Day == 1
92 && now.Hour == 0
93 && now.Minute < 59) {
97 }
98 }
100 return;
101 }
103 float num = m_newYearCelebrationTimeRemaining > 10f
104 ? MathUtils.Lerp(1f, 7f, 0.5f * MathF.Sin(0.25f * m_newYearCelebrationTimeRemaining) + 0.5f)
105 : 20f;
106 if (m_random.Float(0f, 1f) < num * dt) {
107 Vector2 vector = m_random.Vector2(35f, 50f);
108 Vector3 vector2 = componentPlayer.ComponentBody.Position + new Vector3(vector.X, 0f, vector.Y);
109 TerrainRaycastResult? terrainRaycastResult = m_subsystemTerrain.Raycast(
110 new Vector3(vector2.X, 120f, vector2.Z),
111 new Vector3(vector2.X, 40f, vector2.Z),
112 false,
113 true,
114 null
115 );
116 if (terrainRaycastResult.HasValue) {
117 int data = 0;
118 data = FireworksBlock.SetShape(data, (FireworksBlock.Shape)m_random.Int(0, 7));
119 data = FireworksBlock.SetColor(data, m_random.Int(0, 7));
120 data = FireworksBlock.SetAltitude(data, m_random.Int(0, 1));
121 data = FireworksBlock.SetFlickering(data, m_random.Float(0f, 1f) < 0.25f);
122 int value = Terrain.MakeBlockValue(215, 0, data);
123 Vector3 position = new(
124 terrainRaycastResult.Value.CellFace.Point.X,
125 terrainRaycastResult.Value.CellFace.Point.Y + 1,
126 terrainRaycastResult.Value.CellFace.Point.Z
127 );
128 m_subsystemProjectiles.FireProjectile(
129 value,
130 position,
131 new Vector3(m_random.Float(-3f, 3f), 45f, m_random.Float(-3f, 3f)),
133 null
134 );
135 }
136 }
137 }
138 }
139}
Engine.Vector3 Vector3
static float Lerp(float x1, float x2, float f)
static bool PeriodicEvent(double period, double offset)
定义 Time.cs:63
virtual void DisplayLargeMessage(string largeText, string smallText, float duration, float delay)
static int SetFlickering(int data, bool flickering)
static bool GetFlickering(int data)
static Shape GetShape(int data)
static int SetColor(int data, int color)
static readonly Color[] FireworksColors
static int GetAltitude(int data)
static int SetAltitude(int data, int altitude)
static int GetColor(int data)
static int SetShape(int data, Shape shape)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
override void OnFiredAsProjectile(Projectile projectile)
override void Load(ValuesDictionary valuesDictionary)
override bool OnHitAsProjectile(CellFace? cellFace, ComponentBody componentBody, WorldItem worldItem)
static int MakeBlockValue(int contents)
static int ExtractData(int value)
ValuesDictionary ValuesDictionary
static readonly Vector3 Zero