Advertisement
GauHelldragon

palworld team types

Jun 30th, 2025
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.42 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. my @typeNames = ( "Fire","Water","Grass","Neutral","Electric","Ice","Ground","Dark","Dragon");
  6. my @typeWeaknesses =
  7. (
  8. #    Defenders
  9. #    F   W   Gra N   E   I   Gro Da  Dr
  10.     [0.5,0.5,2.0,1.0,1.0,2.0,1.0,1.0,1.0], #F - attackers
  11.     [2.0,0.5,1.0,1.0,0.5,1.0,1.0,1.0,1.0], #W
  12.     [0.5,1.0,0.5,1.0,1.0,1.0,2.0,1.0,1.0], #Gra
  13.     [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0], #N
  14.     [1.0,2.0,1.0,1.0,0.5,1.0,0.5,1.0,1.0], #E
  15.     [0.5,1.0,1.0,1.0,1.0,0.5,1.0,1.0,2.0], #I
  16.     [1.0,1.0,0.5,1.0,2.0,1.0,0.5,1.0,1.0], #Gro
  17.     [1.0,1.0,1.0,2.0,1.0,1.0,1.0,0.5,0.5], #Da
  18.     [1.0,1.0,1.0,1.0,1.0,0.5,1.0,2.0,0.5]  #Dra
  19. );
  20. my @teamInfo = loadTeamInfo();
  21. my ( $testString ) = @ARGV;
  22. my %enemyData = getDataFromCouple($testString);
  23. my $ETR = $enemyData{'types'};
  24. my @enemyTypes = @$ETR;
  25.  
  26. my $EAR = $enemyData{'attacks'};
  27. my @enemyAttacks = @$EAR;
  28.  
  29. #print "@enemyTypes\n";
  30. my $enemyString = typeInfoString(@enemyTypes);
  31. print "Enemy : $enemyString\n\n";
  32.  
  33. my @battleInfo;
  34. for ( @teamInfo ) {
  35.     my %data = %$_;
  36.     my $typeRef = $data{'types'};
  37.     my $info = typeInfoString(@$typeRef);
  38.     my $aveAttack = getAverageAttack($data{'attacks'},\@enemyTypes,$data{'types'});
  39.     my $aveWeakness = getAverageAttack(\@enemyAttacks,$data{'types'},\@enemyTypes);
  40.    
  41.     my $battleRate = $aveAttack * ( 1 / $aveWeakness ) ;
  42.     #print "$battleRate : $info - $aveAttack / $aveWeakness\n";
  43.     my %bInfo = (name => $info, battle => $battleRate, attack => $aveAttack, weakness => $aveWeakness );
  44.     push @battleInfo , \%bInfo;
  45. }
  46.  
  47. my @sortedBattle = sort sortFunc @battleInfo;
  48. #my @sortedBattle = @battleInfo;
  49. print "Rating     Name         Atk   Weak\n";
  50. foreach ( @sortedBattle ) {
  51.     my $hashRef = $_;
  52.     my %hash = %$hashRef;
  53.     #print "$hash{'battle'} - $hash{'name'} : $hash{'attack'} / $hash{'weakness'}\n";
  54.     printf "%4.2f - %-13s : %4.2f / %4.2f\n", $hash{'battle'},$hash{'name'},$hash{'attack'},$hash{'weakness'};
  55.     #print "$hashRef\n";
  56. }
  57.  
  58. sub sortFunc
  59. {
  60.     my %hashA = %$a;
  61.     my %hashB = %$b;
  62.     return $hashB{'battle'} <=> $hashA{'battle'};
  63. }
  64.  
  65.  
  66. sub typeInfoString {
  67. #   print "typeInfoString : @_\n";
  68.  
  69.     my @types = @_;
  70.     if ( @types == 1 ) {
  71.         return "$typeNames[$types[0]]";
  72.     } else {
  73.         return "$typeNames[$types[0]]/$typeNames[$types[1]]";
  74.     }
  75. }
  76.  
  77. sub getDataFromCouple {
  78. #   print "getDataFromCouple @_\n";
  79.     my ($typeStr) = @_;
  80.     my (@attacks,@types);
  81. #   print(" getTypesFromCouple: $typeStr\n");
  82.     if ( $typeStr =~ /:/ ) {
  83.         $typeStr =~ /(.+):(.+)/;
  84.         $typeStr = $1;
  85.         my @attackNames = split(/,/,$2);
  86.         @attacks = map {getTypeFromStr($_)} @attackNames;
  87.     }
  88.    
  89.    
  90.     if ( $typeStr =~ /\// ) {
  91.         $typeStr =~ /(.+)\/(.+)/;
  92.         @types = (getTypeFromStr($1),getTypeFromStr($2));
  93.         if ( @attacks == 0)
  94.         {
  95.             @attacks = (getTypeFromStr($1),getTypeFromStr($2));
  96.         }
  97.     }
  98.     else
  99.     {
  100.         @types = (getTypeFromStr($typeStr));
  101.         if ( @attacks == 0 )
  102.         {
  103.             @attacks = (getTypeFromStr($typeStr));
  104.         }
  105.     }
  106.    
  107.     return ( 'types' => \@types, 'attacks' => \@attacks );
  108. }
  109.  
  110. sub getTypeFromStr {
  111. #   print " getTypeFromStr - @_\n";
  112.  
  113.     my ($typeStr) = @_;
  114.     for (my $i=0; $i < @typeNames; $i++) {
  115.         my $type = uc($typeNames[$i]);
  116.         $typeStr = uc($typeStr);
  117. #       print "$typeStr vs $type \n";
  118.         if ( $type =~ /^$typeStr/ ) { return $i; }
  119.        
  120.     }
  121.     die "Bad Type : $typeStr";
  122. }
  123.  
  124. sub loadTeamInfo {
  125.     open(INPUT,"PalTeams.txt") or die "Could not open PalTeams.txt\n";
  126.     my @team;
  127.     while (<INPUT>) {
  128.         chomp;
  129. #       print "reading $_\n";
  130.         my %data = getDataFromCouple($_);
  131.         push @team,\%data;
  132.     }
  133.     return @team;
  134. }
  135.  
  136. sub getAverageAttack {
  137.     my ($aRef,$dRef,$aTRef) = @_;
  138.     my @attackTypes = @$aRef;
  139.     my @defendTypes = @$dRef;
  140.     my @attackerTypes = @$aTRef;
  141.    
  142.     my $attackNum = 0;
  143.     my $attackTotal = 0;
  144.     for my $attackType (@attackTypes) {
  145.         my $damMulti = 1;
  146.         $attackNum++;
  147.         for my $defendType (@defendTypes) {
  148.            
  149.             my $atkMulti = getTypeMulti($attackType,$defendType);
  150.            
  151.             $damMulti *= $atkMulti;
  152.         #   print " $attackNum : $typeNames[$attackType] vs $typeNames[$defendType] : $atkMulti\n";
  153.         }
  154.         #print "  total damMulti: $damMulti\n";
  155.         if ( $attackType == $attackerTypes[0] || ( @attackerTypes > 1 && $attackType == $attackerTypes[1] ) ) {
  156.             $damMulti *= 1.2;
  157.         }
  158.         $attackTotal += $damMulti;
  159.     }
  160.    
  161.     return $attackTotal / $attackNum;
  162.    
  163. }
  164.  
  165. sub getTypeMulti {
  166.     my ($atk,$def,@types) = @_;
  167.  
  168.     my $value = $typeWeaknesses[$atk][$def];
  169.    
  170. #   if ( $atk == $types[0] || ( @types > 1 && $atk == $types[1] ) )
  171. #   {
  172. #       $value *= 1.2;
  173. #   }
  174.     return $value;
  175. }
  176.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement