- ######################
- sub AnalyzeCommand {
- my ($sText) = @_;
- my $a = 0;
- my $match = "#IF\\(([^#]*)\\s+([^#]*)\\s+([^#]*)\\)\\{([^{}]*)\\}(\\{([^{}]*)\\})?";
- while (1) {
- $a++;
- if ($sText =~ /$match/) {
- my ($left, $compare, $right, $cmd, $cmd2) = ($1, $2, $3, $4, $6);
- if ($compare eq "<") {
- if (GetVariable($left) < $right) {
- $sText =~ s/$match/$4/;
- }
- else {
- $sText =~ s/$match/$cmd2/;
- }
- }
- elsif ($compare eq ">") {
- if (GetVariable($left) > $right) {
- $sText =~ s/$match/$4/;
- }
- else {
- $sText =~ s/$match/$cmd2/;
- }
- }
- elsif ($compare eq "=") {
- if (GetVariable($left) == $right) {
- $sText =~ s/$match/$4/;
- }
- else {
- $sText =~ s/$match/$cmd2/;
- }
- }
- elsif ($compare eq ">=") {
- if (GetVariable($left) >= $right) {
- $sText =~ s/$match/$4/;
- }
- else {
- $sText =~ s/$match/$cmd2/;
- }
- }
- elsif ($compare eq "<=") {
- if (GetVariable($left) <= $right) {
- $sText =~ s/$match/$4/;
- }
- else {
- $sText =~ s/$match/$cmd2/;
- }
- }
- }
- else {
- $sText =~ s/[{}]//g;
- last;
- }
- }
- my @splitedCommand = split(/;/, $sText);
- for my $index (0 .. $#splitedCommand) {
- my $command = $splitedCommand[$index];
- if ($command =~ /^#(\d+)\s+(.*)$/)
- # --------------------------------------------
- # Command: #3 fight bonze %i
- # Send: fight bonze
- # fight bonze 2
- # fight bonze 3
- # --------------------------------------------
- {
- my ($counts, $cmd) = ($1, $2);
- for (my $i = 1 ; $i <= $counts ; $i++) {
- my $curCmd = $cmd;
- $curCmd =~ s/\%i/$i/;
- AnalyzeCommand($curCmd);
- }
- }
- elsif ($command =~ /^#dis$/)
- # --------------------------------------------
- # Command: #dis
- # For Disconnect;
- # --------------------------------------------
- {
- Disconnect();
- }
- elsif ($command =~ /^#wa\s+(\d+)$/)
- # --------------------------------------------
- # Command: #wa 2000
- # Will send command after 2 second
- # --------------------------------------------
- {
- my $second = $1 / 1000;
- my $cmd = join ';', @splitedCommand[ ($index + 1) .. $#splitedCommand ];
- #$world->Note($cmd);
- #$world->Note("$priorCmd,$second,$cmd");
- $second = 0.1 if ($second < 0.1);
- $second = 86399 if ($second > 86399);
- DoAfterSpecial($second, "AnalyzeCommand("$cmd")", "12");
- last;
- }
- #elsif($command =~ /^set (\w+)=(.+)/)
- ## --------------------------------------------
- ## Command: #set var=value
- ## Will set a variable to value
- ## --------------------------------------------
- #{
- # if(SetVariable($1,$2) == 0){
- # Note("Set $1 to $2");
- # }else{
- # Note("Can not set $1 to $2");
- # }
- #}
- else {
- Execute($command);
- }
- }
- }
复制代码 在mush perl script 中不能加入中文.
so 沒寫什麼注釋...
[ 本帖最后由 vase 于 2010-1-19 01:22 AM 编辑 ] |