1package server 2 3import ( 4 "errors" 5 6 "tinyadventure/internal/model" 7 "tinyadventure/internal/world" 8) 9 10const ( 11 dayLength = 140 12 nightLength = 40 13 fightTime = 8 14) 15 16func newClock() model.Clock { 17 return model.Clock{Day: 1, DayLength: dayLength, NightLength: nightLength} 18} 19 20func (g *game) pass(t int) { 21 c := &g.state.Clock 22 dusk := c.Night() 23 c.Time += t 24 if c.Time >= c.DayLength+c.NightLength { 25 c.Day++ 26 c.Time = 0 27 g.note("Dawn breaks without rest") 28 } else if !dusk && c.Night() { 29 g.note("Night falls. Make camp, or press on in the dark") 30 } 31} 32 33func (g *game) rest() error { 34 c := &g.state.Clock 35 if !c.Night() { 36 return errors.New("too early to make camp: rest after dusk") 37 } 38 if g.blockerNear() { 39 return errors.New("enemies are too close to make camp") 40 } 41 g.begin() 42 g.heal(true) 43 g.state.Summary.Camps++ 44 c.Day++ 45 c.Time = 0 46 return nil 47} 48 49func (g *game) blockerNear() bool { 50 px, py := g.state.Party.X, g.state.Party.Y 51 for _, p := range g.state.Map.POIs { 52 if !p.Cleared && world.Distance(p.X, p.Y, px, py) <= 1 { 53 return true 54 } 55 } 56 for _, b := range g.state.Map.Bands { 57 if !b.Cleared && world.Distance(b.X, b.Y, px, py) <= 1 { 58 return true 59 } 60 } 61 return false 62}