Compiles. All weapons, and attachments setup correctly

This commit is contained in:
Franklin 2023-11-19 18:05:13 -04:00
parent 1b83befaad
commit d262378352
61 changed files with 493 additions and 154 deletions

View File

@ -24,5 +24,16 @@ Limit mods to attachments, for now, I don't want to change barrel lengths or for
Only do silencers/compensators, sights, Foregrips.
### Blender:
Use a single file for attachments and a single file for weapons, then export them one by one as a new gltf asset
- Mark every weapon parent with a FirearmEnum custom property
- Mark Firing point
- Mark Firing point without attachments (FiringPoint)
- Mark Sight placement start and end
- Mark Attachment slots (CompensatorSlot, ForeGripSlot, MagazineSlot, StockSlot, SightPlacementStart, SightPlacementEnd, UtilitySlot)
- Attempt to center all the slots
- Mark Gun part slots (ChargingHandle, Trigger)
- Set all attachments origin to where they will be placed on the gun
- Mark them with the specific WeaponAttachment variant
- Set all attachments transform to 0 and the same scale as the gun

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,6 @@
use bevy::{prelude::*, gltf::Gltf};
use crate::{comps::core::{items::item::Item, events::inventory_changed::PlayerInventoryChangedEvent, markers::firearm::FirearmType}, setup::assets::GltfAssets};
use crate::{comps::core::{items::item::Item, events::inventory_changed::PlayerInventoryChangedEvent, weapons::firearm_data::FirearmType}, setup::assets::GltfAssets};
use super::{item_inventory::ItemInventory, slot::PlayerInventorySlotType};

View File

@ -0,0 +1,48 @@
use bevy::prelude::*;
use crate::comps::core::{
grid::UGrid,
items::item::{Item, ItemType},
markers::holdable::HoldableObjectType, inventory::slot::PlayerInventorySlotType, weapons::firearm::Firearm,
};
#[derive(Component, Reflect)]
pub struct Ak105GunItem;
impl Item for Ak105GunItem {
fn get_type(&self) -> ItemType {
ItemType::Holdable(HoldableObjectType::Firearm(Firearm::Glock17))
}
fn asset_path(&self) -> &str {
"weapons/ak105_rifle.glb"
}
#[doc = " Optional Stackable. If value is Some(x) x is the max quantity per stack"]
fn stackable(&self) -> Option<u32> {
None
}
fn inventory_size(&self) -> UGrid {
UGrid {
width: 4,
height: 2,
}
}
fn inventory_rotatable(&self) -> bool {
true
}
fn inventory_title(&self) -> String {
String::from("AK105")
}
fn inventory_description(&self) -> String {
String::from("Rifle chambered in 5.45x39mm.")
}
fn get_item_slot(&self) -> PlayerInventorySlotType {
PlayerInventorySlotType::Primary
}
}

View File

