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

Comparing deliantra/maps/perl/jeweler.ext (file contents):
Revision 1.5 by elmex, Thu Aug 31 00:58:17 2006 UTC vs.
Revision 1.12 by root, Thu Oct 5 19:10:42 2006 UTC

1#! perl 1#! perl
2#CONVERSION: NONE 2
3use Data::Dumper; 3use Data::Dumper;
4use Jeweler; 4use Jeweler;
5use List::Util qw/max min sum/; 5use List::Util qw/max min sum/;
6use strict; 6use strict;
7 7
35 } 35 }
36} 36}
37 37
38my $DEBUG = 1; 38my $DEBUG = 1;
39 39
40sub merge {
41 my ($chdl, $sk, $pl, $do_analyze) = @_;
42
43 my $ingred = $chdl->extract_jeweler_ingredients;
44 my @ring = $ingred->get_ring;
45 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
46
47 @rings >= 2
48 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!");
49
50 my $ring = shift @rings;
51 $ring->improve_by_ring (@rings);
52
53 if ($do_analyze) {
54 $pl->reply (undef, "You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl));
55 $ring->wiz_analyze ($pl)
56 if $pl->flag (cf::FLAG_WIZ);
57 return;
58 }
59
60 make_ring ($chdl, $ingred, $ring, $sk, $pl);
61}
62
63sub make_ring {
64 my ($chdl, $ingred, $ring, $sk, $pl) = @_;
65
66 if (!$pl->flag (cf::FLAG_WIZ)) {
67 $ingred->remove ('rings');
68 $ingred->remove ('ammys');
69 }
70
71 my $ch = $ring->get_chance_perc ($sk);
72 my $succ = 0;
73 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH);
74 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) {
75 my $lvl = max ($ring->power_to_level, 1);
76 my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100;
77 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY);
78 $pl->message ("You succeed and get $exp experience.");
79 } else {
80 $pl->message ("You fail!");
81 $ring->negate;
82 }
83 $chdl->put ($ring->to_object);
84}
85
40cf::attach_to_type cf::SKILL, cf::SK_JEWELER, 86cf::attach_to_type cf::SKILL, cf::SK_JEWELER,
41 on_use_skill => sub { 87 on_use_skill => sub {
42 my ($sk, $ob, $part, $dir, $msg) = @_; 88 my ($sk, $ob, $part, $dir, $msg) = @_;
43 my $pl = $ob; 89 my $pl = $ob;
44 warn "USE SKILL JEWEL[$msg]!\n";
45 90
46 my $skobj = $sk; 91 my $skobj = $sk;
47 92
48 my $chdl = new Jeweler::CauldronHandler; 93 my $chdl = new Jeweler::CauldronHandler;
49 94
61 cf::override; 106 cf::override;
62 107
63 if ($msg =~ m/^\s*analy[sz]e\s*$/i) { 108 if ($msg =~ m/^\s*analy[sz]e\s*$/i) {
64 Jeweler::analyze ($sk, $chdl, $pl); 109 Jeweler::analyze ($sk, $chdl, $pl);
65 110
111 } elsif ($msg =~ m/^\s*make\s*$/i) {
112 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}}));
113
66 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { 114 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
67 my $ingred = $chdl->extract_jeweler_ingredients; 115 my $ingred = $chdl->extract_jeweler_ingredients;
68 116
69 unless ($Jeweler::CFG->{conversions}->{lc $1}) { 117 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
70 $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); 118 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
71 return 119 return
72 } 120 }
73 121
74 simple_converter ($player, $ingred, $chdl, $1); 122 Jeweler::simple_converter ($player, $ingred, $chdl, $1);
123
124 } elsif ($msg =~ m/^\s*merge\s*analy[sz]e\s*$/i) {
125 merge ($chdl, $sk, $pl, 1);
126
75 } elsif ($msg =~ m/^\s*merge\s*$/i) { 127 } elsif ($msg =~ m/^\s*merge\s*$/i) {
76 my $ingred = $chdl->extract_jeweler_ingredients; 128 merge ($chdl, $sk, $pl, 0);
77 my @ring = $ingred->get_ring;
78 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
79
80 my $ring = shift @rings;
81 $ring->improve_by_ring (@rings);
82 $ring->power_to_level;
83 129
84 } else { 130 } else {
85 my $ingred = $chdl->extract_jeweler_ingredients; 131 my $ingred = $chdl->extract_jeweler_ingredients;
86 my $plan = $ingred->get_plan; 132 my $plan = $ingred->get_plan;
87 133
88 if ($plan) { 134 if ($plan) {
89 my @ring = $ingred->get_ring; 135 my @ring = $ingred->get_ring;
90 136
91 if (@ring > 1) { 137 if ((@ring > 1) || ($ring[0]->nrof > 1)) {
92 # actually the algorithm cant handle more than one improvement at a time 138 # actually the algorithm cant handle more than one improvement at a time
93 $pl->message ("You can't manage to improve more than one ring!"); 139 $pl->message ("You can't manage to improve more than one thing at a time!");
140 return;
94 141
95 } elsif (@ring < 1) { 142 } elsif (@ring < 1) {
96 # actually the algorithm cant 143 # actually the algorithm cant
97 $pl->message ("You slap yourself, you forgot the ring!"); 144 $pl->message ("You slap yourself, you forgot the jewelery!");
145 return;
98 146
99 } else { 147 } else {
100 my $ringo = Jeweler::Object->new (object => $ring[0]); 148 my $ringo = Jeweler::Object->new (object => $ring[0]);
101 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); 149 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo);
102 my $c1 = $ringo->calc_costs; 150 my $c1 = $ringo->calc_costs;
103 my $c2 = $iring->calc_costs; 151 my $c2 = $iring->calc_costs;
104 152
105 my %keys; 153 my %keys;
106 my %cdiff; 154 my %cdiff;
107 for (keys %$c1, keys %$c2) { $keys{$_} = 1 } 155 for (keys %$c1, keys %$c2) { $keys{$_} = 1 }
108 warn 'COSTS[' . (join ",", map { $cdiff{$_} = $c2->{$_} - $c1->{$_}; "$_: $cdiff{$_}" } keys %keys) . "]\n"; 156 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_} }
109 157
110 unless (grep { $_ > 0 } values %cdiff) { 158 unless (grep { $_ > 0 } values %cdiff) {
111 $pl->message ("This plan doesn't improve the ring, you find yourself puzzled about what you missed..."); 159 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed...");
112 return; 160 return;
113 } 161 }
114 162
115 my $remcosts = $ingred->check_costs (\%cdiff); 163 my $remcosts = $ingred->check_costs (\%cdiff);
116 warn 'REMCOSTS[' . (join ",", map { "$_: $remcosts->{$_}" } keys %$remcosts) . "]\n";
117 164
118 if (grep { $_ > 0 } values %$remcosts) { 165 if (grep { $_ > 0 } values %$remcosts) {
166 $pl->message ("You want to make a " . $iring->to_string . ": " . $iring->analyze ($sk, $pl));
119 $pl->message ("You recognize that you are short of: " 167 $pl->message ("You recognize that you are short of: "
120 . (join ", ", 168 . (join ", ",
121 map { my $cost = $remcosts->{$_}; $cost . " " . ($cost > 1 ? "times" : "time") . " " . ingred_alias ($_) } 169 map { my $cost = $remcosts->{$_}; $cost . " " . ($cost > 1 ? "times" : "time") . " " . ingred_alias ($_) }
122 grep { $remcosts->{$_} > 0 } keys %$remcosts)) 170 grep { $remcosts->{$_} > 0 } keys %$remcosts));
171
172 if ($pl->flag (cf::FLAG_WIZ)) {
173 $iring->wiz_analyze ($pl);
174 }
123 } else { 175 } else {
176 if (!$pl->flag (cf::FLAG_WIZ)) {
124 $ingred->check_costs (\%cdiff, 1); 177 $ingred->check_costs (\%cdiff, 1);
125 $ingred->remove ('rings'); 178 }
126 $ingred->remove ('ammys'); 179 make_ring ($chdl, $ingred, $iring, $sk, $pl);
127 $chdl->put ($iring->to_object);
128 $pl->message ("You succeed!");
129 } 180 }
130 } 181 }
131 } else { 182 } else {
132 $pl->message ("You've got no idea what you are planning to do!"); 183 $pl->message ("You've got no idea what you are planning to do!");
133 } 184 }
134 } 185 }
135 }; 186 };
136 $@ and warn "ERROR: $@\n"; 187 $@ and warn "ERROR: $@\n";
188 }
189;
137 190
138 my $r = cf::random_roll (0, 101, $pl, cf::PREFER_LOW);
139 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines