2019-05-06 16:07:06 -04:00
using System ;
2018-02-15 13:20:46 -06:00
using FFXIVClassic_Map_Server.actors.chara.ai ;
using FFXIVClassic_Map_Server.actors.chara.ai.utils ;
using FFXIVClassic_Map_Server.Actors ;
2016-08-22 10:43:04 -04:00
2019-05-06 16:07:06 -04:00
namespace FFXIVClassic_Map_Server.packets.send.actor.battle
2016-02-07 15:28:08 -05:00
{
2017-08-29 01:15:12 +01:00
//These flags can be stacked and mixed, but the client will prioritize certain flags over others.
[Flags]
public enum HitEffect : uint
2019-05-27 15:00:17 -07:00
{
//This is used for physical attacks
2017-08-28 23:21:21 -04:00
HitEffectType = 8 < < 24 ,
2019-05-27 15:00:17 -07:00
//This is used for additioanl effect hits. Only difference from HitEffectType is that it does not play audio.
AdditionalEffectType = 24 < < 24 ,
2018-02-15 13:20:46 -06:00
//Status effects use 32 << 24
StatusEffectType = 32 < < 24 ,
2019-05-27 15:00:17 -07:00
//When losing a status effect while using a skill, this prevents the hit effect from playing on the actor playing the animation
StatusLossType = 40 < < 24 ,
//Magic effects use 48 << 24, this is also used for when statuses are lost on attack
2018-02-15 13:20:46 -06:00
MagicEffectType = 48 < < 24 ,
2019-05-27 15:00:17 -07:00
//This places the number on the user regardless of the target this hit effect is for, used for things like bloodbath
SelfHealType = 72 < < 24 ,
2019-06-01 02:10:40 -07:00
//Plays the effect animation with no text or additional effects. Unsure if there are any flags. Used for things like Convert
AnimationEffectType = 96 < < 24 ,
2019-05-27 15:00:17 -07:00
//Each Type has it's own set of flags. These should be split into their own enums,
//but for now just keep them all under HitEffect so we don't have to change anything.
//HitEffectType flags
2017-08-28 23:21:21 -04:00
2017-08-29 01:15:12 +01:00
//Not setting RecoilLv2 or RecoilLv3 results in the weaker RecoilLv1.
//These are the recoil animations that play on the target, ranging from weak to strong.
//The recoil that gets set was likely based on the percentage of HP lost from the attack.
2018-04-18 16:06:41 -05:00
//These also have a visual effect with heals and spells but in reverse. RecoilLv1 has a large effect, Lv3 has none. Crit is very large
//For spells they represent resists. Lv0 is a max resist, Lv3 is no resist. Crit is still used for crits.
//Heals used the same effects sometimes but it isn't clear what for, it seems random? Possibly something like a trait proccing or even just a bug
2018-02-15 13:20:46 -06:00
RecoilLv1 = 0 ,
RecoilLv2 = 1 < < 0 ,
RecoilLv3 = 1 < < 1 ,
2017-08-29 01:15:12 +01:00
//Setting both recoil flags triggers the "Critical!" pop-up text and hit visual effect.
CriticalHit = RecoilLv2 | RecoilLv3 ,
//Hit visual and sound effects when connecting with the target.
//Mixing these flags together will yield different results.
//Each visual likely relates to a specific weapon.
//Ex: HitVisual4 flag alone appears to be the visual and sound effect for hand-to-hand attacks.
2018-02-15 13:20:46 -06:00
//HitVisual is probably based on attack property.
//HitVisual1 is for slashing attacks
//HitVisual2 is for piercing attacks
//HitVisual1 | Hitvisual2 is for blunt attacks
//HitVisual3 is for projectile attacks
//Basically take the attack property of a weapon and shift it left 2
//For auto attacks attack property is weapon's damageAttributeType1
//Still not totally sure how this works with weaponskills or what hitvisual4 or the other combinations are for
HitVisual1 = 1 < < 2 ,
HitVisual2 = 1 < < 3 ,
HitVisual3 = 1 < < 4 ,
HitVisual4 = 1 < < 5 ,
2017-08-29 01:15:12 +01:00
//An additional visual effect that plays on the target when attacked if:
//The attack is physical and they have the protect buff on.
//The attack is magical and they have the shell buff on.
//Special Note: Shell was removed in later versions of the game.
//Another effect plays when both Protect and Shell flags are activated.
//Not sure what this effect is.
//Random guess: if the attack was a hybrid of both physical and magical and the target had both Protect and Shell buffs applied.
2019-06-01 02:59:41 -07:00
Protect = 1 < < 6 ,
Shell = 1 < < 7 ,
2017-08-29 01:15:12 +01:00
ProtectShellSpecial = Protect | Shell ,
//If only HitEffect1 is set out of the hit effects, the "Evade!" pop-up text triggers along with the evade visual.
//If no hit effects are set, the "Miss!" pop-up is triggered and no hit visual is played.
2018-02-15 13:20:46 -06:00
HitEffect1 = 1 < < 9 ,
HitEffect2 = 1 < < 10 , //Plays the standard hit visual effect, but with no sound if used alone.
HitEffect3 = 1 < < 11 , //Yellow effect, crit?
HitEffect4 = 1 < < 12 , //Plays the blocking animation
HitEffect5 = 1 < < 13 ,
2017-08-29 01:15:12 +01:00
GustyHitEffect = HitEffect3 | HitEffect2 ,
GreenTintedHitEffect = HitEffect4 | HitEffect1 ,
2018-02-15 13:20:46 -06:00
//For specific animations
Miss = 0 ,
Evade = HitEffect1 ,
Hit = HitEffect1 | HitEffect2 ,
2018-04-18 16:06:41 -05:00
Crit = HitEffect3 ,
2018-02-15 13:20:46 -06:00
Parry = Hit | HitEffect3 ,
Block = HitEffect4 ,
2017-08-29 01:15:12 +01:00
//Knocks you back away from the attacker.
KnockbackLv1 = HitEffect4 | HitEffect2 | HitEffect1 ,
KnockbackLv2 = HitEffect4 | HitEffect3 ,
KnockbackLv3 = HitEffect4 | HitEffect3 | HitEffect1 ,
KnockbackLv4 = HitEffect4 | HitEffect3 | HitEffect2 ,
KnockbackLv5 = HitEffect4 | HitEffect3 | HitEffect2 | HitEffect1 ,
//Knocks you away from the attacker in a counter-clockwise direction.
KnockbackCounterClockwiseLv1 = HitEffect5 ,
KnockbackCounterClockwiseLv2 = HitEffect5 | HitEffect1 ,
//Knocks you away from the attacker in a clockwise direction.
KnockbackClockwiseLv1 = HitEffect5 | HitEffect2 ,
KnockbackClockwiseLv2 = HitEffect5 | HitEffect2 | HitEffect1 ,
//Completely drags target to the attacker, even across large distances.
DrawIn = HitEffect5 | HitEffect3 ,
//An additional visual effect that plays on the target based on according buff.
UnknownShieldEffect = HitEffect5 | HitEffect4 ,
Stoneskin = HitEffect5 | HitEffect4 | HitEffect1 ,
//A special effect when performing appropriate skill combos in succession.
//Ex: Thunder (SkillCombo1 Effect) -> Thundara (SkillCombo2 Effect) -> Thundaga (SkillCombo3 Effect)
//Special Note: SkillCombo4 was never actually used in 1.0 since combos only chained up to 3 times maximum.
2018-02-15 13:20:46 -06:00
SkillCombo1 = 1 < < 15 ,
SkillCombo2 = 1 < < 16 ,
2017-08-29 01:15:12 +01:00
SkillCombo3 = SkillCombo1 | SkillCombo2 ,
2019-05-27 15:00:17 -07:00
SkillCombo4 = 1 < < 17 ,
//This is used in the absorb effect for some reason
Unknown = 1 < < 19 ,
//AdditionalEffectType flags
//The AdditionalEffectType is used for the additional effects some weapons have.
//These effect ids do not repeat the effect of the attack and will not show without a preceding HitEffectType or MagicEffectType
//It's unclear what this is for. The ifrit fight capture has a BLM using the garuda weapon
//and this flag is set every time but has no apparent effect.
UnknownAdditionalFlag = 1 ,
//These play effects on the target
FireEffect = 1 < < 10 ,
IceEffect = 2 < < 10 ,
WindEffect = 3 < < 10 ,
EarthEffect = 4 < < 10 ,
LightningEffect = 5 < < 10 ,
WaterEffect = 6 < < 10 ,
AstralEffect = 7 < < 10 , //Possibly for blind?
UmbralEffect = 8 < < 10 , //Posibly for poison?
//Unknown status effect effects
StatusEffect1 = 12 < < 10 ,
StatusEffect2 = 13 < < 10 ,
HPAbsorbEffect = 14 < < 10 ,
MPAbsorbEffect = 15 < < 10 ,
TPAbsorbEffect = 16 < < 10 ,
TripleAbsorbEffect = 17 < < 10 , //Not sure about this
MoogleEffect = 18 < < 10 ,
//MagicEffectType Flags
//THese are used for magic effects that deal or heal damage as well as damage over time effects
//Crit is the same as HitEffectType
FullResist = 0 ,
WeakResist = 1 < < 0 , //Used for level 1, 2, and 3 resists probably
NoResist = 1 < < 1 ,
MagicShell = 1 < < 4 , //Used when casting on target with shell effects. MagicEffectType doesnt have a flag for protect or stoneskin
MagicShield = 1 < < 5 , //When used with an command that has an animation, this plays a purple shield effect. DoTs also have this flag set (at least on ifrit) but they have no animations so it doesnt show
2017-08-29 01:15:12 +01:00
2019-05-27 15:00:17 -07:00
// Required for heal text to be blue, not sure if that's all it's used for
Heal = 1 < < 8 ,
MP = 1 < < 9 , //Causes "MP" text to appear when used with MagicEffectType. | with Heal to make text blue
TP = 1 < < 10 , //Causes "TP" text to appear when used with MagicEffectType. | with Heal to make text blue
//SelfHealType flags
//This category causes numbers to appear on the user rather regardless of the target associated with the hit effect and do not play an animation
//These determine the text that displays (HP has no text)
SelfHealHP = 0 ,
SelfHealMP = 1 < < 0 , //Shows MP text on self. | with SelfHeal to make blue
SelfHealTP = 1 < < 1 , //Shows TP text on self. | with SelfHeal to make blue
//Causes self healing numbers to be blue
SelfHeal = 1 < < 10 ,
2017-08-29 01:15:12 +01:00
}
//Mixing some of these flags will cause the client to crash.
//Setting a flag higher than Left (0x10-0x80) will cause the client to crash.
[Flags]
public enum HitDirection : byte
{
None = 0 ,
Front = 1 < < 0 ,
Right = 1 < < 1 ,
Rear = 1 < < 2 ,
Left = 1 < < 3
}
2018-02-15 13:20:46 -06:00
public enum HitType : ushort
{
Miss = 0 ,
Evade = 1 ,
Parry = 2 ,
Block = 3 ,
2019-05-27 16:52:56 -07:00
SingleResist = 4 ,
DoubleResist = 5 ,
TripleResist = 6 ,
FullResist = 7 ,
Hit = 8 ,
Crit = 9
2018-02-15 13:20:46 -06:00
}
2018-04-18 16:06:41 -05:00
//Type of action
public enum ActionType : ushort
2018-02-15 13:20:46 -06:00
{
None = 0 ,
2018-04-18 16:06:41 -05:00
Physical = 1 ,
Magic = 2 ,
2018-02-15 13:20:46 -06:00
Heal = 3 ,
Status = 4
}
2018-04-18 16:06:41 -05:00
//There's are two columns in gamecommand that are for action property and action element respectively and both have percentages next to them
//the percentages are for what percent that property or element factors into the attack. Astral and Umbral are always 33% because they are both 3 elments combined
//ActionProperty and ActionElement are slightly different. Property defines whta type of attack it is, and 11-13 are used for "sonic, breath, neutral". Neutral is always used for magic
//For Element 11-13 are used for astral, umbral, and healing magic.
//Right now we aren't actually using these but when things like resists get better defined we'll have to
public enum ActionProperty : ushort
{
None = 0 ,
Slashing = 1 ,
Piercing = 2 ,
Blunt = 3 ,
Projectile = 4 ,
Fire = 5 ,
Ice = 6 ,
Wind = 7 ,
Earth = 8 ,
Lightning = 9 ,
Water = 10 ,
//These I'm not sure about. Check gameCommand.csv
Astral = 11 ,
Umbral = 12 ,
Heal = 13
}
/ *
public enum ActionProperty : ushort
{
None = 0 ,
Slashing = 1 ,
Piercing = 2 ,
Blunt = 3 ,
Projectile = 4 ,
Fire = 5 ,
Ice = 6 ,
Wind = 7 ,
Earth = 8 ,
Lightning = 9 ,
Water = 10 ,
Sonic = 11 ,
Breath = 12 ,
Neutral = 13 ,
Astral = 14 ,
Umbral = 15
}
public enum ActionElement : ushort
{
None = 0 ,
Slashing = 1 ,
Piercing = 2 ,
Blunt = 3 ,
Projectile = 4 ,
Fire = 5 ,
Ice = 6 ,
Wind = 7 ,
Earth = 8 ,
Lightning = 9 ,
Water = 10 ,
//These I'm not sure about. Check gameCommand.csv
Astral = 11 ,
Umbral = 12 ,
Heal = 13
} * /
2019-01-29 00:02:09 -05:00
class CommandResult
2016-02-07 15:28:08 -05:00
{
2016-06-15 00:08:05 +01:00
public uint targetId ;
2016-02-07 15:28:08 -05:00
public ushort amount ;
2018-04-18 16:06:41 -05:00
public ushort amountMitigated ; //Amount that got blocked/evaded or resisted
2018-02-15 13:20:46 -06:00
public ushort enmity ; //Seperate from amount for abilities that cause a different amount of enmity than damage
2016-02-07 15:28:08 -05:00
public ushort worldMasterTextId ;
2018-02-15 13:20:46 -06:00
public uint effectId ; //Impact effect, damage/heal/status numbers or name
public byte param ; //Which side the battle action is coming from
public byte hitNum ; //Which hit in a sequence of hits this is
2017-08-29 01:15:12 +01:00
/// <summary>
2018-04-18 16:06:41 -05:00
/// these fields are not actually part of the packet struct
2017-08-29 01:15:12 +01:00
/// </summary>
2017-08-30 00:14:14 +01:00
public uint animation ;
2018-04-18 16:06:41 -05:00
public CommandType commandType ; //What type of command was used (ie weaponskill, ability, etc)
public ActionProperty actionProperty ; //Damage type of the action
public ActionType actionType ; //Type of this action (ie physical, magic, heal)
public HitType hitType ;
2017-08-28 21:45:01 -04:00
2018-04-18 16:06:41 -05:00
//Rates, I'm not sure if these need to be stored like this but with the way some buffs work maybe they do?
//Makes things like Blindside easy at least.
public double parryRate = 0.0 ;
public double blockRate = 0.0 ;
public double resistRate = 0.0 ;
public double hitRate = 0.0 ;
public double critRate = 0.0 ;
2019-01-29 00:02:09 -05:00
public CommandResult ( uint targetId , ushort worldMasterTextId , uint effectId , ushort amount = 0 , byte param = 0 , byte hitNum = 1 )
2017-08-28 21:45:01 -04:00
{
2018-04-18 16:06:41 -05:00
this . targetId = targetId ;
2017-08-28 21:45:01 -04:00
this . worldMasterTextId = worldMasterTextId ;
this . effectId = effectId ;
this . amount = amount ;
this . param = param ;
2018-04-18 16:06:41 -05:00
this . hitNum = hitNum ;
2018-02-15 13:20:46 -06:00
this . hitType = HitType . Hit ;
this . enmity = amount ;
2018-04-18 16:06:41 -05:00
this . commandType = ( byte ) CommandType . None ;
2018-02-15 13:20:46 -06:00
}
2019-01-29 00:02:09 -05:00
public CommandResult ( uint targetId , BattleCommand command , byte param = 0 , byte hitNum = 1 )
2018-02-15 13:20:46 -06:00
{
2018-04-18 16:06:41 -05:00
this . targetId = targetId ;
this . worldMasterTextId = command . worldMasterTextId ;
this . param = param ;
this . hitNum = hitNum ;
this . commandType = command . commandType ;
this . actionProperty = command . actionProperty ;
this . actionType = command . actionType ;
2018-02-15 13:20:46 -06:00
}
2018-04-18 16:06:41 -05:00
//Order of what (probably) happens when a skill is used:
//Buffs that alter things like recast times or that only happen once per skill usage like Power Surge are activated
//Script calculates damage and handles any special requirements
//Rates are calculated
//Buffs that impact indiviudal hits like Blindside or Blood for Blood are activated
//The final hit type is determined
//Stoneskin takes damage
//Final damage amount is calculated using the hit type and defender's stats
//Buffs that activate or respond to damage like Rampage. Stoneskin gets removed AFTER damage if it falls off.
//Additional effects that are a part of the skill itself or weapon in case of auto attacks take place like status effects
//Certain buffs that alter the whole skill fall off (Resonance, Excruciate)
2019-01-29 00:02:09 -05:00
public void DoAction ( Character caster , Character target , BattleCommand skill , CommandResultContainer results )
2018-02-15 13:20:46 -06:00
{
2018-04-18 16:06:41 -05:00
//First calculate rates for hit/block/etc
CalcRates ( caster , target , skill ) ;
//Next, modify those rates based on preaction buffs
//Still not sure how we shouldh andle these
2019-01-29 00:02:09 -05:00
PreAction ( caster , target , skill , results ) ;
2018-04-18 16:06:41 -05:00
2019-01-29 00:02:09 -05:00
BattleUtils . DoAction ( caster , target , skill , this , results ) ;
2018-02-15 13:20:46 -06:00
}
2018-04-18 16:06:41 -05:00
//Calculate the chance of hitting/critting/etc
public void CalcRates ( Character caster , Character target , BattleCommand skill )
2018-02-15 13:20:46 -06:00
{
2018-04-18 16:06:41 -05:00
hitRate = BattleUtils . GetHitRate ( caster , target , skill , this ) ;
critRate = BattleUtils . GetCritRate ( caster , target , skill , this ) ;
blockRate = BattleUtils . GetBlockRate ( caster , target , skill , this ) ;
parryRate = BattleUtils . GetParryRate ( caster , target , skill , this ) ;
resistRate = BattleUtils . GetResistRate ( caster , target , skill , this ) ;
}
//These are buffs that activate before the action hits. Usually they change things like hit or crit rates or damage
2019-01-29 00:02:09 -05:00
public void PreAction ( Character caster , Character target , BattleCommand skill , CommandResultContainer results )
2018-04-18 16:06:41 -05:00
{
2019-01-29 00:02:09 -05:00
target . statusEffects . CallLuaFunctionByFlag ( ( uint ) StatusEffectFlags . ActivateOnPreactionTarget , "onPreAction" , caster , target , skill , this , results ) ;
2018-04-18 16:06:41 -05:00
2019-01-29 00:02:09 -05:00
caster . statusEffects . CallLuaFunctionByFlag ( ( uint ) StatusEffectFlags . ActivateOnPreactionCaster , "onPreAction" , caster , target , skill , this , results ) ;
2018-02-15 13:20:46 -06:00
}
2018-04-18 16:06:41 -05:00
//Try and apply a status effect
2019-01-29 00:02:09 -05:00
public void TryStatus ( Character caster , Character target , BattleCommand skill , CommandResultContainer results , bool isAdditional = true )
2018-02-15 13:20:46 -06:00
{
2019-01-29 00:02:09 -05:00
BattleUtils . TryStatus ( caster , target , skill , this , results , isAdditional ) ;
2018-02-15 13:20:46 -06:00
}
2018-04-18 16:06:41 -05:00
public ushort GetHitType ( )
2018-02-15 13:20:46 -06:00
{
2018-04-18 16:06:41 -05:00
return ( ushort ) hitType ;
2017-08-28 21:45:01 -04:00
}
2019-05-27 16:52:56 -07:00
2019-05-29 19:11:32 -07:00
public void SetTextId ( ushort id )
{
worldMasterTextId = id ;
}
2019-05-27 16:52:56 -07:00
//Whether this action didn't miss, and wasn't evaded or resisted
public bool ActionLanded ( )
{
return hitType > HitType . Evade & & hitType ! = HitType . SingleResist & & hitType ! = HitType . DoubleResist & & hitType ! = HitType . FullResist ;
}
2016-02-07 15:28:08 -05:00
}
}