Refactored Demo's battle action code and cleaned things up.

This commit is contained in:
Filip Maj 2017-08-28 21:45:01 -04:00
parent 71d5bbc9ff
commit 7ad40f625a
14 changed files with 217 additions and 122 deletions

View File

@ -433,7 +433,9 @@ namespace FFXIVClassic_Map_Server.Actors
if ((updateFlags & ActorUpdateFlags.State) != 0) if ((updateFlags & ActorUpdateFlags.State) != 0)
{ {
packets.Add(SetActorStatePacket.BuildPacket(actorId, currentMainState, currentSubState)); packets.Add(SetActorStatePacket.BuildPacket(actorId, currentMainState, currentSubState));
packets.Add(BattleActionX01Packet.BuildPacket(actorId, actorId, actorId, 0x72000062, 1, 0, 0x05209, 0, 0));
if (this is Character)
packets.Add(BattleActionX00Packet.BuildPacket(actorId, 0x72000062, 0));
} }
updateFlags = ActorUpdateFlags.None; updateFlags = ActorUpdateFlags.None;
zone.BroadcastPacketsAroundActor(this, packets); zone.BroadcastPacketsAroundActor(this, packets);
@ -710,13 +712,6 @@ namespace FFXIVClassic_Map_Server.Actors
} }
#endregion #endregion
public SubPacket CreateGameMessagePacket(Actor textIdOwner, ushort textId, byte log, params object[] msgParams)
{
if (msgParams == null || msgParams.Length == 0)
return (GameMessagePacket.BuildPacket(Server.GetWorldManager().GetActor().actorId, textIdOwner.actorId, textId, log));
else
return (GameMessagePacket.BuildPacket(Server.GetWorldManager().GetActor().actorId, textIdOwner.actorId, textId, log, LuaUtils.CreateLuaParamList(msgParams)));
}
} }
} }

View File

