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.

419 lines
16 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: <span id="artifact-icon"></span>
<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 />
<div class="row">
<div class="col-xs-6">
<div class="btn btn-success btn-wide" id="artifactbtn" onclick="openartifactselect()"></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>
<div class="menumessage" id="artifactmessage">
<div class="menumessagecontent" id="artifactmessagecontent">
Select an artifact: <br />
<select class="form-control" id="artifact-dropdown"></select>
</div>
<div style="margin-bottom: 5px;" class="btn btn-wide btn-success" onclick="attemptartifact();">
Use
</div>
<div class="btn btn-wide btn-danger" onclick="$('#artifactmessage').css('display', 'none')">
Cancel
</div>
<span style="display: none;" id="giveitem-uuid"></span>
</div>
<script>
var thisplace = null;
var placeteam = 0;
var capturebtndisabled = false;
var refillbtndisabled = false;
var artifactbtndisabled = 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 resetartifactbtn() {
artifactbtndisabled = false;
$('#artifactbtn').removeClass('btn-warning');
$('#artifactbtn').addClass('btn-primary');
$('#artifactbtn').removeClass('disabled');
$('#artifactbtn').prop('disabled', false);
if (placeteam == 0) {
$('#artifactbtn').addClass('disabled');
$('#artifactbtn').text("Add Artifact");
$('#artifactbtn').prop('disabled', true);
} else if (placeteam == userteamid) {
$('#artifactbtn').text("Add Artifact");
} else {
$('#artifactbtn').addClass('disabled');
$('#artifactbtn').text("Add Artifact");
$('#artifactbtn').prop('disabled', true);
}
}
function openartifactselect() {
$.getJSON(mkApiUrl('inventory', 'gs'), {
classname: 'artifact',
lang: USER_LANGUAGE
}, function (data) {
var content = "";
if (data.status === 'OK') {
var items = data.items;
items.forEach(function (item) {
content += "<option value='" + item.itemuuid + "'>" + item.itemname + "</option>\n";
});
} else {
content = "";
}
if (content == '') {
playSound("error");
showErrorMessage("You don't have any artifacts.");
} else {
$('#artifact-dropdown').html(content);
$('#artifactmessage').css('display', 'block');
}
});
}
function closeartifactselect() {
$('#artifactmessage').css('display', 'none');
}
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) + '%');
$('#artifact-icon').html("");
for (var i = 0; i < data.stats.artifact; i++) {
$('#artifact-icon').append('<i class="fa fa-bolt" aria-hidden="true"></i> ');
}
loadTeamSwag();
if (firstload === true) {
resetcapturebtn();
resetrefillbtn();
resetartifactbtn();
} else {
setTimeout(resetcapturebtn, actioninterval);
setTimeout(resetrefillbtn, actioninterval);
setTimeout(resetartifactbtn, 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));
$("#artifactbtn").css("background-color", "#" + getTeamColorFromId(userteamid));
} else {
$("#capturebtn").css("background-color", "#" + getTeamColorFromId(placeteam));
$("#refillbtn").css("background-color", "#" + getTeamColorFromId(placeteam));
$("#artifactbtn").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 attemptartifact() {
capturebtndisabled = true;
$('#artifactbtn').prop('disabled', true);
$('#artifactbtn').addClass('disabled');
$.getJSON(mkApiUrl('artifactplace', 'gs'), {
locationid: thisplace.properties.gameinfo.locationid,
lat: latitude,
long: longitude,
itemid: $('#artifact-dropdown').val(),
lang: USER_LANGUAGE
}, function (data) {
if (data.status === 'OK') {
$('#artifactbtn').text(data.message);
$('#place-log').prepend("Added Artifact<br />");
if (data.levelup === true) {
playSound("levelup");
} else {
playSound("claim");
}
resync();
} else {
playSound("error");
$('#artifactbtn').text(data.message);
$('#artifactbtn').removeClass('btn-primary');
$('#artifactbtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />");
resync();
}
closeartifactselect();
}).fail(function () {
playSound("error");
$('#artifactbtn').text("Try that again.");
$('#artifactbtn').removeClass('btn-primary');
$('#artifactbtn').addClass('btn-warning');
resync();
closeartifactselect();
});
}
function attempttake() {
if (capturebtndisabled) {
return;
}
if (placeteam == 0) {
attemptclaim();
} else if (placeteam == userteamid) {
} else {
attemptcapture();
}
}
</script>