87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
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),
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生命值实体
|
|
/// </summary>
|
|
type HealthPoint struct {
|
|
/// <summary>
|
|
/// 生命值
|
|
/// </summary>
|
|
Hp *FixedNumeric
|
|
/// <summary>
|
|
/// 最大生命值
|
|
/// </summary>
|
|
MaxHp *AttributeNumeric
|
|
/// <summary>
|
|
/// 当前最大生命值
|
|
/// </summary>
|
|
CurrMaxHp *AttributeNumeric
|
|
/// <summary>
|
|
/// 当前最大生命百分比加成
|
|
/// </summary>
|
|
CurrMaxHpPro *AttributeNumeric
|
|
/// <summary>
|
|
/// 当前最大生命加成
|
|
/// </summary>
|
|
CurrMaxHpAppend *AttributeNumeric
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重置当前生命值为最大值
|
|
/// </summary>
|
|
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())
|
|
}
|
|
|
|
/// <summary>
|
|
/// 扣血
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
func (this *HealthPoint) Minus(value float32) {
|
|
this.Hp.Minus(value)
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加血
|
|
/// </summary>
|
|
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)
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取治疗溢出值
|
|
/// </summary>
|
|
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
|
|
}
|
|
|
|
/// <summary>
|
|
/// 剩余血量百分比
|
|
/// </summary>
|
|
func (this *HealthPoint) Percent() float32 {
|
|
return FixedPoint_Divide(this.Hp.Fixed(), this.CurrMaxHp.Fixed()).Scalar()
|
|
}
|