go_dreamfactory/modules/battle/fight/fightbase.go
2022-10-12 10:13:04 +08:00

197 lines
5.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package fight
import (
"fmt"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules/battle/fight/core"
"math"
"math/rand"
"time"
)
/*
基础战斗控制器
*/
type FightBase struct {
/// 战斗类型
fightId string
/// 战斗是否进行中
fightIng bool
/// 战斗类型
fightType core.FightType
/// 是否自动战斗
autoFight bool
/// 战斗配置参数
options *Options
/// 所有参战角色集合
roles []core.IFightRole
/// 当前回合满足行动值大于等于100的所有角色
canAtkRoles []core.IFightRole
/// 最后一次攻击的角色
lastActionRole core.IFightRole
/// 下一个行动角色
nextAtkRole core.IFightRole
/// 战斗AI
rightAI core.IFightAI
/// 战斗事件
fightEvent core.IFightEvent
/// 战报
fightLog core.IFightLog
/// 随机数种子
randSeed int64
}
func (this *FightBase) Init() {
}
/// 开始战斗
func (this *FightBase) StartFight() {
this.fightIng = true
this.Debug("=========开始战斗=========")
//记录战报
com := new(core.ComStartFight)
com.CurWave = 1
this.fightLog.AddCommand(com)
//发送开始事件
this.fightEvent.Emit(int(core.EventType_OnFightStart))
this.BeforeStart()
}
/// 校验战斗结束
func (this *FightBase) CheckFightEnd() {
}
//初始化相关-----------------------------------------------------------------------------------------------------------------------
/// 战前逻辑
func (this *FightBase) BeforeStart() {
}
/// 触发队长技队长技配置在atk表中触发顺序无所谓
func (this *FightBase) EmitCaptainSkill() {
this.Debug("计算队长技...")
for _, role := range this.roles {
if role.GetData().Captain && role.GetData().CaptainSkillId != 0 {
_skill := role.AddSkill(role.GetData().CaptainSkillId, 1)
if _skill != nil && _skill.GetSkillConf().Type == int32(core.SkillType_Captain) {
_skill.Emit()
_skill.SendSkillLog()
}
}
}
}
/// 获取技能配置
func (this *FightBase) GetSkillConfig(skillId int32, skillLv int32) (conf interface{}) {
skillIdStr := fmt.Sprintf("%d", skillId)
switch skillIdStr[0] {
case '1':
conf, _ = this.options.battle.GetSkillAtk(skillId, skillLv)
break
case '2':
conf, _ = this.options.battle.GetSkillAfteratk(skillId)
break
case '3':
conf, _ = this.options.battle.GetSkillBuff(skillId)
break
case '4':
conf, _ = this.options.battle.GetSkillPassive(skillId)
break
}
if conf == nil {
this.Debugln("GetSkillConfig 时候配置获取失败 SkillId:%d skillLv:%d", skillId, skillLv)
}
return conf
}
//回合-----------------------------------------------------------------------------------------------------------------------
/// 开始一个回合
func (this *FightBase) TurnRound() {
}
//随机-----------------------------------------------------------------------------------------------------------------------
/// 初始化随机种子,以便服务端能生成相同随机数
func (this *FightBase) InitRandSeed() {
rand.Seed(time.Now().UnixNano())
this.randSeed = rand.Int63n(100000 + 1)
}
/// 生成随机数
func (this *FightBase) Rand(min, max int32) int32 {
RandSeed := (this.randSeed*9301 + 49297) % 233280
num := int32(math.Floor(float64(RandSeed/233280.0)*float64(max-min+1) + float64(min)))
return num
}
//Log-----------------------------------------------------------------------------------------------------------------------
//日志接口
func (this *FightBase) Debug(msg string, args ...log.Field) {
this.options.Log.Debug(msg, args...)
}
func (this *FightBase) Info(msg string, args ...log.Field) {
this.options.Log.Info(msg, args...)
}
func (this *FightBase) Print(msg string, args ...log.Field) {
this.options.Log.Print(msg, args...)
}
func (this *FightBase) Warn(msg string, args ...log.Field) {
this.options.Log.Warn(msg, args...)
}
func (this *FightBase) Error(msg string, args ...log.Field) {
this.options.Log.Error(msg, args...)
}
func (this *FightBase) Panic(msg string, args ...log.Field) {
this.options.Log.Panic(msg, args...)
}
func (this *FightBase) Fatal(msg string, args ...log.Field) {
this.options.Log.Fatal(msg, args...)
}
func (this *FightBase) Debugf(format string, args ...interface{}) {
this.options.Log.Debugf(format, args...)
}
func (this *FightBase) Infof(format string, args ...interface{}) {
this.options.Log.Infof(format, args...)
}
func (this *FightBase) Printf(format string, args ...interface{}) {
this.options.Log.Printf(format, args...)
}
func (this *FightBase) Warnf(format string, args ...interface{}) {
this.options.Log.Warnf(format, args...)
}
func (this *FightBase) Errorf(format string, args ...interface{}) {
this.options.Log.Errorf(format, args...)
}
func (this *FightBase) Fatalf(format string, args ...interface{}) {
this.options.Log.Fatalf(format, args...)
}
func (this *FightBase) Panicf(format string, args ...interface{}) {
this.options.Log.Panicf(format, args...)
}
func (this *FightBase) Debugln(args ...interface{}) {
this.options.Log.Debugln(args...)
}
func (this *FightBase) Infoln(args ...interface{}) {
this.options.Log.Infoln(args...)
}
func (this *FightBase) Println(args ...interface{}) {
this.options.Log.Println(args...)
}
func (this *FightBase) Warnln(args ...interface{}) {
this.options.Log.Warnln(args...)
}
func (this *FightBase) Errorln(args ...interface{}) {
this.options.Log.Errorln(args...)
}
func (this *FightBase) Fatalln(args ...interface{}) {
this.options.Log.Fatalln(args...)
}
func (this *FightBase) Panicln(args ...interface{}) {
this.options.Log.Panicln(args...)
}