2017-09-21 23:27:31 +02:00
|
|
|
import {CONSTANTS} from "./Constants.js";
|
2017-09-25 14:50:19 +02:00
|
|
|
import {Engine} from "./engine.js";
|
2017-09-26 04:44:33 +02:00
|
|
|
import {displayFactionContent} from "./Faction.js";
|
2017-09-25 14:50:19 +02:00
|
|
|
import {Player} from "./Player.js";
|
2017-09-21 23:27:31 +02:00
|
|
|
import {dialogBoxCreate} from "../utils/DialogBox.js";
|
|
|
|
import {addOffset, getRandomInt,
|
2017-09-26 04:44:33 +02:00
|
|
|
clearEventListenersEl,
|
|
|
|
clearEventListeners} from "../utils/HelperFunctions.js";
|
2017-09-25 14:50:19 +02:00
|
|
|
import {formatNumber, isString} from "../utils/StringHelperFunctions.js";
|
2017-09-21 23:27:31 +02:00
|
|
|
import jsplumb from 'jsplumb'
|
|
|
|
|
|
|
|
let inMission = false; //Flag to denote whether a mission is running
|
2017-09-25 14:50:19 +02:00
|
|
|
let currMission = null;
|
|
|
|
function setInMission(bool, mission) {
|
2017-09-21 23:27:31 +02:00
|
|
|
inMission = bool;
|
2017-09-25 14:50:19 +02:00
|
|
|
if (bool) {
|
|
|
|
currMission = mission;
|
|
|
|
} else {
|
|
|
|
currMission = null;
|
|
|
|
}
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
|
2017-09-26 04:44:33 +02:00
|
|
|
//Keyboard shortcuts
|
|
|
|
$(document).keydown(function(e) {
|
2017-12-07 04:45:47 +01:00
|
|
|
if (inMission && currMission && currMission.selectedNode.length != 0) {
|
2017-09-26 04:44:33 +02:00
|
|
|
switch (e.keyCode) {
|
|
|
|
case 65: //a for Attack
|
|
|
|
currMission.actionButtons[0].click();
|
|
|
|
break;
|
|
|
|
case 83: //s for Scan
|
|
|
|
currMission.actionButtons[1].click();
|
|
|
|
break;
|
|
|
|
case 87: //w for Weaken
|
|
|
|
currMission.actionButtons[2].click();
|
|
|
|
break;
|
|
|
|
case 70: //f for Fortify
|
|
|
|
currMission.actionButtons[3].click();
|
|
|
|
break;
|
|
|
|
case 82: //r for Overflow
|
|
|
|
currMission.actionButtons[4].click();
|
|
|
|
break;
|
|
|
|
case 68: //d for Detach connection
|
|
|
|
currMission.actionButtons[5].click();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-09-21 23:27:31 +02:00
|
|
|
|
|
|
|
let NodeTypes = {
|
|
|
|
Core: "CPU Core Node", //All actions available
|
|
|
|
Firewall: "Firewall Node", //No actions available
|
|
|
|
Database: "Database Node", //No actions available
|
|
|
|
Spam: "Spam Node", //No actions Available
|
2017-09-26 04:44:33 +02:00
|
|
|
Transfer: "Transfer Node", //Can Weaken, Scan, Fortify and Overflow
|
2017-09-21 23:27:31 +02:00
|
|
|
Shield: "Shield Node" //Can Fortify
|
|
|
|
}
|
|
|
|
|
|
|
|
let NodeActions = {
|
2017-09-25 14:50:19 +02:00
|
|
|
Attack: "Attacking", //Damaged based on attack stat + hacking level + opp def
|
2017-09-26 04:44:33 +02:00
|
|
|
Scan: "Scanning", //-Def for target, affected by attack and hacking level
|
|
|
|
Weaken: "Weakening", //-Attack for target, affected by attack and hacking level
|
2017-09-25 14:50:19 +02:00
|
|
|
Fortify: "Fortifying", //+Defense for Node, affected by hacking level
|
|
|
|
Overflow: "Overflowing", //+Attack but -Defense for Node, affected by hacking level
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Node(type, stats) {
|
|
|
|
this.type = type;
|
|
|
|
this.atk = stats.atk ? stats.atk : 0;
|
|
|
|
this.def = stats.def ? stats.def : 0;
|
|
|
|
this.hp = stats.hp ? stats.hp : 0;
|
|
|
|
this.maxhp = this.hp;
|
|
|
|
this.plyrCtrl = false;
|
|
|
|
this.enmyCtrl = false;
|
|
|
|
this.pos = [0, 0]; //x, y
|
|
|
|
this.el = null; //Holds the Node's DOM element
|
|
|
|
this.action = null;
|
2017-10-10 06:56:48 +02:00
|
|
|
this.targetedCount = 0; //Count of how many connections this node is the target of
|
2017-09-25 14:50:19 +02:00
|
|
|
|
|
|
|
//Holds the JsPlumb Connection object for this Node,
|
|
|
|
//where this Node is the Source (since each Node
|
|
|
|
//can only have 1 outgoing Connection)
|
|
|
|
this.conn = null;
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Node.prototype.setPosition = function(x, y) {
|
|
|
|
this.pos = [x, y];
|
|
|
|
}
|
|
|
|
|
|
|
|
Node.prototype.setControlledByPlayer = function() {
|
|
|
|
this.plyrCtrl = true;
|
|
|
|
this.enmyCtrl = false;
|
|
|
|
if (this.el) {
|
2017-09-25 14:50:19 +02:00
|
|
|
this.el.classList.remove("hack-mission-enemy-node");
|
|
|
|
this.el.classList.add("hack-mission-player-node");
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Node.prototype.setControlledByEnemy = function() {
|
|
|
|
this.plyrCtrl = false;
|
|
|
|
this.enmyCtrl = true;
|
|
|
|
if (this.el) {
|
2017-09-25 14:50:19 +02:00
|
|
|
this.el.classList.remove("hack-mission-player-node");
|
|
|
|
this.el.classList.add("hack-mission-enemy-node");
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Sets this node to be the active node
|
|
|
|
Node.prototype.select = function(actionButtons) {
|
|
|
|
if (this.enmyCtrl) {return;}
|
|
|
|
this.el.classList.add("hack-mission-player-node-active");
|
|
|
|
|
|
|
|
//Make all buttons inactive
|
|
|
|
for (var i = 0; i < actionButtons.length; ++i) {
|
|
|
|
actionButtons[i].classList.remove("a-link-button");
|
|
|
|
actionButtons[i].classList.add("a-link-button-inactive");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(this.type) {
|
|
|
|
case NodeTypes.Core:
|
|
|
|
//All buttons active
|
|
|
|
for (var i = 0; i < actionButtons.length; ++i) {
|
|
|
|
actionButtons[i].classList.remove("a-link-button-inactive");
|
|
|
|
actionButtons[i].classList.add("a-link-button");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NodeTypes.Transfer:
|
|
|
|
actionButtons[1].classList.remove("a-link-button-inactive");
|
|
|
|
actionButtons[1].classList.add("a-link-button");
|
|
|
|
actionButtons[2].classList.remove("a-link-button-inactive");
|
|
|
|
actionButtons[2].classList.add("a-link-button");
|
2017-09-26 04:44:33 +02:00
|
|
|
actionButtons[3].classList.remove("a-link-button-inactive");
|
|
|
|
actionButtons[3].classList.add("a-link-button");
|
2017-09-21 23:27:31 +02:00
|
|
|
actionButtons[4].classList.remove("a-link-button-inactive");
|
|
|
|
actionButtons[4].classList.add("a-link-button");
|
2017-09-26 04:44:33 +02:00
|
|
|
actionButtons[5].classList.remove("a-link-button-inactive");
|
|
|
|
actionButtons[5].classList.add("a-link-button");
|
2017-09-21 23:27:31 +02:00
|
|
|
break;
|
2017-12-03 05:19:49 +01:00
|
|
|
case NodeTypes.Shield:
|
|
|
|
case NodeTypes.Firewall:
|
|
|
|
actionButtons[3].classList.remove("a-link-button-inactive");
|
|
|
|
actionButtons[3].classList.add("a-link-button");
|
|
|
|
break;
|
2017-09-21 23:27:31 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Node.prototype.deselect = function(actionButtons) {
|
2017-09-26 04:44:33 +02:00
|
|
|
this.el.classList.remove("hack-mission-player-node-active");
|
2017-09-21 23:27:31 +02:00
|
|
|
for (var i = 0; i < actionButtons.length; ++i) {
|
|
|
|
actionButtons[i].classList.remove("a-link-button");
|
|
|
|
actionButtons[i].classList.add("a-link-button-inactive");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 06:56:48 +02:00
|
|
|
|
|
|
|
Node.prototype.untarget = function() {
|
|
|
|
if (this.targetedCount === 0) {
|
|
|
|
console.log("WARN: Node " + this.el.id + " is being 'untargeted' when it has no target count");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
--this.targetedCount;
|
|
|
|
}
|
|
|
|
|
2017-09-21 23:27:31 +02:00
|
|
|
//Hacking mission instance
|
|
|
|
//Takes in the reputation of the Faction for which the mission is
|
|
|
|
//being conducted
|
|
|
|
function HackingMission(rep, fac) {
|
|
|
|
this.faction = fac;
|
|
|
|
|
2017-09-26 04:44:33 +02:00
|
|
|
this.started = false;
|
2017-10-02 05:27:42 +02:00
|
|
|
this.time = 180000; //5 minutes to start, milliseconds
|
2017-09-25 14:50:19 +02:00
|
|
|
|
2017-09-21 23:27:31 +02:00
|
|
|
this.playerCores = [];
|
|
|
|
this.playerNodes = []; //Non-core nodes
|
2017-09-27 17:13:42 +02:00
|
|
|
this.playerAtk = 0;
|
2017-09-21 23:27:31 +02:00
|
|
|
this.playerDef = 0;
|
|
|
|
|
|
|
|
this.enemyCores = [];
|
|
|
|
this.enemyDatabases = [];
|
|
|
|
this.enemyNodes = []; //Non-core nodes
|
2017-09-27 17:13:42 +02:00
|
|
|
this.enemyAtk = 0;
|
2017-09-21 23:27:31 +02:00
|
|
|
this.enemyDef = 0;
|
|
|
|
|
|
|
|
this.miscNodes = [];
|
|
|
|
|
2017-12-07 04:45:47 +01:00
|
|
|
this.selectedNode = []; //Which of the player's nodes are currently selected
|
2017-09-21 23:27:31 +02:00
|
|
|
|
|
|
|
this.actionButtons = []; //DOM buttons for actions
|
|
|
|
|
|
|
|
this.availablePositions = [];
|
|
|
|
for (var r = 0; r < 8; ++r) {
|
|
|
|
for (var c = 0; c < 8; ++c) {
|
|
|
|
this.availablePositions.push([r, c]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.map = [];
|
|
|
|
for (var i = 0; i < 8; ++i) {
|
|
|
|
this.map.push([null, null, null, null, null, null, null, null]);
|
|
|
|
}
|
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
this.jsplumbinstance = null;
|
|
|
|
|
2017-10-10 06:56:48 +02:00
|
|
|
this.difficulty = rep / CONSTANTS.HackingMissionRepToDiffConversion + 1;
|
2017-09-21 23:27:31 +02:00
|
|
|
console.log("difficulty: " + this.difficulty);
|
2017-09-27 17:13:42 +02:00
|
|
|
this.reward = 250 + (rep / CONSTANTS.HackingMissionRepToRewardConversion);
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HackingMission.prototype.init = function() {
|
|
|
|
//Create Header DOM
|
|
|
|
this.createPageDom();
|
|
|
|
|
|
|
|
//Create player starting nodes
|
|
|
|
var home = Player.getHomeComputer()
|
|
|
|
for (var i = 0; i < home.cpuCores; ++i) {
|
|
|
|
var stats = {
|
2017-10-10 06:56:48 +02:00
|
|
|
atk: (Player.hacking_skill / 7.5) + 30,
|
2017-10-02 04:35:22 +02:00
|
|
|
def: (Player.hacking_skill / 20),
|
2017-10-10 06:56:48 +02:00
|
|
|
hp: (Player.hacking_skill / 4),
|
2017-09-21 23:27:31 +02:00
|
|
|
};
|
|
|
|
this.playerCores.push(new Node(NodeTypes.Core, stats));
|
|
|
|
this.playerCores[i].setControlledByPlayer();
|
2017-10-10 06:56:48 +02:00
|
|
|
this.setNodePosition(this.playerCores[i], i, 0);
|
|
|
|
this.removeAvailablePosition(i, 0);
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Randomly generate enemy nodes (CPU and Firewall) based on difficulty
|
2017-10-10 06:56:48 +02:00
|
|
|
var numNodes = Math.min(8, Math.max(1, Math.round(this.difficulty / 4)));
|
|
|
|
var numFirewalls = Math.min(20,
|
2017-12-07 04:45:47 +01:00
|
|
|
getRandomInt(Math.round(this.difficulty/3), Math.round(this.difficulty/3) + 1));
|
2017-10-10 06:56:48 +02:00
|
|
|
var numDatabases = Math.min(10, getRandomInt(1, Math.round(this.difficulty / 3) + 1));
|
2017-09-21 23:27:31 +02:00
|
|
|
var totalNodes = numNodes + numFirewalls + numDatabases;
|
|
|
|
var xlimit = 7 - Math.floor(totalNodes / 8);
|
2017-10-10 06:56:48 +02:00
|
|
|
var randMult = addOffset(0.8 + (this.difficulty / 5), 10);
|
2017-09-21 23:27:31 +02:00
|
|
|
for (var i = 0; i < numNodes; ++i) {
|
|
|
|
var stats = {
|
2017-12-07 04:45:47 +01:00
|
|
|
atk: randMult * getRandomInt(80, 86),
|
|
|
|
def: randMult * getRandomInt(5, 10),
|
2017-10-15 03:55:41 +02:00
|
|
|
hp: randMult * getRandomInt(210, 230)
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
this.enemyCores.push(new Node(NodeTypes.Core, stats));
|
|
|
|
this.enemyCores[i].setControlledByEnemy();
|
|
|
|
this.setNodeRandomPosition(this.enemyCores[i], xlimit);
|
|
|
|
}
|
|
|
|
for (var i = 0; i < numFirewalls; ++i) {
|
|
|
|
var stats = {
|
2017-10-02 04:35:22 +02:00
|
|
|
atk: 0,
|
2017-12-07 04:45:47 +01:00
|
|
|
def: randMult * getRandomInt(10, 20),
|
2017-10-15 03:55:41 +02:00
|
|
|
hp: randMult * getRandomInt(275, 300)
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
this.enemyNodes.push(new Node(NodeTypes.Firewall, stats));
|
|
|
|
this.enemyNodes[i].setControlledByEnemy();
|
|
|
|
this.setNodeRandomPosition(this.enemyNodes[i], xlimit);
|
|
|
|
}
|
|
|
|
for (var i = 0; i < numDatabases; ++i) {
|
|
|
|
var stats = {
|
2017-10-04 03:50:13 +02:00
|
|
|
atk: 0,
|
2017-12-07 04:45:47 +01:00
|
|
|
def: randMult * getRandomInt(30, 55),
|
2017-10-15 03:55:41 +02:00
|
|
|
hp: randMult * getRandomInt(210, 275)
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
var node = new Node(NodeTypes.Database, stats);
|
|
|
|
node.setControlledByEnemy();
|
|
|
|
this.setNodeRandomPosition(node, xlimit);
|
|
|
|
this.enemyDatabases.push(node);
|
|
|
|
}
|
|
|
|
this.calculateDefenses();
|
2017-09-27 17:13:42 +02:00
|
|
|
this.calculateAttacks();
|
2017-09-21 23:27:31 +02:00
|
|
|
this.createMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
HackingMission.prototype.createPageDom = function() {
|
|
|
|
var container = document.getElementById("mission-container");
|
|
|
|
|
2017-10-10 06:56:48 +02:00
|
|
|
var favorMult = 1 + (this.faction.favor / 100);
|
|
|
|
var gain = this.reward * Player.faction_rep_mult * favorMult;
|
2017-09-21 23:27:31 +02:00
|
|
|
var headerText = document.createElement("p");
|
2017-10-10 06:56:48 +02:00
|
|
|
headerText.innerHTML = "You are about to start a hacking mission! You will gain " +
|
|
|
|
formatNumber(gain, 3) + " faction reputation with " + this.faction.name +
|
|
|
|
" if you win. For more information " +
|
2017-09-21 23:27:31 +02:00
|
|
|
"about how hacking missions work, click one of the guide links " +
|
|
|
|
"below (one opens up an in-game guide and the other opens up " +
|
|
|
|
"the guide from the wiki). Click the 'Start' button to begin.";
|
|
|
|
headerText.style.display = "block";
|
|
|
|
headerText.classList.add("hack-mission-header-element");
|
|
|
|
headerText.style.width = "80%";
|
|
|
|
|
|
|
|
var inGameGuideBtn = document.createElement("a");
|
|
|
|
inGameGuideBtn.innerText = "How to Play";
|
|
|
|
inGameGuideBtn.classList.add("a-link-button");
|
|
|
|
inGameGuideBtn.style.display = "inline-block";
|
|
|
|
inGameGuideBtn.classList.add("hack-mission-header-element");
|
|
|
|
inGameGuideBtn.addEventListener("click", function() {
|
|
|
|
dialogBoxCreate(CONSTANTS.HackingMissionHowToPlay);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
var wikiGuideBtn = document.createElement("a");
|
|
|
|
wikiGuideBtn.innerText = "Wiki Guide";
|
|
|
|
wikiGuideBtn.classList.add("a-link-button");
|
|
|
|
wikiGuideBtn.style.display = "inline-block";
|
|
|
|
wikiGuideBtn.classList.add("hack-mission-header-element");
|
|
|
|
wikiGuideBtn.target = "_blank";
|
|
|
|
//TODO Add link to wiki page wikiGuideBtn.href =
|
|
|
|
|
|
|
|
|
|
|
|
//Start button will get replaced with forfeit when game is started
|
|
|
|
var startBtn = document.createElement("a");
|
2017-09-25 14:50:19 +02:00
|
|
|
startBtn.innerHTML = "Start";
|
2017-09-26 04:44:33 +02:00
|
|
|
startBtn.setAttribute("id", "hack-mission-start-btn");
|
2017-09-25 14:50:19 +02:00
|
|
|
startBtn.classList.add("a-link-button");
|
2017-09-21 23:27:31 +02:00
|
|
|
startBtn.classList.add("hack-mission-header-element");
|
2017-09-25 14:50:19 +02:00
|
|
|
startBtn.style.display = "inline-block";
|
2017-09-26 04:44:33 +02:00
|
|
|
startBtn.addEventListener("click", ()=>{
|
|
|
|
this.start();
|
2017-09-27 17:13:42 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
var forfeitMission = document.createElement("a");
|
|
|
|
forfeitMission.innerHTML = "Forfeit Mission (Exit)";
|
|
|
|
forfeitMission.classList.add("a-link-button");
|
|
|
|
forfeitMission.classList.add("hack-mission-header-element");
|
|
|
|
forfeitMission.style.display = "inline-block";
|
|
|
|
forfeitMission.addEventListener("click", ()=> {
|
|
|
|
this.finishMission(false);
|
|
|
|
return false;
|
2017-09-26 04:44:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
var timer = document.createElement("p");
|
|
|
|
timer.setAttribute("id", "hacking-mission-timer");
|
|
|
|
timer.style.display = "inline-block";
|
2017-09-27 17:13:42 +02:00
|
|
|
timer.style.margin = "6px";
|
2017-09-21 23:27:31 +02:00
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
//Create Action Buttons (Attack/Scan/Weaken/ etc...)
|
2017-09-21 23:27:31 +02:00
|
|
|
var actionsContainer = document.createElement("span");
|
2017-09-25 14:50:19 +02:00
|
|
|
actionsContainer.style.display = "block";
|
2017-09-21 23:27:31 +02:00
|
|
|
actionsContainer.classList.add("hack-mission-action-buttons-container");
|
2017-09-26 04:44:33 +02:00
|
|
|
for (var i = 0; i < 6; ++i) {
|
2017-09-21 23:27:31 +02:00
|
|
|
this.actionButtons.push(document.createElement("a"));
|
|
|
|
this.actionButtons[i].style.display = "inline-block";
|
|
|
|
this.actionButtons[i].classList.add("a-link-button-inactive"); //Disabled at start
|
|
|
|
this.actionButtons[i].classList.add("tooltip"); //Disabled at start
|
|
|
|
this.actionButtons[i].classList.add("hack-mission-header-element");
|
|
|
|
actionsContainer.appendChild(this.actionButtons[i]);
|
|
|
|
}
|
2017-09-25 14:50:19 +02:00
|
|
|
this.actionButtons[0].innerText = "Attack(a)";
|
2017-09-21 23:27:31 +02:00
|
|
|
var atkTooltip = document.createElement("span");
|
2017-10-02 04:35:22 +02:00
|
|
|
atkTooltip.classList.add("tooltiptexthigh");
|
2017-09-21 23:27:31 +02:00
|
|
|
atkTooltip.innerText = "Lowers the targeted node's HP. The effectiveness of this depends on " +
|
2017-09-26 04:44:33 +02:00
|
|
|
"this node's Attack level, your hacking level, and the opponent's defense level.";
|
2017-09-21 23:27:31 +02:00
|
|
|
this.actionButtons[0].appendChild(atkTooltip);
|
2017-09-25 14:50:19 +02:00
|
|
|
this.actionButtons[1].innerText = "Scan(s)";
|
2017-09-21 23:27:31 +02:00
|
|
|
var scanTooltip = document.createElement("span");
|
2017-10-02 04:35:22 +02:00
|
|
|
scanTooltip.classList.add("tooltiptexthigh");
|
2017-09-21 23:27:31 +02:00
|
|
|
scanTooltip.innerText = "Lowers the targeted node's defense. The effectiveness of this depends on " +
|
2017-09-26 04:44:33 +02:00
|
|
|
"this node's Attack level, your hacking level, and the opponent's defense level.";
|
2017-09-21 23:27:31 +02:00
|
|
|
this.actionButtons[1].appendChild(scanTooltip);
|
2017-09-25 14:50:19 +02:00
|
|
|
this.actionButtons[2].innerText = "Weaken(w)";
|
|
|
|
var WeakenTooltip = document.createElement("span");
|
2017-10-02 04:35:22 +02:00
|
|
|
WeakenTooltip.classList.add("tooltiptexthigh");
|
2017-09-25 14:50:19 +02:00
|
|
|
WeakenTooltip.innerText = "Lowers the targeted node's attack. The effectiveness of this depends on " +
|
2017-09-26 04:44:33 +02:00
|
|
|
"this node's Attack level, your hacking level, and the opponent's defense level.";
|
2017-09-25 14:50:19 +02:00
|
|
|
this.actionButtons[2].appendChild(WeakenTooltip);
|
|
|
|
this.actionButtons[3].innerText = "Fortify(f)";
|
2017-09-21 23:27:31 +02:00
|
|
|
var fortifyTooltip = document.createElement("span");
|
2017-10-02 04:35:22 +02:00
|
|
|
fortifyTooltip.classList.add("tooltiptexthigh");
|
2017-09-21 23:27:31 +02:00
|
|
|
fortifyTooltip.innerText = "Raises this node's Defense level. The effectiveness of this depends on " +
|
|
|
|
"your hacking level";
|
|
|
|
this.actionButtons[3].appendChild(fortifyTooltip);
|
2017-09-25 14:50:19 +02:00
|
|
|
this.actionButtons[4].innerText = "Overflow(r)";
|
2017-09-21 23:27:31 +02:00
|
|
|
var overflowTooltip = document.createElement("span");
|
2017-10-02 04:35:22 +02:00
|
|
|
overflowTooltip.classList.add("tooltiptexthigh");
|
2017-09-21 23:27:31 +02:00
|
|
|
overflowTooltip.innerText = "Raises this node's Attack level but lowers its Defense level. The effectiveness " +
|
|
|
|
"of this depends on your hacking level.";
|
|
|
|
this.actionButtons[4].appendChild(overflowTooltip);
|
2017-09-26 04:44:33 +02:00
|
|
|
this.actionButtons[5].innerText = "Drop Connection(d)";
|
|
|
|
var dropconnTooltip = document.createElement("span");
|
2017-10-02 04:35:22 +02:00
|
|
|
dropconnTooltip.classList.add("tooltiptexthigh");
|
2017-09-26 04:44:33 +02:00
|
|
|
dropconnTooltip.innerText = "Removes this Node's current connection to some target Node, if it has one. This can " +
|
|
|
|
"also be done by simply clicking the white connection line.";
|
|
|
|
this.actionButtons[5].appendChild(dropconnTooltip);
|
|
|
|
|
|
|
|
//Player/enemy defense displays will be in action container
|
2017-09-27 17:13:42 +02:00
|
|
|
var playerStats = document.createElement("p");
|
|
|
|
var enemyStats = document.createElement("p");
|
|
|
|
playerStats.style.display = "inline-block";
|
|
|
|
enemyStats.style.display = "inline-block";
|
|
|
|
playerStats.style.color = "#00ccff";
|
|
|
|
enemyStats.style.color = "red";
|
|
|
|
playerStats.style.margin = "4px";
|
|
|
|
enemyStats.style.margin = "4px";
|
|
|
|
playerStats.setAttribute("id", "hacking-mission-player-stats");
|
|
|
|
enemyStats.setAttribute("id", "hacking-mission-enemy-stats");
|
|
|
|
actionsContainer.appendChild(playerStats);
|
|
|
|
actionsContainer.appendChild(enemyStats);
|
2017-09-21 23:27:31 +02:00
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
//Set Action Button event listeners
|
|
|
|
this.actionButtons[0].addEventListener("click", ()=>{
|
2017-12-07 04:45:47 +01:00
|
|
|
if (!(this.selectedNode.length > 0)) {
|
2017-09-25 14:50:19 +02:00
|
|
|
console.log("ERR: Pressing Action button without selected node");
|
|
|
|
return;
|
|
|
|
}
|
2017-12-07 04:45:47 +01:00
|
|
|
if (this.selectedNode[0].type !== NodeTypes.Core) {return;}
|
|
|
|
this.setActionButtonsActive(this.selectedNode[0].type);
|
2017-09-25 14:50:19 +02:00
|
|
|
this.setActionButton(NodeActions.Attack, false); //Set attack button inactive
|
2017-12-07 04:45:47 +01:00
|
|
|
this.selectedNode.forEach(function(node){
|
|
|
|
node.action = NodeActions.Attack;
|
|
|
|
});
|
2017-09-25 14:50:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.actionButtons[1].addEventListener("click", ()=>{
|
2017-12-07 04:45:47 +01:00
|
|
|
if (!(this.selectedNode.length > 0)) {
|
2017-09-25 14:50:19 +02:00
|
|
|
console.log("ERR: Pressing Action button without selected node");
|
|
|
|
return;
|
|
|
|
}
|
2017-12-07 04:45:47 +01:00
|
|
|
var nodeType = this.selectedNode[0].type; //In a multiselect, every Node will have the same type
|
2017-12-03 05:19:49 +01:00
|
|
|
if (nodeType !== NodeTypes.Core && nodeType !== NodeTypes.Transfer) {return;}
|
|
|
|
this.setActionButtonsActive(nodeType);
|
2017-09-25 14:50:19 +02:00
|
|
|
this.setActionButton(NodeActions.Scan, false); //Set scan button inactive
|
2017-12-07 04:45:47 +01:00
|
|
|
this.selectedNode.forEach(function(node){
|
|
|
|
node.action = NodeActions.Scan;
|
|
|
|
});
|
2017-09-25 14:50:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.actionButtons[2].addEventListener("click", ()=>{
|
2017-12-07 04:45:47 +01:00
|
|
|
if (!(this.selectedNode.length > 0)) {
|
2017-09-25 14:50:19 +02:00
|
|
|
console.log("ERR: Pressing Action button without selected node");
|
|
|
|
return;
|
|
|
|
}
|
2017-12-07 04:45:47 +01:00
|
|
|
var nodeType = this.selectedNode[0].type; //In a multiselect, every Node will have the same type
|
2017-12-03 05:19:49 +01:00
|
|
|
if (nodeType !== NodeTypes.Core && nodeType !== NodeTypes.Transfer) {return;}
|
|
|
|
this.setActionButtonsActive(nodeType);
|
2017-09-25 14:50:19 +02:00
|
|
|
this.setActionButton(NodeActions.Weaken, false); //Set Weaken button inactive
|
2017-12-07 04:45:47 +01:00
|
|
|
this.selectedNode.forEach(function(node){
|
|
|
|
node.action = NodeActions.Weaken;
|
|
|
|
});
|
2017-09-25 14:50:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.actionButtons[3].addEventListener("click", ()=>{
|
2017-12-07 04:45:47 +01:00
|
|
|
if (!(this.selectedNode.length > 0)) {
|
2017-09-25 14:50:19 +02:00
|
|
|
console.log("ERR: Pressing Action button without selected node");
|
|
|
|
return;
|
|
|
|
}
|
2017-12-07 04:45:47 +01:00
|
|
|
this.setActionButtonsActive(this.selectedNode[0].type);
|
2017-09-25 14:50:19 +02:00
|
|
|
this.setActionButton(NodeActions.Fortify, false); //Set Fortify button inactive
|
2017-12-07 04:45:47 +01:00
|
|
|
this.selectedNode.forEach(function(node){
|
|
|
|
node.action = NodeActions.Fortify;
|
|
|
|
});
|
2017-09-25 14:50:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.actionButtons[4].addEventListener("click", ()=>{
|
2017-12-07 04:45:47 +01:00
|
|
|
if (!(this.selectedNode.length > 0)) {
|
2017-09-25 14:50:19 +02:00
|
|
|
console.log("ERR: Pressing Action button without selected node");
|
|
|
|
return;
|
|
|
|
}
|
2017-12-07 04:45:47 +01:00
|
|
|
var nodeType = this.selectedNode[0].type;
|
2017-12-03 05:19:49 +01:00
|
|
|
if (nodeType !== NodeTypes.Core && nodeType !== NodeTypes.Transfer) {return;}
|
2017-12-07 04:45:47 +01:00
|
|
|
this.setActionButtonsActive(nodeType);
|
2017-09-25 14:50:19 +02:00
|
|
|
this.setActionButton(NodeActions.Overflow, false); //Set Overflow button inactive
|
2017-12-07 04:45:47 +01:00
|
|
|
this.selectedNode.forEach(function(node){
|
|
|
|
node.action = NodeActions.Overflow;
|
|
|
|
});
|
2017-09-25 14:50:19 +02:00
|
|
|
});
|
|
|
|
|
2017-09-26 04:44:33 +02:00
|
|
|
this.actionButtons[5].addEventListener("click", ()=>{
|
2017-12-07 04:45:47 +01:00
|
|
|
if (!(this.selectedNode.length > 0)) {
|
2017-09-26 04:44:33 +02:00
|
|
|
console.log("ERR: Pressing Action button without selected node");
|
|
|
|
return;
|
|
|
|
}
|
2017-12-07 04:45:47 +01:00
|
|
|
this.selectedNode.forEach(function(node){
|
|
|
|
if (node.conn) {
|
|
|
|
var endpoints = node.conn.endpoints;
|
|
|
|
endpoints[0].detachFrom(endpoints[1]);
|
|
|
|
}
|
|
|
|
node.action = NodeActions.Fortify;
|
|
|
|
});
|
|
|
|
// if (this.selectedNode.conn) {
|
|
|
|
// var endpoints = this.selectedNode.conn.endpoints;
|
|
|
|
// endpoints[0].detachFrom(endpoints[1]);
|
|
|
|
// }
|
2017-09-26 04:44:33 +02:00
|
|
|
})
|
|
|
|
|
2017-09-21 23:27:31 +02:00
|
|
|
var timeDisplay = document.createElement("p");
|
|
|
|
|
|
|
|
container.appendChild(headerText);
|
|
|
|
container.appendChild(inGameGuideBtn);
|
|
|
|
container.appendChild(wikiGuideBtn);
|
|
|
|
container.appendChild(startBtn);
|
2017-09-27 17:13:42 +02:00
|
|
|
container.appendChild(forfeitMission);
|
2017-09-26 04:44:33 +02:00
|
|
|
container.appendChild(timer);
|
2017-09-21 23:27:31 +02:00
|
|
|
container.appendChild(actionsContainer);
|
|
|
|
container.appendChild(timeDisplay);
|
|
|
|
}
|
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
HackingMission.prototype.setActionButtonsInactive = function() {
|
|
|
|
for (var i = 0; i < this.actionButtons.length; ++i) {
|
|
|
|
this.actionButtons[i].classList.remove("a-link-button");
|
|
|
|
this.actionButtons[i].classList.add("a-link-button-inactive");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-03 05:19:49 +01:00
|
|
|
HackingMission.prototype.setActionButtonsActive = function(nodeType=null) {
|
2017-09-25 14:50:19 +02:00
|
|
|
for (var i = 0; i < this.actionButtons.length; ++i) {
|
|
|
|
this.actionButtons[i].classList.add("a-link-button");
|
|
|
|
this.actionButtons[i].classList.remove("a-link-button-inactive");
|
|
|
|
}
|
2017-12-03 05:19:49 +01:00
|
|
|
|
|
|
|
//For Transfer, FireWall and Shield Nodes, certain buttons should always be disabled
|
|
|
|
//0 = Attack, 1 = Scan, 2 = Weaken, 3 = Fortify, 4 = overflow, 5 = Drop conn
|
|
|
|
if (nodeType) {
|
|
|
|
switch (nodeType) {
|
|
|
|
case NodeTypes.Firewall:
|
|
|
|
case NodeTypes.Shield:
|
|
|
|
this.actionButtons[0].classList.remove("a-link-button");
|
|
|
|
this.actionButtons[0].classList.add("a-link-button-inactive");
|
|
|
|
this.actionButtons[1].classList.remove("a-link-button");
|
|
|
|
this.actionButtons[1].classList.add("a-link-button-inactive");
|
|
|
|
this.actionButtons[2].classList.remove("a-link-button");
|
|
|
|
this.actionButtons[2].classList.add("a-link-button-inactive");
|
|
|
|
this.actionButtons[4].classList.remove("a-link-button");
|
|
|
|
this.actionButtons[4].classList.add("a-link-button-inactive");
|
|
|
|
this.actionButtons[5].classList.remove("a-link-button");
|
|
|
|
this.actionButtons[5].classList.add("a-link-button-inactive");
|
|
|
|
break;
|
|
|
|
case NodeTypes.Transfer:
|
|
|
|
this.actionButtons[0].classList.remove("a-link-button");
|
|
|
|
this.actionButtons[0].classList.add("a-link-button-inactive");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//True for active, false for inactive
|
|
|
|
HackingMission.prototype.setActionButton = function(i, active=true) {
|
|
|
|
if (isString(i)) {
|
|
|
|
switch (i) {
|
|
|
|
case NodeActions.Attack:
|
|
|
|
i = 0;
|
|
|
|
break;
|
|
|
|
case NodeActions.Scan:
|
|
|
|
i = 1;
|
|
|
|
break;
|
|
|
|
case NodeActions.Weaken:
|
|
|
|
i = 2;
|
|
|
|
break;
|
|
|
|
case NodeActions.Fortify:
|
|
|
|
i = 3;
|
|
|
|
break;
|
|
|
|
case NodeActions.Overflow:
|
|
|
|
default:
|
|
|
|
i = 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (active) {
|
|
|
|
this.actionButtons[i].classList.remove("a-link-button-inactive");
|
|
|
|
this.actionButtons[i].classList.add("a-link-button");
|
|
|
|
} else {
|
|
|
|
this.actionButtons[i].classList.remove("a-link-button");
|
|
|
|
this.actionButtons[i].classList.add("a-link-button-inactive");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-09-27 17:13:42 +02:00
|
|
|
HackingMission.prototype.calculateAttacks = function() {
|
|
|
|
var total = 0;
|
|
|
|
for (var i = 0; i < this.playerCores.length; ++i) {
|
|
|
|
total += this.playerCores[i].atk;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < this.playerNodes.length; ++i) {
|
|
|
|
total += this.playerNodes[i].atk;
|
|
|
|
}
|
|
|
|
this.playerAtk = total;
|
|
|
|
document.getElementById("hacking-mission-player-stats").innerHTML =
|
|
|
|
"Player Attack: " + formatNumber(this.playerAtk, 1) + "<br>" +
|
|
|
|
"Player Defense: " + formatNumber(this.playerDef, 1);
|
|
|
|
total = 0;
|
|
|
|
for (var i = 0; i < this.enemyCores.length; ++i) {
|
|
|
|
total += this.enemyCores[i].atk;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < this.enemyDatabases.length; ++i) {
|
|
|
|
total += this.enemyDatabases[i].atk;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < this.enemyNodes.length; ++i) {
|
|
|
|
total += this.enemyNodes[i].atk;
|
|
|
|
}
|
|
|
|
this.enemyAtk = total;
|
|
|
|
document.getElementById("hacking-mission-enemy-stats").innerHTML =
|
|
|
|
"Enemy Attack: " + formatNumber(this.enemyAtk, 1) + "<br>" +
|
|
|
|
"Enemy Defense: " + formatNumber(this.enemyDef, 1);
|
|
|
|
}
|
|
|
|
|
2017-09-21 23:27:31 +02:00
|
|
|
HackingMission.prototype.calculateDefenses = function() {
|
|
|
|
var total = 0;
|
|
|
|
for (var i = 0; i < this.playerCores.length; ++i) {
|
|
|
|
total += this.playerCores[i].def;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < this.playerNodes.length; ++i) {
|
|
|
|
total += this.playerNodes[i].def;
|
|
|
|
}
|
|
|
|
this.playerDef = total;
|
2017-09-27 17:13:42 +02:00
|
|
|
document.getElementById("hacking-mission-player-stats").innerHTML =
|
|
|
|
"Player Attack: " + formatNumber(this.playerAtk, 1) + "<br>" +
|
2017-09-26 04:44:33 +02:00
|
|
|
"Player Defense: " + formatNumber(this.playerDef, 1);
|
2017-09-21 23:27:31 +02:00
|
|
|
total = 0;
|
|
|
|
for (var i = 0; i < this.enemyCores.length; ++i) {
|
|
|
|
total += this.enemyCores[i].def;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < this.enemyDatabases.length; ++i) {
|
|
|
|
total += this.enemyDatabases[i].def;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < this.enemyNodes.length; ++i) {
|
|
|
|
total += this.enemyNodes[i].def;
|
|
|
|
}
|
|
|
|
this.enemyDef = total;
|
2017-09-27 17:13:42 +02:00
|
|
|
document.getElementById("hacking-mission-enemy-stats").innerHTML =
|
|
|
|
"Enemy Attack: " + formatNumber(this.enemyAtk, 1) + "<br>" +
|
2017-09-26 04:44:33 +02:00
|
|
|
"Enemy Defense: " + formatNumber(this.enemyDef, 1);
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HackingMission.prototype.removeAvailablePosition = function(x, y) {
|
|
|
|
for (var i = 0; i < this.availablePositions.length; ++i) {
|
|
|
|
if (this.availablePositions[i][0] === x &&
|
|
|
|
this.availablePositions[i][1] === y) {
|
|
|
|
this.availablePositions.splice(i, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log("WARNING: removeAvailablePosition() did not remove " + x + ", " + y);
|
|
|
|
}
|
|
|
|
|
|
|
|
HackingMission.prototype.setNodePosition = function(nodeObj, x, y) {
|
|
|
|
if (!(nodeObj instanceof Node)) {
|
|
|
|
console.log("WARNING: Non-Node object passed into setNodePOsition");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isNaN(x) || isNaN(y)) {
|
|
|
|
console.log("ERR: Invalid values passed as x and y for setNodePosition");
|
|
|
|
console.log(x);
|
|
|
|
console.log(y);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nodeObj.pos = [x, y];
|
|
|
|
this.map[x][y] = nodeObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
HackingMission.prototype.setNodeRandomPosition = function(nodeObj, xlimit=0) {
|
|
|
|
var i = getRandomInt(0, this.availablePositions.length - 1);
|
2017-10-04 03:50:13 +02:00
|
|
|
if (this.availablePositions[i][1] < xlimit) {
|
|
|
|
//Recurse if not within limit
|
|
|
|
return this.setNodeRandomPosition(nodeObj, xlimit);
|
|
|
|
}
|
2017-09-21 23:27:31 +02:00
|
|
|
var pos = this.availablePositions.splice(i, 1);
|
|
|
|
pos = pos[0];
|
|
|
|
this.setNodePosition(nodeObj, pos[0], pos[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
HackingMission.prototype.createMap = function() {
|
|
|
|
//Use a grid
|
|
|
|
var map = document.createElement("div");
|
|
|
|
map.classList.add("hack-mission-grid");
|
|
|
|
map.setAttribute("id", "hacking-mission-map");
|
|
|
|
document.getElementById("mission-container").appendChild(map);
|
|
|
|
|
|
|
|
//Create random Nodes for every space in the map that
|
2017-10-10 06:56:48 +02:00
|
|
|
//hasn't been filled yet. The stats of each Node will be based on
|
|
|
|
//the player/enemy attack
|
|
|
|
var averageAttack = (this.playerAtk + this.enemyAtk) / 2;
|
2017-09-21 23:27:31 +02:00
|
|
|
for (var x = 0; x < 8; ++x) {
|
|
|
|
for (var y = 0; y < 8; ++y) {
|
|
|
|
if (!(this.map[x][y] instanceof Node)) {
|
|
|
|
var node, type = getRandomInt(0, 2);
|
2017-10-10 06:56:48 +02:00
|
|
|
var randMult = addOffset(0.85 + (this.difficulty / 2), 15);
|
2017-09-21 23:27:31 +02:00
|
|
|
switch (type) {
|
|
|
|
case 0: //Spam
|
|
|
|
var stats = {
|
|
|
|
atk: 0,
|
2017-12-07 04:45:47 +01:00
|
|
|
def: averageAttack * 1.1 + getRandomInt(15, 45),
|
2017-10-15 03:55:41 +02:00
|
|
|
hp: randMult * getRandomInt(200, 225)
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
node = new Node(NodeTypes.Spam, stats);
|
|
|
|
break;
|
|
|
|
case 1: //Transfer
|
|
|
|
var stats = {
|
|
|
|
atk: 0,
|
2017-12-07 04:45:47 +01:00
|
|
|
def: averageAttack * 1.1 + getRandomInt(15, 45),
|
2017-10-15 03:55:41 +02:00
|
|
|
hp: randMult * getRandomInt(250, 275)
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
node = new Node(NodeTypes.Transfer, stats);
|
|
|
|
break;
|
|
|
|
case 2: //Shield
|
|
|
|
default:
|
|
|
|
var stats = {
|
|
|
|
atk: 0,
|
2017-12-07 04:45:47 +01:00
|
|
|
def: averageAttack * 1.1 + getRandomInt(30, 70),
|
2017-10-15 03:55:41 +02:00
|
|
|
hp: randMult * getRandomInt(300, 320)
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
node = new Node(NodeTypes.Shield, stats);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.setNodePosition(node, x, y);
|
|
|
|
this.removeAvailablePosition(x, y);
|
|
|
|
this.miscNodes.push(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Create DOM elements in order
|
|
|
|
for (var r = 0; r < 8; ++r) {
|
|
|
|
for (var c = 0; c < 8; ++c) {
|
|
|
|
this.createNodeDomElement(this.map[r][c]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Configure all Player CPUS
|
|
|
|
for (var i = 0; i < this.playerCores.length; ++i) {
|
|
|
|
console.log("Configuring Player Node: " + this.playerCores[i].el.id);
|
|
|
|
this.configurePlayerNodeElement(this.playerCores[i].el);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HackingMission.prototype.createNodeDomElement = function(nodeObj) {
|
2017-10-15 03:55:41 +02:00
|
|
|
var nodeDiv = document.createElement("a"), txtEl = document.createElement('p');
|
2017-09-21 23:27:31 +02:00
|
|
|
nodeObj.el = nodeDiv;
|
|
|
|
|
|
|
|
//Set the node element's id based on its coordinates
|
2017-10-15 03:55:41 +02:00
|
|
|
var id = "hacking-mission-node-" + nodeObj.pos[0] + "-" + nodeObj.pos[1];
|
|
|
|
nodeDiv.setAttribute("id", id);
|
|
|
|
txtEl.setAttribute("id", id + "-txt");
|
2017-09-21 23:27:31 +02:00
|
|
|
|
|
|
|
//Set node classes for owner
|
|
|
|
nodeDiv.classList.add("hack-mission-node");
|
|
|
|
if (nodeObj.plyrCtrl) {
|
|
|
|
nodeDiv.classList.add("hack-mission-player-node");
|
|
|
|
} else if (nodeObj.enmyCtrl) {
|
|
|
|
nodeDiv.classList.add("hack-mission-enemy-node");
|
|
|
|
}
|
|
|
|
|
|
|
|
//Set node classes based on type
|
2017-09-25 14:50:19 +02:00
|
|
|
var txt;
|
2017-09-21 23:27:31 +02:00
|
|
|
switch (nodeObj.type) {
|
|
|
|
case NodeTypes.Core:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "CPU Core<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
2017-09-21 23:27:31 +02:00
|
|
|
nodeDiv.classList.add("hack-mission-cpu-node");
|
|
|
|
break;
|
|
|
|
case NodeTypes.Firewall:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "Firewall<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
2017-09-21 23:27:31 +02:00
|
|
|
nodeDiv.classList.add("hack-mission-firewall-node");
|
|
|
|
break;
|
|
|
|
case NodeTypes.Database:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "Database<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
2017-09-21 23:27:31 +02:00
|
|
|
nodeDiv.classList.add("hack-mission-database-node");
|
|
|
|
break;
|
|
|
|
case NodeTypes.Spam:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "Spam<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
2017-09-21 23:27:31 +02:00
|
|
|
nodeDiv.classList.add("hack-mission-spam-node");
|
|
|
|
break;
|
|
|
|
case NodeTypes.Transfer:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "Transfer<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
2017-09-21 23:27:31 +02:00
|
|
|
nodeDiv.classList.add("hack-mission-transfer-node");
|
|
|
|
break;
|
|
|
|
case NodeTypes.Shield:
|
|
|
|
default:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "Shield<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
2017-09-21 23:27:31 +02:00
|
|
|
nodeDiv.classList.add("hack-mission-shield-node");
|
|
|
|
break;
|
|
|
|
}
|
2017-09-25 14:50:19 +02:00
|
|
|
|
|
|
|
txt += "<br>Atk: " + formatNumber(nodeObj.atk, 1) +
|
2017-10-15 03:55:41 +02:00
|
|
|
"<br>Def: " + formatNumber(nodeObj.def, 1);
|
|
|
|
txtEl.innerHTML = txt;
|
|
|
|
|
|
|
|
nodeDiv.appendChild(txtEl);
|
|
|
|
document.getElementById("hacking-mission-map").appendChild(nodeDiv);
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HackingMission.prototype.updateNodeDomElement = function(nodeObj) {
|
2017-10-26 00:05:12 +02:00
|
|
|
if (nodeObj.el == null) {
|
2017-09-25 14:50:19 +02:00
|
|
|
console.log("ERR: Calling updateNodeDomElement on a Node without an element");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-15 03:55:41 +02:00
|
|
|
var id = "hacking-mission-node-" + nodeObj.pos[0] + "-" + nodeObj.pos[1];
|
|
|
|
var nodeDiv = document.getElementById(id), txtEl = document.getElementById(id + "-txt");
|
2017-09-25 14:50:19 +02:00
|
|
|
|
|
|
|
//Set node classes based on type
|
|
|
|
var txt;
|
|
|
|
switch (nodeObj.type) {
|
|
|
|
case NodeTypes.Core:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "CPU Core<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
|
|
|
break;
|
|
|
|
case NodeTypes.Firewall:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "Firewall<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
|
|
|
break;
|
|
|
|
case NodeTypes.Database:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "Database<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
|
|
|
break;
|
|
|
|
case NodeTypes.Spam:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "Spam<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
|
|
|
break;
|
|
|
|
case NodeTypes.Transfer:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "Transfer<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
|
|
|
break;
|
|
|
|
case NodeTypes.Shield:
|
|
|
|
default:
|
2017-10-15 03:55:41 +02:00
|
|
|
txt = "Shield<br>" + "HP: " +
|
2017-09-25 14:50:19 +02:00
|
|
|
formatNumber(nodeObj.hp, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
txt += "<br>Atk: " + formatNumber(nodeObj.atk, 1) +
|
|
|
|
"<br>Def: " + formatNumber(nodeObj.def, 1);
|
|
|
|
if (nodeObj.action) {
|
|
|
|
txt += "<br>" + nodeObj.action;
|
|
|
|
}
|
2017-10-15 03:55:41 +02:00
|
|
|
txtEl.innerHTML = txt;
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Gets a Node DOM element's corresponding Node object using its
|
2017-10-02 04:35:22 +02:00
|
|
|
//element id. Function accepts either the DOM element object or the ID as
|
|
|
|
//an argument
|
2017-09-21 23:27:31 +02:00
|
|
|
HackingMission.prototype.getNodeFromElement = function(el) {
|
2017-10-02 04:35:22 +02:00
|
|
|
var id;
|
|
|
|
if (isString(el)) {
|
|
|
|
id = el;
|
|
|
|
} else {
|
|
|
|
id = el.id;
|
|
|
|
}
|
2017-09-21 23:27:31 +02:00
|
|
|
id = id.replace("hacking-mission-node-", "");
|
|
|
|
var res = id.split('-');
|
|
|
|
if (res.length != 2) {
|
|
|
|
console.log("ERROR Parsing Hacking Mission Node Id. Could not find coordinates");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var x = res[0], y = res[1];
|
|
|
|
if (isNaN(x) || isNaN(y) || x >= 8 || y >= 8 || x < 0 || y < 0) {
|
|
|
|
console.log("ERROR: Unexpected values for x and y: " + x + ", " + y);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return this.map[x][y];
|
|
|
|
}
|
|
|
|
|
2017-10-13 17:19:42 +02:00
|
|
|
function selectNode(hackMissionInst, el) {
|
|
|
|
var nodeObj = hackMissionInst.getNodeFromElement(el);
|
2017-10-26 00:05:12 +02:00
|
|
|
if (nodeObj == null) {console.log("Error getting Node object");}
|
2017-10-13 17:19:42 +02:00
|
|
|
if (!nodeObj.plyrCtrl) {return;}
|
|
|
|
|
2017-12-07 04:45:47 +01:00
|
|
|
clearAllSelectedNodes(hackMissionInst);
|
2017-10-13 17:19:42 +02:00
|
|
|
nodeObj.select(hackMissionInst.actionButtons);
|
2017-12-07 04:45:47 +01:00
|
|
|
hackMissionInst.selectedNode.push(nodeObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
function multiselectNode(hackMissionInst, el) {
|
|
|
|
var nodeObj = hackMissionInst.getNodeFromElement(el);
|
|
|
|
if (nodeObj == null) {console.log("ERROR: Getting Node Object in multiselectNode()");}
|
|
|
|
if (!nodeObj.plyrCtrl) {return;}
|
|
|
|
|
|
|
|
clearAllSelectedNodes(hackMissionInst);
|
|
|
|
var type = nodeObj.type;
|
|
|
|
if (type === NodeTypes.Core) {
|
|
|
|
hackMissionInst.playerCores.forEach(function(node) {
|
|
|
|
node.select(hackMissionInst.actionButtons);
|
|
|
|
hackMissionInst.selectedNode.push(node);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
hackMissionInst.playerNodes.forEach(function(node) {
|
|
|
|
if (node.type === type) {
|
|
|
|
node.select(hackMissionInst.actionButtons);
|
|
|
|
hackMissionInst.selectedNode.push(node);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearAllSelectedNodes(hackMissionInst) {
|
|
|
|
if (hackMissionInst.selectedNode.length > 0) {
|
|
|
|
hackMissionInst.selectedNode.forEach(function(node){
|
|
|
|
node.deselect(hackMissionInst.actionButtons);
|
|
|
|
});
|
|
|
|
hackMissionInst.selectedNode.length = 0;
|
|
|
|
}
|
2017-10-13 17:19:42 +02:00
|
|
|
}
|
|
|
|
|
2017-09-21 23:27:31 +02:00
|
|
|
//Configures a DOM element representing a player-owned node to
|
|
|
|
//be selectable and actionable
|
|
|
|
//Note: Does NOT change its css class. This is handled by Node.setControlledBy...
|
2017-10-15 03:55:41 +02:00
|
|
|
HackingMission.prototype.configurePlayerNodeElement = function(el) {
|
2017-09-21 23:27:31 +02:00
|
|
|
var nodeObj = this.getNodeFromElement(el);
|
2017-10-26 00:05:12 +02:00
|
|
|
if (nodeObj == null) {console.log("Error getting Node object");}
|
2017-09-21 23:27:31 +02:00
|
|
|
|
|
|
|
//Add event listener
|
2017-10-15 03:55:41 +02:00
|
|
|
var self = this;
|
2017-10-13 17:19:42 +02:00
|
|
|
function selectNodeWrapper() {
|
2017-10-15 03:55:41 +02:00
|
|
|
selectNode(self, el);
|
2017-10-13 17:19:42 +02:00
|
|
|
}
|
2017-10-15 03:55:41 +02:00
|
|
|
el.addEventListener("click", selectNodeWrapper);
|
2017-10-13 17:19:42 +02:00
|
|
|
|
2017-12-07 04:45:47 +01:00
|
|
|
function multiselectNodeWrapper() {
|
|
|
|
multiselectNode(self, el);
|
|
|
|
}
|
|
|
|
el.addEventListener("dblclick", multiselectNodeWrapper);
|
|
|
|
|
|
|
|
|
2017-10-13 17:19:42 +02:00
|
|
|
if (el.firstChild) {
|
|
|
|
el.firstChild.addEventListener("click", selectNodeWrapper);
|
|
|
|
}
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Configures a DOM element representing an enemy-node by removing
|
|
|
|
//any event listeners
|
|
|
|
HackingMission.prototype.configureEnemyNodeElement = function(el) {
|
|
|
|
//Deselect node if it was the selected node
|
|
|
|
var nodeObj = this.getNodeFromElement(el);
|
2017-12-07 04:45:47 +01:00
|
|
|
for (var i = 0; i < this.selectedNode.length; ++i) {
|
|
|
|
if (this.selectedNode[i] == nodeObj) {
|
|
|
|
nodeObj.deselect(this.actionButtons);
|
|
|
|
this.selectedNode.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
//Returns bool indicating whether a node is reachable by player
|
|
|
|
//by checking if any of the adjacent nodes are owned by the player
|
|
|
|
HackingMission.prototype.nodeReachable = function(node) {
|
|
|
|
var x = node.pos[0], y = node.pos[1];
|
|
|
|
if (x > 0 && this.map[x-1][y].plyrCtrl) {return true;}
|
|
|
|
if (x < 7 && this.map[x+1][y].plyrCtrl) {return true;}
|
|
|
|
if (y > 0 && this.map[x][y-1].plyrCtrl) {return true;}
|
|
|
|
if (y < 7 && this.map[x][y+1].plyrCtrl) {return true;}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-29 17:02:33 +02:00
|
|
|
HackingMission.prototype.nodeReachableByEnemy = function(node) {
|
2017-10-26 00:05:12 +02:00
|
|
|
if (node == null) {return false;}
|
2017-09-29 17:02:33 +02:00
|
|
|
var x = node.pos[0], y = node.pos[1];
|
|
|
|
if (x > 0 && this.map[x-1][y].enmyCtrl) {return true;}
|
|
|
|
if (x < 7 && this.map[x+1][y].enmyCtrl) {return true;}
|
|
|
|
if (y > 0 && this.map[x][y-1].enmyCtrl) {return true;}
|
|
|
|
if (y < 7 && this.map[x][y+1].enmyCtrl) {return true;}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-26 04:44:33 +02:00
|
|
|
HackingMission.prototype.start = function() {
|
|
|
|
this.started = true;
|
|
|
|
this.initJsPlumb();
|
|
|
|
var startBtn = clearEventListeners("hack-mission-start-btn");
|
2017-09-27 17:13:42 +02:00
|
|
|
startBtn.classList.remove("a-link-button");
|
|
|
|
startBtn.classList.add("a-link-button-inactive");
|
2017-09-26 04:44:33 +02:00
|
|
|
}
|
|
|
|
|
2017-09-21 23:27:31 +02:00
|
|
|
HackingMission.prototype.initJsPlumb = function() {
|
|
|
|
var instance = jsPlumb.getInstance({
|
|
|
|
DragOptions:{cursor:"pointer", zIndex:2000},
|
|
|
|
PaintStyle: {
|
|
|
|
gradient: { stops: [
|
|
|
|
[ 0, "#FFFFFF" ],
|
|
|
|
[ 1, "#FFFFFF" ]
|
|
|
|
] },
|
|
|
|
stroke: "#FFFFFF",
|
2017-09-25 14:50:19 +02:00
|
|
|
strokeWidth: 8
|
2017-09-21 23:27:31 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
this.jsplumbinstance = instance;
|
|
|
|
|
2017-09-21 23:27:31 +02:00
|
|
|
//All player cores are sources
|
|
|
|
for (var i = 0; i < this.playerCores.length; ++i) {
|
|
|
|
instance.makeSource(this.playerCores[i].el, {
|
|
|
|
deleteEndpointsOnEmpty:true,
|
|
|
|
maxConnections:1,
|
2017-09-27 17:13:42 +02:00
|
|
|
anchor:"Continuous",
|
|
|
|
connector:"Flowchart"
|
2017-09-21 23:27:31 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//Everything else is a target
|
|
|
|
for (var i = 0; i < this.enemyCores.length; ++i) {
|
|
|
|
instance.makeTarget(this.enemyCores[i].el, {
|
|
|
|
maxConnections:-1,
|
2017-09-27 17:13:42 +02:00
|
|
|
anchor:"Continuous",
|
|
|
|
connector:"Flowchart"
|
2017-09-21 23:27:31 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
for (var i = 0; i < this.enemyDatabases.length; ++i) {
|
|
|
|
instance.makeTarget(this.enemyDatabases[i].el, {
|
|
|
|
maxConnections:-1,
|
2017-09-27 17:13:42 +02:00
|
|
|
anchor:"Continuous",
|
|
|
|
connector:["Flowchart"]
|
2017-09-21 23:27:31 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
for (var i = 0; i < this.enemyNodes.length; ++i) {
|
|
|
|
instance.makeTarget(this.enemyNodes[i].el, {
|
|
|
|
maxConnections:-1,
|
2017-09-27 17:13:42 +02:00
|
|
|
anchor:"Continuous",
|
|
|
|
connector:"Flowchart"
|
2017-09-21 23:27:31 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
for (var i = 0; i < this.miscNodes.length; ++i) {
|
|
|
|
instance.makeTarget(this.miscNodes[i].el, {
|
|
|
|
maxConnections:-1,
|
2017-09-27 17:13:42 +02:00
|
|
|
anchor:"Continuous",
|
|
|
|
connector:"Flowchart"
|
2017-09-21 23:27:31 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//Clicking a connection drops it
|
|
|
|
instance.bind("click", function(conn, originalEvent) {
|
|
|
|
var endpoints = conn.endpoints;
|
|
|
|
endpoints[0].detachFrom(endpoints[1]);
|
|
|
|
});
|
2017-09-25 14:50:19 +02:00
|
|
|
|
|
|
|
//Connection events
|
|
|
|
instance.bind("connection", (info)=>{
|
|
|
|
var targetNode = this.getNodeFromElement(info.target);
|
|
|
|
|
2017-10-02 05:27:42 +02:00
|
|
|
//Do not detach for enemy nodes
|
|
|
|
var thisNode = this.getNodeFromElement(info.source);
|
|
|
|
if (thisNode.enmyCtrl) {return;}
|
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
//If the node is not reachable, drop the connection
|
|
|
|
if (!this.nodeReachable(targetNode)) {
|
|
|
|
info.sourceEndpoint.detachFrom(info.targetEndpoint);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var sourceNode = this.getNodeFromElement(info.source);
|
|
|
|
sourceNode.conn = info.connection;
|
2017-10-10 06:56:48 +02:00
|
|
|
var targetNode = this.getNodeFromElement(info.target);
|
|
|
|
++targetNode.targetedCount;
|
2017-09-25 14:50:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
//Detach Connection events
|
|
|
|
instance.bind("connectionDetached", (info, originalEvent)=>{
|
|
|
|
var sourceNode = this.getNodeFromElement(info.source);
|
|
|
|
sourceNode.conn = null;
|
2017-10-10 06:56:48 +02:00
|
|
|
var targetNode = this.getNodeFromElement(info.target);
|
|
|
|
targetNode.untarget();
|
2017-09-25 14:50:19 +02:00
|
|
|
});
|
2017-10-02 04:35:22 +02:00
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Drops all connections where the specified node is the source
|
|
|
|
HackingMission.prototype.dropAllConnectionsFromNode = function(node) {
|
|
|
|
var allConns = this.jsplumbinstance.getAllConnections();
|
|
|
|
for (var i = allConns.length-1; i >= 0; --i) {
|
|
|
|
if (allConns[i].source == node.el) {
|
|
|
|
allConns[i].endpoints[0].detachFrom(allConns[i].endpoints[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Drops all connections where the specified node is the target
|
|
|
|
HackingMission.prototype.dropAllConnectionsToNode = function(node) {
|
|
|
|
var allConns = this.jsplumbinstance.getAllConnections();
|
|
|
|
for (var i = allConns.length-1; i >= 0; --i) {
|
|
|
|
if (allConns[i].target == node.el) {
|
|
|
|
allConns[i].endpoints[0].detachFrom(allConns[i].endpoints[1]);
|
|
|
|
}
|
|
|
|
}
|
2017-10-10 06:56:48 +02:00
|
|
|
node.beingTargeted = false;
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
|
2017-09-27 17:13:42 +02:00
|
|
|
var storedCycles = 0;
|
2017-09-25 14:50:19 +02:00
|
|
|
HackingMission.prototype.process = function(numCycles=1) {
|
2017-09-26 04:44:33 +02:00
|
|
|
if (!this.started) {return;}
|
2017-09-27 17:13:42 +02:00
|
|
|
storedCycles += numCycles;
|
2017-10-10 06:56:48 +02:00
|
|
|
if (storedCycles < 2) {return;} //Only process every 3 cycles minimum
|
2017-09-27 17:13:42 +02:00
|
|
|
|
2017-09-26 04:44:33 +02:00
|
|
|
var res = false;
|
2017-09-25 14:50:19 +02:00
|
|
|
//Process actions of all player nodes
|
2017-09-26 04:44:33 +02:00
|
|
|
this.playerCores.forEach((node)=>{
|
2017-09-27 17:13:42 +02:00
|
|
|
res |= this.processNode(node, storedCycles);
|
2017-09-26 04:44:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.playerNodes.forEach((node)=>{
|
2017-12-03 05:19:49 +01:00
|
|
|
if (node.type === NodeTypes.Transfer ||
|
|
|
|
node.type === NodeTypes.Shield ||
|
|
|
|
node.type === NodeTypes.Firewall) {
|
2017-09-27 17:13:42 +02:00
|
|
|
res |= this.processNode(node, storedCycles);
|
2017-09-26 04:44:33 +02:00
|
|
|
}
|
|
|
|
});
|
2017-09-25 14:50:19 +02:00
|
|
|
|
|
|
|
//Process actions of all enemy nodes
|
2017-09-26 04:44:33 +02:00
|
|
|
this.enemyCores.forEach((node)=>{
|
2017-10-02 04:35:22 +02:00
|
|
|
this.enemyAISelectAction(node);
|
2017-09-27 17:13:42 +02:00
|
|
|
res |= this.processNode(node, storedCycles);
|
2017-09-26 04:44:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.enemyNodes.forEach((node)=>{
|
2017-12-03 05:19:49 +01:00
|
|
|
if (node.type === NodeTypes.Transfer ||
|
|
|
|
node.type === NodeTypes.Shield ||
|
|
|
|
node.type === NodeTypes.Firewall) {
|
2017-10-02 04:35:22 +02:00
|
|
|
this.enemyAISelectAction(node);
|
2017-09-27 17:13:42 +02:00
|
|
|
res |= this.processNode(node, storedCycles);
|
2017-09-26 04:44:33 +02:00
|
|
|
}
|
|
|
|
});
|
2017-09-25 14:50:19 +02:00
|
|
|
|
2017-10-10 06:56:48 +02:00
|
|
|
//The hp of enemy databases increases slowly
|
|
|
|
this.enemyDatabases.forEach((node)=>{
|
|
|
|
node.maxhp += (0.1 * storedCycles);
|
|
|
|
node.hp += (0.1 * storedCycles);
|
|
|
|
});
|
|
|
|
|
2017-09-27 17:13:42 +02:00
|
|
|
if (res) {
|
|
|
|
this.calculateAttacks();
|
|
|
|
this.calculateDefenses();
|
|
|
|
}
|
2017-09-25 14:50:19 +02:00
|
|
|
|
2017-10-04 03:50:13 +02:00
|
|
|
//Win if all enemy databases are conquered
|
2017-09-26 04:44:33 +02:00
|
|
|
if (this.enemyDatabases.length === 0) {
|
|
|
|
this.finishMission(true);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-25 14:50:19 +02:00
|
|
|
|
2017-10-04 03:50:13 +02:00
|
|
|
//Lose if all your cores are gone
|
|
|
|
if (this.playerCores.length === 0) {
|
|
|
|
this.finishMission(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-10 06:56:48 +02:00
|
|
|
//Defense/hp of misc nodes increases slowly over time
|
2017-09-27 17:13:42 +02:00
|
|
|
this.miscNodes.forEach((node)=>{
|
|
|
|
node.def += (0.1 * storedCycles);
|
2017-10-10 06:56:48 +02:00
|
|
|
node.maxhp += (0.05 * storedCycles);
|
|
|
|
node.hp += (0.1 * storedCycles);
|
|
|
|
if (node.hp > node.maxhp) {node.hp = node.maxhp;}
|
2017-09-27 17:13:42 +02:00
|
|
|
this.updateNodeDomElement(node);
|
|
|
|
});
|
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
//Update timer and check if player lost
|
2017-09-27 17:13:42 +02:00
|
|
|
this.time -= (storedCycles * Engine._idleSpeed);
|
2017-09-25 14:50:19 +02:00
|
|
|
if (this.time <= 0) {
|
|
|
|
this.finishMission(false);
|
2017-09-26 04:44:33 +02:00
|
|
|
return;
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
2017-09-26 04:44:33 +02:00
|
|
|
this.updateTimer();
|
2017-09-27 17:13:42 +02:00
|
|
|
|
|
|
|
storedCycles = 0;
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Returns a bool representing whether defenses need to be re-calculated
|
|
|
|
HackingMission.prototype.processNode = function(nodeObj, numCycles=1) {
|
2017-10-26 00:05:12 +02:00
|
|
|
if (nodeObj.action == null) {
|
2017-09-26 04:44:33 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-09-25 14:50:19 +02:00
|
|
|
|
2017-09-27 17:13:42 +02:00
|
|
|
var targetNode = null, def, atk;
|
2017-09-25 14:50:19 +02:00
|
|
|
if (nodeObj.conn) {
|
2017-10-02 04:35:22 +02:00
|
|
|
var targetNode;
|
|
|
|
if (nodeObj.conn.target) {
|
|
|
|
targetNode = this.getNodeFromElement(nodeObj.conn.target);
|
|
|
|
} else {
|
|
|
|
targetNode = this.getNodeFromElement(nodeObj.conn.targetId);
|
|
|
|
}
|
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
if (targetNode.plyrCtrl) {
|
|
|
|
def = this.playerDef;
|
2017-09-27 17:13:42 +02:00
|
|
|
atk = this.enemyAtk;
|
2017-09-25 14:50:19 +02:00
|
|
|
} else if (targetNode.enmyCtrl) {
|
|
|
|
def = this.enemyDef;
|
2017-09-27 17:13:42 +02:00
|
|
|
atk = this.playerAtk;
|
2017-09-25 14:50:19 +02:00
|
|
|
} else { //Misc Node
|
|
|
|
def = targetNode.def;
|
2017-09-27 17:13:42 +02:00
|
|
|
nodeObj.plyrCtrl ? atk = this.playerAtk : atk = this.enemyAtk;
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Calculations are per second, so divide everything by 5
|
2017-10-04 03:50:13 +02:00
|
|
|
var calcStats = false, plyr = nodeObj.plyrCtrl;
|
|
|
|
var enmyHacking = this.difficulty * CONSTANTS.HackingMissionDifficultyToHacking;
|
2017-09-25 14:50:19 +02:00
|
|
|
switch(nodeObj.action) {
|
|
|
|
case NodeActions.Attack:
|
2017-10-26 00:05:12 +02:00
|
|
|
if (nodeObj.conn == null) {break;}
|
2017-10-04 03:50:13 +02:00
|
|
|
var dmg = this.calculateAttackDamage(atk, def, plyr ? Player.hacking_skill : enmyHacking);
|
2017-09-25 14:50:19 +02:00
|
|
|
targetNode.hp -= (dmg/5 * numCycles);
|
|
|
|
break;
|
|
|
|
case NodeActions.Scan:
|
2017-10-26 00:05:12 +02:00
|
|
|
if (nodeObj.conn == null) {break;}
|
2017-10-04 03:50:13 +02:00
|
|
|
var eff = this.calculateScanEffect(atk, def, plyr ? Player.hacking_skill : enmyHacking);
|
2017-09-25 14:50:19 +02:00
|
|
|
targetNode.def -= (eff/5 * numCycles);
|
2017-09-27 17:13:42 +02:00
|
|
|
calcStats = true;
|
2017-09-25 14:50:19 +02:00
|
|
|
break;
|
|
|
|
case NodeActions.Weaken:
|
2017-10-26 00:05:12 +02:00
|
|
|
if (nodeObj.conn == null) {break;}
|
2017-10-04 03:50:13 +02:00
|
|
|
var eff = this.calculateWeakenEffect(atk, def, plyr ? Player.hacking_skill : enmyHacking);
|
2017-09-25 14:50:19 +02:00
|
|
|
targetNode.atk -= (eff/5 * numCycles);
|
2017-09-27 17:13:42 +02:00
|
|
|
calcStats = true;
|
2017-09-25 14:50:19 +02:00
|
|
|
break;
|
|
|
|
case NodeActions.Fortify:
|
|
|
|
var eff = this.calculateFortifyEffect(Player.hacking_skill);
|
|
|
|
nodeObj.def += (eff/5 * numCycles);
|
2017-09-27 17:13:42 +02:00
|
|
|
calcStats = true;
|
2017-09-25 14:50:19 +02:00
|
|
|
break;
|
|
|
|
case NodeActions.Overflow:
|
|
|
|
var eff = this.calculateOverflowEffect(Player.hacking_skill);
|
|
|
|
if (nodeObj.def < eff) {break;}
|
|
|
|
nodeObj.def -= (eff/5 * numCycles);
|
|
|
|
nodeObj.atk += (eff/5 * numCycles);
|
2017-09-27 17:13:42 +02:00
|
|
|
calcStats = true;
|
2017-09-25 14:50:19 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log("ERR: Invalid Node Action: " + nodeObj.action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Stats can't go below 0
|
|
|
|
if (nodeObj.atk < 0) {nodeObj.atk = 0;}
|
|
|
|
if (nodeObj.def < 0) {nodeObj.def = 0;}
|
|
|
|
if (targetNode && targetNode.atk < 0) {targetNode.atk = 0;}
|
|
|
|
if (targetNode && targetNode.def < 0) {targetNode.def = 0;}
|
|
|
|
|
|
|
|
//Conquering a node
|
|
|
|
if (targetNode && targetNode.hp <= 0) {
|
|
|
|
var conqueredByPlayer = nodeObj.plyrCtrl;
|
|
|
|
targetNode.hp = targetNode.maxhp;
|
|
|
|
targetNode.action = null;
|
|
|
|
targetNode.conn = null;
|
|
|
|
if (this.selectedNode == targetNode) {
|
2017-10-04 03:50:13 +02:00
|
|
|
targetNode.deselect(this.actionButtons);
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
2017-09-26 04:44:33 +02:00
|
|
|
|
2017-10-10 06:56:48 +02:00
|
|
|
//The conquered node has its stats reduced
|
2017-10-15 03:55:41 +02:00
|
|
|
targetNode.atk /= 2;
|
|
|
|
targetNode.def /= 3.5;
|
2017-10-10 06:56:48 +02:00
|
|
|
|
2017-09-26 04:44:33 +02:00
|
|
|
//Flag for whether the target node was a misc node
|
|
|
|
var isMiscNode = !targetNode.plyrCtrl && !targetNode.enmyCtrl;
|
|
|
|
|
|
|
|
//Remove all connections from Node
|
2017-09-25 14:50:19 +02:00
|
|
|
this.dropAllConnectionsToNode(targetNode);
|
|
|
|
this.dropAllConnectionsFromNode(targetNode);
|
2017-09-26 04:44:33 +02:00
|
|
|
|
|
|
|
//Changes the css class and turn the node into a JsPlumb Source/Target
|
2017-09-25 14:50:19 +02:00
|
|
|
if (conqueredByPlayer) {
|
2017-09-26 04:44:33 +02:00
|
|
|
targetNode.setControlledByPlayer();
|
|
|
|
this.jsplumbinstance.unmakeTarget(targetNode.el);
|
|
|
|
this.jsplumbinstance.makeSource(targetNode.el, {
|
|
|
|
deleteEndpointsOnEmpty:true,
|
|
|
|
maxConnections:1,
|
2017-09-27 17:13:42 +02:00
|
|
|
anchor:"Continuous",
|
|
|
|
connector:"Flowchart"
|
2017-09-26 04:44:33 +02:00
|
|
|
});
|
|
|
|
} else {
|
2017-09-25 14:50:19 +02:00
|
|
|
targetNode.setControlledByEnemy();
|
2017-10-02 04:35:22 +02:00
|
|
|
nodeObj.conn = null; //Clear connection
|
2017-09-26 04:44:33 +02:00
|
|
|
this.jsplumbinstance.unmakeSource(targetNode.el);
|
|
|
|
this.jsplumbinstance.makeTarget(targetNode.el, {
|
|
|
|
maxConnections:-1,
|
2017-09-27 17:13:42 +02:00
|
|
|
anchor:"Continuous",
|
|
|
|
connector:["Flowchart"]
|
2017-09-26 04:44:33 +02:00
|
|
|
});
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
2017-09-26 04:44:33 +02:00
|
|
|
|
2017-09-27 17:13:42 +02:00
|
|
|
calcStats = true;
|
2017-09-25 14:50:19 +02:00
|
|
|
|
2017-09-26 04:44:33 +02:00
|
|
|
//Helper function to swap nodes between the respective enemyNodes/playerNodes arrays
|
2017-09-25 14:50:19 +02:00
|
|
|
function swapNodes(orig, dest, targetNode) {
|
|
|
|
for (var i = 0; i < orig.length; ++i) {
|
|
|
|
if (orig[i] == targetNode) {
|
|
|
|
var node = orig.splice(i, 1);
|
2017-09-26 04:44:33 +02:00
|
|
|
node = node[0];
|
2017-09-25 14:50:19 +02:00
|
|
|
dest.push(node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(targetNode.type) {
|
|
|
|
case NodeTypes.Core:
|
|
|
|
if (conqueredByPlayer) {
|
|
|
|
swapNodes(this.enemyCores, this.playerCores, targetNode);
|
2017-09-26 04:44:33 +02:00
|
|
|
this.configurePlayerNodeElement(targetNode.el);
|
2017-09-25 14:50:19 +02:00
|
|
|
} else {
|
|
|
|
swapNodes(this.playerCores, this.enemyCores, targetNode);
|
2017-09-26 04:44:33 +02:00
|
|
|
this.configureEnemyNodeElement(targetNode.el);
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NodeTypes.Firewall:
|
|
|
|
if (conqueredByPlayer) {
|
|
|
|
swapNodes(this.enemyNodes, this.playerNodes, targetNode);
|
|
|
|
} else {
|
|
|
|
swapNodes(this.playerNodes, this.enemyNodes, targetNode);
|
2017-12-07 04:45:47 +01:00
|
|
|
this.configureEnemyNodeElement(targetNode.el);
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NodeTypes.Database:
|
2017-09-26 04:44:33 +02:00
|
|
|
if (conqueredByPlayer) {
|
|
|
|
swapNodes(this.enemyDatabases, this.playerNodes, targetNode);
|
|
|
|
} else {
|
|
|
|
swapNodes(this.playerNodes, this.enemyDatabases, targetNode);
|
|
|
|
}
|
2017-09-25 14:50:19 +02:00
|
|
|
break;
|
|
|
|
case NodeTypes.Spam:
|
2017-09-26 04:44:33 +02:00
|
|
|
if (conqueredByPlayer) {
|
|
|
|
swapNodes(isMiscNode ? this.miscNodes : this.enemyNodes, this.playerNodes, targetNode);
|
2017-10-02 04:35:22 +02:00
|
|
|
//Conquering spam node increases time limit
|
|
|
|
this.time += CONSTANTS.HackingMissionSpamTimeIncrease;
|
2017-09-26 04:44:33 +02:00
|
|
|
} else {
|
|
|
|
swapNodes(isMiscNode ? this.miscNodes : this.playerNodes, this.enemyNodes, targetNode);
|
|
|
|
}
|
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
break;
|
|
|
|
case NodeTypes.Transfer:
|
2017-09-26 04:44:33 +02:00
|
|
|
//Conquering a Transfer node increases the attack of all cores by some percentages
|
|
|
|
if (conqueredByPlayer) {
|
|
|
|
swapNodes(isMiscNode ? this.miscNodes : this.enemyNodes, this.playerNodes, targetNode);
|
|
|
|
this.playerCores.forEach(function(node) {
|
|
|
|
node.atk *= CONSTANTS.HackingMissionTransferAttackIncrease;
|
|
|
|
});
|
|
|
|
this.configurePlayerNodeElement(targetNode.el);
|
|
|
|
} else {
|
|
|
|
swapNodes(isMiscNode ? this.miscNodes : this.playerNodes, this.enemyNodes, targetNode);
|
|
|
|
this.enemyCores.forEach(function(node) {
|
|
|
|
node.atk *= CONSTANTS.HackingMissionTransferAttackIncrease;
|
|
|
|
});
|
|
|
|
this.configureEnemyNodeElement(targetNode.el);
|
|
|
|
}
|
2017-09-25 14:50:19 +02:00
|
|
|
break;
|
|
|
|
case NodeTypes.Shield:
|
2017-09-26 04:44:33 +02:00
|
|
|
if (conqueredByPlayer) {
|
|
|
|
swapNodes(isMiscNode ? this.miscNodes : this.enemyNodes, this.playerNodes, targetNode);
|
2017-12-03 05:19:49 +01:00
|
|
|
this.configurePlayerNodeElement(targetNode.el);
|
2017-09-26 04:44:33 +02:00
|
|
|
} else {
|
|
|
|
swapNodes(isMiscNode ? this.miscNodes : this.playerNodes, this.enemyNodes, targetNode);
|
2017-12-07 04:45:47 +01:00
|
|
|
this.configureEnemyNodeElement(targetNode.el);
|
2017-09-26 04:44:33 +02:00
|
|
|
}
|
2017-09-25 14:50:19 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-10-02 04:35:22 +02:00
|
|
|
|
|
|
|
//If a misc node was conquered, the defense for all misc nodes increases by some fixed amount
|
2017-10-10 06:56:48 +02:00
|
|
|
if (isMiscNode) { //&& conqueredByPlayer) {
|
2017-10-04 03:50:13 +02:00
|
|
|
this.miscNodes.forEach((node)=>{
|
2017-10-10 06:56:48 +02:00
|
|
|
if (node.targetedCount === 0) {
|
|
|
|
node.def *= CONSTANTS.HackingMissionMiscDefenseIncrease;
|
|
|
|
}
|
2017-10-04 03:50:13 +02:00
|
|
|
});
|
|
|
|
}
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
2017-10-02 04:35:22 +02:00
|
|
|
|
|
|
|
//Update node DOMs
|
2017-09-25 14:50:19 +02:00
|
|
|
this.updateNodeDomElement(nodeObj);
|
|
|
|
if (targetNode) {this.updateNodeDomElement(targetNode);}
|
2017-09-27 17:13:42 +02:00
|
|
|
return calcStats;
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 06:56:48 +02:00
|
|
|
//Enemy "AI" for CPU Core and Transfer Nodes
|
2017-09-29 17:02:33 +02:00
|
|
|
HackingMission.prototype.enemyAISelectAction = function(nodeObj) {
|
2017-10-26 00:05:12 +02:00
|
|
|
if (nodeObj == null) {return;}
|
2017-09-29 17:02:33 +02:00
|
|
|
switch(nodeObj.type) {
|
|
|
|
case NodeTypes.Core:
|
|
|
|
//Select a single RANDOM target from miscNodes and player's Nodes
|
|
|
|
//If it is reachable, it will target it. If not, no target will
|
|
|
|
//be selected for now, and the next time process() gets called this will repeat
|
2017-10-26 00:05:12 +02:00
|
|
|
if (nodeObj.conn == null) {
|
2017-09-29 17:02:33 +02:00
|
|
|
if (this.miscNodes.length === 0) {
|
2017-10-02 04:35:22 +02:00
|
|
|
//Randomly pick a player node and attack it if its reachable
|
2017-09-29 17:02:33 +02:00
|
|
|
var rand = getRandomInt(0, this.playerNodes.length-1);
|
2017-10-04 03:50:13 +02:00
|
|
|
var node;
|
|
|
|
if (this.playerNodes.length === 0) {
|
|
|
|
node = null;
|
|
|
|
} else {
|
|
|
|
node = this.playerNodes[rand];
|
|
|
|
}
|
2017-09-29 17:02:33 +02:00
|
|
|
if (this.nodeReachableByEnemy(node)) {
|
2017-10-02 04:35:22 +02:00
|
|
|
//Create connection
|
|
|
|
nodeObj.conn = this.jsplumbinstance.connect({
|
|
|
|
source:nodeObj.el,
|
|
|
|
target:node.el
|
|
|
|
});
|
2017-10-10 06:56:48 +02:00
|
|
|
++node.targetedCount;
|
2017-09-29 17:02:33 +02:00
|
|
|
} else {
|
2017-10-02 04:35:22 +02:00
|
|
|
//Randomly pick a player core and attack it if its reachable
|
2017-09-29 17:02:33 +02:00
|
|
|
rand = getRandomInt(0, this.playerCores.length-1);
|
2017-10-04 03:50:13 +02:00
|
|
|
if (this.playerCores.length === 0) {
|
|
|
|
return; //No Misc Nodes, no player Nodes, no Player cores. Player lost
|
|
|
|
} else {
|
|
|
|
node = this.playerCores[rand];
|
|
|
|
}
|
|
|
|
|
2017-09-29 17:02:33 +02:00
|
|
|
if (this.nodeReachableByEnemy(node)) {
|
2017-10-02 04:35:22 +02:00
|
|
|
//Create connection
|
|
|
|
nodeObj.conn = this.jsplumbinstance.connect({
|
|
|
|
source:nodeObj.el,
|
|
|
|
target:node.el
|
|
|
|
});
|
2017-10-10 06:56:48 +02:00
|
|
|
++node.targetedCount;
|
2017-09-29 17:02:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-10-02 04:35:22 +02:00
|
|
|
//Randomly pick a misc node and attack it if its reachable
|
2017-09-29 17:02:33 +02:00
|
|
|
var rand = getRandomInt(0, this.miscNodes.length-1);
|
|
|
|
var node = this.miscNodes[rand];
|
|
|
|
if (this.nodeReachableByEnemy(node)) {
|
2017-10-02 04:35:22 +02:00
|
|
|
nodeObj.conn = this.jsplumbinstance.connect({
|
|
|
|
source:nodeObj.el,
|
|
|
|
target:node.el,
|
|
|
|
});
|
2017-10-10 06:56:48 +02:00
|
|
|
++node.targetedCount;
|
2017-09-29 17:02:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 04:35:22 +02:00
|
|
|
//If no connection was made, set the Core to Fortify
|
|
|
|
nodeObj.action = NodeActions.Fortify;
|
|
|
|
} else {
|
2017-10-04 03:50:13 +02:00
|
|
|
//If this node has a selected target
|
2017-10-02 04:35:22 +02:00
|
|
|
var targetNode;
|
|
|
|
if (nodeObj.conn.target) {
|
|
|
|
targetNode = this.getNodeFromElement(nodeObj.conn.target);
|
|
|
|
} else {
|
|
|
|
targetNode = this.getNodeFromElement(nodeObj.conn.targetId);
|
|
|
|
}
|
2017-10-26 00:05:12 +02:00
|
|
|
if (targetNode == null) {
|
2017-10-02 04:35:22 +02:00
|
|
|
console.log("Error getting Target node Object in enemyAISelectAction()");
|
|
|
|
}
|
2017-09-29 17:02:33 +02:00
|
|
|
|
2017-10-10 06:56:48 +02:00
|
|
|
if (targetNode.def > this.enemyAtk + 15) {
|
2017-10-04 03:50:13 +02:00
|
|
|
if (nodeObj.def < 50) {
|
|
|
|
nodeObj.action = NodeActions.Fortify;
|
|
|
|
} else {
|
|
|
|
nodeObj.action = NodeActions.Overflow;
|
|
|
|
}
|
2017-10-10 06:56:48 +02:00
|
|
|
} else if (Math.abs(targetNode.def - this.enemyAtk) <= 15) {
|
2017-10-02 04:35:22 +02:00
|
|
|
nodeObj.action = NodeActions.Scan;
|
|
|
|
} else {
|
|
|
|
nodeObj.action = NodeActions.Attack;
|
|
|
|
}
|
|
|
|
}
|
2017-09-29 17:02:33 +02:00
|
|
|
break;
|
|
|
|
case NodeTypes.Transfer:
|
|
|
|
//Switch between fortifying and overflowing as necessary
|
2017-10-02 04:35:22 +02:00
|
|
|
if (nodeObj.def < 125) {
|
2017-09-29 17:02:33 +02:00
|
|
|
nodeObj.action = NodeActions.Fortify;
|
|
|
|
} else {
|
|
|
|
nodeObj.action = NodeActions.Overflow;
|
|
|
|
}
|
|
|
|
break;
|
2017-12-03 05:19:49 +01:00
|
|
|
case NodeTypes.Firewall:
|
|
|
|
case NodeTypes.Shield:
|
|
|
|
nodeObj.action = NodeActions.Fortify;
|
|
|
|
break;
|
2017-09-29 17:02:33 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 04:35:22 +02:00
|
|
|
var hackEffWeightSelf = 130; //Weight for Node actions on self
|
2017-09-27 17:13:42 +02:00
|
|
|
var hackEffWeightTarget = 25; //Weight for Node Actions against Target
|
2017-10-02 04:35:22 +02:00
|
|
|
var hackEffWeightAttack = 80; //Weight for Attack action
|
2017-09-25 14:50:19 +02:00
|
|
|
|
|
|
|
//Returns damage per cycle based on stats
|
|
|
|
HackingMission.prototype.calculateAttackDamage = function(atk, def, hacking = 0) {
|
2017-12-03 05:19:49 +01:00
|
|
|
return Math.max(0.55 * (atk + (hacking / hackEffWeightAttack) - def), 1);
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
|
2017-09-26 04:44:33 +02:00
|
|
|
HackingMission.prototype.calculateScanEffect = function(atk, def, hacking=0) {
|
2017-12-03 05:19:49 +01:00
|
|
|
return Math.max(0.6 * ((atk) + hacking / hackEffWeightTarget - (def * 0.95)), 2);
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
|
2017-09-26 04:44:33 +02:00
|
|
|
HackingMission.prototype.calculateWeakenEffect = function(atk, def, hacking=0) {
|
2017-10-10 06:56:48 +02:00
|
|
|
return Math.max((atk) + hacking / hackEffWeightTarget - (def * 0.95), 2);
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HackingMission.prototype.calculateFortifyEffect = function(hacking=0) {
|
2017-12-07 04:45:47 +01:00
|
|
|
return 0.9 * hacking / hackEffWeightSelf;
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HackingMission.prototype.calculateOverflowEffect = function(hacking=0) {
|
2017-12-03 05:19:49 +01:00
|
|
|
return 0.95 * hacking / hackEffWeightSelf;
|
2017-09-25 14:50:19 +02:00
|
|
|
}
|
|
|
|
|
2017-09-26 04:44:33 +02:00
|
|
|
//Updates timer display
|
|
|
|
HackingMission.prototype.updateTimer = function() {
|
|
|
|
var timer = document.getElementById("hacking-mission-timer");
|
|
|
|
|
2017-10-10 06:56:48 +02:00
|
|
|
//Convert time remaining to a string of the form mm:ss
|
2017-09-26 04:44:33 +02:00
|
|
|
var seconds = Math.round(this.time / 1000);
|
|
|
|
var minutes = Math.trunc(seconds / 60);
|
|
|
|
seconds %= 60;
|
|
|
|
var str = ("0" + minutes).slice(-2) + ":" + ("0" + seconds).slice(-2);
|
|
|
|
timer.innerText = "Time left: " + str;
|
|
|
|
}
|
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
//The 'win' argument is a bool for whether or not the player won
|
|
|
|
HackingMission.prototype.finishMission = function(win) {
|
2017-09-26 04:44:33 +02:00
|
|
|
inMission = false;
|
|
|
|
currMission = null;
|
|
|
|
|
|
|
|
if (win) {
|
2017-10-10 06:56:48 +02:00
|
|
|
var favorMult = 1 + (this.faction.favor / 100);
|
|
|
|
console.log("Hacking mission base reward: " + this.reward);
|
|
|
|
console.log("favorMult: " + favorMult);
|
|
|
|
console.log("rep mult: " + Player.faction_rep_mult);
|
|
|
|
var gain = this.reward * Player.faction_rep_mult * favorMult;
|
|
|
|
dialogBoxCreate("Mission won! You earned " +
|
|
|
|
formatNumber(gain, 3) + " reputation with " + this.faction.name);
|
|
|
|
Player.gainIntelligenceExp(this.difficulty * CONSTANTS.IntelligenceHackingMissionBaseExpGain);
|
|
|
|
this.faction.playerReputation += gain;
|
2017-09-26 04:44:33 +02:00
|
|
|
} else {
|
2017-10-10 06:56:48 +02:00
|
|
|
dialogBoxCreate("Mission lost/forfeited! You did not gain any faction reputation.");
|
2017-09-26 04:44:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Clear mission container
|
|
|
|
var container = document.getElementById("mission-container");
|
|
|
|
while(container.firstChild) {
|
|
|
|
container.removeChild(container.firstChild);
|
|
|
|
}
|
2017-09-25 14:50:19 +02:00
|
|
|
|
2017-09-26 04:44:33 +02:00
|
|
|
//Return to Faction page
|
|
|
|
document.getElementById("mainmenu-container").style.visibility = "visible";
|
|
|
|
document.getElementById("character-overview-wrapper").style.visibility = "visible";
|
|
|
|
Engine.loadFactionContent();
|
|
|
|
displayFactionContent(this.faction.name);
|
2017-09-21 23:27:31 +02:00
|
|
|
}
|
|
|
|
|
2017-09-25 14:50:19 +02:00
|
|
|
export {HackingMission, inMission, setInMission, currMission};
|