Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemBoatBlockBehavior.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
13 public Random m_random = new();
14
15 public static string fName = "SubsystemBoatBlockBehavior";
16
17 public override int[] HandledBlocks => [178];
18
19 public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) {
20 _ = componentMiner.Inventory;
21 if (Terrain.ExtractContents(componentMiner.ActiveBlockValue) == 178) {
22 TerrainRaycastResult? terrainRaycastResult = componentMiner.Raycast<TerrainRaycastResult>(ray, RaycastMode.Digging);
23 if (terrainRaycastResult.HasValue) {
24 Vector3 position = terrainRaycastResult.Value.HitPoint();
25 DynamicArray<ComponentBody> dynamicArray = new();
26 m_subsystemBodies.FindBodiesInArea(
27 new Vector2(position.X, position.Z) - new Vector2(8f),
28 new Vector2(position.X, position.Z) + new Vector2(8f),
29 dynamicArray
30 );
31 if (dynamicArray.Count(b => b.Entity.ValuesDictionary.DatabaseObject.Name == "Boat") < 6
32 || m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative) {
33 Entity entity = DatabaseManager.CreateEntity(Project, "Boat", true);
34 entity.FindComponent<ComponentFrame>(true).Position = position;
37 m_random.Float(0f, (float)Math.PI * 2f)
38 );
39 entity.FindComponent<ComponentSpawn>(true).SpawnDuration = 0f;
40 Project.AddEntity(entity);
41 componentMiner.RemoveActiveTool(1);
42 m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, position, 3f, true);
43 }
44 else {
46 }
47 return true;
48 }
49 }
50 return false;
51 }
52
53 public override void Load(ValuesDictionary valuesDictionary) {
54 base.Load(valuesDictionary);
55 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
56 m_subsystemBodies = Project.FindSubsystem<SubsystemBodies>(true);
57 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
58 }
59 }
60}
virtual void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound)
ComponentPlayer ComponentPlayer
virtual void RemoveActiveTool(int removeCount)
virtual object Raycast(Ray3 ray, RaycastMode mode, bool raycastTerrain=true, bool raycastBodies=true, bool raycastMovingBlocks=true, float? Reach=null)
发出射线检测,检测玩家点击到的目标
static Entity CreateEntity(Project project, SpawnEntityData spawnEntityData, bool throwIfNotFound)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
override void Load(ValuesDictionary valuesDictionary)
static int ExtractContents(int value)
Component FindComponent(Type type, string name, bool throwOnError)
ValuesDictionary ValuesDictionary
static Color White
static Quaternion CreateFromAxisAngle(Vector3 axis, float angle)
static readonly Vector3 UnitY