Adding basic combat.

This commit is contained in:
Sergiotarxz 2023-06-26 01:37:23 +02:00
parent a764a4d50e
commit 664f002967
35 changed files with 6879 additions and 140 deletions

View File

@ -0,0 +1,317 @@
--
-- Created by SQL::Translator::Producer::PostgreSQL
-- Created on Sat Jun 24 02:18:42 2023
--
;
--
-- Table: equipment
--
CREATE TABLE "equipment" (
"uuid" uuid NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: inventories
--
CREATE TABLE "inventories" (
"uuid" uuid NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: players
--
CREATE TABLE "players" (
"uuid" uuid NOT NULL,
"username" text NOT NULL,
"encrypted_password" text NOT NULL,
"email" text NOT NULL,
"verified" boolean NOT NULL,
"verification_token" text,
"register_date" timestamp DEFAULT NOW() NOT NULL,
"last_activity" timestamp DEFAULT NOW() NOT NULL,
PRIMARY KEY ("uuid"),
CONSTRAINT "unique_constraint_email" UNIQUE ("email"),
CONSTRAINT "unique_constraint_username" UNIQUE ("username")
);
;
--
-- Table: skill_like_lists
--
CREATE TABLE "skill_like_lists" (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: stats
--
CREATE TABLE "stats" (
"uuid" uuid NOT NULL,
"health" integer NOT NULL,
"mana" integer NOT NULL,
"strength" integer NOT NULL,
"resistance" integer NOT NULL,
"magic" integer NOT NULL,
"speed" integer NOT NULL,
"intelligence" integer NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: equipment_items
--
CREATE TABLE "equipment_items" (
"kind" text NOT NULL,
"equipment" uuid NOT NULL,
"identifier" text NOT NULL,
"quantity" integer NOT NULL,
PRIMARY KEY ("kind", "equipment")
);
CREATE INDEX "equipment_items_idx_equipment" on "equipment_items" ("equipment");
;
--
-- Table: inventory_items
--
CREATE TABLE "inventory_items" (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
"inventory" uuid NOT NULL,
"identifier" text NOT NULL,
"quantity" integer NOT NULL,
PRIMARY KEY ("uuid"),
CONSTRAINT "inventory_items_unique_item" UNIQUE ("inventory", "identifier")
);
CREATE INDEX "inventory_items_idx_inventory" on "inventory_items" ("inventory");
;
--
-- Table: skill_like_items
--
CREATE TABLE "skill_like_items" (
"identifier" text NOT NULL,
"owner_list" uuid NOT NULL,
"level" integer DEFAULT 1 NOT NULL,
PRIMARY KEY ("identifier", "owner_list")
);
CREATE INDEX "skill_like_items_idx_owner_list" on "skill_like_items" ("owner_list");
;
--
-- Table: teams
--
CREATE TABLE "teams" (
"uuid" uuid NOT NULL,
"is_exploring" boolean DEFAULT false NOT NULL,
"action_frame" integer DEFAULT 0 NOT NULL,
"is_moving" boolean DEFAULT false NOT NULL,
"moving_to" jsonb DEFAULT 'null' NOT NULL,
"leader" uuid,
"name" text NOT NULL,
"planet" text NOT NULL,
"super_area" text NOT NULL,
"area" text NOT NULL,
"location" text NOT NULL,
PRIMARY KEY ("uuid"),
CONSTRAINT "u_name" UNIQUE ("name")
);
CREATE INDEX "teams_idx_leader" on "teams" ("leader");
;
--
-- Table: player_pjs
--
CREATE TABLE "player_pjs" (
"uuid" uuid NOT NULL,
"owner" uuid NOT NULL,
"full_name" text NOT NULL,
"short_name" text NOT NULL,
"nick" text NOT NULL,
"race" text NOT NULL,
"team" uuid NOT NULL,
"creation_date" timestamp DEFAULT NOW() NOT NULL,
"last_activity" timestamp DEFAULT NOW() NOT NULL,
"experience" integer DEFAULT 1 NOT NULL,
"equipment" uuid NOT NULL,
"born_stats" uuid NOT NULL,
"training_stats" uuid NOT NULL,
"skills" uuid NOT NULL,
"spells" uuid NOT NULL,
"inventory" uuid NOT NULL,
"health" integer NOT NULL,
"mana" integer NOT NULL,
"combat_target" uuid,
"combat_action" text,
PRIMARY KEY ("uuid")
);
CREATE INDEX "player_pjs_idx_born_stats" on "player_pjs" ("born_stats");
CREATE INDEX "player_pjs_idx_equipment" on "player_pjs" ("equipment");
CREATE INDEX "player_pjs_idx_inventory" on "player_pjs" ("inventory");
CREATE INDEX "player_pjs_idx_owner" on "player_pjs" ("owner");
CREATE INDEX "player_pjs_idx_skills" on "player_pjs" ("skills");
CREATE INDEX "player_pjs_idx_spells" on "player_pjs" ("spells");
CREATE INDEX "player_pjs_idx_team" on "player_pjs" ("team");
CREATE INDEX "player_pjs_idx_training_stats" on "player_pjs" ("training_stats");
;
--
-- Table: player_companion_npcs
--
CREATE TABLE "player_companion_npcs" (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
"owner" uuid NOT NULL,
"identifier" text NOT NULL,
"nick" text,
"race" text NOT NULL,
"level" integer DEFAULT 1 NOT NULL,
"exp" integer DEFAULT 1 NOT NULL,
"equipment" uuid NOT NULL,
"stats" uuid NOT NULL,
"skills" uuid NOT NULL,
"spells" uuid NOT NULL,
"inventory" uuid NOT NULL,
PRIMARY KEY ("uuid")
);
CREATE INDEX "player_companion_npcs_idx_equipment" on "player_companion_npcs" ("equipment");
CREATE INDEX "player_companion_npcs_idx_inventory" on "player_companion_npcs" ("inventory");
CREATE INDEX "player_companion_npcs_idx_owner" on "player_companion_npcs" ("owner");
CREATE INDEX "player_companion_npcs_idx_skills" on "player_companion_npcs" ("skills");
CREATE INDEX "player_companion_npcs_idx_spells" on "player_companion_npcs" ("spells");
CREATE INDEX "player_companion_npcs_idx_stats" on "player_companion_npcs" ("stats");
;
--
-- Table: player_pjs_flags
--
CREATE TABLE "player_pjs_flags" (
"name" text NOT NULL,
"owner" uuid NOT NULL,
PRIMARY KEY ("name", "owner")
);
CREATE INDEX "player_pjs_flags_idx_owner" on "player_pjs_flags" ("owner");
CREATE INDEX "index_flag" on "player_pjs_flags" ("owner", "name");
;
--
-- Table: player_pjs_known_places
--
CREATE TABLE "player_pjs_known_places" (
"owner" uuid NOT NULL,
"planet" text NOT NULL,
"super_area" text NOT NULL,
"area" text NOT NULL,
"location" text NOT NULL,
PRIMARY KEY ("owner", "planet", "super_area", "area", "location")
);
CREATE INDEX "player_pjs_known_places_idx_owner" on "player_pjs_known_places" ("owner");
;
--
-- Table: player_pjs_log
--
CREATE TABLE "player_pjs_log" (
"uuid" uuid NOT NULL,
"content" jsonb NOT NULL,
"owner" uuid NOT NULL,
"date" timestamp DEFAULT NOW() NOT NULL,
PRIMARY KEY ("uuid")
);
CREATE INDEX "player_pjs_log_idx_owner" on "player_pjs_log" ("owner");
CREATE INDEX "index_log" on "player_pjs_log" ("owner", "date");
;
--
-- Foreign Key Definitions
--
;
ALTER TABLE "equipment_items" ADD CONSTRAINT "equipment_items_fk_equipment" FOREIGN KEY ("equipment")
REFERENCES "equipment" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "inventory_items" ADD CONSTRAINT "inventory_items_fk_inventory" FOREIGN KEY ("inventory")
REFERENCES "inventories" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "skill_like_items" ADD CONSTRAINT "skill_like_items_fk_owner_list" FOREIGN KEY ("owner_list")
REFERENCES "skill_like_lists" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "teams" ADD CONSTRAINT "teams_fk_leader" FOREIGN KEY ("leader")
REFERENCES "player_pjs" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_born_stats" FOREIGN KEY ("born_stats")
REFERENCES "stats" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_equipment" FOREIGN KEY ("equipment")
REFERENCES "equipment" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_inventory" FOREIGN KEY ("inventory")
REFERENCES "inventories" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_owner" FOREIGN KEY ("owner")
REFERENCES "players" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_skills" FOREIGN KEY ("skills")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_spells" FOREIGN KEY ("spells")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_team" FOREIGN KEY ("team")
REFERENCES "teams" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_training_stats" FOREIGN KEY ("training_stats")
REFERENCES "stats" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_equipment" FOREIGN KEY ("equipment")
REFERENCES "equipment" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_inventory" FOREIGN KEY ("inventory")
REFERENCES "inventories" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_skills" FOREIGN KEY ("skills")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_spells" FOREIGN KEY ("spells")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_stats" FOREIGN KEY ("stats")
REFERENCES "stats" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs_flags" ADD CONSTRAINT "player_pjs_flags_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs_known_places" ADD CONSTRAINT "player_pjs_known_places_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs_log" ADD CONSTRAINT "player_pjs_log_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;

View File

@ -0,0 +1,318 @@
--
-- Created by SQL::Translator::Producer::PostgreSQL
-- Created on Sun Jun 25 18:30:43 2023
--
;
--
-- Table: equipment
--
CREATE TABLE "equipment" (
"uuid" uuid NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: inventories
--
CREATE TABLE "inventories" (
"uuid" uuid NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: players
--
CREATE TABLE "players" (
"uuid" uuid NOT NULL,
"username" text NOT NULL,
"encrypted_password" text NOT NULL,
"email" text NOT NULL,
"verified" boolean NOT NULL,
"verification_token" text,
"register_date" timestamp DEFAULT NOW() NOT NULL,
"last_activity" timestamp DEFAULT NOW() NOT NULL,
PRIMARY KEY ("uuid"),
CONSTRAINT "unique_constraint_email" UNIQUE ("email"),
CONSTRAINT "unique_constraint_username" UNIQUE ("username")
);
;
--
-- Table: skill_like_lists
--
CREATE TABLE "skill_like_lists" (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: stats
--
CREATE TABLE "stats" (
"uuid" uuid NOT NULL,
"health" integer NOT NULL,
"mana" integer NOT NULL,
"strength" integer NOT NULL,
"resistance" integer NOT NULL,
"magic" integer NOT NULL,
"speed" integer NOT NULL,
"intelligence" integer NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: equipment_items
--
CREATE TABLE "equipment_items" (
"kind" text NOT NULL,
"equipment" uuid NOT NULL,
"identifier" text NOT NULL,
"quantity" integer NOT NULL,
PRIMARY KEY ("kind", "equipment")
);
CREATE INDEX "equipment_items_idx_equipment" on "equipment_items" ("equipment");
;
--
-- Table: inventory_items
--
CREATE TABLE "inventory_items" (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
"inventory" uuid NOT NULL,
"identifier" text NOT NULL,
"quantity" integer NOT NULL,
PRIMARY KEY ("uuid"),
CONSTRAINT "inventory_items_unique_item" UNIQUE ("inventory", "identifier")
);
CREATE INDEX "inventory_items_idx_inventory" on "inventory_items" ("inventory");
;
--
-- Table: skill_like_items
--
CREATE TABLE "skill_like_items" (
"identifier" text NOT NULL,
"owner_list" uuid NOT NULL,
"level" integer DEFAULT 1 NOT NULL,
PRIMARY KEY ("identifier", "owner_list")
);
CREATE INDEX "skill_like_items_idx_owner_list" on "skill_like_items" ("owner_list");
;
--
-- Table: teams
--
CREATE TABLE "teams" (
"uuid" uuid NOT NULL,
"is_exploring" boolean DEFAULT false NOT NULL,
"action_frame" integer DEFAULT 0 NOT NULL,
"is_moving" boolean DEFAULT false NOT NULL,
"moving_to" jsonb DEFAULT 'null' NOT NULL,
"leader" uuid,
"name" text NOT NULL,
"planet" text NOT NULL,
"super_area" text NOT NULL,
"area" text NOT NULL,
"location" text NOT NULL,
"current_battle" uuid,
PRIMARY KEY ("uuid"),
CONSTRAINT "u_name" UNIQUE ("name")
);
CREATE INDEX "teams_idx_leader" on "teams" ("leader");
;
--
-- Table: player_pjs
--
CREATE TABLE "player_pjs" (
"uuid" uuid NOT NULL,
"owner" uuid NOT NULL,
"full_name" text NOT NULL,
"short_name" text NOT NULL,
"nick" text NOT NULL,
"race" text NOT NULL,
"team" uuid NOT NULL,
"creation_date" timestamp DEFAULT NOW() NOT NULL,
"last_activity" timestamp DEFAULT NOW() NOT NULL,
"experience" integer DEFAULT 1 NOT NULL,
"equipment" uuid NOT NULL,
"born_stats" uuid NOT NULL,
"training_stats" uuid NOT NULL,
"skills" uuid NOT NULL,
"spells" uuid NOT NULL,
"inventory" uuid NOT NULL,
"health" integer NOT NULL,
"mana" integer NOT NULL,
"combat_target" uuid,
"combat_action" text,
PRIMARY KEY ("uuid")
);
CREATE INDEX "player_pjs_idx_born_stats" on "player_pjs" ("born_stats");
CREATE INDEX "player_pjs_idx_equipment" on "player_pjs" ("equipment");
CREATE INDEX "player_pjs_idx_inventory" on "player_pjs" ("inventory");
CREATE INDEX "player_pjs_idx_owner" on "player_pjs" ("owner");
CREATE INDEX "player_pjs_idx_skills" on "player_pjs" ("skills");
CREATE INDEX "player_pjs_idx_spells" on "player_pjs" ("spells");
CREATE INDEX "player_pjs_idx_team" on "player_pjs" ("team");
CREATE INDEX "player_pjs_idx_training_stats" on "player_pjs" ("training_stats");
;
--
-- Table: player_companion_npcs
--
CREATE TABLE "player_companion_npcs" (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
"owner" uuid NOT NULL,
"identifier" text NOT NULL,
"nick" text,
"race" text NOT NULL,
"level" integer DEFAULT 1 NOT NULL,
"exp" integer DEFAULT 1 NOT NULL,
"equipment" uuid NOT NULL,
"stats" uuid NOT NULL,
"skills" uuid NOT NULL,
"spells" uuid NOT NULL,
"inventory" uuid NOT NULL,
PRIMARY KEY ("uuid")
);
CREATE INDEX "player_companion_npcs_idx_equipment" on "player_companion_npcs" ("equipment");
CREATE INDEX "player_companion_npcs_idx_inventory" on "player_companion_npcs" ("inventory");
CREATE INDEX "player_companion_npcs_idx_owner" on "player_companion_npcs" ("owner");
CREATE INDEX "player_companion_npcs_idx_skills" on "player_companion_npcs" ("skills");
CREATE INDEX "player_companion_npcs_idx_spells" on "player_companion_npcs" ("spells");
CREATE INDEX "player_companion_npcs_idx_stats" on "player_companion_npcs" ("stats");
;
--
-- Table: player_pjs_flags
--
CREATE TABLE "player_pjs_flags" (
"name" text NOT NULL,
"owner" uuid NOT NULL,
PRIMARY KEY ("name", "owner")
);
CREATE INDEX "player_pjs_flags_idx_owner" on "player_pjs_flags" ("owner");
CREATE INDEX "index_flag" on "player_pjs_flags" ("owner", "name");
;
--
-- Table: player_pjs_known_places
--
CREATE TABLE "player_pjs_known_places" (
"owner" uuid NOT NULL,
"planet" text NOT NULL,
"super_area" text NOT NULL,
"area" text NOT NULL,
"location" text NOT NULL,
PRIMARY KEY ("owner", "planet", "super_area", "area", "location")
);
CREATE INDEX "player_pjs_known_places_idx_owner" on "player_pjs_known_places" ("owner");
;
--
-- Table: player_pjs_log
--
CREATE TABLE "player_pjs_log" (
"uuid" uuid NOT NULL,
"content" jsonb NOT NULL,
"owner" uuid NOT NULL,
"date" timestamp DEFAULT NOW() NOT NULL,
PRIMARY KEY ("uuid")
);
CREATE INDEX "player_pjs_log_idx_owner" on "player_pjs_log" ("owner");
CREATE INDEX "index_log" on "player_pjs_log" ("owner", "date");
;
--
-- Foreign Key Definitions
--
;
ALTER TABLE "equipment_items" ADD CONSTRAINT "equipment_items_fk_equipment" FOREIGN KEY ("equipment")
REFERENCES "equipment" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "inventory_items" ADD CONSTRAINT "inventory_items_fk_inventory" FOREIGN KEY ("inventory")
REFERENCES "inventories" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "skill_like_items" ADD CONSTRAINT "skill_like_items_fk_owner_list" FOREIGN KEY ("owner_list")
REFERENCES "skill_like_lists" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "teams" ADD CONSTRAINT "teams_fk_leader" FOREIGN KEY ("leader")
REFERENCES "player_pjs" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_born_stats" FOREIGN KEY ("born_stats")
REFERENCES "stats" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_equipment" FOREIGN KEY ("equipment")
REFERENCES "equipment" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_inventory" FOREIGN KEY ("inventory")
REFERENCES "inventories" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_owner" FOREIGN KEY ("owner")
REFERENCES "players" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_skills" FOREIGN KEY ("skills")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_spells" FOREIGN KEY ("spells")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_team" FOREIGN KEY ("team")
REFERENCES "teams" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_training_stats" FOREIGN KEY ("training_stats")
REFERENCES "stats" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_equipment" FOREIGN KEY ("equipment")
REFERENCES "equipment" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_inventory" FOREIGN KEY ("inventory")
REFERENCES "inventories" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_skills" FOREIGN KEY ("skills")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_spells" FOREIGN KEY ("spells")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_stats" FOREIGN KEY ("stats")
REFERENCES "stats" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs_flags" ADD CONSTRAINT "player_pjs_flags_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs_known_places" ADD CONSTRAINT "player_pjs_known_places_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs_log" ADD CONSTRAINT "player_pjs_log_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;

View File

@ -0,0 +1,319 @@
--
-- Created by SQL::Translator::Producer::PostgreSQL
-- Created on Sun Jun 25 18:30:56 2023
--
;
--
-- Table: equipment
--
CREATE TABLE "equipment" (
"uuid" uuid NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: inventories
--
CREATE TABLE "inventories" (
"uuid" uuid NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: players
--
CREATE TABLE "players" (
"uuid" uuid NOT NULL,
"username" text NOT NULL,
"encrypted_password" text NOT NULL,
"email" text NOT NULL,
"verified" boolean NOT NULL,
"verification_token" text,
"register_date" timestamp DEFAULT NOW() NOT NULL,
"last_activity" timestamp DEFAULT NOW() NOT NULL,
PRIMARY KEY ("uuid"),
CONSTRAINT "unique_constraint_email" UNIQUE ("email"),
CONSTRAINT "unique_constraint_username" UNIQUE ("username")
);
;
--
-- Table: skill_like_lists
--
CREATE TABLE "skill_like_lists" (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: stats
--
CREATE TABLE "stats" (
"uuid" uuid NOT NULL,
"health" integer NOT NULL,
"mana" integer NOT NULL,
"strength" integer NOT NULL,
"resistance" integer NOT NULL,
"magic" integer NOT NULL,
"speed" integer NOT NULL,
"intelligence" integer NOT NULL,
PRIMARY KEY ("uuid")
);
;
--
-- Table: equipment_items
--
CREATE TABLE "equipment_items" (
"kind" text NOT NULL,
"equipment" uuid NOT NULL,
"identifier" text NOT NULL,
"quantity" integer NOT NULL,
PRIMARY KEY ("kind", "equipment")
);
CREATE INDEX "equipment_items_idx_equipment" on "equipment_items" ("equipment");
;
--
-- Table: inventory_items
--
CREATE TABLE "inventory_items" (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
"inventory" uuid NOT NULL,
"identifier" text NOT NULL,
"quantity" integer NOT NULL,
PRIMARY KEY ("uuid"),
CONSTRAINT "inventory_items_unique_item" UNIQUE ("inventory", "identifier")
);
CREATE INDEX "inventory_items_idx_inventory" on "inventory_items" ("inventory");
;
--
-- Table: skill_like_items
--
CREATE TABLE "skill_like_items" (
"identifier" text NOT NULL,
"owner_list" uuid NOT NULL,
"level" integer DEFAULT 1 NOT NULL,
PRIMARY KEY ("identifier", "owner_list")
);
CREATE INDEX "skill_like_items_idx_owner_list" on "skill_like_items" ("owner_list");
;
--
-- Table: teams
--
CREATE TABLE "teams" (
"uuid" uuid NOT NULL,
"is_exploring" boolean DEFAULT false NOT NULL,
"action_frame" integer DEFAULT 0 NOT NULL,
"is_moving" boolean DEFAULT false NOT NULL,
"last_spawn" jsonb DEFAULT 'null' NOT NULL,
"moving_to" jsonb DEFAULT 'null' NOT NULL,
"leader" uuid,
"name" text NOT NULL,
"planet" text NOT NULL,
"super_area" text NOT NULL,
"area" text NOT NULL,
"location" text NOT NULL,
"current_battle" uuid,
PRIMARY KEY ("uuid"),
CONSTRAINT "u_name" UNIQUE ("name")
);
CREATE INDEX "teams_idx_leader" on "teams" ("leader");
;
--
-- Table: player_pjs
--
CREATE TABLE "player_pjs" (
"uuid" uuid NOT NULL,
"owner" uuid NOT NULL,
"full_name" text NOT NULL,
"short_name" text NOT NULL,
"nick" text NOT NULL,
"race" text NOT NULL,
"team" uuid NOT NULL,
"creation_date" timestamp DEFAULT NOW() NOT NULL,
"last_activity" timestamp DEFAULT NOW() NOT NULL,
"experience" integer DEFAULT 1 NOT NULL,
"equipment" uuid NOT NULL,
"born_stats" uuid NOT NULL,
"training_stats" uuid NOT NULL,
"skills" uuid NOT NULL,
"spells" uuid NOT NULL,
"inventory" uuid NOT NULL,
"health" integer NOT NULL,
"mana" integer NOT NULL,
"combat_target" uuid,
"combat_action" text,
PRIMARY KEY ("uuid")
);
CREATE INDEX "player_pjs_idx_born_stats" on "player_pjs" ("born_stats");
CREATE INDEX "player_pjs_idx_equipment" on "player_pjs" ("equipment");
CREATE INDEX "player_pjs_idx_inventory" on "player_pjs" ("inventory");
CREATE INDEX "player_pjs_idx_owner" on "player_pjs" ("owner");
CREATE INDEX "player_pjs_idx_skills" on "player_pjs" ("skills");
CREATE INDEX "player_pjs_idx_spells" on "player_pjs" ("spells");
CREATE INDEX "player_pjs_idx_team" on "player_pjs" ("team");
CREATE INDEX "player_pjs_idx_training_stats" on "player_pjs" ("training_stats");
;
--
-- Table: player_companion_npcs
--
CREATE TABLE "player_companion_npcs" (
"uuid" uuid DEFAULT uuid_generate_v4() NOT NULL,
"owner" uuid NOT NULL,
"identifier" text NOT NULL,
"nick" text,
"race" text NOT NULL,
"level" integer DEFAULT 1 NOT NULL,
"exp" integer DEFAULT 1 NOT NULL,
"equipment" uuid NOT NULL,
"stats" uuid NOT NULL,
"skills" uuid NOT NULL,
"spells" uuid NOT NULL,
"inventory" uuid NOT NULL,
PRIMARY KEY ("uuid")
);
CREATE INDEX "player_companion_npcs_idx_equipment" on "player_companion_npcs" ("equipment");
CREATE INDEX "player_companion_npcs_idx_inventory" on "player_companion_npcs" ("inventory");
CREATE INDEX "player_companion_npcs_idx_owner" on "player_companion_npcs" ("owner");
CREATE INDEX "player_companion_npcs_idx_skills" on "player_companion_npcs" ("skills");
CREATE INDEX "player_companion_npcs_idx_spells" on "player_companion_npcs" ("spells");
CREATE INDEX "player_companion_npcs_idx_stats" on "player_companion_npcs" ("stats");
;
--
-- Table: player_pjs_flags
--
CREATE TABLE "player_pjs_flags" (
"name" text NOT NULL,
"owner" uuid NOT NULL,
PRIMARY KEY ("name", "owner")
);
CREATE INDEX "player_pjs_flags_idx_owner" on "player_pjs_flags" ("owner");
CREATE INDEX "index_flag" on "player_pjs_flags" ("owner", "name");
;
--
-- Table: player_pjs_known_places
--
CREATE TABLE "player_pjs_known_places" (
"owner" uuid NOT NULL,
"planet" text NOT NULL,
"super_area" text NOT NULL,
"area" text NOT NULL,
"location" text NOT NULL,
PRIMARY KEY ("owner", "planet", "super_area", "area", "location")
);
CREATE INDEX "player_pjs_known_places_idx_owner" on "player_pjs_known_places" ("owner");
;
--
-- Table: player_pjs_log
--
CREATE TABLE "player_pjs_log" (
"uuid" uuid NOT NULL,
"content" jsonb NOT NULL,
"owner" uuid NOT NULL,
"date" timestamp DEFAULT NOW() NOT NULL,
PRIMARY KEY ("uuid")
);
CREATE INDEX "player_pjs_log_idx_owner" on "player_pjs_log" ("owner");
CREATE INDEX "index_log" on "player_pjs_log" ("owner", "date");
;
--
-- Foreign Key Definitions
--
;
ALTER TABLE "equipment_items" ADD CONSTRAINT "equipment_items_fk_equipment" FOREIGN KEY ("equipment")
REFERENCES "equipment" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "inventory_items" ADD CONSTRAINT "inventory_items_fk_inventory" FOREIGN KEY ("inventory")
REFERENCES "inventories" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "skill_like_items" ADD CONSTRAINT "skill_like_items_fk_owner_list" FOREIGN KEY ("owner_list")
REFERENCES "skill_like_lists" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "teams" ADD CONSTRAINT "teams_fk_leader" FOREIGN KEY ("leader")
REFERENCES "player_pjs" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_born_stats" FOREIGN KEY ("born_stats")
REFERENCES "stats" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_equipment" FOREIGN KEY ("equipment")
REFERENCES "equipment" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_inventory" FOREIGN KEY ("inventory")
REFERENCES "inventories" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_owner" FOREIGN KEY ("owner")
REFERENCES "players" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_skills" FOREIGN KEY ("skills")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_spells" FOREIGN KEY ("spells")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_team" FOREIGN KEY ("team")
REFERENCES "teams" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs" ADD CONSTRAINT "player_pjs_fk_training_stats" FOREIGN KEY ("training_stats")
REFERENCES "stats" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_equipment" FOREIGN KEY ("equipment")
REFERENCES "equipment" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_inventory" FOREIGN KEY ("inventory")
REFERENCES "inventories" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_skills" FOREIGN KEY ("skills")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_spells" FOREIGN KEY ("spells")
REFERENCES "skill_like_lists" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_companion_npcs" ADD CONSTRAINT "player_companion_npcs_fk_stats" FOREIGN KEY ("stats")
REFERENCES "stats" ("uuid") DEFERRABLE;
;
ALTER TABLE "player_pjs_flags" ADD CONSTRAINT "player_pjs_flags_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs_known_places" ADD CONSTRAINT "player_pjs_known_places_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;
ALTER TABLE "player_pjs_log" ADD CONSTRAINT "player_pjs_log_fk_owner" FOREIGN KEY ("owner")
REFERENCES "player_pjs" ("uuid") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE;
;

View File

@ -0,0 +1,12 @@
-- Convert schema '/home/sergio/LasTres/script/../dbicdh/_source/deploy/10/001-auto.yml' to '/home/sergio/LasTres/script/../dbicdh/_source/deploy/11/001-auto.yml':;
;
BEGIN;
;
ALTER TABLE teams ADD COLUMN current_battle uuid;
;
COMMIT;

View File

@ -0,0 +1,12 @@
-- Convert schema '/home/sergio/LasTres/script/../dbicdh/_source/deploy/11/001-auto.yml' to '/home/sergio/LasTres/script/../dbicdh/_source/deploy/12/001-auto.yml':;
;
BEGIN;
;
ALTER TABLE teams ADD COLUMN last_spawn jsonb DEFAULT 'null' NOT NULL;
;
COMMIT;

View File

@ -0,0 +1,18 @@
-- Convert schema '/home/sergio/LasTres/script/../dbicdh/_source/deploy/9/001-auto.yml' to '/home/sergio/LasTres/script/../dbicdh/_source/deploy/10/001-auto.yml':;
;
BEGIN;
;
ALTER TABLE player_pjs ADD COLUMN combat_target uuid;
;
ALTER TABLE player_pjs ADD COLUMN combat_action text;
;
ALTER TABLE player_pjs ALTER COLUMN uuid DROP DEFAULT;
;
COMMIT;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -8,39 +8,143 @@ use warnings;
use feature 'signatures';
use Moo::Role;
use LasTres::Battle;
use LasTres::EnemyTeam;
use LasTres::Util;
requires qw/identifier locations name parent/;
has children => (
is => 'ro',
lazy => 1,
is => 'ro',
lazy => 1,
builder => \&_build_children,
);
## OVERRIDE
sub get_auto_discover($self) {
sub get_auto_discover ($self) {
return 0;
}
## OVERRIDE
sub frames_to_move($self) {
sub frames_to_move ($self) {
return 5;
}
## OVERRIDE
sub frames_to_explore($self) {
sub frames_to_explore ($self) {
return 7;
}
## OVERRIDE
sub has_movement_auto_combat ($self) {
return 0;
}
## OVERRIDE
sub min_enemies_per_head ($self) {
return 1;
}
## OVERRIDE
sub max_enemies_per_head ($self) {
return 1;
}
## OVERRIDE
sub list_of_enemies ( $self, $pj ) {
return [];
}
## OVERRIDE
sub chance_combat ($self) {
return 50;
}
## OVERRIDE (Always use $self->SUPER::on_move_explore_frame.)
sub on_move_explore_frame ( $self, $team ) {
return if $self->_try_to_start_battle($team);
}
sub _try_to_start_battle ( $self, $team ) {
if ( !$self->has_movement_auto_combat ) {
## Combat not enabled.
return 0;
}
my $dice_result = LasTres::Util::rand_range_int( 0, 100 );
if ( $dice_result > $self->chance_combat ) {
## No combat in this frame by RNG choice.
return 0;
}
## Creating enemy team.
my $battle = LasTres::Battle->new( team1 => $team, last_frame => 0 );
my $team2 = LasTres::EnemyTeam->new( current_battle => $battle->uuid );
my @enemy_members;
$self->_generate_enemies_team($team2, \@enemy_members, $team);
if ( !scalar @enemy_members ) {
## No enemies generated.
return 0;
}
$team2->members( \@enemy_members );
$battle->team2($team2);
$battle->save_redis;
$team->current_battle( $battle->uuid );
my @enemy_log_list;
my $first = 1;
for my $member ($team2->combat_members->@*) {
if (!$first) {
push @enemy_log_list, { text => ', ' };
}
$first = 0;
push @enemy_log_list, {
color => 'red',
text => $member->nick,
};
push @enemy_log_list, {
text => " NIVEL @{[$member->level]} VIDA @{[$member->health]}/@{[$member->max_health]}"
};
}
for my $member ($team->members) {
$member->append_log_line([
{
text => 'Empieza un combate contra: '
},
@enemy_log_list
]);
}
$team->update;
return 1;
}
sub _generate_enemies_team ($self, $enemy_team, $enemy_members_array, $team) {
for my $pj ( $team->combat_members ) {
my $number_of_enemies =
LasTres::Util::rand_range_int( $self->min_enemies_per_head,
$self->max_enemies_per_head );
$self->_generate_n_enemies_pj( $enemy_team, $number_of_enemies, $enemy_members_array, $pj );
}
}
sub _generate_n_enemies_pj ( $self, $enemy_team, $number_of_enemies,
$enemy_members_array, $pj )
{
my @list_possible_enemies = @{ $self->list_of_enemies };
if ( !scalar @list_possible_enemies ) {
warn "$self does not have defined enemies.";
return;
}
for ( my $i = 0 ; $i < $number_of_enemies ; $i++ ) {
my $choice_enemy_index =
LasTres::Util::rand_range_int( 0, $#list_possible_enemies );
my $choice_enemy = $list_possible_enemies[$choice_enemy_index];
push @$enemy_members_array, $choice_enemy->generate($enemy_team);
}
}
## OVERRIDE
sub can_explore {
return 1;
}
## OVERRIDE
sub enemies($self, $pj) {
}
sub _build_children($self) {
sub _build_children ($self) {
my $locations = $self->locations;
my @locations = map { $locations->{$_} } keys %$locations;
@locations = sort { $a->name cmp $b->name } @locations;

163
lib/LasTres/Battle.pm Normal file
View File

@ -0,0 +1,163 @@
package LasTres::Battle;
use v5.36.0;
use strict;
use warnings;
use feature 'signatures';
use Moo;
use UUID::URandom qw/create_uuid_string/;
use LasTres::Util;
use LasTres::EnemyTeam;
use JSON qw//;
has uuid => (
is => 'rw',
default => \&_build_uuid,
);
has team1 => (
is => 'rw',
required => 1,
);
has team2 => ( is => 'rw', );
has last_frame => (
is => 'rw',
required => 1,
);
sub sanity_check ($self) {
my $team1 = $self->team1;
my $team2 = $self->team2;
if ( !defined $team2 ) {
return 0;
}
if ( !defined $team1->current_battle
|| !defined $team2->current_battle
|| $team1->current_battle ne $self->uuid
|| $team2->current_battle ne $self->uuid )
{
return 0;
}
return 1;
}
sub winner ($self) {
if ($self->team2->is_defeated) {
return $self->team1;
}
if ($self->team1->is_defeated) {
return $self->team2;
}
return;
}
sub try_turn ($self, $entity) {
my $combat_target = $entity->combat_target;
my $enemy_team = $self->get_enemy_team($entity->team);
my @combat_members_enemy = @{$enemy_team->combat_members};
if ($entity->health <= 0) {
# This entity is out of the battle.
return;
}
if (defined $entity->combat_target) {{
my @target_list_only_one_should_match = grep { $combat_target eq $_->uuid } @combat_members_enemy;
if (!scalar @target_list_only_one_should_match) {
undef($combat_target);
next;
}
$combat_target = $target_list_only_one_should_match[0];
}}
if (!defined $combat_target) {
$combat_target = $combat_members_enemy[LasTres::Util::rand_range_int(0, $#combat_members_enemy)];
$entity->combat_target($combat_target->uuid);
$entity->update;
}
$entity->attack($combat_target);
$combat_target->update;
}
sub get_enemy_team ($self, $team) {
if ($self->team1->uuid ne $team->uuid) {
return $self->team1;
}
return $self->team2;
}
sub loser ($self) {
if ($self->team2->is_defeated) {
return $self->team2;
}
if ($self->team1->is_defeated) {
return $self->team1;
}
return;
}
sub end ($self) {
require LasTres::Redis;
my $redis = LasTres::Redis->new;
$self->team1->current_battle(undef);
$self->team1->update;
if ( defined $self->team2 ) {
$self->team2->current_battle(undef);
$self->team2->update;
}
$redis->db->expire( $redis->battle_key( $self->uuid ), 0 );
}
sub _build_uuid {
return create_uuid_string();
}
sub to_json ($self) {
return {
uuid => $self->uuid,
team1 => $self->team1->to_serializable,
team2 => $self->team2->to_serializable,
last_frame => $self->last_frame,
};
}
sub save_redis ($self) {
require LasTres::Redis;
my $redis = LasTres::Redis->new;
$redis->db->setex( $redis->battle_key( $self->uuid ),
3600 * 6, JSON::to_json($self->to_json));
}
sub get_redis ( $class, $uuid ) {
require LasTres::Redis;
my $redis = LasTres::Redis->new;
my $hash_self;
eval {
$hash_self = JSON::from_json($redis->db->get( $redis->battle_key($uuid) ));
};
if ($@) {
return;
}
return $class->from_json( $uuid, $hash_self );
}
sub from_json ( $class, $uuid, $hash ) {
# I do not take the hash uuid since if redis lies that could be really bad.
return $class->new(
uuid => $uuid,
team1 => $class->deserialize_team($hash->{team1}),
team2 => $class->deserialize_team($hash->{team2}),
last_frame => $hash->{last_frame},
);
}
sub deserialize_team ( $class, $team_hash ) {
if ( $team_hash->{is_db} ) {
return LasTres::Schema::Result::Team->from_serializable($team_hash);
}
return LasTres::EnemyTeam->from_serializable($team_hash);
}
1;

View File

@ -4,15 +4,109 @@ use v5.36.0;
use strict;
use warnings;
use utf8;
use feature 'signatures';
use Moo::Role;
requires( 'race', 'nick', 'born_stats', 'training_stats', 'experience' );
requires(
'uuid', 'race_string', 'nick', 'born_stats',
'health', 'mana', 'training_stats', 'experience',
'combat_action', 'combat_target', 'team', 'update',
);
sub append_log_line {
}
sub race ($self) {
my $hash;
$hash = LasTres::Races->new->hash;
if ( $self->isa('LasTres::Schema::Result::PJ') ) {
$hash = LasTres::Races->new->hash_playable;
}
my $race = $hash->{ $self->race_string };
if ( !defined $race ) {
die "Not valid race for entity " . $self->uuid;
}
return $race;
}
sub attack ( $self, $enemy_entity ) {
my $defense = $enemy_entity->resistance;
my $attack = $self->strength;
my $level = $self->level;
# This should change with the different attacks.
my $power = 20;
my $damage = int(
( ( ( 2 * $level ) / 5 + 2 ) * $power * $attack / $defense ) / 50 + 2 );
my $final_health = $enemy_entity->health - $damage;
if ( $final_health < 0 ) {
$final_health = 0;
}
$enemy_entity->health($final_health);
my $team1 = $self->team;
my $team2 = $enemy_entity->team;
for my $member ( $team1->combat_members->@* ) {
$member->append_log_line(
[
{ color => 'green', text => "@{[$self->nick]}" },
{
text => ' atacó a '
},
{ color => 'red', text => "@{[$enemy_entity->nick]}" },
{
text => ". Le causó $damage puntos de daño, ",
},
{
text =>
"vida restante @{[$enemy_entity->health]}/@{[$enemy_entity->max_health]}."
}
]
);
if ( $enemy_entity->health == 0 ) {
$member->append_log_line(
[
{ color => 'red', text => "@{[$enemy_entity->nick]}" },
{ text => " se ha debilitado." },
]
);
}
}
for my $member ( $team2->combat_members->@* ) {
$member->append_log_line(
[
{ color => 'red', text => "@{[$self->nick]}" },
{
text => ' atacó a '
},
{ color => 'green', text => "@{[$enemy_entity->nick]}" },
{
text => ". Le causó $damage puntos de daño, ",
},
{
text =>
"vida restante @{[$enemy_entity->health]}/@{[$enemy_entity->max_health]}."
}
]
);
if ( $enemy_entity->health == 0 ) {
$member->append_log_line(
[
{ color => 'green', text => "@{[$enemy_entity->nick]}" },
{ text => " se ha debilitado." },
]
);
}
}
}
sub level ($self) {
return int($self->experience**( 1 / 3 ));
# Floating point trick, works in level 100,
# for upper levels maybe it may need adjusting.
return int( $self->experience**( 1 / 3 ) + 0.0000000000001 );
}
sub max_health ($self) {
@ -89,55 +183,4 @@ sub max_mana ($self) {
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;

View File

@ -0,0 +1,17 @@
package LasTres::CombatCapableTeam;
use v5.36.0;
use strict;
use warnings;
use feature 'signatures';
use Moo::Role;
requires qw/uuid combat_members current_battle to_serializable from_serializable update is_defeated on_win_combat on_lose_combat update/;
sub get_from_storage($self) {
return $self;
}
1;

View File

@ -129,6 +129,8 @@ sub create ($self) {
sub _insert_new_player ( $self, $owner, $full_name, $short_name, $nick, $race )
{
require LasTres::Schema;
my $schema = LasTres::Schema->Schema;
my $uuid_born_stats = create_uuid_string;
my $uuid_training_stats = create_uuid_string;
my $uuid_equipment = create_uuid_string;
@ -139,7 +141,7 @@ sub _insert_new_player ( $self, $owner, $full_name, $short_name, $nick, $race )
my $uuid_team = create_uuid_string;
my $uuid_owner = $owner->uuid;
my $born_stats = LasTres::Stats->new(
my $born_stats = $schema->resultset('Stats')->new({
uuid => $uuid_born_stats,
health => $self->_get_random_born_stat,
strength => $self->_get_random_born_stat,
@ -148,9 +150,9 @@ sub _insert_new_player ( $self, $owner, $full_name, $short_name, $nick, $race )
magic => $self->_get_random_born_stat,
speed => $self->_get_random_born_stat,
intelligence => $self->_get_random_born_stat,
);
});
$born_stats->insert;
my $training_stats = LasTres::Stats->new(
my $training_stats = $schema->resultset->new({
uuid => $uuid_training_stats,
health => 0,
strength => 0,
@ -159,7 +161,7 @@ sub _insert_new_player ( $self, $owner, $full_name, $short_name, $nick, $race )
magic => 0,
speed => 0,
intelligence => 0,
);
});
$training_stats->insert;
$result_set_equipments->new( { uuid => $uuid_equipment } )->insert;
$result_set_skill_like_list->new( { uuid => $uuid_skills } )->insert;

View File

@ -94,7 +94,7 @@ sub handle ( $self, $ws, $session, $data ) {
sub _location_data($self, $pj) {
my $connected_places = $self->_get_connected_places($pj);
my $team = $pj->team;
my $team = $pj->team->get_from_storage;
my $location = $team->location;
return (
location_data => {

View File

@ -43,6 +43,7 @@ sub handle ( $self, $ws, $session, $data ) {
{
return $ws->send( to_json( { error => "The location is malformed" } ) );
}
$session->{pj} = $session->{pj}->get_from_storage;
my $pj = $session->{pj};
if ( !defined $pj ) {
return $ws->send(

166
lib/LasTres/Enemy.pm Normal file
View File

@ -0,0 +1,166 @@
package LasTres::Enemy;
use v5.36.0;
use strict;
use warnings;
use feature 'signatures';
use Moo;
use UUID::URandom qw/create_uuid_string/;
use LasTres::Stats;
has uuid => (
is => 'rw',
default => sub ($self) {
return create_uuid_string();
},
);
has race => (
is => 'rw',
required => 1,
accessor => "race_string",
);
has nick => (
is => 'rw',
required => 1,
);
has born_stats => (
is => 'rw',
default => \&_build_born_stats
);
has training_stats => (
is => 'rw',
default => \&_build_training_stats,
);
has level => (
is => 'rw',
required => 1,
);
has team => ( is => 'rw', );
has zhealth => (
is => 'rw',
default => sub ($self) {
return $self->max_health;
},
accessor => "health",
);
has zmana => (
is => 'rw',
default => sub ($self) {
return $self->max_mana;
},
accessor => "mana",
);
has combat_target => (
is => 'rw',
accessor => "_combat_target",
);
after team => sub ( $self, @extra ) {
if ( ref $self->{team} && !Scalar::Util::isweak( $self->{team} ) ) {
Scalar::Util::weaken( $self->{team} );
}
};
sub _build_born_stats ($self) {
return LasTres::Stats->new(
health => int( rand(32) ),
mana => int( rand(32) ),
strength => int( rand(32) ),
resistance => int( rand(32) ),
magic => int( rand(32) ),
speed => int( rand(32) ),
intelligence => int( rand(32) ),
);
}
sub _build_training_stats ($self) {
# We assume that most enemies does not have sense that they trained before.
return LasTres::Stats->new(
health => 0,
mana => 0,
strength => 0,
resistance => 0,
magic => 0,
speed => 0,
intelligence => 0,
);
}
sub experience ($self) {
return $self->level**3;
}
sub combat_action ($self) {
return;
}
sub combat_target ($self, @extra) {
my $set;
if (@extra) {
$set = shift @extra;
}
if (!defined $self->_combat_target) {
$self->team( $self->team->get_from_storage );
my $battle_uuid = $self->team->current_battle;
my $battle = LasTres::Battle->get_redis($battle_uuid);
my $target_team = $battle->get_enemy_team($self->team);
my $target_team_members = $target_team->combat_members;
@$target_team_members = grep { $_->health > 0 } @$target_team_members;
if (!@$target_team_members) {
return;
}
my $target_index = LasTres::Util::rand_range_int(0, $#$target_team_members);
$self->_combat_target($target_team_members->[$target_index]->uuid);
}
if (defined $set) {
$self->_combat_target($set);
}
return $self->_combat_target;
}
sub update ($self) {
return $self;
}
sub to_hash ($self) {
return {
kind => 'NPCEnemy',
uuid => $self->uuid,
race => $self->race_string,
nick => $self->nick,
born_stats => $self->born_stats->to_hash,
training_stats => $self->training_stats->to_hash,
level => $self->level,
health => $self->health,
mana => $self->mana,
};
}
sub from_hash ( $class, $hash ) {
return $class->new(
uuid => $hash->{uuid},
race => $hash->{race},
nick => $hash->{nick},
born_stats => LasTres::Stats->from_hash( $hash->{born_stats} ),
training_stats => LasTres::Stats->from_hash( $hash->{training_stats} ),
level => $hash->{level},
zhealth => $hash->{health},
zmana => $hash->{mana},
);
}
with 'LasTres::RedisEnemy';
1;

33
lib/LasTres/EnemyArea.pm Normal file
View File

@ -0,0 +1,33 @@
package LasTres::EnemyArea;
use v5.36.0;
use strict;
use warnings;
use Moo;
use LasTres::Enemy;
has race => (
is => 'rw',
required => 1,
);
has nick => (
is => 'rw',
required => 1,
);
has level => (
is => 'rw',
required => 1,
);
sub generate ( $self, $team ) {
return LasTres::Enemy->new(
race => $self->race,
nick => $self->nick,
level => $self->level,
team => $team,
);
}
1;

79
lib/LasTres/EnemyTeam.pm Normal file
View File

@ -0,0 +1,79 @@
package LasTres::EnemyTeam;
use v5.36.0;
use strict;
use warnings;
use feature 'signatures';
use Moo;
use LasTres::Enemy;
use UUID::URandom qw/create_uuid_string/;
has uuid => (
is => 'rw',
default => sub ($self) {
return create_uuid_string();
},
);
has members => ( is => 'rw', );
has current_battle => (
is => 'rw',
required => 1,
);
sub is_defeated ($self) {
my @members = @{ $self->combat_members };
my @alive_members = grep { $_->health > 0 } @members;
if ( !scalar @alive_members ) {
return 1;
}
return 0;
}
sub update ($self) {
return $self;
}
sub on_lose_combat ($self) {
}
sub on_win_combat ($self) {
}
sub combat_members ($self) {
return $self->members;
}
sub to_serializable ($self) {
return {
members => [ map { $_->to_hash } @{ $self->members } ],
current_battle => $self->current_battle,
uuid => $self->uuid,
};
}
sub from_serializable ( $class, $hash ) {
if ( $hash->{is_db} ) {
die "This is not an Enemy Team but a DB Team.";
}
my $hash_members = $hash->{members};
my $current_battle = $hash->{current_battle};
my $uuid = $hash->{uuid};
my $members = [ map { LasTres::Enemy->from_hash($_) } @$hash_members ];
my $self = $class->new(
members => $members,
current_battle => $current_battle,
uuid => $uuid
);
for my $member ( $self->members->@* ) {
$member->team($self);
}
return $self;
}
with 'LasTres::RedisTeam';
1;

View File

@ -10,6 +10,8 @@ use feature 'signatures';
use Moo;
use JSON qw/to_json from_json/;
use LasTres::Battle;
has _app => ( is => 'lazy' );
has _schema => ( is => 'lazy' );
@ -50,12 +52,67 @@ sub loop ($self) {
sub _work_frame ($self) {
$self->_increment_frame_for_movers();
$self->_increment_frame_for_combats;
}
sub _increment_frame_for_combats ($self) {
my $schema = $self->_schema;
my $result_set_teams = $schema->resultset('Team');
my @teams = $result_set_teams->search(
{
current_battle => { '!=' => undef },
},
);
for my $battle_uuid ( map { $_->current_battle } @teams ) {
$self->_increment_frame_for_combat($battle_uuid);
}
}
sub _expire_battle($self, $battle_uuid) {
my $schema = $self->_schema;
my $result_set_teams = $schema->resultset('Team');
my @teams_in_expired_battle = $result_set_teams->search(
{
current_battle => $battle_uuid
}
);
for my $team (@teams_in_expired_battle) {
$team->current_battle(undef);
$team->update;
}
}
sub _increment_frame_for_combat($self, $battle_uuid) {
my $battle = LasTres::Battle->get_redis($battle_uuid);
if (!defined $battle) {
$self->_expire_battle($battle_uuid);
return;
}
if (!$battle->sanity_check) {
$battle->end;
}
my @combat_members = (@{$battle->team1->combat_members}, @{$battle->team2->combat_members});
@combat_members = sort { $b->speed <=> $a->speed } @combat_members;
for my $entity (@combat_members) {
$battle->try_turn($entity);
if (my $winner = $battle->winner) {
next;
}
$battle->save_redis;
}
if (my $winner = $battle->winner) {
my $loser = $battle->loser;
$winner->on_win_combat;
$loser->on_lose_combat;
$battle->end;
}
$battle->save_redis;
}
sub _increment_frame_for_movers ($self) {
my $schema = $self->_schema;
my $result_set_teams = $schema->resultset('Team');
my @teams = $result_set_teams->search( { -bool => 'is_moving' } );
my @teams = $result_set_teams->search(
{ -bool => 'is_moving', current_battle => undef } );
for my $team (@teams) {
$self->_increment_frame_for_mover($team);
}
@ -78,6 +135,7 @@ sub _increment_frame_for_mover ( $self, $team ) {
return;
}
$team->send_frame_to_members;
$team->location->parent->on_move_explore_frame($team);
}
sub _real_loop ($self) {

View File

@ -42,6 +42,11 @@ sub order ($self) {
return 1000;
}
## OVERRIDE
sub is_spawn($self) {
return 0;
}
## OVERRIDE (Always use $self->SUPER::on_team_arrival.)
sub on_team_arrival ( $self, $team ) {
$team = $team->get_from_storage;
@ -124,6 +129,9 @@ sub on_pj_moving ( $self, $pj ) {
sub place_team ( $self, $team ) {
$team = $team->get_from_storage;
if ($self->is_spawn) {
$team->last_spawn( $self->to_json_array );
}
$team->location($self);
$team->update;
$self->on_team_arrival($team);

View File

@ -7,11 +7,14 @@ use warnings;
use feature 'signatures';
use Module::Pluggable search_path => ['LasTres::Planet::Bahdder::BosqueDelHeroe::TribuDeLaLima'],
instantiate => 'instance',
on_require_error => sub ($plugin, $error) {
die $error;
};
use LasTres::EnemyArea;
use Module::Pluggable
search_path => ['LasTres::Planet::Bahdder::BosqueDelHeroe::TribuDeLaLima'],
instantiate => 'instance',
on_require_error => sub ( $plugin, $error ) {
die $error;
};
use Moo;
use LasTres::Planet::Bahdder::BosqueDelHeroe;
@ -22,7 +25,7 @@ sub can_explore {
return 0;
}
sub get_auto_discover($self) {
sub get_auto_discover ($self) {
return 1;
}
@ -30,16 +33,30 @@ sub frames_to_move {
return 3;
}
sub has_movement_auto_combat ($self) {
return 1;
}
sub list_of_enemies ($self) {
return [
LasTres::EnemyArea->new(
race => 'conejo',
nick => 'Conejo rabioso',
level => 3,
),
];
}
sub identifier {
return 'tribu_de_la_lima';
}
sub locations {
my $self = shift;
my $hash = {};
my $self = shift;
my $hash = {};
my @locations = $self->plugins();
for my $location (@locations) {
$hash->{$location->identifier} = $location;
$hash->{ $location->identifier } = $location;
}
return $hash;
}
@ -53,9 +70,10 @@ sub parent {
}
my $singleton;
sub instance {
my $class = shift;
if (!defined $singleton) {
if ( !defined $singleton ) {
$singleton = $class->new(@_);
}
return $singleton;

View File

@ -45,6 +45,10 @@ has npcs => (
with 'LasTres::Location';
sub is_spawn {
return 1;
}
sub _build_identifier {
return 'entrada';
}

View File

@ -0,0 +1,50 @@
package LasTres::Race::Conejo;
use v5.36.0;
use strict;
use warnings;
use Moo;
with 'LasTres::Race';
sub spawn {
return;
}
sub identifier {
return 'conejo';
}
sub name {
return 'Conejo rabioso';
}
sub name_selection {
return;
}
sub image {
return '/img/bad-rabbit.png';
}
sub description {
return 'Un conejo que se ha vuelto violento por la enfermedad de la rabia.';
}
sub is_playable {
return 0;
}
sub base_stats {
return LasTres::Stats->new(
health => 40,
strength => 90,
resistance => 83,
mana => 0,
magic => 0,
speed => 100,
intelligence => 10,
);
}
1;

View File

@ -32,23 +32,31 @@ has hash_all_playable => (
);
sub _build_hash_all($self) {
return { map { $_ => $self->hash->{$_}->hash } (keys %{$self->hash}) };
my $hash = {};
my @races = $self->plugins();
for my $race (@races) {
$hash->{$race->identifier} = $race;
}
return { map { $_ => $self->hash->{$_}->hash } (keys %{$hash}) };
}
sub _build_hash_all_playable($self) {
my %hash = %{$self->hash};
for my $race_key (keys %hash) {
my $race = $hash{$race_key};
if (!$race->is_playable) {
delete $hash{$race_key};
}
$hash{$race_key} = $race->hash;
my $hash = {};
my @races = $self->plugins();
for my $race (@races) {
$hash->{$race->identifier} = $race;
}
return \%hash;
for my $race_key (keys %$hash) {
my $race = $hash->{$race_key};
if (!$race->is_playable) {
delete $hash->{$race_key};
}
$hash->{$race_key} = $race->hash;
}
return $hash;
}
sub _build_hash {
my $self = shift;
sub _build_hash($self) {
my $hash = {};
my @races = $self->plugins();
for my $race (@races) {
@ -57,9 +65,12 @@ sub _build_hash {
return $hash;
}
sub _build_hash_playable {
my $self = shift;
my $hash = {%{$self->hash}};
sub _build_hash_playable($self) {
my $hash = {};
my @races = $self->plugins();
for my $race (@races) {
$hash->{$race->identifier} = $race;
}
for my $identifier_race (keys %$hash) {
my $race = $hash->{$identifier_race};
if (!$race->is_playable) {

View File

@ -40,6 +40,11 @@ sub publish($self, $topic, $message) {
sub pj_subscription($class, $pj) {
return prefix() . '::Subscriptions::PJ::' . $pj->uuid;
}
sub battle_key($class, $battle_uuid) {
return prefix() . '::Key::Battle' . $battle_uuid;
}
sub executing_frame_key($class) {
return prefix() . '::Key::Frame';
}

13
lib/LasTres/RedisEnemy.pm Normal file
View File

@ -0,0 +1,13 @@
package LasTres::RedisEnemy;
use v5.36.0;
use strict;
use warnings;
use feature 'signatures';
use Moo::Role;
requires ('to_hash', 'level', 'from_hash', 'team');
with 'LasTres::CombatCapableEntity';
1;

11
lib/LasTres/RedisTeam.pm Normal file
View File

@ -0,0 +1,11 @@
package LasTres::RedisTeam;
use v5.36.0;
use strict;
use warnings;
use Moo::Role;
with 'LasTres::CombatCapableTeam';
1;

View File

@ -5,7 +5,7 @@ use v5.36.0;
use strict;
use warnings;
our $VERSION = 9;
our $VERSION = 12;
use feature 'signatures';

View File

@ -22,7 +22,6 @@ __PACKAGE__->table('player_pjs');
__PACKAGE__->add_columns(
uuid => {
data_type => 'uuid',
default_value => \'uuid_generate_v4()',
is_nullable => 0,
},
owner => {
@ -45,7 +44,7 @@ __PACKAGE__->add_columns(
race => {
data_type => 'text',
is_nullable => 0,
accessor => "_race",
accessor => "race_string",
},
team => {
data_type => 'uuid',
@ -104,7 +103,15 @@ __PACKAGE__->add_columns(
data_type => 'integer',
accessor => '_mana',
is_nullable => 0,
}
},
combat_target => {
data_type => 'uuid',
is_nullable => 1,
},
combat_action => {
data_type => 'text',
is_nullable => 1,
},
);
__PACKAGE__->set_primary_key('uuid');
@ -126,10 +133,10 @@ __PACKAGE__->belongs_to( 'owner', 'LasTres::Schema::Result::Player' );
sub knows_location ( $self, $location ) {
require LasTres::Schema;
my $schema = LasTres::Schema->Schema;
my $array = $location->to_array;
my ( $planet, $super_area, $area ) = @$array[ 0 .. 2 ];
$location = $array->[3];
my $schema = LasTres::Schema->Schema;
my @places = $schema->resultset('PJKnownPlaces')->search(
{
owner => $self->uuid,
@ -212,14 +219,7 @@ for my $column_name ( keys %$columns ) {
accessor => "_moo_$column_name",
);
}
sub race ($self) {
my $hash = LasTres::Races->new->hash_playable;
my $race = $hash->{ $self->_race };
if ( !defined $race ) {
die "Not valid race for pj " . $self->uuid;
}
return $race;
}
sub last_50_log ($self) {
return $self->logs->search( {},
@ -295,5 +295,56 @@ sub get_flag ( $self, $name ) {
sub clear_flag ( $self, $name ) {
$self->flags->search( name => $name )->delete;
}
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;
}
with 'LasTres::CombatCapableEntity';
1;

View File

@ -46,9 +46,4 @@ __PACKAGE__->add_columns(
},
);
__PACKAGE__->set_primary_key('uuid');
sub model($self) {
require LasTres::Stats;
return LasTres::Stats->new($self->get_columns);
}
1;

View File

@ -10,6 +10,10 @@ use parent 'DBIx::Class::Core';
use LasTres::Location;
use JSON qw/to_json from_json/;
use Carp qw/cluck/;
use Moo;
__PACKAGE__->table('teams');
__PACKAGE__->add_columns(
@ -32,6 +36,11 @@ __PACKAGE__->add_columns(
is_nullable => 0,
default_value => \'false',
},
last_spawn => {
data_type => 'jsonb',
is_nullable => 0,
default_value => \'\'null\'',
},
moving_to => {
data_type => 'jsonb',
is_nullable => 0,
@ -66,8 +75,58 @@ __PACKAGE__->add_columns(
is_nullable => 0,
accessor => '_location',
},
current_battle => {
data_type => 'uuid',
is_nullable => 1,
},
);
sub is_defeated($self) {
my @members = $self->members;
my @alive_members = grep { $_->health > 0 } @members;
if (!scalar @alive_members) {
return 1;
}
return 0;
}
sub on_win_combat($self) {
}
sub on_lose_combat($self) {
my $last_spawn = $self->get_spawn;
$last_spawn->place_team($self);
$self->is_moving(0);
$self->moving_to('null');
for my $member ($self->combat_members->@*) {
$member->health($member->max_health);
$member->mana($member->max_mana);
$member->update;
}
$self->update;
}
sub update($self) {
return $self->SUPER::update();
}
sub get_spawn($self) {
my $location;
eval {
$location = LasTres::Location::get(@{from_json($self->last_spawn)});
};
if ($@) {
$location = $self->leader->race->spawn;
}
return $location;
}
sub start_random_combat($self) {
$self = $self->get_from_storage;
my $location = $self->location;
my $area = $location->to_array->[2];
}
# May throw error, it is needed to handle.
sub location {
my $self = shift;
@ -102,8 +161,39 @@ sub send_frame_to_members ($self) {
to_json( { command => 'show-frame' } ) );
}
}
sub combat_members($self) {
$self = $self->get_from_storage;
my @members = $self->members;
# Add friendly NPCs here when implemented.
return [@members];
}
sub to_serializable ($self) {
return {
is_db => $JSON::true,
uuid => $self->uuid,
}
}
sub from_serializable($class, $hash) {
require LasTres::Schema;
my $schema = LasTres::Schema->Schema;
my $resultset = $schema->resultset('Team');
if (!$hash->{is_db}) {
die 'This is not a database Team.';
}
my @teams = $resultset->search({uuid => $hash->{uuid}});
if (!@teams) {
die 'This team does not exists.';
}
return $teams[0];
}
__PACKAGE__->set_primary_key('uuid');
__PACKAGE__->add_unique_constraint( u_name => ['name'] );
__PACKAGE__->has_many( 'members', 'LasTres::Schema::Result::PJ', 'team' );
__PACKAGE__->belongs_to( 'leader', 'LasTres::Schema::Result::PJ' );
with 'LasTres::CombatCapableTeam';
1;

View File

@ -9,15 +9,6 @@ use feature 'signatures';
use Moo;
use LasTres::DAO::Stats;
my $result_set = LasTres::DAO::Stats->new->ResultSet;
has uuid => (
is => 'rw',
required => 0,
);
has health => (
is => 'rw',
required => 1,
@ -53,10 +44,8 @@ has intelligence => (
required => 1,
);
sub hash ($self) {
my $uuid = $self->uuid;
sub to_hash ($self) {
return {
( ( defined $uuid ) ? ( uuid => $uuid ) : () ),
health => $self->health,
mana => $self->mana,
strength => $self->strength,
@ -67,22 +56,7 @@ sub hash ($self) {
};
}
sub update($self) {
return $self->result_set->update;
}
sub insert($self) {
return $self->result_set->insert;
}
sub update_or_insert($self) {
return $self->result_set->update_or_insert;
}
sub result_set ($self) {
if (!defined $self->uuid) {
die "This Stat has no correlation with db, unable to continue.";
}
$result_set->new( $self->hash );
sub from_hash($class, $hash) {
return $class->new(%$hash);
}
1;

16
lib/LasTres/Util.pm Normal file
View File

@ -0,0 +1,16 @@
package LasTres::Util;
use v5.36.0;
use strict;
use warnings;
sub rand_range_int($min, $max_inclusive) {
return int(rand_range($min, $max_inclusive));
}
sub rand_range($min, $max_inclusive) {
my $chances = $max_inclusive - $min + 1;
return rand($chances) + $min;
}
1;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB