예제 #1
0
//判断本次攻击是否致命攻击
func IsCriticalAttack(attacker, defender *Warrior, attackNature nature.Nature) bool {
	if attackNature == nature.Physical {
		//如果是物理攻击,则看【物理暴击率】
		return math.IsHitByFloatProbability(attacker.CriticalRatePhysical.GetValue().Get())
	} else if attackNature == nature.Magical {
		//如果是魔法攻击,则看【魔法暴击率】

		return math.IsHitByFloatProbability(attacker.CriticalRateMagical.GetValue().Get())
	} else {
		return false
	}
}
예제 #2
0
파일: skill.go 프로젝트: wbpmrck/survive
func (self *SkillItem) Install() {
	releaser := self.SkillParent.Carrier
	//在技能持有者身上订阅触发技能的事件
	if releaser != nil {
		//在指定的阶段
		stepName := self.PluginStep.StepName

		//技能项在指定阶段决定是否进行效果释放处理。
		//返回信息
		//类型:*SkillItem
		releaser.On(stepName, event.NewEventHandler(func(contextParams ...interface{}) (isCancel bool, handleResult interface{}) {

			//先看概率是否释放
			thisTimeProbabilityHit := math.IsHitByFloatProbability(self.Probability.GetValue().Get())
			if thisTimeProbabilityHit {
				//概率命中了,还要看是否能找到作用对象

				//再找到指定的作用对象
				targets, err := self.Chooser.Choose(releaser, stepName, contextParams...)
				if !err && targets != nil && len(targets) > 0 {

					//有作用对象,还要看pre 阶段是否被取消
					cancel := false

					//触发技能持有者的技能释放事件(前)
					//处理函数将得到一个参数:*SkillItem
					onBeforeResults := releaser.Emit(EVENT_BEFORE_SKILL_ITEM_RELEASE, releaser, self)
					for _, r := range onBeforeResults {
						if r.IsCancel {
							cancel = true
							//执行cancel 阶段[技能被取消释放]
							releaser.Emit(EVENT_CANCEL_SKILL_ITEM_RELEASE, releaser, self)
							break
						}
					}
					//没取消,进入释放
					if !cancel {
						releaser.Emit(EVENT_SKILL_ITEM_RELEASE, releaser, self)
						for _, target := range targets {
							//对每一个效果,使用PutOn进行触发
							for _, effectItem := range self.EffectItems {
								effectItem.PutOn(releaser, target)
							}
						}
						handleResult = self //释放成功
						//释放结束,执行 after 阶段
						releaser.Emit(EVENT_AFTER_SKILL_ITEM_RELEASE, releaser, self)
					}

				}
			}

			return
		}))
	}
}