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

New priceid-sell plugin #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions interhack.pl
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,14 @@ sub print_ih_ttyrec
}

$topline = $vt->row_plaintext(1);
if ($vt->row_plaintext(2) =~ /--More--\s*$/){
$topline=~s/ *$/ /;
$topline.=$vt->row_plaintext(2);
$topline=~s/--More--\s*$//;
}elsif ($vt->row_plaintext(2) =~ /\[ynaq\] \([yn]\)\s*$/){
$topline=~s/ *$/ /;
$topline.=$vt->row_plaintext(2);
};
study $topline;

unless ($stop_sing_pass)
Expand Down
19 changes: 18 additions & 1 deletion plugins/priceid-buy.pl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@
'teleportation'],
500 => ['death', 'wishing'],
},
'boots' => {
10 => ['elven', 'kicking'],
30 => ['fumble', 'levitation'],
50 => ['jumping', 'speed', 'water walking'],
},
'helmet' => {
10 => ['plain'],
50 => ['brilliance', 'opp.align', 'telepathy'],
},
'gloves' => {
8 => ['leather'],
50 => ['dexterity', 'fumbling', 'power'],
},
'cloak' => {
50 => ['displacement', 'protection'],
60 => ['invisibility', 'magic resistance'],
},
);

our $shirt = 0;
Expand Down Expand Up @@ -132,7 +149,7 @@ sub calc_base
"\e\e#name\ny$letter$buc\n";
};

make_tab qr/^(?:You have a little trouble lifting )?(.) - (an?|\d+) (?:blessed |uncursed |cursed )?(.*?) ?(scroll|potion|wand|ring|spellbook)s? (?:(?:called |labeled )(.*?) ?)?\(unpaid, (\d+) zorkmids?\)\./
make_tab qr/^(?:You have a little trouble lifting )?(.) - (an?|\d+) (?:blessed |uncursed |cursed )?(?:pair of )?(.*?) ?(scroll|potion|wand|ring|spellbook|boots|helmet|gloves)s? (?:(?:called |labeled )(.*?) ?)?\(unpaid, (\d+) zorkmids?\)\./
=> sub
{
my ($letter, $count, $appearance, $type, $existing, $cost)
Expand Down
72 changes: 72 additions & 0 deletions plugins/priceid-sell.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Does price-identification when selling

# Options:
# $sell_id_tab=1 - makes TAB name the item (not very tested yet)
# $sell_id_uniq=1 - makes TAB pickup and drop the item again
# iff the price quote is not unique.

include "priceid-buy";

our ($sell_id_tab,$sell_id_uniq);

sub getslot {
if (alphakeys(-2) eq "d"){
return alphakeys(-1);
};
if (alphakeys(-3) eq "d" && alphakeys(-1) eq " "){
return alphakeys(-2);
};
return "-";
}


sub do_sell_id {
my ($amount,$appearance,$type)=@_;
my $slot=getslot();

my %obj=%{$price_table{$type}};

my (@prices,@possibilities);
for my $price (keys %obj){
my $sale=int ($price /2);
$sale = int ($price/3) if ($role eq 'Tou' && $xlvl <= 15) || $shirt;
if ($amount == $sale){
push @prices,$price;
push @possibilities, @{$short_names{$type}{$price}||$obj{$price}};
};
$sale=int($sale*3/4 +0.5); # round up
if ($amount == $sale){
push @prices,$price;
push @possibilities, @{$short_names{$type}{$price}||$obj{$price}};
};
};
my $cost=join"/",@prices;
$cost=~ s/00//g if ($type eq "spellbook");
my $name;
if (@possibilities <= 3){
$name =join '/', @possibilities;
} else {
$name = $cost;
};

my $txt="SELL-ID: $type($appearance) $name";
if ($sell_id_tab && $slot =~ /^[a-zA-Z]$/){
if(@prices == 2 && $sell_id_uniq){
$tab="\e,\ed${slot} ";
$txt.=" [TAB to try again]";
}else{
$tab="\e,\e#name\nn${slot}${appearance} ${name}\n";
$txt.=" [TAB to name it]";
};
if(!$sell_id_tab_nice){
$txt="Press tab to send the string: $tab";
$txt =~ s/\n/\\n/g;
$txt =~ s/\e/\\e/g;
};
}
annotate($txt);
};

each_match qr/offers (\d+) gold pieces for your (\w+) (spellbook|potion|ring|wand)\. +Sell it\?/ => sub { do_sell_id($1,$2,$3) };

each_match qr/offers (\d+) gold pieces for your (scroll) labeled (.*?)\. +Sell it\?/ => sub { do_sell_id($1,$3,$2) };