package fishing

import (
	"math"
	"mongo.games.com/game/gamesrv/base"
	"mongo.games.com/goserver/core"
	"time"
)

type Fish struct {
	FishID      int32   // 唯一标识 PolicyId*1000000 + int32(value.GetId())*100 + int32(index+1)
	TemplateID  int32   // 鱼id
	DropCoin    int32   // 掉落倍率
	MaxDropCoin int32   //最大掉落倍率
	Path        int32   // 鱼路径id
	BirthTick   int32   // 出生帧
	LiveTick    int32   // 存活帧（最多活到第几帧）
	Event       int32   // 事件标签，用于记录当前 鱼所触发的状态
	InitTime    int64   // 创建时间
	Death       bool    // 是否死亡
	Speed       int32   // 速度修正参数
	IsBoss      int32   // 是否boss
	IsJackpot   bool    //（天天捕鱼）
	DealRate    int32   //（天天捕鱼）
	FishType    int32   // 当前鱼是属于 第几类鱼 目前一共有 8 类（天天捕鱼）
	Rate        int32   //鱼死亡概率
	Name        string  //名字
	Gold        int32   //金币
	Exp         int32   //经验
	Child       []int32 //孩子
}

func (this *Fish) IsBirth(timePoint int32) bool {
	return this.BirthTick <= timePoint && timePoint <= this.LiveTick
}
func (this *Fish) SetDeath() {
	this.Death = true
	this.LiveTick = 0
}
func (this *Fish) IsDeath(timePoint int32) bool {
	if this.Death {
		return true
	}
	//return this.BirthTick > timePoint && timePoint > this.LiveTick
	return this.BirthTick < timePoint && timePoint > this.LiveTick
}

func init() {
	core.RegisteHook(core.HOOK_BEFORE_START, func() error {
		base.FishTemplateEx.Reload()
		base.FishOutEx.InitFishAppear()
		return nil
	})
}

// AddTime 增加帧
func (this *Fish) AddTime(offset int32) {
	this.BirthTick += offset
	this.LiveTick += offset
	fishlogger.Tracef("冰冻-暂停出鱼，增加鱼的补偿帧 offset = %v,fishType = %v,当前鱼的出生帧：%v,结束帧：%v", offset, this.FishType, this.BirthTick, this.LiveTick)
}
func (this *Fish) InitCrashDetect(offset int, path *FishPath) {
	// 修正 串串鱼需要补偿时间 暂时不需要
	//if f.appear != AppearFishString {
	//	offset = 0
	//}
	// 初始化
	this.InitTime = time.Now().Unix()
	this.LiveTick = int32(math.Ceil(float64(path.DisappearTime*100)/float64(this.Speed) + float64(offset)))

	// 修正消失时间
	this.LiveTick += ExtraAppearTime
	fishlogger.Infof("初始化碰撞检测 修正后的鱼的出现帧：%v,鱼的消失帧：%v", this.BirthTick, this.LiveTick)
}