@ -179,9 +179,35 @@ namespace FFXIVClassic_Map_Server.Actors
zone.BroadcastPacketAroundActor(this, PlayAnimationOnActorPacket.BuildPacket(actorId, animId)); zone.BroadcastPacketAroundActor(this, PlayAnimationOnActorPacket.BuildPacket(actorId, animId));
} }
public void DoBattleAction(ushort commandId, uint animationId, uint target) public void DoBattleAction(ushort commandId, uint animationId)
{ {
zone.BroadcastPacketAroundActor(this, BattleActionX00Packet.BuildPacket(actorId, target, animationId, commandId)); zone.BroadcastPacketAroundActor(this, BattleActionX00Packet.BuildPacket(actorId, animationId, commandId));
}
public void DoBattleAction(ushort commandId, uint animationId, BattleAction action)
{
zone.BroadcastPacketAroundActor(this, BattleActionX01Packet.BuildPacket(actorId, animationId, commandId, action));
}
public void DoBattleAction(ushort commandId, uint animationId, BattleAction[] actions)
{
int currentIndex = 0;
while (true)
{
if (actions.Length - currentIndex >= 18)
BattleActionX18Packet.BuildPacket(actorId, animationId, commandId, actions, ref currentIndex);
else if (actions.Length - currentIndex >= 1)
BattleActionX10Packet.BuildPacket(actorId, animationId, commandId, actions, ref currentIndex);
else if (actions.Length - currentIndex == 1)
{
BattleActionX01Packet.BuildPacket(actorId, animationId, commandId, actions[currentIndex]);
currentIndex++;
}
else
break;
animationId = 0; //If more than one packet is sent out, only send the animation once to avoid double playing.
}
} }
public void DoBattleAction(ushort commandId, uint animationId, List<BattleAction> actions) public void DoBattleAction(ushort commandId, uint animationId, List<BattleAction> actions)
@ -284,7 +310,7 @@ namespace FFXIVClassic_Map_Server.Actors
} }
} }
public virtual bool IsValidTarget(Character target, ValidTarget validTarget, ref SubPacket errorPacket) public virtual bool IsValidTarget(Character target, ValidTarget validTarget)
{ {
return true; return true;
} }
@ -294,17 +320,17 @@ namespace FFXIVClassic_Map_Server.Actors
return true; return true;
} }
public virtual bool CanCast(Character target, BattleCommand spell, ref SubPacket errorPacket) public virtual bool CanCast(Character target, BattleCommand spell)
{ {
return false; return false;
} }
public virtual bool CanWeaponSkill(Character target, BattleCommand skill, ref SubPacket errorPacket) public virtual bool CanWeaponSkill(Character target, BattleCommand skill)
{ {
return false; return false;
} }
public virtual bool CanUseAbility(Character target, BattleCommand ability, ref SubPacket errorPacket) public virtual bool CanUseAbility(Character target, BattleCommand ability)
{ {
return false; return false;
} }
@ -500,14 +526,14 @@ namespace FFXIVClassic_Map_Server.Actors
return moveSpeeds[2] + GetMod((uint)Modifier.Speed); return moveSpeeds[2] + GetMod((uint)Modifier.Speed);
} }
public virtual void OnAttack(State state, BattleAction action, ref SubPacket errorPacket) public virtual void OnAttack(State state, BattleAction action, ref BattleAction error)
{ {
// todo: change animation based on equipped weapon // todo: change animation based on equipped weapon
action.effectId |= (uint)HitEffect.HitVisual1; // melee action.effectId |= (uint)HitEffect.HitVisual1; // melee
var target = state.GetTarget(); var target = state.GetTarget();
// todo: get hitrate and shit, handle protect effect and whatever // todo: get hitrate and shit, handle protect effect and whatever
if (BattleUtils.TryAttack(this, target, action, ref errorPacket)) if (BattleUtils.TryAttack(this, target, action, ref error))
{ {
action.amount = BattleUtils.CalculateAttackDamage(this, target, action); action.amount = BattleUtils.CalculateAttackDamage(this, target, action);
//var packet = BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, target.actorId, (uint)0x19001000, (uint)0x8000604, (ushort)0x765D, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, (byte)0x1); //var packet = BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, target.actorId, (uint)0x19001000, (uint)0x8000604, (ushort)0x765D, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, (byte)0x1);

View File

@ -97,7 +97,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
return castTimeSeconds == 0; return castTimeSeconds == 0;
} }
public bool IsValidTarget(Character user, Character target, ref SubPacket errorPacket) public bool IsValidTarget(Character user, Character target)
{ {
// todo: set box length.. // todo: set box length..
targetFind = new TargetFind(user); targetFind = new TargetFind(user);
@ -129,18 +129,21 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
if ((validTarget & (ValidTarget.Corpse | ValidTarget.CorpseOnly)) == 0 && target.IsDead()) if ((validTarget & (ValidTarget.Corpse | ValidTarget.CorpseOnly)) == 0 && target.IsDead())
{ {
// cannot be perfomed on // cannot be perfomed on
errorPacket = user.CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32512, 0x20, (uint)id); if (user is Player)
((Player)user).SendGameMessage(Server.GetWorldManager().GetActor(), 32512, 0x20, (uint)id);
return false; return false;
} }
if (level > user.charaWork.parameterSave.state_mainSkillLevel) if (level > user.charaWork.parameterSave.state_mainSkillLevel)
{ {
errorPacket = user.CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32527, 0x20, (uint)id); if (user is Player)
((Player)user).SendGameMessage(Server.GetWorldManager().GetActor(), 32527, 0x20, (uint)id);
return false; return false;
} }
if (tpCost > user.GetTP()) if (tpCost > user.GetTP())
{ {
errorPacket = user.CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32546, 0x20, (uint)id); if (user is Player)
((Player)user).SendGameMessage(Server.GetWorldManager().GetActor(), 32546, 0x20, (uint)id);
return false; return false;
} }
@ -149,7 +152,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
if (BattleUtils.CalculateSpellCost(user, target, this) > user.GetMP()) if (BattleUtils.CalculateSpellCost(user, target, this) > user.GetMP())
{ {
// todo: error message // todo: error message
errorPacket = user.CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32545, 0x20, (uint)id); if (user is Player)
((Player)user).SendGameMessage(Server.GetWorldManager().GetActor(), 32545, 0x20, (uint)id);
return false; return false;
} }
@ -159,7 +163,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
if (false) if (false)
{ {
// Unable to execute [@SHEET(xtx/command,$E8(1),2)]. Conditions for use are not met. // Unable to execute [@SHEET(xtx/command,$E8(1),2)]. Conditions for use are not met.
errorPacket = user.CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32556, 0x20, (uint)id); if (user is Player)
((Player)user).SendGameMessage(Server.GetWorldManager().GetActor(), 32556, 0x20, (uint)id);
return false; return false;
} }
} }
@ -169,7 +174,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{ {
if (target != null && target.IsAlive()) if (target != null && target.IsAlive())
{ {
errorPacket = user.CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32513, 0x20, (uint)id); if (user is Player)
((Player)user).SendGameMessage(Server.GetWorldManager().GetActor(), 32513, 0x20, (uint)id);
return false; return false;
} }
} }
@ -180,7 +186,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
target.currentSubState != (user.currentSubState == SetActorStatePacket.SUB_STATE_MONSTER ? target.currentSubState != (user.currentSubState == SetActorStatePacket.SUB_STATE_MONSTER ?
SetActorStatePacket.SUB_STATE_PLAYER : SetActorStatePacket.SUB_STATE_MONSTER)) SetActorStatePacket.SUB_STATE_PLAYER : SetActorStatePacket.SUB_STATE_MONSTER))
{ {
errorPacket = user.CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32519, 0x20, (uint)id); if (user is Player)
((Player)user).SendGameMessage(Server.GetWorldManager().GetActor(), 32519, 0x20, (uint)id);
return false; return false;
} }
} }
@ -189,7 +196,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{ {
if (target == null || target.currentSubState != user.currentSubState ) if (target == null || target.currentSubState != user.currentSubState )
{ {
errorPacket = user.CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32516, 0x20, (uint)id); if (user is Player)
((Player)user).SendGameMessage(Server.GetWorldManager().GetActor(), 32516, 0x20, (uint)id);
return false; return false;
} }
} }

