ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/jeweler.ext
Revision: 1.4
Committed: Wed Jan 31 15:53:17 2007 UTC (17 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.3: +26 -3 lines
Log Message:
Changed jeweler balancing and made values affordable.
And also don't allow cursed items in the workbench.

File Contents

# Content
1 #! perl
2
3 use Data::Dumper;
4 use Jeweler;
5 use List::Util qw/max min sum/;
6 use strict;
7
8 sub ingred_alias {
9 my ($ing) = @_;
10
11 my %aliases = (
12 pow => 'power',
13 cha => 'charisma',
14 wis => 'wisdom',
15 int => 'intelligence',
16 dex => 'dexterity',
17 con => 'constitution',
18 str => 'strength',
19 );
20
21 if ($ing =~ m/resist_(\S+)/) {
22 my $a = $aliases{lc $1} || $1;
23 "something for '". lc ($a). "' resistance";
24
25 } elsif ($ing =~ m/stat_(\S+)/) {
26 my $a = $aliases{lc $1} || $1;
27 "something for the ". lc ($a). " stat";
28
29 } elsif ($ing =~ m/spec_(\S+)/) {
30 my $a = $aliases{lc $1} || $1;
31 "something for the ". lc ($a). "' special";
32
33 } else {
34 $ing
35 }
36 }
37
38 my $DEBUG = 1;
39
40 sub merge {
41 my ($chdl, $sk, $pl, $do_analyze) = @_;
42
43 my $ingred = eval { $chdl->extract_jeweler_ingredients };
44 if ($@ =~ /cursed/) {
45 $pl->reply ("There are cursed items in the workbench, take them out before you do anything.").
46 return
47 } elsif ($@) {
48 warn "error in jeweler ingredient extraction: $@";
49 return;
50 }
51
52 my @ring = $ingred->get_ring;
53 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
54
55 @rings >= 2
56 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!");
57
58 my $ring = shift @rings;
59 $ring->improve_by_ring (@rings);
60
61 if ($do_analyze) {
62 $pl->reply (undef, "You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl));
63 $ring->wiz_analyze ($pl)
64 if $pl->flag (cf::FLAG_WIZ);
65 return;
66 }
67
68 make_ring ($chdl, $ingred, $ring, $sk, $pl);
69 }
70
71 sub make_ring {
72 my ($chdl, $ingred, $ring, $sk, $pl) = @_;
73
74 if (!$pl->flag (cf::FLAG_WIZ)) {
75 $ingred->remove ('rings');
76 $ingred->remove ('ammys');
77 }
78
79 my $ch = $ring->get_chance_perc ($sk);
80 my $succ = 0;
81 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH);
82 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) {
83 my $lvl = max ($ring->power_to_level, 1);
84 my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100;
85 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY);
86 $pl->message ("You succeed and get $exp experience.");
87 } else {
88 $pl->message ("You fail!");
89 $ring->negate;
90 }
91 $chdl->put ($ring->to_object);
92 }
93
94 cf::object->attach (
95 type => cf::SKILL,
96 subtype => cf::SK_JEWELER,
97 on_use_skill => sub {
98 my ($sk, $ob, $part, $dir, $msg) = @_;
99 my $pl = $ob;
100
101 my $skobj = $sk;
102
103 my $chdl = new Jeweler::CauldronHandler;
104
105 my $rv = 1;
106 eval {
107 $DEBUG = 1;
108
109 my $player = $ob->contr;
110
111 unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) {
112 return;
113 }
114
115 cf::override;
116
117 if ($msg =~ m/^\s*analy[sz]e\s*$/i) {
118 Jeweler::analyze ($sk, $chdl, $pl);
119
120 } elsif ($msg =~ m/^\s*make\s*$/i) {
121 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}}));
122
123 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
124 my $ingred = eval { $chdl->extract_jeweler_ingredients };
125 if ($@ =~ /cursed/) {
126 $pl->message ("There are cursed items in the workbench, take them out before you do anything.").
127 return
128 } elsif ($@) {
129 warn "error in jeweler ingredient extraction: $@";
130 return;
131 }
132
133 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
134 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
135 return
136 }
137
138 Jeweler::simple_converter ($player, $ingred, $chdl, $1);
139
140 } elsif ($msg =~ m/^\s*merge\s*analy[sz]e\s*$/i) {
141 merge ($chdl, $sk, $pl, 1);
142
143 } elsif ($msg =~ m/^\s*merge\s*$/i) {
144 merge ($chdl, $sk, $pl, 0);
145
146 } else {
147 my $ingred = eval { $chdl->extract_jeweler_ingredients };
148 if ($@ =~ /cursed/) {
149 $pl->message ("There are cursed items in the workbench, take them out before you do anything.").
150 return
151 } elsif ($@) {
152 warn "error in jeweler ingredient extraction: $@";
153 return;
154 }
155
156 my $plan = $ingred->get_plan;
157
158 if ($plan) {
159 my @ring = $ingred->get_ring;
160
161 if ((@ring > 1) || ($ring[0]->nrof > 1)) {
162 # actually the algorithm cant handle more than one improvement at a time
163 $pl->message ("You can't manage to improve more than one thing at a time!");
164 return;
165
166 } elsif (@ring < 1) {
167 # actually the algorithm cant
168 $pl->message ("You slap yourself, you forgot the jewelery!");
169 return;
170
171 } else {
172 my $ringo = Jeweler::Object->new (object => $ring[0]);
173 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo);
174 my $c1 = $ringo->calc_costs;
175 my $c2 = $iring->calc_costs;
176
177 my %keys;
178 my %cdiff;
179 for (keys %$c1, keys %$c2) { $keys{$_} = 1 }
180 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; warn "$_: $c2->{$_} | $c1->{$_}\n"; }
181
182 unless ($iring->is_better_than ($ringo)) {
183 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed...");
184 return;
185 }
186
187 my $remcosts = $ingred->check_costs (\%cdiff);
188
189 if (grep { $_ > 0 } values %$remcosts) {
190 $pl->message ("You want to make a " . $iring->to_string . ": " . $iring->analyze ($sk, $pl));
191 $pl->message ("You recognize that you are short of: "
192 . (join ", ",
193 map { my $cost = $remcosts->{$_}; $cost . " " . ($cost > 1 ? "times" : "time") . " " . ingred_alias ($_) }
194 grep { $remcosts->{$_} > 0 } keys %$remcosts));
195
196 if ($pl->flag (cf::FLAG_WIZ)) {
197 $iring->wiz_analyze ($pl);
198 }
199 } else {
200 if (!$pl->flag (cf::FLAG_WIZ)) {
201 $ingred->check_costs (\%cdiff, 1);
202 }
203 make_ring ($chdl, $ingred, $iring, $sk, $pl);
204 }
205 }
206 } else {
207 $pl->message ("You've got no idea what you are planning to do!");
208 }
209 }
210 };
211 $@ and warn "ERROR: $@\n";
212 }
213 );
214
215 Jeweler::read_config (cf::datadir . '/jeweler.yaml');