ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/maps/perl/bonus.ext
Revision: 1.6
Committed: Fri Dec 15 19:11:46 2006 UTC (17 years, 7 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +0 -0 lines
State: FILE REMOVED
Log Message:
move .ext to server

File Contents

# Content
1 #!perl
2 use List::Util qw/min/;
3
4 $cf::CFG{ext_bonus}
5 or return;
6
7 my $WC_BASE_VALUE = 15 * 5000; # 15r
8 my $AC_BASE_VALUE = 40 * 5000; # 40r
9 my $DAM_BASE_VALUE = 200; # 25p
10 my $MAGIC_BASE_VALUE = 100 * 5000; # 100r
11
12 my $MAX_LEVEL = cf::settings->max_level;
13
14 # maximum values of additions at $MAX_LEVEL difficulty
15 my $MAX_ADD_WC = 15;
16 my $MAX_ADD_AC = 5; # weapons should rather give wc than ac
17 my $MAX_ADD_DAM = 50;
18 my $MAX_ADD_MAGIC = 5;
19
20 # TODO: should become part of some stdlib
21 sub rand_range($$) {
22 $_[0] + ($_[1] - $_[0]) * rand
23 }
24
25 sub determine_weapon_value {
26 my ($weapon) = @_;
27
28 my $clone = $weapon->arch->clone;
29 my $value = $clone->value;
30
31 my $wc_diff = $weapon->stats->wc - $clone->stats->wc;
32 my $ac_diff = $weapon->stats->ac - $clone->stats->ac;
33 my $dam_diff = $weapon->stats->dam - $clone->stats->dam;
34
35 my $magic_diff = $weapon->magic - $clone->magic;
36
37 if ($wc_diff > 0) { $value += $WC_BASE_VALUE * 1.5 * $wc_diff * rand_range .5, 1 }
38 if ($ac_diff > 0) { $value += $AC_BASE_VALUE * 1.5 * $ac_diff * rand_range .5, 1 }
39 if ($dam_diff > 0) { $value += $DAM_BASE_VALUE * ($dam_diff ** 2.4) * rand_range .5, 1 }
40 if ($magic_diff > 0) { $value += $MAGIC_BASE_VALUE * 1.5 * $magic_diff * rand_range .5, 1 }
41
42 warn sprintf "WC DIFF: %3d, %3d, %3d, %3d | %10d = %10.3f r\n",
43 $dam_diff, $wc_diff, $ac_diff, $magic_diff, $value, $value / 5000
44 if $cf::CFG{ext_bonus_debug};
45
46 $weapon->value ($value);
47 }
48
49 cf::attach_to_type cf::WEAPON, 0,
50 on_add_bonus => sub {
51 my ($item, $creator, $diff, $max_magic, $flags) = @_;
52 return if $flags || !$creator;
53
54 $diff /= $MAX_LEVEL;
55
56 $item->stats->wc ($item->stats->wc + int $MAX_ADD_WC * (1 + rand) * $diff * rand_range .5, 1) if rand() <= 0.35;
57 $item->stats->ac ($item->stats->ac + int $MAX_ADD_AC * (1 + rand) * $diff * rand_range .5, 1) if rand() <= 0.2;
58 $item->stats->dam ($item->stats->dam + int $MAX_ADD_DAM * (1 + rand) * $diff * rand_range .5, 1) if rand() <= 0.7;
59 $item->magic ($item->magic + int $MAX_ADD_MAGIC * $diff * rand_range .5, 1) if rand() <= 0.2;
60
61 determine_weapon_value $item;
62
63 cf::override;
64 },
65 ;