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.

189 lines
7.3 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">
Type: <span id="team-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="btn btn-success btn-wide" id="capturebtn" onclick="attempttake()"></div>
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;
function resetcapturebtn() {
capturebtndisabled = false;
$('#capturebtn').removeClass('btn-warning');
$('#capturebtn').addClass('btn-primary');
$('#capturebtn').removeClass('disabled');
if (placeteam == 0) {
$('#capturebtn').text("Claim");
} else if (placeteam == userteamid) {
$('#capturebtn').css('visibility', 'hidden');
} else {
$('#capturebtn').text("Challenge");
}
$('#capturebtn').prop('disabled', false);
}
function resyncstats() {
$.getJSON(mkApiUrl('getstats', 'gs'), {
user: username
}, 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
}, 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;
}
$('#place-health-place-bar').css('width', String(placepercent) + '%');
loadTeamSwag();
} else {
//
}
}).fail(function () {
});
}
function resetafteraction() {
resyncstats();
setTimeout(resetcapturebtn, 2 * 1000);
}
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));
} else {
$("#capturebtn").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;
loadTeamSwag();
$("#place-name").text(feature.properties.name);
$("#life-label").text(Math.round(feature.properties.gameinfo.currentlife) + " / " + Math.round(feature.properties.gameinfo.maxlife));
resetcapturebtn();
resyncstats();
}
function attemptcapture() {
capturebtndisabled = true;
$('#capturebtn').prop('disabled', true);
$('#capturebtn').addClass('disabled');
$.getJSON(mkApiUrl('attackplace', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid
}, 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 />");
}
resetafteraction();
} else {
$('#capturebtn').text(data.message);
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />");
resetafteraction();
}
//alert(data.message);
}).fail(function () {
$('#capturebtn').text("Try that again.");
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
resetafteraction();
});
}
function attemptclaim() {
capturebtndisabled = true;
$('#capturebtn').prop('disabled', true);
$('#capturebtn').addClass('disabled');
$.getJSON(mkApiUrl('claimplace', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid
}, function (data) {
if (data.status === 'OK') {
$('#capturebtn').text(data.message);
$('#place-log').prepend("Claimed!<br />");
resetafteraction();
} else {
$('#capturebtn').text(data.message);
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />");
resetafteraction();
}
//alert(data.message);
}).fail(function () {
$('#capturebtn').text("Try that again.");
$('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning');
});
}
function attempttake() {
if (capturebtndisabled) {
return;
}
if (placeteam == 0) {
attemptclaim();
} else if (placeteam == userteamid) {
} else {
attemptcapture();
}
}
</script>