Exemple #1
0
func MonsterAttackToPlayer(monster *g.Monster, player *g.Player) (battleLog []string) {
	battleLog = make([]string, 0)
	battleLog = append(battleLog, "***")
	if !monster.IsLive() || !player.IsLive() {
		return
	}
	attacker := Attack{monster}

	if attacker.Miss(player) {
		battleLog = append(battleLog, fmt.Sprintln("Промах!"))
		return
	}
	damage, resultDamage := attacker.AttackTo(player)
	battleLog = append(battleLog, fmt.Sprintln(monster.Name(), "атаковал:", strconv.Itoa(damage)))
	battleLog = append(battleLog, fmt.Sprintln("Вы понесли урон:", strconv.Itoa(resultDamage)))

	return
}
Exemple #2
0
func PlayerAttackToMonster(player *g.Player, monster *g.Monster) (battleLog []string) {
	battleLog = make([]string, 0)
	battleLog = append(battleLog, "***")
	if !monster.IsLive() || !player.IsLive() {
		return battleLog
	}
	if player.MP-player.CurrentWeapon().ManaCost < 0 {
		battleLog = append(battleLog, fmt.Sprintln("Недостаточно маны"))
		return
	}
	player.MP -= player.CurrentWeapon().ManaCost
	battleLog = append(battleLog, fmt.Sprintln("Вы атаковали:", monster.Name(), "("+strconv.Itoa(monster.HP)+")"))
	attacker := Attack{player}

	if attacker.Miss(monster) {
		battleLog = append(battleLog, fmt.Sprintln("Промах!"))
		return
	}

	damage, resultDamage := attacker.AttackTo(monster)

	battleLog = append(battleLog, fmt.Sprintln("Удар по противнику:", strconv.Itoa(damage)))
	battleLog = append(battleLog, fmt.Sprintln("Противник теряет", strconv.Itoa(resultDamage), "жизней"))

	if !monster.IsLive() {
		battleLog = append(battleLog, fmt.Sprintln("Противник пал"))
	}

	return battleLog
}