View File

@ -87,15 +87,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
public override void OnComplete() public override void OnComplete()
{ {
// todo: possible underflow // todo: possible underflow
BattleAction action = new BattleAction(); BattleAction action = new BattleAction(target.actorId, 0x765D, (uint) HitEffect.Hit, 0, (byte) HitDirection.None);
errorPacket = null; errorResult = null;
//var packet = BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, target.actorId, (uint)0x19001000, (uint)0x8000604, (ushort)0x765D, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, (byte)0x1); //var packet = BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, target.actorId, (uint)0x19001000, (uint)0x8000604, (ushort)0x765D, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, (byte)0x1);
action.animation = 0x19001000;
action.targetId = target.actorId; // HitDirection (auto attack shouldnt need this afaik)
action.effectId = (uint)HitEffect.Hit;
action.worldMasterTextId = 0x765D;
action.param = (byte)HitDirection.None; // HitDirection (auto attack shouldnt need this afaik)
// todo: implement auto attack damage bonus in Character.OnAttack // todo: implement auto attack damage bonus in Character.OnAttack
/* /*
@ -111,14 +108,10 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
* The above damage bonus also applies to Shot attacks by archers. * The above damage bonus also applies to Shot attacks by archers.
*/ */
owner.OnAttack(this, action, ref errorPacket); owner.OnAttack(this, action, ref errorResult);
// handle paralyze/intimidate/sleep/whatever in character thing // handle paralyze/intimidate/sleep/whatever in character thing
if (errorPacket == null) owner.DoBattleAction((ushort)BattleActionX01PacketCommand.Attack, 0x19001000, errorResult != null ? action : errorResult);
owner.zone.BroadcastPacketAroundActor(owner, BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, action.targetId, action.animation,
0x8000000 | action.effectId, action.worldMasterTextId, (ushort)BattleActionX01PacketCommand.Attack, action.amount, action.param)
);
else
owner.zone.BroadcastPacketAroundActor(owner, errorPacket);
//this.errorPacket = BattleActionX01Packet.BuildPacket(target.actorId, owner.actorId, target.actorId, 0, effectId, 0, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, 0); //this.errorPacket = BattleActionX01Packet.BuildPacket(target.actorId, owner.actorId, target.actorId, 0, effectId, 0, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, 0);
} }

View File

@ -28,22 +28,14 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
var returnCode = lua.LuaEngine.CallLuaBattleCommandFunction(owner, spell, "magic", "onMagicPrepare", owner, target, spell); var returnCode = lua.LuaEngine.CallLuaBattleCommandFunction(owner, spell, "magic", "onMagicPrepare", owner, target, spell);
// todo: check recast // todo: check recast
if (returnCode == 0 && owner.CanCast(target, spell, ref errorPacket)) if (returnCode == 0 && owner.CanCast(target, spell))
{ {
// todo: Azia can fix, check the recast time and send error // todo: Azia can fix, check the recast time and send error
OnStart(); OnStart();
} }
else else
{ {
if (owner is Player) errorResult = null;
{
// "Your battle command fails to activate"
if (errorPacket == null)
errorPacket = owner.CreateGameMessagePacket(Server.GetWorldManager().GetActor(), (ushort)(returnCode == -1 ? 32410 : returnCode), 0x20, owner.actorId);
((Player)owner).QueuePacket(errorPacket);
}
errorPacket = null;
interrupt = true; interrupt = true;
} }
} }
@ -55,7 +47,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
if (returnCode != 0) if (returnCode != 0)
{ {
interrupt = true; interrupt = true;
errorPacket = BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, owner.actorId, 0, 0, (ushort)(returnCode == -1 ? 32558 : returnCode), spell.id, 0, 1); errorResult = new BattleAction(target.actorId, (ushort)(returnCode == -1 ? 32558 : returnCode), 0, 0, 0, 1);
} }
else else
{ {
@ -106,9 +98,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
public override void OnInterrupt() public override void OnInterrupt()
{ {
// todo: send paralyzed/sleep message etc. // todo: send paralyzed/sleep message etc.
if (errorPacket != null) if (errorResult != null)
{ {
owner.zone.BroadcastPacketAroundActor(owner, errorPacket); //owner.zone.BroadcastPacketAroundActor(owner, errorResult);
} }
} }
@ -123,23 +115,14 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
var i = 0; var i = 0;
foreach (var chara in targets) foreach (var chara in targets)
{ {
var action = new BattleAction(); var action = new BattleAction(target.actorId, spell.worldMasterTextId, spell.effectAnimation, 0, (byte) HitDirection.None, 1);
action.effectId = spell.effectAnimation;
action.param = (byte)HitDirection.None; // HitDirection (magic shouldnt need this afaik)
action.unknown = 1;
action.targetId = chara.actorId;
action.worldMasterTextId = spell.worldMasterTextId;
action.animation = spell.battleAnimation;
action.amount = (ushort)lua.LuaEngine.CallLuaBattleCommandFunction(owner, spell, "magic", "onMagicFinish", owner, chara, spell, action); action.amount = (ushort)lua.LuaEngine.CallLuaBattleCommandFunction(owner, spell, "magic", "onMagicFinish", owner, chara, spell, action);
actions[i++] = action; actions[i++] = action;
//packets.Add(BattleActionX01Packet.BuildPacket(chara.actorId, owner.actorId, action.targetId, spell.battleAnimation, action.effectId, action.worldMasterTextId, spell.id, action.amount, action.param)); //packets.Add(BattleActionX01Packet.BuildPacket(chara.actorId, owner.actorId, action.targetId, spell.battleAnimation, action.effectId, action.worldMasterTextId, spell.id, action.amount, action.param));
} }
owner.zone.BroadcastPacketAroundActor(owner,
spell.aoeType != TargetFindAOEType.None ? (BattleActionX10Packet.BuildPacket(owner.actorId, owner.actorId, actions[0].animation, spell.id, actions)) : owner.DoBattleAction(spell.id, spell.effectAnimation, actions);
BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, target.actorId, spell.battleAnimation, actions[0].effectId, actions[0].worldMasterTextId, spell.id, actions[0].amount, actions[0].param)
);
//owner.zone.BroadcastPacketsAroundActor(owner, packets);
} }
public override void TryInterrupt() public override void TryInterrupt()
@ -170,7 +153,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
private bool CanCast() private bool CanCast()
{ {
return owner.CanCast(target, spell, ref errorPacket) && !HasMoved(); return owner.CanCast(target, spell) && !HasMoved();
} }
private bool HasMoved() private bool HasMoved()

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFXIVClassic_Map_Server.Actors; using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic.Common; using FFXIVClassic.Common;
using FFXIVClassic_Map_Server.packets.send.actor.battle;
namespace FFXIVClassic_Map_Server.actors.chara.ai.state namespace FFXIVClassic_Map_Server.actors.chara.ai.state
{ {
@ -18,7 +19,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
protected DateTime startTime; protected DateTime startTime;
protected SubPacket errorPacket; protected BattleAction errorResult;
protected bool isCompleted; protected bool isCompleted;

View File

@ -25,22 +25,14 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
var returnCode = lua.LuaEngine.CallLuaBattleCommandFunction(owner, skill, "weaponskill", "onSkillPrepare", owner, target, skill); var returnCode = lua.LuaEngine.CallLuaBattleCommandFunction(owner, skill, "weaponskill", "onSkillPrepare", owner, target, skill);
// todo: check recast // todo: check recast
if (returnCode == 0 && owner.CanWeaponSkill(target, skill, ref errorPacket)) if (returnCode == 0 && owner.CanWeaponSkill(target, skill))
{ {
// todo: Azia can fix, check the recast time and send error // todo: Azia can fix, check the recast time and send error
OnStart(); OnStart();
} }
else else
{ {
if (owner is Player) errorResult = null;
{
// "Your battle command fails to activate"
if (errorPacket == null)
errorPacket = owner.CreateGameMessagePacket(Server.GetWorldManager().GetActor(), (ushort)(returnCode == -1 ? 32410 : returnCode), 0x20, owner.actorId, owner.actorId, owner.actorId, owner.actorId);
((Player)owner).QueuePacket(errorPacket);
}
errorPacket = null;
interrupt = true; interrupt = true;
} }
} }
@ -52,7 +44,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
if (returnCode != 0) if (returnCode != 0)
{ {
interrupt = true; interrupt = true;
errorPacket = BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, owner.actorId, 0, 0, (ushort)(returnCode == -1 ? 32558 : returnCode), skill.id, 0, 1); errorResult = new BattleAction(owner.actorId, (ushort)(returnCode == -1 ? 32558 : returnCode), 0);
} }
else else
{ {
@ -89,9 +81,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
public override void OnInterrupt() public override void OnInterrupt()
{ {
// todo: send paralyzed/sleep message etc. // todo: send paralyzed/sleep message etc.
if (errorPacket != null) if (errorResult != null)
{ {
owner.zone.BroadcastPacketAroundActor(owner, errorPacket); owner.DoBattleAction(skill.id, 0, errorResult);
} }
} }
@ -107,13 +99,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
var i = 0; var i = 0;
foreach (var chara in targets) foreach (var chara in targets)
{ {
var action = new BattleAction(); var action = new BattleAction(chara.actorId, skill.worldMasterTextId, (uint)HitEffect.Hit, 0, 1, 1);
action.effectId = (uint)HitEffect.Hit;
action.param = 1; // HitDirection
action.unknown = 1;
action.targetId = chara.actorId;
action.worldMasterTextId = skill.worldMasterTextId;
action.animation = skill.battleAnimation;
// evasion, miss, dodge, etc to be handled in script, calling helpers from scripts/weaponskills.lua // evasion, miss, dodge, etc to be handled in script, calling helpers from scripts/weaponskills.lua
action.amount = (ushort)lua.LuaEngine.CallLuaBattleCommandFunction(owner, skill, "weaponskill", "onSkillFinish", owner, target, skill, action); action.amount = (ushort)lua.LuaEngine.CallLuaBattleCommandFunction(owner, skill, "weaponskill", "onSkillFinish", owner, target, skill, action);
actions[i++] = action; actions[i++] = action;
@ -121,10 +107,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
//packets.Add(BattleActionX01Packet.BuildPacket(chara.actorId, owner.actorId, action.targetId, skill.battleAnimation, action.effectId, action.worldMasterTextId, skill.id, action.amount, action.param)); //packets.Add(BattleActionX01Packet.BuildPacket(chara.actorId, owner.actorId, action.targetId, skill.battleAnimation, action.effectId, action.worldMasterTextId, skill.id, action.amount, action.param));
} }
owner.zone.BroadcastPacketAroundActor(owner, owner.DoBattleAction(skill.id, 0, actions);
skill.aoeType != TargetFindAOEType.None ? (BattleActionX10Packet.BuildPacket(owner.target.actorId, owner.actorId, actions[0].animation, skill.id, actions)) :
BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, target.actorId, skill.battleAnimation, actions[0].effectId, actions[0].worldMasterTextId, skill.id, actions[0].amount, actions[0].param)
);
} }
public override void TryInterrupt() public override void TryInterrupt()
@ -155,7 +138,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
private bool CanUse() private bool CanUse()
{ {
return owner.CanWeaponSkill(target, skill, ref errorPacket); return owner.CanWeaponSkill(target, skill);
} }
public BattleCommand GetWeaponSkill() public BattleCommand GetWeaponSkill()

View File

@ -13,7 +13,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.utils
{ {
static class BattleUtils static class BattleUtils
{ {
public static bool TryAttack(Character attacker, Character defender, BattleAction action, ref SubPacket errorPacket) public static bool TryAttack(Character attacker, Character defender, BattleAction action, ref BattleAction error)
{ {
// todo: get hit rate, hit count, set hit effect // todo: get hit rate, hit count, set hit effect
action.effectId |= (uint)(HitEffect.RecoilLv2 | HitEffect.Hit | HitEffect.HitVisual1); action.effectId |= (uint)(HitEffect.RecoilLv2 | HitEffect.Hit | HitEffect.HitVisual1);

View File

@ -107,19 +107,19 @@ namespace FFXIVClassic_Map_Server.Actors
return true; return true;
} }
public override bool CanCast(Character target, BattleCommand spell, ref SubPacket errorPacket) public override bool CanCast(Character target, BattleCommand spell)
{ {
// todo: // todo:
return false; return false;
} }
public override bool CanWeaponSkill(Character target, BattleCommand skill, ref SubPacket errorPacket) public override bool CanWeaponSkill(Character target, BattleCommand skill)
{ {
// todo: // todo:
return false; return false;
} }
public override bool CanUseAbility(Character target, BattleCommand ability, ref SubPacket errorPacket) public override bool CanUseAbility(Character target, BattleCommand ability)
{ {
// todo: // todo:
return false; return false;
@ -204,9 +204,9 @@ namespace FFXIVClassic_Map_Server.Actors
return this.isAtSpawn = Utils.DistanceSquared(positionX, positionY, positionZ, spawnX, spawnY, spawnZ) <= 2500.0f; return this.isAtSpawn = Utils.DistanceSquared(positionX, positionY, positionZ, spawnX, spawnY, spawnZ) <= 2500.0f;
} }
public override void OnAttack(State state, BattleAction action, ref SubPacket errorPacket) public override void OnAttack(State state, BattleAction action, ref BattleAction error)
{ {
base.OnAttack(state, action, ref errorPacket); base.OnAttack(state, action, ref error);
} }
} }
} }

