Repository navigation
Expand file tree
/
Copy pathapptesthit.js
More file actions
665 lines (562 loc) · 21.5 KB
/
Copy pathapptesthit.js
File metadata and controls
665 lines (562 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
function Hit(percent, damagestaled, damageunstaled, growth, base, setKnockback, trajectory, character, version, xPos, yPos, crouch, reverse, chargeInterrupt, tdiX, tdiY, fadeIn, doubleJump, sdix, sdiy, adix, adiy, meteorCancel, vcancel, grounded, metal, ice, icg, isThrow, throwChar, throwType, combo, comboFrame) {
/******* Internal functions start *******/
var groundDownHit = false;
var groundDownHitType;
//Calculates base knockback from hit
//Formula taken from http://www.ssbwiki.com/Knockback#Formula
function getReleasePoint(xPos,yPos,character,throwChar,throwType,reverse,version){
//Release Point = ThrowN + TransN + CharOffset
var rpX = 0;
var rpY = 0;
var release = throwFrames[throwChar][throwType+"throw"].release;
var firstActionable = throwFrames[throwChar][throwType+"throw"].firstA;
// if weight dependent
if (throwFrames[throwChar].weight[throwType]){
//animation frame per game frame
var animPerGame = 1/(characters[character][version+"weight"]/100);
var animRelFrame = release + animPerGame - (release % animPerGame);
//use mod 1, so interpolations above 1.00 will be calculated properly
var interpolation = (animRelFrame - release) % 1;
var diffXthrowN = throwAnim[throwChar][throwType+"throw"]["f"+Math.ceil(animRelFrame)].throwN[0] - throwAnim[throwChar][throwType+"throw"]["f"+Math.floor(animRelFrame)].throwN[0];
var diffYthrowN = throwAnim[throwChar][throwType+"throw"]["f"+Math.ceil(animRelFrame)].throwN[1] - throwAnim[throwChar][throwType+"throw"]["f"+Math.floor(animRelFrame)].throwN[1];
var interThrowNx = diffXthrowN * interpolation;
var interThrowNy = diffYthrowN * interpolation;
rpX += interThrowNx + throwAnim[throwChar][throwType+"throw"]["f"+Math.floor(animRelFrame)].throwN[0];
rpY += interThrowNy + throwAnim[throwChar][throwType+"throw"]["f"+Math.floor(animRelFrame)].throwN[1];
if (typeof throwAnim[throwChar][throwType+"throw"]["f"+release].transN !== "undefined"){
var diffXtransN = throwAnim[throwChar][throwType+"throw"]["f"+Math.ceil(animRelFrame)].transN[0] - throwAnim[throwChar][throwType+"throw"]["f"+Math.floor(animRelFrame)].transN[0];
var diffYtransN = throwAnim[throwChar][throwType+"throw"]["f"+Math.ceil(animRelFrame)].transN[1] - throwAnim[throwChar][throwType+"throw"]["f"+Math.floor(animRelFrame)].transN[1];
var interTransNx = diffXtransN * interpolation;
var interTransNy = diffYtransN * interpolation;
rpX += interTransNx + throwAnim[throwChar][throwType+"throw"]["f"+Math.floor(animRelFrame)].transN[0];
rpY += interTransNy + throwAnim[throwChar][throwType+"throw"]["f"+Math.floor(animRelFrame)].transN[1];
}
}
else {
//if throwN exists
if (typeof throwAnim[throwChar][throwType+"throw"]["f"+release].throwN !== "undefined"){
rpX += throwAnim[throwChar][throwType+"throw"]["f"+release].throwN[0];
rpY += throwAnim[throwChar][throwType+"throw"]["f"+release].throwN[1];
}
// if transN exists
if (typeof throwAnim[throwChar][throwType+"throw"]["f"+release].transN !== "undefined"){
rpX += throwAnim[throwChar][throwType+"throw"]["f"+release].transN[0];
rpY += throwAnim[throwChar][throwType+"throw"]["f"+release].transN[1];
}
}
firstActionable *= characters[character][version+"weight"];
firstActionable += throwFrames[throwChar][throwType+"throw"].hLag;
rpX += throwOffsets[character][0];
rpY += throwOffsets[character][1];
if (reverse){
rpX *= -1;
}
return [(xPos+rpX),(yPos+rpY)];
}
function getKnockback(percent, damagestaled, damageunstaled, weight, growth, base, setKnockback, crouch, chargeInterrupt, vcancel, grounded, trajectory, metal, ice, isThrow) {
if (isThrow){
weight = 100;
}
if (setKnockback == 0){
//var percent = percent + damage;
//var kb = ((((((percent / 10) + ((percent * damage) / 20)) * (200 / (weight + 100)) * 1.4) + 18) * (growth / 100)) + base);
var kb = ((0.01 * growth) * ((1.4 * (((0.05 * (damageunstaled * (damagestaled + Math.floor(percent)))) + (damagestaled + Math.floor(percent)) * 0.1) * (2.0 - (2.0 * (weight * 0.01)) / (1.0 + (weight * 0.01))))) + 18) + base);
//var kb = ((0.01 * knockback growth) * ((1.4 * (((0.05 * (attack damage unstaled * (attack damage staled + floor(current damage)))) + (attack damage staled + floor(current damage)) * 0.1) * (2.0 - (2.0 * (weight * 0.01)) / (1.0 + (weight * 0.01))))) + 18) + base knockback);
}
else {
var kb = ((((setKnockback * 10 / 20) + 1) * 1.4 * (200/(weight + 100)) + 18) * (growth / 100)) + base;
}
if (crouch) {
kb *= 0.667;
}
if (chargeInterrupt){
kb *= 1.2;
}
if (vcancel){
kb *= 0.95;
}
if (ice){
kb *= 0.25;
}
if (metal){
kb -= 30;
if (kb < 0){
kb = 0;
}
}
if (kb > 2500){
kb = 2500;
}
if ((trajectory > 180 && trajectory != 361) && grounded){
if (kb >= 80){
kb *= 0.8;
groundDownHitType = "Fly";
}
else {
groundDownHitType = "Stay";
}
groundDownHit = true;
}
return kb;
}
//Calculates Sakurai angle for grounded opponents. Once support for different starting points exists, will need a check for in air / on ground
//Function by Yeroc
function getAngle(trajectory, knockback, reverse, x, y) {
//p = cos(a-arctan(x/y))*sqrt(x^2+y^2)
var deadzone = false;
if (knockback < 80 && grounded && (trajectory == 0 || trajectory == 180)){
deadzone = true;
}
if (x < 0.2875 && x > -0.2875){
x = 0;
}
if (y < 0.2875 && y > -0.2875){
y = 0;
}
if (x == 0 && y < 0){
diAngle = 270;
}
else if (x == 0 && y > 0){
diAngle = 90;
}
else if (x == 0 && y == 0){
deadzone = true;
}
else {
diAngle = Math.atan(y/x) * (180 / Math.PI) * 1;
if (x < 0){
diAngle += 180;
}
else if (y < 0) {
diAngle += 360;
}
}
if (trajectory == 361) {
if (knockback < 32.1) {
if (reverse){
trajectory = 180;
}
else {
trajectory = 0;
}
sakurai = 0;
}
else if (knockback >= 32.1) {
if (reverse){
trajectory = 136;
}
else {
trajectory = 44;
}
sakurai = 44;
}
else {
prompt("Why would this ever get called?");
trajectory = 440*(knockback-32);
if (reverse){
trajectory = 180 - trajectory;
if (trajectory < 0){
trajectory = 360 + trajectory;
}
}
}
}
else {
if (reverse){
trajectory = 180 - trajectory;
if (trajectory < 0){
trajectory = 360 + trajectory;
}
}
}
if (!deadzone){
var rAngle = trajectory - diAngle;
if (rAngle > 180){
rAngle -= 360;
}
var pDistance = Math.sin(rAngle * angleConversion) * Math.sqrt(x*x+y*y);
var angleOffset = pDistance * pDistance * 18;
if (angleOffset > 18){
angleOffset = 18;
}
if (rAngle < 0 && rAngle > -180){
angleOffset *= -1;
}
//$("#debugdIAngle").empty().append(diAngle);
//$("#debugrAngle").empty().append(rAngle);
}
else {
var angleOffset = 0;
}
var newtraj = trajectory - angleOffset;
if (newtraj < 0.01){
newtraj = 0;
}
//$("#debugAngle").empty().append(angleOffset);
//var fCall = parseInt($("#debugFCall").text());
//$("#debugFCall").empty().append((fCall+1));
return newtraj;
}
//The initial horizontal velocity the hit causes
function getHorizontalVelocity(knockback, angle) {
var initialVelocity = knockback * 0.03;
var horizontalAngle = Math.cos(angle * angleConversion);
var horizontalVelocity = initialVelocity * horizontalAngle;
horizontalVelocity = Math.round(horizontalVelocity * 100000) / 100000;
return horizontalVelocity;
}
//The initial vertical velocity the hit causes
function getVerticalVelocity(knockback, angle,grounded) {
var initialVelocity = knockback * 0.03;
var verticalAngle = Math.sin(angle * angleConversion);
var verticalVelocity = initialVelocity * verticalAngle;
verticalVelocity = Math.round(verticalVelocity * 100000) / 100000;
if (knockback < 80 && grounded && (trajectory == 0 || trajectory == 180)){
verticalVelocity = 0;
}
return verticalVelocity;
}
var meteorCancelled = false;
var stayGrounded = false;
var yDisplacement = 0;
var reduceByTraction = false;
//Calculate position for every frame of hitstun
function knockbackTravel(horizontalVelocity, horizontalDecay, verticalVelocity, verticalDecay, character, hitstun, xPos, yPos, fadeIn, doubleJump, sdiVector, asdiVector, trajectory, meteorCancel, grounded, angle, releasePoint, icg) {
var positions = [];
var hPos = releasePoint[0];
var vPos = releasePoint[1];
var horVelChar = 0;
var verVelChar = 0;
var horVelKB = horizontalVelocity;
var verVelKB = verticalVelocity;
if (icg){
verVelKB = 0;
}
var extendedDisplay = 0;
//Gravity only plays into effect until max fallspeed is reached.
var gravityFrames = Math.floor(characters[character]["terminalVelocity"] / characters[character]["gravity"]);
//Since gravity generally doesn't divide into max fallspeed evenly, we have a < gravity frame
var lastGravityFrame = characters[character]["terminalVelocity"] % characters[character]["gravity"];
if (trajectory >= 260 && trajectory <= 280 && meteorCancel && !icg){
hitstun = 8;
meteorCancelled = true;
}
if (grounded && (trajectory == 0 || trajectory == 180) && knockback < 80){
verVelKB = 0;
//prompt("test");
reduceByTraction = true;
}
if (groundDownHit){
if (groundDownHitType == "Stay"){
verVelKB = 0;
reduceByTraction = true;
}
else {
verVelKB = Math.abs(verVelKB);
verticalDecay = Math.abs(verticalDecay);
}
}
for (var i=0; i<hitstun; i++) {
if (reduceByTraction){
if (horVelKB != 0){
if (horVelKB > 0){
horVelKB -= characters[character]["traction"];
if (horVelKB < 0){
horVelKB = 0;
}
}
else {
horVelKB += characters[character]["traction"];
if (horVelKB > 0){
horVelKB = 0;
}
}
}
}
else {
if (horVelKB != 0){
if (horVelKB > 0){
horVelKB -= horizontalDecay;
if (horVelKB < 0){
horVelKB = 0;
}
}
else {
horVelKB -= horizontalDecay;
if (horVelKB > 0){
horVelKB = 0;
}
}
}
if (verVelKB != 0){
if (verVelKB > 0){
verVelKB -= verticalDecay;
if (verVelKB < 0){
verVelKB = 0;
}
}
else {
verVelKB -= verticalDecay;
if (verVelKB > 0){
verVelKB = 0;
}
}
}
if (i < gravityFrames) {
verVelChar -= characters[character]["gravity"];
}
else if (i === gravityFrames) {
verVelChar -= lastGravityFrame;
}
}
hPos = hPos + horVelChar + horVelKB;
vPos = vPos + verVelChar + verVelKB;
if (i == 0){
hPos += sdiVector[0] + asdiVector[0];
vPos += sdiVector[1] + asdiVector[1];
if (asdiVector[1] < 0 && grounded && (verVelChar + verVelKB + asdiVector[1] + sdiVector[1] < 0) && (trajectory < 180 || trajectory == 361)){
stayGrounded = true;
yDisplacement = verVelChar + verVelKB + asdiVector[1] + sdiVector[1];
break;
}
}
positions.push([hPos, vPos, horVelKB, verVelKB, horVelChar, verVelChar]);
}
var hasDoubleJumped = false;
var e = 0;
while ((Math.abs(horVelKB) > 0.001 || Math.abs(verVelKB) > 0.001 || (meteorCancelled && extendedDisplay < 25)) && !stayGrounded){
if (reduceByTraction){
if (horVelKB != 0){
if (horVelKB > 0){
horVelKB -= characters[character]["traction"];
if (horVelKB < 0){
horVelKB = 0;
}
}
else {
horVelKB += characters[character]["traction"];
if (horVelKB > 0){
horVelKB = 0;
}
}
}
}
else {
if (horVelKB != 0){
if (horVelKB > 0){
horVelKB -= horizontalDecay;
if (horVelKB < 0){
horVelKB = 0;
}
}
else {
horVelKB -= horizontalDecay;
if (horVelKB > 0){
horVelKB = 0;
}
}
}
if (verVelKB != 0){
if (verVelKB > 0){
verVelKB -= verticalDecay;
if (verVelKB < 0){
verVelKB = 0;
}
}
else {
verVelKB -= verticalDecay;
if (verVelKB > 0){
verVelKB = 0;
}
}
}
if (i < gravityFrames) {
verVelChar -= characters[character]["gravity"];
}
else if (i == gravityFrames) {
verVelChar -= lastGravityFrame;
}
if (meteorCancelled){
horVelKB = 0;
verVelKB = 0;
extendedDisplay++;
}
if (doubleJump && !hasDoubleJumped){
if (characters[character]["djSetY"]){
verVelChar = characters[character]["djInitY"][e];
if (characters[character]["djSetX"]){
if (hPos > 0){
horVelChar += -characters[character]["djXValues"][e];
}
else if (hPos < 0){
horVelChar += characters[character]["djXValues"][e];
}
}
e++;
}
else {
verVelChar = characters[character]["djInitY"];
if (fadeIn){
if (hPos > 0){
horVelChar = -characters[character]["djInitX"];
}
else if (hPos < 0){
horVelChar = characters[character]["djInitX"];
}
}
hasDoubleJumped = true;
}
}
if (hasDoubleJumped){
verVelChar -= characters[character]["gravity"];
if (verVelChar < -characters[character]["terminalVelocity"]){
verVelChar = -characters[character]["terminalVelocity"];
}
}
if (fadeIn){
if (hPos > 0){
if (horVelChar < -characters[character]["driftMax"]){
horVelChar += characters[character]["airFriction"];
if (horVelChar > -characters[character]["driftMax"]){
horVelChar = -characters[character]["driftMax"];
}
}
else {
horVelChar -= characters[character]["driftAcc"];
if (horVelChar < -characters[character]["driftMax"]){
horVelChar = -characters[character]["driftMax"];
}
}
}
else if (hPos < 0){
if (horVelChar > characters[character]["driftMax"]){
horVelChar -= characters[character]["airFriction"];
if (horVelChar < characters[character]["driftMax"]){
horVelChar = characters[character]["driftMax"];
}
}
else {
horVelChar += characters[character]["driftAcc"];
if (horVelChar > characters[character]["driftMax"]){
horVelChar = characters[character]["driftMax"];
}
}
}
}
}
i++;
hPos = hPos + horVelChar + horVelKB;
vPos = vPos + verVelChar + verVelKB;
positions.push([hPos, vPos, horVelKB, verVelKB, horVelChar, verVelChar]);
}
return positions;
}
//Rate at which horizontal velocity decreases
function getHorizontalDecay(angle) {
var decay = 0.051 * Math.cos(angle * angleConversion)
decay = Math.round(decay * 100000) / 100000;
return decay;
}
//Rate at which vertical velocity decreases
//Gravity also plays a role, but that is done in knockbackTravel
function getVerticalDecay(angle) {
var decay = 0.051 * Math.sin(angle * angleConversion)
decay = Math.round(decay * 100000) / 100000;
return decay;
}
//Frames of hitstun
function getHitstun(knockback) {
if (groundDownHit){
knockback *= 1.25;
}
return Math.floor(knockback * .4);
}
function calculateSDI(x,y,type,grounded,knockback,trajectory){
/*If (xjoy * xjoy) + (yjoy * yjoy) < (0.7 * 0.7)
Then apply no Smash DI.
If cardinal direction change has not occurred in last 4 frames, then apply no smash DI.
- Applying Smash DI -
Set frames since last cardinal direction change for x & y to 254 frames.
TopN x change = xjoy * 6.0
TopN y change = yjoy * 6.0*/
//prompt(grounded);
if (x < 0.2875 && x > -0.2875){
x = 0;
}
if (y < 0.2875 && y > -0.2875){
y = 0;
}
if (((x * x) + (y * y)) < (0.7 * 0.7)){
var xDistance = 0;
var yDistance = 0;
}
else {
var xDistance = 6.0 * x;
var yDistance = 6.0 * y;
if (type == "a"){
xDistance *= 0.5;
yDistance *= 0.5;
}
else if (grounded && yDistance < 0){
yDistance = 0;
}
if (groundDownHit){
if (groundDownHitType == "Stay" && yDistance > 0){
yDistance = 0;
}
if (yDistance < 0){
yDistance = 0;
}
}
if (grounded && knockback < 80 && (trajectory == 0 || trajectory == 180)){
yDistance = 0;
}
}
return [xDistance, yDistance];
}
/******* Internal functions end *******/
/******* Constants start *******/
//Constant we multiply degrees against to get radians (for Math object)
var angleConversion = Math.PI / 180;
//Ugly, but if I use proper JSON spacing this would be like 3 pages long
/******* Constants end *******/
/******* Variable setup start *******/
if (!characters[character]) {
throw("Bad character name given. Aborting.");
}
var weight;
if (version == "NTSC") {
weight = characters[character]["NTSCweight"];
}
else {
weight = characters[character]["PALweight"];
}
var gravity = characters[character]["gravity"];
if (isThrow){
var releasePoint = getReleasePoint(xPos,yPos,character,throwChar,throwType,reverse,version);
}
else {
var releasePoint = [xPos,yPos];
}
var knockback = getKnockback(percent, damagestaled, damageunstaled, weight, growth, base, setKnockback, crouch, chargeInterrupt, vcancel, grounded, trajectory, metal, ice, isThrow);
var hitstun = getHitstun(knockback);
var horizontalVelocity;
var verticalVelocity;
var angle = getAngle(trajectory, knockback, reverse, tdiX, tdiY);
horizontalVelocity = getHorizontalVelocity(knockback, angle, gravity);
verticalVelocity = getVerticalVelocity(knockback, angle, gravity, grounded);
var horizontalDecay = getHorizontalDecay(angle);
var verticalDecay = getVerticalDecay(angle);
var sdiVector = calculateSDI(sdix,sdiy,"s",grounded,knockback,trajectory);
var asdiVector = calculateSDI(adix,adiy,"a",grounded,knockback,trajectory);
this.positions = knockbackTravel(horizontalVelocity, horizontalDecay, verticalVelocity, verticalDecay, character, hitstun, xPos, yPos, fadeIn, doubleJump, sdiVector, asdiVector, trajectory, meteorCancel, grounded, angle, releasePoint, icg);
//prompt("test");
this.hitstun = hitstun;
this.knockback = knockback;
this.meteorCancelled = meteorCancelled;
this.stayGrounded = stayGrounded;
this.yDisplacement = yDisplacement;
//Position on the last frame of hitstun. Not used yet, but potentially useful.
//var endPosition = this.positions[this.positions.length - 1];
/******* Variable setup end *******/
}