You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

302 lines
12 KiB
HTML

<!--
TerranQuest - Augmented Reality fantasy game
Copyright 2016 Netsyms Technologies
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<div class="scrollable-box">
<div class="h4" id="place-name"></div>
<div id="place-info-div">
<span id="place-refresh" class="fa fa-refresh fa-fw" onclick="resync()"></span>
Type: <span id="team-label"></span><br />
Owner: <span id="owner-label"></span><br />
<!-- Life: <span id="life-label"></span><br /> -->
Place life: <div class="progress" id="place-health-place"><div id="place-health-place-bar" class="progress-bar" role="progressbar" ></div></div>
<div class="row">
<div class="col-xs-6">
<div class="btn btn-success btn-wide" id="capturebtn" onclick="attempttake()"></div>
</div>
<div class="col-xs-6">
<div class="btn btn-success btn-wide" id="refillbtn" onclick="attemptrefill()"></div>
</div>
</div>
<br />
My life: <div class="progress" id="user-health-place"><div id="user-health-place-bar" class="progress-bar" role="progressbar" ></div></div>
</div>
<div class="well well-sm place-log" id="place-log">
</div>
</div>
<script>
var thisplace = null;
var placeteam = 0;
var capturebtndisabled = false;
var refillbtndisabled = false;
// Enforced time between actions, in ms
var actioninterval = 1000;
function resetcapturebtn() {
capturebtndisabled = false;
$('#capturebtn').removeClass('btn-warning');
$('#capturebtn').addClass('btn-primary');
$('#capturebtn').removeClass('disabled');
$('#capturebtn').prop('disabled', false);
if (placeteam == 0) {
$('#capturebtn').text("Claim");
} else if (placeteam == userteamid) {
$('#capturebtn').addClass('disabled');
$('#capturebtn').text("Challenge");
$('#capturebtn').prop('disabled', true);
} else {
$('#capturebtn').text("Challenge");
}
}
function resetrefillbtn() {
refillbtndisabled = false;
$('#refillbtn').removeClass('btn-warning');
$('#refillbtn').addClass('btn-primary');
$('#refillbtn').removeClass('disabled');
$('#refillbtn').prop('disabled', false);
if (placeteam == 0) {
$('#refillbtn').addClass('disabled');
$('#refillbtn').text("Recharge");
$('#refillbtn').prop('disabled', true);
} else if (placeteam == userteamid) {
$('#refillbtn').text("Recharge");
} else {
$('#refillbtn').addClass('disabled');
$('#refillbtn').text("Recharge");
$('#refillbtn').prop('disabled', true);
}
}
function resync(firstload) {
$('#place-refresh').addClass('fa-spin');
$.getJSON(mkApiUrl('getstats', 'gs'), {
user: username,
lang: USER_LANGUAGE
}, function (data) {
if (data.status === 'OK') {
maxenergy = data.stats.maxenergy;
energy = data.stats.energy;
level = data.stats.level;
energypercent = (energy * 1.0 / maxenergy * 1.0) * 100.0;
$('#user-health-place-bar').css('width', String(energypercent) + '%');
refreshStats();
}
});
$.getJSON(mkApiUrl('placestats', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid,
lang: USER_LANGUAGE
}, function (data) {
if (data.status === 'OK') {
placeteam = data.stats.teamid;
var placepercent;
if (data.stats.currentlife > 0) {
placepercent = (Math.round(data.stats.currentlife) * 1.0 / Math.round(data.stats.maxlife) * 1.0) * 100.0;
} else {
placepercent = 0;
}
if (data.stats.nickname == null) {
$('#owner-label').text("Nobody");
} else {
$('#owner-label').on('click', function () {
openProfile(data.stats.nickname);
});
$('#owner-label').text(data.stats.nickname);
}
$('#place-health-place-bar').css('width', String(placepercent) + '%');
loadTeamSwag();
if (firstload === true) {
resetcapturebtn();
resetrefillbtn();
} else {
setTimeout(resetcapturebtn, actioninterval);
setTimeout(resetrefillbtn, actioninterval);
}
} else {
$('#place-log').prepend("An error occurred.<br />");
}
$('#place-refresh').removeClass('fa-spin');
}).fail(function () {
$('#place-log').prepend("An error occurred.<br />");
$('#place-refresh').removeClass('fa-spin');
});
}
function loadTeamSwag() {
$("#place-name").css("border-color", "#" + getTeamColorFromId(placeteam));
$("#place-info-div").css("border-color", "#" + getTeamColorFromId(placeteam));
$("#place-log").css("border-color", "#" + getTeamColorFromId(placeteam));
if (placeteam == 0) {
$("#capturebtn").css("background-color", "#" + getTeamColorFromId(userteamid));
$("#refillbtn").css("background-color", "#" + getTeamColorFromId(userteamid));
} else {
$("#capturebtn").css("background-color", "#" + getTeamColorFromId(placeteam));
$("#refillbtn").css("background-color", "#" + getTeamColorFromId(placeteam));
}
$("#place-health-place-bar").css("background-color", "#" + getTeamColorFromId(placeteam));
$("#team-label").css("color", "#" + getTeamColorFromId(placeteam));
$("#team-label").text(getTeamNameFromId(placeteam));
}
function loadPlace(feature) {
thisplace = feature;
placeteam = feature.properties.gameinfo.teamid;
$("#place-name").text(feature.properties.name);
$("#life-label").text(Math.round(feature.properties.gameinfo.currentlife) + " / " + Math.round(feature.properties.gameinfo.maxlife));
resync(true);
}
function attemptcapture() {
capturebtndisabled = true;
$('#capturebtn').prop('disabled', true);
$('#capturebtn').addClass('disabled');
$.getJSON(mkApiUrl('attackplace', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid,
lat: latitude,
long: longitude,
lang: USER_LANGUAGE
}, function (data) {
if (data.status === 'OK') {
$('#capturebtn').text(data.message);
switch (Math.round(Math.random() * (3 - 1) + 1)) {
case 1:
$('#place-log').prepend("Attacking...<br />");
break;
case 2:
$('#place-log').prepend("Attacking..<br />");
break;
case 3:
$('#place-log').prepend("Attacking....<br />");
}
if (data.levelup === true) {
playSound("levelup");
} else {
playSound("woosh");
}
resync();
} else {
playSound("error");
$('#capturebtn').text(data.message);
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />");
resync();
}
}).fail(function () {
playSound("error");
$('#capturebtn').text("Try that again.");
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
resync();
});
}
function attemptrefill() {
refillbtndisabled = true;
$('#refillbtn').prop('disabled', true);
$('#refillbtn').addClass('disabled');
$.getJSON(mkApiUrl('refillplace', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid,
lat: latitude,
long: longitude,
lang: USER_LANGUAGE
}, function (data) {
if (data.status === 'OK') {
$('#refillbtn').text(data.message);
switch (Math.round(Math.random() * (3 - 1) + 1)) {
case 1:
$('#place-log').prepend("Recharging...<br />");
break;
case 2:
$('#place-log').prepend("Recharging..<br />");
break;
case 3:
$('#place-log').prepend("Recharging....<br />");
}
if (data.levelup === true) {
playSound("levelup");
} else {
playSound("refill");
}
} else {
playSound("error");
$('#refillbtn').text(data.message);
$('#refillbtn').removeClass('btn-primary');
$('#refillbtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />");
}
resync();
}).fail(function () {
playSound("error");
$('#refillbtn').text("Try that again.");
$('#refillbtn').removeClass('btn-primary');
$('#refillbtn').addClass('btn-warning');
resync();
});
}
function attemptclaim() {
capturebtndisabled = true;
$('#capturebtn').prop('disabled', true);
$('#capturebtn').addClass('disabled');
$.getJSON(mkApiUrl('claimplace', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid,
lat: latitude,
long: longitude,
lang: USER_LANGUAGE
}, function (data) {
if (data.status === 'OK') {
$('#capturebtn').text(data.message);
$('#place-log').prepend("Claimed!<br />");
if (data.levelup === true) {
playSound("levelup");
} else {
playSound("claim");
}
resync();
} else {
playSound("error");
$('#capturebtn').text(data.message);
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />");
resync();
}
}).fail(function () {
playSound("error");
$('#capturebtn').text("Try that again.");
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
resync();
});
}
function attempttake() {
if (capturebtndisabled) {
return;
}
if (placeteam == 0) {
attemptclaim();
} else if (placeteam == userteamid) {
} else {
attemptcapture();
}
}
</script>