Adding combat stats and xp and level to the main view.
This commit is contained in:
parent
76a471a655
commit
a764a4d50e
|
@ -11,6 +11,7 @@ import OutputPacketInit from '@lastres/output-packet/init'
|
|||
import OutputPacketPing from '@lastres/output-packet/ping'
|
||||
import InputPackets from '@lastres/input-packets'
|
||||
|
||||
export type SetWebsocketCallback = (websocket: WebSocket | null) => WebSocket | null
|
||||
export interface GameProps {
|
||||
setSelectedPJ: (set: PJ | null) => void
|
||||
selectedPJ: PJ | null
|
||||
|
@ -18,6 +19,8 @@ export interface GameProps {
|
|||
setUserWantsToCreatePJ: (set: boolean) => void
|
||||
error: string | null
|
||||
setError: (set: string | null) => void
|
||||
websocket: WebSocket | null
|
||||
setWebsocket: (websocket: WebSocket | null | SetWebsocketCallback) => void
|
||||
}
|
||||
|
||||
export default function Game (props: GameProps): JSX.Element {
|
||||
|
@ -34,7 +37,6 @@ export default function Game (props: GameProps): JSX.Element {
|
|||
</>
|
||||
)
|
||||
}
|
||||
const [websocket, setWebsocket] = React.useState<WebSocket | null>(null)
|
||||
const [teamPJs, setTeamPJs] = React.useState<PJ[] | null>(null)
|
||||
const [currentLocation, setCurrentLocation] = React.useState<Location | null>(null)
|
||||
const [connectedLocations, setConnectedLocations] = React.useState<Location[] | null>(null)
|
||||
|
@ -44,6 +46,8 @@ export default function Game (props: GameProps): JSX.Element {
|
|||
const [movingTo, setMovingTo] = React.useState<Location | null>(null)
|
||||
const [remainingFrames, setRemainingFrames] = React.useState<number | null>(null)
|
||||
const logPresentationRef = React.useRef<HTMLDivElement>(null)
|
||||
const websocket = props.websocket
|
||||
const setWebsocket = props.setWebsocket
|
||||
window.setTimeout(() => {
|
||||
setWebsocket((websocket): WebSocket | null => {
|
||||
if (websocket === null) {
|
||||
|
|
|
@ -14,6 +14,7 @@ export default function Page (): JSX.Element {
|
|||
const [isAskingForRegistration, setIsAskingForRegistration] = React.useState<boolean>(false)
|
||||
const [error, setError] = React.useState<string | null>(null)
|
||||
const [selectedPJ, setSelectedPJ] = React.useState<PJ | null>(null)
|
||||
const [websocket, setWebsocket] = React.useState<WebSocket | null>(null)
|
||||
checkLogin(setError, setIsLoggedIn)
|
||||
if (!isLoggedIn) {
|
||||
return notLoggedRender(setIsLoggedIn, isAskingForRegistration, setIsAskingForRegistration, error, setError)
|
||||
|
@ -24,7 +25,9 @@ export default function Page (): JSX.Element {
|
|||
userWantsToCreatePJ={userWantsToCreatePJ}
|
||||
setUserWantsToCreatePJ={setUserWantsToCreatePJ}
|
||||
error={error}
|
||||
setError={setError}/>
|
||||
setError={setError}
|
||||
setWebsocket={setWebsocket}
|
||||
websocket={websocket}/>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@ export default function PJListItem (props: PJListItemProps): JSX.Element {
|
|||
}
|
||||
</div>
|
||||
<div className="data">
|
||||
<p>{pj.nick}</p>
|
||||
<p>{pj.nick} Nivel <span style={{ color: 'red' }}>{pj.level}.</span></p>
|
||||
<p>Experiencia: <span style={{ color: 'red' }}>{pj.experience_to_next_level_current}</span>
|
||||
/<span style={{ color: 'green' }}>{pj.experience_to_next_level_complete}</span></p>
|
||||
<label className="bar-container">
|
||||
Salud
|
||||
<PJHealthLikeBar value={pj.health} max={pj.max_health}/>
|
||||
|
|
|
@ -9,6 +9,9 @@ export interface PJ {
|
|||
race: string
|
||||
uuid: string
|
||||
image?: string
|
||||
level: number
|
||||
experience_to_next_level_complete: number
|
||||
experience_to_next_level_current: number
|
||||
}
|
||||
|
||||
export async function fetchMyPjs (setError: (set: string | null) => void): Promise<PJ[]> {
|
||||
|
|
|
@ -36,6 +36,10 @@ sub can_explore {
|
|||
return 1;
|
||||
}
|
||||
|
||||
## OVERRIDE
|
||||
sub enemies($self, $pj) {
|
||||
}
|
||||
|
||||
sub _build_children($self) {
|
||||
my $locations = $self->locations;
|
||||
my @locations = map { $locations->{$_} } keys %$locations;
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
package LasTres::CombatCapableEntity;
|
||||
|
||||
use v5.36.0;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use feature 'signatures';
|
||||
|
||||
use Moo::Role;
|
||||
|
||||
requires( 'race', 'nick', 'born_stats', 'training_stats', 'experience' );
|
||||
|
||||
sub level ($self) {
|
||||
return int($self->experience**( 1 / 3 ));
|
||||
}
|
||||
|
||||
sub max_health ($self) {
|
||||
my $races = LasTres::Races->new;
|
||||
my $race = $self->race;
|
||||
my $health_base_race = $race->base_stats->health;
|
||||
my $health_born = $self->born_stats->health;
|
||||
my $health_training = $self->training_stats->health;
|
||||
my $health_mix =
|
||||
2 * $health_base_race + $health_born + ( $health_training / 4 );
|
||||
my $health_scaled = ( ( $health_mix * $self->level ) / 100 );
|
||||
return int( $health_scaled + $self->level + 10 );
|
||||
}
|
||||
|
||||
sub strength ($self) {
|
||||
my $races = LasTres::Races->new;
|
||||
my $race = $self->race;
|
||||
my $strength_base_race = $race->base_stats->strength;
|
||||
my $strength_born = $self->born_stats->strength;
|
||||
my $strength_training = $self->training_stats->strength;
|
||||
my $strength_mix =
|
||||
2 * $strength_base_race + $strength_born + ( $strength_training / 4 );
|
||||
my $strength_scaled = ( ( $strength_mix * $self->level ) / 100 );
|
||||
return int( ( $strength_scaled + 5 ) * 1.1 );
|
||||
}
|
||||
|
||||
sub speed ($self) {
|
||||
my $races = LasTres::Races->new;
|
||||
my $race = $self->race;
|
||||
my $speed_base_race = $race->base_stats->speed;
|
||||
my $speed_born = $self->born_stats->speed;
|
||||
my $speed_training = $self->training_stats->speed;
|
||||
my $speed_mix =
|
||||
2 * $speed_base_race + $speed_born + ( $speed_training / 4 );
|
||||
my $speed_scaled = ( ( $speed_mix * $self->level ) / 100 );
|
||||
return int( ( $speed_scaled + 5 ) * 1.1 );
|
||||
}
|
||||
|
||||
sub intelligence ($self) {
|
||||
my $races = LasTres::Races->new;
|
||||
my $race = $self->race;
|
||||
my $intelligence_base_race = $race->base_stats->intelligence;
|
||||
my $intelligence_born = $self->born_stats->intelligence;
|
||||
my $intelligence_training = $self->training_stats->intelligence;
|
||||
my $intelligence_mix =
|
||||
2 * $intelligence_base_race +
|
||||
$intelligence_born +
|
||||
( $intelligence_training / 4 );
|
||||
my $intelligence_scaled = ( ( $intelligence_mix * $self->level ) / 100 );
|
||||
return int( ( $intelligence_scaled + 5 ) * 1.1 );
|
||||
}
|
||||
|
||||
sub resistance ($self) {
|
||||
my $races = LasTres::Races->new;
|
||||
my $race = $self->race;
|
||||
my $resistance_base_race = $race->base_stats->resistance;
|
||||
my $resistance_born = $self->born_stats->resistance;
|
||||
my $resistance_training = $self->training_stats->resistance;
|
||||
my $resistance_mix =
|
||||
2 * $resistance_base_race +
|
||||
$resistance_born +
|
||||
( $resistance_training / 4 );
|
||||
my $resistance_scaled = ( ( $resistance_mix * $self->level ) / 100 );
|
||||
return int( ( $resistance_scaled + 5 ) * 1.1 );
|
||||
}
|
||||
|
||||
sub max_mana ($self) {
|
||||
my $races = LasTres::Races->new;
|
||||
my $race = $self->race;
|
||||
my $mana_base_race = $race->base_stats->mana;
|
||||
my $mana_born = $self->born_stats->mana;
|
||||
my $mana_training = $self->training_stats->mana;
|
||||
my $mana_mix = 2 * $mana_base_race + $mana_born + ( $mana_training / 4 );
|
||||
my $mana_scaled = ( ( $mana_mix * $self->level ) / 100 );
|
||||
return int( $mana_scaled + $self->level + 10 );
|
||||
}
|
||||
|
||||
sub health {
|
||||
my $self = shift;
|
||||
my $health_to_set = shift;
|
||||
require LasTres::Schema;
|
||||
my $schema = LasTres::Schema->Schema;
|
||||
$schema->txn_do(
|
||||
sub {
|
||||
if ( defined $health_to_set ) {
|
||||
$self->_health($health_to_set);
|
||||
$self->update;
|
||||
}
|
||||
my $health = $self->_health;
|
||||
if ( $health < 0 ) {
|
||||
$self->_health(0);
|
||||
$self->update;
|
||||
}
|
||||
if ( $health > $self->max_health ) {
|
||||
$self->_health( $self->max_health );
|
||||
$self->update;
|
||||
}
|
||||
}
|
||||
);
|
||||
return $self->_health;
|
||||
}
|
||||
|
||||
sub mana {
|
||||
my $self = shift;
|
||||
my $mana_to_set = shift;
|
||||
require LasTres::Schema;
|
||||
my $schema = LasTres::Schema->Schema;
|
||||
$schema->txn_do(
|
||||
sub {
|
||||
if ( defined $mana_to_set ) {
|
||||
$self->_mana($mana_to_set);
|
||||
$self->update;
|
||||
}
|
||||
my $mana = $self->_mana;
|
||||
if ( $mana < 0 ) {
|
||||
$self->_mana(0);
|
||||
$self->update;
|
||||
}
|
||||
if ( $mana > $self->max_mana ) {
|
||||
$self->_mana( $self->max_mana );
|
||||
$self->update;
|
||||
}
|
||||
}
|
||||
);
|
||||
return $self->_mana;
|
||||
}
|
||||
|
||||
1;
|
|
@ -44,6 +44,7 @@ sub loop ($self) {
|
|||
my $child_pid = fork;
|
||||
if ( !$child_pid ) {
|
||||
$self->_real_loop;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,9 +89,6 @@ sub _real_loop ($self) {
|
|||
$self->_work_frame;
|
||||
}
|
||||
my $ttl = $redis->db->ttl( $redis->executing_frame_key );
|
||||
if ( $ttl > 0 ) {
|
||||
sleep $ttl;
|
||||
}
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
|
|
|
@ -13,8 +13,8 @@ use LasTres::Schema;
|
|||
our $VERSION = $LasTres::Schema::VERSION;
|
||||
|
||||
{
|
||||
my $self;
|
||||
sub new {
|
||||
my $self;
|
||||
my $class = shift;
|
||||
if (!defined $self) {
|
||||
$self = $class->SUPER::new(@_);
|
||||
|
|
|
@ -177,6 +177,9 @@ sub hash ($self) {
|
|||
health => $self->health,
|
||||
max_health => $self->max_health,
|
||||
mana => $self->mana,
|
||||
level => $self->level,
|
||||
experience_to_next_level_complete => $self->experience_to_next_level_complete,
|
||||
experience_to_next_level_current => $self->experience_to_next_level_current,
|
||||
max_mana => $self->max_mana,
|
||||
(
|
||||
( defined $image )
|
||||
|
@ -186,6 +189,14 @@ sub hash ($self) {
|
|||
};
|
||||
}
|
||||
|
||||
sub experience_to_next_level_complete($self) {
|
||||
return ($self->level+1)**3 - $self->level**3;
|
||||
}
|
||||
|
||||
sub experience_to_next_level_current($self) {
|
||||
return $self->experience - $self->level**3;
|
||||
}
|
||||
|
||||
my $columns = __PACKAGE__->columns_info;
|
||||
for my $column_name ( keys %$columns ) {
|
||||
my $column = $columns->{$column_name};
|
||||
|
@ -201,80 +212,6 @@ for my $column_name ( keys %$columns ) {
|
|||
accessor => "_moo_$column_name",
|
||||
);
|
||||
}
|
||||
|
||||
sub max_health ($self) {
|
||||
my $races = LasTres::Races->new;
|
||||
my $race = $self->race;
|
||||
my $health_base_race = $race->base_stats->health;
|
||||
my $health_born = $self->born_stats->health;
|
||||
my $health_training = $self->training_stats->health;
|
||||
my $health_mix =
|
||||
2 * $health_base_race + $health_born + ( $health_training / 4 );
|
||||
my $health_scaled = ( ( $health_mix * $self->level ) / 100 );
|
||||
return int( $health_scaled + $self->level + 10 );
|
||||
}
|
||||
|
||||
sub max_mana ($self) {
|
||||
my $races = LasTres::Races->new;
|
||||
my $race = $self->race;
|
||||
my $mana_base_race = $race->base_stats->mana;
|
||||
my $mana_born = $self->born_stats->mana;
|
||||
my $mana_training = $self->training_stats->mana;
|
||||
my $mana_mix = 2 * $mana_base_race + $mana_born + ( $mana_training / 4 );
|
||||
my $mana_scaled = ( ( $mana_mix * $self->level ) / 100 );
|
||||
return int( $mana_scaled + $self->level + 10 );
|
||||
}
|
||||
|
||||
sub health {
|
||||
my $self = shift;
|
||||
my $health_to_set = shift;
|
||||
require LasTres::Schema;
|
||||
my $schema = LasTres::Schema->Schema;
|
||||
$schema->txn_do(
|
||||
sub {
|
||||
if ( defined $health_to_set ) {
|
||||
$self->_health($health_to_set);
|
||||
$self->update;
|
||||
}
|
||||
my $health = $self->_health;
|
||||
if ( $health < 0 ) {
|
||||
$self->_health(0);
|
||||
$self->update;
|
||||
}
|
||||
if ( $health > $self->max_health ) {
|
||||
$self->_health( $self->max_health );
|
||||
$self->update;
|
||||
}
|
||||
}
|
||||
);
|
||||
return $self->_health;
|
||||
}
|
||||
|
||||
sub mana {
|
||||
my $self = shift;
|
||||
my $mana_to_set = shift;
|
||||
require LasTres::Schema;
|
||||
my $schema = LasTres::Schema->Schema;
|
||||
$schema->txn_do(
|
||||
sub {
|
||||
if ( defined $mana_to_set ) {
|
||||
$self->_mana($mana_to_set);
|
||||
$self->update;
|
||||
}
|
||||
my $mana = $self->_mana;
|
||||
if ( $mana < 0 ) {
|
||||
$self->_mana(0);
|
||||
$self->update;
|
||||
}
|
||||
if ( $mana > $self->max_mana ) {
|
||||
$self->_mana( $self->max_mana );
|
||||
$self->update;
|
||||
}
|
||||
}
|
||||
);
|
||||
return $self->_mana;
|
||||
}
|
||||
|
||||
sub race ($self) {
|
||||
my $hash = LasTres::Races->new->hash_playable;
|
||||
my $race = $hash->{ $self->_race };
|
||||
|
@ -338,9 +275,6 @@ sub location ($self) {
|
|||
return $self->team->location;
|
||||
}
|
||||
|
||||
sub level ($self) {
|
||||
return $self->experience**( 1 / 3 );
|
||||
}
|
||||
|
||||
sub set_flag ( $self, $name ) {
|
||||
require LasTres::Schema;
|
||||
|
@ -361,4 +295,5 @@ sub get_flag ( $self, $name ) {
|
|||
sub clear_flag ( $self, $name ) {
|
||||
$self->flags->search( name => $name )->delete;
|
||||
}
|
||||
with 'LasTres::CombatCapableEntity';
|
||||
1;
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue