renamed ability to battlecommand

- moved spells to scripts/commands/
- added aoe range field to battle_commands.sql
- changed AttackState to use character's onAttack
This commit is contained in:
Tahir Akhlaq
2017-08-28 04:45:20 +01:00
parent 6f5a480cbd
commit 6c74222b68
23 changed files with 658 additions and 335 deletions

View File

@@ -11,8 +11,6 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
{
class AttackState : State
{
private int damage = 0;
private bool tooFar = false;
private DateTime attackTime;
public AttackState(Character owner, Character target) :
@@ -31,8 +29,6 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
public override void OnStart()
{
// todo: check within attack range
owner.LookAt(target);
}
public override bool Update(DateTime tick)
@@ -46,7 +42,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
return true;
}
*/
if (owner.target != target || owner.target?.actorId != owner.currentLockedTarget)
if (target == null || owner.target != target || owner.target?.actorId != owner.currentLockedTarget)
owner.aiContainer.ChangeTarget(target = Server.GetWorldManager().GetActorInWorld(owner.currentLockedTarget == 0xC0000000 ? owner.currentTarget : owner.currentLockedTarget) as Character);
if (target == null || target.IsDead())
@@ -90,22 +86,15 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
public override void OnComplete()
{
damage = utils.AttackUtils.CalculateDamage(owner, target);
// todo: possible underflow
BattleAction action = new BattleAction();
//var packet = BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, target.actorId, (uint)0x19001000, (uint)0x8000604, (ushort)0x765D, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, (byte)0x1);
// onAttack(actor, target, damage)
utils.BattleUtils.DamageTarget(owner, target, damage);
lua.LuaEngine.CallLuaBattleAction(owner, "onAttack", false, owner, target, damage);
{
var actors = owner.zone.GetActorsAroundActor<Player>(owner, 50);
foreach (var player in actors)
{
var packet = BattleActionX01Packet.BuildPacket(player.actorId, owner.actorId, target.actorId, (uint)0x19001000, (uint)0x8000604, (ushort)0x765D, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, (byte)0x1);
player.QueuePacket(packet);
}
}
target.DelHP((short)damage);
owner.LookAt(target);
action.targetId = target.actorId;
action.effectId = (uint)HitEffect.Hit;
action.worldMasterTextId = 0x765D;
action.param = 1; // todo: hit effect doesnt display without this?
owner.OnAttack(this, action);
//this.errorPacket = BattleActionX01Packet.BuildPacket(target.actorId, owner.actorId, target.actorId, 0, effectId, 0, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, 0);
}

View File

@@ -15,29 +15,34 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
class MagicState : State
{
private Ability spell;
private uint cost;
private BattleCommand spell;
private Vector3 startPos;
public MagicState(Character owner, Character target, ushort spellId) :
base(owner, target)
{
this.startPos = owner.GetPosAsVector3();
this.startTime = DateTime.Now;
// todo: lookup spell from global table
this.spell = Server.GetWorldManager().GetAbility(spellId);
var returnCode = lua.LuaEngine.CallLuaAbilityFunction(owner, spell, "spells", "onSpellPrepare", owner, target, spell);
var returnCode = lua.LuaEngine.CallLuaBattleCommandFunction(owner, spell, "magic", "onMagicPrepare", owner, target, spell);
// todo: check recast
if (owner.CanCast(target, spell, ref errorPacket))
if (returnCode == 0 && owner.CanCast(target, spell, ref errorPacket))
{
// todo: Azia can fix, check the recast time and send error
OnStart();
}
else if (interrupt || errorPacket != null)
else
{
if (owner is Player && errorPacket != null)
((Player)owner).QueuePacket(errorPacket);
if (owner is Player)
{
// "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;
}
@@ -45,7 +50,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
public override void OnStart()
{
var returnCode = lua.LuaEngine.CallLuaAbilityFunction(owner, spell, "spells", "onSpellStart", owner, target, spell);
var returnCode = lua.LuaEngine.CallLuaBattleCommandFunction(owner, spell, "magic", "onMagicStart", owner, target, spell);
if (returnCode != 0)
{
@@ -55,8 +60,6 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
else
{
// todo: check within attack range
startPos = owner.GetPosAsVector3();
owner.LookAt(target);
float[] baseCastDuration = { 1.0f, 0.25f };
float spellSpeed = spell.castTimeSeconds;
@@ -126,12 +129,15 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
action.unknown = 1;
action.targetId = chara.actorId;
action.worldMasterTextId = spell.worldMasterTextId;
action.amount = (ushort)lua.LuaEngine.CallLuaAbilityFunction(owner, spell, "spells", "onSpellFinish", owner, chara, spell, action);
action.amount = (ushort)lua.LuaEngine.CallLuaBattleCommandFunction(owner, spell, "magic", "onMagicFinish", owner, chara, spell, 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(BattleActionX10Packet.BuildPacket(owner.target.actorId, owner.actorId, spell.battleAnimation, spell.id, actions));
owner.zone.BroadcastPacketAroundActor(owner,
spell.aoeType != TargetFindAOEType.None ? (BattleActionX10Packet.BuildPacket(owner.target.actorId, owner.actorId, spell.battleAnimation, spell.id, 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);
}
@@ -181,5 +187,10 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
}
owner.zone.BroadcastPacketsAroundActor(owner, packets);
}
public BattleCommand GetSpell()
{
return spell;
}
}
}

View File

@@ -59,5 +59,10 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
this.target = target;
}
public Character GetTarget()
{
return target;
}
}
}

View File

@@ -14,7 +14,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
class WeaponSkillState : State
{
private Ability skill;
private BattleCommand skill;
public WeaponSkillState(Character owner, Character target, ushort skillId) :
base(owner, target)
@@ -22,19 +22,24 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
this.startTime = DateTime.Now;
// todo: lookup skill from global table
this.skill = Server.GetWorldManager().GetAbility(skillId);
var returnCode = lua.LuaEngine.CallLuaAbilityFunction(owner, skill, "weaponskills", "onSkillPrepare", owner, target, skill);
var returnCode = lua.LuaEngine.CallLuaBattleCommandFunction(owner, skill, "weaponskill", "onSkillPrepare", owner, target, skill);
// todo: check recast
if (owner.CanWeaponSkill(target, skill, ref errorPacket))
if (returnCode == 0 && owner.CanWeaponSkill(target, skill, ref errorPacket))
{
// todo: Azia can fix, check the recast time and send error
OnStart();
}
else if (interrupt || errorPacket != null)
else
{
if (owner is Player && errorPacket != null)
((Player)owner).QueuePacket(errorPacket);
if (owner is Player)
{
// "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;
}
@@ -42,7 +47,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
public override void OnStart()
{
var returnCode = lua.LuaEngine.CallLuaAbilityFunction(owner, skill, "weaponskills", "onSkillStart", owner, target, skill);
var returnCode = lua.LuaEngine.CallLuaBattleCommandFunction(owner, skill, "weaponskill", "onSkillStart", owner, target, skill);
if (returnCode != 0)
{
@@ -96,25 +101,29 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
isCompleted = true;
var targets = skill.targetFind.GetTargets();
BattleAction[] actions = new BattleAction[targets.Count];
List<SubPacket> packets = new List<SubPacket>();
var i = 0;
foreach (var chara in targets)
{
var action = new BattleAction();
action.effectId = 0;
action.effectId = (uint)HitEffect.Hit;
action.param = 1;
action.unknown = 1;
action.targetId = chara.actorId;
action.worldMasterTextId = skill.worldMasterTextId;
action.amount = (ushort)lua.LuaEngine.CallLuaAbilityFunction(owner, skill, "skills", "onSkillFinish", owner, target, skill, action);
// 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);
actions[i++] = action;
//packets.Add(BattleActionX01Packet.BuildPacket(chara.actorId, owner.actorId, action.targetId, skill.battleAnimation, action.effectId, action.worldMasterTextId, skill.id, action.amount, action.param));
}
packets.Add(BattleActionX10Packet.BuildPacket(owner.target.actorId, owner.actorId, skill.battleAnimation, skill.id, actions));
owner.zone.BroadcastPacketsAroundActor(owner, packets);
owner.zone.BroadcastPacketAroundActor(owner,
skill.aoeType != TargetFindAOEType.None ? (BattleActionX10Packet.BuildPacket(owner.target.actorId, owner.actorId, skill.battleAnimation, 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()
@@ -147,5 +156,10 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state
{
return owner.CanWeaponSkill(target, skill, ref errorPacket);
}
public BattleCommand GetWeaponSkill()
{
return skill;
}
}
}