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.4 by elmex, Wed Jan 31 15:53:17 2007 UTC vs.
Revision 1.6 by elmex, Fri Feb 2 12:05:28 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 = eval { $chdl->extract_jeweler_ingredients }; 43 my $ingred = get_ingred ($pl, $chdl) || return;
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
52 my @ring = $ingred->get_ring; 45 my @ring = $ingred->get_ring;
53 my @rings = map { Jeweler::Object->new (object => $_) } @ring; 46 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
54 47
55 @rings >= 2 48 @rings >= 2
56 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!"); 49 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!");
50
51 my $input_level;
52 $input_level = max ($_->power_to_level, $input_level) for @rings;
57 53
58 my $ring = shift @rings; 54 my $ring = shift @rings;
59 $ring->improve_by_ring (@rings); 55 $ring->improve_by_ring (@rings);
60 56
61 if ($do_analyze) { 57 if ($do_analyze) {
63 $ring->wiz_analyze ($pl) 59 $ring->wiz_analyze ($pl)
64 if $pl->flag (cf::FLAG_WIZ); 60 if $pl->flag (cf::FLAG_WIZ);
65 return; 61 return;
66 } 62 }
67 63
68 make_ring ($chdl, $ingred, $ring, $sk, $pl); 64 make_ring ($chdl, $ingred, $ring, $sk, $pl, $input_level);
69} 65}
70 66
71sub make_ring { 67sub make_ring {
72 my ($chdl, $ingred, $ring, $sk, $pl) = @_; 68 my ($chdl, $ingred, $ring, $sk, $pl, $input_level) = @_;
73 69
74 if (!$pl->flag (cf::FLAG_WIZ)) { 70 if (!$pl->flag (cf::FLAG_WIZ)) {
75 $ingred->remove ('rings'); 71 $ingred->remove ('rings');
76 $ingred->remove ('ammys'); 72 $ingred->remove ('ammys');
77 } 73 }
78 74
79 my $ch = $ring->get_chance_perc ($sk); 75 my $ch = $ring->get_chance_perc ($sk);
80 my $succ = 0; 76 my $succ = 0;
81 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); 77 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH);
78
82 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { 79 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) {
83 my $lvl = max ($ring->power_to_level, 1); 80 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; 81 my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100;
82
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
85 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); 93 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY);
86 $pl->message ("You succeed and get $exp experience."); 94 $pl->message ("You succeed and get $exp experience.");
87 } else { 95 } else {
88 $pl->message ("You fail!"); 96 $pl->message ("You fail!");
89 $ring->negate; 97 $ring->negate;
90 } 98 }
91 $chdl->put ($ring->to_object); 99 $chdl->put ($ring->to_object);
92} 100}
101
102sub get_ingred {
103 my ($pl, $chdl) = @_;
104 my $ingred = eval { $chdl->extract_jeweler_ingredients };
105 if ($@ =~ /cursed/) {
106 $pl->message ("There are cursed items in the workbench, take them out before you do anything.").
107 return
108 } elsif ($@ =~ /unidentified/) {
109 $pl->message ("There are unidentified items in the workbench, identify them before you do anything.").
110 return
111 } elsif ($@) {
112 warn "error in jeweler ingredient extraction: $@";
113 return;
114 }
115 $ingred;
116}
117
118cf::object::attachment check_ring_drop_on =>
119 on_drop_on => sub {
120 my ($self, $obj, $who) = @_;
121 my $cfg = $self->{check_ring_drop_on};
122 if ($obj->type == cf::RING
123 && !$obj->flag (cf::FLAG_CURSED)
124 && !$obj->flag (cf::FLAG_DAMNED)
125 ) {
126 my $ringo = Jeweler::Object->new (object => $obj);
127 for (grep { /^resist_/ } keys %$cfg) {
128 if (/^resist_(\S+)$/) {
129 if ($ringo->has_resist ($1)) {
130 $self->map->trigger (
131 $cfg->{connection},
132 $cfg->{state}
133 );
134 cf::override;
135 }
136 }
137 }
138 }
139 };
93 140
94cf::object->attach ( 141cf::object->attach (
95 type => cf::SKILL, 142 type => cf::SKILL,
96 subtype => cf::SK_JEWELER, 143 subtype => cf::SK_JEWELER,
97 on_use_skill => sub { 144 on_use_skill => sub {
119 166
120 } elsif ($msg =~ m/^\s*make\s*$/i) { 167 } elsif ($msg =~ m/^\s*make\s*$/i) {
121 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); 168 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}}));
122 169
123 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { 170 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
124 my $ingred = eval { $chdl->extract_jeweler_ingredients }; 171 my $ingred = get_ingred ($pl, $chdl) || return;
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 172
133 unless ($Jeweler::CFG->{conversions}->{lc $1}) { 173 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
134 $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); 174 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
135 return 175 return
136 } 176 }
142 182
143 } elsif ($msg =~ m/^\s*merge\s*$/i) { 183 } elsif ($msg =~ m/^\s*merge\s*$/i) {
144 merge ($chdl, $sk, $pl, 0); 184 merge ($chdl, $sk, $pl, 0);
145 185
146 } else { 186 } else {
147 my $ingred = eval { $chdl->extract_jeweler_ingredients }; 187 my $ingred = get_ingred ($pl, $chdl) || return;
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 188
156 my $plan = $ingred->get_plan; 189 my $plan = $ingred->get_plan;
157 190
158 if ($plan) { 191 if ($plan) {
159 my @ring = $ingred->get_ring; 192 my @ring = $ingred->get_ring;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines