Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
Injury.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
4 public class Injury {
6 public float Amount;
9 public string Cause;
11
12 public Injury(float amount, ComponentCreature attacker, bool ignoreInvulnerability, string cause) {
13 Amount = amount;
14 m_attacker = attacker;
15 IgnoreInvulnerability = ignoreInvulnerability;
16 Cause = cause;
17 }
18
19 float Health {
20 get => ComponentHealth.Health;
21 set => ComponentHealth.Health = value;
22 }
23
24 public virtual ComponentCreature Attacker {
25 get {
26 if (m_attacker != null) {
27 return m_attacker;
28 }
29 return m_attacker = Attackment?.Attacker?.FindComponent<ComponentCreature>();
30 }
31 set => m_attacker = value;
32 }
33
35
36 public virtual void AddPlayerStats() {
37 if (ComponentHealth.m_componentCreature.PlayerStats != null) {
38 if (Attackment?.Attacker != null) {
39 ComponentHealth.m_componentCreature.PlayerStats.HitsReceived++;
40 }
41 ComponentHealth.m_componentCreature.PlayerStats.TotalHealthLost += MathUtils.Min(Amount, ComponentHealth.Health);
42 }
43 }
44
45 public virtual void ProcessToLivingCreature() { }
46
47 public virtual void Process() {
48 if (ComponentHealth == null) {
49 return;
50 }
52 "CalculateCreatureInjuryAmount",
53 loader => {
54 loader.CalculateCreatureInjuryAmount(this);
55 return false;
56 }
57 );
58 if (!(Amount > 0f)
59 || (!IgnoreInvulnerability && ComponentHealth.IsInvulnerable)) {
60 return;
61 }
62 ComponentHealth.Injured?.Invoke(this);
63 if (ComponentHealth.Health > 0f) {
66 }
67 }
68 }
69}
static int Min(int x1, int x2)
static int Max(int x1, int x2)
ComponentCreature m_attacker
Attackment Attackment
virtual void ProcessToLivingCreature()
virtual void AddPlayerStats()
virtual ComponentPlayer AttackerPlayer
ComponentHealth ComponentHealth
Injury(float amount, ComponentCreature attacker, bool ignoreInvulnerability, string cause)
virtual void Process()
string Cause
bool IgnoreInvulnerability
virtual ComponentCreature Attacker
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook