aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_attack.go
blob: 5635fd0e3b34f20a922c6b88562ec2a16c6d9e4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package game

import (
	"fmt"
	"strings"

	"thehouseoficarus/internal/net"
)

func (g *Game) executeAttack(sess *net.Session, args []string, rawInput string) {
	if len(args) == 0 {
		p := sess.Player
		target := g.resolveDefaultMob(p.RoomID)
		if target == "" {
			sess.WriteLine("Attack what?")
			return
		}
		g.doAttack(sess, target)
	} else {
		g.doAttack(sess, strings.Join(args, " "))
	}
}

// executeWork is the non-violent alias of attack. It routes to the same engine;
// doAttack auto-detects whether the target is a task worksite or a combat mob.
func (g *Game) executeWork(sess *net.Session, args []string, rawInput string) {
	if len(args) == 0 {
		p := sess.Player
		target := g.resolveDefaultMob(p.RoomID)
		if target == "" {
			sess.WriteLine("Work on what?")
			return
		}
		g.doAttack(sess, target)
	} else {
		g.doAttack(sess, strings.Join(args, " "))
	}
}

func (g *Game) respawnMob(instanceID string) {
	inst := g.MobStore.GetInstance(instanceID)
	if inst == nil {
		return
	}
	homeRoom := inst.HomeRoomID
	inst.RoomID = homeRoom
	inst.HP = inst.MaxHP
	g.MobStore.RollIdleDescription(inst)

	if g.Hub != nil {
		for _, sess := range g.Hub.PlayersInRoom(homeRoom) {
			if p := sess.Player; p != nil && p.OptionBool("mob_spawn") {
				mobLvl := mobCombatLevel(inst)
				levelStr := g.levelColorize(sess, p.CombatLevel(), mobLvl, fmt.Sprintf("(level %d)", mobLvl))
				sess.WriteLine(fmt.Sprintf("\n%s %s spawns in the area.", g.colorize(sess, "mob", mobDisplayName(inst, false)), levelStr))
			}
		}
	}
}