--- deliantra/server/ext/Jeweler.pm 2006/12/23 15:49:40 1.3 +++ deliantra/server/ext/Jeweler.pm 2007/02/02 12:05:28 1.7 @@ -119,6 +119,8 @@ cf::ATNR_DISEASE => "DISEASE", ); +our %REV_RESMAP = map { $RESMAP{$_} => $_ } keys %RESMAP; + our %LVL_DIFF_CHANCES = ( +5 => 100, +4 => 95, @@ -224,14 +226,20 @@ my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); if ($nrof) { # XXX: yes, i know what i'm doing here, i don't set nrof, but it didn't work somehow (pls. chek sometimes) - $chdl->put (cf::object::new $outarch) for 1..$nrof; + for (1..$nrof) { + $chdl->put (my $ob = cf::object::new $outarch); + $ob->set_animation (cf::rndm $ob->num_animations); + $ob->flag (cf::FLAG_IDENTIFIED, 1); + } my $xp_sum = ($xp_gain * $nrof); if ($xp_sum) { $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); - $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_ADD_SKILL); + $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY); } + } else { + $pl->ob->message ("You fail to make something, propably you used not enough source material?"); } } @@ -322,9 +330,16 @@ ); for ($self->{cauldron}->inv) { + if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { + die "unidentified"; + } elsif ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) { + die "cursed"; + } if (my $k = $type_to_key{$_->type}) { push @{$ingreds->{$k}}, $_; + } else { + push @{$ingreds->{other}}, $_; } } @@ -429,21 +444,17 @@ my $ingred = $self->{ingredients}; - for my $grp (keys %$ingred) { - for my $pot (@{$ingred->{$grp}}) { - for my $plan (keys %{$Jeweler::CFG->{plans}}) { - my $plg = $Jeweler::CFG->{plans}->{$plan}; - my @plga = (); - unless (ref $plg eq 'ARRAY') { - push @plga, $plg; - } else { - @plga = @$plg; - } - next unless @plga > 0; - if (Jeweler::Util::grep_for_match ($pot, @plga)) { - return $plan; - } - } + for my $plan (keys %{$Jeweler::CFG->{plans}}) { + my $plg = $Jeweler::CFG->{plans}->{$plan}; + my @plga = (); + unless (ref $plg eq 'ARRAY') { + push @plga, $plg; + } else { + @plga = @$plg; + } + next unless @plga > 0; + if (Jeweler::Util::grep_for_match ($ingred, @plga)) { + return $plan; } } } @@ -456,6 +467,14 @@ ); } +sub improve_max { + my ($stat, $impro) = @_; + if ($stat >= 0) { + $stat = $impro > $stat ? $impro : $stat; + } + $stat +} + sub improve_ring_by_plan { my ($self, $plan, $ring) = @_; @@ -470,53 +489,84 @@ or die "ingredients for plan '$plan' not defined!"; my $cnt = 0; - for my $pot (@{$ingred->{potions}}) { - if (Jeweler::Util::grep_for_match ($pot, @$plingred)) { - $cnt += $pot->nrof; - } + if (my $pot = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { + $cnt += $pot->nrof; } my $maxstat = Jeweler::getcfg (maximprovements => 'stats'); - my $did_impr = 0; for my $x (1..$maxstat) { - my $y = Jeweler::Object::fx ($x, 'stat_potions'); + my $y = Jeweler::Object::fx ($x, 'stat_items'); if ($cnt <= $y->[0]) { - $ring->{hash}->{stat}->{$statname} += $x; - $did_impr = 1; + $ring->{hash}->{stat}->{$statname} = + improve_max $ring->{hash}->{stat}->{$statname}, $x; last; } } - # we want at least this improvement if we have a plan... - $ring->{hash}->{stat}->{$statname} += 1 unless $did_impr; - } elsif ($plan =~ m/^spec_(\S+)$/) { + my $specname = $1; + my $plingred = Jeweler::getcfg (plans => $plan) + or die "ingredients for plan '$plan' not defined!"; + + my $cnt = 0; + if (my $pot = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { + $cnt += $pot->nrof; + } + + my $maxspec = Jeweler::getcfg (maximprovements => 'specials'); + for my $x (1..$maxspec) { + my $y = Jeweler::Object::fx ($x, 'spec_items'); + + if ($cnt <= $y->[0]) { + $ring->{hash}->{spec}->{$specname} = + improve_max $ring->{hash}->{spec}->{$specname}, $x; + last; + } + } + } elsif ($plan =~ m/^resist_(\S+)$/) { + my $resname = $1; + my $resnum = $REV_RESMAP{$resname}; + my $plingred = Jeweler::getcfg (plans => $plan) + or die "ingredients for plan '$plan' not defined!"; + + my $cnt = 0; + if (my $it = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { + $cnt += $it->nrof; + } + my $resist_item_nr = 0; + $self->do_grep (sub { $resist_item_nr += ($_[0]->nrof || 1); 0 }, @$plingred); + + my $maximprovname = (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) + ? 'effect_resistances' + : 'attack_resistances'; + + my $maxres = Jeweler::getcfg (maximprovements => $maximprovname); + $resist_item_nr = $maxres if ($resist_item_nr > $maxres); + $ring->{hash}->{resist}->{$resnum} = + improve_max $ring->{hash}->{resist}->{$resnum}, $resist_item_nr; } return $ring; } sub do_grep { - my ($self, $cb, @grepar) = @_; + my ($self, $cb, $cat, @grepar) = @_; my $ingred = $self->{ingredients}; - - for my $cat (keys %$ingred) { - my @rem; - for my $ing (@{$ingred->{$cat}}) { - if (Jeweler::Util::grep_for_match ($ing, @grepar)) { - unless ($cb->($ing)) { - push @rem, $ing; - } - } else { + my @rem; + for my $ing (@{$ingred->{$cat}}) { + if (Jeweler::Util::check_for_match ($ing, @grepar)) { + unless ($cb->($ing)) { push @rem, $ing; } + } else { + push @rem, $ing; } - @{$ingred->{$cat}} = @rem; } + @{$ingred->{$cat}} = @rem; } sub check_costs { @@ -526,10 +576,10 @@ for my $key (keys %$costs) { my @grepar; - if ($key =~ m/^stat_(\S+)$/) { + if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items @grepar = @{Jeweler::getcfg (plans => $key) || []}; - } else { - @grepar = (undef, undef, $key); + } else { # check the gems + @grepar = ('gems', undef, undef, $key); } if ($do_remove) { @@ -540,9 +590,10 @@ } } else { my $nr; - $self->do_grep (sub { $nr += $_[0]->nrof; 0 }, @grepar); + $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); $costs->{$key} -= $nr; } + } return $costs; @@ -579,6 +630,17 @@ $self; } +sub has_resist { + my ($self, $resistnam, $resistval) = @_; + my $resnum = $REV_RESMAP{uc $resistnam}; + if (defined ($resistval)) { + return 1 if $self->{hash}->{resist}->{$resnum} == $resistval; + } else { + return 1 if $self->{hash}->{resist}->{$resnum}; + } + return undef; +} + sub analyze { my ($self, $sk, $pl) = @_; @@ -600,7 +662,18 @@ my $costs = $self->calc_costs; my $desc = ""; my $lvl = $self->power_to_level (\$desc); - $pl->message ("costs: " . join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)); + my $emarch = cf::arch::find 'emerald'; + my $saarch = cf::arch::find 'sapphire'; + my $pearch = cf::arch::find 'pearl'; + my $ruarch = cf::arch::find 'ruby'; + my $diarch = cf::arch::find 'gem'; + my $scosts = $emarch->clone->value * $costs->{emerald} + + $saarch->clone->value * $costs->{sapphire} + + $pearch->clone->value * $costs->{pearl} + + $ruarch->clone->value * $costs->{ruby} + + $diarch->clone->value * $costs->{gem}; + + $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); $pl->message ("level: " . $desc); } @@ -706,6 +779,8 @@ my $obj = cf::object::new $self->{hash}->{arch}; + $obj->item_power ($self->power_to_level); # there have to be strings attached! + $obj->face ($self->{hash}{face}); my $stats = $obj->stats; @@ -730,6 +805,20 @@ return $obj; } +sub is_better_than { + my ($self, $other) = @_; + + for my $type (qw/spec stat resist/) { + for my $stat (keys %{$self->{hash}->{$type}}) { + if ($self->{hash}->{$type}->{$stat} > $other->{hash}->{$type}->{$stat}) { + return 1; + } + } + } + + return 0; +} + sub stat_level { my ($self) = @_; my $stats = $self->{hash}->{stat} || {}; @@ -851,7 +940,7 @@ next unless $sum > 0; - my $statfx = fx ($sum, 'stat_potions'); + my $statfx = fx ($sum, 'stat_items'); $cost->{"stat_$stat"} += $statfx->[0]; split_diamonds ($cost, $statfx->[1], 'stat_' . $stat); } @@ -867,7 +956,7 @@ next unless $sum > 0; - my $specfx = fx ($sum, 'spec_potions'); + my $specfx = fx ($sum, 'spec_items'); $cost->{"spec_$spec"} += $specfx->[0]; split_diamonds ($cost, $specfx->[1], 'spec_' . $spec); } @@ -880,22 +969,22 @@ my $ring = $self->{hash}; - for my $resnam (keys %{$ring->{resist} || {}}) { + for my $resnum (keys %{$ring->{resist} || {}}) { - my $res = $ring->{resist}->{$resnam}; + my $res = $ring->{resist}->{$resnum}; next unless $res > 0; - $costs->{"resist_" . $Jeweler::RESMAP{$resnam} . "_item"} += $res; + $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; my $diamonds; - if (grep { $resnam eq $_ } @Jeweler::EFFECT_RESISTS) { + if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { $diamonds += fx ($res, 'effect_resist_diamonds'); } else { $diamonds += fx ($res, 'attack_resist_diamonds'); } - split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnam}); + split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); } $self->add_stat_costs ($costs); @@ -952,7 +1041,8 @@ my $cnt; if (defined $nrof) { - return 0 if ($nrof * 1) == 0; + # TODO: Check tihis line: + return 0 if ($nrof * 1) == 0; #XXX: ??? $cnt = int (($obj->nrof || 1) - (1 * $nrof)); if ($cnt > 0) { @@ -966,7 +1056,7 @@ return $cnt; } -sub grep_for_match { +sub check_for_match { my ($thing, @matchar) = @_; my $i = 0; @@ -991,6 +1081,18 @@ return 0; } +sub grep_for_match { + my ($ingred, $group, @matchar) = @_; + + for my $thing (@{$ingred->{$group} || []}) { + warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# + if (check_for_match ($thing, @matchar)) { + return $thing; + } + } + return undef; +} + =back 1