rts-sim-module/sys/iscs_sys/iscs_bas_purification_device.go

37 lines
973 B
Go
Raw Normal View History

package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
// PurificationDeviceSystem 净化装置
type PurificationDeviceSystem struct {
query *ecs.Query
}
func NewPurificationDeviceSystem() *PurificationDeviceSystem {
return &PurificationDeviceSystem{
query: ecs.NewQuery(filter.Contains(component.PurificationDeviceType, component.CounterType)),
}
}
func (s *PurificationDeviceSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
pd := component.PurificationDeviceType.Get(entry)
counter := component.CounterType.Get(entry)
if pd.Starting {
counter.Step = w.Tick()
if counter.Val >= component.PurificationDeviceStartTime { //启动延时结束
pd.Starting = false
counter.Step = 0
if entry.HasComponent(component.DeviceStartTimeoutTag) { //设置启动超时故障
pd.Running = false //启动失败
} else {
pd.Running = true
}
}
}
})
}