From 4f80023156d222881e6d654900f9735c38e7db6a Mon Sep 17 00:00:00 2001 From: Yogurt Date: Wed, 29 May 2019 22:59:24 -0700 Subject: [PATCH] Target flag and bug fixes Add new flags for MainTarget's party, which allows for Protect to buff other parties. Fixed incorrect script function calls Fixed bug causing World server to get stuck in a loop --- FFXIVClassic Map Server/Database.cs | 25 +++++++++-- .../actors/chara/ai/helpers/TargetFind.cs | 43 ++++++++++++------- .../actors/chara/ai/state/AbilityState.cs | 4 +- .../actors/chara/ai/state/AttackState.cs | 4 +- .../actors/chara/ai/state/MagicState.cs | 6 +-- .../actors/chara/ai/state/WeaponSkillState.cs | 6 +-- FFXIVClassic Map Server/actors/group/Group.cs | 9 ++-- 7 files changed, 65 insertions(+), 32 deletions(-) diff --git a/FFXIVClassic Map Server/Database.cs b/FFXIVClassic Map Server/Database.cs index aee01f0e..579e6568 100644 --- a/FFXIVClassic Map Server/Database.cs +++ b/FFXIVClassic Map Server/Database.cs @@ -2413,8 +2413,8 @@ namespace FFXIVClassic_Map_Server battleCommand.job = reader.GetByte("classJob"); battleCommand.level = reader.GetByte("lvl"); battleCommand.requirements = (BattleCommandRequirements)reader.GetUInt16("requirements"); - battleCommand.mainTarget = (ValidTarget)reader.GetByte("mainTarget"); - battleCommand.validTarget = (ValidTarget)reader.GetByte("validTarget"); + battleCommand.mainTarget = (ValidTarget)reader.GetUInt16("mainTarget"); + battleCommand.validTarget = (ValidTarget)reader.GetUInt16("validTarget"); battleCommand.aoeType = (TargetFindAOEType)reader.GetByte("aoeType"); battleCommand.basePotency = reader.GetUInt16("basePotency"); battleCommand.numHits = reader.GetByte("numHits"); @@ -2454,7 +2454,26 @@ namespace FFXIVClassic_Map_Server battleCommand.actionType = (ActionType)reader.GetInt16("actionType"); battleCommand.accuracyModifier = reader.GetFloat("accuracyMod"); battleCommand.worldMasterTextId = reader.GetUInt16("worldMasterTextId"); - lua.LuaEngine.LoadBattleCommandScript(battleCommand, "weaponskill"); + + string folderName = ""; + + switch (battleCommand.commandType) + { + case CommandType.AutoAttack: + folderName = "autoattack"; + break; + case CommandType.WeaponSkill: + folderName = "weaponskill"; + break; + case CommandType.Ability: + folderName = "ability"; + break; + case CommandType.Spell: + folderName = "magic"; + break; + } + + lua.LuaEngine.LoadBattleCommandScript(battleCommand, folderName); battleCommandDict.Add(id, battleCommand); Tuple tuple = Tuple.Create(battleCommand.job, battleCommand.level); diff --git a/FFXIVClassic Map Server/actors/chara/ai/helpers/TargetFind.cs b/FFXIVClassic Map Server/actors/chara/ai/helpers/TargetFind.cs index 5801debe..d2c94e00 100644 --- a/FFXIVClassic Map Server/actors/chara/ai/helpers/TargetFind.cs +++ b/FFXIVClassic Map Server/actors/chara/ai/helpers/TargetFind.cs @@ -18,20 +18,24 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai public enum ValidTarget : ushort { None = 0x00, - Self = 0x01, //Can be used on self (if this flag isn't set and target is self, return false) - SelfOnly = 0x02, //Must be used on self (if this flag is set and target isn't self, return false) - Party = 0x4, //Can be used on party members - PartyOnly = 0x8, //Must be used on party members - Ally = 0x10, //Can be used on allies - AllyOnly = 0x20, //Must be used on allies - NPC = 0x40, //Can be used on static NPCs - NPCOnly = 0x60, //Must be used on static NPCs - Enemy = 0x80, //Can be used on enemies - EnemyOnly = 0x100, //Must be used on enemies - Object = 0x200, //Can be used on objects - ObjectOnly = 0x400, //Must be used on objects - Corpse = 0x600, //Can be used on corpses - CorpseOnly = 0x800, //Must be used on corpses + Self = 0x01, //Can be used on self (if this flag isn't set and target is self, return false) + SelfOnly = 0x02, //Must be used on self (if this flag is set and target isn't self, return false) + Party = 0x4, //Can be used on party members + PartyOnly = 0x8, //Must be used on party members + Ally = 0x10, //Can be used on allies + AllyOnly = 0x20, //Must be used on allies + NPC = 0x40, //Can be used on static NPCs + NPCOnly = 0x80, //Must be used on static NPCs + Enemy = 0x100, //Can be used on enemies + EnemyOnly = 0x200, //Must be used on enemies + Object = 0x400, //Can be used on objects + ObjectOnly = 0x800, //Must be used on objects + Corpse = 0x1000, //Can be used on corpses + CorpseOnly = 0x2000, //Must be used on corpses + + //These are only used for ValidTarget, not MainTarget + MainTargetParty = 0x4000, //Can be used on main target's party (This will basically always be true.) + MainTargetPartyOnly = 0x8000, //Must be used on main target's party (This is for Protect basically.) } /// Targeting from/to different entity types @@ -94,7 +98,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai { Reset(); this.owner = owner; - this.masterTarget = mainTarget == null ? owner : mainTarget; + this.mainTarget = mainTarget == null ? owner : mainTarget; } public void Reset() @@ -393,6 +397,15 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai if (validTarget == ValidTarget.Self && aoeType == TargetFindAOEType.None && owner != target) return false; + //This skill can't be used on main target's party members and target is a party member of main target + if ((validTarget & ValidTarget.MainTargetParty) == 0 && target.currentParty == mainTarget.currentParty) + return false; + + //This skill must be used on main target's party members and target is not a party member of main target + if ((validTarget & ValidTarget.MainTargetPartyOnly) != 0 && target.currentParty != mainTarget.currentParty) + return false; + + // this is fuckin retarded, think of a better way l8r if (!ignoreAOE) { diff --git a/FFXIVClassic Map Server/actors/chara/ai/state/AbilityState.cs b/FFXIVClassic Map Server/actors/chara/ai/state/AbilityState.cs index 96b5afaf..955fe22b 100644 --- a/FFXIVClassic Map Server/actors/chara/ai/state/AbilityState.cs +++ b/FFXIVClassic Map Server/actors/chara/ai/state/AbilityState.cs @@ -21,7 +21,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state { this.startTime = DateTime.Now; this.skill = Server.GetWorldManager().GetBattleCommand(skillId); - var returnCode = skill.CallLuaFunction(owner, "ability", "onAbilityPrepare", owner, target, skill); + var returnCode = skill.CallLuaFunction(owner, "onAbilityPrepare", owner, target, skill); this.target = (skill.mainTarget & ValidTarget.SelfOnly) != 0 ? owner : target; @@ -39,7 +39,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state public override void OnStart() { - var returnCode = skill.CallLuaFunction(owner, "ability", "onAbilityStart", owner, target, skill); + var returnCode = skill.CallLuaFunction(owner, "onAbilityStart", owner, target, skill); if (returnCode != 0) { diff --git a/FFXIVClassic Map Server/actors/chara/ai/state/AttackState.cs b/FFXIVClassic Map Server/actors/chara/ai/state/AttackState.cs index df042941..febcdcdc 100644 --- a/FFXIVClassic Map Server/actors/chara/ai/state/AttackState.cs +++ b/FFXIVClassic Map Server/actors/chara/ai/state/AttackState.cs @@ -112,8 +112,8 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state attackCommand.range = 5; attackCommand.rangeHeight = 10; attackCommand.worldMasterTextId = 0x765D; - attackCommand.mainTarget = (ValidTarget)384; - attackCommand.validTarget = (ValidTarget)384; + attackCommand.mainTarget = (ValidTarget)768; + attackCommand.validTarget = (ValidTarget)17152; attackCommand.commandType = CommandType.AutoAttack; attackCommand.numHits = (byte)owner.GetMod(Modifier.HitCount); attackCommand.basePotency = 100; diff --git a/FFXIVClassic Map Server/actors/chara/ai/state/MagicState.cs b/FFXIVClassic Map Server/actors/chara/ai/state/MagicState.cs index 6564cb03..2162dc9c 100644 --- a/FFXIVClassic Map Server/actors/chara/ai/state/MagicState.cs +++ b/FFXIVClassic Map Server/actors/chara/ai/state/MagicState.cs @@ -24,7 +24,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state this.startPos = owner.GetPosAsVector3(); this.startTime = DateTime.Now; this.spell = Server.GetWorldManager().GetBattleCommand(spellId); - var returnCode = spell.CallLuaFunction(owner, "magic", "onMagicPrepare", owner, target, spell); + var returnCode = spell.CallLuaFunction(owner, "onMagicPrepare", owner, target, spell); //Modify spell based on status effects. Need to do it here because they can modify cast times List effects = owner.statusEffects.GetStatusEffectsByFlag((uint)(StatusEffectFlags.ActivateOnCastStart)); @@ -49,7 +49,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state public override void OnStart() { - var returnCode = spell.CallLuaFunction(owner, "magic", "onMagicStart", owner, target, spell); + var returnCode = spell.CallLuaFunction(owner, "onMagicStart", owner, target, spell); if (returnCode != 0) { @@ -68,7 +68,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state Player p = (Player)owner; if (spell.comboStep == 1 || ((p.playerWork.comboNextCommandId[0] == spell.id || p.playerWork.comboNextCommandId[1] == spell.id))) { - spell.CallLuaFunction(owner, "magic", "onCombo", owner, target, spell); + spell.CallLuaFunction(owner, "onCombo", owner, target, spell); spell.isCombo = true; } } diff --git a/FFXIVClassic Map Server/actors/chara/ai/state/WeaponSkillState.cs b/FFXIVClassic Map Server/actors/chara/ai/state/WeaponSkillState.cs index 1de6df32..3b0da761 100644 --- a/FFXIVClassic Map Server/actors/chara/ai/state/WeaponSkillState.cs +++ b/FFXIVClassic Map Server/actors/chara/ai/state/WeaponSkillState.cs @@ -22,7 +22,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state this.startTime = DateTime.Now; this.skill = Server.GetWorldManager().GetBattleCommand(skillId); - var returnCode = skill.CallLuaFunction(owner, "weaponskill", "onSkillPrepare", owner, target, skill); + var returnCode = skill.CallLuaFunction(owner, "onSkillPrepare", owner, target, skill); this.target = (skill.mainTarget & ValidTarget.SelfOnly) != 0 ? owner : target; @@ -40,7 +40,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state public override void OnStart() { - var returnCode = skill.CallLuaFunction(owner, "weaponskill", "onSkillStart", owner, target, skill); + var returnCode = skill.CallLuaFunction(owner, "onSkillStart", owner, target, skill); if (returnCode != 0) { @@ -69,7 +69,7 @@ namespace FFXIVClassic_Map_Server.actors.chara.ai.state //If owner is a player and the skill being used is part of the current combo if (p.playerWork.comboNextCommandId[0] == skill.id || p.playerWork.comboNextCommandId[1] == skill.id) { - skill.CallLuaFunction(owner, "weaponskill", "onCombo", owner, target, skill); + skill.CallLuaFunction(owner, "onCombo", owner, target, skill); skill.isCombo = true; } //or if this just the start of a combo diff --git a/FFXIVClassic Map Server/actors/group/Group.cs b/FFXIVClassic Map Server/actors/group/Group.cs index c8a24047..e5f1e164 100644 --- a/FFXIVClassic Map Server/actors/group/Group.cs +++ b/FFXIVClassic Map Server/actors/group/Group.cs @@ -127,13 +127,14 @@ namespace FFXIVClassic_Map_Server.actors.group while (true) { - if (GetMemberCount() - currentIndex >= 64) + int memberCount = Math.Min(GetMemberCount(), members.Count); + if (memberCount - currentIndex >= 64) session.QueuePacket(GroupMembersX64Packet.buildPacket(session.id, session.GetActor().zoneId, time, members, ref currentIndex)); - else if (GetMemberCount() - currentIndex >= 32) + else if (memberCount - currentIndex >= 32) session.QueuePacket(GroupMembersX32Packet.buildPacket(session.id, session.GetActor().zoneId, time, members, ref currentIndex)); - else if (GetMemberCount() - currentIndex >= 16) + else if (memberCount - currentIndex >= 16) session.QueuePacket(GroupMembersX16Packet.buildPacket(session.id, session.GetActor().zoneId, time, members, ref currentIndex)); - else if (GetMemberCount() - currentIndex > 0) + else if (memberCount - currentIndex > 0) session.QueuePacket(GroupMembersX08Packet.buildPacket(session.id, session.GetActor().zoneId, time, members, ref currentIndex)); else break;