Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemMusketBlockBehavior.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
7
9
11
13
15
17 public static string fName = "SubsystemMusketBlockBehavior";
18 public Random m_random = new();
19
20 public Dictionary<ComponentMiner, double> m_aimStartTimes = [];
21
23
25 public override int[] HandledBlocks => [];
26
27 public override bool OnEditInventoryItem(IInventory inventory, int slotIndex, ComponentPlayer componentPlayer) {
28 componentPlayer.ComponentGui.ModalPanelWidget = componentPlayer.ComponentGui.ModalPanelWidget == null
29 ? new MusketWidget(inventory, slotIndex)
30 : null;
31 return true;
32 }
33
34 public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state) {
35 IInventory inventory = componentMiner.Inventory;
36 if (inventory != null) {
37 int activeSlotIndex = inventory.ActiveSlotIndex;
38 if (activeSlotIndex >= 0) {
39 int slotValue = inventory.GetSlotValue(activeSlotIndex);
40 int slotCount = inventory.GetSlotCount(activeSlotIndex);
41 int num = Terrain.ExtractContents(slotValue);
42 int data = Terrain.ExtractData(slotValue);
43 int num2 = slotValue;
44 int num3 = 0;
45 if (num == m_MusketBlockIndex
46 && slotCount > 0) {
47 if (!m_aimStartTimes.TryGetValue(componentMiner, out double value)) {
48 value = m_subsystemTime.GameTime;
49 m_aimStartTimes[componentMiner] = value;
50 }
51 float num4 = (float)(m_subsystemTime.GameTime - value);
52 float num5 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
53 Vector3 v =
54 ((componentMiner.ComponentCreature.ComponentBody.IsCrouching ? 0.01f : 0.03f)
55 + 0.2f * MathUtils.Saturate((num4 - 2.5f) / 6f))
56 * new Vector3 {
57 X = SimplexNoise.OctavedNoise(num5, 2f, 3, 2f, 0.5f),
58 Y = SimplexNoise.OctavedNoise(num5 + 100f, 2f, 3, 2f, 0.5f),
59 Z = SimplexNoise.OctavedNoise(num5 + 200f, 2f, 3, 2f, 0.5f)
60 };
61 aim.Direction = Vector3.Normalize(aim.Direction + v);
62 switch (state) {
63 case AimState.InProgress: {
64 if (num4 >= 10f) {
66 return true;
67 }
68 if (num4 > 0.5f
71 m_subsystemAudio.PlaySound("Audio/HammerCock", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
72 }
74 componentFirstPersonModel = componentMiner.Entity.FindComponent<ComponentFirstPersonModel>();
75 if (componentFirstPersonModel != null) {
77 componentFirstPersonModel.ItemOffsetOrder = new Vector3(-0.21f, 0.15f, 0.08f);
78 componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f);
79 }
80 componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder = 1.4f;
81 componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder = new Vector3(-0.08f, -0.08f, 0.07f);
82 componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.7f, 0f, 0f);
83 break;
84 }
85 case AimState.Cancelled:
88 m_subsystemAudio.PlaySound("Audio/HammerUncock", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
89 }
90 m_aimStartTimes.Remove(componentMiner);
91 break;
92 case AimState.Completed: {
93 bool flag = false;
94 int value2 = 0;
95 int num6 = 0;
96 float s = 0f;
97 Vector3 vector = Vector3.Zero;
101 switch (loadState) {
102 case MusketBlock.LoadState.Empty:
105 Color.White,
106 true,
107 false
108 ); break;
109 case MusketBlock.LoadState.Gunpowder:
110 case MusketBlock.LoadState.Wad:
111 flag = true;
114 Color.White,
115 true,
116 false
117 );
118 break;
119 case MusketBlock.LoadState.Loaded:
120 flag = true;
121 if (bulletType == BulletBlock.BulletType.Buckshot) {
122 value2 = Terrain.MakeBlockValue(
124 0,
126 );
127 num6 = 8;
128 vector = new Vector3(0.04f, 0.04f, 0.25f);
129 s = 80f;
130 }
131 else if (bulletType == BulletBlock.BulletType.BuckshotBall) {
132 value2 = Terrain.MakeBlockValue(
134 0,
136 );
137 num6 = 1;
138 vector = new Vector3(0.06f, 0.06f, 0f);
139 s = 60f;
140 }
141 else if (bulletType.HasValue) {
142 value2 = Terrain.MakeBlockValue(
144 0,
145 BulletBlock.SetBulletType(0, bulletType.Value)
146 );
147 num6 = 1;
148 s = 120f;
149 }
150 break;
151 }
152 }
153 if (flag) {
154 if (componentMiner.ComponentCreature.ComponentBody.ImmersionFactor > 0.4f) {
155 m_subsystemAudio.PlaySound(
156 "Audio/MusketMisfire",
157 1f,
158 m_random.Float(-0.1f, 0.1f),
160 3f,
161 true
162 );
163 }
164 else {
165 Vector3 vector2 = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition
166 + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f
167 - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
168 Vector3 vector3 = Vector3.Normalize(vector2 + aim.Direction * 10f - vector2);
169 Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector3, Vector3.UnitY));
170 Vector3 v2 = Vector3.Normalize(Vector3.Cross(vector3, vector4));
171 for (int i = 0; i < num6; i++) {
172 Vector3 v3 = m_random.Float(0f - vector.X, vector.X) * vector4
173 + m_random.Float(0f - vector.Y, vector.Y) * v2
174 + m_random.Float(0f - vector.Z, vector.Z) * vector3;
175 Vector3 velocity = componentMiner.ComponentCreature.ComponentBody.Velocity + s * (vector3 + v3);
176 Projectile projectile = m_subsystemProjectiles.FireProjectile(
177 value2,
178 vector2,
179 velocity,
181 componentMiner.ComponentCreature
182 );
183 if (projectile != null) {
184 projectile.ProjectileStoppedAction = ProjectileStoppedAction.Disappear;
185 }
186 }
187 m_subsystemAudio.PlaySound(
188 "Audio/MusketFire",
189 1f,
190 m_random.Float(-0.1f, 0.1f),
192 10f,
193 true
194 );
195 m_subsystemParticles.AddParticleSystem(
196 new GunSmokeParticleSystem(m_subsystemTerrain, vector2 + 0.3f * vector3, vector3)
197 );
198 m_subsystemNoise.MakeNoise(vector2, 1f, 40f);
199 componentMiner.ComponentCreature.ComponentBody.ApplyImpulse(-4f * vector3);
200 }
201 num2 = Terrain.MakeBlockValue(
203 0,
205 );
206 num3 = 1;
207 }
209 num2 = Terrain.MakeBlockValue(
211 0,
213 );
214 m_subsystemAudio.PlaySound("Audio/HammerRelease", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
215 }
216 m_aimStartTimes.Remove(componentMiner);
217 break;
218 }
219 }
220 }
221 if (num2 != slotValue) {
222 inventory.RemoveSlotItems(activeSlotIndex, 1);
223 inventory.AddSlotItems(activeSlotIndex, num2, 1);
224 }
225 if (num3 > 0) {
226 componentMiner.DamageActiveTool(num3);
227 }
228 }
229 }
230 return false;
231 }
232
233 public override int GetProcessInventoryItemCapacity(IInventory inventory, int slotIndex, int value) {
234 int num = Terrain.ExtractContents(value);
236 if (loadState == MusketBlock.LoadState.Empty
237 && num == 109) {
238 return 1;
239 }
240 if (loadState == MusketBlock.LoadState.Gunpowder
241 && num == 205) {
242 return 1;
243 }
244 if (loadState == MusketBlock.LoadState.Wad
245 && num == m_BulletBlockIndex) {
246 return 1;
247 }
248 return 0;
249 }
250
251 public override void ProcessInventoryItem(IInventory inventory,
252 int slotIndex,
253 int value,
254 int count,
255 int processCount,
256 out int processedValue,
257 out int processedCount) {
258 processedValue = value;
259 processedCount = count;
260 if (processCount == 1) {
261 int data = Terrain.ExtractData(inventory.GetSlotValue(slotIndex));
264 switch (loadState) {
265 case MusketBlock.LoadState.Empty:
266 loadState = MusketBlock.LoadState.Gunpowder;
267 bulletType = null;
268 break;
269 case MusketBlock.LoadState.Gunpowder:
270 loadState = MusketBlock.LoadState.Wad;
271 bulletType = null;
272 break;
273 case MusketBlock.LoadState.Wad: {
274 loadState = MusketBlock.LoadState.Loaded;
275 int data2 = Terrain.ExtractData(value);
276 bulletType = BulletBlock.GetBulletType(data2);
277 break;
278 }
279 }
280 processedValue = 0;
281 processedCount = 0;
282 inventory.RemoveSlotItems(slotIndex, 1);
283 inventory.AddSlotItems(
284 slotIndex,
286 1
287 );
288 }
289 }
290
291 public override void Load(ValuesDictionary valuesDictionary) {
292 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
293 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
295 m_subsystemParticles = Project.FindSubsystem<SubsystemParticles>(true);
296 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
297 m_subsystemNoise = Project.FindSubsystem<SubsystemNoise>(true);
300 base.Load(valuesDictionary);
301 }
302 }
303}
Engine.Vector3 Vector3
static float Remainder(float x, float y)
static float Saturate(float x)
static int GetBlockIndex(string BlockName, bool throwIfNotFound=false)
通过方块名称来获取方块的Index
static BulletType GetBulletType(int data)
static int SetBulletType(int data, BulletType bulletType)
virtual void ShowAimingSights(Vector3 position, Vector3 direction)
virtual float ImmersionFactor
virtual void ApplyImpulse(Vector3 impulse)
ComponentCreatureModel ComponentCreatureModel
ComponentCreatureSounds ComponentCreatureSounds
virtual void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound)
ComponentPlayer ComponentPlayer
ComponentCreature ComponentCreature
virtual void DamageActiveTool(int damageCount)
ComponentAimingSights ComponentAimingSights
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static int SetLoadState(int data, LoadState loadState)
static LoadState GetLoadState(int data)
static BulletBlock.? BulletType GetBulletType(int data)
static int SetHammerState(int data, bool state)
static int SetBulletType(int data, BulletBlock.BulletType? bulletType)
static bool GetHammerState(int data)
static float OctavedNoise(float x, float frequency, int octaves, float frequencyStep, float amplitudeStep, bool ridged=false)
override void Load(ValuesDictionary valuesDictionary)
override bool OnEditInventoryItem(IInventory inventory, int slotIndex, ComponentPlayer componentPlayer)
Dictionary< ComponentMiner, double > m_aimStartTimes
override int GetProcessInventoryItemCapacity(IInventory inventory, int slotIndex, int value)
override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state)
override void ProcessInventoryItem(IInventory inventory, int slotIndex, int value, int count, int processCount, out int processedValue, out int processedCount)
static int ExtractContents(int value)
static int MakeBlockValue(int contents)
static int ExtractData(int value)
Component FindComponent(Type type, string name, bool throwOnError)
ValuesDictionary ValuesDictionary
int RemoveSlotItems(int slotIndex, int count)
实际移除的数量
int GetSlotCount(int slotIndex)
void AddSlotItems(int slotIndex, int value, int count)
int GetSlotValue(int slotIndex)
static Color White
Vector3 Position
定义 Ray3.cs:3
Vector3 Direction
定义 Ray3.cs:5
static Vector3 Cross(Vector3 v1, Vector3 v2)
static Vector3 Normalize(Vector3 v)
static readonly Vector3 Zero
static readonly Vector3 UnitY