Last active
February 3, 2021 16:39
-
-
Save cydh/cd1c3b5b68f21360488d10db05c2bcd5 to your computer and use it in GitHub Desktop.
A function to solve message with <ITEML> contents from item link feature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Solve message that contains <ITEML> to kore-style item name | |
sub solveITEML { | |
my ($msg) = @_; | |
if ($msg =~ /<ITEML>([a-zA-Z0-9\%\&\(\,\+\*]*)<\/ITEML>/) { | |
my $newmsg = $msg; | |
$newmsg =~ s/<ITEML>([a-zA-Z0-9\%\&\(\,\+\*]*)<\/ITEML>/{itemlink}/g; # I don't really like this part | |
my (@items) = grep { $_; } $msg=~ /<ITEML>([a-zA-Z0-9\%\&\(\,\+\*]*)<\/ITEML>/g; | |
for my $item (@items) { | |
my $refine = 0; | |
my ($id, $class_num, $cardstr) = map { $_ } $item =~ /([\d\w%]*)&([\d\w]+)(.*)/; | |
if ($id =~ /([\d\w]*)%([\d\w]+)/) { | |
$id = $1; | |
$refine = $2; | |
} | |
if ($id =~ /([\d\w]{5})(\d)([\d\w]+)/) { | |
$id = $3; | |
} | |
my $item_info = { | |
nameID => fromBase62($id), | |
upgrade => fromBase62($refine), | |
}; | |
if ($cardstr ne "") { | |
my (@cards, @randopts) = undef; | |
if ($cardstr =~ /\(([a-zA-Z0-9\(]*)\*(.*)/) { # (c0(c1(c2(c3*o0+p0,v0*o1+p1,v1*o2+p2,v2*o3+p3,v3*o4+p4,v4 | |
my @str = ($1, $2); | |
(@cards) = split(/\(/, @str[0]); | |
foreach my $opt (split(/\*/, @str[1])) { | |
my ($type, $param, $value) = $opt =~ /([a-zA-Z0-9]+)\+([a-zA-Z0-9]+),([a-zA-Z0-9]+)/; # the order from client is type-param-value | |
my $packed = pack 'vvC', ( fromBase62($type), fromBase62($value), fromBase62($param) ); # the itemName need packedstring as type-value-param | |
push @randopts,{ packed => $packed }; | |
} | |
} else { | |
(@cards) = map { $_; } $cardstr =~ /\(([\d\w]+)/g; | |
} | |
if (scalar(@cards) > 0) { | |
$item_info->{cards} = join '', map { pack('v',fromBase62($_)); } @cards; | |
} | |
if (scalar(@randopts) > 0) { | |
$item_info->{options} = join '', map { $_->{packed} } @randopts; | |
} | |
} | |
my $newitem = "<".itemName($item_info).">"; | |
$newmsg =~ s/\{itemlink\}/$newitem/; | |
} | |
return $newmsg; | |
} | |
return $msg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where should i put those script to?
please gv the path of file to put em im newbie thank you