2023-08-18 10:06:17 +08:00
|
|
|
package system
|
|
|
|
|
2023-08-18 11:02:00 +08:00
|
|
|
import (
|
|
|
|
"github.com/yohamta/donburi/filter"
|
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/components"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 百分比设备系统
|
2023-08-18 10:06:17 +08:00
|
|
|
type PercentageSystem struct {
|
2023-08-18 11:02:00 +08:00
|
|
|
query *ecs.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPercentageSystem() *PercentageSystem {
|
|
|
|
return &PercentageSystem{query: ecs.NewQuery(filter.Contains(components.PercentageDeviceComponent, components.PercentageDeviceOperatingComponent))}
|
2023-08-18 10:06:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// world 执行
|
|
|
|
func (me *PercentageSystem) Update(world ecs.World) {
|
2023-08-18 11:02:00 +08:00
|
|
|
me.query.Each(world, func(e *ecs.Entry) {
|
|
|
|
operation := components.PercentageDeviceOperatingComponent.Get(e)
|
|
|
|
if operation.RemainingDistance <= 0 {
|
|
|
|
operation.RemainingDistance = 0
|
|
|
|
e.RemoveComponent(components.PercentageDeviceOperatingComponent)
|
|
|
|
} else {
|
|
|
|
operation.RemainingDistance -= int64(world.Tick())
|
2023-08-18 14:40:13 +08:00
|
|
|
if operation.RemainingDistance < 0 {
|
|
|
|
operation.RemainingDistance = 0
|
|
|
|
}
|
2023-08-18 11:02:00 +08:00
|
|
|
}
|
|
|
|
//
|
|
|
|
rateDevice := components.PercentageDeviceComponent.Get(e)
|
2023-08-18 16:15:19 +08:00
|
|
|
if operation.ToH { //百分比变大
|
2023-08-18 11:02:00 +08:00
|
|
|
rateDevice.Rate = int32(float64(100) * (float64(operation.InitDistance+operation.SumDistance-operation.RemainingDistance) / float64(operation.LhDistance)))
|
|
|
|
} else {
|
2023-08-18 14:40:13 +08:00
|
|
|
rateDevice.Rate = 100 - int32(float64(100)*(float64(operation.InitDistance+operation.SumDistance-operation.RemainingDistance)/float64(operation.LhDistance)))
|
2023-08-18 11:02:00 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|