-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_catch.go
More file actions
56 lines (39 loc) · 1.32 KB
/
command_catch.go
File metadata and controls
56 lines (39 loc) · 1.32 KB
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
package main
import (
"fmt"
"math/rand"
)
func catchCommand(c *config, args ...string) error {
if len(args) != 1 {
return fmt.Errorf("missing required argument: <pokemon name>")
}
name := args[0]
mon, err := c.client.GetPokemonAndSpecies(name)
if err != nil {
return err
}
formattedName := getFormattedName(c, mon)
printLine("Throwing a Pokéball at %s...", formattedName)
pokemonSpecies := mon.SpeciesEntry
rate := pokemonSpecies.CaptureRate
roll := rand.Int() % 255
if roll < rate {
printLine("%s was caught! (rate: %d, roll: %d)", formattedName, rate, roll)
mon.SpeciesEntry = pokemonSpecies
c.pokedex[pokemonSpecies.Name] = mon
c.box = append(c.box, mon)
printLine("You have registered %d Pokémon Species in your Pokédex.", len(c.pokedex))
printLine("You have %d Pokémon in your box.", len(c.box))
if c.currentEncounter != nil && c.currentEncounter.Name == mon.Name {
c.currentEncounter = nil
}
c.latestCaught = &pokemonSpecies.Name
printLine()
printLine("Type:")
printLine(" %sinspect%s to view the Pokédex entry on %s", c.colors.Blue, c.colors.Reset, formattedName)
printLine(" %spokedex%s to view a list of all Pokémon in your Pokédex", c.colors.Blue, c.colors.Reset)
} else {
printLine("%s broke free! (rate: %d, roll: %d)", formattedName, rate, roll)
}
return nil
}