Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created the troll launcher trigger #30

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

parsec
Copy link
Member

@parsec parsec commented Jul 8, 2021

No description provided.

@parsec parsec requested review from bbriggs and m-242 July 8, 2021 06:56
@parsec parsec added the enhancement New feature or request label Jul 8, 2021
@parsec parsec linked an issue Jul 8, 2021 that may be closed by this pull request
@parsec
Copy link
Member Author

parsec commented Jul 8, 2021

FINALLY

THE BUILD PASSED

func troll(nick, msg string) string {
const TROLL_USAGE = "Usage: !troll <nick>"

msg = strings.Trim(msg, "!troll ")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not strings.Split(msg, " ") and then check length to get the target for the troll launcher?

const TROLL_USAGE = "Usage: !troll <nick>"

msg = strings.Trim(msg, "!troll ")
if len(msg) > 1 || len(msg) < 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is equivalent to len(msg) != 1

return TROLL_USAGE
}

target := string(msg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend against casting this here. If you want to treat a slice of length 1 as a string, just make it a string when you create it initially.

return "Wha?! The trolls missed! That, like, never happens!"
}

return nick + " fires " + numTrolls + " at " + target + ", dealing " + dmg + " points of " + dmgType + " damage!"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many concatenations here. Why not use a format string to make this simpler to read?

}

func launchTrolls() (numTrolls, dmg, dmgType string) {
damage_type := [13]string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a slice, not an array of fixed length.

Suggested change
damage_type := [13]string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison",
damage_type := []string{"bludgeoning", "piercing", "slashing", "cold", "fire", "acid", "poison",

Comment on lines +33 to +41
trolls := rand.Intn(10)
if trolls == 0 {
return string(trolls), "", ""
}

dmg = trollDamage(trolls)

return string(trolls), dmg, damage_type[rand.Intn(12)]
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding a zero case to trollDamage? Doing so would allow you to do something like

Suggested change
trolls := rand.Intn(10)
if trolls == 0 {
return string(trolls), "", ""
}
dmg = trollDamage(trolls)
return string(trolls), dmg, damage_type[rand.Intn(12)]
}
return string(trolls), trollDamage(rand.Intn[10]), damage_type[rand.Intn(12)]
}


dmg = trollDamage(trolls)

return string(trolls), dmg, damage_type[rand.Intn(12)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Treating a []string with len 1 like a string. Fix the type at initialization so you can use it properly.

Comment on lines +43 to +55
func trollDamage(trolls int) string {
i := 0
trollDmg := 0
for i < trolls {
trollDmg += rand.Intn(20)
}

if trollDmg == 0 {
return "miss"
}

return string(trollDmg)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this function a little less surprising. We expect we are dealing with integers, so let's stay dealing with integers and only cast if we need to

Suggested change
func trollDamage(trolls int) string {
i := 0
trollDmg := 0
for i < trolls {
trollDmg += rand.Intn(20)
}
if trollDmg == 0 {
return "miss"
}
return string(trollDmg)
}
func trollDamage(trolls int) int {
dmg := 0
for i, _ range trolls {
dmg += rand.Intn(20)
}
return dmg
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

troll launcher
2 participants