User Tools

Site Tools


user:meflin:scripts:charge.pl

This is a client side script to manage the charging and discharging of powercrystals. The crystals must be named c1 c2 c3 ect.

Set crystals=7 to how many crystals you are managing

Shrike made this one

Code

#!/usr/bin/perl
$|=1;
$crystals=7;
 
sub getstats()
{
  print "request stat hp\n";
  $input=<STDIN>;
  @stats=split(/ /,$input);
  $hp=@stats[3];
  $hpmax=@stats[4];
  $sp=@stats[5];
  $spmax=@stats[6];
  $gp=@stats[7];
  $gpmax=@stats[8];
  $food=@stats[9];
}
 
 
$mode=0;
$maxcounter=0;
 
$pointer=1;
while (1)
{
 
 
  sleep(1);
  getstats();
 
  if ($sp>=$spmax)
  {
	  $maxcounter+=1;
  }
  else
  {
	  $maxcounter=0;
  }
 
  if ($maxcounter==10)
  {
	  $mode=0;
	  print "draw 1 charging crystals\n";
          $pointer=1;
  }
 
  if ($sp<(($spmax/2)-5) && $mode !=3)
  {
	  $mode=1;
	  print "draw 1 discharging crystals\n";
          $pointer=1;
  }
 
 if ($pointer > $crystals)
 {
   $pointer=1;
 }
 
#charge mode
  if ($mode==0)
  {
	  for ($a=$pointer; $a<=$crystals; $a++)
	  {
		   if ($sp>=$spmax)
		   {
			   print "issue 1 1 apply c".$a."\n";
			   sleep(1);
			   getstats();
                           $pointer=$a;
		   }
	  }
	  if ($sp==$spmax)
	  {
		  $mode=2;
		  print "draw 1 charge comeplete\n";
	  }
  }
#discharge mode
  if ($mode==1)
  {
	  for ($a=$pointer; $a<=$crystals; $a++)
	  {
		   if ($sp<$spmax)
		   {
			   print "issue 1 1 apply c".$a."\n";
			   sleep(1);
			   getstats();
                           $pointer=$a;
		   }
	  }
	  if ($sp<$spmax)
	  {
                  $pointer=1;
	  }
  }
 
 
 
 
}
user/meflin/scripts/charge.pl.txt · Last modified: 2007/11/20 08:03 (external edit)