Professional Documents
Culture Documents
/*
How to Use:
Press Shift+R to cycle through the tanks.
Press Shift+Q to disable/enable the script.
Press I to hide the dialog. (The script remains functional, though).
Hold rightclick to activate . For best results, leave autofire off for a bit before
doing so.
Note: This calibration may break for Triple Twin, and is unnecessary for
Streamliner.
*/
(function(){//info
if(window.updateInfo) return;
function toggle_info_container(e){
if(e.key == "i"){
info_container.style.display =
info_container.style.display=="block" ? "none" : "block";
}
}
window.addEventListener("keyup", toggle_info_container);
(function(){
var cycleRate = 0.003125; // ms^-1
var maxAngle = Math.PI * 45 / 180;
var NCANNON = 3;
var angleUnit = maxAngle / (NCANNON - 1);
var tankData = [
{name: "Tri-angle", cycleRate: 0.003095, maxAngle: Math.PI * 135 / 180,
NCANNON: 2},
{name: "Penta", cycleRate: 0.003095, maxAngle: Math.PI * 45 / 180,
NCANNON: 3},
{name: "SpreadShot", cycleRate: 0.001515, maxAngle: Math.PI * 75 / 180,
NCANNON: 6},
{name: "Octo", cycleRate: 0.003095, maxAngle: Math.PI * 45 / 180,
NCANNON: 2},
{name: "GunnerTrapper",cycleRate: 0.015, maxAngle: Math.PI, NCANNON: 2},
{name: "TripleTwin", cycleRate: 0.003125, maxAngle: Math.PI * 180 / 180,
NCANNON: 2},
{name: "Streamliner", cycleRate: 0.0625, maxAngle: Math.PI * 15 / 180,
NCANNON: 3},
];
var tankIndex = 0;
var mouseX;
var mouseY;
var a = 0;
var startA = 0;
var artificialMouseMove = false;
function onMouseDown(e){
if(e.button == 2){
if(!effective){
startA = a - 50;
mouseX = e.clientX;
mouseY = e.clientY;
canvas.dispatchEvent(new MouseEvent("mousedown", {clientX:
mouseX, clientY: mouseY}));
}
effective = true;
}
}
function onMouseUp(e){
if(e.button == 2){
if(effective){
canvas.dispatchEvent(new MouseEvent("mouseup", {clientX:
mouseX, clientY: mouseY}));
}
effective = false;
}
}
function onMouseMove(e){
if(effective){
if(!artificialMouseMove){
e.stopPropagation();
mouseX = e.clientX;
mouseY = e.clientY;
}
}else{
mouseX = e.clientX;
mouseY = e.clientY;
}
}
function update(_a){
frameRequest = window.requestAnimationFrame(update);
a = _a;
if(effective){
var da = a - startA;
var state = Math.floor(cycleRate * da * NCANNON) % (NCANNON * 2);
var state1 = state % NCANNON;
var state2 = Math.floor(state / NCANNON);
var angle = angleUnit * state1 * (state1 % 2 == state2 ? 1 : -1);
var cx = window.innerWidth / 2;
var cy = window.innerHeight / 2;
var sin = Math.sin(angle);
var cos = Math.cos(angle);
artificialMouseMove = true;
canvas.dispatchEvent(new MouseEvent("mousemove", {clientX: x,
clientY: y}));
artificialMouseMove = false;
}
}
function onKeyUp(e){
if(e.key == "Q"){
disabled = !disabled;
if(disabled){
if(measuring){
cycleRate = 1 / measure.terminate();
measuring = false;
} else stop();
}else start();
window.updateInfo && window.updateInfo("off", disabled ?
"Disabled." : null);
return;
}
if(disabled) return;
if(e.key == "R"){
changeTank((tankIndex + 1) % tankData.length);
}
}
function changeTank(index){
var data = tankData[index];
tankIndex = index;
function init(){
window.addEventListener("keyup", onKeyUp);
start();
changeTank(0);
}
function start(){
canvas.addEventListener("mousedown", onMouseDown);
canvas.addEventListener("mouseup", onMouseUp);
window.addEventListener("mousemove", onMouseMove, true);
frameRequest = window.requestAnimationFrame(update);
}
function stop(){
canvas.removeEventListener("mousedown", onMouseDown);
canvas.removeEventListener("mouseup", onMouseUp);
window.removeEventListener("mousemove", onMouseMove, true);
window.cancelAnimationFrame(frameRequest);
effective = false;
}
init();
})();