<commit_before>// Entity mixins


Game.Mixins = {};

//Movement

//Entity can move to unblocked squares
//Takes argument in absolute coordinates to current position
Game.Mixins.AbsMoveable = {
	name : 'AbsMoveable',
	groupName : 'Moveable',
	tryMove: function(x,y,map) {
		var tile = map.getTile(x,y);
		if (tile.isWalkable() && !this._map.getEntityAt(x,y)) {
			this._x = x;
			this._y = y;

			if (this._playercontrolled) {
				this._map.getEngine().unlock();
			}

			return true;
		}
		else { return false;}
	}
}

//Has balance statistic that governs whether various actions can be used
Game.Mixins.Balanced = {
	name : 'Balanced',
	groupName : 'Balanced',
	init : function(properties) {
		this._mbal = properties['mbal'] || 5; //Max balance
		this._cbal = properties['cbal'] || 5; //Current balance
	},
	getBalance : function() {
		return this._cbal;
	},
	setBalance : function(balance) {
		this._cbal = balance;
	},
	reduceBalance : function(reduction) {
		this._cbal = Math.max(0,this._cbal-reduction);
		if (this._cbal == 1) {
			Game.sendMessage(this, "Your intricate dance is getting your legs into quite a tangle");
		}
		if (this._cbal == 0) {
			Game.sendMessage(this, "You fall over");
		}
	},
	increaseBalance : function(increase) {
		this._cbal = Math.min(this._mbal,this._cbal+increase);
	}
}


//Coordinates are relative to current position and direction
//'Fpsmove' direction is relative to current directin
//'RogueMove' direction is absolute
Game.Mixins.DirectionMoveable = {
	name : 'DirectionMoveable',
	groupName : 'Moveable',
	init : function(properties) {
		var x = properties['x_dir'] || 1;
		var y = properties['y_dir'] || -1;

		this._direction = v2d(x,-y);
		this._olddirection = this._direction;
		this._chararray = properties['chararray'] || Game.Chars.SingleArrows;
		this._char = this._chararray[this._direction];
	},
	getChar : function() {
		return this._chararray[this._direction];
	},
	turn : function(x,y) {
		if (this.getBalance()) {
			this._direction = v2d(x,-y);
			return 1;
		} else {
			return 0;
		}
	},

	fpsMove : function(dx,dy,map) {

		if (dx == 0 && dy == 0) {
			this.increaseBalance(2);
			this._olddirection = this._direction;
			return true;
		}

		var movedir = v2d(dx,dy);
		var absdir = mod(this._direction-movedir,8);
		var movevec = d2v(absdir);
		var x = movevec[0]+this.getX();
		var y = movevec[1]+this.getY();
		var tile = map.getTile(x,y);
		var target = this._map.getEntityAt(x,y);

		if (tile.isWalkable() && (!target || target == this)) {

			this._olddirection = this._direction;

			if (!this.getBalance()) {
				Game.sendMessage(this,'You stand on shaking legs, steadying yourself to step once more.');
				this.setBalance(2);
				return true;
			} else {
				var bal_loss = Math.min(1,movedir);
				this.reduceBalance(bal_loss);
				this._x = x;
				this._y = y;
			}
			
		} else {
			return false;
		}
	},


	kbMove: function(dx,dy,noturn,map) {
		var x = this.getX() + dx;
		var y = this.getY() + dy;
		var tile = map.getTile(x,y);
		var target = this._map.getEntityAt(x,y);
		
		if (tile.isWalkable() && (!target || target == this)) {
			
			if (!this.getBalance()) {
				Game.sendMessage(this,'You stand on shaking legs, steadying yourself to step once more.');
				this.setBalance(2);
				return true;
			} else {

				this._x = x;
				this._y = y;
				if (!noturn) {
					this.turn(dx,dy);
				} else {
					var movedir = v2d(dx,dy);
					var absdir = mod(this._direction-movedir,8);
					var bal_loss = Math.min(1,absdir);
					this.reduceBalance(bal_loss);
			}
				return true;
			}
		} else { return false;}
	}
}


//Actor

