hearthstone-observer

0.0.3 • Public • Published

Hearthstone Observer

Watches Hearthstone log files and emits events, acting as a basic API for Hearthstone. As of right now, this only works on Windows, there is no reason it shouldn't work on OSX, I just don't have a Mac.

Getting Started

$ npm install hearthstone-observer --save

Require it and listen for events:

var ho = require('hearthstone-observer');
var observer = ho.observe();

observer.on('hs-match-result', function(data) {
    console.log('hearthstone match ended');
});

Samples

sample.js has some basic examples, to run clone the repo and run:

$ DEBUG=hs-observer-sample
$ node sample.js

On Windows

$ set DEBUG=hs-observer-sample
$ node sample.js

Events

  • hs-observer-error hearthstone-observer uses a very simple state object to track players, the state being invalid is the only error right now.
  • hs-match-start also means the state object has been (re)initialized.
  • hs-entity-created everything in a Hearthstone match is an entity and gets an id when it is created. If the entity has been revealed (played), it can be looked up, otherwise only the id and owner are known.
  • hs-player-created raised after the player's hero, hero power, and friendliness are determined.
  • hs-match-result raised when a match ends, a result can be WON, LOST, or CONCEDED. Separate events are raised for lost and conceded.
  • hs-mulligan-start raised when the mulligan stage starts, no player data is attached.
  • hs-turn-start raised when a turn starts, the player whose turn is starting is attached.
  • hs-turn-end raised when a turn ends, the player whose turn is ending is attached.
  • hs-attack raised when a minion or player attacks, always has a target.
  • hs-card-played raised when a card is played. If the card played has a target (e.g. a target-able spell or a minion with a target-able battle cry), the target will be included. Opponent secrets are the only played cards that can't be identified when played.
  • hs-minion-died raised when a minion dies.

Methods

  • observe() instantiates a HearthstoneObserver object and calls go().
  • go() starts watching the specified log files, this is called internally by observe().
  • getCard(cardId) looks up a card in cards.json by cardId.

Development

Clone the repo and run:

$ npm install
  • The regex patterns are stored in hearthstone-observer-constants.js
  • Add a pattern you want to look for in the watchFor array.
  • Add a prototype method in index.js that has the same name as your pattern pre-pended with __
  • To see debug messages run $ DEBUG=hs-observer or on Windows $ set DEBUG=hs-observer
  • To see verbose debugging messages run $ DEBUG=hs-observer-verbose or on Windows $ set DEBUG=hs-observer-verbose
  • To run tests $ npm test

Readme

Keywords

none

Package Sidebar

Install

npm i hearthstone-observer

Weekly Downloads

3

Version

0.0.3

License

ISC

Last publish

Collaborators

  • leehopkins