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.6 by elmex, Thu Aug 31 12:39:19 2006 UTC

39 39
40cf::attach_to_type cf::SKILL, cf::SK_JEWELER, 40cf::attach_to_type cf::SKILL, cf::SK_JEWELER,
41 on_use_skill => sub { 41 on_use_skill => sub {
42 my ($sk, $ob, $part, $dir, $msg) = @_; 42 my ($sk, $ob, $part, $dir, $msg) = @_;
43 my $pl = $ob; 43 my $pl = $ob;
44 warn "USE SKILL JEWEL[$msg]!\n"; 44 warn ($pl->name . " uses jeweler skill [$msg]!\n");
45 45
46 my $skobj = $sk; 46 my $skobj = $sk;
47 47
48 my $chdl = new Jeweler::CauldronHandler; 48 my $chdl = new Jeweler::CauldronHandler;
49 49
61 cf::override; 61 cf::override;
62 62
63 if ($msg =~ m/^\s*analy[sz]e\s*$/i) { 63 if ($msg =~ m/^\s*analy[sz]e\s*$/i) {
64 Jeweler::analyze ($sk, $chdl, $pl); 64 Jeweler::analyze ($sk, $chdl, $pl);
65 65
66 } elsif ($msg =~ m/^\s*make\s*$/i) {
67 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}}));
68
66 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { 69 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
67 my $ingred = $chdl->extract_jeweler_ingredients; 70 my $ingred = $chdl->extract_jeweler_ingredients;
68 71
69 unless ($Jeweler::CFG->{conversions}->{lc $1}) { 72 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
70 $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); 73 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
71 return 74 return
72 } 75 }
73 76
74 simple_converter ($player, $ingred, $chdl, $1); 77 Jeweler::simple_converter ($player, $ingred, $chdl, $1);
78
75 } elsif ($msg =~ m/^\s*merge\s*$/i) { 79 } elsif ($msg =~ m/^\s*merge\s*$/i) {
76 my $ingred = $chdl->extract_jeweler_ingredients; 80 my $ingred = $chdl->extract_jeweler_ingredients;
77 my @ring = $ingred->get_ring; 81 my @ring = $ingred->get_ring;
78 my @rings = map { Jeweler::Object->new (object => $_) } @ring; 82 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
79 83
86 my $plan = $ingred->get_plan; 90 my $plan = $ingred->get_plan;
87 91
88 if ($plan) { 92 if ($plan) {
89 my @ring = $ingred->get_ring; 93 my @ring = $ingred->get_ring;
90 94
91 if (@ring > 1) { 95 if ((@ring > 1) || ($ring[0]->nrof > 1)) {
92 # actually the algorithm cant handle more than one improvement at a time 96 # 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!"); 97 $pl->message ("You can't manage to improve more than one thing at a time!");
94 98
95 } elsif (@ring < 1) { 99 } elsif (@ring < 1) {
96 # actually the algorithm cant 100 # actually the algorithm cant
97 $pl->message ("You slap yourself, you forgot the ring!"); 101 $pl->message ("You slap yourself, you forgot the jewelery!");
98 102
99 } else { 103 } else {
100 my $ringo = Jeweler::Object->new (object => $ring[0]); 104 my $ringo = Jeweler::Object->new (object => $ring[0]);
101 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); 105 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo);
102 my $c1 = $ringo->calc_costs; 106 my $c1 = $ringo->calc_costs;
103 my $c2 = $iring->calc_costs; 107 my $c2 = $iring->calc_costs;
104 108
105 my %keys; 109 my %keys;
106 my %cdiff; 110 my %cdiff;
107 for (keys %$c1, keys %$c2) { $keys{$_} = 1 } 111 for (keys %$c1, keys %$c2) { $keys{$_} = 1 }
108 warn 'COSTS[' . (join ",", map { $cdiff{$_} = $c2->{$_} - $c1->{$_}; "$_: $cdiff{$_}" } keys %keys) . "]\n"; 112 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_} }
109 113
110 unless (grep { $_ > 0 } values %cdiff) { 114 unless (grep { $_ > 0 } values %cdiff) {
111 $pl->message ("This plan doesn't improve the ring, you find yourself puzzled about what you missed..."); 115 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed...");
112 return; 116 return;
113 } 117 }
114 118
115 my $remcosts = $ingred->check_costs (\%cdiff); 119 my $remcosts = $ingred->check_costs (\%cdiff);
116 warn 'REMCOSTS[' . (join ",", map { "$_: $remcosts->{$_}" } keys %$remcosts) . "]\n";
117 120
118 if (grep { $_ > 0 } values %$remcosts) { 121 if (grep { $_ > 0 } values %$remcosts) {
122 $pl->message ("You want to make a " . $iring->to_string . ": " . $iring->analyze ($sk, $pl));
119 $pl->message ("You recognize that you are short of: " 123 $pl->message ("You recognize that you are short of: "
120 . (join ", ", 124 . (join ", ",
121 map { my $cost = $remcosts->{$_}; $cost . " " . ($cost > 1 ? "times" : "time") . " " . ingred_alias ($_) } 125 map { my $cost = $remcosts->{$_}; $cost . " " . ($cost > 1 ? "times" : "time") . " " . ingred_alias ($_) }
122 grep { $remcosts->{$_} > 0 } keys %$remcosts)) 126 grep { $remcosts->{$_} > 0 } keys %$remcosts));
127 if ($pl->get_flag (cf::FLAG_WIZ)) {
128 $iring->wiz_analyze ($pl);
129 }
123 } else { 130 } else {
131 if (!$pl->get_flag (cf::FLAG_WIZ)) {
124 $ingred->check_costs (\%cdiff, 1); 132 $ingred->check_costs (\%cdiff, 1);
125 $ingred->remove ('rings'); 133 $ingred->remove ('rings');
126 $ingred->remove ('ammys'); 134 $ingred->remove ('ammys');
135 }
136
137 my $ch = $iring->get_chance_perc ($sk);
138 my $succ = 0;
139 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH);
140 if ($r <= $ch) {
141 $pl->message ("You succeed.");
142 } else {
143 $pl->message ("You fail!");
144 $iring->negate;
145 }
127 $chdl->put ($iring->to_object); 146 $chdl->put ($iring->to_object);
128 $pl->message ("You succeed!");
129 } 147 }
130 } 148 }
131 } else { 149 } else {
132 $pl->message ("You've got no idea what you are planning to do!"); 150 $pl->message ("You've got no idea what you are planning to do!");
133 } 151 }
134 } 152 }
135 }; 153 };
136 $@ and warn "ERROR: $@\n"; 154 $@ and warn "ERROR: $@\n";
137
138 my $r = cf::random_roll (0, 101, $pl, cf::PREFER_LOW);
139 } 155 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines