Skip to content

Weapons Code Logic

PurrplePandaa edited this page Aug 29, 2022 · 18 revisions

Back to Combat Items Contents Page

Defining the weapons

The type and stats of weapons in the game are defined in .json config files under \source\core\assets\configs image

The parameters in the config files will be "parsed" into their weapon type config classes under source/core/src/main/com/deco2800/game/entities/configs/CombatItemsConfig. Image below shows the config class for Melee weapons. image

The general weapon config class initialises specialised config classes for the weapons that will be defined in game. image

Creating the weapons into the game

The type and stats of weapons in the config files can be sent into the WeaponFactory class under source\core\src\main\com\deco2800\game\entities\factories\WeaponFactory.java and read by the FileLoader.readClass() method as shown below

image

The types of weapons in the config files can be created with the different create() methods for each weapon type in the WeaponFactory class. The different weapon types weapon creator methods will call the base weapon creator method to create a base weapon entity, and have different component add-ons onto the Weapon Entity.

image

Weapon Stats Component

In this context, the most important component is WeaponStatsComponent in source/core/src/main/com/deco2800/game/components/CombatItemsComponents, which is an abstract class that is extended by the StatComponent classes for different weapon types (eg: Melee, Ranged, AreaOfEffect).

Every weapon has at least three stats:

  1. damage - The damage of the weapon
  2. coolDown - The duration in milliseconds before the next attack instance can be called
  3. materials - The materials required to craft the weapon These variables have protected status, so that every sub-weapon can inherit them.

The StatComponent classes have getter and setter methods used to get and define the stats of the weapons based on the config .json files as stated above.

The image below shows the constructor for the base WeaponStatsComponent constructor and a getter method. image

Some extra getter and setter methods will be added to more specific StatComponents. Eg: setDuration() and getDuration() methods in AreaOfEffectStatsComponent

Aura Applier

In all of the StatComponentMethods, there is an auraEffect() that takes in an aura entity that acts as a buff, debuff or a curse to be applied to the weapon's stats. The method will have a timer that will revert the aura after a certain duration as specified by the aura applied. image

UML Diagram

image

Back to Combat Items Contents Page

Author

  • Eugene Chong
  • GitHub: @eugene2341
  • Discord: gene#0729
  • Slack: Eugene Chong
Clone this wiki locally