--- deliantra/server/ext/Jeweler.pm 2007/04/10 17:46:22 1.14 +++ deliantra/server/ext/Jeweler.pm 2008/04/10 15:35:16 1.25 @@ -26,13 +26,12 @@ sub read_config { my ($filename) = @_; - unless (-e $filename) { - warn "$filename doesn't exists! no config for jeweler skill loaded!\n"; + if (my $meta = $cf::RESOURCE{$filename}) { + $CFG = cf::decode_json $meta->{data}; + } else { + warn "$filename doesn't exist! no config for jeweler skill loaded!\n"; $CFG = {}; - return } - - $CFG = YAML::LoadFile $filename; } sub getcfg { @@ -164,24 +163,27 @@ } sub analyze { - my ($sk, $chdl, $pl) = @_; + my ($sk, $chdl, $pl, $input_level) = @_; my $hadunid = 0; + my $found = 0; for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { $hadunid = 1; next; } + $found = 1; my $r = Jeweler::Object->new (object => $_); - my $msg = $r->analyze ($sk, $pl); + my $msg = $r->analyze ($sk, $pl, $input_level); $pl->message ($r->to_string . ": " . $msg); if ($pl->flag (cf::FLAG_WIZ)) { $r->wiz_analyze ($pl); } } - if ($hadunid) { - $pl->message ("You couldn't identify the other rings and not analyze them!"); - } + $pl->message ("You couldn't identify the other rings and not analyze them!") + if $hadunid; + $pl->message ("You couldn't find anything in the bench to analyse!") + unless $found; } # this function converts metals/minerals into a raw ring (of adornment) @@ -205,7 +207,7 @@ } unless ($xp_gain > 0) { - warn "WARNING: xp gain isn't > 0 in convesion '$outarch'\n"; + warn "WARNING: xp gain isn't > 0 in conversion '$outarch'\n"; return; } @@ -221,26 +223,26 @@ my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); $ingred->remove ($ingr_grp, $srcarchname); - my $outarchval = cf::arch::find ($outarch)->clone->value; + my $outarchval = cf::arch::find ($outarch)->value; - my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); + 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) - for (1..$nrof) { + # XXX: yes, I know what I'm doing here, I don't set nrof, but it didn't work somehow (pls. check sometimes) + for (1 .. $nrof) { $chdl->put (my $ob = cf::object::new $outarch); $ob->set_animation (cf::rndm $ob->num_animations) if ($ob->type == cf::RING); $ob->flag (cf::FLAG_IDENTIFIED, 1); } - my $xp_sum = ($xp_gain * $nrof); + 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_SKILL_ONLY); } } else { - $pl->ob->message ("You fail to make something, propably you used not enough source material?"); + $pl->ob->message ("You fail to make something, probably you used not enough source material?"); } } @@ -282,7 +284,7 @@ my @c = grep { $_->flag (cf::FLAG_IS_CAULDRON) - and $_->arch->name eq $arch_name + and $_->arch->archname eq $arch_name } @map_stack; $self->{cauldron} = $c[0]; @@ -357,7 +359,7 @@ my ($self, $obj) = @_; return undef unless $self->{cauldron}; - $obj->insert_ob_in_ob ($self->{cauldron}); + $self->{cauldron}->insert ($obj); } =back @@ -400,7 +402,7 @@ my ($self, $group, $archname) = @_; my @objs = grep { - $_->arch->name eq $archname + $_->arch->archname eq $archname } @{$self->{ingredients}->{$group} || []}; my $sum = 0; @@ -427,7 +429,7 @@ for (@{$ingred->{$group}}) { if (defined $archname) { - if ($_->arch->name eq $archname) { + if ($_->arch->archname eq $archname) { Jeweler::Util::remove ($_); } else { push @out, $_; @@ -479,7 +481,7 @@ sub improve_ring_by_plan { my ($self, $plan, $ring) = @_; - $ring = dclone ($ring); + $ring = do { my $guard = Coro::Storable::guard; dclone $ring }; my $ingred = $self->{ingredients}; my $impr = {}; @@ -573,7 +575,7 @@ sub check_costs { my ($self, $costs, $do_remove) = @_; - my $costs = dclone ($costs); + my $costs = do { my $guard = Coro::Storable::guard; dclone $costs }; for my $key (keys %$costs) { my @grepar; @@ -643,8 +645,44 @@ return undef; } +sub projected_exp { + my ($self, $input_level) = @_; + + my $lvl = max ($self->power_to_level, 1); + my $exp = + (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) + / (10 + max ($lvl - 1, 0)); # 10 + level times making such a ring + # should get you to the rings level at least. + + if (defined $input_level) { + my $subexp = + (cf::level_to_min_exp ($input_level) + - cf::level_to_min_exp ($input_level - 1)) + / (10 + max ($input_level - 1, 0)); # see above for comment + + $exp -= $subexp; + $exp = max ($exp, 0); + + } else { + # the experience bonus here is to make level 1 rings give you at least + # 100 exp points when making them. This also makes leveling in the + # first few levels a bit easier. (probably until around level 5-6). + my $expbonus = cf::level_to_min_exp (2) / 10; + # this bonus should also only be given for _new_ rings and not for merged + # ones - to prevent infinite exp making. + $exp += $expbonus; + } + + $exp +} + sub analyze { - my ($self, $sk, $pl) = @_; + my ($self, $sk, $pl, $input_level) = @_; + my $costs = $self->calc_costs; + + unless (defined $costs) { + return "This ring has a resistancy above 99%, you can't make that."; + } my $sklvl = cf::exp_to_level ($sk->stats->exp); my $ringlvl = $self->power_to_level; @@ -655,7 +693,7 @@ } else { $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); } - my $msg = sprintf "Projected success rate: %s", $tmpl; + my $msg = sprintf "Projected success rate: %s, you would get %d exp for this.", $tmpl, $self->projected_exp ($input_level); return $msg; } @@ -666,11 +704,11 @@ my $pearch = cf::arch::find 'pearl'; my $ruarch = cf::arch::find 'ruby'; my $diarch = cf::arch::find 'gem'; - my $value = $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}; + my $value = $emarch->value * $costs->{emerald} + + $saarch->value * $costs->{sapphire} + + $pearch->value * $costs->{pearl} + + $ruarch->value * $costs->{ruby} + + $diarch->value * $costs->{gem}; $value } @@ -678,12 +716,20 @@ sub wiz_analyze { my ($self, $pl) = @_; my $costs = $self->calc_costs; - my $desc = ""; - my $lvl = $self->power_to_level (\$desc); - my $scosts = $self->calc_value_from_cost ($costs); - - $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); - $pl->message ("level: " . $desc); + if (defined $costs) { + my $desc = ""; + my $lvl = $self->power_to_level (\$desc); + my $scosts = $self->calc_value_from_cost ($costs); + + $pl->message ("costs: " + . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) + . " (" + . ($scosts / "royalty"->cf::arch::find->value) + . " royalties)"); + $pl->message ("level: $desc"); + } else { + $pl->message ("level: impossible to make, due to impossible resistancy configuration"); + } } sub get_chance_perc { @@ -698,18 +744,21 @@ my $or = $res; my $ar = $Jeweler::CFG->{functions}->{$cfg}; - if (ref $ar->[0] eq 'ARRAY') { + if (ref $ar && ref $ar->[0] eq 'ARRAY') { $res = $res - 1; return $ar->[max (min ($res, @$ar - 1), 0)]; } else { # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3... - my $idx = ceil (($res / 5) + 0.1) - 1; - my $a = $ar->[max (min ($idx, @$ar - 1), 0)]; - my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)]; - my $diff = $b - $a; # use the difference of the cost to the next cost - my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation - return $o_cost; + # old code: + #my $idx = ceil (($res / 5) + 0.1) - 1; + #my $a = $ar->[max (min ($idx, @$ar - 1), 0)]; + #my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)]; + #my $diff = $b - $a; # use the difference of the cost to the next cost + #my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation + #return $o_cost; + return 0 if $res <= 0; + return ($ar / (1 - ($res * 0.01)) - $ar) } } @@ -785,7 +834,7 @@ $obj->{spec}{food} = $stats->food; $obj->{name} = $thing->name; - $obj->{arch} = $thing->arch->name; + $obj->{arch} = $thing->arch->archname; $obj->{face} = $thing->face; $obj->{value} = $thing->value; @@ -998,13 +1047,15 @@ next unless $res > 0; + return undef if $res == 100; + $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; my $diamonds; if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { - $diamonds += fx ($res, 'effect_resist_diamonds'); + $diamonds += fx ($res, 'effect_resist_diamonds_x'); } else { - $diamonds += fx ($res, 'attack_resist_diamonds'); + $diamonds += fx ($res, 'attack_resist_diamonds_x'); } split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); @@ -1022,9 +1073,6 @@ my $stat_split = Jeweler::getcfg (diamond_split => $category); my $sum = sum (@$stat_split); - if ($sum < (1 - 0.0001)) { - warn "JEWELER BUG: sum (@$stat_split) = $sum < 1 for $category!"; - } my $emarch = cf::arch::find 'emerald'; my $saarch = cf::arch::find 'sapphire'; @@ -1032,13 +1080,13 @@ my $ruarch = cf::arch::find 'ruby'; my $diarch = cf::arch::find 'gem'; - my $sumvalue = $diarch->clone->value * $diamonds; + my $sumvalue = $diarch->value * $diamonds; - $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->clone->value; - $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->clone->value; - $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->clone->value; - $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->clone->value; - $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->clone->value; + $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->value; + $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->value; + $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->value; + $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->value; + $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; } package Jeweler::Util; @@ -1105,12 +1153,12 @@ $thing->title eq $match and $check_true++; } else { # $i % 3 == 2 - $thing->arch->name eq $match + $thing->arch->archname eq $match and $check_true++; } $i++; } - #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->name))."\n"; + #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->archname))."\n"; return 1 if $check_true && $check_cnts == $check_true; return 0; } @@ -1119,7 +1167,7 @@ my ($ingred, $group, @matchar) = @_; for my $thing (@{$ingred->{$group} || []}) { - #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# + #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->archname, "@matchar"; #d# if (check_for_match ($thing, @matchar)) { return $thing; }