Skip to content

Instantly share code, notes, and snippets.

@pfn
Created Apr 21, 2017
Embed
What would you like to do?
usage is now splitFrames(framedata, casttime, dwdelay, firsthit, numoffsets, showindividualwields, enabledualwieldcast, showdrops)
function splitFrames(frames, cast, dwdelay, fst, offsets, showwields, enabledw, enabledrops) {
var out = [];
var firsthits = [];
for (var i = 0; i <= offsets; i++) {
var newhits = splitFramesOffset(frames, cast, dwdelay, fst, i, firsthits, showwields, enabledw, enabledrops);
if (firsthits.length == 0)
firsthits = newhits[0];
out = out.concat(newhits);
}
return out;
}
function splitFramesOffset(frames, cast, dwdelay, fst, offset, hits, showwields, enabledw, enabledrops) {
var CHAIN_BREAK_LIMIT = 19;
var first = parseInt(cast) + parseInt(fst) + parseInt(offset);
var hitsoffset = -1;
for (var i = 1; hitsoffset == -1 && i < hits.length; i++) {
if (first < hits[i] && first >= hits[i - 1]) hitsoffset = i;
}
var fs = frames.split(",").map(function(x) { return parseInt(x) });
var outframes = [];
outframes.push(first);
for (var i = 0; i < fs.length; i++) {
outframes.push(fs[i] + (i == 0 ? first : outframes[i]));
}
var wield2 = parseInt(cast) + first + parseInt(dwdelay);
var wield2i = -1;
for (var i = 1; wield2i == -1 && i < outframes.length; i++) {
if (wield2 < outframes[i] && wield2 >= outframes[i-1]) wield2i = i;
}
var outframes2 = [];
var w2shift = wield2i == -1 ? outframes.length : (wield2i - 1);
for (var i = 0; i < w2shift; i++)
outframes2.push("");
outframes2.push("");
outframes2.push(wield2)
var w2start = outframes2.length - 1;
for (var i = 0; i < fs.length; i++) {
outframes2.push(fs[i] + (i == 0 ? wield2 : outframes2[w2start + i]));
}
var outframes3 = outframes.concat(outframes2.filter(function(x) { return enabledw && x != "" }));
outframes3.sort(function(a,b) { return a - b });
var hitshift = hitsoffset == -1 ? 0 : Math.max(0,hitsoffset-1);
for (var i = 0; i < hitshift; i++) {
outframes.unshift("");
outframes2.unshift("");
outframes3.unshift("");
}
outframes.unshift(offset);
outframes2.unshift(offset);
outframes3.unshift(offset);
if (offset != 0) {
for (var i = 1; i < outframes3.length; i++) {
if (outframes[i] != "") {
if (enabledrops && (outframes3[i] < hits[i-1] || outframes3[i] > hits[i])) {
outframes3[i] = "(" + outframes3[i] + ")";
} else if (enabledrops && Math.abs(outframes3[i] - hits[i-1]) > CHAIN_BREAK_LIMIT)
outframes3[i] = "*" + outframes3[i];
else if (enabledrops && Math.abs(outframes3[i] - hits[i]) > CHAIN_BREAK_LIMIT)
outframes3[i] = outframes3[i] + "*";
}
}
}
return enabledw && showwields ? [outframes3, outframes, outframes2] : [outframes3];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment