Damage Type - MSUTeam/MSU GitHub Wiki
MSU adds a robust and flexible DamageType
system for skills. The purpose of this system is to allow skills to deal a variety of damage types and to streamline the injuries system. This system also eliminates the need to use this.m.InjuriesOnBody
and this.m.InjuriesOnHead
in skills. Only the DamageType
needs to be defined.
Each skill now has a parameter called this.m.DamageType
which can be set during the skill’s create()
function. This parameter is a class that inherits from weighted container and contains damage types as its elements.
When attacking a target, the skill pulls a weighted random DamageType
from its this.m.DamageType
. The rolled damage type is then passed to the _hitInfo
during onBeforeTargetHit
. The type of injuries the skill can inflict is also determined at this point based on what type of damage it rolled, and which part of the body is going to be hit. The skill’s rolled damage type’s Probability is also passed to _hitInfo
. This allows the target to access this information and receive different effects depending on how much weight of that DamageType
the skill has.
MSU also adds the damage types of a skill to the skill’s tooltip automatically including their relative probabilities. This info is hidden by default but can be enabled by enabling the "ExpandedSkillDescriptions" setting of the MSU mod.
For vanilla skills, and skills from mods, which do not have a DamageType
defined, MSU calculates and assigns them a DamageType based on their InjuriesOnBody
field. For skills with mixed injury types e.g. PiercingAndCuttingBody
the weights of the two damage types is calculated based on the overall ratio of the two injury types in both their Head and Body variants. Therefore, for such skills only the vanilla injury type arrays are supported for the automatic calculation.
![img-damage-type](https://user-images.githubusercontent.com/55047920/163660213-c5d290d2-8246-480b-803b-3c6deb91231d.jpg)
Damage types are contained in a new table created by MSU: ::Const.Damage.DamageType
. By default the following damage types are defined which correspond to the kinds of injuries attacks can inflict in vanilla BB:
- Cutting
- Piercing
- Blunt
- Burning
::Const.Damage.addNewDamageType( _damageType, _injuriesOnHead, _injuriesOnBody, _damageTypeName = "" )
// _damageType is a string
// /injuriesOnHead is an array
// _injuriesOnBody is an array
// _damageTypeName is a string
_damageType
is a string which will become a key in ::Const.Damage.DamageType
. _injuriesOnHead
and _injuriesOnBody
are arrays of strings where each entry is an ID of an injury skill. _damageTypeName
is a string which can be used as the name of this damage type in tooltips; if not provided then _damageType
is used as the name in tooltips.
::Const.Damage.getDamageTypeName( _damageType )
// _damageType is a key in ::Const.Damage.DamageType
Returns the name of the damage type as string. Throws the MSU KeyNotFound exception if _damageType
does not exist.
::Const.Damage.getDamageTypeInjuries( _damageType )
// _damageType is a key in ::Const.Damage.DamageType
Returns a table { Head = [], Body = [] }
where Head and Body are arrays of tables with each table having the following keys: ID
, Threshold
, Script
for the injury skills that this damage type can apply on the respective body part. For examples of how such tables are constructed see the character_injuries.nut
file in vanilla.
Note: The returned table is a back-end table that MSU uses for this damage type's injuries (as it is passed by reference) and any changes made to the returned table or its arrays will change the back-end table. If you want to avoid changing this table, use the getApplicableInjuries function instead which returns a new array.
::Const.Damage.setDamageTypeInjuries( _damageType, _injuriesOnHead, _injuriesOnBody )
// _damageType is a key in ::Const.Damage.DamageType
// /injuriesOnHead is an array
// _injuriesOnBody is an array
_injuriesOnHead
and _injuriesOnBody
are arrays of tables as their entries with each table having the following keys: ID
, Threshold
, Script
for the injury skills that this damage type can apply. For examples of how such tables are constructed see the character_injuries.nut
file in vanilla.
::Const.Damage.getApplicableInjuries( _damageType, _bodyPart, _targetEntity = null )
// _damageType is a key in ::Const.Damage.DamageType
// _bodyPart is a key in ::Const.BodyPart
// _targetEntity is a BB object
_bodyPart
is the body part hit. _targetEntity
is the entity being attacked which, if not null, removes the ExcludedInjuries of the _targetEntity
from the returned array. Returns an array which contains tables as its entries with each table having the following keys: ID
, Threshold
, Script
for the injury skills that this damage type can apply in the given situation. For examples of how such tables are constructed see the character_injuries.nut
file in vanilla.
<skill>.getDamageType()
Returns the this.m.DamageType
container of the skill which is a class that inherits from weighted container.
As the this.m.DamageType
of a skill is a child of weighted container, all the functions of the weighted container class can be used to work with it. For example:
<skill>.getDamageType().contains( _damageType )
<skill>.getDamageType().add( _damageType, _weight )
<skill>.getDamageType().remove( _damageType )
<skill>.getDamageType().getWeight( _damageType )
<skill>.getDamageType().setWeight( _damageType, _weight )
<skill>.getDamageType().getProbability( _damageType )
<skill>.getDamageType().roll()
// and so on
MSU adds the following two slots to the ::Const.Tactical.HitInfo
table:
DamageType
DamageTypeProbability
When a skill is used to attack a target, the damage type of the skill is rolled. The rolled DamageType
and its DamageTypeProbability
are added to the _hitinfo
. These parameters can then be accessed by all skills which have access to the _hitInfo
.
For example, if a skill should only do something when the attacker attacked with Cutting damage using a skill which has more than 50% probability for cutting damage.
function onBeforeTargetHit( _skill, _targetEntity, _hitInfo )
{
if (_hitInfo.DamageType == ::Const.Damage.DamageType.Cutting && _hitInfo.DamageTypeProbability > 0.5)
{
// Do stuff
}
}