49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package iscs_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/consts"
|
|
)
|
|
|
|
// 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
|
|
}
|
|
}
|
|
}
|
|
//
|
|
pd.Exception = consts.DeviceExceptionNon
|
|
if entry.HasComponent(component.DeviceStartTimeoutTag) {
|
|
pd.Exception = consts.DeviceStartTimeout
|
|
}
|
|
if entry.HasComponent(component.DeviceAbnormalTag) {
|
|
pd.Exception = consts.DeviceAbnormal
|
|
}
|
|
if entry.HasComponent(component.DeviceCommunicationInterruptTag) {
|
|
pd.Exception = consts.DeviceCommunicationInterrupt
|
|
}
|
|
})
|
|
}
|