Refactor StatusEffectContainer to better handle messages using

CommandResultContainer.

Alter Modifiers to be the same as ParamNames.

Add LoseOnClassChange flag for status effects.

Add a few missing status effects.

Fix EndTime for stance status effects to stop icon from blinking.
This commit is contained in:
Yogurt
2019-05-27 23:05:20 -07:00
parent cc07e1f453
commit 26ef649a6c
17 changed files with 586 additions and 381 deletions

View File

@@ -109,55 +109,44 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
return effects.ContainsKey((uint)id);
}
public CommandResult AddStatusForCommandResult(uint id, byte tier = 1, ulong magnitude = 0, uint duration = 0)
{
CommandResult action = null;
if (AddStatusEffect(id, tier, magnitude, duration))
action = new CommandResult(owner.actorId, 30328, id | (uint)HitEffect.StatusEffectType);
return action;
}
public bool AddStatusEffect(uint id)
public bool AddStatusEffect(uint id, CommandResultContainer actionContainer = null, ushort worldmasterTextId = 30328)
{
var se = Server.GetWorldManager().GetStatusEffect(id);
return AddStatusEffect(se, owner);
return AddStatusEffect(se, owner, actionContainer, worldmasterTextId);
}
public bool AddStatusEffect(uint id, byte tier)
public bool AddStatusEffect(uint id, byte tier, CommandResultContainer actionContainer = null, ushort worldmasterTextId = 30328)
{
var se = Server.GetWorldManager().GetStatusEffect(id);
se.SetTier(tier);
return AddStatusEffect(se, owner);
return AddStatusEffect(se, owner, actionContainer, worldmasterTextId);
}
public bool AddStatusEffect(uint id, byte tier, double magnitude)
public bool AddStatusEffect(uint id, byte tier, double magnitude, CommandResultContainer actionContainer = null, ushort worldmasterTextId = 30328)
{
var se = Server.GetWorldManager().GetStatusEffect(id);
se.SetMagnitude(magnitude);
se.SetTier(tier);
return AddStatusEffect(se, owner);
return AddStatusEffect(se, owner, actionContainer, worldmasterTextId);
}
public bool AddStatusEffect(uint id, byte tier, double magnitude, uint duration, int tickMs = 3000)
public bool AddStatusEffect(uint id, byte tier, double magnitude, uint duration, int tickMs, CommandResultContainer actionContainer = null, ushort worldmasterTextId = 30328)
{
var se = Server.GetWorldManager().GetStatusEffect(id);
if (se != null)
{
se.SetDuration(duration);
se.SetStartTime(DateTime.Now);
se.SetOwner(owner);
}
return AddStatusEffect(se ?? new StatusEffect(this.owner, id, magnitude, 3000, duration, tier), owner);
return AddStatusEffect(se ?? new StatusEffect(this.owner, id, magnitude, 3000, duration, tier), owner, actionContainer, worldmasterTextId);
}
public bool AddStatusEffect(StatusEffect newEffect, Character source, bool silent = false, bool hidden = false)
public bool AddStatusEffect(StatusEffect newEffect, Character source, CommandResultContainer actionContainer = null, ushort worldmasterTextId = 30328)
{
/*
worldMasterTextId
@@ -179,9 +168,10 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
if (canOverwrite || effect == null)
{
// send packet to client with effect added message
if (effect != null && (!silent || !effect.GetSilent() || (effect.GetFlags() & (uint)StatusEffectFlags.Silent) == 0))
if (newEffect != null && !newEffect.GetSilentOnGain())
{
// todo: send packet to client with effect added message
if (actionContainer != null)
actionContainer.AddAction(new CommandResult(owner.actorId, worldmasterTextId, newEffect.GetStatusEffectId() | (uint)HitEffect.StatusEffectType));
}
// wont send a message about losing effect here
@@ -194,13 +184,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
if (effects.Count < MAX_EFFECTS)
{
if(newEffect.script != null)
newEffect.CallLuaFunction(this.owner, "onGain", this.owner, newEffect);
else
LuaEngine.CallLuaStatusEffectFunction(this.owner, newEffect, "onGain", this.owner, newEffect);
newEffect.CallLuaFunction(this.owner, "onGain", this.owner, newEffect, actionContainer);
effects.Add(newEffect.GetStatusEffectId(), newEffect);
//newEffect.SetSilent(silent);
newEffect.SetHidden(hidden);
if (!newEffect.GetHidden())
{
@@ -225,15 +211,19 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
return false;
}
public bool RemoveStatusEffect(StatusEffect effect, bool silent = false)
//playEffect determines whether the effect of the animation that's going to play with actionContainer is going to play on owner
//Generally, for abilities removing an effect, this is true and for effects removing themselves it's false.
public bool RemoveStatusEffect(StatusEffect effect, CommandResultContainer actionContainer = null, ushort worldmasterTextId = 30331, bool playEffect = true)
{
bool removedEffect = false;
if (effect != null && effects.ContainsKey(effect.GetStatusEffectId()))
{
// send packet to client with effect remove message
if (!silent && !effect.GetSilent() && (effect.GetFlags() & (uint)StatusEffectFlags.Silent) == 0)
if (!effect.GetSilentOnLoss())
{
owner.DoBattleAction(0, 0, new CommandResult(owner.actorId, 30331, effect.GetStatusEffectId()));
//Only send a message if we're using an actioncontainer and the effect normally sends a message when it's lost
if (actionContainer != null)
actionContainer.AddAction(new CommandResult(owner.actorId, worldmasterTextId, effect.GetStatusEffectId() | (playEffect ? 0 : (uint)HitEffect.StatusLossType)));
}
//hidden effects not in charawork
@@ -243,54 +233,20 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
SetStatusAtIndex(index, 0);
SetTimeAtIndex(index, 0);
}
// function onLose(actor, effect)
effects.Remove(effect.GetStatusEffectId());
if(effect.script != null)
effect.CallLuaFunction(owner, "onLose", owner, effect);
else
LuaEngine.CallLuaStatusEffectFunction(this.owner, effect, "onLose", this.owner, effect);
effect.CallLuaFunction(owner, "onLose", owner, effect, actionContainer);
owner.RecalculateStats();
sendUpdate = true;
removedEffect = true;
}
return removedEffect;
}
public bool RemoveStatusEffect(uint effectId, bool silent = false)
public bool RemoveStatusEffect(uint effectId, CommandResultContainer resultContainer = null, ushort worldmasterTextId = 30331, bool playEffect = true)
{
bool removedEffect = false;
foreach (var effect in effects.Values)
{
if (effect.GetStatusEffectId() == effectId)
{
RemoveStatusEffect(effect, effect.GetSilent() || silent);
removedEffect = true;
break;
}
}
return removedEffect;
}
//Remove status effect and return the CommandResult message instead of sending it immediately
public CommandResult RemoveStatusEffectForCommandResult(uint effectId, ushort worldMasterTextId = 30331)
{
CommandResult action = null;
if (RemoveStatusEffect(effectId, true))
action = new CommandResult(owner.actorId, worldMasterTextId, effectId);
return action;
}
//Remove status effect and return the CommandResult message instead of sending it immediately
public CommandResult RemoveStatusEffectForCommandResult(StatusEffect effect, ushort worldMasterTextId = 30331)
{
CommandResult action = null;
if (RemoveStatusEffect(effect, true))
action = new CommandResult(owner.actorId, worldMasterTextId, effect.GetStatusEffectId());
return action;
return RemoveStatusEffect(GetStatusEffectById(effectId), resultContainer, worldmasterTextId, playEffect);
}
public StatusEffect CopyEffect(StatusEffect effect)
@@ -301,14 +257,14 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
return AddStatusEffect(newEffect, effect.GetSource()) ? newEffect : null;
}
public bool RemoveStatusEffectsByFlags(uint flags, bool silent = false)
public bool RemoveStatusEffectsByFlags(uint flags, CommandResultContainer resultContainer = null)
{
// build list of effects to remove
var removeEffects = GetStatusEffectsByFlag(flags);
// remove effects from main list
foreach (var effect in removeEffects)
RemoveStatusEffect(effect, silent);
RemoveStatusEffect(effect, resultContainer, effect.GetStatusLossTextId(), true);
// removed an effect with one of these flags
return removeEffects.Count > 0;
@@ -334,6 +290,16 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
return list;
}
public StatusEffect GetRandomEffectByFlag(uint flag)
{
var list = GetStatusEffectsByFlag(flag);
if (list.Count > 0)
return list[Program.Random.Next(list.Count)];
return null;
}
// todo: why the fuck cant c# convert enums/
public bool HasStatusEffectsByFlag(StatusEffectFlags flags)
{
@@ -442,7 +408,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
SetStatusAtIndex(index, (ushort) (newEffectId - 200000));
SetTimeAtIndex(index, time);
return new CommandResult(owner.actorId, 30328, (uint) HitEffect.StatusEffectType | newEffectId);
return new CommandResult(owner.actorId, 30330, (uint) HitEffect.StatusEffectType | newEffectId);
}
}
}