The config key of "useSelf_skill"

Forum closed. All further discussion to be discussed at https://github.com/OpenKore/

Moderator: Moderators

Message
Author
sofax222
Developers
Developers
Posts: 214
Joined: 24 Nov 2010, 03:08
Noob?: Yes

The config key of "useSelf_skill"

#1 Post by sofax222 »

About the config key of "useSelf_skill", I make some changes in /src/AI.pm and /src/Misc.pm.
I add two attributes("nearMonsters" and "nearDist") into the config key of "useSelf_skill".

The description:
When I set the "useSelf_skill" for the "Endure" skill. I think the moment for using "Endure" on self should be before attacking or attacked (or even walking through some monsters). The conditions for using "Endure" on self should be how closed some specified monsters. So, I add the two attributes "nearMonsters" and "nearDist" into the config key of "useSelf_skill", and add some codes into /src/AI.pm and /src/Misc.pm.

the codes are:
the AI.pm:
(1) add a line before "ai_getAggressives". such as:

Code: Select all

...........
our @EXPORT = (
    qw/
    ai_clientSuspend
    ai_drop
    ai_follow
    ai_partyfollow
    ai_getNearMonster
    ai_getAggressives
    ai_getPlayerAggressives
    ai_getMonstersAttacking
................
(2) add a subroutine "ai_getNearMonster" befor "sub ai_getNearMonster", such as:

Code: Select all

sub ai_getNearMonster {
    my ($type, $party) = @_;
    my $dist = shift;
    my $wantArray = wantarray;
    my @agMonsters;
    $dist = 20 unless($dist);

    foreach my $monster (@{$monstersList->getItems()}) {
        my $control = Misc::mon_control($monster->name,$monster->{nameID}) if $type || !$wantArray;
        my $ID = $monster->{ID};
        if ($monster->distance() < $dist) {
            if ($wantArray) {
                # Function is called in array context
                push @agMonsters, $ID;
            }
        }
    }

    return @agMonsters;
}
the Misc.pm
Add lines with in the "checkSelfCondition" subroutime, near the line 3774 , such as:

Code: Select all

.......
    if ($config{$prefix . "_notWhileSitting"} > 0) { return 0 if ($char->{sitting}); }
    if ($config{$prefix . "_notInTown"} > 0) { return 0 if ($field->isCity); }

    if ($config{$prefix . "_nearMonsters"} && ($prefix =~ /useSelf_skill/i)) {
        my $exists;
        foreach (ai_getNearMonster($config{$prefix . "_nearDist"})) {
            if (existsInList($config{$prefix . "_nearMonsters"}, $monsters{$_}->name)) {
                $exists = 1;
                last;
            }
        }
        return 0 unless $exists;
    }

    if ($config{$prefix . "_monsters"} && !($prefix =~ /skillSlot/i) && !($prefix =~ /ComboSlot/i)) {
        my $exists;
        foreach (ai_getAggressives()) {
.......
May be there is some other solution with plugins !

User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: The config key of "useSelf_skill"

#2 Post by kLabMouse »

Nice Feature... but the Code should be moved to Plugin (is that could be done using current system), or saved for better day's.
As currently OpenKore is under heavy feature freeze before 2.1 Release.
the the Release day will be the day, when all the critical and logic bug's will be fixed. (check the list of bug reports).

Edit. Moved to Commit Queue

sofax222
Developers
Developers
Posts: 214
Joined: 24 Nov 2010, 03:08
Noob?: Yes

Re: The config key of "useSelf_skill"

#3 Post by sofax222 »

I am learning for writing plugins !
I will change the featrue into plugin, after I understand the plugin mechaism.

EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: The config key of "useSelf_skill"

#4 Post by EternalHarvest »

Example of adding self conditions with a plugin:
http://openkore.svn.sourceforge.net/vie ... iew=markup

sofax222
Developers
Developers
Posts: 214
Joined: 24 Nov 2010, 03:08
Noob?: Yes

Re: The config key of "useSelf_skill"

#5 Post by sofax222 »

Thank you very much !
I will try to add some plugin what like the sample !

Thanks again !

Locked