burguillos.info/lib/BurguillosInfo/Schema/Result/ConquerNode.pm

84 lines
1.9 KiB
Perl

package BurguillosInfo::Schema::Result::ConquerNode;
use v5.36.0;
use strict;
use warnings;
use parent 'DBIx::Class::Core';
use feature 'signatures';
use JSON;
use GIS::Distance;
__PACKAGE__->table('conquer_node');
__PACKAGE__->load_components("TimeStamp");
__PACKAGE__->add_columns(
uuid => {
data_type => 'uuid',
is_nullable => 0,
},
name => {
data_type => 'text',
is_nullable => 0,
default_value => \'0',
},
coordinate_1 => {
data_type => 'real',
is_nullable => 0,
},
coordinate_2 => {
data_type => 'real',
is_nullable => 0,
},
type => {
data_type => 'text',
is_nullable => 0,
},
description => {
data_type => 'text',
is_nullable => 0,
}
);
sub serialize ( $self, $player = undef ) {
$self = $self->get_from_storage();
my $return = {
kind => 'ConquerNode',
uuid => $self->uuid,
name => $self->name,
description => $self->description,
type => $self->type,
coordinate_1 => $self->coordinate_1,
coordinate_2 => $self->coordinate_2,
is_near => $self->is_near($player),
};
return $return;
}
sub is_near ( $self, $player ) {
if ( !defined $player ) {
return $JSON::false;
}
# Meters
if ($self->get_distance_to_player($player) < 100) {
return $JSON::true;
}
return $JSON::false;
}
sub get_distance_to_player ($self, $player) {
my $longitude_player = $player->last_coordinate_1;
my $latitude_player = $player->last_coordinate_2;
my $longitude_node = $self->coordinate_1;
my $latitude_node = $self->coordinate_2;
my $gis = GIS::Distance->new;
# Setting distance to meters.
my $distance = $gis->distance_metal( $latitude_node, $longitude_node, $latitude_player, $longitude_player) * 1000;
}
__PACKAGE__->set_primary_key('uuid');
1;