Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemBowBlockBehavior.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
7
9
11 public static string fName = "SubsystemBowBlockBehavior";
12 public Random m_random = new();
13
14 public Dictionary<ComponentMiner, double> m_aimStartTimes = [];
15
18
20 ArrowBlock.ArrowType.WoodenArrow,
21 ArrowBlock.ArrowType.StoneArrow,
22 ArrowBlock.ArrowType.CopperArrow,
23 ArrowBlock.ArrowType.IronArrow,
24 ArrowBlock.ArrowType.DiamondArrow,
26 ];
27
28 public override int[] HandledBlocks => [];
29
30 public override bool OnEditInventoryItem(IInventory inventory, int slotIndex, ComponentPlayer componentPlayer) {
31 componentPlayer.ComponentGui.ModalPanelWidget = componentPlayer.ComponentGui.ModalPanelWidget == null
32 ? new BowWidget(inventory, slotIndex)
33 : null;
34 return true;
35 }
36
37 public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state) {
38 IInventory inventory = componentMiner.Inventory;
39 if (inventory != null) {
40 int activeSlotIndex = inventory.ActiveSlotIndex;
41 if (activeSlotIndex >= 0) {
42 int slotValue = inventory.GetSlotValue(activeSlotIndex);
43 int slotCount = inventory.GetSlotCount(activeSlotIndex);
44 int num = Terrain.ExtractContents(slotValue);
45 int data = Terrain.ExtractData(slotValue);
46 if (slotCount > 0) {
47 if (!m_aimStartTimes.TryGetValue(componentMiner, out double value)) {
48 value = m_subsystemTime.GameTime;
49 m_aimStartTimes[componentMiner] = value;
50 }
51 float num2 = (float)(m_subsystemTime.GameTime - value);
52 float num3 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
53 Vector3 v =
54 ((componentMiner.ComponentCreature.ComponentBody.IsCrouching ? 0.02f : 0.04f)
55 + 0.25f * MathUtils.Saturate((num2 - 2.1f) / 5f))
56 * new Vector3 {
57 X = SimplexNoise.OctavedNoise(num3, 2f, 3, 2f, 0.5f),
58 Y = SimplexNoise.OctavedNoise(num3 + 100f, 2f, 3, 2f, 0.5f),
59 Z = SimplexNoise.OctavedNoise(num3 + 200f, 2f, 3, 2f, 0.5f)
60 };
61 aim.Direction = Vector3.Normalize(aim.Direction + v);
62 switch (state) {
63 case AimState.InProgress: {
64 if (num2 >= 9f) {
66 return true;
67 }
69 componentFirstPersonModel = componentMiner.Entity.FindComponent<ComponentFirstPersonModel>();
70 if (componentFirstPersonModel != null) {
72 componentFirstPersonModel.ItemOffsetOrder = new Vector3(-0.1f, 0.15f, 0f);
73 componentFirstPersonModel.ItemRotationOrder = new Vector3(0f, -0.7f, 0f);
74 }
75 componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder = 1.2f;
76 componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder = new Vector3(0f, 0f, 0f);
77 componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(0f, -0.2f, 0f);
78 if (m_subsystemTime.PeriodicGameTimeEvent(0.10000000149011612, 0.0)) {
79 int draw2 = MathUtils.Min(BowBlock.GetDraw(data) + 1, 15);
80 inventory.RemoveSlotItems(activeSlotIndex, 1);
81 inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, draw2)), 1);
82 }
83 break;
84 }
85 case AimState.Cancelled:
86 inventory.RemoveSlotItems(activeSlotIndex, 1);
87 inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0)), 1);
88 m_aimStartTimes.Remove(componentMiner);
89 break;
90 case AimState.Completed: {
91 int draw = BowBlock.GetDraw(data);
92 ArrowBlock.ArrowType? arrowType = BowBlock.GetArrowType(data);
93 if (arrowType.HasValue) {
94 Vector3 vector = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition
95 + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f
96 - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
97 Vector3 vector2 = Vector3.Normalize(vector + aim.Direction * 10f - vector);
98 float num4 = MathUtils.Lerp(0f, 28f, MathF.Pow(draw / 15f, 0.75f));
99 if (componentMiner.ComponentPlayer != null) {
100 num4 *= 0.5f * (componentMiner.ComponentPlayer.ComponentLevel.StrengthFactor - 1f) + 1f;
101 }
102 Vector3 vector3 = Vector3.Zero;
103 if (arrowType == ArrowBlock.ArrowType.WoodenArrow) {
104 vector3 = new Vector3(0.025f, 0.025f, 0.025f);
105 }
106 if (arrowType == ArrowBlock.ArrowType.StoneArrow) {
107 vector3 = new Vector3(0.01f, 0.01f, 0.01f);
108 }
109 int value2 = Terrain.MakeBlockValue(m_arrowBlockIndex, 0, ArrowBlock.SetArrowType(0, arrowType.Value));
110 Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector2, Vector3.UnitY));
111 Vector3 v2 = Vector3.Normalize(Vector3.Cross(vector2, vector4));
112 Vector3 v3 = m_random.Float(0f - vector3.X, vector3.X) * vector4
113 + m_random.Float(0f - vector3.Y, vector3.Y) * v2
114 + m_random.Float(0f - vector3.Z, vector3.Z) * vector2;
115 Vector3 velocity = componentMiner.ComponentCreature.ComponentBody.Velocity + (vector2 + v3) * num4;
116 if (m_subsystemProjectiles.FireProjectile(
117 value2,
118 vector,
119 velocity,
121 componentMiner.ComponentCreature
122 )
123 != null) {
124 data = BowBlock.SetArrowType(data, null);
125 m_subsystemAudio.PlaySound("Audio/Bow", 1f, m_random.Float(-0.1f, 0.1f), vector, 3f, true);
126 }
127 }
128 else {
131 Color.White,
132 true,
133 false
134 );
135 }
136 inventory.RemoveSlotItems(activeSlotIndex, 1);
137 int value3 = Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0));
138 inventory.AddSlotItems(activeSlotIndex, value3, 1);
139 int damageCount = 0;
140 if (draw >= 15) {
141 damageCount = 2;
142 }
143 else if (draw >= 4) {
144 damageCount = 1;
145 }
146 componentMiner.DamageActiveTool(damageCount);
147 m_aimStartTimes.Remove(componentMiner);
148 break;
149 }
150 }
151 }
152 }
153 }
154 return false;
155 }
156
157 public override int GetProcessInventoryItemCapacity(IInventory inventory, int slotIndex, int value) {
158 int num = Terrain.ExtractContents(value);
160 if (num == m_arrowBlockIndex
161 && m_supportedArrowTypes.Contains(arrowType)) {
162 if (!BowBlock.GetArrowType(Terrain.ExtractData(inventory.GetSlotValue(slotIndex))).HasValue) {
163 return 1;
164 }
165 }
166 return 0;
167 }
168
169 public override void ProcessInventoryItem(IInventory inventory,
170 int slotIndex,
171 int value,
172 int count,
173 int processCount,
174 out int processedValue,
175 out int processedCount) {
176 if (processCount == 1) {
178 int data = Terrain.ExtractData(inventory.GetSlotValue(slotIndex));
179 processedValue = 0;
180 processedCount = 0;
181 inventory.RemoveSlotItems(slotIndex, 1);
182 inventory.AddSlotItems(slotIndex, Terrain.MakeBlockValue(m_bowBlockIndex, 0, BowBlock.SetArrowType(data, arrowType)), 1);
183 }
184 else {
185 processedValue = value;
186 processedCount = count;
187 }
188 }
189
190 public override void Load(ValuesDictionary valuesDictionary) {
191 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
193 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
196 base.Load(valuesDictionary);
197 }
198 }
199}
Engine.Vector3 Vector3
static float Remainder(float x, float y)
static int Min(int x1, int x2)
static float Saturate(float x)
static float Lerp(float x1, float x2, float f)
static int SetArrowType(int data, ArrowType arrowType)
static ArrowType GetArrowType(int data)
static int GetBlockIndex(string BlockName, bool throwIfNotFound=false)
通过方块名称来获取方块的Index
static int SetDraw(int data, int draw)
static ArrowBlock.? ArrowType GetArrowType(int data)
static int SetArrowType(int data, ArrowBlock.ArrowType? arrowType)
static int GetDraw(int data)
virtual void ShowAimingSights(Vector3 position, Vector3 direction)
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 float OctavedNoise(float x, float frequency, int octaves, float frequencyStep, float amplitudeStep, bool ridged=false)
override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state)
override int GetProcessInventoryItemCapacity(IInventory inventory, int slotIndex, int value)
Dictionary< ComponentMiner, double > m_aimStartTimes
override void ProcessInventoryItem(IInventory inventory, int slotIndex, int value, int count, int processCount, out int processedValue, out int processedCount)
override void Load(ValuesDictionary valuesDictionary)
override bool OnEditInventoryItem(IInventory inventory, int slotIndex, ComponentPlayer componentPlayer)
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