0.0.3 • Published 10 years ago
hearthstone-observer v0.0.3
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 --saveRequire 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.jsOn Windows
$ set DEBUG=hs-observer-sample
$ node sample.jsEvents
hs-observer-errorhearthstone-observer uses a very simple state object to track players, the state being invalid is the only error right now.hs-match-startalso means the state object has been (re)initialized.hs-entity-createdeverything 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-createdraised after the player's hero, hero power, and friendliness are determined.hs-match-resultraised when a match ends, a result can be WON, LOST, or CONCEDED. Separate events are raised for lost and conceded.hs-mulligan-startraised when the mulligan stage starts, no player data is attached.hs-turn-startraised when a turn starts, the player whose turn is starting is attached.hs-turn-endraised when a turn ends, the player whose turn is ending is attached.hs-attackraised when a minion or player attacks, always has a target.hs-card-playedraised 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-diedraised when a minion dies.
Methods
observe()instantiates a HearthstoneObserver object and callsgo().go()starts watching the specified log files, this is called internally byobserve().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
watchForarray. - Add a prototype method in
index.jsthat has the same name as your pattern pre-pended with__ - To see debug messages run
$ DEBUG=hs-observeror on Windows$ set DEBUG=hs-observer - To see verbose debugging messages run
$ DEBUG=hs-observer-verboseor on Windows$ set DEBUG=hs-observer-verbose - To run tests
$ npm test