diff options
Diffstat (limited to 'internal/game/cmd_move.go')
| -rw-r--r-- | internal/game/cmd_move.go | 73 |
1 files changed, 66 insertions, 7 deletions
diff --git a/internal/game/cmd_move.go b/internal/game/cmd_move.go index a140003..2a3e698 100644 --- a/internal/game/cmd_move.go +++ b/internal/game/cmd_move.go @@ -4,7 +4,9 @@ import ( "fmt" "thehouseoficarus/internal/combat" + "thehouseoficarus/internal/engine" "thehouseoficarus/internal/net" + "thehouseoficarus/internal/object" "thehouseoficarus/internal/player" ) @@ -45,17 +47,74 @@ func (g *Game) doMove(sess *net.Session, dir string) { return } - if cs := combat.GetCombat(p.Name); cs != nil && cs.LockedTicks > 0 { - sess.WriteLine(fmt.Sprintf("You are locked in combat for another %d tick%s!", cs.LockedTicks, plural(cs.LockedTicks))) + inCombat := combat.GetCombat(p.Name) != nil + + if !inCombat && p.Action != nil { + g.CancelAction(p) + } + + ticks := g.moveTicks(p) + p.MoveDirection = string(exitDir) + p.MoveTarget = targetID + + if ticks <= 0 { + g.completeMove(sess, p) return } - g.stopCombat(p.Name) + p.MoveTicks = ticks + p.ActionState = &ActionState{Type: ActionMoving, Direction: string(exitDir)} - if p.Action != nil { - g.CancelAction(p) + if inCombat && p.OptionBool("run_countdown") { + if p.MoveTicks > 1 { + sess.WriteLine(fmt.Sprintf("Running in %d ticks...", p.MoveTicks)) + } else { + sess.WriteLine("Running next tick!") + } + } +} + +var gracefulItems = map[string]bool{ + "graceful_hat": true, + "graceful_torso": true, + "graceful_legs": true, + "graceful_gloves": true, + "graceful_boots": true, + "graceful_cape": true, +} + +func (g *Game) moveTicks(p *player.Player) int { + if id, ok := p.Equipment[object.SlotBack]; ok && id == "cape_of_agility" { + return 0 } + count := 0 + for _, id := range p.Equipment { + if gracefulItems[id] { + count++ + } + } + + base := 4.0 - float64(count)*0.25 + if count == 6 { + base -= 0.5 + } + + return engine.ToTicks(base) - 1 +} + +func (g *Game) completeMove(sess *net.Session, p *player.Player) { + exitDir := p.MoveDirection + targetID := p.MoveTarget + + p.ClearMoveState() + + if combat.GetCombat(p.Name) != nil { + g.stopCombat(p.Name) + } + + p.Action = nil + oldRoom := p.RoomID p.RoomID = targetID g.AccountStore.SaveCharacter(p) @@ -78,8 +137,8 @@ func (g *Game) doMove(sess *net.Session, dir string) { } } - sess.WriteLine(fmt.Sprintf("\nYou walk %s.", g.colorize(sess, "direction", string(exitDir)))) - p.ActionState = &ActionState{Type: ActionMoving, Direction: string(exitDir)} + sess.WriteLine(fmt.Sprintf("\nYou walk %s.", g.colorize(sess, "direction", exitDir))) + p.ActionState = &ActionState{Type: ActionMoving, Direction: exitDir} if p.OptionBool("description") { g.doLook(sess) } else { |
