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.8 by elmex, Tue Apr 10 17:09:13 2007 UTC vs.
Revision 1.25 by elmex, Mon May 10 15:42:06 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 = (
48 48
49 my @ring = $ingred->get_ring; 49 my @ring = $ingred->get_ring;
50 my @rings = map { Jeweler::Object->new (object => $_) } @ring; 50 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
51 51
52 @rings >= 2 52 @rings >= 2
53 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!");
54 54
55 my $input_level; 55 my $input_level = 0;
56 my $value; 56 my $value;
57 for (@rings) { 57 for (@rings) {
58 $input_level = max ($_->power_to_level, $input_level); 58 $input_level = max ($_->power_to_level, $input_level);
59 $value += $_->{hash}->{value}; 59 $value += $_->{hash}->{value};
60 } 60 }
61 61
62 my $ring = shift @rings; 62 my $ring = shift @rings;
63 $ring->improve_by_ring (@rings); 63 $ring->improve_by_ring (@rings);
64 64
65 if ($do_analyze) { 65 if ($do_analyze) {
66 $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));
67 $ring->wiz_analyze ($pl) 67 $ring->wiz_analyze ($pl)
68 if $pl->flag (cf::FLAG_WIZ); 68 if $pl->flag (cf::FLAG_WIZ);
69 return; 69 return;
70 } 70 }
71 71
80 $ingred->remove ('ammys'); 80 $ingred->remove ('ammys');
81 } 81 }
82 82
83 my $ch = $ring->get_chance_perc ($sk); 83 my $ch = $ring->get_chance_perc ($sk);
84 my $succ = 0; 84 my $succ = 0;
85 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); 85 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_LOW);
86 86
87 my $make_status; 87 my $make_status;
88 my $exp; 88 my $exp;
89 89
90 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { 90 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) {
91 my $lvl = max ($ring->power_to_level, 1); 91 $exp = $ring->projected_exp ($input_level);
92 $exp =
93 (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1))
94 / (10 + max ($lvl - 1, 0));
95 # divided by 10 + level
96 92
97 if (defined $input_level) {
98 my $subexp =
99 (cf::level_to_min_exp ($input_level)
100 - cf::level_to_min_exp ($input_level - 1))
101 / (10 + max ($input_level - 1, 0));
102 $exp -= $subexp;
103 $exp = max ($exp, 0);
104 }
105
106 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); 93 $pl->change_exp ($exp, "jeweler");
94 $pl->message (
107 $pl->message ("You succeed and get $exp experience points."); 95 "You succeed and get " . int ($exp) . " experience points.");
108 $make_status = "succeeded"; 96 $make_status = "succeeded";
109 97
110 $ring->set_value ($value * 0.8); # 20% of the input values will vanish 98 $ring->set_value ($value);
111 99
112 } else { 100 } else {
113 $pl->message ("You fail!"); 101 $pl->message ("You fail!");
114 $ring->negate; 102 $ring->negate;
115 $make_status = "fail"; 103 $make_status = "fail";
116 $exp = 0; 104 $exp = 0;
117 } 105 }
118 106
119 my $ring_ob = $ring->to_object; 107 my $ring_ob = $ring->to_object;
120 108
109 $ring_ob->kv_set (ext_jeweler_maker => $pl->name);
110
121 { # some audit info calculation 111 { # some audit info calculation
122 my $sklvl = cf::exp_to_level ($sk->stats->exp); 112 my $sklvl = cf::exp_to_level ($sk->stats->exp);
123 113
124 my $make_info = sprintf 114 my $make_info = sprintf
125 "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s", 115 "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s",
126 $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl, 116 $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl,
127 $ring->power_to_level, $exp, $make_status; 117 $ring->power_to_level, $exp, $make_status;
128 118
119 cf::debug "$make_info\n"
129 warn "$make_info\n" if $make_status eq 'succeeded'; 120 if $make_status eq 'succeeded';
130
131 $ring_ob->set_ob_key_value (ext_jeweler_made_by => $pl->name);
132 $ring_ob->set_ob_key_value (ext_jeweler_make_info => $make_info);
133 } 121 }
134 122
135 $chdl->put ($ring_ob); 123 $chdl->put ($ring_ob);
136} 124}
137 125
143 return 131 return
144 } elsif ($@ =~ /unidentified/) { 132 } elsif ($@ =~ /unidentified/) {
145 $pl->message ("There are unidentified items in the workbench, identify them before you do anything."). 133 $pl->message ("There are unidentified items in the workbench, identify them before you do anything.").
146 return 134 return
147 } elsif ($@) { 135 } elsif ($@) {
148 warn "error in jeweler ingredient extraction: $@"; 136 cf::error "error in jeweler ingredient extraction: $@";
149 return; 137 return;
150 } 138 }
151 $ingred; 139 $ingred;
152} 140}
153 141
165 if ($ringo->has_resist ($1)) { 153 if ($ringo->has_resist ($1)) {
166 $self->map->trigger ( 154 $self->map->trigger (
167 $cfg->{connection}, 155 $cfg->{connection},
168 $cfg->{state} 156 $cfg->{state}
169 ); 157 );
158 $obj->decrease (1);
170 cf::override; 159 cf::override;
171 } 160 }
172 } 161 }
173 } 162 }
174 } 163 }
209 unless ($Jeweler::CFG->{conversions}->{lc $1}) { 198 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
210 $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); 199 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
211 return 200 return
212 } 201 }
213 202
214 Jeweler::simple_converter ($player, $ingred, $chdl, $1); 203 Jeweler::simple_converter (
204 $player, $ingred, $chdl, $1,
205 cf::exp_to_level ($sk->stats->exp));
215 206
216 } elsif ($msg =~ m/^\s*merge\s*analy[sz]e\s*$/i) { 207 } elsif ($msg =~ m/^\s*merge\s*analy[sz]e\s*$/i) {
217 merge ($chdl, $sk, $pl, 1); 208 merge ($chdl, $sk, $pl, 1);
218 209
219 } elsif ($msg =~ m/^\s*merge\s*$/i) { 210 } elsif ($msg =~ m/^\s*merge\s*$/i) {
225 my $plan = $ingred->get_plan; 216 my $plan = $ingred->get_plan;
226 217
227 if ($plan) { 218 if ($plan) {
228 my @ring = $ingred->get_ring; 219 my @ring = $ingred->get_ring;
229 220
221 if (!@ring) {
222 # actually the algorithm cant
223 $pl->message ("You slap yourself, you forgot the jewelery!");
224 return;
225
230 if ((@ring > 1) || ($ring[0]->nrof > 1)) { 226 } elsif ((@ring > 1) || (grep { $_->nrof > 1 } @ring)) {
231 # actually the algorithm cant handle more than one improvement at a time 227 # actually the algorithm cant handle more than one improvement at a time
232 $pl->message ("You can't manage to improve more than one thing at a time!"); 228 $pl->message ("You can't manage to improve more than one thing at a time!");
233 return; 229 return;
234
235 } elsif (@ring < 1) {
236 # actually the algorithm cant
237 $pl->message ("You slap yourself, you forgot the jewelery!");
238 return;
239
240 } else { 230 } else {
241 my $ringo = Jeweler::Object->new (object => $ring[0]); 231 my $ringo = Jeweler::Object->new (object => $ring[0]);
242 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); 232 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo);
243 my $c1 = $ringo->calc_costs; 233 my $c1 = $ringo->calc_costs;
244 my $c2 = $iring->calc_costs; 234 my $c2 = $iring->calc_costs;
245 my $value = $iring->calc_value_from_cost ($c2); 235 my $value = $iring->calc_value_from_cost ($c2);
236
237 if ((not defined $c1) || (not defined $c2)) {
238 $pl->message ("The jewel has or will become a resistancy above 99%,\n"
239 ."that is completly impossible to make!");
240 return;
241 }
246 242
247 my %keys; 243 my %keys;
248 my %cdiff; 244 my %cdiff;
249 for (keys %$c1, keys %$c2) { $keys{$_} = 1 } 245 for (keys %$c1, keys %$c2) { $keys{$_} = 1 }
250 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; } 246 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; }
276 } else { 272 } else {
277 $pl->message ("You've got no idea what you are planning to do!"); 273 $pl->message ("You've got no idea what you are planning to do!");
278 } 274 }
279 } 275 }
280 }; 276 };
281 $@ and warn "ERROR: $@\n"; 277 $@ and cf::error "$@\n";
282 } 278 }
283); 279);
284 280
285Jeweler::read_config (cf::datadir . '/jeweler.yaml'); 281Jeweler::load_config;
282

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines