Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ClothingData.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
5using XmlUtilities;
6
7namespace Game {
8 public class ClothingData {
9 public ClothingData() { }
10
11 public ClothingData(XElement item) {
12 int.TryParse(item.Attribute("Index").Value, out int ClothIndex);
13 ClothIndex &= 0x3FF;
14 string newDescription = item.Attribute("Description")?.Value;
15 string newDisplayName = item.Attribute("DisplayName")?.Value;
16 if (newDescription != null
17 && newDescription.StartsWith('[')
18 && newDescription.EndsWith(']')
19 && LanguageControl.TryGetBlock($"{typeof(ClothingBlock).Name}:{ClothIndex}", "Description", out string d)) {
20 newDescription = d;
21 }
22 if (newDisplayName != null
23 && newDisplayName.StartsWith('[')
24 && newDisplayName.EndsWith(']')
25 && LanguageControl.TryGetBlock($"{typeof(ClothingBlock).Name}:{ClothIndex}", "DisplayName", out string n)) {
26 newDisplayName = n;
27 }
28 xElement = item;
29 Index = ClothIndex;
30 DisplayName = newDisplayName;
31 string slotName = XmlUtils.GetAttributeValue<string>(item, "Slot");
33 ArmorProtection = XmlUtils.GetAttributeValue<float>(item, "ArmorProtection");
34 Sturdiness = XmlUtils.GetAttributeValue<float>(item, "Sturdiness");
35 Insulation = XmlUtils.GetAttributeValue<float>(item, "Insulation");
36 MovementSpeedFactor = XmlUtils.GetAttributeValue<float>(item, "MovementSpeedFactor");
37 SteedMovementSpeedFactor = XmlUtils.GetAttributeValue<float>(item, "SteedMovementSpeedFactor");
38 DensityModifier = XmlUtils.GetAttributeValue<float>(item, "DensityModifier");
39 IsOuter = XmlUtils.GetAttributeValue<bool>(item, "IsOuter");
40 CanBeDyed = XmlUtils.GetAttributeValue<bool>(item, "CanBeDyed");
41 Layer = XmlUtils.GetAttributeValue<int>(item, "Layer");
42 PlayerLevelRequired = XmlUtils.GetAttributeValue<int>(item, "PlayerLevelRequired");
43 ImpactSoundsFolder = XmlUtils.GetAttributeValue<string>(item, "ImpactSoundsFolder");
44 Description = newDescription;
45
46 string textureRoute = XmlUtils.GetAttributeValue<string>(item, "TextureName");
47
48 bool useLazyLoading = XmlUtils.GetAttributeValue<bool>(item, "UseLazyLoading", false);
49
50 if (useLazyLoading) {
51 _textureName = textureRoute; // 保存纹理名称用于按需加载
52 }
53 else {
54 Texture = ContentManager.Get<Texture2D>(textureRoute);//立即加载纹理
55 }
56 }
57
58 public string _textureName;
59
61
62 public XElement xElement;
63
64 public int Index;
65
66 public int DisplayIndex;
67
69
70 public float ArmorProtection;
71
72 public float Sturdiness;
73
74 public float Insulation;
75
76 public float MovementSpeedFactor;
77
79
80 public float DensityModifier;
81
82 public string DisplayName;
83
84 public string Description;
85
86 public string ImpactSoundsFolder;
87
88 public bool IsOuter;
89
90 public bool CanBeDyed;
91
92 public int Layer;
93
95
99 public Action<int, ComponentClothing> Mount;
100
104 public Action<int, ComponentClothing> Dismount;
105
109 public Action<int, ComponentClothing> Update;
110
115
125 public virtual void ApplyArmorProtection(ComponentClothing componentClothing,
126 List<int> clothesBeforeProtection,
127 List<int> clothesAfterProtection,
128 int sequence,
129 Attackment attackment,
130 ref float attackPowerAfterProtection) {
131 int value = clothesBeforeProtection[sequence];
133 float maxDurability = block.GetDurability(value) + 1;
134 float remainingSturdiness = (maxDurability - block.GetDamage(value)) / maxDurability * Sturdiness;
135 float damageToAbsorb = MathF.Min(
136 attackPowerAfterProtection * MathUtils.Saturate(ArmorProtection / attackment.ArmorProtectionDivision),
137 remainingSturdiness
138 );
139 if (damageToAbsorb > 0f) {
140 attackPowerAfterProtection -= damageToAbsorb;
141 if (componentClothing.m_subsystemGameInfo.WorldSettings.GameMode != 0) {
142 float x2 = damageToAbsorb / Sturdiness * maxDurability + 0.001f;
143 int damageCount = (int)(MathF.Floor(x2) + (componentClothing.m_random.Bool(MathUtils.Remainder(x2, 1f)) ? 1 : 0));
144 clothesAfterProtection[sequence] = BlocksManager.DamageItem(value, damageCount, componentClothing.Entity);
145 Block blockDamaged = BlocksManager.Blocks[Terrain.ExtractContents(clothesAfterProtection[sequence])];
146 if (!blockDamaged.CanWear(clothesAfterProtection[sequence])) {
147 componentClothing.m_subsystemParticles.AddParticleSystem(
149 componentClothing.m_subsystemTerrain,
150 componentClothing.m_componentBody.Position + componentClothing.m_componentBody.StanceBoxSize / 2f,
151 1f,
152 1f,
153 Color.White,
154 0
155 )
156 );
157 }
158 }
159 if (!string.IsNullOrEmpty(ImpactSoundsFolder)) {
160 componentClothing.m_subsystemAudio.PlayRandomSound(
162 1f,
163 componentClothing.m_random.Float(-0.3f, 0.3f),
164 componentClothing.m_componentBody.Position,
165 4f,
166 0.15f
167 );
168 }
169 }
170 }
171
178 public virtual void UpdateGraduallyDamagedOverTime(ComponentClothing componentClothing, int indexInClothesList, float dt) {
179 try {
180 if (componentClothing.m_subsystemGameInfo.WorldSettings.GameMode == 0
182 return;
183 }
184 {
185 float num2 = componentClothing.m_componentVitalStats.Wetness > 0f ? 10f * Sturdiness : 20f * Sturdiness;
186 double num3 = Math.Floor(componentClothing.m_lastTotalElapsedGameTime.Value / num2);
187 if (Math.Floor(componentClothing.m_subsystemGameInfo.TotalElapsedGameTime / num2) > num3
188 && componentClothing.m_random.Float(0f, 1f) < 0.75f) {
189 componentClothing.m_clothesList[indexInClothesList] = BlocksManager.DamageItem(
190 componentClothing.m_clothesList[indexInClothesList],
191 1,
192 componentClothing.Entity
193 );
194 //检查衣服是否已损坏
195 int damagedClothingBlockValue = componentClothing.m_clothesList[indexInClothesList];
196 Block clothingBlock = BlocksManager.Blocks[Terrain.ExtractContents(damagedClothingBlockValue)];
197 if (!clothingBlock.CanWear(damagedClothingBlockValue)) {
198 componentClothing.m_subsystemParticles.AddParticleSystem(
200 componentClothing.m_subsystemTerrain,
201 componentClothing.m_componentBody.Position + componentClothing.m_componentBody.StanceBoxSize / 2f,
202 1f,
203 1f,
204 Color.White,
205 0
206 )
207 );
208 componentClothing.m_componentGui.DisplaySmallMessage(
209 LanguageControl.Get(typeof(ComponentClothing).Name, 2),
210 Color.White,
211 true,
212 true
213 );
214 }
215 }
216 }
217 }
218 catch (Exception ex) {
219 Log.Error(ex);
220 }
221 }
222
227 public virtual void OnClotheSet(ComponentClothing componentClothing) {
228 componentClothing.InsulationBySlots[Slot] += Insulation;
229 componentClothing.SteedMovementSpeedFactor *= SteedMovementSpeedFactor;
230 componentClothing.m_densityModifierApplied += DensityModifier;
231 }
232
237 public virtual Color GetColor(ComponentClothing componentClothing, int value) {
238 int data = Terrain.ExtractData(value);
240 }
241 }
242}
static void Error(object message)
定义 Log.cs:80
static float Remainder(float x, float y)
static float Saturate(float x)
The spell "Attackment" is wrong, But it is not recommended to change it because many mods rely on thi...
virtual float ArmorProtectionDivision
该攻击被护甲结算时,护甲的防御值会除以ArmorProtectionDivision。 例如当ArmorProtectionDivision = 2,模组护甲的ArmorProtection = 150...
virtual bool CanWear(int value)
virtual int GetDamage(int value)
virtual int GetDurability(int value)
static int DamageItem(int value, int damageCount, Entity owner=null)
static int GetClothingColor(int data)
virtual void OnClotheSet(ComponentClothing componentClothing)
在ComponentClothing执行SetClothes()时触发,用于调整ComponentClothing中的一些参数
Action< int, ComponentClothing > Update
ComponentClothing更新时触发。
ValuesDictionary DictionaryForOtherMods
模组可以向Dictionary里面添加特殊数据,另一个模组可以从Dictionary读取数据,以实现模组联动效果
virtual void UpdateGraduallyDamagedOverTime(ComponentClothing componentClothing, int indexInClothesList, float dt)
在ComponentClothing中每帧都会调用的UpdateGraduallyDamagedOverTime(),主要用于控制衣物随时间逐渐损坏
virtual Color GetColor(ComponentClothing componentClothing, int value)
获取衣物穿着在身上时的颜色附加
virtual void ApplyArmorProtection(ComponentClothing componentClothing, List< int > clothesBeforeProtection, List< int > clothesAfterProtection, int sequence, Attackment attackment, ref float attackPowerAfterProtection)
计算单件护甲的防御
Action< int, ComponentClothing > Mount
装备
ClothingData(XElement item)
Action< int, ComponentClothing > Dismount
卸载
static Dictionary< string, ClothingSlot > ClothingSlots
调用自定义部位(比如手臂)的ClothingSlot,可以用ClothingSlot.ClothingSlots["Arms"]
virtual Vector3 StanceBoxSize
SubsystemParticles m_subsystemParticles
SubsystemGameInfo m_subsystemGameInfo
Dictionary< ClothingSlot, float > InsulationBySlots
virtual void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound)
static object Get(Type type, string name)
static bool TryGetBlock(string blockName, string prop, out string result)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
float Float()
void PlayRandomSound(string directory, float volume, float pitch, float pan, float delay)
void AddParticleSystem(ParticleSystemBase particleSystem, bool throwOnAlreadyAdded=false)
static int ExtractContents(int value)
static int ExtractData(int value)
static object GetAttributeValue(XElement node, string attributeName, Type type)
static Color White