… | |
… | |
2698 | } |
2698 | } |
2699 | |
2699 | |
2700 | sub prepare_random_map { |
2700 | sub prepare_random_map { |
2701 | my ($exit) = @_; |
2701 | my ($exit) = @_; |
2702 | |
2702 | |
2703 | my $guard = cf::lock_acquire "exit_prepare:$exit"; |
|
|
2704 | |
|
|
2705 | # all this does is basically replace the /! path by |
2703 | # all this does is basically replace the /! path by |
2706 | # a new random map path (?random/...) with a seed |
2704 | # a new random map path (?random/...) with a seed |
2707 | # that depends on the exit object |
2705 | # that depends on the exit object |
2708 | |
2706 | |
2709 | my $rmp = parse_random_map_params $exit->msg; |
2707 | my $rmp = parse_random_map_params $exit->msg; |
… | |
… | |
2711 | if ($exit->map) { |
2709 | if ($exit->map) { |
2712 | $rmp->{region} = $exit->region->name; |
2710 | $rmp->{region} = $exit->region->name; |
2713 | $rmp->{origin_map} = $exit->map->path; |
2711 | $rmp->{origin_map} = $exit->map->path; |
2714 | $rmp->{origin_x} = $exit->x; |
2712 | $rmp->{origin_x} = $exit->x; |
2715 | $rmp->{origin_y} = $exit->y; |
2713 | $rmp->{origin_y} = $exit->y; |
|
|
2714 | |
|
|
2715 | $exit->map->touch; |
2716 | } |
2716 | } |
2717 | |
2717 | |
2718 | $rmp->{random_seed} ||= $exit->random_seed; |
2718 | $rmp->{random_seed} ||= $exit->random_seed; |
2719 | |
2719 | |
2720 | my $data = JSON::XS->new->utf8->pretty->canonical->encode ($rmp); |
2720 | my $data = JSON::XS->new->utf8->pretty->canonical->encode ($rmp); |
… | |
… | |
2724 | if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) { |
2724 | if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) { |
2725 | aio_write $fh, 0, (length $data), $data, 0; |
2725 | aio_write $fh, 0, (length $data), $data, 0; |
2726 | undef $fh; |
2726 | undef $fh; |
2727 | aio_rename "$meta~", $meta; |
2727 | aio_rename "$meta~", $meta; |
2728 | |
2728 | |
|
|
2729 | my $slaying = "?random/$md5"; |
|
|
2730 | |
|
|
2731 | if ($exit->valid) { |
2729 | $exit->slaying ("?random/$md5"); |
2732 | $exit->slaying ("?random/$md5"); |
2730 | $exit->msg (undef); |
2733 | $exit->msg (undef); |
|
|
2734 | } |
2731 | } |
2735 | } |
2732 | } |
2736 | } |
2733 | |
2737 | |
2734 | sub cf::object::player::enter_exit { |
2738 | sub cf::object::player::enter_exit { |
2735 | my ($self, $exit) = @_; |
2739 | my ($self, $exit) = @_; |
2736 | |
2740 | |
2737 | return unless $self->type == cf::PLAYER; |
2741 | return unless $self->type == cf::PLAYER; |
2738 | |
2742 | |
2739 | if ($exit->slaying eq "/!") { |
|
|
2740 | #TODO: this should de-fi-ni-te-ly not be a sync-job |
|
|
2741 | # the problem is that $exit might not survive long enough |
|
|
2742 | # so it needs to be done right now, right here |
|
|
2743 | cf::sync_job { prepare_random_map $exit }; |
|
|
2744 | } |
|
|
2745 | |
|
|
2746 | my $slaying = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path; |
|
|
2747 | my $hp = $exit->stats->hp; |
|
|
2748 | my $sp = $exit->stats->sp; |
|
|
2749 | |
|
|
2750 | $self->enter_link; |
2743 | $self->enter_link; |
2751 | |
2744 | |
2752 | # if exit is damned, update players death & WoR home-position |
|
|
2753 | $self->contr->savebed ($slaying, $hp, $sp) |
|
|
2754 | if $exit->flag (FLAG_DAMNED); |
|
|
2755 | |
|
|
2756 | (async { |
2745 | (async { |
2757 | $Coro::current->{desc} = "enter_exit $slaying $hp $sp"; |
2746 | $Coro::current->{desc} = "enter_exit"; |
2758 | |
2747 | |
2759 | $self->deactivate_recursive; # just to be sure |
|
|
2760 | unless (eval { |
2748 | unless (eval { |
|
|
2749 | $self->deactivate_recursive; # just to be sure |
|
|
2750 | |
|
|
2751 | # random map handling |
|
|
2752 | { |
|
|
2753 | my $guard = cf::lock_acquire "exit_prepare:$exit"; |
|
|
2754 | |
|
|
2755 | prepare_random_map $exit |
|
|
2756 | if $exit->slaying eq "/!"; |
|
|
2757 | } |
|
|
2758 | |
|
|
2759 | my $map = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path; |
|
|
2760 | my $x = $exit->stats->hp; |
|
|
2761 | my $y = $exit->stats->sp; |
|
|
2762 | |
2761 | $self->goto ($slaying, $hp, $sp); |
2763 | $self->goto ($map, $x, $y); |
2762 | |
2764 | |
|
|
2765 | # if exit is damned, update players death & WoR home-position |
|
|
2766 | $self->contr->savebed ($map, $x, $y) |
|
|
2767 | if $exit->flag (cf::FLAG_DAMNED); |
|
|
2768 | |
2763 | 1; |
2769 | 1 |
2764 | }) { |
2770 | }) { |
2765 | $self->message ("Something went wrong deep within the crossfire server. " |
2771 | $self->message ("Something went wrong deep within the crossfire server. " |
2766 | . "I'll try to bring you back to the map you were before. " |
2772 | . "I'll try to bring you back to the map you were before. " |
2767 | . "Please report this to the dungeon master!", |
2773 | . "Please report this to the dungeon master!", |
2768 | cf::NDI_UNIQUE | cf::NDI_RED); |
2774 | cf::NDI_UNIQUE | cf::NDI_RED); |