Skip to content

Instantly share code, notes, and snippets.

@Rio6
Last active April 16, 2020 19:41
Show Gist options
  • Save Rio6/51e853a5d8252a9a362c80e29f6c82d1 to your computer and use it in GitHub Desktop.
Save Rio6/51e853a5d8252a9a362c80e29f6c82d1 to your computer and use it in GitHub Desktop.
Community made parts. _partLoader.js loads all the parts automatically with images so you just need to load that one. Try load this mod before others if there's any conflict with other mods.
/*
* Loads all weapons in this gist, plus their images
*/
if(!window.partLoader_partsLoaded) {
let imgloaderUrl = "https://gist.githubusercontent.com/Rio6/456ce90a98f38d74d095e7caf5a63f31/raw/"; // image loader
let parts = [
"https://gist.githubusercontent.com/Rio6/51e853a5d8252a9a362c80e29f6c82d1/raw/energyBeam.js", // Leach beam
"https://gist.githubusercontent.com/Rio6/51e853a5d8252a9a362c80e29f6c82d1/raw/jwdeWeapons.js", // Battle Cannon, Needle Gun
"https://gist.githubusercontent.com/Rio6/51e853a5d8252a9a362c80e29f6c82d1/raw/modprojector.js", // Mod Projector
"https://gist.githubusercontent.com/Rio6/51e853a5d8252a9a362c80e29f6c82d1/raw/burstCannon.js", // Burst Cannon
];
let loadMod = url => {
let http = new XMLHttpRequest();
http.open("GET", url, false);
http.send();
try {
(0, eval)(http.responseText);
} catch(e) {
console.error(e);
}
};
loadMod(imgloaderUrl);
imgloader.addImage("parts/turBattleCannon.png","https://i.imgur.com/0dbutRM.png");
imgloader.addImage("parts/turBattleCannonReload.png","https://i.imgur.com/7GdXAPu.png");
imgloader.addImage("parts/battleCannonBullet","https://i.imgur.com/Qrfyjjl.png");
imgloader.addImage("parts/turNeedleGun.png","https://i.imgur.com/HC55kPO.png");
imgloader.addImage("parts/turNeedleGunReload.png","https://i.imgur.com/6rC1g8G.png");
imgloader.addImage("parts/needleGunBullet","https://i.imgur.com/D8IEkFp.png");
imgloader.addImage("parts/turBurstTurret.png","https://i.imgur.com/4Ull8O0.png");
imgloader.addImage("parts/turBurstTurretReload.png","https://i.imgur.com/sXdVWAP.png");
imgloader.addImage("parts/turLeechBeam.png","https://i.imgur.com/sy8nMZ7.png");
imgloader.addImage("parts/turLeechBeamReload.png","https://i.imgur.com/OIIzmDs.png");
imgloader.combineImages();
for(let url of parts) {
loadMod(url);
}
partLoader_partsLoaded = true;
}
// A way to notify custom servers that the parts are loaded
if(!window.partLoader_connection_sendPlayer) window.partLoader_connection_sendPlayer = Connection.prototype.sendPlayer;
Connection.prototype.sendPlayer = function() {
let sender = {
send: function() {
let args = Array.from(arguments);
args[26] = true;
network.send(...args);
}
};
partLoader_connection_sendPlayer.call(sender);
}
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
var hasProp = {}.hasOwnProperty;
var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
parts.BurstTurret = (function(superClass) {
extend(BurstTurret, superClass);
function BurstTurret() {
return BurstTurret.__super__.constructor.apply(this, arguments);
}
BurstTurret.prototype.name = "Burst Cannon";
BurstTurret.prototype.desc = "A mid-range weapon that fires 3 bullets in rapid bursts.";
BurstTurret.prototype.hp = 10;
BurstTurret.prototype.cost = 5;
BurstTurret.prototype.image = "turBurstTurret.png";
BurstTurret.prototype.size = [2, 2];
BurstTurret.prototype.reloadTime = 54.5;
BurstTurret.prototype.trackSpeed = 25;
BurstTurret.prototype.bulletCls = types.AutoBullet;
BurstTurret.prototype.range = 710;
BurstTurret.prototype.shotEnergy = 1250 * 3;
BurstTurret.prototype.mass = 35;
BurstTurret.prototype.bulletSpeed = 31;
BurstTurret.prototype.damage = 16 * 3;
BurstTurret.prototype.fired = 10;
BurstTurret.prototype.volley = 3;
BurstTurret.prototype.spread = [0, 0, 0];
return BurstTurret;
})(parts.AutoTurret);
var ebeam_turret_canShoot = ebeam_turret_canShoot || Turret.prototype.canShoot;
Turret.prototype.canShoot = function(other) {
if(!ebeam_turret_canShoot.call(this, other))
return false;
if(this.noOverkill) {
if(this.energyDamage && other.energy * 2 < this.energyDamage)
return false
}
return true;
};
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
var hasProp = {}.hasOwnProperty;
var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
types.EnergyBeam = (function(superClass) {
extend(EnergyBeam, superClass);
function EnergyBeam() {
return EnergyBeam.__super__.constructor.apply(this, arguments);
}
EnergyBeam.prototype.image = "parts/fireBeamLarge.png";
EnergyBeam.prototype.sound = "sounds/weapons/beam4.wav";
EnergyBeam.prototype.size = [1, 1];
EnergyBeam.prototype.color = [80, 120, 255, 255];
return EnergyBeam;
})(LaserBullet);
parts.EnergyBeamTurret = (function(superClass) {
extend(EnergyBeamTurret, superClass);
function EnergyBeamTurret() {
return EnergyBeamTurret.__super__.constructor.apply(this, arguments);
}
EnergyBeamTurret.prototype.name = "Energy Beam";
EnergyBeamTurret.prototype.desc = "Energy sucker";
EnergyBeamTurret.prototype.hp = 10;
EnergyBeamTurret.prototype.cost = 5;
EnergyBeamTurret.prototype.image = "turLeechBeam.png";
EnergyBeamTurret.prototype.size = [2, 2];
EnergyBeamTurret.prototype.reloadTime = 8;
EnergyBeamTurret.prototype.trackSpeed = 25;
EnergyBeamTurret.prototype.bulletCls = types.EnergyBeam;
EnergyBeamTurret.prototype.shotEnergy = 1400;
EnergyBeamTurret.prototype.instant = true;
EnergyBeamTurret.prototype.range = 710;
EnergyBeamTurret.prototype.mass = 10;
EnergyBeamTurret.prototype.bulletSpeed = 2000;
EnergyBeamTurret.prototype.damage = 0;
EnergyBeamTurret.prototype.energyDamage = 570;
EnergyBeamTurret.prototype.maxLife = .5;
EnergyBeamTurret.prototype.makeBullet = function(distance) {
EnergyBeamTurret.__super__.makeBullet.call(this);
this.unit.energy += Math.min(this.target.energy, this.energyDamage);
return this.target.applyEnergyDamage(this.energyDamage);
};
return EnergyBeamTurret;
})(Turret);
//Battle Cannon
hasProp = {}.hasOwnProperty
extendz=function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }
parts.BattleCannon = (function(superClass) {
extendz(BattleCannon, superClass);
function BattleCannon() {
return BattleCannon.__super__.constructor.apply(this, arguments);
}
// BulletSlowMod.prototype.id = 999;
BattleCannon.prototype.name = "Battle Cannon";
BattleCannon.prototype.desc = "Glory to PDables!";
BattleCannon.prototype.cost = 5;
BattleCannon.prototype.mass = 50;
BattleCannon.prototype.hp = 10;
BattleCannon.prototype.image = "turBattleCannon.png";
BattleCannon.prototype.damage = 29*2;
BattleCannon.prototype.reloadTime = 80;
BattleCannon.prototype.shotEnergy = 3360;
BattleCannon.prototype.bulletSpeed = 20.75;
BattleCannon.prototype.size = [2, 2];
BattleCannon.prototype.range = 900;
BattleCannon.prototype.volley = 2;
BattleCannon.prototype.fired = 2;
BattleCannon.prototype.spread = [.01, -.01];
types.BattleCannonBullet = (function(superClass) {
extendz(BattleCannonBullet, superClass);
function BattleCannonBullet() {
return BattleCannonBullet.__super__.constructor.apply(this, arguments);
}
BattleCannonBullet.prototype.image = "parts/battleCannonBullet";
BattleCannonBullet.prototype.sound = "sounds/weapons/torp2.wav";
BattleCannonBullet.prototype.size = [1, 1];
BattleCannonBullet.prototype.radius = 30;
BattleCannonBullet.prototype.missile = true;
BattleCannonBullet.prototype.trailTime = 50;
BattleCannonBullet.prototype.trailSize = 0.03;
return BattleCannonBullet;
})(StraightMissile);
BattleCannon.prototype.bulletCls = types.BattleCannonBullet;
BattleCannon.prototype.tick = function() {
BattleCannon.__super__.tick.call(this);
if (this.fired < 2) {
this.makeRealBullet(this.spread[0]+this.rot,0);
this.makeRealBullet(this.spread[1]+this.rot,1);
this.fired += 2;
return this.working = true;
}
}
;
BattleCannon.prototype.makeBullet = function(distance) {
this.unit.cloak = 0;
return this.fired = 0;
};
BattleCannon.prototype.makeRealBullet = function(spread,pos) {
var particle;
particle = new this.bulletCls();
sim.things[particle.id] = particle;
particle.side = this.unit.side;
particle.life = 0;
particle.dead = false;
particle.z = this.unit.z + .001;
particle.turretNum = this.turretNum;
particle.origin = this.unit;
particle.target = this.target;
particle.speed = this.bulletSpeed;
particle.damage = this.damage / 2;
particle.maxLife = this.range / particle.speed * 1.3;
//Decide which barrel we are firing out of
tempPos = v2.create(this.worldPos);
if (pos == 0) {
tempPos[0] = 6*Math.cos(spread)-6*Math.sin(spread)+tempPos[0]
tempPos[1] = 6*Math.cos(spread)+6*Math.sin(spread)+tempPos[1]
}
else
{
tempPos[0] = -6*Math.cos(spread)+6*Math.sin(spread)+tempPos[0]
tempPos[1] = -8*Math.cos(spread)-8*Math.sin(spread)+tempPos[1]
}
v2.set(tempPos, particle.pos);
v2.pointTo(particle.vel, spread);
v2.scale(particle.vel, particle.speed);
return particle.rot = spread;
};
return BattleCannon;
})(parts.AutoTurret.__super__.constructor);
types.NeedleGunBullet = (function(superClass) {
extendz(NeedleGunBullet, superClass);
function NeedleGunBullet() {
return NeedleGunBullet.__super__.constructor.apply(this, arguments);
}
NeedleGunBullet.prototype.image = "parts/needleGunBullet";
NeedleGunBullet.prototype.sound = "sounds/weapons/blaster1.wav";
NeedleGunBullet.prototype.size = [1, 1];
NeedleGunBullet.prototype.radius = 20;
NeedleGunBullet.prototype.trailTime = 50;
NeedleGunBullet.prototype.trailSize = 0;
return NeedleGunBullet;
})(Bullet);
parts.NeedleGun = (function(superClass) {
extendz(NeedleGun, superClass);
function NeedleGun() {
return NeedleGun.__super__.constructor.apply(this, arguments);
}
NeedleGun.prototype.name = "Needle Gun";
NeedleGun.prototype.desc = "It shoots needles, what else do you expect?";
NeedleGun.prototype.cost = 5;
NeedleGun.prototype.mass = 15;
NeedleGun.prototype.hp = 10;
NeedleGun.prototype.image = "turNeedleGun.png";
NeedleGun.prototype.damage = 4;
NeedleGun.prototype.reloadTime = 5.12;
NeedleGun.prototype.shotEnergy = 380;
NeedleGun.prototype.bulletSpeed = 34;
NeedleGun.prototype.size = [2, 2];
NeedleGun.prototype.spread = [.0698, -.0698];
NeedleGun.prototype.range = 700;
NeedleGun.prototype.fired = 1;
NeedleGun.prototype.fireState = 0;
NeedleGun.prototype.bulletCls = types.NeedleGunBullet;
NeedleGun.prototype.makeBullet = function() {
var particle;
this.unit.cloak = 0;
particle = new this.bulletCls();
sim.things[particle.id] = particle;
particle.side = this.unit.side;
particle.life = 0;
particle.dead = false;
particle.z = this.unit.z + .001;
particle.turretNum = this.turretNum;
particle.origin = this.unit;
particle.target = this.target;
particle.speed = this.bulletSpeed;
particle.damage = this.damage;
particle.maxLife = this.range / particle.speed * 1.3;
v2.set(this.worldPos, particle.pos);
v2.pointTo(particle.vel, this.rot + Math.random() * .14 - .07);
v2.scale(particle.vel, particle.speed);
return particle.rot = v2.angle(particle.vel);
};
NeedleGun.prototype.tick = function() {
NeedleGun.__super__.tick.call(this);
if (this.fired < 1) {
this.rot += this.spread[this.fireState];
this.makeBullet();
this.fired += 1;
if (this.fireState == 0) {
this.fireState += 1;
}
else {
this.fireState = 0;
}
return this.working = true;
}
};
return NeedleGun;
})(Turret);
var modproj_unit_tick = modproj_unit_tick || types.Unit.prototype.tick;
types.Unit.prototype.tick = function() {
modproj_unit_tick.call(this);
if (this.weapons.length > 0) {
return this.applyNearbyBuffs();
}
}
types.Unit.prototype.applyNearbyBuffs = function() {
var applyEffect, buffs, c, j, len, ref, w;
buffs = {
weaponRange: 1,
weaponRangeFlat: 0,
weaponDamage: 1,
weaponEnergyDamage: 1,
weaponSpeed: 1,
weaponReload: 1,
weaponEnergy: 1,
noOverkill: false
};
applyEffect = function(n, effect) {
return 1 + (n - 1) * effect;
};
sim.unitSpaces[this.side].findInRange(this.pos, parts.ModProjector.prototype.range, (function(_this) {
return function(u) {
if (u.id !== _this.id && u.projector && v2.distance(_this.pos, u.pos) < parts.ModProjector.prototype.range) {
buffs.weaponRange *= applyEffect(u.projector.weaponRange, u.effect);
buffs.weaponRangeFlat += u.projector.weaponRangeFlat * u.effect;
buffs.weaponDamage *= applyEffect(u.projector.weaponDamage, u.effect);
buffs.weaponEnergyDamage *= applyEffect(u.projector.weaponDamage, u.effect);
buffs.weaponSpeed *= applyEffect(u.projector.weaponSpeed, u.effect);
buffs.weaponReload *= applyEffect(u.projector.weaponReload, u.effect);
buffs.weaponEnergy *= applyEffect(u.projector.weaponEnergy, u.effect);
return buffs.noOverkill |= u.projector.noOverkill;
}
};
})(this));
ref = this.weapons;
for (j = 0, len = ref.length; j < len; j++) {
w = ref[j];
w.applyAdditionalBuffs(buffs);
}
return false;
};
Turret.prototype.applyBuffs = function() {
var j, len, ref, results, s;
this.range *= this.weaponRange;
this.range += this.weaponRangeFlat;
this.damage *= this.weaponDamage;
this.energyDamage *= this.weaponDamage;
this.bulletSpeed *= this.weaponSpeed;
this.reloadTime *= this.weaponReload;
this.shotEnergy *= this.weaponEnergy;
this.reloadTime = Math.ceil(this.reloadTime);
this.fireEnergy = this.shotEnergy / this.reloadTime;
this.dps = this.damage / this.reloadTime;
this.baseStats = {};
ref = ["range", "damage", "energyDamage", "bulletSpeed", "reloadTime", "shotEnergy", "noOverkill"];
results = [];
for (j = 0, len = ref.length; j < len; j++) {
s = ref[j];
results.push(this.baseStats[s] = this[s]);
}
return results;
};
Turret.prototype.applyAdditionalBuffs = function(buffs) {
this.range = this.baseStats.range * buffs.weaponRange + buffs.weaponRangeFlat;
this.damage = this.baseStats.damage * buffs.weaponDamage;
this.energyDamage = this.baseStats.energyDamage * buffs.weaponDamage;
this.bulletSpeed = this.baseStats.bulletSpeed * buffs.weaponSpeed;
this.reloadTime = this.baseStats.reloadTime * buffs.weaponReload;
this.shotEnergy = this.baseStats.shotEnergy * buffs.weaponEnergy;
this.noOverkill = buffs.noOverkill;
this.reloadTime = Math.ceil(this.reloadTime);
this.fireEnergy = this.shotEnergy / this.reloadTime;
return this.dps = this.damage / this.reloadTime;
};
parts.ModProjector = (function(superClass) {
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
extend(ModProjector, superClass);
function ModProjector() {
return ModProjector.__super__.constructor.apply(this, arguments);
}
ModProjector.prototype.name = "Mod Effect Projector";
ModProjector.prototype.desc = "Projects mod effects to nearby ships. -15% effect on each armed ship. -40% effect overall";
ModProjector.prototype.hp = 10;
ModProjector.prototype.cost = 30;
ModProjector.prototype.mass = 60;
ModProjector.prototype.image = "focus.png";
ModProjector.prototype.size = [2, 2];
ModProjector.prototype.tab = "weapons";
ModProjector.prototype.range = 500;
ModProjector.prototype.reductionRatio = .2;
ModProjector.prototype.splitRatio = .95;
ModProjector.prototype.useEnergy = 50 / 16;
ModProjector.prototype.shotEnergy = 10;
ModProjector.prototype.instant = true;
ModProjector.prototype.bulletCls = LaserBullet;
ModProjector.prototype.gimble = false;
ModProjector.prototype.weaponRange = 1;
ModProjector.prototype.weaponRangeFlat = 0;
ModProjector.prototype.weaponDamage = 1;
ModProjector.prototype.weaponSpeed = 0;
ModProjector.prototype.weaponReload = 1;
ModProjector.prototype.weaponEnergy = 1;
ModProjector.prototype.noOverkill = false;
ModProjector.prototype.init = function() {
return this.unit.projector = {
weaponRange: 1,
weaponRangeFlat: 0,
weaponDamage: 1,
weaponEnergyDamage: 1,
weaponSpeed: 1,
weaponReload: 1,
weaponEnergy: 1,
noOverkill: false
};
};
ModProjector.prototype.tick = function() {
var giveTo;
this.working = false;
giveTo = 0;
sim.unitSpaces[this.unit.side].findInRange(this.unit.pos, this.range, (function(_this) {
return function(thing) {
var distance, i, len, ref, w, weapons;
weapons = (function() {
var i, len, ref, results;
ref = thing.weapons;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
w = ref[i];
if (!w.projector) {
results.push(w);
}
}
return results;
})();
if (thing.id !== _this.unit.id && weapons.length > 0) {
distance = v2.distance(_this.unit.pos, thing.pos);
if (distance < _this.range) {
giveTo += weapons.length;
}
}
return false;
};
})(this));
if (this.unit.energy < this.useEnergy * giveTo) {
this.unit.effect = 0;
return;
}
if (giveTo > 0) {
this.unit.effect = (1 / this.splitRatio) * (Math.pow(this.splitRatio, giveTo));
this.unit.energy -= this.useEnergy * giveTo;
return this.working = true;
}
};
ModProjector.prototype.applyBuffs = function() {
var applyEffect;
applyEffect = function(n, effect) {
return 1 + (n - 1) * effect;
};
this.unit.projector.weaponRange *= applyEffect(this.weaponRange, this.reductionRatio);
this.unit.projector.weaponRangeFlat += this.weaponRangeFlat * this.reductionRatio;
this.unit.projector.weaponDamage *= applyEffect(this.weaponDamage, this.reductionRatio);
this.unit.projector.weaponEnergyDamage *= applyEffect(this.weaponEnergyDamage, this.reductionRatio);
this.unit.projector.weaponSpeed += this.weaponSpeed * this.reductionRatio;
this.unit.projector.weaponReload *= applyEffect(this.weaponReload, this.reductionRatio);
this.unit.projector.weaponEnergy *= applyEffect(this.weaponEnergy, this.reductionRatio);
return this.unit.projector.noOverkill |= this.noOverkill;
};
ModProjector.prototype.applyAdditionalBuffs = function(buffs) {};
ModProjector.prototype.preDraw = function() {
var r;
if (this.working) {
r = (this.range + 40) / 255;
return baseAtlas.drawSprite("img/point02.png", this.unit.pos, [r, r], 0, [255, 128, 128, 30]);
}
};
ModProjector.prototype.draw = function() {
return Part.prototype.draw.call(this);
};
return ModProjector;
})(Turret);
var _pos = v2.create();
var isArray = function(a) {
if (Array.isArray(a)) {
return true;
}
if (a instanceof Float64Array) {
return true;
}
return false;
};
Sim.prototype.send = function() {
var _, changes, data, e, f, i, id, l, len1, len2, len3, len4, len5, len6, len7, len8, m, o, p, packet, part, partId, player, predictable, q, r, ref, ref1, ref10, ref11, ref12, ref13, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, s, send, splayers, sthings, t, targetId, thing, v, x, y, z;
this.timeStart("send");
this.timeStart("things");
sthings = [];
ref = this.things;
for (id in ref) {
thing = ref[id];
changes = [];
changes.push(["thingId", thing.id]);
if (thing.net == null) {
thing.net = s = {};
changes.push(["name", thing.constructor.name]);
changes.push(["spec", thing.spec]);
changes.push(["color", thing.color]);
changes.push(["z", thing.z]);
} else if (thing["static"]) {
continue;
} else {
s = thing.net;
}
ref1 = this.thingFields;
for (l = 0, len1 = ref1.length; l < len1; l++) {
f = ref1[l];
v = thing[f];
if ((v != null) && !simpleEquals(s[f], v)) {
if (isArray(v)) {
if (s.length !== v.length) {
s[f] = new Array(v.length);
}
for (i = m = 0, len2 = v.length; m < len2; i = ++m) {
e = v[i];
s[f][i] = e;
}
} else {
s[f] = v;
}
changes.push([f, v]);
}
}
predictable = false;
if ((s.vel != null) && (s.pos != null)) {
v2.add(s.pos, s.vel, _pos);
if (v2.distance(_pos, thing.pos) < .1) {
v2.set(_pos, s.pos);
predictable = true;
}
}
if (!predictable) {
if (s.vel == null) {
s.vel = v2.create();
}
if (s.pos == null) {
s.pos = v2.create();
}
v2.set(thing.vel, s.vel);
v2.set(thing.pos, s.pos);
changes.push(["vel", thing.vel]);
changes.push(["pos", thing.pos]);
}
if (s.targetId !== ((ref2 = thing.target) != null ? ref2.id : void 0)) {
s.targetId = (ref3 = thing.target) != null ? ref3.id : void 0;
changes.push(["targetId", s.targetId]);
}
if (s.originId !== ((ref4 = thing.origin) != null ? ref4.id : void 0)) {
s.originId = (ref5 = thing.origin) != null ? ref5.id : void 0;
changes.push(["originId", s.originId]);
}
if (s.followId !== ((ref6 = thing.follow) != null ? ref6.id : void 0)) {
s.followId = (ref7 = thing.follow) != null ? ref7.id : void 0;
changes.push(["followId", s.followId]);
}
if (this.local) {
if (s.message !== thing.message) {
s.message = thing.message;
changes.push(["message", s.message]);
}
}
if (thing.parts != null) {
ref8 = thing.parts;
for (partId = o = 0, len3 = ref8.length; o < len3; partId = ++o) {
part = ref8[partId];
changes.push(["partId", partId]);
s = part.net;
if (!s) {
part.net = s = {};
}
if ((part.working != null) && s.working !== part.working) {
changes.push(["partWorking", part.working]);
s.working = part.working;
}
if (part.weapon) {
targetId = ((ref9 = part.target) != null ? ref9.id : void 0) || 0;
if (s.targetId !== targetId) {
changes.push(["partTargetId", targetId]);
s.targetId = targetId;
}
if (s.range !== part.range) {
changes.push(["partRange", part.range]);
s.range = part.range;
}
}
if (changes[changes.length - 1][0] === "partId") {
changes.pop();
}
}
}
if (changes.length > 1) {
sthings.push(changes);
}
}
this.timeEnd("things");
this.timeStart("players");
splayers = [];
ref10 = this.players;
for (q = 0, len4 = ref10.length; q < len4; q++) {
player = ref10[q];
changes = [];
changes.push(["playerNumber", player.number]);
if (player.net == null) {
player.net = s = {};
} else {
s = player.net;
}
ref11 = this.playerFields;
for (r = 0, len5 = ref11.length; r < len5; r++) {
f = ref11[r];
v = player[f];
if ((v != null) && !simpleEquals(s[f], v)) {
if (isArray(v)) {
if (s.length !== v.length) {
s[f] = new Array(v.length);
}
for (i = x = 0, len6 = v.length; x < len6; i = ++x) {
e = v[i];
s[f][i] = e;
}
} else {
s[f] = v;
}
changes.push([f, v]);
}
}
if (changes.length > 1) {
splayers.push(changes);
}
}
this.timeEnd("players");
this.timeStart("other");
data = {};
s = this.net;
if (!s) {
this.net = s = {};
}
ref12 = this.simFields;
for (y = 0, len7 = ref12.length; y < len7; y++) {
f = ref12[y];
if (!simpleEquals(s[f], this[f])) {
data[f] = this[f];
s[f] = this[f];
}
}
if (splayers.length > 0) {
data.players = splayers;
}
if (sthings.length > 0) {
data.things = sthings;
}
if (this.fullUpdate) {
data.fullUpdate = true;
this.fullUpdate = false;
}
if (sim.step % 16 === 0) {
send = false;
ref13 = this.players;
for (z = 0, len8 = ref13.length; z < len8; z++) {
player = ref13[z];
if (player.name === "treeform" && player.connected) {
send = true;
}
}
if (send) {
data.perf = {
numbers: {
things: ((function() {
var results;
results = [];
for (t in this.things) {
results.push(t);
}
return results;
}).call(this)).length,
sthings: sthings.length,
players: ((function() {
var i1, len9, ref14, results;
ref14 = this.players;
results = [];
for (i1 = 0, len9 = ref14.length; i1 < len9; i1++) {
p = ref14[i1];
results.push(p);
}
return results;
}).call(this)).length,
splayers: splayers.length,
units: ((function() {
var ref14, results;
ref14 = this.things;
results = [];
for (_ in ref14) {
t = ref14[_];
if (t.unit) {
results.push(t);
}
}
return results;
}).call(this)).length,
bullets: ((function() {
var ref14, results;
ref14 = this.things;
results = [];
for (_ in ref14) {
t = ref14[_];
if (t.bullet) {
results.push(t);
}
}
return results;
}).call(this)).length,
others: ((function() {
var ref14, results;
ref14 = this.things;
results = [];
for (_ in ref14) {
t = ref14[_];
if (!t.bullet && !t.unit) {
results.push(t);
}
}
return results;
}).call(this)).length
},
timeings: this.timeings
};
}
this.timeings = {};
}
this.timeEnd("other");
this.timeStart("zJson");
packet = this.zJson.dumpDv(data);
this.timeEnd("zJson");
this.timeEnd("send");
return packet;
};
Interpolator.prototype.process = function(data) {
var _, dt, id, j, k, kv, l, len, len1, len2, len3, len4, len5, len6, len7, len8, n, newObj, newThing, number, o, p, part, player, q, r, ref, ref1, ref10, ref11, ref12, ref13, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, s, selection, t, thing, u, unit, v, w, y, z;
if (this.replay === "recording") {
this.replayFrames.push(packet);
}
t = now();
dt = t - this.stepTime;
this.avgTime = this.avgTime * .9 + dt * .1;
this.stepTime = t;
this.avgFrame = this.avgFrame * .9 + this.lastFrame * .1;
this.lastFrame = 0;
if (intp.players.length === 0 && !data.fullUpdate && commander) {
print("waiting for full update");
return;
}
if (data.fullUpdate) {
intp.step = data.step;
} else if (data.step != null) {
if (intp.step + 1 === data.step) {
intp.step += 1;
} else {
print("Over step, what about full update?");
return;
}
}
if (data.winningSide) {
intp.winningSide = data.winningSide;
onecup.refresh();
}
if (data.state) {
intp.state = data.state;
onecup.refresh();
}
if (intp.state === "starting") {
this.gameStarted();
}
if (intp.state === "ended") {
console.log("ended");
this.gameEnded();
}
if (data.serverType) {
intp.serverType = data.serverType;
onecup.refresh();
}
if (data.theme) {
intp.theme = data.theme;
}
if (intp.countDown === 5 * 16 && !sim.local) {
onecup.refresh();
}
if (data.countDown != null) {
intp.countDown = data.countDown;
if (intp.countDown % 16 === 0 && intp.state === "waiting") {
onecup.refresh();
}
}
designMode.locked = intp.serverType === "1v1t" && intp.state === "running" && commander.side !== "spectators";
if (data.perf) {
intp.perf = data.perf;
if (control.perf) {
onecup.refresh();
}
}
ref = intp.things;
for (_ in ref) {
thing = ref[_];
v2.add(thing._pos, thing.vel);
v2.set(thing.pos, thing._pos2);
thing._rot2 = thing.rot;
if (thing.parts != null) {
ref1 = thing.parts;
for (j = 0, len = ref1.length; j < len; j++) {
part = ref1[j];
part._rot2 = part.rot;
}
}
}
ref2 = intp.players;
for (l = 0, len1 = ref2.length; l < len1; l++) {
player = ref2[l];
player._mouse = player.mouse;
}
if (data.things) {
ref3 = data.things;
for (o = 0, len2 = ref3.length; o < len2; o++) {
t = ref3[o];
thing = null;
part = null;
newObj = false;
for (q = 0, len3 = t.length; q < len3; q++) {
kv = t[q];
k = kv[0], v = kv[1];
switch (k) {
case "thingId":
thing = intp.things[v];
if (!thing) {
thing = {
dummy: true
};
newObj = true;
}
thing.id = v;
part = null;
newObj = false;
break;
case "spec":
if (thing.dummy) {
newThing = new types[thing.name](v);
newThing.id = thing.id;
newThing.name = thing.name;
intp.things[newThing.id] = newThing;
thing = newThing;
newObj = true;
}
break;
case "pos":
if (newObj || (thing._pos == null)) {
thing.pos = v2.create(v);
thing._pos = v2.create(thing.pos);
thing._pos2 = v2.create(thing.pos);
} else {
v2.set(v, thing._pos);
}
break;
case "rot":
if (newObj) {
thing.rot = v;
thing._rot = thing.rot;
thing._rot2 = thing.rot;
if (thing.weapons) {
ref4 = thing.weapons;
for (r = 0, len4 = ref4.length; r < len4; r++) {
w = ref4[r];
w.rot = thing.rot;
w._rot = thing.rot;
w._rot2 = thing.rot;
}
}
} else {
thing._rot = v;
}
break;
case "dead":
thing.dead = v;
if (thing.dead) {
if (typeof thing.createDebree === "function") {
thing.createDebree();
}
}
break;
case "partId":
if (thing.parts) {
part = thing.parts[v];
newObj = false;
} else {
part = {};
}
break;
case "partWorking":
part.working = v;
break;
case "partTargetId":
part.targetId = v;
break;
case "partRange":
part.range = v;
break;
case "orders":
thing.orders = v;
if (thing.preOrders) {
thing.preOrders = thing.preOrders.filter(function(order) {
return order.step + 16 * 5 < sim.step;
});
}
break;
default:
thing[k] = v;
}
}
}
}
if (data.players) {
ref5 = data.players;
for (s = 0, len5 = ref5.length; s < len5; s++) {
p = ref5[s];
player = null;
for (u = 0, len6 = p.length; u < len6; u++) {
kv = p[u];
k = kv[0], v = kv[1];
if (k === "playerNumber") {
while (intp.players.length <= v) {
intp.players.push(new Player());
}
player = intp.players[v];
player.number = v;
} else {
player[k] = v;
}
if ((k === "buildQ" || k === "validBar") && commander.name === player.name) {
onecup.refresh();
}
}
}
}
ref6 = intp.things;
for (_ in ref6) {
thing = ref6[_];
if (thing.targetId) {
thing.target = intp.things[thing.targetId];
}
if (thing.originId) {
thing.origin = intp.things[thing.originId];
}
}
ref7 = this.things;
for (id in ref7) {
thing = ref7[id];
if (typeof thing.clientTick === "function") {
thing.clientTick();
}
if (thing.dead) {
delete this.things[id];
}
}
ref8 = this.players;
for (number = y = 0, len7 = ref8.length; y < len7; number = ++y) {
player = ref8[number];
if ((typeof commander !== "undefined" && commander !== null) && (player != null ? player.ai : void 0) === false && commander.name === (player != null ? player.name : void 0)) {
if (player.side) {
commander.side = player.side;
}
if (player.money) {
commander.money = player.money;
}
if (player.selection) {
commander.selection = player.selection;
}
if (player.buildQ) {
commander.buildQ = player.buildQ;
}
if (player.validBar) {
commander.validBar = player.validBar;
}
if (player.rallyPoint) {
commander.rallyPoint = player.rallyPoint;
}
commander.number = number;
if (player.host != null) {
commander.host = player.host;
}
}
if (!player.name) {
player.name = "no name";
}
if (!player.side) {
player.side = "spectators";
}
if (!player.color) {
player.color = [255, 0, 0, 255];
}
}
ref9 = this.particles;
for (id in ref9) {
thing = ref9[id];
if (thing.dead) {
delete this.particles[id];
continue;
}
if (!thing._pos) {
thing._pos = v2.create(thing.pos);
}
if (!thing._pos2) {
thing._pos2 = v2.create(thing.pos);
}
v2.set(thing.pos, thing._pos2);
thing._rot2 = thing.rot;
if (typeof thing.tick === "function") {
thing.tick();
}
if (typeof thing.move === "function") {
thing.move();
}
v2.set(thing.pos, thing._pos);
thing._rot = thing.rot;
}
if (this.state === "starting") {
this.focusMap();
this.state = "running";
onecup.refresh();
}
if (this.state === "ended") {
this.state = "waiting";
onecup.refresh();
if (this.winningSide === false) {
playSound("sounds/drone/draw.wav");
} else if (this.winningSide === (typeof commander !== "undefined" && commander !== null ? commander.side : void 0)) {
playSound("sounds/drone/victory.wav");
} else {
playSound("sounds/drone/defeat.wav");
}
onecup.refresh();
}
if ((ref10 = onecup.lookup("#money-text")) != null) {
ref10.innerHTML = buildBar.moneyText();
}
if ((ref11 = onecup.lookup("#money-income")) != null) {
ref11.innerHTML = buildBar.moneyIncomeText();
}
if (typeof commander !== "undefined" && commander !== null ? commander.selection : void 0) {
selection = [];
ref12 = commander.selection;
for (n = z = 0, len8 = ref12.length; z < len8; n = ++z) {
unit = ref12[n];
thing = this.things[unit.id];
if (thing) {
selection.push(thing);
}
}
commander.selection = selection;
}
if (localStorage.useAi === "true" && localStorage.aiGrid === "true") {
if (ui.mode === "battle" && (typeof commander !== "undefined" && commander !== null ? (ref13 = commander.selection) != null ? ref13.length : void 0 : void 0) > 0) {
return onecup.refresh();
}
}
};
window.drawAllArcs = function(unit) {
var arc, cur, i, j, l, len, n, pos, range, ref, ref1, ref2, results, th, w, x, y;
unit = sim.things[unit.id];
if (!unit) {
return;
}
ref = unit.weapons;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
w = ref[j];
if (w.projector) {
continue;
}
range = w.range;
arc = w.arc;
cur = Math.PI * range * 2;
n = Math.floor(cur / 40 * arc / 360);
for (i = l = ref1 = -n, ref2 = n; ref1 <= ref2 ? l < ref2 : l > ref2; i = ref1 <= ref2 ? ++l : --l) {
th = i / (n * 2) * arc / 180 * Math.PI + unit.rot + Math.PI;
x = Math.sin(-th) * range;
y = Math.cos(-th) * range;
pos = [w.worldPos[0] + x, w.worldPos[1] + y];
baseAtlas.drawSprite("img/arrow02.png", pos, [.25, .25], th + Math.PI, [255, 0, 0, 255]);
}
if (w.minRange > 0) {
cur = Math.PI * w.minRange * 2;
n = Math.floor(cur / 40 * arc / 360);
results.push((function() {
var m, ref3, ref4, results1;
results1 = [];
for (i = m = ref3 = -n, ref4 = n; ref3 <= ref4 ? m < ref4 : m > ref4; i = ref3 <= ref4 ? ++m : --m) {
th = i / (n * 2) * arc / 180 * Math.PI + unit.rot + Math.PI;
x = Math.sin(-th) * w.minRange;
y = Math.cos(-th) * w.minRange;
pos = [w.worldPos[0] + x, w.worldPos[1] + y];
results1.push(baseAtlas.drawSprite("img/arrow02.png", pos, [.25, .25], th, [255, 0, 0, 255]));
}
return results1;
})());
} else {
results.push(void 0);
}
}
return results;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment