ProjectileManager2D

Inherits: ProjectileCaller2D < Node2D < CanvasItem < Node < Object

Handles projectile spawning through Attack2D instances.


Description

ProjectileManager2D nodes are ProjectileCaller2D extensions, and like the latter, you can use them to request the creation of any of its projectiles.

The main difference between these two is that you can use ProjectileManager2Ds in conjunction with AttackBlueprint2Ds to convert a constant Input request into an orderly timed projectile barrage.

With ProjectileManager2D:

Projectile example using Attack2D and ProjectileManager2D
extends Node2D

@onready var projectile_manager: ProjectileManager2D = $ProjectileManager2D

func _process(_delta: float) -> void:
	if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
		projectile_manager.request_execution(0, 0, position, get_global_mouse_position())

With ProjectileCaller2D:

Projectile example without using Attack2D and ProjectileManager2D
extends Node2D

@onready var projectile_caller: ProjectileCaller2D = $ProjectileCaller2D

func _process(_delta: float) -> void:
	if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
		projectile_caller.request_projectile(0, position, get_global_mouse_position())

Tutorials


Properties



Methods



Property Descriptions

Array[AttackBlueprint2D] attack_resources

List of all AttackBlueprint2D resources allocated on the ProjectileManager2D.

Each element in the array is used to create its corresponding Attack2D object in the attacks array by the same index.


Array[Attack2D] attacks

List of all Attack2D objects that can be used by the ProjectileManager2D.

Each ProjectileManager2D instance can only modify its own stored attacks.


bool auto_add_attacks_to_database = true

If true the ProjectileManager2D Node will automatically add its unregistered attacks to the Global Database; using its blueprint name as key.


bool get_attack_copies_from_database = true

If true the ProjectileManager2D Node will only get copies when requesting attacks from the Global Database instead of direct references.

Consequently, any changes you make on them will not be reflected on the attacks allocated on the Global Database itself.



Method Descriptions

bool add_attack_from_database(id: StringName, include_blueprints: bool = false)

Returns true on success.

Adds the attack with key id from the Global Database to the end of its local attacks array.

If include_blueprints is true, it also adds its AttackBlueprint2D counterpart to its attack_resources array.

extends Node2D

@onready var projectile_manager: ProjectileManager2D = $ProjectileManager2D

func _ready() -> void:
	projectile_manager.add_attack_from_database("MEGA_LASER")

bool add_attack_modifier(index: int, modifier: Attack2DModifier)

Returns true on success.

Adds a modifier to the attack at the specified index of its local attacks array.

projectile_manager.add_attack_modifier(0, Attack2DModifier.new("ATTACK_BUFF", 1.0))
projectile_manager.add_attack_modifier(0, APDatabase.get_attack_2d_modifier("MULTISHOT_BUFF"))

void append_attacks_from_database(names: Array, include_blueprints: bool = false)

Adds attacks from the Global Database to the end of its local attacks array.

If include_blueprints is true, it also adds its AttackBlueprint2D counterparts to its attack_resources array.

extends Node2D

@onready var projectile_manager: ProjectileManager2D = $ProjectileManager2D

enum Spells{
	MAGIC_BOLT,
	SOUL_SEEKER,
	FIREBALL,
	ERUPTION,
	MEGA_LASER
}

func _ready() -> void:
	projectile_manager.append_attacks_from_database(Spells.keys())

Attack2D get_attack(index: int)

Returns the attack at the specified index of its local attacks array.

Use it to change the properties and behaviors of your attacks.

projectile_manager.get_attack(0)

AttackBlueprint2D get_attack_blueprint(index: int)

Returns the blueprint at the specified index of its local attack_resources array.

projectile_manager.get_attack_blueprint(0)

void reassign_attacks_from_database(names: Array, include_blueprints: bool = false)

Replaces its entire attacks array with attacks from the Global Database.

If include_blueprints is true, it also replaces its AttackBlueprint2D counterparts at the attack_resources array.

extends Node2D

@onready var projectile_manager: ProjectileManager2D = $ProjectileManager2D

enum Spells{
	MAGIC_BOLT,
	SOUL_SEEKER,
	FIREBALL,
	ERUPTION,
	MEGA_LASER
}

func _ready() -> void:
	projectile_manager.reassign_attacks_from_database(Spells.keys())

bool remove_attack_modifier(index: int, id: StringName)

Returns true on success.

Removes a modifier from the attack at the specified index of its local attacks array by id.

projectile_manager.remove_attack_modifier(0, "ATTACK_BUFF")

bool remove_modifier_stacks_from_attack(index: int, id: StringName, stacks: int = -1)

Returns true on success.

Removes a specific number of modifier stacks from the attack at the specified index of its local attacks array.

If stacks < 0, removes all stacks.

projectile_manager.remove_modifier_stacks_from_attack(0, "ATTACK_BUFF", 2)

bool request_execution (attack_index: int, proj_index: int, _position: Vector2, destination: Vector2, target: Node2D = null, move_method: Callable = Callable(), start_method: Callable = Callable(), collision_method: Callable = Callable(), expired_method: Callable = Callable())

Returns true if the execution request has been successful.

Requests the creation of the projectile at the specified proj_index of its local projectiles array, under the conditions of the attack at the specified attack_index of its local attacks array.

Additional parameters and requirements still match those of request_projectile.

extends Node2D

@onready var projectile_manager: ProjectileManager2D = $ProjectileManager2D

func _process(_delta: float) -> void:
	if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
		projectile_manager.request_execution(0, 0, position, get_global_mouse_position())

bool request_new_attack_creation(attack_index: int, proj_index: int, _position: Vector2, destination: Vector2, target: Node2D = null, move_method: Callable = Callable(), start_method: Callable = Callable(), collision_method: Callable = Callable(), expired_method: Callable = Callable())

Returns true if the execution request has been successful.

It works exactly as request_execution, however each call creates an entirely new, completely unregulated, fully autonomous Attack2D instance.

Use it at your own discretion.

extends Node2D

@onready var projectile_manager: ProjectileManager2D = $ProjectileManager2D

func _input(event) -> void:
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
			projectile_manager.request_new_attack_creation(0, 0, position, get_global_mouse_position())

void set_attack(index: int, projectile: Attack2D, auto_assign_blueprint: bool = true)

Sets the given attack at the specified index of its local attacks array.

If auto_assign_blueprint is true it sets its blueprint to the same one its method index is replacing.

func _ready() -> void:
	# These two statements are the same
	projectile_manager.set_attack(0, MyAttack.new())
	projectile_manager.set_attack(0, MyAttack.new(projectile_manager.get_attack_blueprint(0)))
    
	# Set it to "false" so it does not auto assing
	projectile_manager.set_attack(0, MyAttack.new(projectile_manager.get_attack_blueprint(1)), false)

bool set_attack_from_database(index: int, id: StringName, include_blueprints: bool = false)

Returns true on success.

Sets the element at the specified index in the attacks array, to the attack with key id from the Global Database.

If include_blueprints is true, it also sets its AttackBlueprint2D counterpart at the specified index of its attack_resources array.

extends Node2D

@onready var projectile_manager: ProjectileManager2D = $ProjectileManager2D

func _ready() -> void:
	projectile_manager.set_attack_from_database(4, "MEGA_LASER")

bool validate_attack(index: int)

Returns true if the attack at the specified index of its local attacks array can be used.


bool validate_attack_resource(index: int)

Returns true if the blueprint at the specified index of its local attack_resources array can be used.


bool verify_attack_from_database(id: StringName)

Returns true if the Global Database has a registered attack under key id.