// 控制人物的kbe 类

var KBEngine = require("kbengine");

/*-----------------------------------------------------------------------------------------
												entity
-----------------------------------------------------------------------------------------*/
KBEngine.Avatar = KBEngine.Entity.extend(
	{
		__init__: function () {
			this._super();
			console.log('Avatar init == ');
			
		},

		// 起跳函数
		jump: function () {
			console.log('jump');
			this.cellCall("jump");
		},
		//action 执行完后通知服务器
		actionEnd:function(){
			console.log('通知服务器 actionEnd');

			this.cellCall("actionEnd");
		},
		// 修改对象速度状态
		changeSpeed :function(speed){
			KBEngine.INFO_MSG('通知服务器，速度: ' + speed);
			this.cellCall("changeSpeed",speed/CONVERSION_SPEED_UNIT);
		},

		onJump: function () {
			KBEngine.INFO_MSG(this.className + '::onJump: ' + this.id);
			KBEngine.Event.fire("otherAvatarOnJump", this);
		},

		onEnterWorld: function () {
			KBEngine.INFO_MSG(this.className + '::onEnterWorld: ' + this.id);
			if (this.isPlayer()) {
				KBEngine.Event.fire("onAvatarEnterWorld", KBEngine.app.entity_uuid, this.id, this);
			}

			this._super();
		},

		onReady: function(eid, second)
	    {
            KBEngine.INFO_MSG("avatar " + eid + " onReady：second="+second);
		    KBEngine.Event.fire("onReady", eid, second);
		}, 
		onNewTurn : function(eid, second, startSpeed,position)
	    {
            KBEngine.INFO_MSG("avatar " + eid + " on new turn：second="+second+" ,startSpeed="+startSpeed);
		    KBEngine.Event.fire("onNewTurn", eid, second,startSpeed*CONVERSION_SPEED_UNIT,position);
		}, 

		setAvatarSpeed: function(eid, Speed)
	    {
            KBEngine.INFO_MSG("avatar " + eid +" ,Speed="+Speed);
		    KBEngine.Event.fire("onSetAvatarSpeed", eid, Speed*CONVERSION_SPEED_UNIT);
		}, 
		//玩家移动
		setAvatarMove: function(isMoveing, pos)
	    {
		    KBEngine.Event.fire("onSetAvatarMove", isMoveing, pos);
		}, 

		//玩家状态
		setAvatarState:function(eid,avatarType)
		{
			KBEngine.Event.fire("onSetAvatarState",eid, avatarType);
		},

		onGameOver:function(win,score){
			KBEngine.INFO_MSG("onGameOver= " + win + " , score="+score);
			KBEngine.Event.fire("onGameOver", win,score);
		},
		onServerMoveOver: function()
	    {
			console.log('onServerMoveOver');
		    KBEngine.Event.fire("onServerMoveOver",this);
		}, 

		//寻找房间
		//匹配对应的房间
		joinRoom:function(){
			console.log('发送请求加入房间');
			this.baseCall("joinRoom");
		},
		onAvatarMatchingSuccess:function(id1,name1,id2,name2){
			KBEngine.Event.fire("onAvatarMatchingSuccess",id1,name1,id2,name2)
		},

		//进入游戏场景
		enterGame:function(){
			console.log('发送请求通知服务器已进入游戏场景');
			this.baseCall("enterGame");
		},

		levelRoom:function(){
			console.log('发送请求离开房间');
			this.baseCall("levelRoom");
		}
	
	});


