MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / clawMachineNounDesc

Method clawMachineNounDesc

modules/gambling/claw.go:237–289  ·  view source on GitHub ↗

clawMachineNounDesc returns the description shown when a player looks at the claw machine.

()

Source from the content-addressed store, hash-verified

235
236// clawMachineNounDesc returns the description shown when a player looks at the claw machine.
237func (g *GamblingModule) clawMachineNounDesc() string {
238
239 cost := defaultClawCost
240 if v, ok := g.plug.Config.Get(`ClawCost`).(int); ok && v > 0 {
241 cost = v
242 }
243 winChance := defaultClawWinChance
244 if v, ok := g.plug.Config.Get(`ClawWinChance`).(int); ok && v > 0 {
245 winChance = v
246 }
247
248 totalWeight := 0
249 prizes := g.buildClawPrizes()
250 for i := range prizes {
251 totalWeight += g.clawPrizeWeight(prizes[i])
252 }
253
254 type weightedPrize struct {
255 prize clawPrize
256 wt int
257 }
258 sorted := make([]weightedPrize, 0, len(prizes))
259 for i := range prizes {
260 wt := g.clawPrizeWeight(prizes[i])
261 if wt > 0 {
262 sorted = append(sorted, weightedPrize{prizes[i], wt})
263 }
264 }
265 sort.Slice(sorted, func(i, j int) bool { return sorted[i].wt > sorted[j].wt })
266
267 var sb strings.Builder
268 sb.WriteString(`<ansi fg="cyan">╔════════════════════════════════╗</ansi>` + "\n")
269 sb.WriteString(`<ansi fg="cyan">║</ansi> <ansi fg="cyan-bold">C L A W M A C H I N E</ansi> <ansi fg="cyan">║</ansi>` + "\n")
270 sb.WriteString(`<ansi fg="cyan">╚════════════════════════════════╝</ansi>` + "\n")
271 sb.WriteString("\n")
272 sb.WriteString("A tall glass cabinet filled with small prizes, lit from within by a warm glow.\n")
273 sb.WriteString("A mechanical claw hangs from a gantry inside, waiting to be guided by a brave soul.\n")
274 sb.WriteString("\n")
275 sb.WriteString(fmt.Sprintf(" Cost to play: <ansi fg=\"gold\">%d gold</ansi>\n", cost))
276 sb.WriteString(fmt.Sprintf(" Chance to win: <ansi fg=\"cyan-bold\">%d%%</ansi>\n", winChance))
277 sb.WriteString("\n")
278 sb.WriteString(`<ansi fg="cyan">Prizes</ansi> <ansi fg="8">(chance on win):</ansi>` + "\n")
279 for _, wp := range sorted {
280 pct := 0
281 if totalWeight > 0 {
282 pct = wp.wt * 100 / totalWeight
283 }
284 sb.WriteString(fmt.Sprintf(" <ansi fg=\"item\">%-16s</ansi> <ansi fg=\"cyan\">%d%%</ansi>\n", wp.prize.name, pct))
285 }
286 sb.WriteString("\n")
287 sb.WriteString(`Type <ansi fg="command">play claw machine</ansi> to try your luck.`)
288 return sb.String()
289}

Callers 1

onLookInputMethod · 0.95

Calls 4

buildClawPrizesMethod · 0.95
clawPrizeWeightMethod · 0.95
StringMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected