npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tcg-game/sdk

v0.0.18

Published

## Data types

Downloads

5

Readme

TCG Game Frontend

Data types

GameInfo: 和之前的 BoardInfo 一样,包含了所有的数据

Init SDK


/** tokenIds 是 card config 的 id 集合,比如 card config 是
[
    {id: 1001, name: xxx, type: xxx },
    {id: 1002, name: xxx, type: xxx },
    {id: 1003, name: xxx, type: xxx },
]
这里就传入 [1001, 1002, 1003] 
**/
const sdk = new TCGSDK({
    signer, provider,
    tokenIds,
});

// 初始化
await sdk.init();

SDK interfaces


// 和之前一样的接口

await sdk.getGameInstance(gameId: number);

await sdk.getL1GasPrice();

await sdk.getAccountInfo(address: string);


// heroType: 选择的英雄种类
// 和之前一样会返回 stateMachine
await sdk.createGame(heroType);

Game instance interfaces

获取game instance

const game = await sdk.getGameInstance(gameId);

// 监听接口,和之前 onBoardUpdate 一样
game.onGameInfoUpdate((newGameInfo: GameInfo) => {
    ....
})

// 加入游戏
await game.joinGame(buyinAmount: number, heroType: HeroType);

// 加入游戏后,需要双方调用 prepare 得到起手牌,底层是双方都 deal 对方的起手牌
await game.prepare();

// 第一次 shuffle,双方轮流做
await game.firstShuffleDeck();

// 第一次 shuffle,双方轮流做
await game.secondShuffleDeck();

// 本round结束,轮到对手出牌
await game.nextRound();

// 帮对手发牌,只有在法术牌某些效果生效的时候才会直接调用
await game.drawCard();

// 对手超时后踢掉对方
await game.kickPlayer();

// 投降
await game.surrender();

// 使用英雄效果
await game.useHeroEffects();

// 使用英雄攻击,targetIdx 为 99 的时候攻击对方英雄
// targetIdx 为其他值的时候攻击对方 随从, 可以从
// gameInfo 中拿到对方 随从 然后挑选
await game.useHeroAttack(targetIdx: number);

// 使用随从攻击,minionIdx 为挑选的随从,targetIdx 规则同上
await game.useMinionAttack(
    minionIdx: number,
    targetIdx: number,
);

// 和之前一样
await game.playerIndex();

Game flow

初始化

和 holdem 一样,初始化sdk,下载资源,setup account, ...

游戏流程

  • 房主(creator) sdk.createGame
  • 对手(joiner) sdk.joinGame,加入后游戏自动开始
  • creator 和 joiner 轮流调用 sdk.prepare
  • creator 和 joiner 轮流调用 sdk.firstShuffleDeck
  • creator 和 joiner 轮流调用 sdk.secondShuffleDeck
  • 进入 play 阶段,creator 调用 game.nextRound, 轮到 joiner 出牌
    • joiner 调用 game.playCard(cardIndex), cardIndex 就是 handCards
    • joiner 可以多次调用 playCard, useHeroAttack, usexxx 等,直到 currentMana 用完
    • joiner 点击 game.nextRound,切换到 creator
    • creator 重复上面步骤
    • ...