Implements critical capture, tweaks for integration tests.
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build / Build (push) Successful in 48s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build / Build (push) Successful in 48s
				
			This commit is contained in:
		| @@ -5,6 +5,13 @@ namespace PkmnLib.Plugin.Gen7.Libraries.Battling; | ||||
|  | ||||
| public class Gen7CaptureLibrary : ICaptureLibrary | ||||
| { | ||||
|     private readonly Gen7PluginConfiguration _configuration; | ||||
|  | ||||
|     public Gen7CaptureLibrary(Gen7PluginConfiguration configuration) | ||||
|     { | ||||
|         _configuration = configuration; | ||||
|     } | ||||
|  | ||||
|     /// <inheritdoc /> | ||||
|     public CaptureResult TryCapture(IPokemon target, IItem captureItem, IBattleRandom random) | ||||
|     { | ||||
| @@ -22,10 +29,10 @@ public class Gen7CaptureLibrary : ICaptureLibrary | ||||
|         byte bonusStatus = 1; | ||||
|         target.RunScriptHook(x => x.ChangeCatchRateBonus(target, captureItem, ref bonusStatus)); | ||||
|  | ||||
|         var modifiedCatchRate = (3.0 * maxHealth - 2.0 * currentHealth) * catchRate * bonusBall / (3.0 * maxHealth); | ||||
|         var modifiedCatchRate = (3.0f * maxHealth - 2.0f * currentHealth) * catchRate * bonusBall / (3.0f * maxHealth); | ||||
|         modifiedCatchRate *= bonusStatus; | ||||
|  | ||||
|         var shakeProbability = 65536 / Math.Pow(255 / modifiedCatchRate, 0.1875); | ||||
|         var shakeProbability = 65536 / Math.Pow(255 / modifiedCatchRate, 0.1875f); | ||||
|         byte shakes = 0; | ||||
|         if (modifiedCatchRate >= 255) | ||||
|         { | ||||
| @@ -33,7 +40,26 @@ public class Gen7CaptureLibrary : ICaptureLibrary | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             // FIXME: Implement critical capture | ||||
|             var timesCaught = _configuration.TimesSpeciesCaught(target.Species); | ||||
|             if (timesCaught > 30) | ||||
|             { | ||||
|                 var criticalCaptureModifier = timesCaught switch | ||||
|                 { | ||||
|                     > 600 => 2.5f, | ||||
|                     > 450 => 2.0f, | ||||
|                     > 300 => 1.5f, | ||||
|                     > 150 => 1.0f, | ||||
|                     > 30 => 0.5f, | ||||
|                     // Default arm, should be heuristically unreachable (due to the timesCaught > 30 check above) | ||||
|                     _ => throw new ArgumentOutOfRangeException(), | ||||
|                 }; | ||||
|                 var criticalCaptureChance = (int)(modifiedCatchRate * criticalCaptureModifier / 6); | ||||
|                 if (random.GetInt(0, 256) < criticalCaptureChance) | ||||
|                 { | ||||
|                     return new CaptureResult(true, 1, true); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             for (var i = 0; i < 4; i++) | ||||
|             { | ||||
|                 if (random.GetInt(0, 65536) < shakeProbability) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user