--- deliantra/server/ext/Jeweler.pm 2007/02/04 00:35:23 1.8 +++ deliantra/server/ext/Jeweler.pm 2007/02/04 11:17:52 1.9 @@ -658,27 +658,33 @@ return $msg; } -sub wiz_analyze { - my ($self, $pl) = @_; - my $costs = $self->calc_costs; - my $desc = ""; - my $lvl = $self->power_to_level (\$desc); +sub calc_value_from_cost { + my ($self, $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}; + 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}; + + $value +} + +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); } - sub get_chance_perc { my ($self, $sk) = @_; my $sklvl = cf::exp_to_level ($sk->stats->exp); @@ -690,12 +696,20 @@ my ($res, $cfg) = @_; my $or = $res; my $ar = $Jeweler::CFG->{functions}->{$cfg}; + if (ref $ar->[0] eq 'ARRAY') { $res = $res - 1; + return $ar->[max (min ($res, @$ar - 1), 0)]; + } else { - $res = ceil ($res / 5) - 1; + # +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; } - $ar->[max (min ($res, @$ar - 1), 0)]; } sub improve_by_ring { @@ -721,6 +735,7 @@ } } } + $self->{hash}{value} = 0; } sub to_string { @@ -772,6 +787,8 @@ $obj->{arch} = $thing->arch->name; $obj->{face} = $thing->face; + $obj->{value} = $thing->value; + $self->{hash} = $obj } @@ -803,9 +820,13 @@ $obj->flag (cf::FLAG_IDENTIFIED, 1); + $obj->value ($self->{hash}{value}); + return $obj; } +sub set_value { $_[0]->{hash}{value} = $_[1] } + sub is_better_than { my ($self, $other) = @_; @@ -1061,24 +1082,30 @@ my ($thing, @matchar) = @_; my $i = 0; + my $check_cnts = 0; + my $check_true = 0; for my $match (@matchar) { if ($match =~ m/^\s*$/) { $i++; next; } + $check_cnts++; if ($i % 3 == 0) { $thing->name eq $match - and return 1; + and $check_true++; } elsif ($i % 3 == 1) { $thing->title eq $match - and return 1; + and $check_true++; } else { # $i % 3 == 2 $thing->arch->name eq $match - and return 1; + and $check_true++; } $i++; } + if ($check_true && $check_cnts == $check_true) { + return 1; + } return 0; } @@ -1086,7 +1113,7 @@ 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# + #d# 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; }