rpg

package
v0.0.0-...-b2e696f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const BannerID = "fajar-v1"
View Source
const RulesVersion = "arunika-v3"

Variables

This section is empty.

Functions

func NewHTTPHandler

func NewHTTPHandler(s *Service, c HTTPConfig) (http.Handler, error)

func SetDefault

func SetDefault(s *Service)

func ShutdownHTTP

func ShutdownHTTP(server *http.Server)

func StartHTTP

func StartHTTP(s *Service, c HTTPConfig) (*http.Server, error)

StartHTTP binds synchronously, so an invalid port fails before WhatsApp login.

Types

type Ability

type Ability struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

type Action

type Action struct {
	RequestID string `json:"request_id"`
	Revision  int64  `json:"expected_revision"`
	Actor     int    `json:"actor"`
	Action    string `json:"action"`
	Target    int    `json:"target"`
}

type Art

type Art struct {
	SpritePrompt   string `json:"sprite_prompt"`
	PortraitPrompt string `json:"portrait_prompt,omitempty"`
}

type Battle

type Battle struct {
	ID               string     `json:"id"`
	Revision         int64      `json:"revision"`
	Rules            string     `json:"rules"`
	Stage            int        `json:"stage"`
	Round            int        `json:"round"`
	Active           int        `json:"active"`
	Target           int        `json:"target"`
	Phase            string     `json:"phase"`
	Done             bool       `json:"done"`
	Result           string     `json:"result"`
	FirstClear       bool       `json:"first_clear"`
	RewardShards     int        `json:"reward_shards"`
	RewardCoins      int        `json:"reward_coins"`
	RewardXP         int        `json:"reward_xp"`
	RewardTrainingXP int        `json:"reward_training_xp"`
	Heroes           []Hero     `json:"heroes"`
	Enemies          []Opponent `json:"enemies"`
	Logs             []string   `json:"logs"`
}

type Catalog

type Catalog struct {
	Version     string           `json:"version"`
	Characters  []Character      `json:"characters"`
	Enemies     []Enemy          `json:"enemies"`
	Regions     []Region         `json:"regions"`
	Stages      []Stage          `json:"stages"`
	Featured    string           `json:"featured"`
	Equipment   []Equipment      `json:"equipment"`
	Progression ProgressionRules `json:"progression"`
}

type Character

type Character struct {
	ID          string  `json:"id"`
	Name        string  `json:"name"`
	Rarity      int     `json:"rarity"`
	Role        string  `json:"role"`
	Element     string  `json:"element"`
	RegionID    string  `json:"region_id"`
	Visual      string  `json:"visual"`
	Personality string  `json:"personality"`
	Skill       Ability `json:"skill"`
	Passive     Ability `json:"passive"`
	Art         Art     `json:"art"`
}

type Enemy

type Enemy struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	RegionID  string `json:"region_id"`
	Element   string `json:"element"`
	Archetype string `json:"archetype"`
	MinLevel  int    `json:"min_level"`
	MaxLevel  int    `json:"max_level"`
	Visual    string `json:"visual"`
	Ability   string `json:"ability"`
	Art       Art    `json:"art"`
}

type Equipment

type Equipment struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Slot    string `json:"slot"`
	Price   int    `json:"price"`
	Unlock  int    `json:"unlock"`
	HP      int    `json:"hp"`
	Attack  int    `json:"attack"`
	Defense int    `json:"defense"`
}

type Error

type Error struct {
	Status  int
	Code    string
	Message string
}

func (*Error) Error

func (e *Error) Error() string

type Growth

type Growth struct {
	Level int `json:"level"`
	XP    int `json:"xp"`
}

type HTTPConfig

type HTTPConfig struct {
	PublicURL     string
	GatewaySecret string
	ListenAddr    string
}

func (HTTPConfig) Validate

func (c HTTPConfig) Validate() error

type HTTPHandler

type HTTPHandler struct {
	// contains filtered or unexported fields
}

func (*HTTPHandler) ServeHTTP

func (h *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Hero

type Hero struct {
	Awakening        int     `json:"awakening"`
	CurrentAction    string  `json:"-"`
	ShieldBreakRound int     `json:"shield_break_round,omitempty"`
	PassiveUsed      bool    `json:"passive_used,omitempty"`
	PassiveRound     int     `json:"passive_round,omitempty"`
	PassiveBoost     float64 `json:"passive_boost,omitempty"`
	SkillBoost       bool    `json:"skill_boost,omitempty"`
	ShieldSource     string  `json:"shield_source,omitempty"`
	Character
	HP      int  `json:"hp"`
	Max     int  `json:"max"`
	Attack  int  `json:"attack"`
	Defense int  `json:"defense"`
	Energy  int  `json:"energy"`
	Acted   bool `json:"acted"`
	Guard   bool `json:"guard"`
	Level   int  `json:"level"`
	Shield  int  `json:"shield"`
	Taunt   bool `json:"taunt"`
	Regen   int  `json:"regen"`
	Reflect bool `json:"reflect"`
	Evade   bool `json:"evade"`
	Empower bool `json:"empower"`
}

type HistoryEntry

type HistoryEntry struct {
	RequestID string `json:"request_id"`
	CreatedAt int64  `json:"created_at"`
	Results   []Pull `json:"results"`
}

type Opponent

type Opponent struct {
	MarkBonus   int    `json:"mark_bonus,omitempty"`
	BlindChance int    `json:"blind_chance,omitempty"`
	BurnExpose  bool   `json:"burn_expose,omitempty"`
	BurnSource  string `json:"burn_source,omitempty"`
	Enemy
	HP        int    `json:"hp"`
	Max       int    `json:"max"`
	Attack    int    `json:"attack"`
	Defense   int    `json:"defense"`
	Kind      string `json:"kind"`
	Charged   bool   `json:"charged"`
	Burn      int    `json:"burn"`
	BurnPower int    `json:"burn_power"`
	Weaken    int    `json:"weaken"`
	Expose    int    `json:"expose"`
	Slow      int    `json:"slow"`
	Blind     int    `json:"blind"`
	Mark      bool   `json:"mark"`
	Shield    int    `json:"shield"`
}

type PartyRequest

type PartyRequest struct {
	RequestID string   `json:"request_id"`
	Revision  int64    `json:"expected_revision"`
	Party     []string `json:"party"`
}

type Profile

type Profile struct {
	ID           string                       `json:"id"`
	Name         string                       `json:"name"`
	Revision     int64                        `json:"revision"`
	Version      int                          `json:"version"`
	Shards       int                          `json:"shards"`
	Coins        int                          `json:"coins"`
	Dust         int                          `json:"dust"`
	Pity5        int                          `json:"pity5"`
	Pity4        int                          `json:"pity4"`
	Guarantee    bool                         `json:"guarantee"`
	Unlocked     int                          `json:"unlocked"`
	Cleared      []int                        `json:"cleared"`
	Party        []string                     `json:"party"`
	Collection   map[string]int               `json:"collection"`
	Awakening    map[string]int               `json:"awakening"`
	Enhancements map[string]int               `json:"enhancements"`
	LastBattle   string                       `json:"last_battle"`
	Growth       map[string]Growth            `json:"growth"`
	TrainingXP   int                          `json:"training_xp"`
	LevelCap     int                          `json:"level_cap"`
	Inventory    map[string]int               `json:"inventory"`
	Loadouts     map[string]map[string]string `json:"loadouts"`
}

type ProgressRequest

type ProgressRequest struct {
	RequestID   string `json:"request_id"`
	Revision    int64  `json:"expected_revision"`
	CharacterID string `json:"character_id"`
	Levels      int    `json:"levels,omitempty"`
	ItemID      string `json:"item_id,omitempty"`
	Slot        string `json:"slot,omitempty"`
}

type ProgressionRules

type ProgressionRules struct {
	AwakeningMax       int `json:"awakening_max"`
	AwakeningCoins     int `json:"awakening_coins"`
	AwakeningDust      int `json:"awakening_dust"`
	AwakeningPercent   int `json:"awakening_percent"`
	EnhancementMax     int `json:"enhancement_max"`
	EnhancementDust    int `json:"enhancement_dust"`
	EnhancementPercent int `json:"enhancement_percent"`
}

Costs are sent in the catalog so clients display the same deterministic rules.

type Pull

type Pull struct {
	Character Character `json:"character"`
	Duplicate bool      `json:"duplicate"`
}

type Region

type Region struct {
	ID       string   `json:"id"`
	Name     string   `json:"name"`
	MinLevel int      `json:"min_level"`
	MaxLevel int      `json:"max_level"`
	Palette  []string `json:"palette"`
	Lore     string   `json:"lore"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func Default

func Default() *Service

func New

func New(ctx context.Context, db *sqlx.DB) (*Service, error)

func (*Service) Act

func (s *Service) Act(ctx context.Context, player, battleID string, a Action) (Snapshot, error)

func (*Service) Catalog

func (s *Service) Catalog() Catalog

func (*Service) EnsurePlayer

func (s *Service) EnsurePlayer(ctx context.Context, aliases []string, name string) (Profile, error)

EnsurePlayer is reachable only from the WhatsApp handler, never from HTTP. Trusted PN/LID aliases map to one internal ID so a different addressing mode does not create a second wallet. Conflicting existing accounts are not merged silently.

func (*Service) ExchangeTicket

func (s *Service) ExchangeTicket(ctx context.Context, ticket string) (string, error)

func (*Service) History

func (s *Service) History(ctx context.Context, player string) ([]HistoryEntry, error)

func (*Service) IssueTicket

func (s *Service) IssueTicket(ctx context.Context, player string) (string, error)

IssueTicket invalidates older, unused links for this player. Raw tickets and session tokens never enter the database or application logs.

func (*Service) Logout

func (s *Service) Logout(ctx context.Context, session string) error

func (*Service) Progress

func (s *Service) Progress(ctx context.Context, player, operation string, a ProgressRequest) (Snapshot, error)

func (*Service) Retreat

func (s *Service) Retreat(ctx context.Context, player, battleID, request string, revision int64) (Snapshot, error)

func (*Service) SessionPlayer

func (s *Service) SessionPlayer(ctx context.Context, session string) (string, error)

func (*Service) SetParty

func (s *Service) SetParty(ctx context.Context, player string, a PartyRequest) (Snapshot, error)

func (*Service) Snapshot

func (s *Service) Snapshot(ctx context.Context, id string) (Snapshot, error)

func (*Service) StartBattle

func (s *Service) StartBattle(ctx context.Context, player, request string, stage int) (Snapshot, error)

func (*Service) Summon

func (s *Service) Summon(ctx context.Context, player, request, banner string, count int) (Snapshot, error)

type Snapshot

type Snapshot struct {
	Profile Profile `json:"profile"`
	Battle  *Battle `json:"battle"`
	Results []Pull  `json:"results,omitempty"`
}

type Stage

type Stage struct {
	Name   string `json:"name"`
	Level  int    `json:"level"`
	Region int    `json:"region"`
	Icon   string `json:"icon"`
	Label  string `json:"label"`
	Boss   bool   `json:"boss"`
	Elite  bool   `json:"elite"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址