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 2 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
}
}
24 changes: 17 additions & 7 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,18 +581,24 @@ 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,
Expand All @@ -598,9 +607,10 @@ sub commandHandler {
0
);

if ( defined $eventMacro->{Macro_Runner} ) {
$eventMacro->{AI_start_Macros_Running_Hook_Handle} = Plugins::addHook( 'AI_start', sub { $eventMacro->iterate_macro }, undef );
if ( defined $eventMacro->{Macro_Runner}{$slot} ) {
$eventMacro->{AI_start_Macros_Running_Hook_Handle}{$slot} = Plugins::addHook( 'AI_start', sub { $eventMacro->iterate_macro($slot) }, undef );
} else {
delete $eventMacro->{Macro_Runner}{$slot};
error "[eventMacro] unable to create macro queue.\n";
}
}
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