Unique Weapon Merging Mechanic

Using Godot4.3

Heya guys I’m still new here. And slowly getting the hang of coding and such. I’ve followed some tutorials in making a 2d platformer and a 2d survivor game. I’ve recently learnt about classes and have been using them to make a blueprint for enemies to smash out several mobs with various stats.

Anyways, the point of this post is that I’m wanting to expand on the survivors game and want to make a mechanic that I have no clue where to start from. The idea is to be able to take two obtained weapons, and combine them into a unique custom weapon. The idea isn’t to craft a pre-made weapon, but to choose two weapons you have, fuse them together, then you get given a new weapon where it’s values are the best from the two respective weapons.
And because it seems people really like specifics, I’m talking about a way to compare two weapons with stats such as damage, attack speed, projectile speed, projectile count etc and take the highest from each seperate weapon

Is this possible and if so, how can I go about this?

There are many ways to go about this. A very simple one would be to use a class to store weapon values, and another class to do the comparison.

class_name WeaponStatistics
@export var damage : int = 0
@export var attack_speed : int = 0
# etcetera
class_name WeaponStatisticsFuser
func get_highest_statistics_of_both_weapons(weapon_statistics_1 : WeaponStatistics, weapon_statistics_2 : WeaponStatistics)->WeaponStatistics:
	var new_statistics : WeaponStatistics

	if weapon_statistics_1.damage > weapon_statistics_2.damage:
		new_statistics.damage = weapon_statistics_1.damage
	else:
		new_statistics.damage = weapon_statistics_2.damage

	return new_statistics
# etcetera

(It is indeed very simple, for this code has absolutely no safeguards for ‘special cases’. If one field is ‘max_ammo_capacity’ for the first weapon, and the second weapon is a sword, you may end up with a sword that has ammo capacity.)

1 Like

Thank you so much. That actually looks so much easier than I was expecting. I do plan on weapons attacking differently like one that attacks at cursor position or another to attack closest enemy etc. So the plan was when fusing, you use on of them as a base to have the same attack pattern with entirely new stats and projectiles and such based on the fused. I will be going down the path of spells rather than guns and swords with no ammo count but we will see how we go with that. Thank you