#!perl # mandatory our $WAIT_TIME = 5 * 60; # 4 minutes # the max price is base_price * 1.5 our $MAX_BASE_PRICE = 100 * 100 * 50; # 70 platinum (for lvl 115 players) our $MIN_BASE_PRICE = 100 * 10; # 10 gold sub calc_player_price { my ($name) = @_; if (my $player = cf::player::find $name) { my $price = ($player->ob->level / 115) * ($MAX_BASE_PRICE - $MIN_BASE_PRICE); return $MIN_BASE_PRICE + $price; } else { return $MIN_BASE_PRICE } } sub calc_text_price_ratio { my ($txt) = @_; my $some_constant = 111; my $cnt = 0; for (map ord $_, split //, $txt) { $cnt++; $cnt = $cnt % $some_constant; } my $ratio = (($some_constant - $cnt) / (2 * $some_constant)) + 1.0; $ratio } cf::register_script_function "gravedigger::buy_gravestones" => sub { my ($who, $msg, $npc) = @_; if ($who->flag (cf::FLAG_WIZ)) { delete $who->{gravedigger_last_time}; } if (defined $who->{gravedigger_last_time}) { my $waittime = time - $who->{gravedigger_last_time}; if ($waittime < $WAIT_TIME) { $who->reply ($npc, "I'm sorry sir, you have to wait until I stored the " . "previous stone you sold. " . "H"); return; } } my (@stones) = cf::match::match <<'MATCH', $who; (type=SIGN and { warn "MSG" . $_->msg; $_->msg =~ /hero.*killed.*by/si }) in inv MATCH unless (@stones) { $who->reply ($npc, "I'm sorry sir, but you don't have any gravestones with you " . "I'm interested in!"); return; } cf::async { my $ston = $stones[0]; next unless $ston->msg =~ /the hero (\S+).*killed\s+by (.*)/s; my $player = $1; my $reason = $2; $reason =~ s/\.$//; $reason =~ s/\n+//g; my $player_price = calc_player_price ($player) or return; my $text_price_ratio = calc_text_price_ratio ($ston->msg); my $price = int ($player_price *= $text_price_ratio); $ston->decrease (1) unless $who->flag (cf::FLAG_WIZ); $who->pay_player ($price); my $price_txt = cf::cost_string_from_value $price; $who->reply ($npc, "I gave you $price_txt for the gravestone of " . $player . ". Poor fellow, $reason can be tricky..."); $who->{gravedigger_last_time} = time; }; $who->reply ($npc, "Let me have a look..."); };