👽 interstellar delivery

This commit is contained in:
anyreso 2024-10-16 21:43:01 +00:00
parent 547c97bfba
commit 97c8292858
257 changed files with 7309 additions and 4637 deletions

View file

@ -1,16 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://qb5sf7awdeui"]
[ext_resource type="Script" path="res://entities/components/explosive_damage/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"]

View file

@ -1,52 +0,0 @@
# 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 ExplosiveDamageComponent extends Area3D
## Emitted when the scale tween is finished
signal finished
@export var damage : float = 89
@export var impulse_force : int = 1000
var damage_dealer : MatchParticipant
var _damaged_objects : Dictionary= {
"bodies": [],
"areas": []
}
func _ready() -> void:
# 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 _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)
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)

View file

@ -15,40 +15,35 @@
## This component allows its entity to interact with flags
class_name FlagCarryComponent extends Node3D
@export var max_throw_speed : float = 10.0
@export var throw_force : int = 12
@export var mesh : Node3D
var _carried_flag : Flag
func _process(_delta : float) -> void:
if _is_carrying():
_carried_flag.global_position = global_position
_carried_flag.global_rotation = Vector3(.0, global_rotation.y, .0)
func _is_carrying() -> bool:
return _carried_flag != null
var _flag : Flag
func grab(flag : Flag) -> void:
if not _is_carrying():
flag.grabbed.emit(owner)
_carried_flag = flag
if flag.state < Flag.FlagState.TAKEN:
show()
_flag = flag
flag.grabbed.emit(self)
func drop(dropper : Player) -> void:
_release(Vector3.ZERO, 0.0, dropper)
func drop(inherited_velocity : Vector3 = Vector3.ZERO) -> void:
_release(inherited_velocity, 0)
func throw(inherited_velocity : Vector3, dropper : Player) -> void:
_release(inherited_velocity, max_throw_speed, dropper)
func throw(inherited_velocity : Vector3 = Vector3.ZERO, _force: int = throw_force) -> void:
_release(inherited_velocity, _force)
func _release(inherited_velocity : Vector3, throw_speed : float, dropper : Player) -> void:
if not _is_carrying() or !is_inside_tree():
return
# update carried flag global rotation based on component global rotation
_carried_flag.global_rotation = Vector3(.0, global_rotation.y, .0)
_carried_flag.linear_velocity = inherited_velocity + (global_basis.z * throw_speed)
# Throw the flag from some distance in front of the player to avoid regrabbing mid-air
_carried_flag.global_position = owner.global_position + (global_basis.z * 1.7)
_carried_flag.dropped.emit(dropper)
_carried_flag = null
func _release(inherited_velocity : Vector3 = Vector3.ZERO, _force: int = throw_force) -> void:
if not _flag or !is_inside_tree(): return
_flag.dropped.emit(self)
var impulse : Vector3 = _flag.mass * (inherited_velocity + global_basis.z * _force)
_flag.apply_central_impulse(impulse) # wake up the flag
# @NOTE: throw the flag from some distance in front of the player to avoid regrabbing mid-air
# @FIXME: there is a small chance to send the flag under the map
_flag.global_position = global_position + (global_basis.z * 1.7)
# rotate carried flag based on flag carry global rotation
_flag.global_rotation = Vector3(.0, global_rotation.y, .0)
# drop reference to flag
_flag = null
# hide carried flag mesh
hide()

View file

@ -0,0 +1,59 @@
# 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 class defines a Health component for entities.
class_name Health extends Area3D
## An entity with this component can be either dead or alive.
enum HealthState { DEAD, ALIVE }
## Emitted when a peer damaged this component too much.
signal killed(by_peer_id:int)
## Emitted when value is exhausted.
signal exhausted()
## Emitted when the value is updated.
signal updated(new_value:int)
## Emitted when the health component is damaged.
signal damaged(source: Node, target: Node, amount: int)
@export var collider:CollisionShape3D
@export var max_value:int = 255
@export var value:int = 255:
set = set_value
@export var state : HealthState = HealthState.ALIVE
func _ready() -> void:
# only collide with the layer 3 named "Damage", disable monitoring completely
collision_layer = 0b00000000_00000000_00000000_00000100
collision_mask = 0
monitoring = false
func set_value(new_value:int) -> void:
value = clampi(new_value, 0, max_value)
updated.emit(value)
@rpc("authority", "call_local", "reliable")
func damage(amount:int, by_peer_id:int) -> void:
value -= amount
if value == 0 and state != HealthState.DEAD:
state = HealthState.DEAD
killed.emit(by_peer_id)
exhausted.emit(owner)
@rpc("authority", "call_local", "reliable")
func heal(amount:int = max_value) -> void:
# add strictly positive amount to value
value += clampi(amount, 1, max_value)
state = HealthState.ALIVE

