1package fomo3d
2
3import (
4 "std"
5 "strconv"
6 "strings"
7
8 "gno.land/p/demo/grc/grc721"
9 "gno.land/p/demo/ufmt"
10
11 "gno.land/r/demo/users"
12)
13
14// RenderHome renders the main game state
15func RenderHome() string {
16 var builder strings.Builder
17 builder.WriteString("# FOMO3D - The Ultimate Game of Greed\n\n")
18
19 // About section
20 builder.WriteString("## About the Game\n\n")
21 builder.WriteString("FOMO3D is a game that combines elements of lottery and investment mechanics. ")
22 builder.WriteString("Players purchase keys using GNOT tokens, where each key purchase:\n\n")
23 builder.WriteString("* Extends the game timer\n")
24 builder.WriteString("* Increases the key price by 1%\n")
25 builder.WriteString("* Makes you the potential winner of the jackpot\n")
26 builder.WriteString("* Distributes dividends to all key holders\n\n")
27 builder.WriteString("## How to Win\n\n")
28 builder.WriteString("* Be the last person to buy a key before the timer expires!\n\n")
29 builder.WriteString("**Rewards Distribution:**\n")
30 builder.WriteString("* 47% goes to the jackpot (for the winner)\n")
31 builder.WriteString("* 28% distributed as dividends to all key holders\n")
32 builder.WriteString("* 20% goes to next round's starting pot\n")
33 builder.WriteString("* 5% development fee for continuous improvement\n\n")
34
35 // Play Game section
36 builder.WriteString("## How to Play\n\n")
37 builder.WriteString(ufmt.Sprintf("1. **Buy Keys** - Send GNOT to this realm with function [`BuyKeys()`](%s)\n", gameState.BuyKeysLink))
38 builder.WriteString(ufmt.Sprintf("2. **Collect Dividends** - Call [`ClaimDividends()`](%s) to collect your earnings\n", gameState.ClaimDividendsLink))
39 builder.WriteString("3. **Check Your Stats** - Append `:player/` followed by your address or namespace to the current URL to view your keys and dividends\n")
40 if gameState.Ended {
41 builder.WriteString(ufmt.Sprintf("4. **Start New Round** - Call [`StartGame()`](%s) to begin a new round\n", gameState.StartGameLink))
42 }
43 builder.WriteString("\n")
44
45 // Game Status section
46 builder.WriteString("## Game Status\n\n")
47 if gameState.StartBlock == 0 {
48 builder.WriteString("๐ด Game has not started yet.\n\n")
49 } else {
50 if gameState.Ended {
51 builder.WriteString("๐ด **Game Status:** Ended\n")
52 builder.WriteString(ufmt.Sprintf("๐ **Winner:** %s\n\n", gameState.LastBuyer))
53 } else {
54 builder.WriteString("๐ข **Game Status:** Active\n\n")
55 builder.WriteString(ufmt.Sprintf("๐ **Round:** %d\n\n", gameState.CurrentRound))
56 builder.WriteString(ufmt.Sprintf("โฑ๏ธ **Time Remaining:** %d blocks\n\n", gameState.EndBlock-std.ChainHeight()))
57 }
58 builder.WriteString(ufmt.Sprintf("๐ฐ **Jackpot:** %d ugnot\n\n", gameState.Jackpot))
59 builder.WriteString(ufmt.Sprintf("๐ **Key Price:** %d ugnot\n\n", gameState.KeyPrice))
60 builder.WriteString(ufmt.Sprintf("๐ **Total Keys:** %d\n\n", gameState.TotalKeys))
61 builder.WriteString(ufmt.Sprintf("๐ค **Last Buyer:** %s\n\n", getDisplayName(gameState.LastBuyer)))
62 builder.WriteString(ufmt.Sprintf("๐ฎ **Next Round Pot:** %d ugnot\n\n", gameState.NextPot))
63 }
64
65 // Separator before less important sections
66 builder.WriteString("---\n\n")
67
68 // Vote For Me section
69 builder.WriteString("### Vote For Us! ๐ณ๏ธ\n\n")
70 builder.WriteString("If you enjoy playing FOMO3D, please consider upvoting this game in the [Hall of Realms](https://gno.land/r/leon/hof)!\n\n")
71 builder.WriteString("Your support helps more players discover the game and grow our community! ๐\n\n")
72
73 // Report Bug section
74 builder.WriteString("### Report a Bug ๐ชฒ\n\n")
75 builder.WriteString("Something unusual happened? Help us improve the game by reporting bugs!\n")
76 builder.WriteString("[Visit our GitHub repository](https://github.com/gnolang/gno/issues)\n\n")
77 builder.WriteString("Please include:\n")
78 builder.WriteString("* Detailed description of what happened\n")
79 builder.WriteString("* Transaction hash (if applicable)\n")
80 builder.WriteString("* Your address\n")
81 builder.WriteString("* Current round number\n")
82
83 return builder.String()
84}
85
86// RenderPlayer renders specific player information
87func RenderPlayer(addr std.Address, keys int64, dividends int64) string {
88 var builder strings.Builder
89 displayName := getDisplayName(addr)
90 builder.WriteString(ufmt.Sprintf("# Player Stats: %s\n\n", displayName))
91 builder.WriteString("## Your Holdings\n\n")
92 builder.WriteString(ufmt.Sprintf("๐ **Keys Owned:** %d\n\n", keys))
93 builder.WriteString(ufmt.Sprintf("๐ฐ **Unclaimed Dividends:** %d ugnot\n\n", dividends))
94
95 // Check if player has any NFTs
96 nftBalance, err := BalanceOf(addr)
97 if err == nil && nftBalance > 0 {
98 builder.WriteString("## Your Victory NFTs ๐\n\n")
99
100 // Iterate through all rounds up to current round to find player's NFTs
101 for i := int64(1); i <= gameState.CurrentRound; i++ {
102 tokenID := grc721.TokenID(strconv.FormatInt(i, 10))
103 owner, err := OwnerOf(tokenID)
104 if err == nil && owner == addr {
105 metadata, err := TokenMetadata(tokenID)
106 if err == nil {
107 builder.WriteString(ufmt.Sprintf("### Round #%d Winner\n", i))
108 builder.WriteString(ufmt.Sprintf("\n\n", metadata.Image))
109 builder.WriteString("---\n\n")
110 }
111 }
112 }
113 }
114
115 builder.WriteString("## Actions\n\n")
116 builder.WriteString(ufmt.Sprintf("* To buy more keys, send GNOT to this realm with [`BuyKeys()`](%s)\n", gameState.BuyKeysLink))
117 if dividends > 0 {
118 builder.WriteString("* You have unclaimed dividends! Call `ClaimDividends()` to collect them\n")
119 }
120
121 return builder.String()
122}
123
124// Helper to get display name - just returns namespace if exists, otherwise address
125func getDisplayName(addr std.Address) string {
126 if user := users.GetUserByAddress(addr); user != nil {
127 return user.Name
128 }
129 return addr.String()
130}
131
132// UpdateFunctionLinks updates the links for game functions
133func UpdateFunctionLinks(buyKeysLink string, claimDividendsLink string, startGameLink string) {
134 Ownable.AssertCallerIsOwner()
135 gameState.BuyKeysLink = buyKeysLink
136 gameState.ClaimDividendsLink = claimDividendsLink
137 gameState.StartGameLink = startGameLink
138}
render.gno
5.92 Kb ยท 138 lines