47 lines
847 B
Go
47 lines
847 B
Go
package fight
|
|
|
|
import (
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules/battle/fight/core"
|
|
)
|
|
|
|
type Option func(*Options)
|
|
type Options struct {
|
|
Debug bool //日志是否开启
|
|
Log log.ILogger
|
|
battle core.IBattle //战斗模块对象
|
|
}
|
|
|
|
func Set_Battle(v core.IBattle) Option {
|
|
return func(o *Options) {
|
|
o.battle = v
|
|
}
|
|
}
|
|
func Set_Debug(v bool) Option {
|
|
return func(o *Options) {
|
|
o.Debug = v
|
|
}
|
|
}
|
|
|
|
func Set_Log(v log.ILogger) Option {
|
|
return func(o *Options) {
|
|
o.Log = v
|
|
}
|
|
}
|
|
|
|
func newOptionsByOption(opts ...Option) (options *Options, err error) {
|
|
options = &Options{}
|
|
for _, o := range opts {
|
|
o(options)
|
|
}
|
|
if options.Log == nil {
|
|
if options.Debug {
|
|
options.Log = log.NewTurnlog(options.Debug, log.Clone("fight", 4))
|
|
} else {
|
|
options.Log = log.NewTurnlog(options.Debug, nil)
|
|
}
|
|
}
|
|
|
|
return options, nil
|
|
}
|