1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-22 04:37:47 +00:00

Merged in skeletonhorn/ffxiv-classic-server-ai-fork/ai-open (pull request #2)

Ai open
This commit is contained in:
yogurt 2017-08-22 20:17:50 +00:00 committed by Tahir Akhlaq
commit c79b5c9992
3 changed files with 84 additions and 44 deletions

View file

@ -1286,7 +1286,7 @@ namespace FFXIVClassic_Map_Server
cmd = new MySqlCommand(query, conn); cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId); cmd.Parameters.AddWithValue("@charId", player.actorId);
cmd.Parameters.AddWithValue("@classId", player.charaWork.parameterSave.state_mainSkill[0]); cmd.Parameters.AddWithValue("@classId", player.charaWork.parameterSave.state_mainSkill[0]);
cmd.Parameters.AddWithValue("@hotbarSlot", hotbarSlot - 1); cmd.Parameters.AddWithValue("@hotbarSlot", hotbarSlot);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
catch (MySqlException e) catch (MySqlException e)
@ -1336,9 +1336,16 @@ namespace FFXIVClassic_Map_Server
while (reader.Read()) while (reader.Read())
{ {
int index = reader.GetUInt16(0); int index = reader.GetUInt16(0);
player.charaWork.command[index] = reader.GetUInt32(1); uint trueCommandId = reader.GetUInt32(1);
player.charaWork.command[index] = trueCommandId;
player.charaWork.commandCategory[index] = 1; player.charaWork.commandCategory[index] = 1;
player.charaWork.parameterSave.commandSlot_recastTime[index - player.charaWork.commandBorder] = reader.GetUInt32(2); player.charaWork.parameterSave.commandSlot_recastTime[index - player.charaWork.commandBorder] = reader.GetUInt32(2);
//Recast timer
Ability 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);
} }
} }
} }

View file

