Skip to content

Companion Weapon Component

Maxwell Schroder edited this page Oct 5, 2023 · 3 revisions

Companion Weapon Component

Introduction

The Companion Weapon Component is an integral part of a game engine designed for handling the control of companion weapons within a game world. This component enables companions to interact with game entities through various weapon types. This documentation will provide a detailed explanation of the 'CompanionWeaponComponent' and its related classes, methods, and usage.

The 'CompanionWeaponComponent' is a critical element of a game engine designed to facilitate the control of companion weapons. These weapons can be equipped by in-game companions and used to attack game entities. This component works in conjunction with other game systems to provide a seamless and engaging gaming experience.

Class Structure

The CompanionWeaponComponent is the main class responsible for managing companion weapons. It holds a reference to the currently equipped weapon and provides methods for attacking with weapons and switching between different weapon types.

CompanionWeaponComponent: The primary class that manages companion weapons.

CurrentWeapon: A reference to the currently equipped weapon.

image image

Usage

  1. Create an instance of CompanionWeaponComponent.
  2. Call its create() method to set up listeners on key binds and initialize the component.
  3. Utilize the component to trigger attacks and weapon changes in response to game events and user input.

Here's an example of how to use the component:

CompanionWeaponComponent weaponComponent = new CompanionWeaponComponent(); weaponComponent.create();

Methods

1.create()

Description: Sets up listeners on key binds and initializes the component.

Example:

weaponComponent.create();

  1. companionAttacking(weaponType, clickPosition)

Description:

Handles companion attacks with the specified weapon type and target position.

Parameters:

weaponType (CompanionWeaponType): The type of weapon to use. clickPosition (Vector2): The position where the companion is attacking.

Example:

weaponComponent.companionAttacking(CompanionWeaponType.Death_Potion, targetPosition);

  1. updateHolding(weaponType)

Description:

Updates the currently equipped weapon based on the given weapon type.

Parameters:

weaponType (CompanionWeaponType): The type of weapon to equip.

Example:

weaponComponent.updateHolding(CompanionWeaponType.Death_Potion);

  1. calcRotationAngleInDegrees(centerPt, targetPt)

Description:

Calculates the rotation angle in degrees between two points.

Parameters:

centerPt (Vector2): The center point from which to calculate the angle. targetPt (Vector2): The target point to which the angle is calculated. Returns: The rotation angle in degrees.

Example:

float angle = weaponComponent.calcRotationAngleInDegrees(centerPoint, targetPoint);

CompanionWeaponController

Description:

A related class that determines the target of the companion's weapon attack. It is responsible for tracking and selecting valid targets for different weapon types.

CompanionWeaponType

**Description: **

An enumeration representing different companion weapon types. It includes Death_Potion as an example.

Companion Weapon Configurations

Description:

This section can detail the various weapon configurations available, including their properties and attributes. For example, the Death_Potion .

CompanionWeaponFactory

**Description: **

CompanionWeaponFactory is a factory class responsible for creating companion weapons with various weapon types. It takes a CompanionWeaponType and a companion entity as input and produces a weapon entity based on the specified weapon type and its associated configuration.

CompanionAttackFactory

Description:

** CompanionAttackFactory** is a factory class responsible for creating companion attacks with various weapon types. It uses configurations loaded from a JSON file to create companion attack entities. The code also handles setting up animations, adjusting attack parameters, and handling different weapon types, including a specific case for the "Death_Potion" weapon.

Classes:

CompanionWeaponComponent: Manages companion weapons and their creation.

CompanionWeaponController: Controls the behavior of companion weapons, including movement.

CompanionWeaponTargetComponent: Determines the target for companion weapons.

CompanionWeaponType (Enum): Represents different companion weapon types.

CompanionWeaponConfig: Stores configuration data for companion weapons.

CompanionWeaponConfigs: Stores configurations for multiple companion weapons.

CompanionAttackFactory: Creates companion attack entities.

Associations:

CompanionWeaponComponent uses CompanionAttackFactory to create companion attacks.

CompanionWeaponComponent uses CompanionWeaponFactory to create companion weapons.

CompanionWeaponComponent uses CompanionInventoryComponent to manage companion weapon inventory.

CompanionWeaponComponent uses events to listen for weapon-related actions.

CompanionWeaponController is a component attached to companion weapon entities.

CompanionWeaponTargetComponent is a component attached to companion weapon entities.

CompanionWeaponConfig stores configuration data for companion weapons.

CompanionWeaponConfigs stores multiple CompanionWeaponConfig instances.

CompanionWeaponConfigs provides weapon configurations based on weapon type.

CompanionAttackFactory creates companion attack entities based on configurations.

Clone this wiki locally