//Player version of the Actor mixin
Game.Mixins.PlayerActor = {
	name : 'PlayerActor',
	groupName : 'Actor',
	act : function() {
		Game.refresh();
		this.getMap().getEngine().lock();
		console.log("Player moving");<commit_msg>regain balance on forward move<commit_after>// Entity mixins


Game.Mixins = {};

//Movement

//Entity can move to unblocked squares
//Takes argument in absolute coordinates to current position
Game.Mixins.AbsMoveable = {
	name : 'AbsMoveable',
	groupName : 'Moveable',
	tryMove: function(x,y,map) {
		var tile = map.getTile(x,y);
		if (tile.isWalkable() && !this._map.getEntityAt(x,y)) {
			this._x = x;
			this._y = y;

			if (this._playercontrolled) {
				this._map.getEngine().unlock();
			}

			return true;
		}
		else { return false;}
	}
}

//Has balance statistic that governs whether various actions can be used
Game.Mixins.Balanced = {
	name : 'Balanced',
	groupName : 'Balanced',
	init : function(properties) {
		this._mbal = properties['mbal'] || 5; //Max balance
		this._cbal = properties['cbal'] || 5; //Current balance
	},
	getBalance : function() {
		return this._cbal;
	},
	setBalance : function(balance) {
		this._cbal = balance;
	},
	reduceBalance : function(reduction) {
		var bal = Math.max(0,this._cbal-reduction);
		this._cbal = Math.min(this._mbal, bal);
		if (this._cbal == 1) {
			Game.sendMessage(this, "Your intricate dance is getting your legs into quite a tangle");
		}
		if (this._cbal == 0) {
			Game.sendMessage(this, "You fall over");
		}
	},
	increaseBalance : function(increase) {
		var bal = Math.min(this._mbal,this._cbal+increase);
		this._cbal = Math.max(bal,0);
	}
}


//Coordinates are relative to current position and direction
//'Fpsmove' direction is relative to current directin
//'RogueMove' direction is absolute
Game.Mixins.DirectionMoveable = {
	name : 'DirectionMoveable',
	groupName : 'Moveable',
	init : function(properties) {
		var x = properties['x_dir'] || 1;
		var y = properties['y_dir'] || -1;

		this._direction = v2d(x,-y);
		this._olddirection = this._direction;
		this._chararray = properties['chararray'] || Game.Chars.SingleArrows;
		this._char = this._chararray[this._direction];
	},
	getChar : function() {
		return this._chararray[this._direction];
	},
	turn : function(x,y) {
		if (this.getBalance()) {
			this._direction = v2d(x,-y);
			return 1;
		} else {
			return 0;
		}
	},

	fpsMove : function(dx,dy,map) {

		if (dx == 0 && dy == 0) {
			this.increaseBalance(2);
			this._olddirection = this._direction;
			return true;
		}

		var movedir = v2d(dx,dy);
		var absdir = mod(this._direction-movedir,8);
		var movevec = d2v(absdir);
		var x = movevec[0]+this.getX();
		var y = movevec[1]+this.getY();
		var tile = map.getTile(x,y);
		var target = this._map.getEntityAt(x,y);

		if (tile.isWalkable() && (!target || target == this)) {

			this._olddirection = this._direction;

			if (!this.getBalance()) {
				Game.sendMessage(this,'You stand on shaking legs, steadying yourself to step once more.');
				this.setBalance(2);
				return true;
			} else {
				var bal_loss = Math.min(1,movedir-1);
				this.reduceBalance(bal_loss);
				this._x = x;
				this._y = y;
			}
			
		} else {
			return false;
		}
	},


	kbMove: function(dx,dy,noturn,map) {
		var x = this.getX() + dx;
		var y = this.getY() + dy;
		var tile = map.getTile(x,y);
		var target = this._map.getEntityAt(x,y);
		
		if (tile.isWalkable() && (!target || target == this)) {
			
			if (!this.getBalance()) {
				Game.sendMessage(this,'You stand on shaking legs, steadying yourself to step once more.');
				this.setBalance(2);
				return true;
			} else {

				this._x = x;
				this._y = y;
				if (!noturn) {
					this.turn(dx,dy);
				} else {
					var movedir = v2d(dx,dy);
					var absdir = mod(this._direction-movedir,8);
					var bal_loss = Math.min(1,absdir-1);
					this.reduceBalance(bal_loss);
			}
				return true;
			}
		} else { return false;}
	}
}


//Actor

//Player version of the Actor mixin
Game.Mixins.PlayerActor = {
	name : 'PlayerActor',
	groupName : 'Actor',
	act : function() {
		Game.refresh();
		this.getMap().getEngine().lock();
		console.log("Player moving");
{'fraction_non_alphanumeric': 0.15685010955019976, 'fraction_numerical': 0.006830777162005413, 'mean_word_length': 3.3327749860413176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2166055', 'n_tokens_mistral': 3161, 'n_tokens_neox': 2780, 'n_words': 640}