示例#1
0
文件: ai.go 项目: sguzwf/ouster
func (ai *MonsterAI) useSkill(pEnemy CreatureInterface, SkillType SkillType_t, ratio int) int {
	// enemy := pEnemy.CreatureInstance()
	// ex := enemy.X
	// ey := enemy.Y
	// dist := ai.Body.getDistance(ex, ey)

	if rand.Intn(100) >= ratio {
		// return SKILL_FAILED_RATIO
		return -1
	}

	if ai.Body.isFlag(EFFECT_CLASS_HIDE) {
		SkillType = SKILL_UN_BURROW
	} else if ai.Body.isFlag(EFFECT_CLASS_TRANSFORM_TO_BAT) {
		SkillType = SKILL_UN_TRANSFORM
	} else if ai.Body.isFlag(EFFECT_CLASS_INVISIBILITY) {
		SkillType = SKILL_UN_INVISIBILITY
	}

	skill, ok := skillTable[SkillType]
	if !ok {
		log.Errorf("技能%d的handler没有实现!!", SkillType)
		return 0
	}

	switch handler := skill.(type) {
	case SkillToObjectInterface:
		// 移动计算,以闭包形式发到agent的goroutine中运行
		if agent, ok := pEnemy.(*Agent); ok {
			closure := func() {
				handler.ExecuteToObject(ai.Body, pEnemy)
			}
			agent.computation <- closure
		} else {
			log.Errorln("怪物打怪物还没实现")
		}

		ai.LastAction = LAST_ACTION_SKILL
	default:
		log.Warnln("skill handler没有实现", SkillType)
	}

	return 0
}
示例#2
0
文件: monster.go 项目: sguzwf/ouster
func NewMonster(monsterType MonsterType_t) *Monster {
	info, ok := data.MonsterInfoTable[monsterType]
	if !ok {
		log.Warnln("未知的monster类型:", monsterType)
		return nil
	}

	ret := &Monster{
		MonsterType:  monsterType,
		Name:         info.Name,
		STR:          info.STR,
		DEX:          info.DEX,
		INI:          info.INTE,
		Exp:          info.Exp,
		MeleeRange:   info.MeleeRange,
		MissileRange: info.MissileRange,
		MainColor:    info.MColor,
		SubColor:     info.SColor,
		MoveMode:     info.MoveMode,
	}

	ret.Sight = info.Sight
	ret.Level = info.Level
	ret.Delay = time.Duration(info.Delay) * time.Millisecond
	ret.AttackDelay = ret.Delay

	ret.computeHP()
	ret.HP[ATTR_CURRENT] = ret.HP[ATTR_MAX]

	ret.computeToHit()
	ret.computeDefense()
	ret.computeProtection()
	ret.computeMinDamage()
	ret.computeMaxDamage()

	ret.Brain = NewMonsterAI(ret, info.AIType)
	ret.Enemies = make(map[ObjectID_t]CreatureInterface)
	ret.EffectManager = NewEffectManager()
	ret.Creature.Init()

	return ret
}