package attribute func NewHealthPoint(pHp *FixedNumeric) *HealthPoint { return &HealthPoint{ Hp: pHp, MaxHp: NewAttributeNumeric(pHp.Value()), CurrMaxHp: NewAttributeNumeric(pHp.Value()), CurrMaxHpPro: NewAttributeNumeric(0), CurrMaxHpAppend: NewAttributeNumeric(0), } } /// /// 生命值实体 /// type HealthPoint struct { /// /// 生命值 /// Hp *FixedNumeric /// /// 最大生命值 /// MaxHp *AttributeNumeric /// /// 当前最大生命值 /// CurrMaxHp *AttributeNumeric /// /// 当前最大生命百分比加成 /// CurrMaxHpPro *AttributeNumeric /// /// 当前最大生命加成 /// CurrMaxHpAppend *AttributeNumeric } /// /// 重置当前生命值为最大值 /// func (this *HealthPoint) Reset() { this.Hp.SetFloat(this.CurrMaxHp.Value()) } func (this *HealthPoint) Value() int32 { return int32(this.Hp.Value()) } func (this *HealthPoint) MaxValue() int32 { return int32(this.CurrMaxHp.Value()) } /// /// 扣血 /// /// func (this *HealthPoint) Minus(value float32) { this.Hp.Minus(value) } /// /// 加血 /// func (this *HealthPoint) Add(value float32) { if FixedPoint_Add(this.Hp.Fixed(), NewFixedPoint(value)).rawValue > this.CurrMaxHp.Fixed().rawValue { this.Reset() } else { this.Hp.Add(value) } } /// /// 获取治疗溢出值 /// func (this *HealthPoint) Overflow(value float32) float32 { if FixedPoint_Add(this.Hp.Fixed(), NewFixedPoint(value)).rawValue > this.CurrMaxHp.Fixed().rawValue { return FixedPoint_Divide(FixedPoint_Add(this.Hp.Fixed(), NewFixedPoint(value)), this.CurrMaxHp.Fixed()).Scalar() } return 0 } /// /// 剩余血量百分比 /// func (this *HealthPoint) Percent() float32 { return FixedPoint_Divide(this.Hp.Fixed(), this.CurrMaxHp.Fixed()).Scalar() }