View File

@ -1956,18 +1956,19 @@ namespace FFXIVClassic_Map_Server.Actors
return firstSlot; return firstSlot;
} }
/*
public void SendBattleActionX01Packet(uint anim, uint effect, uint text = 0x756D, uint command = 27260, uint param = 0x01, uint idek = 0x01) public void SendBattleActionX01Packet(uint anim, uint effect, uint text = 0x756D, uint command = 27260, uint param = 0x01, uint idek = 0x01)
{ {
var packet = BattleActionX01Packet.BuildPacket(actorId, actorId, currentTarget != 0xC0000000 ? currentTarget : currentLockedTarget, (uint)anim, (uint)effect, (ushort)text, (ushort)command, (ushort)param, (byte)idek); var packet = BattleActionX01Packet.BuildPacket(actorId, actorId, currentTarget != 0xC0000000 ? currentTarget : currentLockedTarget, (uint)anim, (uint)effect, (ushort)text, (ushort)command, (ushort)param, (byte)idek);
QueuePacket(packet); QueuePacket(packet);
} }*/
public override bool IsValidTarget(Character target, ValidTarget validTarget, ref SubPacket errorPacket) public override bool IsValidTarget(Character target, ValidTarget validTarget)
{ {
if (target == null) if (target == null)
{ {
// Target does not exist. // Target does not exist.
errorPacket = CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32511, 0x20); SendGameMessage(Server.GetWorldManager().GetActor(), 32511, 0x20);
return false; return false;
} }
@ -1977,21 +1978,21 @@ namespace FFXIVClassic_Map_Server.Actors
if (target.currentSubState == SetActorStatePacket.SUB_STATE_NONE) if (target.currentSubState == SetActorStatePacket.SUB_STATE_NONE)
{ {
// That command cannot be performed on the current target. // That command cannot be performed on the current target.
errorPacket = CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32547, 0x20); SendGameMessage(Server.GetWorldManager().GetActor(), 32547, 0x20);
return false; return false;
} }
if (currentParty != null && target.currentParty == currentParty) if (currentParty != null && target.currentParty == currentParty)
{ {
// That command cannot be performed on a party member. // That command cannot be performed on a party member.
errorPacket = CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32548, 0x20); SendGameMessage(Server.GetWorldManager().GetActor(), 32548, 0x20);
return false; return false;
} }
// todo: pvp? // todo: pvp?
if (target.currentSubState == currentSubState) if (target.currentSubState == currentSubState)
{ {
// That command cannot be performed on an ally. // That command cannot be performed on an ally.
errorPacket = CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32549, 0x20); SendGameMessage(Server.GetWorldManager().GetActor(), 32549, 0x20);
return false; return false;
} }
} }
@ -1999,7 +2000,7 @@ namespace FFXIVClassic_Map_Server.Actors
if ((validTarget & ValidTarget.Ally) != 0 && target.currentSubState != currentSubState) if ((validTarget & ValidTarget.Ally) != 0 && target.currentSubState != currentSubState)
{ {
// That command cannot be performed on the current target. // That command cannot be performed on the current target.
errorPacket = CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32547, 0x20); SendGameMessage(Server.GetWorldManager().GetActor(), 32547, 0x20);
return false; return false;
} }
@ -2011,29 +2012,29 @@ namespace FFXIVClassic_Map_Server.Actors
if (target is Player && ((Player)target).playerSession.isUpdatesLocked) if (target is Player && ((Player)target).playerSession.isUpdatesLocked)
{ {
// That command cannot be performed on the current target. // That command cannot be performed on the current target.
errorPacket = CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32547, 0x20); SendGameMessage(Server.GetWorldManager().GetActor(), 32547, 0x20);
return false; return false;
} }
return true; return true;
} }
public override bool CanCast(Character target, BattleCommand spell, ref SubPacket errorPacket) public override bool CanCast(Character target, BattleCommand spell)
{ {
// todo: move the ability specific stuff to ability.cs // todo: move the ability specific stuff to ability.cs
if (target == null) if (target == null)
{ {
// Target does not exist. // Target does not exist.
errorPacket = CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32511, 0x20, (uint)spell.id); SendGameMessage(Server.GetWorldManager().GetActor(), 32511, 0x20, (uint)spell.id);
return false; return false;
} }
if (Utils.Distance(positionX, positionY, positionZ, target.positionX, target.positionY, target.positionZ) > spell.range) if (Utils.Distance(positionX, positionY, positionZ, target.positionX, target.positionY, target.positionZ) > spell.range)
{ {
// The target is out of range. // The target is out of range.
errorPacket = CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32539, 0x20, spell.id); SendGameMessage(Server.GetWorldManager().GetActor(), 32539, 0x20, spell.id);
return false; return false;
} }
if (!IsValidTarget(target, spell.validTarget, ref errorPacket) || !spell.IsValidTarget(this, target, ref errorPacket)) if (!IsValidTarget(target, spell.validTarget) || !spell.IsValidTarget(this, target))
{ {
// error packet is set in IsValidTarget // error packet is set in IsValidTarget
return false; return false;
@ -2041,22 +2042,22 @@ namespace FFXIVClassic_Map_Server.Actors
return true; return true;
} }
public override bool CanWeaponSkill(Character target, BattleCommand skill, ref SubPacket errorPacket) public override bool CanWeaponSkill(Character target, BattleCommand skill)
{ {
// todo: see worldmaster ids 32558~32557 for proper ko message and stuff // todo: see worldmaster ids 32558~32557 for proper ko message and stuff
if (target == null) if (target == null)
{ {
// Target does not exist. // Target does not exist.
errorPacket = CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32511, 0x20, (uint)skill.id); SendGameMessage(Server.GetWorldManager().GetActor(), 32511, 0x20, (uint)skill.id);
return false; return false;
} }
if (Utils.Distance(positionX, positionY, positionZ, target.positionX, target.positionY, target.positionZ) > skill.range) if (Utils.Distance(positionX, positionY, positionZ, target.positionX, target.positionY, target.positionZ) > skill.range)
{ {
// The target is out of range. // The target is out of range.
errorPacket = CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32539, 0x20, (uint)skill.id); SendGameMessage(Server.GetWorldManager().GetActor(), 32539, 0x20, (uint)skill.id);
return false; return false;
} }
if (!IsValidTarget(target, skill.validTarget, ref errorPacket) || !skill.IsValidTarget(this, target, ref errorPacket)) if (!IsValidTarget(target, skill.validTarget) || !skill.IsValidTarget(this, target))
{ {
// error packet is set in IsValidTarget // error packet is set in IsValidTarget
return false; return false;
@ -2064,14 +2065,14 @@ namespace FFXIVClassic_Map_Server.Actors
return true; return true;
} }
public override void OnAttack(State state, BattleAction action, ref SubPacket errorPacket) public override void OnAttack(State state, BattleAction action, ref BattleAction error)
{ {
base.OnAttack(state, action, ref errorPacket); base.OnAttack(state, action, ref error);
if (errorPacket == null) if (error == null)
{ {
// melee attack animation // melee attack animation
action.animation = 0x19001000; //action.animation = 0x19001000;
} }
var target = state.GetTarget(); var target = state.GetTarget();
//if (target is BattleNpc) //if (target is BattleNpc)

View File

@ -109,6 +109,16 @@ namespace FFXIVClassic_Map_Server.packets.send.actor.battle
/// <summary> /// <summary>
/// this field is not actually part of the packet struct /// this field is not actually part of the packet struct
/// </summary> /// </summary>
public uint animation; //public uint animation;
public BattleAction(uint targetId, ushort worldMasterTextId, uint effectId, ushort amount = 0, byte param = 0, byte unknown = 0)
{
this.targetId = targetId;
this.worldMasterTextId = worldMasterTextId;
this.effectId = effectId;
this.amount = amount;
this.param = param;
this.unknown = unknown;
}
} }
} }

View File

@ -9,7 +9,7 @@ namespace FFXIVClassic_Map_Server.packets.send.actor.battle
public const ushort OPCODE = 0x013C; public const ushort OPCODE = 0x013C;
public const uint PACKET_SIZE = 0x48; public const uint PACKET_SIZE = 0x48;
public static SubPacket BuildPacket(uint sourceActorId, uint targetActorId, uint animationId, ushort commandId) public static SubPacket BuildPacket(uint sourceActorId, uint animationId, ushort commandId)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];

View File

@ -11,6 +11,53 @@ namespace FFXIVClassic_Map_Server.packets.send.actor.battle
public const ushort OPCODE = 0x013A; public const ushort OPCODE = 0x013A;
public const uint PACKET_SIZE = 0xD8; public const uint PACKET_SIZE = 0xD8;
public static SubPacket BuildPacket(uint sourceActorId, uint animationId, ushort commandId, BattleAction[] actionList, ref int currentIndex)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)sourceActorId);
binWriter.Write((UInt32)animationId);
//Missing... last value is float, string in here as well?
binWriter.Seek(0x20, SeekOrigin.Begin);
binWriter.Write((UInt32)actionList.Length); //Num actions (always 1 for this)
binWriter.Write((UInt16)commandId);
binWriter.Write((UInt16)0x810); //?
//binWriter.Seek(0x20, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((UInt32)action.targetId);
binWriter.Seek(0x50, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((UInt16)action.amount);
binWriter.Seek(0x64, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((UInt16)action.worldMasterTextId);
binWriter.Seek(0x78, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((UInt32)action.effectId);
binWriter.Seek(0xA0, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((Byte)action.param);
binWriter.Seek(0xAA, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((Byte)action.unknown);
}
}
return new SubPacket(OPCODE, sourceActorId, data);
}
public static SubPacket BuildPacket(uint sourceActorId, uint animationId, ushort commandId, List<BattleAction> actionList, ref int currentIndex) public static SubPacket BuildPacket(uint sourceActorId, uint animationId, ushort commandId, List<BattleAction> actionList, ref int currentIndex)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];
@ -57,5 +104,6 @@ namespace FFXIVClassic_Map_Server.packets.send.actor.battle
return new SubPacket(OPCODE, sourceActorId, data); return new SubPacket(OPCODE, sourceActorId, data);
} }
} }
} }

