Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentShapeshifter.cs
浏览该文件的文档.
3
4namespace Game {
7
9
11
13
15
17
19
21
23
25
26 public float m_timeToSwitch;
27
29
30 public static Random s_random = new();
31
32 public bool IsEnabled { get; set; }
33
35
36 public virtual void Update(float dt) {
37 bool areSupernaturalCreaturesEnabled = m_subsystemGameInfo.WorldSettings.AreSupernaturalCreaturesEnabled;
38 if (IsEnabled
39 && !m_componentSpawn.IsDespawning
40 && m_componentHealth.Health > 0f) {
41 if (!areSupernaturalCreaturesEnabled
42 && !string.IsNullOrEmpty(m_dayEntityTemplateName)) {
44 }
45 else if (m_subsystemSky.SkyLightIntensity > 0.25f
46 && !string.IsNullOrEmpty(m_dayEntityTemplateName)) {
47 m_timeToSwitch -= 2f * dt;
48 if (m_timeToSwitch <= 0f) {
50 }
51 }
52 else if (areSupernaturalCreaturesEnabled
53 && m_subsystemSky.SkyLightIntensity < 0.1f
54 && (m_subsystemSky.MoonPhase == 0 || m_subsystemSky.MoonPhase == 4)
55 && !string.IsNullOrEmpty(m_nightEntityTemplateName)) {
56 m_timeToSwitch -= dt;
57 if (m_timeToSwitch <= 0f) {
59 }
60 }
61 }
62 if (!string.IsNullOrEmpty(m_spawnEntityTemplateName)) {
63 if (m_particleSystem == null) {
65 m_subsystemParticles.AddParticleSystem(m_particleSystem);
66 }
67 m_particleSystem.BoundingBox = m_componentBody.BoundingBox;
68 }
69 }
70
71 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
72 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
73 m_subsystemSky = Project.FindSubsystem<SubsystemSky>(true);
74 m_subsystemParticles = Project.FindSubsystem<SubsystemParticles>(true);
75 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
76 m_componentSpawn = Entity.FindComponent<ComponentSpawn>(true);
77 m_componentBody = Entity.FindComponent<ComponentBody>(true);
78 m_componentHealth = Entity.FindComponent<ComponentHealth>(true);
79 m_dayEntityTemplateName = valuesDictionary.GetValue<string>("DayEntityTemplateName");
80 m_nightEntityTemplateName = valuesDictionary.GetValue<string>("NightEntityTemplateName");
81 float value = valuesDictionary.GetValue<float>("Probability");
82 if (!string.IsNullOrEmpty(m_dayEntityTemplateName)) {
84 }
85 if (!string.IsNullOrEmpty(m_nightEntityTemplateName)) {
87 }
88 m_timeToSwitch = s_random.Float(3f, 15f);
89 IsEnabled = s_random.Float(0f, 1f) < value;
90 m_componentSpawn.Despawned += ComponentSpawn_Despawned;
91 }
92
93 public virtual void ShapeshiftTo(string entityTemplateName) {
94 if (string.IsNullOrEmpty(m_spawnEntityTemplateName)) {
95 m_spawnEntityTemplateName = entityTemplateName;
96 m_componentSpawn.DespawnDuration = 3f;
97 m_componentSpawn.Despawn();
98 m_subsystemAudio.PlaySound("Audio/Shapeshift", 1f, 0f, m_componentBody.Position, 3f, true);
99 }
100 }
101
102 public virtual void ComponentSpawn_Despawned(ComponentSpawn componentSpawn) {
103 if (m_componentHealth.Health > 0f
104 && !string.IsNullOrEmpty(m_spawnEntityTemplateName)) {
106 ComponentBody componentBody = entity.FindComponent<ComponentBody>(true);
107 componentBody.Position = m_componentBody.Position;
108 componentBody.Rotation = m_componentBody.Rotation;
109 componentBody.Velocity = m_componentBody.Velocity;
110 entity.FindComponent<ComponentSpawn>(true).SpawnDuration = 0.5f;
112 "OnDespawned",
113 modLoader => {
114 modLoader.OnDespawned(entity, componentSpawn);
115 return false;
116 }
117 );
118 Project.AddEntity(entity);
119 }
120 if (m_particleSystem != null) {
121 m_particleSystem.Stopped = true;
122 }
123 }
124 }
125}
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
virtual void ShapeshiftTo(string entityTemplateName)
ShapeshiftParticleSystem m_particleSystem
virtual void ComponentSpawn_Despawned(ComponentSpawn componentSpawn)
static Entity CreateEntity(Project project, SpawnEntityData spawnEntityData, bool throwIfNotFound)
static ValuesDictionary FindEntityValuesDictionary(string entityTemplateName, bool throwIfNotFound)
ValuesDictionary ValuesDictionary
Component FindComponent(Type type, string name, bool throwOnError)
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook