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

@ -1343,7 +1343,7 @@ namespace FFXIVClassic_Map_Server
player.charaWork.parameterSave.commandSlot_recastTime[index - player.charaWork.commandBorder] = reader.GetUInt32(2);
//Recast timer
Ability ability = Server.GetWorldManager().GetAbility((ushort)(trueCommandId ^ 2700083200));
BattleCommand ability = Server.GetWorldManager().GetAbility((ushort)(trueCommandId ^ 2700083200));
player.charaWork.parameterTemp.maxCommandRecastTime[index - player.charaWork.commandBorder] = (ushort) (ability != null ? ability.recastTimeSeconds : 1);
//Previous recast timer
player.charaWork.parameterSave.commandSlot_recastTime[index - player.charaWork.commandBorder] = reader.GetUInt32(2);
@ -2149,9 +2149,9 @@ namespace FFXIVClassic_Map_Server
}
}
public static Dictionary<ushort, Ability> LoadGlobalAbilityList()
public static Dictionary<ushort, BattleCommand> LoadGlobalBattleCommandList()
{
var abilities = new Dictionary<ushort, Ability>();
var battleCommands = new Dictionary<ushort, BattleCommand>();
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
{
@ -2160,7 +2160,7 @@ namespace FFXIVClassic_Map_Server
conn.Open();
var query = ("SELECT `id`, name, classJob, lvl, requirements, validTarget, aoeType, numHits, positionBonus, procRequirement, `range`, buffDuration, debuffDuration, " +
"castType, castTime, recastTime, mpCost, tpCost, animationType, effectAnimation, modelAnimation, animationDuration FROM abilities;");
"castType, castTime, recastTime, mpCost, tpCost, animationType, effectAnimation, modelAnimation, animationDuration, aoeRange FROM battle_commands;");
MySqlCommand cmd = new MySqlCommand(query, conn);
@ -2168,33 +2168,34 @@ namespace FFXIVClassic_Map_Server
{
while (reader.Read())
{
var id = reader.GetUInt16(0);
var name = reader.GetString(1);
var ability = new Ability(id, name);
var id = reader.GetUInt16("id");
var name = reader.GetString("name");
var battleCommand = new BattleCommand(id, name);
ability.job = reader.GetByte(2);
ability.level = reader.GetByte(3);
ability.requirements = (AbilityRequirements)reader.GetUInt16(4);
ability.validTarget = (ValidTarget)reader.GetByte(5);
ability.aoeType = (TargetFindAOEType)reader.GetByte(6);
ability.numHits = reader.GetByte(7);
ability.positionBonus = (AbilityPositionBonus)reader.GetByte(8);
ability.procRequirement = (AbilityProcRequirement)reader.GetByte(9);
ability.range = reader.GetInt32(10);
ability.debuffDurationSeconds = reader.GetUInt32(11);
ability.buffDurationSeconds = reader.GetUInt32(12);
ability.castType = reader.GetByte(13);
ability.castTimeSeconds = reader.GetUInt32(14);
ability.recastTimeSeconds = reader.GetUInt32(15);
ability.mpCost = reader.GetUInt16(16);
ability.tpCost = reader.GetUInt16(17);
ability.animationType = reader.GetByte(18);
ability.effectAnimation = reader.GetUInt16(19);
ability.modelAnimation = reader.GetUInt16(20);
ability.animationDurationSeconds = reader.GetUInt16(21);
ability.battleAnimation = (uint)((ability.animationType << 24) | (ability.modelAnimation << 12) | (ability.effectAnimation));
battleCommand.job = reader.GetByte("classJob");
battleCommand.level = reader.GetByte("lvl");
battleCommand.requirements = (AbilityRequirements)reader.GetUInt16("requirements");
battleCommand.validTarget = (ValidTarget)reader.GetByte("validTarget");
battleCommand.aoeType = (TargetFindAOEType)reader.GetByte("aoeType");
battleCommand.numHits = reader.GetByte("numHits");
battleCommand.positionBonus = (AbilityPositionBonus)reader.GetByte("positionBonus");
battleCommand.procRequirement = (AbilityProcRequirement)reader.GetByte("procRequirement");
battleCommand.range = reader.GetInt32("range");
battleCommand.debuffDurationSeconds = reader.GetUInt32("debuffDuration");
battleCommand.buffDurationSeconds = reader.GetUInt32("buffDuration");
battleCommand.castType = reader.GetByte("castType");
battleCommand.castTimeSeconds = reader.GetUInt32("castTime");
battleCommand.recastTimeSeconds = reader.GetUInt32("recastTime");
battleCommand.mpCost = reader.GetUInt16("mpCost");
battleCommand.tpCost = reader.GetUInt16("tpCost");
battleCommand.animationType = reader.GetByte("animationType");
battleCommand.effectAnimation = reader.GetUInt16("effectAnimation");
battleCommand.modelAnimation = reader.GetUInt16("modelAnimation");
battleCommand.animationDurationSeconds = reader.GetUInt16("animationDuration");
battleCommand.aoeRange = reader.GetInt32("aoeRange");
battleCommand.battleAnimation = (uint)((battleCommand.animationType << 24) | (battleCommand.modelAnimation << 12) | (battleCommand.effectAnimation));
abilities.Add(id, ability);
battleCommands.Add(id, battleCommand);
}
}
}
@ -2207,7 +2208,7 @@ namespace FFXIVClassic_Map_Server
conn.Dispose();
}
}
return abilities;
return battleCommands;
}

View file

@ -93,7 +93,7 @@
<Compile Include="actors\chara\ai\controllers\PlayerController.cs" />
<Compile Include="actors\chara\ai\HateContainer.cs" />
<Compile Include="actors\chara\ai\PathFind.cs" />
<Compile Include="actors\chara\ai\Ability.cs" />
<Compile Include="actors\chara\ai\BattleCommand.cs" />
<Compile Include="actors\chara\ai\state\AttackState.cs" />
<Compile Include="actors\chara\ai\state\DeathState.cs" />
<Compile Include="actors\chara\ai\state\MagicState.cs" />

View file

@ -37,7 +37,7 @@ namespace FFXIVClassic_Map_Server
private Dictionary<uint, ActorClass> actorClasses = new Dictionary<uint,ActorClass>();
private Dictionary<ulong, Party> currentPlayerParties = new Dictionary<ulong, Party>(); //GroupId, Party object
private Dictionary<uint, StatusEffect> effectList = new Dictionary<uint, StatusEffect>();
private Dictionary<ushort, Ability> abilityList = new Dictionary<ushort, Ability>();
private Dictionary<ushort, BattleCommand> abilityList = new Dictionary<ushort, BattleCommand>();
private Server mServer;
@ -1153,12 +1153,12 @@ namespace FFXIVClassic_Map_Server
public void LoadAbilities()
{
abilityList = Database.LoadGlobalAbilityList();
abilityList = Database.LoadGlobalBattleCommandList();
}
public Ability GetAbility(uint id)
public BattleCommand GetAbility(uint id)
{
Ability ability;
BattleCommand ability;
return abilityList.TryGetValue((ushort)id, out ability) ? ability.Clone() : null;
}
}

View file

@ -11,6 +11,7 @@ using System.Collections.Generic;
using FFXIVClassic_Map_Server.actors.chara;
using FFXIVClassic_Map_Server.packets.send.actor.battle;
using FFXIVClassic_Map_Server.packets.send;
using FFXIVClassic_Map_Server.actors.chara.ai.state;
namespace FFXIVClassic_Map_Server.Actors
{
@ -177,6 +178,7 @@ namespace FFXIVClassic_Map_Server.Actors
zone.BroadcastPacketAroundActor(this, PlayAnimationOnActorPacket.BuildPacket(actorId, animId));
}
#region ai stuff
public void PathTo(float x, float y, float z, float stepSize = 0.70f, int maxPath = 40, float polyRadius = 0.0f)
{
aiContainer?.pathFind?.PreparePath(x, y, z, stepSize, maxPath, polyRadius);
@ -265,17 +267,17 @@ namespace FFXIVClassic_Map_Server.Actors
return true;
}
public virtual bool CanCast(Character target, Ability spell, ref SubPacket errorPacket)
public virtual bool CanCast(Character target, BattleCommand spell, ref SubPacket errorPacket)
{
return false;
}
public virtual bool CanWeaponSkill(Character target, Ability skill, ref SubPacket errorPacket)
public virtual bool CanWeaponSkill(Character target, BattleCommand skill, ref SubPacket errorPacket)
{
return false;
}
public virtual bool CanUseAbility(Character target, Ability ability, ref SubPacket errorPacket)
public virtual bool CanUseAbility(Character target, BattleCommand ability, ref SubPacket errorPacket)
{
return false;
}
@ -470,6 +472,27 @@ namespace FFXIVClassic_Map_Server.Actors
// todo: for battlenpc/player calculate speed
return moveSpeeds[2] + GetMod((uint)Modifier.Speed);
}
public virtual void OnAttack(State state, BattleAction action)
{
}
public virtual void OnCast(State state, BattleAction action)
{
}
public virtual void OnWeaponSkill(State state, BattleAction action)
{
}
public virtual void OnAbility(State state, BattleAction action)
{
}
#endregion
}
}

View file

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using FFXIVClassic_Map_Server.actors.chara.player;
using FFXIVClassic.Common;
using FFXIVClassic_Map_Server.packets.send.actor;
using FFXIVClassic_Map_Server.actors.chara.ai.utils;
namespace FFXIVClassic_Map_Server.actors.chara.ai
{
@ -43,7 +44,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
Miss = 0x08
}
class Ability
class BattleCommand
{
public ushort id;
public string name;
@ -70,20 +71,20 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
public uint battleAnimation;
public ushort worldMasterTextId;
public uint param;
public int aoeRange;
public TargetFind targetFind;
public Ability(ushort id, string name)
public BattleCommand(ushort id, string name)
{
this.id = id;
this.name = name;
this.range = 0;
}
public Ability Clone()
public BattleCommand Clone()
{
return (Ability)MemberwiseClone();
return (BattleCommand)MemberwiseClone();
}
public bool IsSpell()
@ -104,15 +105,16 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
if (aoeType == TargetFindAOEType.Box)
{
// todo: read box width from sql
targetFind.SetAOEBox(validTarget, range, 3);
targetFind.SetAOEBox(validTarget, range, aoeRange);
}
else
{
targetFind.SetAOEType(validTarget, aoeType, range, 40);
targetFind.SetAOEType(validTarget, aoeType, range, aoeRange);
}
/*
worldMasterTextId
32512 cannot be performed on a KO'd target.
32513 can only be performed on a KO'd target.
32514 cannot be performed on yourself.
@ -143,8 +145,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
}
// todo: calculate cost based on modifiers also (probably in BattleUtils)
if (mpCost > 0 && (mpCost = CalculateCost((ushort)user.charaWork.parameterSave.state_mainSkillLevel)) > user.GetMP())
if (BattleUtils.CalculateSpellCost(user, target, this) > user.GetMP())
{
// todo: error message
errorPacket = user.CreateGameMessagePacket(Server.GetWorldManager().GetActor(), 32545, 0x20, (uint)id);
@ -215,7 +217,10 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
else
cost = (ushort)(8000 + (level - 70) * 500);
return (ushort)Math.Ceiling((cost * ((mpCost == 0 ? tpCost : mpCost) * 0.001)));
if (mpCost != 0)
return (ushort)Math.Ceiling((cost * mpCost * 0.001));
return tpCost;
}
}
}

View file

@ -137,6 +137,10 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{
point = path[path.Count - 1];
}
else
{
return true;
}
if (distanceFromPoint == 0)
return owner.positionX == point.X && owner.positionZ == point.Z;

View file

@ -1,6 +1,7 @@
using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.lua;
using FFXIVClassic_Map_Server.packets.send.actor;
using FFXIVClassic_Map_Server.packets.send.actor.battle;
using System;
using System.Collections.Generic;
using System.Linq;
@ -368,6 +369,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
private StatusEffectOverwrite overwrite; // how to handle adding an effect with same id (see StatusEfectOverwrite)
private bool silent = false; // do i send a message on losing effect
HitEffect animationEffect;
public StatusEffect(Character owner, uint id, UInt64 magnitude, uint tickMs, uint durationMs, byte tier = 0)
{
this.owner = owner;
@ -566,5 +569,15 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{
this.silent = silent;
}
public void SetAnimation(uint hitEffect)
{
animationEffect = (HitEffect)hitEffect;
}
public uint GetAnimation()
{
return (uint)animationEffect;
}
}
}

View file

@ -68,6 +68,11 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
public bool AddStatusEffect(StatusEffect newEffect, Character source, bool silent = false)
{
/*
worldMasterTextId
32001 [@2B([@IF($E4($EB(1),$EB(2)),you,[@IF($E9(7),[@SHEETEN(xtx/displayName,2,$E9(7),1,1)],$EB(2))])])] [@IF($E4($EB(1),$EB(2)),resist,resists)] the effect of [@SHEET(xtx/status,$E8(11),3)].
32002 [@SHEET(xtx/status,$E8(11),3)] fails to take effect.
*/
// todo: check flags/overwritable and add effect to list
var effect = GetStatusEffectById(newEffect.GetStatusEffectId());
bool canOverwrite = false;
@ -85,8 +90,6 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
if (!silent || !effect.GetSilent() || (effect.GetFlags() & (uint)StatusEffectFlags.Silent) == 0)
{
// todo: send packet to client with effect added message
foreach (var player in owner.zone.GetActorsAroundActor<Player>(owner, 50))
player.QueuePacket(packets.send.actor.battle.BattleActionX01Packet.BuildPacket(player.actorId, newEffect.GetSource().actorId, newEffect.GetOwner().actorId, 0x7678, 0, 0, newEffect.GetStatusId(), 0, 0));
}
// wont send a message about losing effect here
@ -119,11 +122,10 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
if (effects.ContainsKey(effect.GetStatusEffectId()))
{
// send packet to client with effect remove message
if (!silent || !effect.GetSilent() || (effect.GetFlags() & (uint)StatusEffectFlags.Silent) == 0)
if (!silent && !effect.GetSilent() || (effect.GetFlags() & (uint)StatusEffectFlags.Silent) == 0)
{
// todo: send packet to client with effect added message
foreach (var player in owner.zone.GetActorsAroundActor<Player>(owner, 50))
player.QueuePacket(packets.send.actor.battle.BattleActionX01Packet.BuildPacket(player.actorId, owner.actorId, owner.actorId, 0x7679, 0, 0, effect.GetStatusId(), 0, 0));
}
// todo: this is retarded..
@ -147,7 +149,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
{
if (effect.GetStatusEffectId() == effectId)
{
RemoveStatusEffect(effect, silent);
RemoveStatusEffect(effect, effect.GetSilent() || silent);
break;
}
}

View file

@ -309,11 +309,15 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai
private void AddAllInHateList()
{
if (!(owner is BattleNpc))
Program.Log.Error($"TargetFind.AddAllInHateList() owner [{owner.actorId}] {owner.customDisplayName} {owner.actorName} is not a BattleNpc");
foreach (var hateEntry in ((BattleNpc)owner).hateContainer.GetHateList())
{
AddTarget(hateEntry.Value.actor, false);
Program.Log.Error($"TargetFind.AddAllInHateList() owner [{owner.actorId}] {owner.customDisplayName} {owner.actorName} is not a BattleNpc");
}
else
{
foreach (var hateEntry in ((BattleNpc)owner).hateContainer.GetHateList())
{
AddTarget(hateEntry.Value.actor, false);
}
}
}

View file

@ -66,6 +66,11 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.controllers
owner.aiContainer.InternalCast(target, spellId);
}
public override void WeaponSkill(Character target, uint weaponSkillId)
{
owner.aiContainer.InternalWeaponSkill(target, weaponSkillId);
}
public override void Ability(Character target, uint abilityId)
{
owner.aiContainer.InternalAbility(target, abilityId);

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;
}
}
}

View file

@ -5,12 +5,66 @@ using System.Text;
using System.Threading.Tasks;
using FFXIVClassic_Map_Server.Actors;
using FFXIVClassic_Map_Server.packets.send.actor;
using FFXIVClassic_Map_Server.packets.send.actor.battle;
namespace FFXIVClassic_Map_Server.actors.chara.ai.utils
{
static class BattleUtils
{
public static void DamageTarget(Character attacker, Character defender, int damage)
public static void TryAttack(Character attacker, Character defender, BattleAction action)
{
// todo: get hit rate, hit count, set hit effect
action.effectId |= (uint)(HitEffect.RecoilLv2 | HitEffect.Hit | HitEffect.HitVisual1);
}
public static ushort CalculateAttackDamage(Character attacker, Character defender, BattleAction action)
{
ushort damage = (ushort)(Program.Random.Next(10) * 10);
// todo: handle all other crap before protect/stoneskin
// todo: handle crit etc
if (defender.statusEffects.HasStatusEffect(StatusEffectId.Protect) || defender.statusEffects.HasStatusEffect(StatusEffectId.Protect2))
{
if (action != null)
action.effectId |= (uint)HitEffect.Protect;
}
if (defender.statusEffects.HasStatusEffect(StatusEffectId.Stoneskin))
{
if (action != null)
action.effectId |= (uint)HitEffect.Stoneskin;
}
return damage;
}
public static ushort CalculateSpellDamage(Character attacker, Character defender, BattleAction action)
{
ushort damage = 0;
// todo: handle all other crap before shell/stoneskin
if (defender.statusEffects.HasStatusEffect(StatusEffectId.Shell))
{
// todo: shell probably only shows on magic..
if (defender.statusEffects.HasStatusEffect(StatusEffectId.Shell))
{
if (action != null)
action.effectId |= (uint)HitEffect.Shell;
}
}
if (defender.statusEffects.HasStatusEffect(StatusEffectId.Stoneskin))
{
if (action != null)
action.effectId |= (uint)HitEffect.Stoneskin;
}
return damage;
}
public static void DamageTarget(Character attacker, Character defender, BattleAction action)
{
// todo: other stuff too
if (defender is BattleNpc)
@ -19,15 +73,31 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.utils
{
((BattleNpc)defender).hateContainer.AddBaseHate(attacker);
}
((BattleNpc)defender).hateContainer.UpdateHate(attacker, damage);
((BattleNpc)defender).hateContainer.UpdateHate(attacker, action.amount);
}
defender.DelHP((short)damage);
defender.DelHP((short)action.amount);
}
public static int CalculateSpellDamage(Character attacker, Character defender, Ability spell)
public static int CalculateSpellDamage(Character attacker, Character defender, BattleCommand spell)
{
// todo: spell formulas and stuff (stoneskin, mods, stats, etc)
return 69;
}
public static uint CalculateSpellCost(Character caster, Character target, BattleCommand spell)
{
var scaledCost = spell.CalculateCost((uint)caster.charaWork.parameterSave.state_mainSkillLevel);
// todo: calculate cost for mob/player
if (caster.currentSubState == SetActorStatePacket.SUB_STATE_MONSTER)
{
}
else
{
}
return scaledCost;
}
}
}

View file

@ -13,6 +13,8 @@ using FFXIVClassic_Map_Server.actors.chara.ai.controllers;
using FFXIVClassic_Map_Server.packets.send.actor;
using FFXIVClassic_Map_Server.actors.chara.ai.state;
using FFXIVClassic_Map_Server.utils;
using FFXIVClassic_Map_Server.packets.send.actor.battle;
using FFXIVClassic_Map_Server.actors.chara.ai.utils;
namespace FFXIVClassic_Map_Server.Actors
{
@ -95,19 +97,19 @@ namespace FFXIVClassic_Map_Server.Actors
return true;
}
public override bool CanCast(Character target, Ability spell, ref SubPacket errorPacket)
public override bool CanCast(Character target, BattleCommand spell, ref SubPacket errorPacket)
{
// todo:
return false;
}
public override bool CanWeaponSkill(Character target, Ability skill, ref SubPacket errorPacket)
public override bool CanWeaponSkill(Character target, BattleCommand skill, ref SubPacket errorPacket)
{
// todo:
return false;
}
public override bool CanUseAbility(Character target, Ability ability, ref SubPacket errorPacket)
public override bool CanUseAbility(Character target, BattleCommand ability, ref SubPacket errorPacket)
{
// todo:
return false;
@ -183,7 +185,7 @@ namespace FFXIVClassic_Map_Server.Actors
}
// dont bother checking for any in-range players if going back to spawn
if (!this.isMovingToSpawn && this.aggroType != AggroType.None)
if (!this.isMovingToSpawn && this.aiContainer.pathFind.AtPoint() && this.aggroType != AggroType.None)
{
foreach (var player in zone.GetActorsAroundActor<Player>(this, 50))
{
@ -199,5 +201,18 @@ namespace FFXIVClassic_Map_Server.Actors
{
return this.isAtSpawn = Utils.DistanceSquared(positionX, positionY, positionZ, spawnX, spawnY, spawnZ) <= 2500.0f;
}
public override void OnAttack(State state, BattleAction action)
{
// player melee animation
uint battleAnimation = 0x19001000;
// todo: get hitrate and shit, handle protect effect and whatever
BattleUtils.TryAttack(this, state.GetTarget(), action);
zone.BroadcastPacketAroundActor(this,
BattleActionX01Packet.BuildPacket(actorId, actorId, target.actorId, (uint)battleAnimation,
(uint)action.effectId, (ushort)action.worldMasterTextId, (ushort)BattleActionX01PacketCommand.Attack, (ushort)action.amount, (byte)action.param)
);
}
}
}

View file

@ -23,6 +23,8 @@ using FFXIVClassic_Map_Server.packets.WorldPackets.Send.Group;
using FFXIVClassic_Map_Server.actors.chara.ai;
using FFXIVClassic_Map_Server.actors.chara.ai.controllers;
using FFXIVClassic_Map_Server.packets.send.actor.battle;
using FFXIVClassic_Map_Server.actors.chara.ai.utils;
using FFXIVClassic_Map_Server.actors.chara.ai.state;
namespace FFXIVClassic_Map_Server.Actors
{
@ -2016,7 +2018,7 @@ namespace FFXIVClassic_Map_Server.Actors
return true;
}
public override bool CanCast(Character target, Ability spell, ref SubPacket errorPacket)
public override bool CanCast(Character target, BattleCommand spell, ref SubPacket errorPacket)
{
// todo: move the ability specific stuff to ability.cs
if (target == null)
@ -2039,7 +2041,7 @@ namespace FFXIVClassic_Map_Server.Actors
return true;
}
public override bool CanWeaponSkill(Character target, Ability skill, ref SubPacket errorPacket)
public override bool CanWeaponSkill(Character target, BattleCommand skill, ref SubPacket errorPacket)
{
// todo: see worldmaster ids 32558~32557 for proper ko message and stuff
if (target == null)
@ -2061,5 +2063,24 @@ namespace FFXIVClassic_Map_Server.Actors
}
return true;
}
public override void OnAttack(State state, BattleAction action)
{
// melee attack animation
uint battleAnimation = 0x19001000;
// todo: change animation based on equipped weapon
action.effectId |= (uint)HitEffect.HitVisual1; // melee
// todo: get hitrate and shit, handle protect effect and whatever
BattleUtils.TryAttack(this, state.GetTarget(), action);
action.amount = BattleUtils.CalculateAttackDamage(this, state.GetTarget(), action);
//var packet = BattleActionX01Packet.BuildPacket(owner.actorId, owner.actorId, target.actorId, (uint)0x19001000, (uint)0x8000604, (ushort)0x765D, (ushort)BattleActionX01PacketCommand.Attack, (ushort)damage, (byte)0x1);
zone.BroadcastPacketAroundActor(this, BattleActionX01Packet.BuildPacket(actorId, actorId, action.targetId, (uint)battleAnimation,
0x8000000 | action.effectId, (ushort)action.worldMasterTextId, (ushort)BattleActionX01PacketCommand.Attack, (ushort)action.amount, (byte)action.param)
);
}
}
}

View file

@ -191,12 +191,16 @@ namespace FFXIVClassic_Map_Server.lua
return (int)res.Number;
}
}
else
{
Program.Log.Error($"LuaEngine.CallLuaStatusEffectFunction [{effect.GetName()}] Unable to find script {path}");
}
return -1;
}
public static int CallLuaAbilityFunction(Character actor, Ability ability, string folder, string functionName, params object[] args)
public static int CallLuaBattleCommandFunction(Character actor, BattleCommand command, string folder, string functionName, params object[] args)
{
string path = $"./scripts/{folder}/{ability.name}.lua";
string path = $"./scripts/commands/{folder}/{command.name}.lua";
if (File.Exists(path))
{
@ -208,7 +212,7 @@ namespace FFXIVClassic_Map_Server.lua
}
catch (Exception e)
{
Program.Log.Error($"LuaEngine.CallLuaSpellFunction [{functionName}] {e.Message}");
Program.Log.Error($"LuaEngine.CallLuaBattleCommandFunction [{functionName}] {e.Message}");
}
DynValue res = new DynValue();
@ -219,6 +223,10 @@ namespace FFXIVClassic_Map_Server.lua
return (int)res.Number;
}
}
else
{
Program.Log.Error($"LuaEngine.CallLuaBattleCommandFunction [{command.name}] Unable to find script {path}");
}
return -1;
}