Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentCreature.cs
浏览该文件的文档.
1using Engine;
5
6namespace Game {
7 public class ComponentCreature : Component {
9
10 public string[] m_killVerbs;
11
12 public ComponentBody ComponentBody { get; set; }
13
14 public ComponentHealth ComponentHealth { get; set; }
15
16 public ComponentSpawn ComponentSpawn { get; set; }
17
19
21
23
25 get {
26 if (this is ComponentPlayer componentPlayer) {
27 return m_subsystemPlayerStats.GetPlayerStats(componentPlayer.PlayerData.PlayerIndex);
28 }
29 return null;
30 }
31 }
32
33 public bool ConstantSpawn { get; set; }
34
35 public CreatureCategory Category { get; set; }
36
37 public string DisplayName { get; set; }
38
39 public ReadOnlyList<string> KillVerbs => new(m_killVerbs);
40
41 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
42 ComponentBody = Entity.FindComponent<ComponentBody>(true);
43 ComponentHealth = Entity.FindComponent<ComponentHealth>(true);
44 ComponentSpawn = Entity.FindComponent<ComponentSpawn>(true);
47 ComponentLocomotion = Entity.FindComponent<ComponentLocomotion>(true);
49 ConstantSpawn = valuesDictionary.GetValue<bool>("ConstantSpawn");
50 Category = valuesDictionary.GetValue<CreatureCategory>("Category");
51 DisplayName = valuesDictionary.GetValue<string>("DisplayName");
52 if (DisplayName.StartsWith('[')
53 && DisplayName.EndsWith(']')) {
54 string[] lp = DisplayName.Substring(1, DisplayName.Length - 2).Split([":"], StringSplitOptions.RemoveEmptyEntries);
55 DisplayName = LanguageControl.GetDatabase("DisplayName", lp[1]);
56 }
57 m_killVerbs = HumanReadableConverter.ValuesListFromString<string>(',', valuesDictionary.GetValue<string>("KillVerbs"));
58 if (m_killVerbs.Length == 0) {
59 throw new InvalidOperationException("Must have at least one KillVerb");
60 }
61 if (!MathUtils.IsPowerOf2((long)Category)) {
62 throw new InvalidOperationException("A single category must be assigned for creature.");
63 }
64 }
65
66 public override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap) {
67 valuesDictionary.SetValue("ConstantSpawn", ConstantSpawn);
68 }
69 }
70}
static bool IsPowerOf2(uint x)
override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap)
ComponentCreatureModel ComponentCreatureModel
SubsystemPlayerStats m_subsystemPlayerStats
ComponentLocomotion ComponentLocomotion
ReadOnlyList< string > KillVerbs
ComponentCreatureSounds ComponentCreatureSounds
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
static string GetDatabase(string name, string prop)
ValuesDictionary ValuesDictionary