go_dreamfactory/modules/battle/fight/attribute/fixednumeric.go
2022-09-21 14:44:44 +08:00

55 lines
1.1 KiB
Go

package attribute
func NewFixedNumeric(pData float32) FixedNumeric {
fixed := FixedNumeric{}
fixed.SetFloat(pData)
return fixed
}
type FixedNumeric struct {
baseValue FixedPoint
}
func (this FixedNumeric) Fixed() FixedPoint {
return this.baseValue
}
func (this FixedNumeric) Value() float32 {
return this.baseValue.Scalar()
}
func (this FixedNumeric) GetValue(pDefault float32) float32 {
if this.Value() != 0 {
return this.Value()
} else {
return pDefault
}
}
func (this FixedNumeric) SetFloat(value float32) float32 {
this.baseValue = NewFixedPoint(value)
return this.baseValue.Scalar()
}
func (this FixedNumeric) Set(value FixedPoint) float32 {
this.baseValue = value
return this.baseValue.Scalar()
}
/// <summary>
/// 增加基本值
/// </summary>
func (this FixedNumeric) Add(value float32) float32 {
this.baseValue.Add(value)
return this.baseValue.Scalar()
}
/// <summary>
/// 减少基本值
/// </summary>
func (this FixedNumeric) Minus(value float32) float32 {
this.baseValue.Reduce(value)
if this.baseValue.Scalar() < 0 {
this.baseValue.SetInt(0)
}
return this.baseValue.Scalar()
}