Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event macro slot system #2781

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions control/eventMacros.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

automacro test_slot1 {
Henrybk marked this conversation as resolved.
Show resolved Hide resolved
exclusive 1
InMap prontera
disabled 0
overrideAI 1
slot 1
call {
log This is working in slot 1 start
pause 1
do c hey
pause 1.5
log This is working in slot 1 end
}
}

automacro test_slot2 {
exclusive 1
InMap prontera
disabled 0
overrideAI 1
slot 2
call {
log This is working in slot 2 start
pause 1.5
do c there
pause 1
log This is working in slot 2 end
}
}

automacro test_slot3 {
exclusive 1
InMap prontera
disabled 0
overrideAI 1
slot 3
call {
log This is working in slot 3 start
pause 2
do c man
pause 0.5
log This is working in slot 3 end
}
}
5 changes: 2 additions & 3 deletions plugins/eventMacro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ TODO:

1 - Create more conditions, at least the same number as the old macro plugin had.
2 - Hook AI only when we are sure an automacro is to be activated.
3 - Make slot system for automacros and macros, so in each slot a macro can be run and a group of automacros can be checked (so multiple macros can be run at the same time).
4 - Transfer macro code check to parsing time.
5 - Review macro condition code parsing (old Parser.pm and Script.pm)
3 - Transfer macro code check to parsing time.
4 - Review macro condition code parsing (old Parser.pm and Script.pm)
32 changes: 23 additions & 9 deletions plugins/eventMacro/eventMacro.pl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ sub parseAndHook {
}
}


# TODO: fix the command to work with slots
sub commandHandler {
### no parameter given
if (!defined $_[1]) {
Expand Down Expand Up @@ -218,6 +220,7 @@ sub commandHandler {
message( sprintf( "interruptible: %s\n", $macro->interruptible ), "list" );
message( sprintf( "orphan method: %s\n", $macro->orphan ), "list" );
message( sprintf( "remaining repeats: %s\n", $macro->repeat ), "list" );
message( sprintf( "slot: %s\n", $macro->slot ), "list" );
message( sprintf( "macro delay: %s\n", $macro->macro_delay ), "list" );

message( sprintf( "current command: %s\n", $macro->{current_line} ), "list" );
Expand Down Expand Up @@ -578,30 +581,41 @@ sub commandHandler {
### if nothing triggered until here it's probably a macro name
} elsif ( !$eventMacro->{Macro_List}->getByName( $arg ) ) {
error "[eventMacro] Macro $arg not found\n";
} elsif ( $eventMacro->{Macro_Runner} ) {
warning "[eventMacro] A macro is already running. Wait until the macro has finished or call 'eventMacro stop'\n";
return;

} else {
my $opt = {};
GetOptionsFromArray( \@params, $opt, 'repeat|r=i', 'overrideAI', 'exclusive', 'macro_delay=f', 'orphan=s' );
GetOptionsFromArray( \@params, $opt, 'repeat|r=i', 'slot=i', 'overrideAI', 'exclusive', 'macro_delay=f', 'orphan=s' );

my $slot = defined $opt->{slot} ? $opt->{slot} : 1;

if ( exists $eventMacro->{Macro_Runner}{$slot} ) {
warning "[eventMacro] A macro is already running in slot ".$slot.". Wait until the macro has finished or call 'eventMacro [".$slot."] stop'\n";
return;
}

$eventMacro->set_full_array( ".param", \@params );

$eventMacro->{Macro_Runner} = new eventMacro::Runner(
$eventMacro->{Macro_Runner}{$slot} = new eventMacro::Runner(
$arg,
defined $opt->{repeat} ? $opt->{repeat} : 1,
$slot,
defined $opt->{exclusive} ? $opt->{exclusive} ? 0 : 1 : undef,
defined $opt->{overrideAI} ? $opt->{overrideAI} : undef,
defined $opt->{orphan} ? $opt->{orphan} : undef,
undef,
defined $opt->{macro_delay} ? $opt->{macro_delay} : undef,
0
);

if ( defined $eventMacro->{Macro_Runner} ) {
$eventMacro->{AI_start_Macros_Running_Hook_Handle} = Plugins::addHook( 'AI_start', sub { $eventMacro->iterate_macro }, undef );
} else {

if (!defined $eventMacro->{Macro_Runner}{$slot}) {
error "[eventMacro] unable to create macro queue.\n";
delete $eventMacro->{Macro_Runner}{$slot};
return;
}

if (keys %{$eventMacro->{Macro_Runner}} == 1) {
my $iterate_macro_sub = sub { $eventMacro->iterate_macro(); };
$eventMacro->{AI_start_Macros_Running_Hook_Handle} = Plugins::addHook( 'AI_start', $iterate_macro_sub, undef );
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions plugins/eventMacro/eventMacro/Automacro.pm
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ sub set_parameters {
if (!defined $self->{parameters}{'repeat'}) {
$self->{parameters}{'repeat'} = 1;
}
if (!defined $self->{parameters}{'slot'}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a 1-based counting system (ie, there's no slot zero), you could do:

$self->{parameters}{'slot'} ||= 1;

$self->{parameters}{'slot'} = 1;
}
$self->{parameters}{time} = 0;
}

Expand Down
Loading