ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/jeweler.ext
(Generate patch)

Comparing deliantra/server/ext/jeweler.ext (file contents):
Revision 1.5 by elmex, Thu Feb 1 01:46:45 2007 UTC vs.
Revision 1.24 by root, Thu Apr 29 07:52:01 2010 UTC

1#! perl 1#! perl
2 2
3use Data::Dumper; 3use strict;
4
4use Jeweler; 5use Jeweler;
5use List::Util qw/max min sum/; 6use List::Util qw/max min sum/;
6use strict;
7 7
8sub ingred_alias { 8sub ingred_alias {
9 my ($ing) = @_; 9 my ($ing) = @_;
10 10
11 my %aliases = ( 11 my %aliases = (
14 wis => 'wisdom', 14 wis => 'wisdom',
15 int => 'intelligence', 15 int => 'intelligence',
16 dex => 'dexterity', 16 dex => 'dexterity',
17 con => 'constitution', 17 con => 'constitution',
18 str => 'strength', 18 str => 'strength',
19 gem => 'diamond',
19 ); 20 );
20 21
21 if ($ing =~ m/resist_(\S+)/) { 22 if ($ing =~ m/resist_(\S+)/) {
22 my $a = $aliases{lc $1} || $1; 23 my $a = $aliases{lc $1} || $1;
23 "something for '". lc ($a). "' resistance"; 24 "something for '". lc ($a). "' resistance";
28 29
29 } elsif ($ing =~ m/spec_(\S+)/) { 30 } elsif ($ing =~ m/spec_(\S+)/) {
30 my $a = $aliases{lc $1} || $1; 31 my $a = $aliases{lc $1} || $1;
31 "something for the ". lc ($a). "' special"; 32 "something for the ". lc ($a). "' special";
32 33
34 } elsif ($aliases{$ing}) {
35 $aliases{$ing}
36
33 } else { 37 } else {
34 $ing 38 $ing
35 } 39 }
36} 40}
37 41
44 48
45 my @ring = $ingred->get_ring; 49 my @ring = $ingred->get_ring;
46 my @rings = map { Jeweler::Object->new (object => $_) } @ring; 50 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
47 51
48 @rings >= 2 52 @rings >= 2
49 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!"); 53 or return $pl->message ("You slap yourself, you forgot to put at least 2 jewels in!");
50 54
51 my $input_level; 55 my $input_level = 0;
56 my $value;
57 for (@rings) {
52 $input_level = max ($_->power_to_level, $input_level) for @rings; 58 $input_level = max ($_->power_to_level, $input_level);
59 $value += $_->{hash}->{value};
60 }
53 61
54 my $ring = shift @rings; 62 my $ring = shift @rings;
55 $ring->improve_by_ring (@rings); 63 $ring->improve_by_ring (@rings);
56 64
57 if ($do_analyze) { 65 if ($do_analyze) {
58 $pl->reply (undef, "You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl)); 66 $pl->message ("You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl, $input_level));
59 $ring->wiz_analyze ($pl) 67 $ring->wiz_analyze ($pl)
60 if $pl->flag (cf::FLAG_WIZ); 68 if $pl->flag (cf::FLAG_WIZ);
61 return; 69 return;
62 } 70 }
63 71
64 make_ring ($chdl, $ingred, $ring, $sk, $pl, $input_level); 72 make_ring ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level);
65} 73}
66 74
67sub make_ring { 75sub make_ring {
68 my ($chdl, $ingred, $ring, $sk, $pl, $input_level) = @_; 76 my ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level) = @_;
69 77
70 if (!$pl->flag (cf::FLAG_WIZ)) { 78 if (!$pl->flag (cf::FLAG_WIZ)) {
71 $ingred->remove ('rings'); 79 $ingred->remove ('rings');
72 $ingred->remove ('ammys'); 80 $ingred->remove ('ammys');
73 } 81 }
74 82
75 my $ch = $ring->get_chance_perc ($sk); 83 my $ch = $ring->get_chance_perc ($sk);
76 my $succ = 0; 84 my $succ = 0;
77 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); 85 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_LOW);
86
87 my $make_status;
88 my $exp;
78 89
79 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { 90 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) {
80 my $lvl = max ($ring->power_to_level, 1); 91 $exp = $ring->projected_exp ($input_level);
81 my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100;
82 92
83 if (defined $input_level) {
84 my $subexp =
85 (cf::level_to_min_exp ($input_level)
86 - cf::level_to_min_exp ($input_level - 1))
87 / 100;
88 warn "INPUT: $lvl <-> $input_level ($exp <-> $subexp)\n";
89 $exp -= $subexp;
90 $exp = max ($exp, 0);
91 }
92
93 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); 93 $pl->change_exp ($exp, "jeweler");
94 $pl->message ("You succeed and get $exp experience."); 94 $pl->message (
95 "You succeed and get " . int ($exp) . " experience points.");
96 $make_status = "succeeded";
97
98 $ring->set_value ($value);
99
95 } else { 100 } else {
96 $pl->message ("You fail!"); 101 $pl->message ("You fail!");
97 $ring->negate; 102 $ring->negate;
103 $make_status = "fail";
104 $exp = 0;
98 } 105 }
106
107 my $ring_ob = $ring->to_object;
108
109 { # some audit info calculation
110 my $sklvl = cf::exp_to_level ($sk->stats->exp);
111
112 my $make_info = sprintf
113 "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s",
114 $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl,
115 $ring->power_to_level, $exp, $make_status;
116
117 cf::debug "$make_info\n"
118 if $make_status eq 'succeeded';
119 }
120
99 $chdl->put ($ring->to_object); 121 $chdl->put ($ring_ob);
100} 122}
101 123
102sub get_ingred { 124sub get_ingred {
103 my ($pl, $chdl) = @_; 125 my ($pl, $chdl) = @_;
104 my $ingred = eval { $chdl->extract_jeweler_ingredients }; 126 my $ingred = eval { $chdl->extract_jeweler_ingredients };
107 return 129 return
108 } elsif ($@ =~ /unidentified/) { 130 } elsif ($@ =~ /unidentified/) {
109 $pl->message ("There are unidentified items in the workbench, identify them before you do anything."). 131 $pl->message ("There are unidentified items in the workbench, identify them before you do anything.").
110 return 132 return
111 } elsif ($@) { 133 } elsif ($@) {
112 warn "error in jeweler ingredient extraction: $@"; 134 cf::error "error in jeweler ingredient extraction: $@";
113 return; 135 return;
114 } 136 }
115 $ingred; 137 $ingred;
116} 138}
139
140cf::object::attachment check_ring_drop_on =>
141 on_drop_on => sub {
142 my ($self, $obj, $who) = @_;
143 my $cfg = $self->{check_ring_drop_on};
144 if ($obj->type == cf::RING
145 && !$obj->flag (cf::FLAG_CURSED)
146 && !$obj->flag (cf::FLAG_DAMNED)
147 ) {
148 my $ringo = Jeweler::Object->new (object => $obj);
149 for (grep { /^resist_/ } keys %$cfg) {
150 if (/^resist_(\S+)$/) {
151 if ($ringo->has_resist ($1)) {
152 $self->map->trigger (
153 $cfg->{connection},
154 $cfg->{state}
155 );
156 $obj->decrease (1);
157 cf::override;
158 }
159 }
160 }
161 }
162 };
117 163
118cf::object->attach ( 164cf::object->attach (
119 type => cf::SKILL, 165 type => cf::SKILL,
120 subtype => cf::SK_JEWELER, 166 subtype => cf::SK_JEWELER,
121 on_use_skill => sub { 167 on_use_skill => sub {
150 unless ($Jeweler::CFG->{conversions}->{lc $1}) { 196 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
151 $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); 197 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
152 return 198 return
153 } 199 }
154 200
155 Jeweler::simple_converter ($player, $ingred, $chdl, $1); 201 Jeweler::simple_converter (
202 $player, $ingred, $chdl, $1,
203 cf::exp_to_level ($sk->stats->exp));
156 204
157 } elsif ($msg =~ m/^\s*merge\s*analy[sz]e\s*$/i) { 205 } elsif ($msg =~ m/^\s*merge\s*analy[sz]e\s*$/i) {
158 merge ($chdl, $sk, $pl, 1); 206 merge ($chdl, $sk, $pl, 1);
159 207
160 } elsif ($msg =~ m/^\s*merge\s*$/i) { 208 } elsif ($msg =~ m/^\s*merge\s*$/i) {
166 my $plan = $ingred->get_plan; 214 my $plan = $ingred->get_plan;
167 215
168 if ($plan) { 216 if ($plan) {
169 my @ring = $ingred->get_ring; 217 my @ring = $ingred->get_ring;
170 218
219 if (!@ring) {
220 # actually the algorithm cant
221 $pl->message ("You slap yourself, you forgot the jewelery!");
222 return;
223
171 if ((@ring > 1) || ($ring[0]->nrof > 1)) { 224 } elsif ((@ring > 1) || (grep { $_->nrof > 1 } @ring)) {
172 # actually the algorithm cant handle more than one improvement at a time 225 # actually the algorithm cant handle more than one improvement at a time
173 $pl->message ("You can't manage to improve more than one thing at a time!"); 226 $pl->message ("You can't manage to improve more than one thing at a time!");
174 return; 227 return;
175
176 } elsif (@ring < 1) {
177 # actually the algorithm cant
178 $pl->message ("You slap yourself, you forgot the jewelery!");
179 return;
180
181 } else { 228 } else {
182 my $ringo = Jeweler::Object->new (object => $ring[0]); 229 my $ringo = Jeweler::Object->new (object => $ring[0]);
183 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); 230 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo);
184 my $c1 = $ringo->calc_costs; 231 my $c1 = $ringo->calc_costs;
185 my $c2 = $iring->calc_costs; 232 my $c2 = $iring->calc_costs;
233 my $value = $iring->calc_value_from_cost ($c2);
234
235 if ((not defined $c1) || (not defined $c2)) {
236 $pl->message ("The jewel has or will become a resistancy above 99%,\n"
237 ."that is completly impossible to make!");
238 return;
239 }
186 240
187 my %keys; 241 my %keys;
188 my %cdiff; 242 my %cdiff;
189 for (keys %$c1, keys %$c2) { $keys{$_} = 1 } 243 for (keys %$c1, keys %$c2) { $keys{$_} = 1 }
190 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; warn "$_: $c2->{$_} | $c1->{$_}\n"; } 244 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; }
191 245
192 unless ($iring->is_better_than ($ringo)) { 246 unless ($iring->is_better_than ($ringo)) {
193 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); 247 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed...");
194 return; 248 return;
195 } 249 }
208 } 262 }
209 } else { 263 } else {
210 if (!$pl->flag (cf::FLAG_WIZ)) { 264 if (!$pl->flag (cf::FLAG_WIZ)) {
211 $ingred->check_costs (\%cdiff, 1); 265 $ingred->check_costs (\%cdiff, 1);
212 } 266 }
213 make_ring ($chdl, $ingred, $iring, $sk, $pl); 267 make_ring ($chdl, $ingred, $iring, $value, $sk, $pl);
214 } 268 }
215 } 269 }
216 } else { 270 } else {
217 $pl->message ("You've got no idea what you are planning to do!"); 271 $pl->message ("You've got no idea what you are planning to do!");
218 } 272 }
219 } 273 }
220 }; 274 };
221 $@ and warn "ERROR: $@\n"; 275 $@ and cf::error "$@\n";
222 } 276 }
223); 277);
224 278
225Jeweler::read_config (cf::datadir . '/jeweler.yaml'); 279Jeweler::load_config;
280

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines