Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

tavernlogic source pure

Package tavernlogic holds the pure game rules of the Gnome Tavern: the menu, the level ladder, the rotating daily que...

Overview

Package tavernlogic holds the pure game rules of the Gnome Tavern: the menu, the level ladder, the rotating daily quest board and the per-gnome state machine (serving drinks, claiming quests, feasting).

It is a pure package (gno.land/p/...): it owns no chain state of its own. The Gnome Tavern realm keeps the state (a *Gnome per player) and calls into these functions, which keeps every rule unit-testable without a chain.

Constants 5

const FeastCost, FeastXP

1const (
2	FeastCost = 50
3	FeastXP   = 15
4)
source

FeastCost and FeastXP describe the Gnome Feast: a coin sink that lets a hard-working gnome convert earnings into experience, once per day.

const QuestTotalServes, QuestItemServes

1const (
2	QuestTotalServes = 0 // serve Count items of any kind today
3	QuestItemServes  = 1 // serve Count of item ItemID today
4)
source

Quest kinds: what the progress counter measures.

const DayBlocks

1const DayBlocks int64 = 2000
source

DayBlocks is the length of one tavern day, in blocks. Quest boards, daily serve counters and feast allowances all reset when the day rolls over. A short day keeps the game lively on a testnet: at Onyx's block pace a tavern day lasts roughly an hour.

const MaxServesPerDay

1const MaxServesPerDay = 40
source

MaxServesPerDay caps how many items one gnome may serve per tavern day.

const XPPerLevel

1const XPPerLevel = 40
source

XPPerLevel is the amount of XP between consecutive levels.

Functions 8

func DayAt

1func DayAt(height int64) int64
source

DayAt maps a chain height to its tavern day number.

func LevelForXP

1func LevelForXP(xp int) int
source

LevelForXP returns the level of a gnome holding xp experience points. Level 1 is the starting level; every XPPerLevel XP earns a new level.

func XPForLevel

1func XPForLevel(l int) int
source

XPForLevel returns the cumulative XP at which level l is reached.

func NewGnome

1func NewGnome(name string, day int64) *Gnome
source

NewGnome creates a fresh gnome registered under the given name.

func Menu

1func Menu() []MenuItem
source

Menu returns the full tavern menu, in serving order.

func MenuItemByID

1func MenuItemByID(id int) (MenuItem, bool)
source

MenuItemByID looks up a menu item by its ID.

func QuestPool

1func QuestPool() []Quest
source

QuestPool returns every quest that can appear on the board.

func QuestsForDay

1func QuestsForDay(day int64) [3]Quest
source

QuestsForDay deterministically picks the 3 quests on the board for a tavern day. The same day always yields the same board, on every node, with no randomness source beyond the day number itself (a small LCG).

Types 3

type Gnome

struct
 1type Gnome struct {
 2	Name  string
 3	XP    int
 4	Coins int
 5
 6	TotalServes int
 7
 8	// Daily counters; they belong to LastDay and reset on rollover.
 9	LastDay      int64
10	ServesToday  int
11	ItemToday    map[int]int
12	ClaimedToday map[int]bool // quest IDs already claimed today
13	FeastedToday bool
14}
source

Gnome is one player's tavern career. The realm owns one *Gnome per registered address; all fields are plain data so the realm can persist it directly.

Methods on Gnome

func ClaimQuest

method on Gnome
1func (g *Gnome) ClaimQuest(day int64, slot int) (Quest, error)
source

ClaimQuest pays out the quest in board slot (0-2) for the given day, if the gnome has met its requirement and has not claimed it yet today.

func Feast

method on Gnome
1func (g *Gnome) Feast(day int64) error
source

Feast lets the gnome spend FeastCost coins on a Gnome Feast, gaining FeastXP experience. Once per tavern day.

func Level

method on Gnome
1func (g *Gnome) Level() int
source

Level returns the gnome's current level.

func ProgressFor

method on Gnome
1func (g *Gnome) ProgressFor(day int64, q Quest) int
source

ProgressFor reports the gnome's progress toward a quest today.

func Serve

method on Gnome
1func (g *Gnome) Serve(day int64, itemID int) (coinsEarned, xpEarned int, err error)
source

Serve records the gnome serving one menu item on the given day and returns what was earned. It enforces the menu's level requirement and the daily serve cap.

type MenuItem

struct
1type MenuItem struct {
2	ID       int
3	Name     string
4	Detail   string
5	MinLevel int
6	Coins    int
7	XP       int
8}
source

MenuItem is one serveable entry on the tavern menu. Serving it pays the gnome Coins tavern coins and XP experience, and requires MinLevel.

type Quest

struct
 1type Quest struct {
 2	ID         int
 3	Title      string
 4	Desc       string
 5	Kind       int
 6	ItemID     int // only for QuestItemServes
 7	Count      int
 8	CoinReward int
 9	XPReward   int
10}
source

Quest is one entry on the daily quest board.

Dependencies

Imports 1

/p/g17dvvky49vjqj6a4cjhwcvzctteqjm9stee000h/tavernlogic

Imported by indexer

Source Files 3