'use strict';

const EventEmitter = require('events');
const MapNode = require('./map-node');
const Inventory = require('./inventory');

class Game extends EventEmitter {
  constructor(repositorySet, commandHandlers) {
    super();
    this.gameDefinition = repositorySet.gameDefinitionRepository.gameDefinition;
    this.nodeMapRepository = repositorySet.mapNodeRepository;
    this.itemRepository = repositorySet.itemRepository;
    this.commandHandlers = commandHandlers;

    this.currentNode = new MapNode({ id: -1, name: 'the real world', description: [''], location: { x: 0, y: 0, z: 0 } });
    this.inventory = new Inventory();
  }

  get currentNode() {
    return this._currentNode;
  }

  set currentNode(node) {
    this._currentNode = node;
    node.visit();
  }

  removeInventory(item, count) {
    this.inventory.remove(item, count);
    this.emit('inventory-removed', { item, count });
  }

  unequip(item) {
    this.inventory.unequip(item);
    this.emit('item-unequipped', { item });
  }

  listInventory() {
    this.emit('inventory-requested', { items: this.inventory.getAll(), equipped: this.inventory.getEquipped() });
  }

  acceptCommand(command) {
    for (const handler of this.commandHandlers) {
      if (handler.canHandle(command)) {
        handler.handle(command, this);
        return;
      }
    }

    this.emit('error', `unrecognized command "${command.name}".`);
  }
}

module.exports = Game;

@@ -802,250 +802,8 @@
 %0D%0A%0D%0A
-  removeInventory(item, count) %7B%0D%0A    this.inventory.remove(item, count);%0D%0A    this.emit('inventory-removed', %7B item, count %7D);%0D%0A  %7D%0D%0A%0D%0A  unequip(item) %7B%0D%0A    this.inventory.unequip(item);%0D%0A    this.emit('item-unequipped', %7B item %7D);%0D%0A  %7D%0D%0A%0D%0A
   li

Clean unused methods from game