aboutsummaryrefslogtreecommitdiff
path: root/internal/game/act_finishing_blow.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/act_finishing_blow.go')
-rw-r--r--internal/game/act_finishing_blow.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/internal/game/act_finishing_blow.go b/internal/game/act_finishing_blow.go
new file mode 100644
index 0000000..fbd9781
--- /dev/null
+++ b/internal/game/act_finishing_blow.go
@@ -0,0 +1,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)
+}