View file

@ -1,52 +0,0 @@
# 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 HealthComponent extends Area3D
@export var match_participant : MatchParticipant
@export var max_health : int = 255
@export var health : int = 255:
set(new_health):
health = new_health
health_changed.emit(new_health)
signal health_zeroed(killer_id : int)
signal health_changed(new_health : int)
func _ready() -> void:
# only collide with the "Damage" layer, disable monitoring completely
collision_layer = 0b00000000_00000000_00000000_00000100
monitoring = false
collision_mask = 0
call_deferred("heal_full")
@rpc("call_local", "reliable")
func damage(amount : int, damage_dealer_player_id : int, damage_dealer_team_id : int) -> void:
if (damage_dealer_team_id == match_participant.team_id) and (damage_dealer_player_id != match_participant.player_id):
return
health = clampi(health - amount, 0, max_health)
if health == 0:
health_zeroed.emit(damage_dealer_player_id)
@rpc("call_local", "reliable")
func _heal(amount : int) -> void:
health = clampi(health + amount, 0, max_health)
func heal_full() -> void:
if not is_multiplayer_authority():
return
_heal.rpc(max_health)

View file

@ -1,4 +1,5 @@
# This file is part of open-fpsz.
# copyright (c) 2024 - anyreso & open-fpsz contributors
#
# 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
@ -12,63 +13,65 @@
#
# 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
@tool
## This component allows its entity to hold [Weapon] nodes.
class_name Inventory extends Node3D
signal selection_changed(index : int)
signal selected(node: Node)
signal unselected(node: Node)
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
@export_range(0, _max_items - 1) var cursor : int = 0:
set = set_cursor
signal selection_changed(selected : Node3D, index : int)
# Function to set the cursor position in the inventory
func set_cursor(new_cursor: int) -> void:
# Ensure the cursor is within the valid range
if new_cursor >= 0 and new_cursor < _max_items:
# emit unselected signal
_emit_child(unselected, cursor)
# update cursor position
cursor = new_cursor
# emit selected signal
_emit_child(selected, cursor)
# helper function to emit the selected signal for the current cursor position
func _emit_child(sig: Signal, idx: int) -> void:
var child : Node = get_child(idx)
if child:
sig.emit(child)
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
unselected.connect(_on_unselected)
selected.connect(_on_selected)
func _on_unselected(node: Node) -> void:
node.hide()
func _on_selected(node: Node) -> void:
node.show()
## 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:
## This method overrides [method Node.add_child] to make sure not to exceed
## 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.
## This method moves the [member selection] cursor to specified item index.
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()
cursor = wrapi(index, 0, get_child_count())
## This method cycles through items in the inventory.
func cycle(shift : int = 1) -> void:
select(cursor + shift)

View file

@ -1,20 +0,0 @@
class_name MatchParticipant extends Node
signal player_id_changed(new_player_id : int)
signal username_changed(new_username : String)
signal team_id_changed(new_team_id : int)
@export var username : String = "Newblood":
set(value):
username = value
username_changed.emit(username)
@export var player_id : int:
set(value):
player_id = value
player_id_changed.emit(player_id)
@export var team_id : int = 1:
set(value):
team_id = value
team_id_changed.emit(team_id)

View file

@ -1,31 +0,0 @@
# 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 : MatchParticipant
) -> Node3D:
return projectile_type.new_projectile(
self,
owner_velocity * inheritance,
shooter,
PROJECTILE
)