mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-15 08:24:48 +00:00
✨ Inventory, Weapons and refactoring
This commit is contained in:
parent
f43056d251
commit
6df677eda7
70 changed files with 1812 additions and 3895 deletions
16
entities/components/explosive_damage.tscn
Normal file
16
entities/components/explosive_damage.tscn
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://qb5sf7awdeui"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/components/explosive_damage_component.gd" id="1_alx3x"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_1htx7"]
|
||||
radius = 5.0
|
||||
|
||||
[node name="ExplosiveDamage" type="Area3D"]
|
||||
collision_mask = 13
|
||||
script = ExtResource("1_alx3x")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_1htx7")
|
||||
|
||||
[connection signal="area_shape_entered" from="." to="." method="_on_area_shape_entered"]
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
|
|
@ -14,26 +14,39 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
class_name ExplosiveDamageComponent extends Area3D
|
||||
|
||||
## Emitted when the scale tween is finished
|
||||
signal finished
|
||||
|
||||
@export var damage : int = 35
|
||||
@export var impulse_force : int = 1000
|
||||
var damage_dealer : MatchParticipantComponent
|
||||
|
||||
var _damaged_objects : Dictionary= {
|
||||
"bodies": [],
|
||||
"areas": []
|
||||
}
|
||||
|
||||
func _ready() -> void:
|
||||
# this component only scans to apply explosion damage/impulse
|
||||
# at the moment layers: 1 Object, 3 Damage, 4 Objective
|
||||
monitorable = false
|
||||
monitoring = true
|
||||
collision_mask = 0b10000000_00000000_00000000_00001101
|
||||
# scale explosive damage aoe
|
||||
var tween : Tween = get_tree().create_tween()
|
||||
tween.set_trans(Tween.TRANS_SINE)
|
||||
tween.tween_property($CollisionShape3D,
|
||||
"scale", Vector3.ONE, .3).from(Vector3.ZERO)
|
||||
tween.tween_property($CollisionShape3D,
|
||||
"scale", Vector3.ZERO, .1).from(Vector3.ONE)
|
||||
tween.finished.connect(func() -> void: finished.emit(); queue_free())
|
||||
|
||||
func _physics_process(_delta : float) -> void:
|
||||
for body in get_overlapping_bodies():
|
||||
if body is RigidBody3D:
|
||||
var center_of_mass_global_position : Vector3 = body.center_of_mass + body.global_position
|
||||
var direction : Vector3 = ( center_of_mass_global_position - global_position).normalized()
|
||||
body.apply_central_impulse(direction * impulse_force)
|
||||
func _on_body_entered(body: Node3D) -> void:
|
||||
if body is RigidBody3D and body not in _damaged_objects["bodies"]:
|
||||
var center_of_mass_global_position : Vector3 = body.center_of_mass + body.global_position
|
||||
var direction : Vector3 = ( center_of_mass_global_position - global_position).normalized()
|
||||
body.apply_central_impulse(direction * impulse_force)
|
||||
_damaged_objects["bodies"].append(body)
|
||||
|
||||
for area in get_overlapping_areas():
|
||||
if area is HealthComponent and is_multiplayer_authority():
|
||||
(area as HealthComponent).damage.rpc(damage, damage_dealer.player_id, damage_dealer.team_id)
|
||||
|
||||
set_physics_process(false)
|
||||
func _on_area_shape_entered(_area_rid: RID, area: Area3D, _area_shape_index: int, _local_shape_index: int) -> void:
|
||||
if area is HealthComponent and area not in _damaged_objects["areas"]:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
assert(damage_dealer)
|
||||
area.damage.rpc(damage, damage_dealer.player_id, damage_dealer.team_id)
|
||||
_damaged_objects["areas"].append(area)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ func _ready() -> void:
|
|||
collision_layer = 0b00000000_00000000_00000000_00000100
|
||||
monitoring = false
|
||||
collision_mask = 0
|
||||
heal_full()
|
||||
call_deferred("heal_full")
|
||||
|
||||
@rpc("call_local", "reliable")
|
||||
func damage(amount : float, damage_dealer_player_id : int, damage_dealer_team_id : int) -> void:
|
||||
|
|
|
|||
74
entities/components/inventory.gd
Normal file
74
entities/components/inventory.gd
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# This file is part of open-fpsz.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
## This component allows its entity to interact with pickable nodes
|
||||
class_name Inventory extends Node3D
|
||||
|
||||
const _max_items = 3
|
||||
## This is the total capacity of inventory.
|
||||
@export_range(0, _max_items) var capacity : int = _max_items:
|
||||
set(value):
|
||||
capacity = clamp(value, 1, _max_items)
|
||||
|
||||
@export var selected : Node3D
|
||||
|
||||
signal selection_changed(selected : Node3D, index : int)
|
||||
|
||||
func _ready() -> void:
|
||||
# make sure a child is selected if any
|
||||
if not selected and get_child_count() > 0:
|
||||
selected = get_child(0)
|
||||
# make sure this inventory is linked to its owner
|
||||
if not owner.inventory:
|
||||
owner.inventory = self
|
||||
|
||||
## This method overrides [method Node.add_child] method to make sure not to exceed the inventory capacity
|
||||
func _add_child(node: Node, force_readable_name: bool = false, internal: InternalMode = InternalMode.INTERNAL_MODE_DISABLED) -> void:
|
||||
if get_child_count() <= capacity:
|
||||
super.add_child(node, force_readable_name, internal)
|
||||
else:
|
||||
push_warning("inventory is full")
|
||||
|
||||
## This method cycles through the items in the inventory. If an item is already
|
||||
## [member selected], it hides the current item, shifts by the specified number
|
||||
## of items, and shows the new selected item. If no item is selected, it selects
|
||||
## the first item. If the inventory is empty, it displays a warning message.
|
||||
func cycle(shift : int = 1) -> void:
|
||||
var child_count : int = get_child_count()
|
||||
if selected:
|
||||
selected.hide()
|
||||
var index : int = wrapi(selected.get_index() + shift, 0, child_count)
|
||||
selected = get_child(index)
|
||||
selection_changed.emit(selected, index)
|
||||
selected.show()
|
||||
elif child_count > 0:
|
||||
selected = get_child(0)
|
||||
selection_changed.emit(selected, 0)
|
||||
selected.show()
|
||||
else:
|
||||
push_warning("inventory is empty")
|
||||
|
||||
## This method moves the [member selected] cursor to a specific inventory item.
|
||||
func select(index : int) -> void:
|
||||
if selected:
|
||||
selected.hide()
|
||||
selected = get_child(index)
|
||||
if selected:
|
||||
selection_changed.emit(selected, index)
|
||||
selected.show()
|
||||
else:
|
||||
selected = get_child(index)
|
||||
if selected:
|
||||
selection_changed.emit(selected, index)
|
||||
selected.show()
|
||||
|
|
@ -13,7 +13,7 @@ signal nickname_changed(new_nickname : String)
|
|||
player_id_changed.emit(player_id)
|
||||
@export var team_id : int = 1
|
||||
|
||||
func _ready() -> void:
|
||||
func _enter_tree() -> void:
|
||||
root_path = "."
|
||||
replication_config = SceneReplicationConfig.new()
|
||||
for prop : String in ["player_id", "team_id", "nickname"]:
|
||||
|
|
|
|||
31
entities/components/projectile_spawner.gd
Normal file
31
entities/components/projectile_spawner.gd
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# This file is part of open-fpsz.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
class_name ProjectileSpawner extends Node3D
|
||||
|
||||
@export_category("Projectile")
|
||||
@export var PROJECTILE : PackedScene
|
||||
@export_range(0., 1., .01) var inheritance : float = .5 # ratio
|
||||
|
||||
func new_projectile(
|
||||
projectile_type : Object,
|
||||
owner_velocity : Vector3,
|
||||
shooter : MatchParticipantComponent
|
||||
) -> Node3D:
|
||||
return projectile_type.new_projectile(
|
||||
self,
|
||||
owner_velocity * inheritance,
|
||||
shooter,
|
||||
PROJECTILE
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue