#ifndef _DealToPlayer_
#define _DealToPlayer_

#include "Events/LocomotionEvent.h"
#include "Behaviors/Nodes/MotionSequenceNode.h"
#include "Behaviors/Nodes/WalkNode.h"
#include "Motion/HeadPointerMC.h"
#include "Motion/WalkMC.h"
#include "Motion/MMAccessor.h"
#include "Shared/WorldState.h"
#include "Neutral.h"

#include "Motion/WalkMC.h"

#include "DualCoding/DualCoding.h"
using namespace DualCoding;

class DealToPlayer : public VisualRoutinesStateNode {
 public:
  DealToPlayer() : VisualRoutinesStateNode("WalkToTarget"),
	  walk_mc(), walk_id(MotionManager::invalid_MC_ID){}

  void DoStart() {
    VisualRoutinesStateNode::DoStart();
    cout << "DealToPlayer starting up." << endl;
	 SharedObject<MediumMotionSequenceMC> mseq_mc;
	 mseq_mc->LoadFile("neutHead.mot");
	 motman->addPrunableMotion(mseq_mc);
	 erouter->addTimer(this, 1100, 1000, false);
  }

  void processEvent(const EventBase& event) {
	  if(event.getSourceID() == 1100) {
		  walk_id = motman->addPersistentMotion(walk_mc);
		  erouter->addTimer(this, 1000, 7000, false);
		  MMAccessor<WalkMC>(walk_id)->setTargetVelocity(80, 0, 0, 12);
	  }
	  else if(event.getSourceID() == 1000){
		  SharedObject<MediumMotionSequenceMC> mseq_mc1;
		  mseq_mc1->LoadFile("dropCard.mot");
		  motman->addPrunableMotion(mseq_mc1);
		  erouter->addTimer(this, 1001, 2000, false);
	  }
	  else if(event.getSourceID() == 1001){
		  erouter->addTimer(this, 1002, 7000, false);
		  MMAccessor<WalkMC>(walk_id)->setTargetVelocity(-80, 0, 0, 17);
	  }
	   else if(event.getSourceID() == 1002){
		  erouter->addTimer(this, 1004, 10, false);
		  MMAccessor<WalkMC>(walk_id)->setTargetDisplacement(0, 0, 0, 0);
		}
		else if(event.getSourceID() == 1004){
		  motman->removeMotion(walk_id);
		  Neutral *rtn = new Neutral();
		  rtn->DoStart();
		  erouter->addTimer(this, 1005, 25000, false); 
		}
		else if(event.getSourceID() == 1005)
			postCompletionEvent();
  }
  

  void DoStop() {
    cout << "Deal to Player stopped." << endl;
    VisualRoutinesStateNode::DoStop();
  }


 private:
  SharedObject<WalkMC> walk_mc;
  MotionManager::MC_ID walk_id;

  DealToPlayer(const DealToPlayer&);
  DealToPlayer& operator=(const DealToPlayer&);
};

#endif