@ -1,12 +1,9 @@
use bevy::prelude::*;
use crate::{
comps::core::{
use crate::comps::core::{
grid::UGrid,
items::item::{Item, ItemType},
markers::holdable::HoldableObjectType, inventory::slot::PlayerInventorySlotType,
},
logic::core::guns::firearm::Firearm,
markers::holdable::HoldableObjectType, inventory::slot::PlayerInventorySlotType, weapons::firearm::Firearm,
};
#[derive(Component, Reflect)]

View File

@ -1,12 +1,9 @@
use bevy::prelude::*;
/*use bevy::prelude::*;
use crate::{
comps::core::{
use crate::comps::core::{
grid::UGrid,
items::item::{Item, ItemType},
markers::holdable::HoldableObjectType, inventory::slot::PlayerInventorySlotType,
},
logic::core::guns::firearm::Firearm,
markers::holdable::HoldableObjectType, inventory::slot::PlayerInventorySlotType, weapons::firearm::Firearm,
};
#[derive(Component, Reflect)]
@ -48,3 +45,4 @@ impl Item for M4a1GunItem {
PlayerInventorySlotType::Primary
}
}
*/

View File

@ -1,2 +1,3 @@
pub mod glock17;
pub mod m4a1;
pub mod ak105;

View File

@ -1,9 +1,8 @@
use crate::{
comps::core::{
grid::UGrid,
markers::{firearm::FirearmData, holdable::HoldableObjectType, interactable::Interactable}, inventory::slot::PlayerInventorySlotType,
markers::{holdable::HoldableObjectType, interactable::Interactable}, inventory::slot::PlayerInventorySlotType, weapons::{firearm_data::FirearmData, firearm::Firearm},
},
logic::core::guns::firearm::Firearm,
setup::assets::{GltfAssetType, GltfAssets},
utils,
};

View File

@ -4,7 +4,7 @@ use bevy::{
time::Timer,
};
use crate::logic::core::guns::caliber::Caliber;
use crate::comps::core::weapons::caliber::Caliber;
#[derive(Component, Reflect)]
pub struct BulletMarker {

View File

@ -1,60 +0,0 @@
use bevy::{
prelude::{Component, Quat, Vec3},
reflect::Reflect,
};
use crate::logic::core::guns::{caliber::Caliber, spray_pattern::FirearmSprayPattern};
#[derive(Default, Debug, Clone, Reflect)]
pub struct FiringPoint {
pub forward: f32,
pub up: f32,
pub right: f32,
}
#[derive(Reflect, Clone)]
pub enum FirearmType {
Primary,
Secondary,
}
#[derive(Component, Clone, Reflect)]
pub struct FirearmData {
/// Where the bullets will come out of, and muzzle flash will be spawned out of.
/// Also, this transform's .forward() should be pointing the same Vec3 as the barrel is
/// Global transform
pub firing_point: FiringPoint,
pub caliber: Caliber,
/// Placeholder until mags get implemented
pub max_capacity: usize,
/// Rounds per minute
pub fire_rate: f32,
/// Amount of seconds it takes for gun to come down from shooting
/// Also is the time it takes for the gun to aim in or aim out.
pub rebound_time_seconds: f32,
pub asset_path: String,
pub vertical_recoil_modifier: f32,
pub horizontal_recoil_modifier: f32,
pub recoil_pattern: FirearmSprayPattern,
/// Final rotation of hands when aimed in
pub final_aimed_rotation: Quat,
/// Final rotation of hands when not aimed in
pub final_rotation: Quat,
/// Final position of hands when aimed in
pub final_aimed_position: Vec3,
/// Final position of hands when not aimed in
pub final_position: Vec3,
pub scale_factor: f32,
pub firearm_type: FirearmType,
}
#[derive(Component, Reflect)]
pub struct MagazineData {
pub rounds_shot: usize,
pub max_capacity: usize,
}

View File

@ -1,6 +1,6 @@
use bevy::prelude::*;
use crate::logic::core::guns::firearm::Firearm;
use crate::comps::core::weapons::firearm::Firearm;
/// Anything that can go in the player's hands.
#[derive(Component, Default, Debug, Reflect)]

View File

@ -1,6 +1,5 @@
pub mod bullet;
pub mod camera;
pub mod firearm;
pub mod holdable;
pub mod interactable;
pub mod inventory_screen;

View File

@ -1,4 +1,5 @@
pub mod character;
pub mod plugin;
pub mod physics;
pub mod bevy;
pub mod bevy;
pub mod weapons;

View File

@ -1,6 +1,6 @@
use bevy::app::{Plugin, Update};
use crate::setup::load_state::update_game_load_state;
use crate::{setup::load_state::update_game_load_state, comps::core::weapons::{firearm::Firearm, attachments::{weapon_attachment::WeaponAttachment, optic::Optic, stock::Stock, compensator::Compensator, magazine::Magazine, foregrip::ForeGrip}, parts::{charging_handle::ChargingHandle, fire_selector::FireSelector, firing_point::FiringPoint, trigger::Trigger}, slot::{compensator_slot::CompensatorSlot, fore_grip_slot::ForeGripSlot, magazine_slot::MagazineSlot, sight_placement_start_slot::SightPlacementStartSlot, sight_placement_end_slot::SightPlacementEndSlot, stock_slot::StockSlot, utility_slot::UtilitySlot}}};
use super::{character::{player_hitbox::PlayerHitBox, player_character::PlayerCharacter, player_eye::{PlayerEye, insert_components_into_spawned_player}, in_player_hands_parent::{InPlayerHandsParent, insert_components_into_player_hand}, third_person_camera::ThirdPersonCameraProxy}, physics::{rapier::{AutoAABBCollider, physics_replace_proxies}, self}};
@ -20,6 +20,32 @@ impl Plugin for ProxyComponentsPlugin {
app.register_type::<InPlayerHandsParent>();
app.register_type::<ThirdPersonCameraProxy>();
// Firearms
app.register_type::<Firearm>();
// Attachments
app.register_type::<WeaponAttachment>();
app.register_type::<Optic>();
app.register_type::<Stock>();
app.register_type::<Compensator>();
app.register_type::<Magazine>();
app.register_type::<ForeGrip>();
// Parts
app.register_type::<ChargingHandle>();
app.register_type::<FireSelector>();
app.register_type::<FiringPoint>();
app.register_type::<Trigger>();
// Slots
app.register_type::<CompensatorSlot>();
app.register_type::<ForeGripSlot>();
app.register_type::<MagazineSlot>();
app.register_type::<SightPlacementStartSlot>();
app.register_type::<SightPlacementEndSlot>();
app.register_type::<StockSlot>();
app.register_type::<UtilitySlot>();
// Physics
app.register_type::<AutoAABBCollider>();
app.register_type::<physics::rapier::Collider>();

View File

@ -0,0 +1,8 @@
use bevy::prelude::*;
#[derive(Component, Reflect, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Firearm {
Ak105,
Glock17
}

View File

@ -0,0 +1 @@
pub mod firearm;

View File

@ -5,3 +5,5 @@ pub mod inventory;
pub mod items;
pub mod markers;
pub mod spawners;
#[allow(unused)]
pub mod weapons;

View File

@ -0,0 +1,21 @@
use bevy::prelude::*;
use crate::comps::core::{
items::{guns::ak105::Ak105GunItem, item::Item},
spawners::item::ItemSpawnPoint,
};
#[derive(Component)]
pub struct Ak105SpawnPoint {
pub transform: Transform,
}
impl ItemSpawnPoint for Ak105SpawnPoint {
fn get_transform(&self) -> Transform {
self.transform
}
fn get_item(&self) -> Box<dyn Item> {
Box::new(Ak105GunItem)
}
}

View File

@ -1,4 +1,4 @@
use bevy::prelude::*;
/*use bevy::prelude::*;
use crate::comps::core::{
items::{guns::m4a1::M4a1GunItem, item::Item},
@ -18,4 +18,4 @@ impl ItemSpawnPoint for M4a1SpawnPoint {
fn get_item(&self) -> Box<dyn Item> {
Box::new(M4a1GunItem)
}
}
}*/

View File

@ -1,2 +1,3 @@
pub mod glock17_spawner;
pub mod m4a1_spawner;
pub mod ak105_spawner;

View File

@ -3,7 +3,7 @@ use bevy::{gltf::Gltf, prelude::*};
use crate::{
comps::core::{
items::item::Item,
spawners::guns::{glock17_spawner::Glock17SpawnPoint, m4a1_spawner::M4a1SpawnPoint},
spawners::guns::{glock17_spawner::Glock17SpawnPoint, ak105_spawner::Ak105SpawnPoint},
},
setup::{assets::GltfAssets, load_state::GameLoadState},
};
@ -43,7 +43,8 @@ pub struct ItemSpawnPointPlugin;
impl Plugin for ItemSpawnPointPlugin {
fn build(&self, app: &mut App) {
use bevy_trait_query::RegisterExt;
app.register_component_as::<dyn ItemSpawnPoint, M4a1SpawnPoint>()
app
.register_component_as::<dyn ItemSpawnPoint, Ak105SpawnPoint>()//.register_component_as::<dyn ItemSpawnPoint, M4a1SpawnPoint>()
.register_component_as::<dyn ItemSpawnPoint, Glock17SpawnPoint>();
}
}

View File

@ -0,0 +1,9 @@
use bevy::{reflect::Reflect, ecs::{component::Component, reflect::ReflectComponent}};
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
#[reflect(Component)]
pub enum Compensator {
#[default]
FirstCompensator,
}

View File

@ -0,0 +1,9 @@
use bevy::{reflect::Reflect, ecs::{component::Component, reflect::ReflectComponent}};
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
#[reflect(Component)]
pub enum ForeGrip {
#[default]
Pk5,
}

View File

@ -0,0 +1,9 @@
use bevy::{reflect::Reflect, ecs::{component::Component, reflect::ReflectComponent}};
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
#[reflect(Component)]
pub enum Magazine {
#[default]
Ak105,
}

View File

@ -0,0 +1,6 @@
pub mod weapon_attachment;
pub mod optic;
pub mod magazine;
pub mod compensator;
pub mod stock;
pub mod foregrip;

View File

@ -0,0 +1,9 @@
use bevy::{reflect::Reflect, ecs::{component::Component, reflect::ReflectComponent}};
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
#[reflect(Component)]
pub enum Optic {
#[default]
AimpointT1,
}

View File

@ -0,0 +1,9 @@
use bevy::{reflect::Reflect, ecs::{component::Component, reflect::ReflectComponent}};
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
#[reflect(Component)]
pub enum Stock {
#[default]
MagpullTan,
}

View File

@ -0,0 +1,59 @@
use bevy::prelude::*;
use super::{compensator::Compensator, magazine::Magazine, stock::Stock, foregrip::ForeGrip, optic::Optic};
#[derive(Component, PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Debug)]
#[reflect(Component)]
pub enum WeaponAttachment {
Compensator(Compensator),
Magazine(Magazine),
Stock(Stock),
ForeGrip(ForeGrip),
Optic(Optic)
}
impl Default for WeaponAttachment {
fn default() -> Self {
Self::Optic(Optic::default())
}
}
impl WeaponAttachment {
pub fn vertical_recoil_modifier(&self) -> f32 {
match self {
WeaponAttachment::Compensator(_) => 0.0,
WeaponAttachment::Magazine(_) => 0.0,
WeaponAttachment::Stock(_) => 0.0,
WeaponAttachment::ForeGrip(_) => 0.0,
WeaponAttachment::Optic(_) => 0.0,
}
}
pub fn horizontal_recoil_modifier(&self) -> f32 {
match self {
WeaponAttachment::Compensator(_) => 0.0,
WeaponAttachment::Magazine(_) => 0.0,
WeaponAttachment::Stock(_) => 0.0,
WeaponAttachment::ForeGrip(_) => 0.0,
WeaponAttachment::Optic(_) => 0.0,
}
}
pub fn asset_path<'a>(&self) -> &'a str {
match self {
WeaponAttachment::Compensator(compensator) => match compensator {
Compensator::FirstCompensator => "attachments/first_compensator.glb",
},
WeaponAttachment::Magazine(magazine) => match magazine {
Magazine::Ak105 => "attachments/ak105_magazine.glb",
},
WeaponAttachment::Stock(stock) => match stock {
Stock::MagpullTan => "attachments/tan_magpull_stock.glb",
},
WeaponAttachment::ForeGrip(foregrip) => match foregrip {
ForeGrip::Pk5 => "attachments/pk5_foregrip.glb",
},
WeaponAttachment::Optic(optic) => match optic {
Optic::AimpointT1 => "attachments/aimpoint_t1.glb",
},
}
}
}

View File

@ -3,50 +3,61 @@ use bevy::reflect::Reflect;
#[allow(unused)]
#[derive(Clone, Reflect)]
pub enum Caliber {
/// 5.56x45mm
NATO556,
/// 9x19mm
Parabellum9mm,
/// 5.45x39mm
RU545
}
impl Caliber {
pub fn range(&self) -> f32 {
match self {
Caliber::NATO556 => 7500.0,
Caliber::Parabellum9mm => 2500.0,
Caliber::RU545 => 4500.0,
}
}
pub fn max_airtime_secs(&self) -> f32 {
match self {
Caliber::NATO556 => 3.0,
Caliber::Parabellum9mm => 3.0,
Caliber::RU545 => 3.0,
}
}
pub fn impulse(&self) -> f32 {
match self {
Caliber::NATO556 => 100.0,
Caliber::Parabellum9mm => 50.0,
Caliber::RU545 => 75.0,
}
}
pub fn mass(&self) -> f32 {
match self {
Caliber::NATO556 => 0.1,
Caliber::Parabellum9mm => 0.05,
Caliber::RU545 => 0.07,
}
}
pub fn linear_damping(&self) -> f32 {
match self {
Caliber::NATO556 => 1.0,
Caliber::Parabellum9mm => 2.0,
Caliber::RU545 => 1.5,
}
}
pub fn angular_damping(&self) -> f32 {
match self {
Caliber::NATO556 => 1.0,
Caliber::Parabellum9mm => 1.0,
Caliber::RU545 => 1.0,
}
}
pub fn size(&self) -> f32 {
match self {
Caliber::NATO556 => 0.07,
Caliber::Parabellum9mm => 0.05,
Caliber::RU545 => 0.06
}
}
}

View File

@ -1,29 +1,23 @@
use std::sync::Arc;
use crate::comps::core::{
items::{
guns::{glock17::Glock17GunItem, m4a1::M4a1GunItem},
item::Item,
},
markers::{
firearm::{FirearmData, FirearmType, FiringPoint},
holdable::HoldableObjectData,
},
};
use bevy::prelude::*;
use super::{caliber::Caliber, spray_pattern::FirearmSprayPattern};
use crate::comps::core::{markers::holdable::HoldableObjectData, items::{item::Item, guns::glock17::Glock17GunItem}};
#[derive(Component, PartialEq, Eq, PartialOrd, Ord, Clone, Reflect)]
use super::{firearm_data::{FirearmData, FirearmType}, caliber::Caliber, spray_pattern::FirearmSprayPattern};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub enum Firearm {
M4A1,
Glock17,
Ak105,
#[default]
Glock17
}
impl Firearm {
pub fn firearm_data(&self) -> FirearmData {
match self {
Firearm::M4A1 => {
/*Firearm::M4A1 => {
FirearmData {
firing_point: FiringPoint {
forward: 2.5,
@ -64,20 +58,12 @@ impl Firearm {
asset_path: String::from("weapons/m4a1_rifle.glb"),
firearm_type: FirearmType::Primary,
}
}
}*/
Firearm::Glock17 => {
FirearmData {
firing_point: FiringPoint {
forward: 1.2,
up: 0.445,
right: 0.0,
},
caliber: Caliber::Parabellum9mm,
max_capacity: 17,
fire_rate: 600.0,
rebound_time_seconds: 0.1,
vertical_recoil_modifier: 5.0,
horizontal_recoil_modifier: 1.0,
recoil_pattern: FirearmSprayPattern {
vertical: Vec::from([
1.0, 1.2, 1.3, 1.6, 1.5, 1.7, 1.5, 1.5, 1.5, 2.0, // 10 for now
@ -107,44 +93,78 @@ impl Firearm {
firearm_type: FirearmType::Secondary,
}
}
Firearm::Ak105 => FirearmData {
caliber: Caliber::RU545,
fire_rate: 600.0,
rebound_time_seconds: 0.2,
asset_path: String::from("weapons/ak105_rifle.glb"),
recoil_pattern: FirearmSprayPattern {
vertical: Vec::from([
1.0, 1.2, 1.3, 1.6, 1.5, 1.7, 1.5, 1.5, 1.5, 2.0, // 10 for now
]),
horizontal: Vec::from([
1.0, 1.2, 1.3, -1.6, 1.5, -1.7, -1.5, 1.5, -1.5, 2.0, // 10 for now
]),
},
final_aimed_rotation: Quat::default(),
final_rotation: Quat::default(),
final_aimed_position: Vec3::ZERO,
final_position: Vec3::ZERO,
scale_factor: 0.3,
firearm_type: FirearmType::Primary,
},
}
}
pub fn holdable_object_data(&self) -> HoldableObjectData {
match self {
/*
Firearm::M4A1 => HoldableObjectData {
held_at: Vec3::ZERO,
y_rot: -90.0,
},
},*/
Firearm::Glock17 => HoldableObjectData {
held_at: Vec3::ZERO,
y_rot: 0.0,
},
Firearm::Ak105 => HoldableObjectData {
held_at: Vec3::ZERO,
y_rot: 0.0
},
}
}
pub fn get_size(&self) -> Vec3 {
match self {
Firearm::M4A1 => Vec3 {
/*Firearm::M4A1 => Vec3 {
x: 0.3,
y: 0.7,
z: 2.5,
},
},*/
Firearm::Glock17 => Vec3 {
x: 0.3,
y: 0.4,
z: 1.0,
},
Firearm::Ak105 => Vec3 {
x: 0.3,
y: 0.7,
z: 2.5,
},
}
}
pub fn get_item_arc(&self) -> Arc<dyn Item> {
match self {
Firearm::M4A1 => Arc::new(M4a1GunItem),
//Firearm::M4A1 => Arc::new(M4a1GunItem),
Firearm::Glock17 => Arc::new(Glock17GunItem),
Firearm::Ak105 => todo!(),
}
}
pub fn get_item_box(&self) -> Box<dyn Item> {
match self {
Firearm::M4A1 => Box::new(M4a1GunItem),
//Firearm::M4A1 => Box::new(M4a1GunItem),
Firearm::Glock17 => Box::new(Glock17GunItem),
Firearm::Ak105 => todo!(),
}
}
}
}

View File

@ -0,0 +1,34 @@
use bevy::prelude::*;
use super::{spray_pattern::FirearmSprayPattern, caliber::Caliber};
/// Static data retrieved from a trait impl (Firearm)
#[derive(Clone, Reflect)]
pub struct FirearmData {
pub caliber: Caliber,
/// Rounds per minute
pub fire_rate: f32,
/// Amount of seconds it takes for gun to come down from shooting
/// Also is the time it takes for the gun to aim in or aim out.
pub rebound_time_seconds: f32,
pub asset_path: String,
pub recoil_pattern: FirearmSprayPattern,
/// Final rotation of hands when aimed in
pub final_aimed_rotation: Quat,
/// Final rotation of hands when not aimed in
pub final_rotation: Quat,
/// Final position of hands when aimed in
pub final_aimed_position: Vec3,
/// Final position of hands when not aimed in
pub final_position: Vec3,
pub scale_factor: f32,
pub firearm_type: FirearmType,
}
#[derive(Reflect, Clone)]
pub enum FirearmType {
Primary,
Secondary,
}

View File

@ -0,0 +1,8 @@
use bevy::prelude::*;
#[derive(Component, Reflect, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct MagazineData {
pub rounds_shot: usize,
pub max_capacity: usize,
}

View File

@ -0,0 +1,8 @@
pub mod attachments;
pub mod firearm;
pub mod firearm_data;
pub mod caliber;
pub mod spray_pattern;
pub mod magazine_data;
pub mod slot;
pub mod parts;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub struct ChargingHandle;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub struct FireSelector;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub struct FiringPoint;

View File

@ -0,0 +1,4 @@
pub mod fire_selector;
pub mod charging_handle;
pub mod trigger;
pub mod firing_point;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub struct Trigger;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub struct CompensatorSlot;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub struct ForeGripSlot;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub struct MagazineSlot;

View File

@ -0,0 +1,7 @@
pub mod compensator_slot;
pub mod magazine_slot;
pub mod stock_slot;
pub mod fore_grip_slot;
pub mod utility_slot;
pub mod sight_placement_start_slot;
pub mod sight_placement_end_slot;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub struct SightPlacementEndSlot;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub struct SightPlacementStartSlot;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub struct StockSlot;

View File

@ -0,0 +1,5 @@
use bevy::{ecs::{component::Component, reflect::ReflectComponent}, reflect::Reflect};
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
#[reflect(Component)]
pub struct UtilitySlot;

View File

@ -1,6 +1,3 @@
pub mod caliber;
pub mod despawn_shots;
pub mod firearm;
pub mod player_firing;
pub mod shoot;
pub mod spray_pattern;

View File

@ -3,9 +3,7 @@ use std::time::Duration;
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use crate::comps::core::markers::{bullet::BulletMarker, muzzle_flash::MuzzleFlashMarker};
use super::caliber::Caliber;
use crate::comps::core::{markers::{bullet::BulletMarker, muzzle_flash::MuzzleFlashMarker}, weapons::caliber::Caliber};
pub fn shoot_bullet(
commands: &mut Commands,

View File

@ -7,7 +7,6 @@ use crate::{
inventory::{player_inventory::{PlayerInventory, self}, slot::PlayerInventorySlotType},
markers::{
camera::MainCamera,
firearm::{FirearmData, MagazineData},
holdable::InPlayerHands,
interactable::Interactable,
player::Player, proxy::{character::in_player_hands_parent::InPlayerHandsParent, physics::rapier::LinkToPlayer},
@ -47,8 +46,6 @@ pub fn capture_hand_usage(
(
Entity,
&GlobalTransform,
&'static FirearmData,
&mut MagazineData,
),
(With<InPlayerHands>, Without<InPlayerHandsParent>),
>,
@ -120,7 +117,7 @@ pub fn capture_hand_usage(
.full_auto_timer
.tick(resources.time.delta());
for (_f, firearm_transform, firearm_data, mut magazine_data) in
for (_f, firearm_transform) in
firearm_query.iter_mut()
{
for mut hand_transform in hand_query.iter_mut() {
@ -157,7 +154,7 @@ pub fn capture_hand_usage(
// Player is not in a reload animation
if resources.keyboard_input.just_pressed(KeyCode::R)
&& !resources.game_ui_state.any_window()
{
{}
/*
// Start reload animation
for (animation_player_entity, mut animation_player) in
@ -186,6 +183,7 @@ pub fn capture_hand_usage(
// At the end of reload animation, set magazine data to capacity = 0
}
// AIMING IN/OUT
/*
if resources.mouse_buttons.pressed(MouseButton::Right)
&& !resources.game_ui_state.any_window()
{
@ -281,7 +279,7 @@ pub fn capture_hand_usage(
player_firing_info.current_round_index = 0;
}
}
}
}*/
}
}

View File

@ -4,7 +4,7 @@ use crate::{
comps::core::{
markers::player::{Player, PlayerData},
spawners::{
guns::{glock17_spawner::Glock17SpawnPoint, m4a1_spawner::M4a1SpawnPoint},
guns::glock17_spawner::Glock17SpawnPoint,
player::PlayerSpawnPoint,
},
},
@ -16,13 +16,13 @@ pub fn set_spawn_points(mut commands: Commands) {
transform: Transform::from_xyz(3.0, 5.0, 2.0),
player: Player(PlayerData::default()),
});
commands.spawn(M4a1SpawnPoint {
/*commands.spawn(M4a1SpawnPoint {
transform: {
let mut transform = Transform::from_xyz(18.0, 10.0, 10.0);
transform.rotate_z(utils::rad_deg::radians_from_degrees(-90.0));
transform
},
});
});*/
commands.spawn(Glock17SpawnPoint {
transform: {
let mut transform = Transform::from_xyz(20.0, 10.0, 10.0);
@ -30,13 +30,13 @@ pub fn set_spawn_points(mut commands: Commands) {
transform
},
});
commands.spawn(M4a1SpawnPoint {
/*commands.spawn(M4a1SpawnPoint {
transform: {
let mut transform = Transform::from_xyz(18.0, 10.0, 18.0);
transform.rotate_z(utils::rad_deg::radians_from_degrees(-90.0));
transform
},
});
});*/
commands.spawn(Glock17SpawnPoint {
transform: {
let mut transform = Transform::from_xyz(20.0, 10.0, 20.0);

View File

@ -1,13 +1,11 @@
use bevy::{gltf::Gltf, prelude::*};
use crate::{
logic::core::guns::firearm::Firearm,
scenes::scene1::skybox::{Cubemap, CUBEMAPS},
};
use crate::{scenes::scene1::skybox::{Cubemap, CUBEMAPS}, comps::core::weapons::{firearm::Firearm, attachments::{weapon_attachment::WeaponAttachment, optic::Optic, magazine::Magazine, compensator::Compensator, foregrip::ForeGrip, stock::Stock}}};
#[derive(PartialEq, Eq, PartialOrd, Ord, Reflect)]
pub enum GltfAssetType {
Firearm(Firearm),
Attachment(WeaponAttachment),
Character,
#[allow(unused)]
Enemy,
@ -35,20 +33,67 @@ pub fn load_all_assets(
is_loaded: false,
image_handle: skybox_handle,
});
let m4a1_gltf_asset = GltfAsset {
/*let m4a1_gltf_asset = GltfAsset {
asset_type: GltfAssetType::Firearm(Firearm::M4A1),
asset: asset_server.load(Firearm::M4A1.firearm_data().asset_path),
};*/
// Weapons
let ak105_gltf_asset = GltfAsset {
asset_type: GltfAssetType::Firearm(Firearm::Ak105),
asset: asset_server.load(Firearm::Ak105.firearm_data().asset_path),
};
let glock17_gltf_asset = GltfAsset {
asset_type: GltfAssetType::Firearm(Firearm::Glock17),
asset: asset_server.load(Firearm::Glock17.firearm_data().asset_path),
};
// Attachments
let aimpoint_t1_gltf_asset = {
let attachment = WeaponAttachment::Optic(Optic::AimpointT1);
GltfAsset {
asset: asset_server.load(attachment.asset_path()),
asset_type: GltfAssetType::Attachment(attachment),
}
};
let ak105_magazine_gltf_asset = {
let attachment = WeaponAttachment::Magazine(Magazine::Ak105);
GltfAsset {
asset: asset_server.load(attachment.asset_path()),
asset_type: GltfAssetType::Attachment(attachment),
}
};
let first_compensator_gltf_asset = {
let attachment = WeaponAttachment::Compensator(Compensator::FirstCompensator);
GltfAsset {
asset: asset_server.load(attachment.asset_path()),
asset_type: GltfAssetType::Attachment(attachment),
}
};
let pk5_foregrip_gltf_asset = {
let attachment = WeaponAttachment::ForeGrip(ForeGrip::Pk5);
GltfAsset {
asset: asset_server.load(attachment.asset_path()),
asset_type: GltfAssetType::Attachment(attachment),
}
};
let tan_magpull_stock_gltf_asset = {
let attachment = WeaponAttachment::Stock(Stock::MagpullTan);
GltfAsset {
asset: asset_server.load(attachment.asset_path()),
asset_type: GltfAssetType::Attachment(attachment),
}
};
// Characters
let main_character_asset = GltfAsset {
asset_type: GltfAssetType::Character,
asset: asset_server.load("character/main_character.glb"),
};
commands.insert_resource(GltfAssets {
assets: Vec::from([m4a1_gltf_asset, glock17_gltf_asset, main_character_asset]),
assets: Vec::from([/*m4a1_gltf_asset, */
ak105_gltf_asset, glock17_gltf_asset, // Firearms
main_character_asset, // Characters
aimpoint_t1_gltf_asset, pk5_foregrip_gltf_asset, ak105_magazine_gltf_asset, first_compensator_gltf_asset, tan_magpull_stock_gltf_asset // Attachments
]),
});
}

View File

@ -3,12 +3,11 @@ use std::time::Duration;
use bevy::{gltf::Gltf, prelude::*};
use crate::{
comps::core::markers::{
firearm::{FirearmData, MagazineData},
comps::core::{markers::{
holdable::InPlayerHands,
player::Player, proxy::character::in_player_hands_parent::InPlayerHandsParent,
},
logic::core::guns::{firearm::Firearm, player_firing::PlayerFiringInfo},
}, weapons::{firearm::Firearm, firearm_data::FirearmData}},
logic::core::guns::player_firing::PlayerFiringInfo,
utils,
};
@ -96,12 +95,7 @@ fn spawn_firearm_on_player_hands(
.id();
let firearm_entity = commands
.spawn((
firearm_data.clone(),
firearm.holdable_object_data(),
MagazineData {
rounds_shot: 0,
max_capacity: firearm_data.max_capacity,
},
InPlayerHands,
Name::new("Firearm"),
TransformBundle {

View File

@ -13,7 +13,7 @@ pub struct GameLoadState {
impl GameLoadState {
pub fn is_everything_except_player_loaded(&self) -> bool {
self.assets_loaded && self.animations_loaded
self.assets_loaded// && self.animations_loaded
}
}

View File

@ -3,16 +3,12 @@ use bevy_editor_pls::EditorPlugin;
use bevy_inspector_egui::bevy_egui::EguiPlugin;
use crate::{
comps::core::markers::{
firearm::{FirearmData, MagazineData},
comps::core::{markers::{
holdable::{HoldableObjectData, InPlayerHands},
player::{Player, PlayerData, PlayerHand},
},
}, weapons::{firearm_data::FirearmData, magazine_data::MagazineData, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern}},
logic::core::{
guns::{
caliber::Caliber, firearm::Firearm, player_firing::PlayerFiringInfo,
spray_pattern::FirearmSprayPattern,
},
guns::player_firing::PlayerFiringInfo,
player::{
camera_player_sync::MouseMovementSettings,
player_movement::{PlayerLinearXZState, PlayerLinearYState, PlayerMovementInput},