View File

@ -11,6 +11,53 @@ namespace FFXIVClassic_Map_Server.packets.send.actor.battle
public const ushort OPCODE = 0x013B; public const ushort OPCODE = 0x013B;
public const uint PACKET_SIZE = 0x148; public const uint PACKET_SIZE = 0x148;
public static SubPacket BuildPacket(uint sourceActorId, uint animationId, ushort commandId, BattleAction[] actionList, ref int currentIndex)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt32)sourceActorId);
binWriter.Write((UInt32)animationId);
//Missing... last value is float, string in here as well?
binWriter.Seek(0x20, SeekOrigin.Begin);
binWriter.Write((UInt32)actionList.Length); //Num actions (always 1 for this)
binWriter.Write((UInt16)commandId);
binWriter.Write((UInt16)0x810); //?
binWriter.Seek(0x58, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((UInt32)action.targetId);
binWriter.Seek(0xA0, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((UInt16)action.amount);
binWriter.Seek(0xC4, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((UInt16)action.worldMasterTextId);
binWriter.Seek(0xE8, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((UInt32)action.effectId);
binWriter.Seek(0x130, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((Byte)action.param);
binWriter.Seek(0x142, SeekOrigin.Begin);
foreach (BattleAction action in actionList)
binWriter.Write((Byte)action.unknown);
}
}
return new SubPacket(OPCODE, sourceActorId, data);
}
public static SubPacket BuildPacket(uint sourceActorId, uint animationId, ushort commandId, List<BattleAction> actionList, ref int currentIndex) public static SubPacket BuildPacket(uint sourceActorId, uint animationId, ushort commandId, List<BattleAction> actionList, ref int currentIndex)
{ {
byte[] data = new byte[PACKET_SIZE - 0x20]; byte[] data = new byte[PACKET_SIZE - 0x20];