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

84 lines
1.9 KiB
Perl
Raw Normal View History

2023-12-31 20:43:53 +01:00
package BurguillosInfo::Schema::Result::ConquerNode;
use v5.36.0;
use strict;
use warnings;
use parent 'DBIx::Class::Core';
use feature 'signatures';
2024-01-13 01:17:57 +01:00
use JSON;
use GIS::Distance;
2023-12-31 20:43:53 +01:00
__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,
}
);
2024-01-13 01:17:57 +01:00
sub serialize ( $self, $player = undef ) {
2023-12-31 20:43:53 +01:00
$self = $self->get_from_storage();
2024-01-13 01:17:57 +01:00
my $return = {
2023-12-31 20:43:53 +01:00
kind => 'ConquerNode',
uuid => $self->uuid,
name => $self->name,
description => $self->description,
type => $self->type,
coordinate_1 => $self->coordinate_1,
coordinate_2 => $self->coordinate_2,
2024-01-13 01:17:57 +01:00
is_near => $self->is_near($player),
2023-12-31 20:43:53 +01:00
};
2024-01-13 01:17:57 +01:00
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;
2023-12-31 20:43:53 +01:00
}
2024-01-13 01:17:57 +01:00
2023-12-31 20:43:53 +01:00
__PACKAGE__->set_primary_key('uuid');
1;