🌱
The Insurgent's Forge
  • Home
  • Getting Started
    • Setup
    • Resources
  • Overview
    • Configuration
      • Formulas
      • Functions
      • Classes
      • Helpers
      • Assemblies
      • Middlewares
      • Dependencies
      • Options
      • Errors
    • Improvements & Additions
    • Structures & Parameters
    • Formula Workflow
      • Combo
      • Counter
      • Area of Effect
      • Reserve Party Member
      • Reflect
      • Mist
      • Trap
      • Chain Benefit
      • Summon
      • Spawn
      • Gambit
    • Limitations
      • Animations
      • Status Effects & Augments
    • Notes
      • Flags
      • Loops
      • Function in a Function
    • Helpers
      • Add Augment
      • Add Status Effect
      • Apply Knockback
      • Get Active Party Member
      • Get Action Status Effects
      • Get Augment Duration
      • Get Battle Unit Keep
      • Get Battle Unit Keep By Focus
      • Get Battle Unit Work
      • Get Character Max Hp
      • Get Character Max Mp
      • Get Character Type
      • Get Elemental Affinities Match
      • Get Equipment Status Effects
      • Get Forced Poach Rarity
      • Get Forced Steal Rarity
      • Get Formula Proc Keep
      • Get Knockback Range
      • Get Location Mist Strength
      • Get Model Evade Types
      • Get One Hit Kill State
      • Get Random Number
      • Get Reflect Target
      • Get Remedy Status Effects
      • Get Status Effect Duration
      • Get Status Effect Tick Duration
      • Get Status Effects Match
      • Get Terrain Type
      • Get Weather
      • Is Interactable
      • Modify Content
      • Modify Gil
      • Modify Hp
      • Modify Mist Charges
      • Modify Mp
      • Modify Sky Pirates Den Stats
      • Refresh Stats
      • Remove Augment
      • Remove Status Effect
      • Set Level
      • Shift Elements
      • Show Combat Log
      • Show Number Text
      • Teleport Location
  • Support & Updates
    • Changelogs
      • Version 1.0.3
      • Version 1.0.2
      • Version 1.0.1
      • Version 1.0.0
    • Known Issues
    • FAQ
Powered by GitBook
On this page
  • Description
  • Layout
  • Usage
  • Expansion
  1. Overview
  2. Configuration

Classes

Description

Classes are metatables that simulate object oriented programming to help with creating easily readable and maintainable code in formula functions.

Every class is defined in a separate file, has a unique name, and is located in the classes directory.

The classes.lua file contains a list of all classes and in which order they will be loaded (higher first). The latter is important in cases where one requires another.

Layout

classes/getBattleUnitWork.lua
local function getBattleUnitWork(address)
  --your code
end

return getBattleUnitWork
classes.lua
local classes = {
  --more classes
  "getBattleUnitWork"
}

return classes

The former file returns a function that builds a metatable.

The latter file returns a table with every class. The value of a table entry equals the filename of the class (e.g. getBattleUnitWork).

Usage

Let's say you wanted to create a formula function that doubles the damage the target receives if the caster catches them by surprise. Now, one way to do this would be to check whether the target is in a battle stance and if not, double the damage.

This is how the code would look without classes (partially):

local function func(formula, caster, target, functions, classes, helpers)
  local battleFlags = memory.u32[formula.target.battleUnitWork.address + 0x00]
  local isInBattleStance = battleFlags >> 23 & 0x01

  if isInBattleStance == 1 then
    formula.target.removedHp = formula.target.removedHp * 2
  end
end

return func

and this with classes:

local function func(formula, caster, target, functions, classes, helpers)
  if formula.target.battleUnitWork.battleFlags.isInBattleStance == 1 then
    formula.target.removedHp = formula.target.removedHp * 2
  end
end

return func

As you can see, if you do not use classes, you will have to manually get value of the battle stance flag via the base address and the battle flags offset (which is 0x00 in this case).

On the other hand, with classes, you can simply access that property of the structure directly. Not to mention that you won't have to remember or look up the address or offsets of hundreds of properties every time you use them.

In the background, the work required to get the result is of course still the same. You just have to write less to get what you want.

This is extremely helpful, even when working on basic tasks such as setting the caster's hp, level, etc. for some calculation. Without classes, you would have to constantly manually read from and write to memory.

Expansion

You can modify existing classes created by me and add entirely new ones if you want. However, this is more on the advanced side of modding, so unless you really know what you are doing, I would avoid messing with it. In almost all cases, I will have already provided all necessary properties for a class. The option is just there in case you really want to create your own.

PreviousFunctionsNextHelpers

Last updated 1 year ago