Phaser Game project - Goblins - JavaScript

Hello there,

my name is John and after finishing Create Video Games with Phaser course i tried to code a game. I am at first steps so dont expect anything spectacular. I reached one problem with my project, but first a little introduction.

I plan to build a game, in which you lead a most despicable fantasy creatures - goblins. You start as a small leader with 3 followers (goblins). Leader will develop skills and abilities that will shape his followers (inherit properties) in reaction to his actions and game choices. Each goblin (leader or grunt) have also his own stats with his own equipment (objects and nested objects). Your goblin dies a lot during a game but if you loose your leader, it is a game over. Because you replenish your forces alot i created a goblin facory function. For Factory i also create an Armory and Skillmory objects, which have nested equipment and skill objects in them. Here lies my first problem. When i generate goblins I “copy” reference to those objects, not actual objects. So during battles, when equipment gets damaged, all changes were directed to “core/parent” object located in Armory/Skillmory. I find information about shallow copies and deep copies yet i was wondering it there is an elegant solution to my code. Something like “superHardCopy()” method that will create entirly new object without ties to the source.

If it would not provide inconvinience, can someone check my beginner code? I would really like to learn from my mistakes :slight_smile:

here is a link to my project: