go_dreamfactory/modules/battle/fight/attribute/healthpoint.go
2022-09-26 20:25:20 +08:00

127 lines
3.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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())
}
func (this *HealthPoint) OnChange() {
//先计算当前血量百分比
var per = this.Percent()
// 当前最大生命值 = 总生命 * 1 + 当前最大生命百分比加成 + 当前最大生命加成
//FightDebug.Log($"增加前属性{(MaxHp.Fixed)}----- {(1 + CurrMaxHpPro.Fixed)}----- {CurrMaxHpAppend.Fixed}");
this.CurrMaxHp.SetBase((FixedPoint_Multiply(this.MaxHp.Fixed(), (NewFixedPoint(1)+this.CurrMaxHpPro.Fixed())) + this.CurrMaxHpAppend.Fixed()).Scalar())
//计算变化之后的当前血量
var curHp = FixedPoint_Multiply(this.CurrMaxHp.Fixed(), NewFixedPoint(per))
this.Hp.Set(curHp)
//FightDebug.Log($"增加后属性{(MaxHp.Fixed)}----- {(1 + CurrMaxHpPro.Fixed)}----- {CurrMaxHpAppend.Fixed}");
}
/// <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)) > this.CurrMaxHp.Fixed() {
this.Reset()
} else {
this.Hp.Add(value)
}
}
/// <summary>
/// 获取治疗溢出值
/// </summary>
func (this *HealthPoint) Overflow(value float32) float32 {
if FixedPoint_Add(this.Hp.Fixed(), NewFixedPoint(value)) > this.CurrMaxHp.Fixed() {
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()
}
/// <summary>
/// 损失血量百分比
/// </summary>
func (this *HealthPoint) LostPercent() float32 {
return FixedPoint_Divide((this.CurrMaxHp.Fixed() - this.Hp.Fixed()), this.CurrMaxHp.Fixed()).Scalar()
}
/// <summary>
/// 指定百分比血量
/// </summary>
func (this *HealthPoint) PercentHealth(pct float32) float32 {
return FixedPoint_Multiply(this.CurrMaxHp.Fixed(), NewFixedPoint(pct)).Scalar()
}
/// <summary>
/// 扣除的血量
/// </summary>
func (this *HealthPoint) Deduct() float32 {
return FixedPoint(this.CurrMaxHp.Fixed() - this.Hp.Fixed()).Scalar()
}
/// <summary>
/// 是否满血
/// </summary>
func (this *HealthPoint) IsFull() bool {
return this.Hp.Fixed() == this.CurrMaxHp.Fixed()
}