Added initial game logic service
This commit is contained in:
20
game-logic-service/src/components/basic_info.rs
Normal file
20
game-logic-service/src/components/basic_info.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BasicInfo {
|
||||
pub name: String,
|
||||
pub id: u16,
|
||||
pub tag: u32,
|
||||
pub team_id: u32,
|
||||
pub job: u16,
|
||||
pub stat_points: u32,
|
||||
pub skill_points: u32,
|
||||
pub pk_flag: u16,
|
||||
pub stone: u8,
|
||||
pub char_id: u32,
|
||||
}
|
||||
|
||||
impl Default for BasicInfo {
|
||||
fn default() -> Self {
|
||||
Self { name: "TEST".to_string(), id: 0, tag: 0, team_id: 0, job: 0, stat_points: 0, skill_points: 0, pk_flag: 0, stone: 0, char_id: 0 }
|
||||
}
|
||||
}
|
||||
31
game-logic-service/src/components/character_graphics.rs
Normal file
31
game-logic-service/src/components/character_graphics.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
#[derive(Debug)]
|
||||
struct CharacterGraphics {
|
||||
race: u8,
|
||||
hair: u8,
|
||||
face: u8,
|
||||
}
|
||||
|
||||
impl Default for CharacterGraphics {
|
||||
fn default() -> Self {
|
||||
Self { race: 0, hair: 0, face: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl CharacterGraphics {
|
||||
pub fn new(race: u8, hair: u8, face: u8) -> Self {
|
||||
Self { race, hair, face }
|
||||
}
|
||||
|
||||
pub fn get_race(&self) -> u8 {
|
||||
self.race
|
||||
}
|
||||
|
||||
pub fn get_hair(&self) -> u8 {
|
||||
self.hair
|
||||
}
|
||||
|
||||
pub fn get_face(&self) -> u8 {
|
||||
self.face
|
||||
}
|
||||
}
|
||||
22
game-logic-service/src/components/client.rs
Normal file
22
game-logic-service/src/components/client.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Client {
|
||||
client_id: u16,
|
||||
access_level: u16,
|
||||
}
|
||||
|
||||
impl Default for Client {
|
||||
fn default() -> Self {
|
||||
Self { client_id: 0, access_level: 1 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub fn get_client_id(&self) -> u16 {
|
||||
self.client_id
|
||||
}
|
||||
|
||||
pub fn get_access_level(&self) -> u16 {
|
||||
self.access_level
|
||||
}
|
||||
}
|
||||
13
game-logic-service/src/components/destination.rs
Normal file
13
game-logic-service/src/components/destination.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
#[derive(Debug)]
|
||||
struct Destination {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub z: f32,
|
||||
dest: u16,
|
||||
}
|
||||
|
||||
impl Default for Destination {
|
||||
fn default() -> Self {
|
||||
Self { x: 520000.0, y: 520000.0, z: 1.0, dest: 20 }
|
||||
}
|
||||
}
|
||||
30
game-logic-service/src/components/item.rs
Normal file
30
game-logic-service/src/components/item.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
#[derive(Debug)]
|
||||
pub struct Item {
|
||||
pub is_created: bool,
|
||||
pub is_zuly: bool,
|
||||
pub life: f32,
|
||||
pub durability: u8,
|
||||
pub has_socket: bool,
|
||||
pub is_appraised: bool,
|
||||
pub grade: u8,
|
||||
pub count: u32,
|
||||
pub gem_option: u16,
|
||||
pub price: u32,
|
||||
}
|
||||
|
||||
impl Default for Item {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
is_created: false,
|
||||
is_zuly: false,
|
||||
life: 0.0,
|
||||
durability: 0,
|
||||
has_socket: false,
|
||||
is_appraised: false,
|
||||
grade: 0,
|
||||
count: 0,
|
||||
gem_option: 0,
|
||||
price: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
34
game-logic-service/src/components/level.rs
Normal file
34
game-logic-service/src/components/level.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Level {
|
||||
pub level: u16,
|
||||
pub xp: u64,
|
||||
pub penalty_xp: u64,
|
||||
}
|
||||
|
||||
impl Default for Level {
|
||||
fn default() -> Self {
|
||||
Self { level: 1, xp: 0, penalty_xp: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Level {
|
||||
pub fn get_level(&self) -> u16 {
|
||||
self.level
|
||||
}
|
||||
|
||||
pub fn get_xp(&self) -> u64 {
|
||||
self.xp
|
||||
}
|
||||
|
||||
pub fn get_penalty_xp(&self) -> u64 {
|
||||
self.penalty_xp
|
||||
}
|
||||
|
||||
pub fn add_xp(&mut self, amount: u64) {
|
||||
self.xp += amount;
|
||||
}
|
||||
|
||||
pub fn add_penalty_xp(&mut self, amount: u64) {
|
||||
self.penalty_xp += amount;
|
||||
}
|
||||
}
|
||||
40
game-logic-service/src/components/life.rs
Normal file
40
game-logic-service/src/components/life.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Life {
|
||||
hp: u32,
|
||||
max_hp: u32,
|
||||
}
|
||||
|
||||
impl Default for Life {
|
||||
fn default() -> Self {
|
||||
Self { hp: 100, max_hp: 100 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Life {
|
||||
pub fn new(hp: u32, max_hp: u32) -> Self {
|
||||
Self { hp, max_hp }
|
||||
}
|
||||
|
||||
pub fn get_hp(&self) -> u32 {
|
||||
self.hp
|
||||
}
|
||||
|
||||
pub fn get_max_hp(&self) -> u32 {
|
||||
self.max_hp
|
||||
}
|
||||
|
||||
pub fn take_damage(&mut self, damage: u32) {
|
||||
self.hp = self.hp.saturating_sub(damage);
|
||||
if self.hp <= 0 {
|
||||
self.hp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn heal(&mut self, amount: u32) {
|
||||
self.hp = self.hp.saturating_add(amount);
|
||||
if self.hp > self.max_hp {
|
||||
self.hp = self.max_hp;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
game-logic-service/src/components/magic.rs
Normal file
36
game-logic-service/src/components/magic.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Magic {
|
||||
mp: u32,
|
||||
max_mp: u32,
|
||||
}
|
||||
|
||||
impl Default for Magic {
|
||||
fn default() -> Self {
|
||||
Self { mp: 55, max_mp: 55 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Magic {
|
||||
pub fn get_mp(&self) -> u32 {
|
||||
self.mp
|
||||
}
|
||||
|
||||
pub fn get_max_mp(&self) -> u32 {
|
||||
self.max_mp
|
||||
}
|
||||
|
||||
pub fn use_mp(&mut self, amount: u32) {
|
||||
self.mp = self.mp.saturating_sub(amount);
|
||||
if self.mp <= 0 {
|
||||
self.mp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn restore_mp(&mut self, amount: u32) {
|
||||
self.mp = self.mp.saturating_add(amount);
|
||||
if self.mp > self.max_mp {
|
||||
self.mp = self.max_mp;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
game-logic-service/src/components/markers.rs
Normal file
28
game-logic-service/src/components/markers.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use hecs::Entity;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Mob {
|
||||
pub id: u32,
|
||||
pub quest_id: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Npc {
|
||||
pub id: u32,
|
||||
pub quest_id: u32,
|
||||
pub angle: f32,
|
||||
pub event_status: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Pet {
|
||||
pub owner: Entity,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PlayerSpawn {
|
||||
pub point_type: u32
|
||||
}
|
||||
13
game-logic-service/src/components/mod.rs
Normal file
13
game-logic-service/src/components/mod.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
pub mod markers;
|
||||
pub mod position;
|
||||
pub mod basic_info;
|
||||
pub mod destination;
|
||||
pub mod target;
|
||||
pub mod level;
|
||||
pub mod life;
|
||||
pub mod magic;
|
||||
pub mod client;
|
||||
pub mod item;
|
||||
pub mod stats;
|
||||
pub mod character_graphics;
|
||||
pub mod spawner;
|
||||
20
game-logic-service/src/components/position.rs
Normal file
20
game-logic-service/src/components/position.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Position {
|
||||
#[serde(rename = "X")]
|
||||
pub x: f32,
|
||||
#[serde(rename = "Y")]
|
||||
pub y: f32,
|
||||
#[serde(rename = "Z")]
|
||||
pub z: f32,
|
||||
pub map_id: u16,
|
||||
pub spawn_id: u16,
|
||||
}
|
||||
|
||||
impl Default for Position {
|
||||
fn default() -> Self {
|
||||
// Set the default position to (520000.0, 520000.0)
|
||||
Self { x: 520000.0, y: 520000.0, z: 1.0, map_id: 20, spawn_id: 1 }
|
||||
}
|
||||
}
|
||||
60
game-logic-service/src/components/spawner.rs
Normal file
60
game-logic-service/src/components/spawner.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use std::time::{Duration, Instant};
|
||||
use hecs::Entity;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Spawner {
|
||||
/// The ID of the mob to be spawned.
|
||||
pub mob_id: u32,
|
||||
/// The maximum number of mobs that can be spawned.
|
||||
pub max_mob_count: u32,
|
||||
/// The maximum number of mobs that can be spawned at once.
|
||||
pub max_spawn_count_at_once: u32,
|
||||
/// The range within which the spawner should generate a mob.
|
||||
pub spawn_range: u32,
|
||||
/// The frequency in seconds at which the spawner should generate a mob.
|
||||
pub spawn_rate: Duration,
|
||||
/// The last time a mob was spawned.
|
||||
pub last_spawn: Instant,
|
||||
/// The list of mobs that have been spawned by this spawner.
|
||||
pub mobs: Vec<Entity>,
|
||||
}
|
||||
|
||||
impl Default for Spawner {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
mob_id: 0,
|
||||
max_mob_count: 1,
|
||||
max_spawn_count_at_once: 1,
|
||||
spawn_rate: Duration::from_secs(10),
|
||||
last_spawn: Instant::now(),
|
||||
spawn_range: 100,
|
||||
mobs: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Spawner {
|
||||
pub fn get_mob_id(&self) -> u32 {
|
||||
self.mob_id
|
||||
}
|
||||
|
||||
pub fn get_max_mob_count(&self) -> u32 {
|
||||
self.max_mob_count
|
||||
}
|
||||
|
||||
pub fn get_max_spawn_count_at_once(&self) -> u32 {
|
||||
self.max_spawn_count_at_once
|
||||
}
|
||||
|
||||
pub fn get_spawn_rate(&self) -> Duration {
|
||||
self.spawn_rate
|
||||
}
|
||||
|
||||
pub fn get_last_spawn(&self) -> Instant {
|
||||
self.last_spawn
|
||||
}
|
||||
|
||||
pub fn get_spawn_range(&self) -> u32 {
|
||||
self.spawn_range
|
||||
}
|
||||
}
|
||||
51
game-logic-service/src/components/stats.rs
Normal file
51
game-logic-service/src/components/stats.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
#[derive(Debug)]
|
||||
pub struct Stats {
|
||||
strength: u16,
|
||||
dexterity: u16,
|
||||
intelligence: u16,
|
||||
constitution: u16,
|
||||
charisma: u16,
|
||||
sense: u16,
|
||||
head_size: u8,
|
||||
body_size: u8,
|
||||
}
|
||||
|
||||
impl Default for Stats {
|
||||
fn default() -> Self {
|
||||
Self { strength: 10, dexterity: 10, intelligence: 10, constitution: 10, charisma: 10, sense: 10, head_size: 1, body_size: 1 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Stats {
|
||||
pub fn get_strength(&self) -> u16 {
|
||||
self.strength
|
||||
}
|
||||
|
||||
pub fn get_dexterity(&self) -> u16 {
|
||||
self.dexterity
|
||||
}
|
||||
|
||||
pub fn get_intelligence(&self) -> u16 {
|
||||
self.intelligence
|
||||
}
|
||||
|
||||
pub fn get_constitution(&self) -> u16 {
|
||||
self.constitution
|
||||
}
|
||||
|
||||
pub fn get_charisma(&self) -> u16 {
|
||||
self.charisma
|
||||
}
|
||||
|
||||
pub fn get_sense(&self) -> u16 {
|
||||
self.sense
|
||||
}
|
||||
|
||||
pub fn get_head_size(&self) -> u8 {
|
||||
self.head_size
|
||||
}
|
||||
|
||||
pub fn get_body_size(&self) -> u8 {
|
||||
self.body_size
|
||||
}
|
||||
}
|
||||
20
game-logic-service/src/components/target.rs
Normal file
20
game-logic-service/src/components/target.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use hecs::{Entity};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Target {
|
||||
target: Entity,
|
||||
}
|
||||
|
||||
impl Target {
|
||||
pub fn new(target: Entity) -> Self {
|
||||
Self { target }
|
||||
}
|
||||
|
||||
pub fn get_target(&self) -> Entity {
|
||||
self.target
|
||||
}
|
||||
|
||||
pub fn set_target(&mut self, target: Entity) {
|
||||
self.target = target;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user