Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemCrossbowBlockBehavior.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
7
9
11
12 public Random m_random = new();
13 public static string fName = "SubsystemCrossbowBlockBehavior";
14
15 public Dictionary<ComponentMiner, double> m_aimStartTimes = [];
16
19 ];
20
22
24 public override int[] HandledBlocks => [];
25
26 public override bool OnEditInventoryItem(IInventory inventory, int slotIndex, ComponentPlayer componentPlayer) {
27 componentPlayer.ComponentGui.ModalPanelWidget = componentPlayer.ComponentGui.ModalPanelWidget == null
28 ? new CrossbowWidget(inventory, slotIndex)
29 : null;
30 return true;
31 }
32
33 public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state) {
34 IInventory inventory = componentMiner.Inventory;
35 if (inventory != null) {
36 int activeSlotIndex = inventory.ActiveSlotIndex;
37 if (activeSlotIndex >= 0) {
38 int slotValue = inventory.GetSlotValue(activeSlotIndex);
39 int slotCount = inventory.GetSlotCount(activeSlotIndex);
40 int num = Terrain.ExtractContents(slotValue);
41 int data = Terrain.ExtractData(slotValue);
42 if (slotCount > 0) {
43 int draw = CrossbowBlock.GetDraw(data);
44 if (!m_aimStartTimes.TryGetValue(componentMiner, out double value)) {
45 value = m_subsystemTime.GameTime;
46 m_aimStartTimes[componentMiner] = value;
47 }
48 float num2 = (float)(m_subsystemTime.GameTime - value);
49 float num3 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
50 Vector3 v =
51 ((componentMiner.ComponentCreature.ComponentBody.IsCrouching ? 0.01f : 0.03f)
52 + 0.15f * MathUtils.Saturate((num2 - 2.5f) / 6f))
53 * new Vector3 {
54 X = SimplexNoise.OctavedNoise(num3, 2f, 3, 2f, 0.5f),
55 Y = SimplexNoise.OctavedNoise(num3 + 100f, 2f, 3, 2f, 0.5f),
56 Z = SimplexNoise.OctavedNoise(num3 + 200f, 2f, 3, 2f, 0.5f)
57 };
58 aim.Direction = Vector3.Normalize(aim.Direction + v);
59 switch (state) {
60 case AimState.InProgress: {
61 if (num2 >= 10f) {
63 return true;
64 }
66 componentFirstPersonModel = componentMiner.Entity.FindComponent<ComponentFirstPersonModel>();
67 if (componentFirstPersonModel != null) {
69 componentFirstPersonModel.ItemOffsetOrder = new Vector3(-0.22f, 0.15f, 0.1f);
70 componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f);
71 }
72 componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder = 1.3f;
73 componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder = new Vector3(-0.08f, -0.1f, 0.07f);
74 componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.55f, 0f, 0f);
75 break;
76 }
77 case AimState.Cancelled: m_aimStartTimes.Remove(componentMiner); break;
78 case AimState.Completed: {
80 if (draw != 15) {
84 true,
85 false
86 );
87 }
88 else if (!arrowType.HasValue) {
92 true,
93 false
94 );
95 }
96 else {
97 Vector3 vector = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition
98 + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f
99 - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
100 Vector3 v2 = Vector3.Normalize(vector + aim.Direction * 10f - vector);
101 int value2 = Terrain.MakeBlockValue(m_ArrowBlockIndex, 0, ArrowBlock.SetArrowType(0, arrowType.Value));
102 float s = 38f;
103 Vector3 velocity = componentMiner.ComponentCreature.ComponentBody.Velocity + s * v2;
104 if (m_subsystemProjectiles.FireProjectile(
105 value2,
106 vector,
107 velocity,
109 componentMiner.ComponentCreature
110 )
111 != null) {
112 data = CrossbowBlock.SetArrowType(data, null);
113 m_subsystemAudio.PlaySound(
114 "Audio/Bow",
115 1f,
116 m_random.Float(-0.1f, 0.1f),
118 3f,
119 0.05f
120 );
121 }
122 }
123 inventory.RemoveSlotItems(activeSlotIndex, 1);
124 int value3 = Terrain.MakeBlockValue(num, 0, CrossbowBlock.SetDraw(data, 0));
125 inventory.AddSlotItems(activeSlotIndex, value3, 1);
126 if (draw > 0) {
127 componentMiner.DamageActiveTool(1);
128 m_subsystemAudio.PlaySound(
129 "Audio/CrossbowBoing",
130 1f,
131 m_random.Float(-0.1f, 0.1f),
133 3f,
134 0f
135 );
136 }
137 m_aimStartTimes.Remove(componentMiner);
138 break;
139 }
140 }
141 }
142 }
143 }
144 return false;
145 }
146
147 public override int GetProcessInventoryItemCapacity(IInventory inventory, int slotIndex, int value) {
148 int num = Terrain.ExtractContents(value);
150 if (num == m_ArrowBlockIndex
151 && m_supportedArrowTypes.Contains(arrowType)) {
152 int data = Terrain.ExtractData(inventory.GetSlotValue(slotIndex));
154 int draw = CrossbowBlock.GetDraw(data);
155 if (!arrowType2.HasValue
156 && draw == 15) {
157 return 1;
158 }
159 }
160 return 0;
161 }
162
163 public override void ProcessInventoryItem(IInventory inventory,
164 int slotIndex,
165 int value,
166 int count,
167 int processCount,
168 out int processedValue,
169 out int processedCount) {
170 if (processCount == 1) {
172 int data = Terrain.ExtractData(inventory.GetSlotValue(slotIndex));
173 processedValue = 0;
174 processedCount = 0;
175 inventory.RemoveSlotItems(slotIndex, 1);
176 inventory.AddSlotItems(slotIndex, Terrain.MakeBlockValue(m_CrossbowBlockIndex, 0, CrossbowBlock.SetArrowType(data, arrowType)), 1);
177 }
178 else {
179 processedValue = value;
180 processedCount = count;
181 }
182 }
183
184 public override void Load(ValuesDictionary valuesDictionary) {
185 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
187 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
190 base.Load(valuesDictionary);
191 }
192 }
193}
Engine.Vector3 Vector3
static float Remainder(float x, float y)
static float Saturate(float x)
static int SetArrowType(int data, ArrowType arrowType)
static ArrowType GetArrowType(int data)
static int GetBlockIndex(string BlockName, bool throwIfNotFound=false)
通过方块名称来获取方块的Index
virtual void ShowAimingSights(Vector3 position, Vector3 direction)
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 ArrowBlock.? ArrowType GetArrowType(int data)
static int GetDraw(int data)
static int SetArrowType(int data, ArrowBlock.ArrowType? arrowType)
static int SetDraw(int data, int draw)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static float OctavedNoise(float x, float frequency, int octaves, float frequencyStep, float amplitudeStep, bool ridged=false)
override int GetProcessInventoryItemCapacity(IInventory inventory, int slotIndex, int value)
override void Load(ValuesDictionary valuesDictionary)
override bool OnEditInventoryItem(IInventory inventory, int slotIndex, ComponentPlayer componentPlayer)
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)
Dictionary< ComponentMiner, double > m_aimStartTimes
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 Normalize(Vector3 v)
static readonly Vector3 Zero