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.5 by elmex, Thu Feb 1 01:46:45 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);
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;
92} 116}
93 117
94cf::object->attach ( 118cf::object->attach (
95 type => cf::SKILL, 119 type => cf::SKILL,
96 subtype => cf::SK_JEWELER, 120 subtype => cf::SK_JEWELER,
119 143
120 } elsif ($msg =~ m/^\s*make\s*$/i) { 144 } elsif ($msg =~ m/^\s*make\s*$/i) {
121 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); 145 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}}));
122 146
123 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { 147 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
124 my $ingred = eval { $chdl->extract_jeweler_ingredients }; 148 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 149
133 unless ($Jeweler::CFG->{conversions}->{lc $1}) { 150 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
134 $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); 151 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
135 return 152 return
136 } 153 }
142 159
143 } elsif ($msg =~ m/^\s*merge\s*$/i) { 160 } elsif ($msg =~ m/^\s*merge\s*$/i) {
144 merge ($chdl, $sk, $pl, 0); 161 merge ($chdl, $sk, $pl, 0);
145 162
146 } else { 163 } else {
147 my $ingred = eval { $chdl->extract_jeweler_ingredients }; 164 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 165
156 my $plan = $ingred->get_plan; 166 my $plan = $ingred->get_plan;
157 167
158 if ($plan) { 168 if ($plan) {
159 my @ring = $ingred->get_ring; 169 my @ring = $ingred->get_ring;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines