--- deliantra/server/ext/Jeweler.pm 2007/01/31 15:53:17 1.5 +++ deliantra/server/ext/Jeweler.pm 2007/05/19 00:11:11 1.15 @@ -228,7 +228,8 @@ # 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) { $chdl->put (my $ob = cf::object::new $outarch); - $ob->set_animation (cf::rndm $ob->num_animations); + $ob->set_animation (cf::rndm $ob->num_animations) + if ($ob->type == cf::RING); $ob->flag (cf::FLAG_IDENTIFIED, 1); } @@ -239,7 +240,7 @@ $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?"); } } @@ -330,7 +331,9 @@ ); for ($self->{cauldron}->inv) { - if ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) { + if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { + die "unidentified"; + } elsif ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) { die "cursed"; } @@ -575,7 +578,8 @@ for my $key (keys %$costs) { my @grepar; if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items - @grepar = @{Jeweler::getcfg (plans => $key) || []}; + eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; + next if $@; } else { # check the gems @grepar = ('gems', undef, undef, $key); } @@ -628,6 +632,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) = @_; @@ -644,27 +659,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); @@ -676,12 +697,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 { @@ -707,6 +736,7 @@ } } } + $self->{hash}{value} = 0; } sub to_string { @@ -758,6 +788,8 @@ $obj->{arch} = $thing->arch->name; $obj->{face} = $thing->face; + $obj->{value} = $thing->value; + $self->{hash} = $obj } @@ -766,6 +798,8 @@ my $obj = cf::object::new $self->{hash}->{arch}; + $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached! + $obj->face ($self->{hash}{face}); my $stats = $obj->stats; @@ -787,9 +821,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) = @_; @@ -1045,24 +1083,35 @@ my ($thing, @matchar) = @_; my $i = 0; + my $check_cnts = 0; + my $check_true = 0; for my $match (@matchar) { + if ($i % 3 == 0) { + return 1 if $check_true && $check_cnts == $check_true; + $check_cnts = 0; + $check_true = 0; + } + 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++; } + #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->name))."\n"; + return 1 if $check_true && $check_cnts == $check_true; return 0; } @@ -1070,7 +1119,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; }