<commit_before>/*
* All non-combat commands that one would consider 'general' to a all
* users (like get, look, and movement). Anything combat (even potentially) related is in skills.js
* the actual combat loop is in combat.js.
* 
* Events fired on particular commands are also triggered here; for example onEnter, onLeave
*/
'use strict';
var fs = require('fs'),
util = require('util'),
World = require('../world'),
players = World.players,
time = World.time,
areas = World.areas,

Cmd = function () {};

/*
	// cast detect hidden rok
	command object = {
		cmd: 'cast', 
		msg: 'detect hidden rok',
		arg: 'detect hidden',
		input: 'rok',
		last: 'rok',
		second: 'detect',
		number: 1
	};
*/
Cmd.prototype.createCommandObject = function(resFromClient) {
	var cmdArr = resFromClient.msg.split(' '),
	cmdObj = {};

	if (cmdArr.length === 1) {
		cmdArr[1] = '';
	}

	if (/[`~@#$%^&*()-+={}[]|<>]+$/g.test(resFromClient.msg) === false) {
		cmdObj.cmd = cmdArr[0];
		cmdObj.msg = cmdArr.slice(1).join(' ');
		cmdObj.last = cmdArr[cmdArr.length - 1].toLowerCase();
		cmdObj.number = 1;

		if (cmdArr.length < 4) {
			if (cmdArr.length === 3) {
				cmdObj.arg = cmdArr[1].toLowerCase();
				cmdObj.input = cmdArr[2].toLowerCase();
			} else if (cmdArr.length === 2) {
				cmdObj.arg = cmdArr[1].toLowerCase();
				cmdObj.input = cmdObj.msg;
			}
		} else {
			cmdObj.arg = cmdArr[1].toLowerCase() + ' ' + cmdArr[2].toLowerCase(),
			cmdObj.input = cmdArr.slice(3).join(' ')
		}

		if (cmdObj.input && !isNaN(parseInt(cmdObj.input[0]))
			|| (!cmdObj.input && !isNaN(parseInt(cmdObj.msg[0]))) ) {

			cmdObj.arg = cmdObj.arg.replace(/.*[.]/g, '');
			cmdObj.number = parseInt(cmdObj.last[0]);

			if (!cmdObj.input) {
				cmdObj.msg = cmdObj.msg.replace(/^[0-9][.]/, '');
			} else {
				cmdObj.input = cmdObj.input.replace(/^[0-9][.]/, '');
			}
		}

		if (cmdObj.arg.indexOf(' ') !== -1) {
			cmdObj.second = cmdObj.arg.split(' ')[0];
		} else {
			cmdObj.second = cmdObj.arg;
		}
	}

	return cmdObj;
};

Cmd.prototype.whizinvis = function(target, command) {
	World.addAffect(target, {
		id: 'whizinvis',
		affect: 'invis',
		display: 'Admin Invisiblity',
		caster: target.refId,
		modifiers: null,
		decay: -1
	});
};

Cmd.prototype.buy = function(target, command) {
	var i = 0,
	roomObj,
	item,
	canBuy = true,
	merchant;

	if (command.roomObj) {
		roomObj = command.roomObj;
	} else {
		roomObj = World.getRoomObject(target.area, target.roomid);
	}

	if (target.position === 'standing' || target.position === 'resting') {
		merchant = World.room.getMerchants(roomObj)[0];

		if (merchant) {
			canSell = World.processEvents('beforeSell', merchant, roomObj, target);

			if (canSell) {
				item =  World.character.getItem(merchant, command);

				if (item) {
					if (item.value <= target.gold) {
						target.gold -= item.value;
						merchant.gold += item.value;

						World.character.removeItem(merchant, item);

						World.character.addItem(target, item);
					
						World.msgPlayer(target, {<commit_msg>update buy command to propert intialize merchant<commit_after>/*
* All non-combat commands that one would consider 'general' to a all
* users (like get, look, and movement). Anything combat (even potentially) related is in skills.js
* the actual combat loop is in combat.js.
* 
* Events fired on particular commands are also triggered here; for example onEnter, onLeave
*/
'use strict';
var fs = require('fs'),
util = require('util'),
World = require('../world'),
players = World.players,
time = World.time,
areas = World.areas,

Cmd = function () {};

/*
	// cast detect hidden rok
	command object = {
		cmd: 'cast', 
		msg: 'detect hidden rok',
		arg: 'detect hidden',
		input: 'rok',
		last: 'rok',
		second: 'detect',
		number: 1
	};
*/
Cmd.prototype.createCommandObject = function(resFromClient) {
	var cmdArr = resFromClient.msg.split(' '),
	cmdObj = {};

	if (cmdArr.length === 1) {
		cmdArr[1] = '';
	}

	if (/[`~@#$%^&*()-+={}[]|<>]+$/g.test(resFromClient.msg) === false) {
		cmdObj.cmd = cmdArr[0];
		cmdObj.msg = cmdArr.slice(1).join(' ');
		cmdObj.last = cmdArr[cmdArr.length - 1].toLowerCase();
		cmdObj.number = 1;

		if (cmdArr.length < 4) {
			if (cmdArr.length === 3) {
				cmdObj.arg = cmdArr[1].toLowerCase();
				cmdObj.input = cmdArr[2].toLowerCase();
			} else if (cmdArr.length === 2) {
				cmdObj.arg = cmdArr[1].toLowerCase();
				cmdObj.input = cmdObj.msg;
			}
		} else {
			cmdObj.arg = cmdArr[1].toLowerCase() + ' ' + cmdArr[2].toLowerCase(),
			cmdObj.input = cmdArr.slice(3).join(' ')
		}

		if (cmdObj.input && !isNaN(parseInt(cmdObj.input[0]))
			|| (!cmdObj.input && !isNaN(parseInt(cmdObj.msg[0]))) ) {

			cmdObj.arg = cmdObj.arg.replace(/.*[.]/g, '');
			cmdObj.number = parseInt(cmdObj.last[0]);

			if (!cmdObj.input) {
				cmdObj.msg = cmdObj.msg.replace(/^[0-9][.]/, '');
			} else {
				cmdObj.input = cmdObj.input.replace(/^[0-9][.]/, '');
			}
		}

		if (cmdObj.arg.indexOf(' ') !== -1) {
			cmdObj.second = cmdObj.arg.split(' ')[0];
		} else {
			cmdObj.second = cmdObj.arg;
		}
	}

	return cmdObj;
};

Cmd.prototype.whizinvis = function(target, command) {
	World.addAffect(target, {
		id: 'whizinvis',
		affect: 'invis',
		display: 'Admin Invisiblity',
		caster: target.refId,
		modifiers: null,
		decay: -1
	});
};

Cmd.prototype.buy = function(target, command) {
	var i = 0,
	roomObj,
	item,
	canBuy = true,
	canSell = false,
	merchant;

	if (command.roomObj) {
		roomObj = command.roomObj;
	} else {
		roomObj = World.getRoomObject(target.area, target.roomid);
	}

	if (target.position === 'standing' || target.position === 'resting') {
		merchant = World.room.getMerchants(roomObj)[0];

		if (merchant) {
			canSell = World.processEvents('beforeSell', merchant, roomObj, target);

			if (canSell) {
				item =  World.character.getItem(merchant, command);

				if (item) {
					if (item.value <= target.gold) {
						target.gold -= item.value;
						merchant.gold += item.value;

						World.character.removeItem(merchant, item);

						World.character.addItem(target, item);
					
						World.msgPlayer(target, {
{'fraction_non_alphanumeric': 0.1867896557404052, 'fraction_numerical': 0.009224180530390381, 'mean_word_length': 3.384115523465704, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '2939733', 'n_tokens_mistral': 2503, 'n_tokens_neox': 2244, 'n_words': 464}