Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentLoot.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
7 public struct Loot {
8 public Loot() { }
9 public int Value;
10
11 public int MinCount;
12
13 public int MaxCount;
14
15 public float Probability;
16
21 }
22
24
26
28
29 public List<Loot> m_lootList;
30
31 public List<Loot> m_lootOnFireList;
32
33 public Random m_random = new();
34
35 public bool m_lootDropped;
36
38
39 public static List<Loot> ParseLootList(ValuesDictionary lootVd) {
40 List<Loot> list = new();
41 foreach (string value in lootVd.Values) {
42 list.Add(ParseLoot(value));
43 }
44 list.Sort((l1, l2) => l1.Value - l2.Value);
45 return list;
46 }
47
48 public virtual void Update(float dt) {
49 if (!m_lootDropped
50 && m_componentCreature.ComponentHealth.DeathTime.HasValue
51 && m_subsystemGameInfo.TotalElapsedGameTime
52 >= m_componentCreature.ComponentHealth.DeathTime.Value + m_componentCreature.ComponentHealth.CorpseDuration) {
53 bool num = m_componentCreature.Entity.FindComponent<ComponentOnFire>()?.IsOnFire ?? false;
54 m_lootDropped = true;
55 List<BlockDropValue> blockDropValues = [];
56 foreach (Loot item in num ? m_lootOnFireList : m_lootList) {
57 if (m_random.Float(0f, 1f) < item.Probability) {
58 int num2 = m_random.Int(item.MinCount, item.MaxCount);
59 for (int i = 0; i < num2; i++) {
60 blockDropValues.Add(new BlockDropValue { Value = item.Value, Count = 1 });
61 }
62 }
63 }
65 "DecideLoot",
66 loader => {
67 loader.DecideLoot(this, blockDropValues);
68 return false;
69 }
70 );
71 Vector3 position = (m_componentCreature.ComponentBody.BoundingBox.Min + m_componentCreature.ComponentBody.BoundingBox.Max) / 2f;
72 foreach (BlockDropValue blockDropValue in blockDropValues) {
73 m_subsystemPickables.AddPickable(blockDropValue.Value, blockDropValue.Count, position, null, null, Entity);
74 }
75 }
76 }
77
78 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
79 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
80 m_subsystemPickables = Project.FindSubsystem<SubsystemPickables>(true);
81 m_componentCreature = Entity.FindComponent<ComponentCreature>(true);
82 m_lootDropped = valuesDictionary.GetValue<bool>("LootDropped");
83 m_lootList = ParseLootList(valuesDictionary.GetValue<ValuesDictionary>("Loot"));
84 m_lootOnFireList = ParseLootList(valuesDictionary.GetValue<ValuesDictionary>("LootOnFire"));
85 }
86
87 public override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap) {
88 valuesDictionary.SetValue("LootDropped", m_lootDropped);
89 }
90
91 public static Loot ParseLoot(string lootString) {
92 string[] array = lootString.Split([";"], StringSplitOptions.None);
93 if (array.Length >= 3) {
94 try {
95 int v = CraftingRecipesManager.DecodeResult(array[0]);
96 Loot result = default;
97 result.Value = v;
98 result.MinCount = int.Parse(array[1]);
99 result.MaxCount = int.Parse(array[2]);
100 result.Probability = array.Length >= 4 ? float.Parse(array[3]) : 1f;
101 return result;
102 }
103 catch {
104 return default;
105 }
106 }
107 throw new InvalidOperationException("Invalid loot string.");
108 }
109 }
110}
ComponentCreature m_componentCreature
override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap)
SubsystemGameInfo m_subsystemGameInfo
static Loot ParseLoot(string lootString)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
virtual void Update(float dt)
static List< Loot > ParseLootList(ValuesDictionary lootVd)
SubsystemPickables m_subsystemPickables
List< Loot > m_lootOnFireList
ValuesDictionary ValuesDictionary
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
ValuesDictionary ValuesDictionaryForMods
模组如果需要添加或使用额外信息,可以在这个ValuesDictionary读写元素