Move data and data loading to plugin libraries.
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		| @@ -0,0 +1,48 @@ | ||||
| using System; | ||||
| using PkmnLib.Dynamic.Libraries; | ||||
|  | ||||
| namespace PkmnLib.Plugin.Gen7.Libraries.Battling; | ||||
|  | ||||
| public class Gen7CaptureLibrary : ICaptureLibrary | ||||
| { | ||||
|     /// <inheritdoc /> | ||||
|     public CaptureResult TryCapture(IPokemon target, IItem captureItem, IBattleRandom random) | ||||
|     { | ||||
|         var maxHealth = target.BoostedStats.Hp; | ||||
|         var currentHealth = target.CurrentHealth; | ||||
|         var catchRate = target.Species.CaptureRate; | ||||
|  | ||||
|         byte bonusBall = 1; | ||||
|         if (target.Library.ScriptResolver.TryResolveBattleItemScript(captureItem, out var script) && | ||||
|             script is PokeballScript pokeballScript) | ||||
|         { | ||||
|             bonusBall = pokeballScript.GetCatchRate(target); | ||||
|         } | ||||
|  | ||||
|         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); | ||||
|         modifiedCatchRate *= bonusStatus; | ||||
|  | ||||
|         var shakeProbability = 65536 / Math.Pow(255 / modifiedCatchRate, 0.1875); | ||||
|         byte shakes = 0; | ||||
|         if (modifiedCatchRate >= 255) | ||||
|         { | ||||
|             shakes = 4; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             // FIXME: Implement critical capture | ||||
|             for (var i = 0; i < 4; i++) | ||||
|             { | ||||
|                 if (random.GetInt(0, 65536) < shakeProbability) | ||||
|                 { | ||||
|                     shakes++; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         var success = shakes >= 3; | ||||
|         return new CaptureResult(success, shakes, false); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user