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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
"thehouseoficarus/internal/world"
)
func (g *Game) tryFinishingBlow(sess *net.Session, input string) bool {
p := sess.Player
cs := g.Combat.Get(p.Name)
if cs == nil {
return false
}
mob := g.MobStore.GetInstance(cs.MobID)
if mob == nil || mob.FinishingBlow == "" || mob.HP != 1 {
return false
}
lower := strings.ToLower(input)
var itemPart, targetPart string
for _, sep := range []string{" on ", " with "} {
if idx := strings.Index(lower, sep); idx > 0 {
itemPart = strings.TrimSpace(input[:idx])
targetPart = strings.TrimSpace(input[idx+len(sep):])
break
}
}
if targetPart == "" {
itemPart = strings.TrimSpace(input)
if mob.MatchQuality(itemPart) != world.MatchNone {
targetPart = itemPart
itemPart = strings.TrimSpace(mob.FinishingBlow)
}
}
if targetPart == "" {
return false
}
if mob.MatchQuality(targetPart) == world.MatchNone {
return false
}
g.doFinishingBlow(sess, p, mob, itemPart)
return true
}
func (g *Game) doFinishingBlow(sess *net.Session, p *player.Player, mob *world.MobInstance, itemInput string) {
fbDef, err := g.ItemStore.Load(mob.FinishingBlow)
if err != nil {
sess.WriteLine("Something went wrong.")
return
}
if !fbDef.MatchesName(itemInput) && !strings.EqualFold(itemInput, fbDef.ID) {
sess.WriteLine(fmt.Sprintf("That won't work on %s. You need %s.", mobDisplayName(mob, true), g.itemColorize(sess, fbDef, fbDef.Name)))
return
}
if !p.HasItem(mob.FinishingBlow) {
sess.WriteLine(fmt.Sprintf("You don't have any %s.", g.itemColorize(sess, fbDef, fbDef.Name)))
return
}
autoKey := "assassin_unlocked_auto_" + mob.FinishingBlow
consumed := true
if p.Flags != nil {
if val, ok := p.Flags[autoKey]; ok {
if b, ok := val.(bool); ok && b {
consumed = false
}
}
}
if consumed {
p.RemoveItem(mob.FinishingBlow, 1)
}
sess.WriteLine(fmt.Sprintf("You use the %s on %s!", g.itemColorize(sess, fbDef, fbDef.Name), g.colorize(sess, "mob", mobDisplayName(mob, true))))
mob.HP = 0
g.endCombat(sess, p, mob)
}
|