Forge

Дополнения к OpenKore, расширяющиее её функциональность, называются плагинами.

Модератор: 4epT

Rumata
Грамотный
Сообщения: 235
Зарегистрирован: Ср фев 14, 2007 10:52 am

Сообщение Rumata »

Код: Выделить всё

############################################################
#
# Forge
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
# 


package Forge;

use strict;
use Plugins;
use Globals;
use Utils;
use Log qw(message error);
use Network::Send;

our ($Item, $VVVS, $ESt);

Plugins::register('Forge', 'Forge plugin by Falcon', \&Unload);
my $hooks = Plugins::addHooks(
                ['mainLoop_pre',\&checkTimeOut,undef],
                ['packet/forge_list', \&forge_list,undef],
                ['packet/arrowcraft_list', \&arrowcraft_list,undef]
);

my $cmd = Commands::register(
        ["forge", "forge command", \&cmdForge]
);



sub Unload {
        Commands::unregister($cmd);
        Plugins::delHooks($hooks);
};

sub cmdForge {
        my (undef,$args) = @_;
        my ($type,$useName,$Element);
        ($type, $useName, $Item, $VVVS ,$Element) = split(',', $args);
        $type =~ s/^\s+//g;
        $useName =~ s/^\s+//g;
        $Item =~ s/^\s+//g;
        $VVVS =~ s/^\s+//g;
        $Element =~ s/^\s+//g;

        if ((($type ne 'skill')&&($type ne 'item'))||($useName eq "")||($Item eq "")||($VVVS<0)||($VVVS>3)||(($Element)&&((!existsInList('fire,ice,wind,earth',$Element))||($VVVS>2)))) {
                error "Syntax Error in function 'forge'\n";
                error "Usage: forge <skill|item>,skill or forging item name,item to forge\n             [,num of Star Crumbs [,<fire|ice|wind|earth>]]\n";
                error "Ex: forge item,Oridecon Hammer,Sword,2,fire\n";
                return;
        };

        my $InventoryList = $char->inventory;
        my $Item;

        if($VVVS){
                $Item = $InventoryList->getByNameID(1000);
                if ((!defined $Item)||($Item->{amount}<$VVVS)){
                        error "Not enough Star Crumbs to forge.\n";
                        return 0;
                };
        };

        if ($Element eq 'fire') {
                $ESt = 994 # Flame Heart
        } elsif ($Element eq 'ice') {
                $ESt = 995 # Mystic Frozen
        } elsif ($Element eq 'wind') {
                $ESt = 997 # Rough Wind
        } elsif ($Element eq 'earth') {
                $ESt = 996 # Great Nature
        } else {
                $ESt = 0
        };

        if($ESt > 0){
                $Item = $InventoryList->getByNameID($ESt);
                if (!defined $Item){
                        error "You must have a ".$items_lut{$ESt}." to forge.\n";
                        return 0;
                };
        };

        if ($type eq 'skill') {
                my $forgeSkill = new Skill(auto => $useName);
                my $skillID=$forgeSkill->getIDN() || $useName;
                sendSkillUse($net, $skillID, 10, $accountID);
        } elsif ($type eq 'item') {          
                $Item = $InventoryList->getByName($useName) || $InventoryList->getByNameID($useName);      
                if(defined $Item){
                        sendItemUse($net, $Item->{index}, $accountID);
                } else {
                        error "You must have a ".$useName." to forge.\n";
                        return 0;
                };
        };
        $timeout{forge}{time} = time;
        AI::queue('Forge') if !(AI::action eq "Forge");
};

sub checkTimeOut {
  if(AI::action eq "Forge"){
    if(timeOut($timeout{forge}{time},2)){
      error 'Unable to forge '.$Item." (timeout)\n";
      sendForgeItem($net, 0, 0, 0, 0);
          sendArrowCraft($net,0);
      AI::dequeue;
    };
  };
};

sub forge_list {
  if(AI::action eq "Forge"){
    my (undef, $args) = @_;
    AI::dequeue;
    for (my $i = 4; $i < $args->{RAW_MSG_SIZE}; $i += 8) {
      my $viewID = unpack("v1", substr($args->{RAW_MSG}, $i, 2));
      if (($viewID eq $Item)||($items_lut{$viewID} eq $Item)) {
        my ($add1,$add2,$add3) = (0,0,0);
        if ($VVVS > 0) {$add1=1000;$add2=$ESt};
        if ($VVVS > 1) {$add2=1000;$add3=$ESt};
        if ($VVVS > 2) {$add3=1000}; #Star Crumb
        sendForgeItem($net, $viewID, $add1, $add2, $add3);
        return 0;
      };
    };
    error 'Unable to forge '.$Item." (absent in forge list)\n";
    sendForgeItem($net, 0, 0, 0, 0);
  };
};

sub arrowcraft_list {
  if(AI::action eq "Forge"){
    my (undef, $args) = @_;
    my $newmsg;
    my $msg = $args->{RAW_MSG};
    my $msg_size = $args->{RAW_MSG_SIZE};
    Network::Receive->decrypt(\$newmsg, substr($msg, 4));
    $msg = substr($msg, 0, 4).$newmsg;
    AI::dequeue;
    for (my $i = 4; $i < $msg_size; $i += 2) {
      my $viewID = unpack("v1", substr($msg, $i, 2));
      if (($viewID eq $Item)||($items_lut{$viewID} eq $Item)) {
        sendArrowCraft($net,$viewID);
        return 0;
      };
    };
    error 'Unable to forge '.$Item." (absent in craft list)\n";
   sendArrowCraft($net,0);
  };
};

1;
dvdc
Бывалый
Сообщения: 556
Зарегистрирован: Вс ноя 05, 2006 1:43 pm
Контактная информация:

Сообщение dvdc »

Rumata
Атлична!! :)
работает? проверял? :)
Rumata
Грамотный
Сообщения: 235
Зарегистрирован: Ср фев 14, 2007 10:52 am

Сообщение Rumata »

кузя мой месяц назад им кувал без проблем :)
Ответить