Kits, associating players and player-kit fields

Discussion in 'Plugin Development' started by OshaGoro, May 25, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    OshaGoro

    Hello, all!

    This is my first time using these forums, so I hope this thread is appropriate and that I don't mess up.
    I am attempting to create a game that involves kits that players can select. I've currently got a rather lengthy setup so I will try and condense this to what is necessary.

    I have a Kit abstract class, which concrete kits extend, let's say for example, Fighter and Archer. These classes have no information about any players, and as such, they only contain information about the kit itself such as the name, a description of the kit, a list of potential skills or abilities (This seems like an appropriate place to put this, though I'm unsure), etc. The idea is that at the start of each game, only one of each of these kits is instantiated and stored, and they are constantly referenced - for example, when a Kit Selection Menu of some sort is made, it will refer to these Kit objects.

    I have two issues and questions regarding this:

    1) For associating a player with a kit, I'm unsure whether I should use PlayerMetaData to store this, or whether I should just create a HashMap that maps the player to a reference to this kit.​

    2) When a player selects a kit and uses it, there may be fields specific to that player-kit instance. Say for example, an integer shotsCount that exists for each player that uses the Archer kit. Because I am only creating one instance of a kit per game, shotsCount cannot exist in the Archer class, as it will be shared across all players using the Archer kit (in a "global" manner?), as opposed to a per player basis.

    On the other hand, if I were to create multiple kits for each player instance, as opposed to one per game, then if I want to only retrieve information about a kit without any player reference, then this wouldn't make much sense (The player reference in the kit class would be null?). As a result, I don't think this approach is correct.

    Say, if I create a PlayerKit class that has this shotsCount variable, this wouldn't make much sense if the player were a Fighter, as that variable is insignificant/irrelevant/doesn't exist for that kit.

    On the other hand, if I were to create separate classes for each player-kit instance, associating a player to their kit and the kit-specific stats for the player (for example, PlayerFighter, PlayerArcher, etc.), there would be many classes if there were a large number of kits added in the future, which may be unnecessary or redundant if many do not contain player-kit specific fields.​

    I am wondering what the best approach to model this would be or if there are any suggestions regarding this. Are there useful design strategies or patterns for this? I hope I've explained this well enough to be understood. Thanks in advance! :)
     
Thread Status:
Not open for further replies.

Share This Page