<commit_before>var app = angular.module('infinityRPG', ['ngRoute', 'ngCookies']);


app.controller('GameController', function ($scope, $http, $cookies, $location) {
	var cookieToken = $cookies.get('token');
	$scope.me = $cookies.get('user');

	$scope.getHpBar = function (user) {
		var percentage = (user.hp/user.maxHp)*100 + '%';
		return percentage;
	};

	$scope.getLvl = function (user) {
		if (user) {
				return parseInt(Math.sqrt(user.exp));
		}
	};

	$scope.getBarClass = function (user) {
		if (user.hp/user.maxHp > 0.6) {
			return 'progress-bar-info';
		} else if (user.hp/user.maxHp > 0.3) {
			return 'progress-bar-warning';
		} else {
			return 'progress-bar-danger';
		}
	};

	$scope.useItem = function ( itemName ) {
		$http.get('/api/items/use/' + itemName,
			{ headers: { 'x-access-token' : cookieToken } })
			.then( function (res) {
				$scope.getPlayers();
			}, function (res) {
				console.log('Error on using item');
			});
	};

	$scope.attack = function (user) {
		var defender = {};
		defender.username = user.username;

		if (defender.username != $scope.me.username) {
			$http.post('/api/1x1', defender,
				{ headers: {'x-access-token' : cookieToken } })
				.then ( function (res) {
					if (res.data.attacker) {
						var attackerName = res.data.attacker.username;
						var defenderName = res.data.defender.username;

						$scope.me = res.data.attacker;
						$scope.players[attackerName] = res.data.attacker;
						(res.data.defender.hp < 0)
							?	delete $scope.players[defenderName]
							: $scope.players[defenderName] = res.data.defender;
					} else { //ATTACKER DIED
						console.log(res.data);

						$location.path('/');

					}

				}, function (res) {
					console.log('Error');
				});

		} else { //ATTACKING SELF
			console.log("Can't attack yourself!");
		}


	};

	$scope.upgradeStat = function (stat) {
		$http.post('/api/me/stats', { stat: stat},
			{ headers: {'x-access-token': cookieToken } })
			.then ( function (res) {
				$scope.getMe(cookieToken);
			}, function (res) {
				console.log('Error upgrading stat.');
			})
	};


	$scope.getMe = function(cookieToken) {
		$http.get('/api/me',
			{ headers: {'x-access-token' : cookieToken } })
			.then ( function (res) {<commit_msg>Waiting before sending another attack.<commit_after>var app = angular.module('infinityRPG', ['ngRoute', 'ngCookies']);


app.controller('GameController', function ($scope, $http, $cookies, $location) {
	var cookieToken = $cookies.get('token');
	$scope.me = $cookies.get('user');

	$scope.getHpBar = function (user) {
		var percentage = (user.hp/user.maxHp)*100 + '%';
		return percentage;
	};

	$scope.getLvl = function (user) {
		if (user) {
				return parseInt(Math.sqrt(user.exp));
		}
	};

	$scope.getBarClass = function (user) {
		if (user.hp/user.maxHp > 0.6) {
			return 'progress-bar-info';
		} else if (user.hp/user.maxHp > 0.3) {
			return 'progress-bar-warning';
		} else {
			return 'progress-bar-danger';
		}
	};

	$scope.useItem = function ( itemName ) {
		$http.get('/api/items/use/' + itemName,
			{ headers: { 'x-access-token' : cookieToken } })
			.then( function (res) {
				$scope.getPlayers();
			}, function (res) {
				console.log('Error on using item');
			});
	};

	$scope.attack = function (user) {
		if ($scope.attacking) {
			$scope.error = 'Wait!';
		} else {
			$scope.attacking = true;
			var defender = {};
			defender.username = user.username;

			if (defender.username != $scope.me.username) {
				$http.post('/api/1x1', defender,
					{ headers: {'x-access-token' : cookieToken } })
					.then ( function (res) {
						$scope.attacking = false;
						if (res.data.attacker) {
							var attackerName = res.data.attacker.username;
							var defenderName = res.data.defender.username;

							$scope.me = res.data.attacker;
							$scope.players[attackerName] = res.data.attacker;
							(res.data.defender.hp < 0)
								?	delete $scope.players[defenderName]
								: $scope.players[defenderName] = res.data.defender;
						} else { //ATTACKER DIED
							console.log(res.data);

							$location.path('/');

						}

					}, function (res) { //ERROR RESPONSE
						$scope.attacking = false;
						console.log('Error on attack.');
					});

			} else { //ATTACKING SELF
				console.log("Can't attack yourself!");
			}
		}
	};

	$scope.upgradeStat = function (stat) {
		$http.post('/api/me/stats', { stat: stat},
			{ headers: {'x-access-token': cookieToken } })
			.then ( function (res) {
				$scope.getMe(cookieToken);
			}, function (res) {
				console.log('Error upgrading stat.');
			})
	};


	$scope.getMe = function(cookieToken) {
		$http.get('/api/me',
			{ headers: {'x-access-token' : cookieToken } })
			.then ( function (res) {
{'fraction_non_alphanumeric': 0.18380326478694084, 'fraction_numerical': 0.00423998304006784, 'mean_word_length': 2.9481171548117153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2702398', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1660, 'n_words': 305}