@ -399,7 +399,15 @@ namespace FFXIVClassic_Map_Server.Actors
for (int i = 0; i < charaWork.command.Length; i++) for (int i = 0; i < charaWork.command.Length; i++)
{ {
if (charaWork.command[i] != 0) if (charaWork.command[i] != 0)
{
propPacketUtil.AddProperty(String.Format("charaWork.command[{0}]", i)); propPacketUtil.AddProperty(String.Format("charaWork.command[{0}]", i));
//Recast Timers
if(i >= charaWork.commandBorder)
{
propPacketUtil.AddProperty(String.Format("charaWork.parameterTemp.maxCommandRecastTime[{0}]", i - charaWork.commandBorder));
propPacketUtil.AddProperty(String.Format("charaWork.parameterSave.commandSlot_recastTime[{0}]", i - charaWork.commandBorder));
}
}
} }
@ -968,7 +976,6 @@ namespace FFXIVClassic_Map_Server.Actors
charaWork.parameterSave.state_mainSkill[0] = classId; charaWork.parameterSave.state_mainSkill[0] = classId;
charaWork.parameterSave.state_mainSkillLevel = charaWork.battleSave.skillLevel[classId-1]; charaWork.parameterSave.state_mainSkillLevel = charaWork.battleSave.skillLevel[classId-1];
Database.LoadHotbar(this);
playerWork.restBonusExpRate = 0.0f; playerWork.restBonusExpRate = 0.0f;
ActorPropertyPacketUtil propertyBuilder = new ActorPropertyPacketUtil("charaWork/stateForAll", this); ActorPropertyPacketUtil propertyBuilder = new ActorPropertyPacketUtil("charaWork/stateForAll", this);
@ -978,7 +985,18 @@ namespace FFXIVClassic_Map_Server.Actors
propertyBuilder.NewTarget("playerWork/expBonus"); propertyBuilder.NewTarget("playerWork/expBonus");
propertyBuilder.AddProperty("playerWork.restBonusExpRate"); propertyBuilder.AddProperty("playerWork.restBonusExpRate");
QueuePackets(GetUpdateHotbarPacket(actorId).Done()); Database.LoadHotbar(this);
var time = Utils.UnixTimeStampUTC();
for(int i = charaWork.commandBorder; i < charaWork.command.Length; i++)
{
if(charaWork.command[i] != 0)
{
charaWork.parameterSave.commandSlot_recastTime[i - charaWork.commandBorder] = time + charaWork.parameterTemp.maxCommandRecastTime[i - charaWork.commandBorder];
}
}
UpdateHotbar();
List<SubPacket> packets = propertyBuilder.Done(); List<SubPacket> packets = propertyBuilder.Done();
@ -1747,58 +1765,62 @@ namespace FFXIVClassic_Map_Server.Actors
aiContainer.InternalDie(tick, 60); aiContainer.InternalDie(tick, 60);
} }
//Update all the hotbar slots past the commandborder. Commands before the commandborder only need to be sent on init since they never change //Update commands and recast timers for the entire hotbar
public ActorPropertyPacketUtil GetUpdateHotbarPacket(uint playerActorId) public void UpdateHotbar()
{ {
List<ushort> slotsToUpdate = new List<ushort>(); List<ushort> slotsToUpdate = new List<ushort>();
for (ushort i = charaWork.commandBorder; i < charaWork.commandBorder + 30; i++) for (ushort i = charaWork.commandBorder; i < charaWork.commandBorder + 30; i++)
{ {
slotsToUpdate.Add(i); slotsToUpdate.Add(i);
} }
UpdateHotbar(slotsToUpdate);
return GetUpdateHotbarPacket(playerActorId, slotsToUpdate);
} }
//Update select hotbar slots. //Updates the hotbar and recast timers for only certain hotbar slots
public ActorPropertyPacketUtil GetUpdateHotbarPacket(uint playerActorId, List<ushort> slotsToUpdate) public void UpdateHotbar(List<ushort> slotsToUpdate)
{
UpdateHotbarCommands(slotsToUpdate);
UpdateRecastTimers(slotsToUpdate);
}
//Update command ids for the passed in hotbar slots
public void UpdateHotbarCommands(List<ushort> slotsToUpdate)
{ {
ActorPropertyPacketUtil propPacketUtil = new ActorPropertyPacketUtil("charaWork/command", this); ActorPropertyPacketUtil propPacketUtil = new ActorPropertyPacketUtil("charaWork/command", this);
ActorPropertyPacketUtil compatibiltyUtil = new ActorPropertyPacketUtil("charaWork/commandDetailForSelf", this);
propPacketUtil.AddProperty("charaWork.commandBorder");
foreach (ushort slot in slotsToUpdate) foreach (ushort slot in slotsToUpdate)
{ {
propPacketUtil.AddProperty(String.Format("charaWork.command[{0}]", slot)); propPacketUtil.AddProperty(String.Format("charaWork.command[{0}]", slot));
propPacketUtil.AddProperty(String.Format("charaWork.commandCategory[{0}]", slot)); propPacketUtil.AddProperty(String.Format("charaWork.commandCategory[{0}]", slot));
} }
for (int i = 0; i < charaWork.parameterSave.commandSlot_compatibility.Length; i++) //Enable or disable slots based on whether there is an ability in that slot
foreach (ushort slot in slotsToUpdate)
{ {
//charaWork.parameterSave.commandSlot_compatibility[i] = true; charaWork.parameterSave.commandSlot_compatibility[slot - charaWork.commandBorder] = charaWork.command[slot] != 0;
// propPacketUtil.AddProperty(String.Format("charaWork.parameterSave.commandSlot_compatibility[{0}]", i)); compatibiltyUtil.AddProperty(String.Format("charaWork.parameterSave.commandSlot_compatibility[{0}]", slot - charaWork.commandBorder));
} }
charaWork.parameterTemp.otherClassAbilityCount[0] = 3; QueuePackets(propPacketUtil.Done());
charaWork.parameterTemp.otherClassAbilityCount[1] = 5; QueuePackets(compatibiltyUtil.Done());
// charaWork.parameterTemp.giftCount[1] = 5; }
propPacketUtil.AddProperty("charaWork.parameterTemp.otherClassAbilityCount[0]");
propPacketUtil.AddProperty("charaWork.parameterTemp.otherClassAbilityCount[1]");
propPacketUtil.AddProperty("charaWork.parameterTemp.giftCount[1]");
//Update recast timers for the passed in hotbar slots
public void UpdateRecastTimers(List<ushort> slotsToUpdate)
{
ActorPropertyPacketUtil recastPacketUtil = new ActorPropertyPacketUtil("charaWork/commandDetailForSelf", this); ActorPropertyPacketUtil recastPacketUtil = new ActorPropertyPacketUtil("charaWork/commandDetailForSelf", this);
for(int i = 0; i < charaWork.parameterSave.commandSlot_recastTime.Length; i++)
foreach (ushort slot in slotsToUpdate)
{ {
propPacketUtil.AddProperty(String.Format("charawork.parameterSave.commandSlot_recastTime[{0}]", i)); recastPacketUtil.AddProperty(String.Format("charaWork.parameterTemp.maxCommandRecastTime[{0}]", slot - charaWork.commandBorder));
propPacketUtil.AddProperty(String.Format("charawork.parameterTemp.maxCommandRecastTime[{0}]", i)); recastPacketUtil.AddProperty(String.Format("charaWork.parameterSave.commandSlot_recastTime[{0}]", slot - charaWork.commandBorder));
} }
QueuePackets(recastPacketUtil.Done()); QueuePackets(recastPacketUtil.Done());
return propPacketUtil;
} }
public void EquipAbility(ushort hotbarSlot, uint commandId, uint recastTime) public void EquipAbility(ushort hotbarSlot, ushort commandId)
{ {
//if (charaWork.commandAcquired[commandId]) //if (charaWork.commandAcquired[commandId])
{ {
@ -1814,8 +1836,8 @@ namespace FFXIVClassic_Map_Server.Actors
//If hotbar slot is 0, look for the first open slot //If hotbar slot is 0, look for the first open slot
if (hotbarSlot == 0) if (hotbarSlot == 0)
{ {
trueHotbarSlot = findFirstCommandSlotById(0); trueHotbarSlot = FindFirstCommandSlotById(0);
int equippedSlot = findFirstCommandSlotById(trueCommandId); ushort equippedSlot = FindFirstCommandSlotById(trueCommandId);
//We can only equip a command if there is an open hotbar slot and if the command was not found in the hotbar. //We can only equip a command if there is an open hotbar slot and if the command was not found in the hotbar.
canEquip = trueHotbarSlot < endOfHotbar && equippedSlot >= endOfHotbar; canEquip = trueHotbarSlot < endOfHotbar && equippedSlot >= endOfHotbar;
//If the command was found in the hotbar, mark it as already equipped //If the command was found in the hotbar, mark it as already equipped
@ -1824,32 +1846,47 @@ namespace FFXIVClassic_Map_Server.Actors
//If the slot the command is being moved to is occupied, move that command to the slot currently occupied by the command being placed. //If the slot the command is being moved to is occupied, move that command to the slot currently occupied by the command being placed.
else if (charaWork.command[trueHotbarSlot] != trueCommandId) else if (charaWork.command[trueHotbarSlot] != trueCommandId)
{ {
ushort oldSlot = findFirstCommandSlotById(trueCommandId); //Search for where the ability we're equipping is already equipped
ushort oldSlot = FindFirstCommandSlotById(trueCommandId);
//If the command was found, update the old slot, otherwise it will just be overwritten //If the command was found, update the old slot, otherwise it will just be overwritten
if (oldSlot < endOfHotbar) if (oldSlot < endOfHotbar)
{ {
Database.EquipAbility(this, oldSlot, charaWork.command[trueHotbarSlot], recastTime);
charaWork.command[oldSlot] = charaWork.command[trueHotbarSlot]; charaWork.command[oldSlot] = charaWork.command[trueHotbarSlot];
slotsToUpdate.Add(oldSlot); slotsToUpdate.Add(oldSlot);
//Need to update the old slot's recast timer as well
charaWork.parameterTemp.maxCommandRecastTime[oldSlot - charaWork.commandBorder] = charaWork.parameterTemp.maxCommandRecastTime[trueHotbarSlot - charaWork.commandBorder];
//I don't know how the game handled moving abilities in terms of cooldowns.
//I'm assuming they just keep whatever their current cooldown was instead of being reset to their max but SE were dicks in 1.0 so who knows
charaWork.parameterSave.commandSlot_recastTime[oldSlot - charaWork.commandBorder] = charaWork.parameterSave.commandSlot_recastTime[trueHotbarSlot - charaWork.commandBorder];
Database.EquipAbility(this, oldSlot, charaWork.command[trueHotbarSlot], charaWork.parameterSave.commandSlot_recastTime[oldSlot - charaWork.commandBorder]);
} }
} }
if (canEquip) if (canEquip)
{ {
Actor a = Server.GetStaticActors(trueCommandId);
Database.EquipAbility(this, trueHotbarSlot, trueCommandId, recastTime);
charaWork.command[trueHotbarSlot] = trueCommandId; charaWork.command[trueHotbarSlot] = trueCommandId;
charaWork.commandCategory[trueHotbarSlot] = 1; charaWork.commandCategory[trueHotbarSlot] = 1;
//Set recast time
ushort maxRecastTime = (ushort)Server.GetWorldManager().GetAbility(commandId).recastTimeSeconds;
uint recastEnd = Utils.UnixTimeStampUTC() + maxRecastTime;
charaWork.parameterTemp.maxCommandRecastTime[trueHotbarSlot - charaWork.commandBorder] = maxRecastTime;
charaWork.parameterSave.commandSlot_recastTime[trueHotbarSlot - charaWork.commandBorder] = recastEnd;
slotsToUpdate.Add(trueHotbarSlot); slotsToUpdate.Add(trueHotbarSlot);
Database.EquipAbility(this, trueHotbarSlot, trueCommandId, recastEnd);
//"[Command] set." //"[Command] set."
SendGameMessage(Server.GetWorldManager().GetActor(), 30603, 0x20, 0, commandId); SendGameMessage(Server.GetWorldManager().GetActor(), 30603, 0x20, 0, (int)commandId);
} }
//Ability is already equipped
else if (isAlreadyEquipped) else if (isAlreadyEquipped)
{ {
//"That action is already set to an action slot." //"That action is already set to an action slot."
SendGameMessage(Server.GetWorldManager().GetActor(), 30719, 0x20, 0); SendGameMessage(Server.GetWorldManager().GetActor(), 30719, 0x20, 0);
} }
//Hotbar full
else else
{ {
//"You cannot set any more actions." //"You cannot set any more actions."
@ -1860,17 +1897,13 @@ namespace FFXIVClassic_Map_Server.Actors
else if (trueCommandId == 2700083200 && charaWork.command[trueHotbarSlot] != 0) else if (trueCommandId == 2700083200 && charaWork.command[trueHotbarSlot] != 0)
{ {
//Need to get the commandId this way because when unequipping an ability the commandId is 0. //Need to get the commandId this way because when unequipping an ability the commandId is 0.
commandId = charaWork.command[trueHotbarSlot] ^ 2700083200;
SendGameMessage(Server.GetWorldManager().GetActor(), 30604, 0x20, 0, charaWork.command[trueHotbarSlot] ^ 2700083200); SendGameMessage(Server.GetWorldManager().GetActor(), 30604, 0x20, 0, charaWork.command[trueHotbarSlot] ^ 2700083200);
Database.UnequipAbility(this, trueHotbarSlot); Database.UnequipAbility(this, trueHotbarSlot);
charaWork.command[trueHotbarSlot] = 0; charaWork.command[trueHotbarSlot] = 0;
slotsToUpdate.Add(trueHotbarSlot); slotsToUpdate.Add(trueHotbarSlot);
//"[Command] removed."
SendGameMessage(Server.GetWorldManager().GetActor(), 30747, 0x20, 0);
} }
ActorPropertyPacketUtil packet = GetUpdateHotbarPacket(actorId, slotsToUpdate); UpdateHotbar(slotsToUpdate);
QueuePackets(packet.Done());
} }
//action not acquired //action not acquired
// else // else
@ -1882,7 +1915,7 @@ namespace FFXIVClassic_Map_Server.Actors
//Finds the first hotbar slot with a given commandId. //Finds the first hotbar slot with a given commandId.
//If the returned value is outside the hotbar, it indicates it wasn't found. //If the returned value is outside the hotbar, it indicates it wasn't found.
private ushort findFirstCommandSlotById(uint commandId) private ushort FindFirstCommandSlotById(uint commandId)
{ {
ushort firstSlot = (ushort)(charaWork.commandBorder + 30); ushort firstSlot = (ushort)(charaWork.commandBorder + 30);

View file

@ -8,7 +8,7 @@ require ("global")
function onEventStarted(player, equipAbilityWidget, triggername, slot, ability, unkown, arg1, arg2, arg3, arg4, arg5, arg6) function onEventStarted(player, equipAbilityWidget, triggername, slot, ability, unkown, arg1, arg2, arg3, arg4, arg5, arg6)
if ability then if ability then
player:EquipAbility(slot, ability, 1); player:EquipAbility(slot, ability);
end end
player:endEvent(); player:endEvent();
end end