package effect

import (
	"blazing/common/utils"
	"blazing/logic/service/fight/info"
	"blazing/logic/service/fight/input"
	"blazing/logic/service/fight/node"
)

// 施加一个基类effect
type Effect0 struct {
	node.EffectNode
}

// 技能命中计算
func (this *Effect0) IsHit(opp *input.Input, skill *info.SkillEntity) {
	skill.AttackTimeC(int(opp.GetProp(5, true))) //计算命中
}

// 比如xx技能无效
func (this *Effect0) UseSkill(opp *input.Input) bool {
	return true
}

func (this *Effect0) IsCrit(opp *input.Input, skill *info.SkillEntity) {
	skill.Crit = 0
	CritRate := utils.Max(skill.CritRate, 1)
	CritRateR := this.Input.FightC.GetRand().Int31n(16)
	//CritAtkFirst: 先出手时必定致命一击; 默认: 0
	if skill.CritAtkFirst != 0 && this.Input.First {
		CritRate = 16
	}
	//CritAtkSecond: 后出手时必定致命一击; 默认: 0
	if skill.CritAtkSecond != 0 && !this.Input.First {
		CritRate = 16
	}
	// CritSelfHalfHp: 自身体力低于一半时必定致命一击; 默认: 0
	if skill.CritSelfHalfHp != 0 && (this.Input.CurrentPet.HP < int(this.Input.CurrentPet.Info.MaxHp)/2) {
		CritRate = 16
	}
	//  CritFoeHalfHp: 对方体力低于一半时必定致命一击; 默认: 0
	if skill.CritSelfHalfHp != 0 && (opp.CurrentPet.HP < int(opp.CurrentPet.Info.MaxHp)/2) {
		CritRate = 16
	}

	//todo 暴击伤害
	if CritRateR <= int32(CritRate) {
		skill.Crit = 1
	}

}
func init() {
	input.InitDamageEffect(1, &Effect0{})

}
