| 1 |
elmex |
1.1 |
#!perl # mandatory |
| 2 |
|
|
|
| 3 |
|
|
our $WAIT_TIME = 5 * 60; # 4 minutes |
| 4 |
|
|
# the max price is base_price * 1.5 |
| 5 |
|
|
our $MAX_BASE_PRICE = 100 * 100 * 50; # 70 platinum (for lvl 115 players) |
| 6 |
|
|
our $MIN_BASE_PRICE = 100 * 10; # 10 gold |
| 7 |
|
|
|
| 8 |
|
|
sub calc_player_price { |
| 9 |
|
|
my ($name) = @_; |
| 10 |
|
|
|
| 11 |
|
|
if (my $player = cf::player::find $name) { |
| 12 |
|
|
my $price = ($player->ob->level / 115) * ($MAX_BASE_PRICE - $MIN_BASE_PRICE); |
| 13 |
|
|
return $MIN_BASE_PRICE + $price; |
| 14 |
|
|
|
| 15 |
|
|
} else { |
| 16 |
|
|
return $MIN_BASE_PRICE |
| 17 |
|
|
} |
| 18 |
|
|
} |
| 19 |
|
|
|
| 20 |
|
|
sub calc_text_price_ratio { |
| 21 |
|
|
my ($txt) = @_; |
| 22 |
|
|
|
| 23 |
|
|
my $some_constant = 111; |
| 24 |
|
|
|
| 25 |
|
|
my $cnt = 0; |
| 26 |
|
|
for (map ord $_, split //, $txt) { |
| 27 |
|
|
$cnt++; |
| 28 |
|
|
$cnt = $cnt % $some_constant; |
| 29 |
|
|
} |
| 30 |
|
|
|
| 31 |
|
|
my $ratio = (($some_constant - $cnt) / (2 * $some_constant)) + 1.0; |
| 32 |
|
|
$ratio |
| 33 |
|
|
} |
| 34 |
|
|
|
| 35 |
|
|
cf::register_script_function "gravedigger::buy_gravestones" => sub { |
| 36 |
|
|
my ($who, $msg, $npc) = @_; |
| 37 |
|
|
|
| 38 |
|
|
if ($who->flag (cf::FLAG_WIZ)) { |
| 39 |
|
|
delete $who->{gravedigger_last_time}; |
| 40 |
|
|
} |
| 41 |
|
|
|
| 42 |
|
|
if (defined $who->{gravedigger_last_time}) { |
| 43 |
|
|
my $waittime = time - $who->{gravedigger_last_time}; |
| 44 |
|
|
if ($waittime < $WAIT_TIME) { |
| 45 |
|
|
$who->reply ($npc, |
| 46 |
|
|
"I'm sorry sir, you have to wait until I stored the " |
| 47 |
|
|
. "previous stone you sold. " |
| 48 |
|
|
. "H<You have to wait " |
| 49 |
|
|
. int ((($WAIT_TIME - $waittime) / 60) + 0.5) |
| 50 |
|
|
. " minutes.>"); |
| 51 |
|
|
return; |
| 52 |
|
|
} |
| 53 |
|
|
} |
| 54 |
|
|
|
| 55 |
|
|
my (@stones) = cf::match::match <<'MATCH', $who; |
| 56 |
elmex |
1.2 |
(type=SIGN and { $_->msg =~ /hero.*killed.*by/si }) in inv |
| 57 |
elmex |
1.1 |
MATCH |
| 58 |
|
|
unless (@stones) { |
| 59 |
|
|
$who->reply ($npc, |
| 60 |
|
|
"I'm sorry sir, but you don't have any gravestones with you " |
| 61 |
elmex |
1.2 |
. "I'm interested in! " |
| 62 |
|
|
. "H<He is only interested in gravestones caused by player deaths.>"); |
| 63 |
elmex |
1.1 |
return; |
| 64 |
|
|
} |
| 65 |
|
|
|
| 66 |
|
|
cf::async { |
| 67 |
|
|
my $ston = $stones[0]; |
| 68 |
|
|
|
| 69 |
|
|
next unless $ston->msg =~ /the hero (\S+).*killed\s+by (.*)/s; |
| 70 |
|
|
my $player = $1; |
| 71 |
|
|
my $reason = $2; |
| 72 |
|
|
$reason =~ s/\.$//; |
| 73 |
|
|
$reason =~ s/\n+//g; |
| 74 |
|
|
|
| 75 |
|
|
my $player_price = calc_player_price ($player) |
| 76 |
|
|
or return; |
| 77 |
|
|
my $text_price_ratio = calc_text_price_ratio ($ston->msg); |
| 78 |
|
|
my $price = int ($player_price *= $text_price_ratio); |
| 79 |
|
|
|
| 80 |
|
|
$ston->decrease (1) |
| 81 |
|
|
unless $who->flag (cf::FLAG_WIZ); |
| 82 |
|
|
|
| 83 |
|
|
$who->pay_player ($price); |
| 84 |
|
|
|
| 85 |
|
|
my $price_txt = cf::cost_string_from_value $price; |
| 86 |
|
|
$who->reply ($npc, |
| 87 |
|
|
"I gave you $price_txt for the gravestone of " |
| 88 |
|
|
. $player |
| 89 |
|
|
. ". Poor fellow, $reason can be tricky..."); |
| 90 |
|
|
|
| 91 |
|
|
$who->{gravedigger_last_time} = time; |
| 92 |
|
|
}; |
| 93 |
|
|
|
| 94 |
|
|
$who->reply ($npc, "Let me have a look..."); |
| 95 |
|
|
}; |