ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/gravedigger.ext
Revision: 1.1
Committed: Sat Mar 20 14:57:58 2010 UTC (14 years, 2 months ago) by elmex
Branch: MAIN
Log Message:
added grave digger.

File Contents

# User Rev Content
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     (type=SIGN and { warn "MSG" . $_->msg; $_->msg =~ /hero.*killed.*by/si }) in inv
57     MATCH
58     unless (@stones) {
59     $who->reply ($npc,
60     "I'm sorry sir, but you don't have any gravestones with you "
61     . "I'm interested in!");
62     return;
63     }
64    
65     cf::async {
66     my $ston = $stones[0];
67    
68     next unless $ston->msg =~ /the hero (\S+).*killed\s+by (.*)/s;
69     my $player = $1;
70     my $reason = $2;
71     $reason =~ s/\.$//;
72     $reason =~ s/\n+//g;
73    
74     my $player_price = calc_player_price ($player)
75     or return;
76     my $text_price_ratio = calc_text_price_ratio ($ston->msg);
77     my $price = int ($player_price *= $text_price_ratio);
78    
79     $ston->decrease (1)
80     unless $who->flag (cf::FLAG_WIZ);
81    
82     $who->pay_player ($price);
83    
84     my $price_txt = cf::cost_string_from_value $price;
85     $who->reply ($npc,
86     "I gave you $price_txt for the gravestone of "
87     . $player
88     . ". Poor fellow, $reason can be tricky...");
89    
90     $who->{gravedigger_last_time} = time;
91     };
92    
93     $who->reply ($npc, "Let me have a look...");
94     };