var itemsArray = [];
var multipleArray = [];
var waterLevel;
var staLevel;
var characterIsDead = false;
var hasCanteen = false;
var characterClass = " ";
var itemUsed;
var usedItemClicked = false;
var S2_usedRope = false;
var S3_caveFirst = false;
var S3_chooseCave = false;
var S3_chooseJuniper = false;
var S3_choice = 0;
var S3_hasFire = false;
var S3_grass = false;
var S3_shallowBed = false;
var S3_deepBed = false;
var S3_noImprovement = false;
var S4_boatLevel = 0;
var S5_maxedWater = false;
var S5_grassBed = false;
var S5_hasFire = false;
var S5_tea = false;
var globalIndex; //the index within itemsArray that refers to the currently selected
item
var S9_open_cistern = false;
var S9_open_outhouse = false;
var S9_open_cellar = false;
var S9_ladder_free = false;
function InventoryItem(id,name,usable){
this.idValue = id;
this.nameValue = name;
this.isUsable = usable;
}
$(document).ready(function() {
waterLossCounter = 0;
staLossCounter = 0;
waterLevel = 9; //9
staLevel = 5; //3
updateStats();
hideValue('#hidden_text');
hideValue('#system_messages');
hideValue(".locationText");
hideValue('#useWaterBTN');
hideValue('#useStaBTN');
controlTextNodes();
//hideValue('#useItemBTN');
// TESTING ONLY
$('#showMessages').click(function(){
showValue('#system_messages');
});
// TESTING ONLY
$('#hideMessages').click(function(){
hideValue('#system_messages');
});
// TESTING ONLY
$('#showHiddenText').click(function(){
showValue('#hidden_text');
});
// TESTING ONLY
$('#hideHiddenText').click(function(){
hideValue('#hidden_text');
});
// TESTING ONLY
$('#checkInventory').click(function(){
checkInventoryArray();
//alert("itemsArray length is: " + itemsArray.length);
//alert("class is: " + characterClass);
alert("boat level is: " + S4_boatLevel);
}); //end $('#checkInventory').click
}); //end $(document).ready(function()
// ----------------------------------------------------------------------------------------------------------------------- //
function hideValue(value) {
// hideValue('#span1_item1');
$(value).hide();
}
function showValue(value) {
$(value).show();
}
function showElement(value) {
//$(value).style.display = "inline";
$(value).style.visibility = 'visible';
}
function hideElement(value) {
//$(value).style.display = "none";
$(value).css('display','none');
}
// ----------------------------------------------------------------------------------------------------------------------- //
function controlTextNodes() {
$('#span0_1').click(function(){
// alert("1 clicked");
addItemToInventory("sta_item", "snack", false);
});
$('#span0_2').click(function(){
// alert("2 clicked");
addItemToInventory("boat_part", "rudder", false);
});
$('#span0_3').click(function(){
// alert("3 clicked");
removeSingle("sta_item");
});
$('#span0_4').click(function(){
// alert("4 clicked");
removeSingle("boat_part");
});
$('#span0_5').click(function(){
// alert("5 clicked");
selectMultiple("sta_item");
});
$('#span0_6').click(function(){
// alert("6 clicked");
selectMultiple("boat_part");
});
$('#span0_7').click(function(){
// alert("7 clicked");
removeMultiple();
});
$('#span0_8').click(function(){
// alert("8 clicked");
removeMultiple();
});
$('#span0_9').click(function(){
// alert("9 clicked");
setAsUsable("boat_part");
});
//--------------------------------------
$('#span0_10').click(function(){
changeWater(+1);
});
$('#span0_11').click(function(){
changeSta(+1);
});
$('#span0_12').click(function(){
changeVit(+1);
});
$('#span0_13').click(function(){
changeWater(-1);
});
$('#span0_14').click(function(){
changeSta(-1);
});
$('#span0_15').click(function(){
changeVit(-1);
});
$('#span0_16').click(function(){
// alert("9 clicked");
alert ("water is: " + waterLevel + " | stamina is: " + staLevel + " | vitality is: " + vitLevel );
});
$("#useStaBTN").click(function() {
var x = findIndex("sta_item");
if (!(x === null) && staLevel < 5){
changeSta(+1);
removeSingle("sta_item");
}
/*
if(x === "sta_item" && staLevel < 5) {
changeSta(+1);
removeSingle("sta_item");
}
*/
});
$("#useWaterBTN").click(function() {
var y = findIndex("full_bottle");
if (!(y === null) && waterLevel < 9){
// alert("bottle");
changeWater(+1);
$("#water_div").fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
removeSingle("full_bottle");
removeSingle("empty_bottle");
removeSingle("full_bottle");
addItemToInventory("empty_bottle", "Bottle (empty)", false);
}
});
$("#changeFont1").click(function() { //font-size: 1.15em;
$("#current_text_area").css('font-family', 'Sans-Serif');
$("#current_text_area").css('font-size', '1.0em');
});
$("#changeFont1L").click(function() { //font-size: 1.15em;
$("#current_text_area").css('font-family', 'Sans-Serif');
$("#current_text_area").css('font-size', '1.15em');
/*$("#current_text_area").css('line-height', '1.3em');*/
});
$("#changeFont2").click(function() {
$("#current_text_area").css('font-family', 'sheep_sans');
$("#current_text_area").css('font-size', '1.15em');
});
$("#changeFont2L").click(function() {
//alert("sdd");
$("#current_text_area").css('font-family', 'sheep_sans');
$("#current_text_area").css('font-size', '1.3em');
});
$("#showPageID").click(function() { //font-size: 1.15em;
//$("#locationText").show();
showValue(".locationText");
});
$("#hidePageID").click(function() { //font-size: 1.15em;
//$("#locationText").hide();
hideValue(".locationText");
});
//=------------------------------------------
setText(S1_01);
// setText(S5_05b);
//S4_boatLevel = 1;
// characterClass="sports";
// characterClass="survivialist";
//staLevel = 2;
//waterLevel= 4;
//updateStats();
// addItemToInventory("sta_item", "Granola Bar", true);
//addItemToInventory("sta_item", "Granola Bar", true);
// addItemToInventory("digging_tool", "Digging Tool", false);
} //END function controlTextNodes() {
// ----------------------------------------------------------------------------------------------------------------------- //
function setText(value) {
/*
$("#current_text_area span").empty();
temp = $(value).clone(true);
$('#current_text_area').append(temp);
//$('#hidden_text').show();
*/
$("#current_text_area span").remove();
temp = $(value).clone(true);
$('#current_text_area').append(temp);
//$('#hidden_text').show();
itemUsed = "";
}
// ----------------------------------------------------------------------------------------------------------------------- //
function sendMessage(value){
//alert("value is: " + value);
$('#system_messages').text(value);
}
function appendMessage(value){
//alert("value is: " + value);
var val1 = $('#internal_messages').text();
var val2 = val1 + " | " + value;
$('#internal_messages').text(val2);
}
// ----------------------------------------------------------------------------------------------------------------------- //
function changeWater(amount){
waterLevel += amount;
/*
if(waterLevel < 0){
waterLevel = 0;
}
*/
//hasCanteen
if (hasCanteen == false){
if(waterLevel > 9){
waterLevel = 9;
}
}
if (hasCanteen == false){
if(waterLevel > 12){
waterLevel = 12;
}
}
if(waterLevel < 0){
waterLevel = 0;
}
$("#water_div").fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
updateStats();
} //end changeWater
function changeSta(amount){
staLevel += amount;
/*
if(staLevel < 0){
staLevel = 0;
}
*/
if(staLevel > 5){
staLevel = 5;
}
if(staLevel < 0){
staLevel = 0;
}
$("#sta_div").fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
updateStats();
}
function updateStats() {
$('#water_stat').text(waterLevel);
$('#sta_stat').text(staLevel);
if (waterLevel == 0 || staLevel == 0){
// alert("character died, probably should show a THE END screen or something");
}
}
// ----------------------------------------------------------------------------------------------------------------------- //
function addItemToInventory(id,name,usable) {
itemsArray.push(new InventoryItem(id,name,usable));
updateInventory();
}
//takes idValue ie "boat_part" and returns its index within itemsArray
function findIndex(idValue) {
for(var i = itemsArray.length-1; i >= 0; i--) {
if (itemsArray[i].idValue === idValue)
return itemsArray.indexOf(itemsArray[i]);
}
return null;
}
//takes nameValue ie. "rudder" (which has an idValue of "boat_part")
//pretty much don't use findByName, use findIndex instead, but it's here if you need it
function findByName(nameValue) {
//for (var i = 0; i < itemsArray.length; i++) {
for(var i = itemsArray.length-1; i >= 0; i--) {
if (itemsArray[i].nameValue === nameValue)
return itemsArray.indexOf(itemsArray[i]); // Return as soon as the object is found
}
return null; // The object was not found
}
//DEPRECATED, use removeSingle instead
function removeItemFromInventory(value) {
/*
var idPosition = findIndex(value);
if(idPosition != null) {
itemsArray.splice(idPosition,1);
}
*/
var namePosition = findByName(value);
alert("name position is " + namePosition);
if(namePosition != null) {
itemsArray.splice(namePosition,1);
}
updateInventory();
}
function removeSingle(value) {
var idPosition = findIndex(value);
if(idPosition != null) {
itemsArray.splice(idPosition,1);
}
updateInventory();
}
function selectMultiple(value){
multipleArray = [];
for (var i = 0; i < itemsArray.length; i++) {
if (itemsArray[i].idValue === value)
multipleArray.push(itemsArray.indexOf(itemsArray[i]));
}
// alert("temp array: " + multipleArray);
//updateInventory();
}
function removeMultiple(){
itemsArray = itemsArray.filter(function(e,i){
return multipleArray.indexOf(i) == -1;
}
);
//alert("newArray is:" + itemsArray);
multipleArray = null;
updateInventory();
}
function selectItem(indexValue) {
/*
//globalIndex = indexValue;
for (var i = 0; i < itemsArray.length; i++) {
$("#inventory_list li").eq(i).removeClass('selected');
}
$("#inventory_list li").eq(indexValue).addClass('selected');
*/
}
function setAsUsable(value) {
// alert("temp array: " + multipleArray);
for (var i = 0; i < itemsArray.length; i++) {
if (itemsArray[i].idValue === value){
itemsArray[i].isUsable = true;
}
}
} //end setAsUsable()
//for a single item:
function setSingleAsUnusable(value) {
for (var i = 0; i < itemsArray.length; i++) {
if (itemsArray[i].idValue === value){
itemsArray[i].isUsable = false;
}
}
} //end setAsUsable()
// for multiple items
function setAsUnusable(){
for (var i = 0; i < itemsArray.length; i++) {
itemUsed = itemsArray[i].idValue;
if(!(itemUsed === "sta_item")){
itemsArray[i].isUsable = false;
}
}
}
function updateInventory() {
clearList();
for (var i = 0; i < itemsArray.length; i++) {
addLi(itemsArray[i].nameValue);
}
$("#inventory_list li").click(function() {
//var index = -1;
globalIndex = $(this).index();
// $(this).addClass('selected');
// alert("index is: " + globalIndex);
selectItem(globalIndex);
});//end inventory_list li click
}// end updateInventory
function clearList() {
var list = inventory_list;
while( list.hasChildNodes() ) {
list.removeChild( list.lastChild );
}
}
function addLi(text) {
$("#inventory_bottom ol").append(''+text+'');
}
function changeColor() {
alert("0: " + itemsArray[0].isUsable + " 1: " + itemsArray[1].isUsable + " 2: " + itemsArray[2].isUsable + " 3: " + itemsArray[3].isUsable + " 4: " + itemsArray[4].isUsable );
for (var i = 0; i < itemsArray.length; i++) {
if (itemsArray[i].isUsable === true) {
$("#inventory_list li").eq(i).addClass('testRed');
}
else {
}
}
}
// TESTING ONLY
function checkInventoryArray() {
var arrayList = " ";
for (var i = 0; i < itemsArray.length; i++) {
arrayList += itemsArray[i].idValue + " | ";
}
alert("" + arrayList);
}
// TESTING ONLY
function checkForItem(value) {
if(jQuery.inArray(value, itemsArray) != -1) {
alert("item " + value + " is in the array");
}
else if (jQuery.inArray(value, itemsArray) == -1) {
alert("item " + value + " is NOT in the array, -1 returned");
}
}