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.1 by root, Fri Dec 15 19:29:18 2006 UTC vs.
Revision 1.4 by elmex, Wed Jan 31 15:53:17 2007 UTC

38my $DEBUG = 1; 38my $DEBUG = 1;
39 39
40sub merge { 40sub merge {
41 my ($chdl, $sk, $pl, $do_analyze) = @_; 41 my ($chdl, $sk, $pl, $do_analyze) = @_;
42 42
43 my $ingred = $chdl->extract_jeweler_ingredients; 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
44 my @ring = $ingred->get_ring; 52 my @ring = $ingred->get_ring;
45 my @rings = map { Jeweler::Object->new (object => $_) } @ring; 53 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
46 54
47 @rings >= 2 55 @rings >= 2
48 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!"); 56 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!");
81 $ring->negate; 89 $ring->negate;
82 } 90 }
83 $chdl->put ($ring->to_object); 91 $chdl->put ($ring->to_object);
84} 92}
85 93
86cf::attach_to_type cf::SKILL, cf::SK_JEWELER, 94cf::object->attach (
95 type => cf::SKILL,
96 subtype => cf::SK_JEWELER,
87 on_use_skill => sub { 97 on_use_skill => sub {
88 my ($sk, $ob, $part, $dir, $msg) = @_; 98 my ($sk, $ob, $part, $dir, $msg) = @_;
89 my $pl = $ob; 99 my $pl = $ob;
90 100
91 my $skobj = $sk; 101 my $skobj = $sk;
92 102
93 my $chdl = new Jeweler::CauldronHandler; 103 my $chdl = new Jeweler::CauldronHandler;
94 104
95 my $rv = 1; 105 my $rv = 1;
96 eval { 106 eval {
97 Jeweler::read_config ($ENV{CROSSFIRE_LIBDIR} . '/jeweler.yaml');
98 $DEBUG = 1; 107 $DEBUG = 1;
99 108
100 my $player = $ob->contr; 109 my $player = $ob->contr;
101 110
102 unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) { 111 unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) {
110 119
111 } elsif ($msg =~ m/^\s*make\s*$/i) { 120 } elsif ($msg =~ m/^\s*make\s*$/i) {
112 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); 121 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}}));
113 122
114 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { 123 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
115 my $ingred = $chdl->extract_jeweler_ingredients; 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 }
116 132
117 unless ($Jeweler::CFG->{conversions}->{lc $1}) { 133 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
118 $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); 134 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
119 return 135 return
120 } 136 }
126 142
127 } elsif ($msg =~ m/^\s*merge\s*$/i) { 143 } elsif ($msg =~ m/^\s*merge\s*$/i) {
128 merge ($chdl, $sk, $pl, 0); 144 merge ($chdl, $sk, $pl, 0);
129 145
130 } else { 146 } else {
131 my $ingred = $chdl->extract_jeweler_ingredients; 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
132 my $plan = $ingred->get_plan; 156 my $plan = $ingred->get_plan;
133 157
134 if ($plan) { 158 if ($plan) {
135 my @ring = $ingred->get_ring; 159 my @ring = $ingred->get_ring;
136 160
151 my $c2 = $iring->calc_costs; 175 my $c2 = $iring->calc_costs;
152 176
153 my %keys; 177 my %keys;
154 my %cdiff; 178 my %cdiff;
155 for (keys %$c1, keys %$c2) { $keys{$_} = 1 } 179 for (keys %$c1, keys %$c2) { $keys{$_} = 1 }
156 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_} } 180 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; warn "$_: $c2->{$_} | $c1->{$_}\n"; }
157 181
158 unless (grep { $_ > 0 } values %cdiff) { 182 unless ($iring->is_better_than ($ringo)) {
159 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); 183 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed...");
160 return; 184 return;
161 } 185 }
162 186
163 my $remcosts = $ingred->check_costs (\%cdiff); 187 my $remcosts = $ingred->check_costs (\%cdiff);
184 } 208 }
185 } 209 }
186 }; 210 };
187 $@ and warn "ERROR: $@\n"; 211 $@ and warn "ERROR: $@\n";
188 } 212 }
189; 213);
190 214
215Jeweler::read_config (cf::datadir . '/jeweler.yaml');

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines