Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentIntro.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
15 public bool m_playIntro;
16
17 public static string fName = "ComponentIntro";
18
20
22
23 public static Vector2 FindOceanDirection(ITerrainContentsGenerator generator, Vector2 position) {
24 float num = float.MaxValue;
25 Vector2 result = Vector2.Zero;
26 for (int i = 0; i < 36; i++) {
27 Vector2 vector = Vector2.CreateFromAngle(i / 36f * 2f * (float)Math.PI);
28 Vector2 vector2 = position + 50f * vector;
29 float num2 = generator.CalculateOceanShoreDistance(vector2.X, vector2.Y);
30 if (num2 < num) {
31 result = vector;
32 num = num2;
33 }
34 }
35 return result;
36 }
37
38 public virtual void Update(float dt) {
39 if (m_playIntro) {
40 m_playIntro = false;
41 m_stateMachine.TransitionTo("ShipView");
42 }
43 m_stateMachine.Update();
44 }
45
46 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
47 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
48 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
49 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
50 m_componentPlayer = Entity.FindComponent<ComponentPlayer>(true);
51 m_playIntro = valuesDictionary.GetValue<bool>("PlayIntro") && SettingsManager.AllowInitialIntro;
52 m_stateMachine.AddState("ShipView", ShipView_Enter, ShipView_Update, null);
53 }
54
55 public override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap) {
56 valuesDictionary.SetValue("PlayIntro", m_playIntro);
57 }
58
59 public virtual void ShipView_Enter() {
60 ComponentBody componentBody = m_componentPlayer.Entity.FindComponent<ComponentBody>(true);
61 Vector2 vector = FindOceanDirection(m_subsystemTerrain.TerrainContentsGenerator, componentBody.Position.XZ);
62 Vector2 vector2 = componentBody.Position.XZ + 25f * vector;
63 bool isPlayerMounted = m_componentPlayer.ComponentRider.Mount != null;
64 Vector2 vector3 = vector2;
65 float num = float.MinValue;
66 for (int i = Terrain.ToCell(vector2.Y) - 15; i < Terrain.ToCell(vector2.Y) + 15; i++) {
67 for (int j = Terrain.ToCell(vector2.X) - 15; j < Terrain.ToCell(vector2.X) + 15; j++) {
68 float num2 = ScoreShipPosition(componentBody.Position.XZ, j, i);
69 if (num2 > num) {
70 num = num2;
71 vector3 = new Vector2(j, i);
72 }
73 }
74 }
75 DatabaseObject databaseObject = Project.GameDatabase.Database.FindDatabaseObject(
76 "IntroShip",
77 Project.GameDatabase.EntityTemplateType,
78 true
79 );
80 ValuesDictionary valuesDictionary = new();
81 valuesDictionary.PopulateFromDatabaseObject(databaseObject);
82 Entity entity = Project.CreateEntity(valuesDictionary);
83 Vector3 vector4 = new(vector3.X, m_subsystemTerrain.TerrainContentsGenerator.OceanLevel + 0.5f, vector3.Y);
84 entity.FindComponent<ComponentFrame>(true).Position = vector4;
85 entity.FindComponent<ComponentIntroShip>(true).Heading = Vector2.Angle(vector, -Vector2.UnitY);
86 Project.AddEntity(entity);
87 m_subsystemTime.QueueGameTimeDelayedExecution(
88 2.0,
89 delegate { m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 1), 5f, 0f); }
90 );
91 m_subsystemTime.QueueGameTimeDelayedExecution(
92 7.0,
93 delegate {
94 if (isPlayerMounted) {
95 m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 2), 5f, 0f);
96 }
97 else {
98 m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 3), 5f, 0f);
99 }
100 }
101 );
102 m_subsystemTime.QueueGameTimeDelayedExecution(
103 12.0,
104 delegate { m_componentPlayer.ComponentGui.DisplayLargeMessage(null, LanguageControl.Get(fName, 4), 5f, 0f); }
105 );
106 IntroCamera introCamera = m_componentPlayer.GameWidget.FindCamera<IntroCamera>();
107 m_componentPlayer.GameWidget.ActiveCamera = introCamera;
108 introCamera.CameraPosition = vector4 + new Vector3(12f * vector.X, 8f, 12f * vector.Y) + new Vector3(-5f * vector.Y, 0f, 5f * vector.X);
109 introCamera.TargetPosition = m_componentPlayer.ComponentCreatureModel.EyePosition + 2.5f * new Vector3(vector.X, 0f, vector.Y);
110 introCamera.Speed = 0f;
111 introCamera.TargetCameraPosition = m_componentPlayer.ComponentCreatureModel.EyePosition;
112 }
113
114 public virtual void ShipView_Update() {
115 IntroCamera introCamera = m_componentPlayer.GameWidget.FindCamera<IntroCamera>();
116 introCamera.Speed = MathUtils.Lerp(0f, 8f, MathUtils.Saturate(((float)m_subsystemGameInfo.TotalElapsedGameTime - 6f) / 3f));
117 if (Vector3.Distance(introCamera.TargetCameraPosition, introCamera.CameraPosition) < 0.3f) {
118 m_componentPlayer.GameWidget.ActiveCamera = m_componentPlayer.GameWidget.FindCamera<FppCamera>();
119 m_stateMachine.TransitionTo(null);
120 }
121 }
122
123 public virtual float ScoreShipPosition(Vector2 playerPosition, int x, int z) {
124 float num = 0f;
125 float num2 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(x, z);
126 if (num2 > -8f) {
127 num -= 100f;
128 }
129 num -= 0.25f * num2;
130 float num3 = Vector2.Distance(playerPosition, new Vector2(x, z));
131 num -= MathF.Abs(num3 - 20f);
132 int num4 = 0;
133 TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
134 if (chunkAtCell != null
135 && chunkAtCell.State >= TerrainChunkState.InvalidLight) {
136 int oceanLevel = m_subsystemTerrain.TerrainContentsGenerator.OceanLevel;
137 int num5 = oceanLevel;
138 while (num5 >= oceanLevel - 5
139 && num5 >= 0) {
140 int cellContentsFast = chunkAtCell.GetCellContentsFast(x & 0xF, num5, z & 0xF);
141 if (cellContentsFast != 18
142 && cellContentsFast != 92) {
143 break;
144 }
145 num5--;
146 num4++;
147 }
148 }
149 else {
150 num4 = 2;
151 }
152 if (num4 < 2) {
153 num -= 100f;
154 }
155 return num + 2f * num4;
156 }
157 }
158}
Engine.Vector3 Vector3
static float Saturate(float x)
static float Lerp(float x1, float x2, float f)
virtual float ScoreShipPosition(Vector2 playerPosition, int x, int z)
SubsystemGameInfo m_subsystemGameInfo
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
static Vector2 FindOceanDirection(ITerrainContentsGenerator generator, Vector2 position)
ComponentPlayer m_componentPlayer
override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap)
virtual void ShipView_Enter()
SubsystemTime m_subsystemTime
SubsystemTerrain m_subsystemTerrain
virtual void Update(float dt)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
TerrainChunkState State
virtual int GetCellContentsFast(int x, int y, int z)
static int ToCell(float x)
ValuesDictionary ValuesDictionary
Component FindComponent(Type type, string name, bool throwOnError)
void PopulateFromDatabaseObject(DatabaseObject databaseObject)
float CalculateOceanShoreDistance(float x, float z)
static readonly Vector2 Zero
static Vector2 CreateFromAngle(float angle)
static readonly Vector2 UnitY
static float Angle(Vector2 v1, Vector2 v2)
static float Distance(Vector2 v1, Vector2 v2)
static float Distance(Vector3 v1, Vector3 v2)