#!/usr/bin/perl


$recall = <<EOF;
Assistant.Macros.IfAction|4|0|no metal here
Assistant.Macros.EndIfAction
Assistant.Macros.ExtCastSpellAction|32|4294967295
Assistant.Macros.WaitForTargetAction|30
Assistant.Macros.AbsoluteTargetAction|0|0|RUNE|0|7956
Assistant.Macros.PauseAction|00:00:02.0000000
// hide
Assistant.Macros.UseSkillAction|21
Assistant.Macros.PauseAction|00:00:00.4000000
Assistant.Macros.HotKeyAction|0|Play: Minax\\JUMPTO
EOF

@runes = ( "1138566913|45|66", "1138610365|56|66", "1138629052|67|66",
"1138640721|78|66", "1138652298|89|66", "1138667911|99|66",
"1138593811|45|81", "1138681180|56|80", "1138691050|67|80",
"1138691053|78|79", "1138691062|89|79", "1138720770|100|80"
);

#$homerune = $runes[0];
#$lastjump = "recall";
$homerune = "1167757948|141|66";
$lastjump = "done";

$minesome = <<EOF;
!Loop
// Mine here
Assistant.Macros.ForAction|10
Assistant.Macros.DoubleClickTypeAction|3897|True
Assistant.Macros.WaitForTargetAction|3
Assistant.Macros.TargetRelLocAction|MINEWHERE
Assistant.Macros.PauseAction|00:00:00.7000000
Assistant.Macros.IfAction|4|0|no metal here
// Mined out, try south
// Smelt
Assistant.Macros.ForAction|2
Assistant.Macros.DoubleClickTypeAction|6585|True
Assistant.Macros.PauseAction|00:00:00.2000000
Assistant.Macros.AbsoluteTargetAction|0|0|1154136256|30|78|0|3634
Assistant.Macros.PauseAction|00:00:00.3000000
Assistant.Macros.EndForAction
// Collect stone
Assistant.Macros.DoubleClickAction|1130627326|5995
Assistant.Macros.WaitForGumpAction|2633467501|False|300
Assistant.Macros.PauseAction|00:00:00.1000000
Assistant.Macros.GumpResponseAction|15|0|0
Assistant.Macros.ForAction|3
Assistant.Macros.PauseAction|00:00:00.4000000
Assistant.Macros.TargetTypeAction|False|6009
Assistant.Macros.EndForAction
// jump to south
Assistant.Macros.HotKeyAction|0|Play: Minax\\JUMPTO
Assistant.Macros.EndIfAction
Assistant.Macros.EndForAction
// smelt every 10 mining attempts
Assistant.Macros.ForAction|2
Assistant.Macros.DoubleClickTypeAction|6585|True
Assistant.Macros.PauseAction|00:00:00.2000000
Assistant.Macros.AbsoluteTargetAction|0|0|1154136256|30|78|0|3634
Assistant.Macros.PauseAction|00:00:00.3000000
Assistant.Macros.EndForAction
EOF

$minehere = "0|0";
$minesouth = "0|2";
$mineeast = "2|0";
$minesoutheast = "2|2";

$collect = <<EOF;
// Collect ore
Assistant.Macros.PauseAction|00:00:00.2000000
Assistant.Macros.DoubleClickAction|1154197366|5995
Assistant.Macros.WaitForGumpAction|4213074123|False|300
Assistant.Macros.PauseAction|00:00:00.1000000
Assistant.Macros.GumpResponseAction|15|0|0
Assistant.Macros.ForAction|5
Assistant.Macros.PauseAction|00:00:00.4000000
Assistant.Macros.TargetTypeAction|False|7154
Assistant.Macros.EndForAction
Assistant.Macros.PauseAction|00:00:00.2000000
// Collect stone
Assistant.Macros.DoubleClickAction|1130627326|5995
Assistant.Macros.WaitForGumpAction|2633467501|False|300
Assistant.Macros.PauseAction|00:00:00.1000000
Assistant.Macros.GumpResponseAction|15|0|0
Assistant.Macros.ForAction|3
Assistant.Macros.PauseAction|00:00:00.4000000
Assistant.Macros.TargetTypeAction|False|6009
Assistant.Macros.EndForAction
Assistant.Macros.PauseAction|00:00:00.2000000
Assistant.Macros.TargetRelLocAction|0|0
Assistant.Macros.PauseAction|00:00:00.4000000
Assistant.Macros.HotKeyAction|0|Play: Minax\\JUMPTO
EOF

$prefix="recall\\";
$count = 1;
foreach $rune (@runes) {
  open $f, ">m${count}recall.macro";
  $o = $recall;
  $o =~ s/RUNE/$rune/g;
  $o =~ s/JUMPTO/${prefix}m${count}minehere/g;
  print $f $o;
  close ($f);
  open $f, ">m${count}minehere.macro";
  $o = $minesome;
  $o =~ s/MINEWHERE/$minehere/g;
  $o =~ s/JUMPTO/${prefix}m${count}minesouth/g;
  print $f $o;
  close ($f);
  open $f, ">m${count}minesouth.macro";
  $o = $minesome;
  $o =~ s/MINEWHERE/$minesouth/g;
  $o =~ s/JUMPTO/${prefix}m${count}mineeast/g;
  print $f $o;
  close ($f);
  open $f, ">m${count}mineeast.macro";
  $o = $minesome;
  $o =~ s/MINEWHERE/$mineeast/g;
  $o =~ s/JUMPTO/${prefix}m${count}minesoutheast/g;
  print $f $o;
  close ($f);
  open $f, ">m${count}minesoutheast.macro";
  $o = $minesome;
  $o =~ s/MINEWHERE/$minesoutheast/g;
  $o =~ s/JUMPTO/${prefix}m${count}collect/g;
  print $f $o;
  close ($f);
  open $f, ">m${count}collect.macro";
  $o = $collect;
  $count ++;
  $o =~ s/JUMPTO/${prefix}m${count}recall/g;
  print $f $o;
  close ($f);
}
open $f, ">m${count}recall.macro";
$o = $recall;
$o =~ s/RUNE/$homerune/g;
$o =~ s/JUMPTO/${prefix}m1$lastjump/g;
print $f $o;
close ($f);

