@@ -308,6 +308,8 @@ public void gunPlayerInteractEvent(PlayerInteractEvent event) {
308308 } else {
309309 player .sendMessage (ChatColor .AQUA + gun .getName () + ChatColor .RED + " misfired! Try again." );
310310 }
311+
312+ AddGun .getPlugin ().getPlayerListener ().recordShotImpact (player .getUniqueId (), gun .getInnateAim (), gun .getInnateAim () / ((gun .getCooldown ()*2l ) / 50 ), (int ) (gun .getCooldown ()*2l ) / 50 );
311313 } else {
312314 // based on their stillness and settledness.
313315 double accuracy = computeAccuracyFor (gun , bulletType , player );
@@ -323,6 +325,9 @@ public void gunPlayerInteractEvent(PlayerInteractEvent event) {
323325 Location origin = player .getLocation ().clone ().add (bbOff .getX (), offset , bbOff .getZ ());
324326
325327 Location baseLocation = player .getEyeLocation ().clone ();
328+ Location kick = baseLocation .clone ();
329+
330+ double kickback = gun .getKickback ();
326331
327332 double minJitter = gun .getMinMissRadius () + bulletType .getMinMissRadius ();
328333 double maxJitter = gun .getMaxMissRadius () + bulletType .getMaxMissRadius ();
@@ -344,8 +349,14 @@ public void gunPlayerInteractEvent(PlayerInteractEvent event) {
344349 float pitchJitter = (float ) (((rand2 * (maxJitter - minJitter )) + Math .signum (rand2 ) * minJitter ) * accuracy );
345350 baseLocation .setYaw (baseLocation .getYaw () + yawJitter );
346351 baseLocation .setPitch (baseLocation .getPitch () + pitchJitter );
352+
353+ float kickYaw = yawJitter + (float ) (Math .signum (rand1 ) * kickback );
354+ float kickPitch = pitchJitter + (float ) (Math .signum (rand2 ) * kickback );
355+ kick .setYaw (kick .getYaw () + kickYaw );
356+ kick .setPitch (kick .getPitch () + kickPitch );
357+
347358 if (accuracy > 0.25 ) {
348- player .sendMessage (ChatColor .AQUA + gun .getName () + ChatColor .RED + " isn't easy to aim. Crouch and hold still to improve accuracy." );
359+ player .sendMessage (ChatColor .AQUA + gun .getName () + ChatColor .RED + " isn't always easy to aim. Try running less, or crouch and hold still to improve accuracy." );
349360 } else if (accuracy < 0.01 ) {
350361 // TODO: remove
351362 player .sendMessage (ChatColor .AQUA + gun .getName () + ChatColor .GREEN + " is shooting straight, good work." );
@@ -414,9 +425,11 @@ public void run() {
414425 player .setCooldown (gun .getMinimalGun ().getType (), (int ) (gun .getCooldown () / 50 ));
415426
416427 // jerk player's view back and reset still
417- gun .knockback (player , baseLocation .getDirection ());
428+ gun .knockback (player , kick .getDirection ());
418429
419430 AddGun .getPlugin ().getPlayerListener ().resetStillSince (player .getUniqueId ());
431+ // TODO: figure this stuff out like wtf
432+ AddGun .getPlugin ().getPlayerListener ().recordShotImpact (player .getUniqueId (), gun .getInnateAim (), gun .getInnateAim () / ((gun .getCooldown ()*2l ) / 50 ), (int ) (gun .getCooldown ()*2l ) / 50 );
420433 }
421434 }
422435 } else {
@@ -764,42 +777,92 @@ public double computeAccuracyFor(StandardGun gun, Bullet bullet, LivingEntity en
764777
765778
766779 /**
767- * Internally computes jitter based only on stillness and sneakness .
780+ * Internally computes jitter based on many factors .
768781 *
769782 * @param entity the entity's UUID to check
770783 * @return value from 0 to 1 where 1 is worse and 0 is best
771784 */
772785 private double computeAccuracyFor (UUID entity , StandardGun gun , Bullet bullet ) {
773786 long now = System .currentTimeMillis ();
774787 PlayerListener listener = AddGun .getPlugin ().getPlayerListener ();
788+
789+ double gunroot = gun .getInnateMiss ();
790+ double root = gun .getInnateBase ();
791+
775792 Long sneak = listener .getSneakingSince (entity );
776793 Long still = listener .getStillSince (entity );
794+ Long notsneak = listener .getSneakingEnd (entity );
795+ Long notstill = listener .getStillEnd (entity );
777796
797+ // TODO: per-player adjustments.
778798 double base = 1.0d ;
779- if (sneak == null && still == null ) { // not sneaking, not still.
780- return 1.0d ;
799+ if (sneak != null ) {
800+ // Sneaking reduces baseline impact
801+ base -= 0.025d * (double ) ((now - sneak ) / 50l );
802+ }
803+ if (still != null ) {
804+ // Still reduces baseline impact
805+ base -= 0.05d * (double ) ((now - still ) / 50l );
806+ }
807+ if (notsneak != null ) {
808+ // Not sneaking increases baseline impact
809+ base += 0.025d * (double ) ((now - notsneak ) / 50l );
810+ }
811+ if (notstill != null ) {
812+ // Not still increases baseline impact.
813+ base += 0.05d * (double ) ((now - notstill ) / 50l );
814+ }
815+ if (base < 0d ) base = 0d ;
816+ if (base > 1d ) base = 1d ;
817+
818+ root *= base ; // so this is root.
819+
820+ double pbase = 0.0d ;
821+ if (still != null ) {
822+ // If we are still, reduce "walk" impact.
823+ pbase += 0.1d - 0.00005d * (double ) (now - still );
824+ } else if (notstill != null ) {
825+ // if we are moving, increase "walk" impact.
826+ pbase += Math .min (0.1d , (0.0001d * (double ) (now - notstill )));
827+ }
828+
829+ Long notrun = listener .getSprintingEnd (entity );
830+ Long run = listener .getSprintingSince (entity );
831+ // if we were running, but stopped, linearly impact aim
832+ if (notrun != null ) {
833+ pbase += 0.4d - (0.0001d * (double ) (now - notrun ));
834+ } else if (run != null ) {
835+ // if we are running, aim is worsened, up to a max.
836+ pbase += Math .min (0.4d , (0.001d * (double ) (now - run )));
837+ }
838+ Long notglide = listener .getGlidingEnd (entity );
839+ Long glide = listener .getGlidingSince (entity );
840+ // Do the same for gliding
841+ if (notglide != null ) {
842+ pbase += 0.7d - (0.0001d * (double ) (now - notglide ));
843+ } else if (glide != null ) {
844+ pbase += Math .min (0.7d , (0.001d * (double ) (now - glide )));
781845 }
782846
783- double combineSneakInflection = gun . getSneakInflection () + bullet . getSneakInflection ();
784- if ( combineSneakInflection < 0.0d ) combineSneakInflection = 0.0d ;
847+ // now pull in any impact of prior shots.
848+ pbase += listener . getShotImpact ( entity ) ;
785849
786- double combineStillInflection = gun .getStillInflection () + bullet .getStillInflection ();
787- if (combineStillInflection < 0.0d ) combineStillInflection = 0.0d ;
850+ if (sneak != null ) { // we are sneaking!
851+ // so cut the impacts in half.
852+ pbase /= 2d ;
853+ }
788854
789- double combineSneakSpread = gun .getSneakSpread () + bullet .getSneakSpread ();
790- if (combineSneakSpread < 0.00001d ) combineSneakSpread = 0.00001d ;
855+ // now add in base.
856+ pbase += root ;
857+ // add in root.
858+ pbase += gunroot ;
791859
792- double combineStillSpread = gun . getStillSpread () + bullet . getStillSpread () ;
793- if (combineStillSpread < 0.00001d ) combineStillSpread = 0.00001d ;
860+ if ( pbase > 1.0d ) pbase = 1.0d ;
861+ if (pbase < 0.0d ) pbase = 0.0d ;
794862
795- if (sneak != null ) { // sneaking
796- base -= sigmoid ((now - sneak ) / 1000.0d , combineSneakInflection , 0.25d , combineSneakSpread );
797- }
798- if (still != null ) { // still
799- base -= sigmoid ((now - still ) / 1000.0d , combineStillInflection , 0.25d , combineStillSpread );
800- }
863+ return pbase ; // accuracy is then computed.
801864
802- return base > 0.0d ? base : 0.0d ;
865+ // TODO: These factors should be global...
803866 }
804867
805868 /**
0 commit comments