diff options
Diffstat (limited to 'internal/game/action_agility.go')
| -rw-r--r-- | internal/game/action_agility.go | 74 |
1 files changed, 34 insertions, 40 deletions
diff --git a/internal/game/action_agility.go b/internal/game/action_agility.go index f916a8d..116e888 100644 --- a/internal/game/action_agility.go +++ b/internal/game/action_agility.go @@ -24,42 +24,36 @@ func (g *Game) startObstacle(sess *net.Session, p *player.Player, info *Obstacle } p.Action = &action.Action{ - Type: "obstacle", + Type: action.TypeObstacle, TargetID: info.CourseID, TargetName: info.CourseName, WaitLeft: 0, - Data: map[string]any{ - "course_id": info.CourseID, - "phase": 0, - "obstacle_index": info.ObstacleIndex, - "total_obstacles": info.TotalObstacles, - "next_room": info.NextRoom, - "start_room": info.StartRoom, - "obstacle_xp": info.ObstacleXP, - "completion_xp": info.CompletionXP, - "fail_chance": failChance, - "fail_damage_min": info.FailDamage[0], - "fail_damage_max": info.FailDamage[1], - "messages": msgs, - "ticks_per_phase": info.TicksPerPhase, - "required_level": info.RequiredLevel, + Data: &action.ObstacleData{ + CourseID: info.CourseID, + Phase: 0, + ObstacleIndex: info.ObstacleIndex, + TotalObstacles: info.TotalObstacles, + NextRoom: info.NextRoom, + StartRoom: info.StartRoom, + ObstacleXP: info.ObstacleXP, + CompletionXP: info.CompletionXP, + FailChance: failChance, + FailDamageMin: info.FailDamage[0], + FailDamageMax: info.FailDamage[1], + Messages: msgs, + TicksPerPhase: info.TicksPerPhase, + RequiredLevel: info.RequiredLevel, }, } - p.ActionState = &ActionState{ - Type: ActionTraversing, - Verb: gerund, - TargetName: info.CourseName, - } - g.broadcastAction(sess, "\n%s starts %s on the %s.", p.Name, gerund, info.CourseName) } func (g *Game) advanceObstacle(sess *net.Session, p *player.Player) { - data := p.Action.Data - phase := data["phase"].(int) - messages := data["messages"].([]any) - ticksPerPhase := data["ticks_per_phase"].(float64) + d := p.Action.Data.(*action.ObstacleData) + phase := d.Phase + messages := d.Messages + ticksPerPhase := d.TicksPerPhase if phase >= len(messages) { g.cancelAction(p) @@ -70,9 +64,9 @@ func (g *Game) advanceObstacle(sess *net.Session, p *player.Player) { sess.WriteLine(g.colorize(sess, "broadcast", msg)) if phase == 1 { - failChance := data["fail_chance"].(float64) + failChance := d.FailChance if rand.Float64() < failChance { - g.obstacleFail(sess, p, data) + g.obstacleFail(sess, p, d) return } } @@ -80,13 +74,13 @@ func (g *Game) advanceObstacle(sess *net.Session, p *player.Player) { nextPhase := phase + 1 if nextPhase >= len(messages) { - obstacleXP := data["obstacle_xp"].(int) - completionXP := data["completion_xp"].(int) - nextRoom := data["next_room"].(int) - startRoom := data["start_room"].(int) - obstacleIndex := data["obstacle_index"].(int) - totalObstacles := data["total_obstacles"].(int) - courseID := data["course_id"].(string) + obstacleXP := d.ObstacleXP + completionXP := d.CompletionXP + nextRoom := d.NextRoom + startRoom := d.StartRoom + obstacleIndex := d.ObstacleIndex + totalObstacles := d.TotalObstacles + courseID := d.CourseID if obstacleXP > 0 { g.awardSkillXP(sess, p, player.Agility, obstacleXP) @@ -126,14 +120,14 @@ func (g *Game) advanceObstacle(sess *net.Session, p *player.Player) { return } - data["phase"] = nextPhase + d.Phase = nextPhase p.Action.WaitLeft = engine.ToTicks(ticksPerPhase) } -func (g *Game) obstacleFail(sess *net.Session, p *player.Player, data map[string]any) { - startRoom := data["start_room"].(int) - failMin := data["fail_damage_min"].(int) - failMax := data["fail_damage_max"].(int) +func (g *Game) obstacleFail(sess *net.Session, p *player.Player, d *action.ObstacleData) { + startRoom := d.StartRoom + failMin := d.FailDamageMin + failMax := d.FailDamageMax damage := failMin if failMax > failMin { |
