Extensive work on virtually all of the visuals and the net code
This commit is contained in:
215
scripts/hack.gd
Normal file
215
scripts/hack.gd
Normal file
@@ -0,0 +1,215 @@
|
||||
class_name Hack extends Area3D
|
||||
|
||||
enum Type{
|
||||
BOMB,
|
||||
MINE,
|
||||
GAS,
|
||||
FORCE_PANEL,
|
||||
SWITCH,
|
||||
PITFALL
|
||||
}
|
||||
|
||||
const range_shapes : Dictionary = {
|
||||
Hack.Type.BOMB : Vector3(4.25,3,4.25),
|
||||
Hack.Type.GAS : Vector3(1,1,1),
|
||||
Hack.Type.PITFALL : Vector3(1,1,1),
|
||||
Hack.Type.FORCE_PANEL : Vector3(1,1,1),
|
||||
Hack.Type.SWITCH : Vector3(3,1,3),
|
||||
Hack.Type.MINE : Vector3(4.25,3,4.25),
|
||||
}
|
||||
const hack_icons : Dictionary = {
|
||||
Hack.Type.BOMB : preload("res://visuals/images/icons/t-bomb.png"),
|
||||
Hack.Type.GAS : preload("res://visuals/images/icons/t-gas.png"),
|
||||
Hack.Type.PITFALL : preload("res://visuals/images/icons/t-pitfall.png"),
|
||||
Hack.Type.FORCE_PANEL : preload("res://visuals/images/icons/t-force_panel.png"),
|
||||
Hack.Type.SWITCH : preload("res://visuals/images/icons/t-switch.png"),
|
||||
Hack.Type.MINE : preload("res://visuals/images/icons/t-mine.png"),
|
||||
}
|
||||
|
||||
const bomb_explosion_template = preload("res://templates/explosion.tscn")
|
||||
const mine_explosion_template = preload("res://templates/explosion.tscn")
|
||||
const pitfall_template = preload("res://templates/pitfall.tscn")
|
||||
const switch_explosion_template = preload("res://templates/explosion.tscn")
|
||||
const gas_emitter_template = preload("res://templates/gas_emitter.tscn")
|
||||
const force_activate_sound = preload("res://audio/sounds/TomWinandySFX_UI_ScifiTech_Start_06.wav")
|
||||
|
||||
@onready var range_area : Area3D = %RangeArea
|
||||
@onready var range_shape : BoxShape3D = %RangeShape.shape
|
||||
@onready var model : MeshInstance3D = %Model
|
||||
@onready var icon : Sprite3D = %Icon
|
||||
@onready var force_strip : Sprite3D = %ForceStrip
|
||||
@onready var material : ShaderMaterial = model.get_active_material(0)
|
||||
@onready var reveal_timer : Timer = %RevealTimer
|
||||
@onready var activation_timer : Timer = %ActivationTimer
|
||||
|
||||
var type : Type
|
||||
var square : Vector3i
|
||||
var hack_owner : int
|
||||
var direction : Vector3
|
||||
|
||||
var expended : bool = false
|
||||
var decompiling : bool
|
||||
var decompile_id : int
|
||||
|
||||
var delayed_trigger_tween : Tween = null
|
||||
|
||||
var damage : int = 10
|
||||
|
||||
var just_revealed : bool = false
|
||||
|
||||
|
||||
signal removed(type : Hack.Type)
|
||||
signal decompiled(type : Hack.Type)
|
||||
signal activated(type : Hack.Type)
|
||||
signal revealed(is_visible : bool)
|
||||
|
||||
func _enter_tree() -> void:
|
||||
Game.level.add_map_marker(self)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
Game.level.remove_map_marker(self)
|
||||
|
||||
func setup(type : Type, direction : Vector3, hack_owner : int) -> void:
|
||||
self.type = type
|
||||
self.hack_owner = hack_owner
|
||||
if type == Type.FORCE_PANEL:
|
||||
var r : float = atan2(direction.z, direction.x)
|
||||
var cardinal : float = roundi(r * 2 / PI) * PI / 2
|
||||
self.direction = Vector3(cos(cardinal), 0, sin(cardinal))
|
||||
|
||||
func remove() -> void:
|
||||
removed.emit(type)
|
||||
queue_free()
|
||||
|
||||
func decompile() -> void:
|
||||
decompiled.emit(type)
|
||||
queue_free()
|
||||
|
||||
func reveal() -> void:
|
||||
if model.visible:
|
||||
return
|
||||
model.visible = true
|
||||
reveal_timer.start(5)
|
||||
just_revealed = true
|
||||
revealed.emit(true)
|
||||
|
||||
func is_just_revealed() -> bool:
|
||||
return just_revealed
|
||||
|
||||
func is_revealed() -> bool:
|
||||
return model.visible
|
||||
|
||||
func _on_reveal_timeout() -> void:
|
||||
if Game.level.is_square_detected(square) or decompiling:
|
||||
reveal_timer.start(5)
|
||||
else:
|
||||
model.visible = false
|
||||
revealed.emit(false)
|
||||
|
||||
func _ready() -> void:
|
||||
var owns_hack = hack_owner == Multiplayer.id
|
||||
print("Setup Hack " + name)
|
||||
material.set_shader_parameter("glow_color", Color.YELLOW if owns_hack else Color.RED)
|
||||
icon.texture = hack_icons[type]
|
||||
model.visible = owns_hack
|
||||
icon.visible = owns_hack
|
||||
range_shape.size = range_shapes[type]
|
||||
match(type):
|
||||
Type.BOMB:
|
||||
damage = 15
|
||||
Type.MINE:
|
||||
damage = 10
|
||||
Type.SWITCH:
|
||||
damage = 5
|
||||
Type.GAS:
|
||||
activation_timer.start()
|
||||
Type.FORCE_PANEL:
|
||||
var r : float = atan2(direction.z, -direction.x) + PI/2
|
||||
force_strip.rotate_y(r)
|
||||
force_strip.visible = owns_hack
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
just_revealed = false
|
||||
|
||||
func blast(body : PawnController) -> void:
|
||||
body.hurt(damage)
|
||||
body.knockup((global_position.direction_to(body.global_position) + Vector3(0,2,0)) * 3)
|
||||
|
||||
func activate() -> void:
|
||||
if expended:
|
||||
return
|
||||
var explode : bool = false
|
||||
match(type):
|
||||
Type.PITFALL:
|
||||
generate_pitfall(square)
|
||||
for body in get_overlapping_bodies():
|
||||
body.start_pitfall(square, 6.0)
|
||||
#Generate the circle here
|
||||
Type.FORCE_PANEL:
|
||||
Game.oneshot(force_activate_sound)
|
||||
for body in get_overlapping_bodies():
|
||||
body.fling(direction, 5.0)
|
||||
Type.MINE:
|
||||
var exp = mine_explosion_template.instantiate()
|
||||
Game.level.add_vfx(exp, square)
|
||||
explode = true
|
||||
Type.SWITCH:
|
||||
var exp = switch_explosion_template.instantiate()
|
||||
Game.level.add_vfx(exp, square)
|
||||
explode = true
|
||||
Type.BOMB:
|
||||
var exp = bomb_explosion_template.instantiate()
|
||||
Game.level.add_vfx(exp, square)
|
||||
explode = true
|
||||
Type.GAS:
|
||||
var emitter = gas_emitter_template.instantiate()
|
||||
emitter.hack_owner = hack_owner
|
||||
emitter.square = square
|
||||
emitter.damage = 4
|
||||
Game.level.add_vfx(emitter, square)
|
||||
|
||||
if explode:
|
||||
trigger_adjacent_bombs()
|
||||
blast_players()
|
||||
|
||||
expended = true
|
||||
Game.level.uninstall_hack_square(square)
|
||||
activated.emit(type)
|
||||
queue_free()
|
||||
|
||||
func trigger_adjacent_bombs() -> void:
|
||||
for hack : Hack in range_area.get_overlapping_areas():
|
||||
if hack.type == Type.BOMB and hack != self:
|
||||
hack.delay_trigger()
|
||||
|
||||
func generate_pitfall(suqare : Vector3i) -> void:
|
||||
var pitfall = pitfall_template.instantiate()
|
||||
pitfall.duration = 6.0
|
||||
Game.level.add_vfx(pitfall, square)
|
||||
|
||||
func blast_players() -> void:
|
||||
for body in range_area.get_overlapping_bodies():
|
||||
blast(body)
|
||||
|
||||
func delay_trigger() -> void:
|
||||
if delayed_trigger_tween != null:
|
||||
return
|
||||
delayed_trigger_tween = create_tween()
|
||||
delayed_trigger_tween.tween_interval(.25)
|
||||
delayed_trigger_tween.tween_callback(activate)
|
||||
|
||||
|
||||
func _on_body_entered(body: Node3D) -> void:
|
||||
if type == Type.GAS or type == Type.BOMB:
|
||||
return
|
||||
|
||||
if body.id == hack_owner:
|
||||
return
|
||||
|
||||
if !decompiling or body.id != decompile_id:
|
||||
if !body.detecting:
|
||||
activate()
|
||||
|
||||
|
||||
func _on_activation_timer_timeout() -> void:
|
||||
activate()
|
||||
Reference in New Issue
Block a user