mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-23 13:17:45 +00:00
Merge branch 'ai-open' of https://bitbucket.org/takhlaq/ffxiv-classic-server into ai
shitty line ending conflicts # Conflicts: # FFXIVClassic Map Server/lua/LuaEngine.cs
This commit is contained in:
commit
13af16ec0e
7 changed files with 374 additions and 98 deletions
|
@ -951,25 +951,7 @@ namespace FFXIVClassic_Map_Server
|
|||
}
|
||||
|
||||
//Load Hotbar
|
||||
query = @"
|
||||
SELECT
|
||||
hotbarSlot,
|
||||
commandId,
|
||||
recastTime
|
||||
FROM characters_hotbar WHERE characterId = @charId AND classId = @classId";
|
||||
|
||||
cmd = new MySqlCommand(query, conn);
|
||||
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
||||
cmd.Parameters.AddWithValue("@classId", player.charaWork.parameterSave.state_mainSkill[0]);
|
||||
using (MySqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
int index = reader.GetUInt16(0);
|
||||
player.charaWork.command[index+32] = reader.GetUInt32(1);
|
||||
player.charaWork.parameterSave.commandSlot_recastTime[index] = reader.GetUInt32(2);
|
||||
}
|
||||
}
|
||||
LoadHotbar(player);
|
||||
|
||||
//Load Scenario Quests
|
||||
query = @"
|
||||
|
@ -1208,6 +1190,143 @@ namespace FFXIVClassic_Map_Server
|
|||
}
|
||||
|
||||
}
|
||||
public static void EquipAbility(Player player, ushort hotbarSlot, uint commandId, uint recastTime)
|
||||
{
|
||||
//2700083201 is where abilities start. 2700083200 is for unequipping abilities. Trying to put this in the hotbar will crash the game, need to put 0 instead
|
||||
if (commandId > 2700083200)
|
||||
{
|
||||
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)))
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
MySqlCommand cmd;
|
||||
string query = @"
|
||||
INSERT INTO characters_hotbar
|
||||
(characterId, classId, hotbarSlot, commandId, recastTime)
|
||||
VALUES
|
||||
(@charId, @classId, @hotbarSlot, @commandId, @recastTime)
|
||||
ON DUPLICATE KEY UPDATE commandId=@commandId, recastTime=@recastTime;
|
||||
";
|
||||
|
||||
cmd = new MySqlCommand(query, conn);
|
||||
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
||||
cmd.Parameters.AddWithValue("@classId", player.charaWork.parameterSave.state_mainSkill[0]);
|
||||
cmd.Parameters.AddWithValue("@commandId", commandId);
|
||||
cmd.Parameters.AddWithValue("@hotbarSlot", hotbarSlot);
|
||||
cmd.Parameters.AddWithValue("@recastTime", recastTime);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (MySqlException e)
|
||||
{
|
||||
Program.Log.Error(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
conn.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Unequipping is done by sending an equip packet with 2700083200 as the ability and the hotbar slot of the action being unequipped
|
||||
public static void UnequipAbility(Player player, ushort hotbarSlot)
|
||||
{
|
||||
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)))
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
MySqlCommand cmd;
|
||||
string query = "";
|
||||
|
||||
//Drop
|
||||
List<Tuple<ushort, uint>> hotbarList = new List<Tuple<ushort, uint>>();
|
||||
query = @"
|
||||
DELETE FROM characters_hotbar
|
||||
WHERE characterId = @charId AND classId = @classId AND hotbarSlot = @hotbarSlot
|
||||
";
|
||||
cmd = new MySqlCommand(query, conn);
|
||||
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
||||
cmd.Parameters.AddWithValue("@classId", player.charaWork.parameterSave.state_mainSkill[0]);
|
||||
cmd.Parameters.AddWithValue("@hotbarSlot", hotbarSlot - 1);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (MySqlException e)
|
||||
{
|
||||
Program.Log.Error(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
conn.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void LoadHotbar(Player player)
|
||||
{
|
||||
string query;
|
||||
MySqlCommand cmd;
|
||||
|
||||
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)))
|
||||
{
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
//Load Hotbar
|
||||
query = @"
|
||||
SELECT
|
||||
hotbarSlot,
|
||||
commandId,
|
||||
recastTime
|
||||
FROM characters_hotbar WHERE characterId = @charId AND classId = @classId
|
||||
ORDER BY hotbarSlot";
|
||||
|
||||
cmd = new MySqlCommand(query, conn);
|
||||
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
||||
cmd.Parameters.AddWithValue("@classId", player.charaWork.parameterSave.state_mainSkill[0]);
|
||||
player.charaWork.commandBorder = 32;
|
||||
for (int i = player.charaWork.commandBorder; i < player.charaWork.commandCategory.Length; i++)
|
||||
{
|
||||
player.charaWork.command[i] = 0;
|
||||
player.charaWork.commandCategory[i] = 0;
|
||||
player.charaWork.parameterSave.commandSlot_recastTime[i - player.charaWork.commandBorder] = 0;
|
||||
}
|
||||
|
||||
using (MySqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
int index = reader.GetUInt16(0);
|
||||
player.charaWork.command[index] = reader.GetUInt32(1);
|
||||
player.charaWork.commandCategory[index] = 1;
|
||||
player.charaWork.parameterSave.commandSlot_recastTime[index - player.charaWork.commandBorder] = reader.GetUInt32(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MySqlException e)
|
||||
{
|
||||
Program.Log.Error(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
conn.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<InventoryItem> GetInventory(Player player, uint slotOffset, uint type)
|
||||
{
|
||||
|
|
|
@ -95,7 +95,8 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
hasMoved = true;
|
||||
}
|
||||
|
||||
public SubPacket CreateAddActorPacket(byte val) {
|
||||
public SubPacket CreateAddActorPacket(byte val)
|
||||
{
|
||||
return AddActorPacket.BuildPacket(actorId, val);
|
||||
}
|
||||
|
||||
|
@ -160,7 +161,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
updateMs = 150;
|
||||
}
|
||||
|
||||
if (forceUpdate || (hasMoved && ((this is Player ) || diffTime.Milliseconds >= updateMs)))
|
||||
if (forceUpdate || (hasMoved && ((this is Player) || diffTime.Milliseconds >= updateMs)))
|
||||
{
|
||||
hasMoved = (this.positionUpdates != null && this.positionUpdates.Count > 0);
|
||||
if (hasMoved)
|
||||
|
|
|
@ -213,10 +213,6 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
charaWork.command[14] = 0xA0F00000 | 29497;
|
||||
charaWork.command[15] = 0xA0F00000 | 22015;
|
||||
|
||||
charaWork.command[32] = 0xA0F00000 | 27191;
|
||||
charaWork.command[33] = 0xA0F00000 | 22302;
|
||||
charaWork.command[34] = 0xA0F00000 | 28466;
|
||||
|
||||
charaWork.commandAcquired[27150 - 26000] = true;
|
||||
|
||||
playerWork.questScenarioComplete[110001 - 110001] = true;
|
||||
|
@ -235,13 +231,9 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
|
||||
charaWork.commandCategory[0] = 1;
|
||||
charaWork.commandCategory[1] = 1;
|
||||
charaWork.commandCategory[32] = 1;
|
||||
charaWork.commandCategory[33] = 1;
|
||||
charaWork.commandCategory[34] = 1;
|
||||
|
||||
charaWork.parameterSave.commandSlot_compatibility[0] = true;
|
||||
charaWork.parameterSave.commandSlot_compatibility[1] = true;
|
||||
charaWork.parameterSave.commandSlot_compatibility[32] = true;
|
||||
|
||||
charaWork.commandBorder = 0x20;
|
||||
|
||||
|
@ -294,6 +286,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
|
||||
ActorInstantiatePacket.BuildPacket(actorId, actorName, className, lParams).DebugPrintSubPacket();
|
||||
|
||||
|
||||
return ActorInstantiatePacket.BuildPacket(actorId, actorName, className, lParams);
|
||||
}
|
||||
|
||||
|
@ -967,7 +960,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
|
||||
charaWork.parameterSave.state_mainSkill[0] = classId;
|
||||
charaWork.parameterSave.state_mainSkillLevel = charaWork.battleSave.skillLevel[classId-1];
|
||||
|
||||
Database.LoadHotbar(this);
|
||||
playerWork.restBonusExpRate = 0.0f;
|
||||
|
||||
ActorPropertyPacketUtil propertyBuilder = new ActorPropertyPacketUtil("charaWork/stateForAll", this);
|
||||
|
@ -977,6 +970,8 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
propertyBuilder.NewTarget("playerWork/expBonus");
|
||||
propertyBuilder.AddProperty("playerWork.restBonusExpRate");
|
||||
|
||||
QueuePackets(GetUpdateHotbarPacket(actorId).Done());
|
||||
|
||||
List<SubPacket> packets = propertyBuilder.Done();
|
||||
|
||||
foreach (SubPacket packet in packets)
|
||||
|
@ -1681,12 +1676,161 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
currentParty = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Update(double delta)
|
||||
{
|
||||
LuaEngine.GetInstance().CallLuaFunction(this, this, "OnUpdate", true, delta);
|
||||
}
|
||||
|
||||
//Update all the hotbar slots past the commandborder. Commands before the commandborder only need to be sent on init since they never change
|
||||
public ActorPropertyPacketUtil GetUpdateHotbarPacket(uint playerActorId)
|
||||
{
|
||||
List<ushort> slotsToUpdate = new List<ushort>();
|
||||
for (ushort i = charaWork.commandBorder; i < charaWork.commandBorder + 30; i++)
|
||||
{
|
||||
slotsToUpdate.Add(i);
|
||||
}
|
||||
|
||||
return GetUpdateHotbarPacket(playerActorId, slotsToUpdate);
|
||||
}
|
||||
|
||||
//Update select hotbar slots.
|
||||
public ActorPropertyPacketUtil GetUpdateHotbarPacket(uint playerActorId, List<ushort> slotsToUpdate)
|
||||
{
|
||||
ActorPropertyPacketUtil propPacketUtil = new ActorPropertyPacketUtil("charawork/command", this);
|
||||
|
||||
propPacketUtil.AddProperty("charaWork.commandBorder");
|
||||
|
||||
foreach (ushort slot in slotsToUpdate)
|
||||
{
|
||||
propPacketUtil.AddProperty(String.Format("charaWork.command[{0}]", slot));
|
||||
propPacketUtil.AddProperty(String.Format("charaWork.commandCategory[{0}]", slot));
|
||||
}
|
||||
|
||||
for (int i = 0; i < charaWork.parameterSave.commandSlot_compatibility.Length; i++)
|
||||
{
|
||||
//charaWork.parameterSave.commandSlot_compatibility[i] = true;
|
||||
// propPacketUtil.AddProperty(String.Format("charaWork.parameterSave.commandSlot_compatibility[{0}]", i));
|
||||
}
|
||||
|
||||
charaWork.parameterTemp.otherClassAbilityCount[0] = 3;
|
||||
charaWork.parameterTemp.otherClassAbilityCount[1] = 5;
|
||||
// charaWork.parameterTemp.giftCount[1] = 5;
|
||||
propPacketUtil.AddProperty("charaWork.parameterTemp.otherClassAbilityCount[0]");
|
||||
propPacketUtil.AddProperty("charaWork.parameterTemp.otherClassAbilityCount[1]");
|
||||
propPacketUtil.AddProperty("charaWork.parameterTemp.giftCount[1]");
|
||||
|
||||
ActorPropertyPacketUtil recastPacketUtil = new ActorPropertyPacketUtil("charaWork/commandDetailForSelf", this);
|
||||
for(int i = 0; i < charaWork.parameterSave.commandSlot_recastTime.Length; i++)
|
||||
{
|
||||
propPacketUtil.AddProperty(String.Format("charawork.parameterSave.commandSlot_recastTime[{0}]", i));
|
||||
propPacketUtil.AddProperty(String.Format("charawork.parameterTemp.maxCommandRecastTime[{0}]", i));
|
||||
}
|
||||
|
||||
QueuePackets(recastPacketUtil.Done());
|
||||
|
||||
return propPacketUtil;
|
||||
}
|
||||
|
||||
|
||||
public void EquipAbility(ushort hotbarSlot, uint commandId, uint recastTime)
|
||||
{
|
||||
//if (charaWork.commandAcquired[commandId])
|
||||
{
|
||||
uint trueCommandId = 0xA0F00000 | commandId;
|
||||
ushort trueHotbarSlot = (ushort)(hotbarSlot + charaWork.commandBorder - 1);
|
||||
ushort endOfHotbar = (ushort)(charaWork.commandBorder + 30);
|
||||
List<ushort> slotsToUpdate = new List<ushort>();
|
||||
if (trueCommandId != 2700083200)
|
||||
{
|
||||
bool canEquip = true;
|
||||
bool isAlreadyEquipped = false;
|
||||
|
||||
//If hotbar slot is 0, look for the first open slot
|
||||
if (hotbarSlot == 0)
|
||||
{
|
||||
trueHotbarSlot = findFirstCommandSlotById(0);
|
||||
int 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.
|
||||
canEquip = trueHotbarSlot < endOfHotbar && equippedSlot >= endOfHotbar;
|
||||
//If the command was found in the hotbar, mark it as already equipped
|
||||
isAlreadyEquipped = equippedSlot < endOfHotbar;
|
||||
}
|
||||
//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)
|
||||
{
|
||||
ushort oldSlot = findFirstCommandSlotById(trueCommandId);
|
||||
//If the command was found, update the old slot, otherwise it will just be overwritten
|
||||
if (oldSlot < endOfHotbar)
|
||||
{
|
||||
Database.EquipAbility(this, oldSlot, charaWork.command[trueHotbarSlot], recastTime);
|
||||
charaWork.command[oldSlot] = charaWork.command[trueHotbarSlot];
|
||||
slotsToUpdate.Add(oldSlot);
|
||||
}
|
||||
}
|
||||
|
||||
if (canEquip)
|
||||
{
|
||||
Actor a = Server.GetStaticActors(trueCommandId);
|
||||
Database.EquipAbility(this, trueHotbarSlot, trueCommandId, recastTime);
|
||||
charaWork.command[trueHotbarSlot] = trueCommandId;
|
||||
charaWork.commandCategory[trueHotbarSlot] = 1;
|
||||
slotsToUpdate.Add(trueHotbarSlot);
|
||||
|
||||
//"[Command] set."
|
||||
SendGameMessage(Server.GetWorldManager().GetActor(), 30603, 0x20, 0, commandId);
|
||||
}
|
||||
else if (isAlreadyEquipped)
|
||||
{
|
||||
//"That action is already set to an action slot."
|
||||
SendGameMessage(Server.GetWorldManager().GetActor(), 30719, 0x20, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
//"You cannot set any more actions."
|
||||
SendGameMessage(Server.GetWorldManager().GetActor(), 30720, 0x20, 0);
|
||||
}
|
||||
}
|
||||
//Unequip command
|
||||
else if (trueCommandId == 2700083200)
|
||||
{
|
||||
//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);
|
||||
Database.UnequipAbility(this, trueHotbarSlot);
|
||||
charaWork.command[trueHotbarSlot] = 0;
|
||||
slotsToUpdate.Add(trueHotbarSlot);
|
||||
//"[Command] removed."
|
||||
SendGameMessage(Server.GetWorldManager().GetActor(), 30747, 0x20, 0);
|
||||
|
||||
}
|
||||
ActorPropertyPacketUtil packet = GetUpdateHotbarPacket(actorId, slotsToUpdate);
|
||||
QueuePackets(packet.Done());
|
||||
}
|
||||
//action not acquired
|
||||
// else
|
||||
{
|
||||
//"You have not yet acquired that action."
|
||||
//SendGameMessage(Server.GetWorldManager().GetActor(), 30742, 0x20, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//Finds the first hotbar slot with a given commandId.
|
||||
//If the returned value is outside the hotbar, it indicates it wasn't found.
|
||||
private ushort findFirstCommandSlotById(uint commandId)
|
||||
{
|
||||
ushort firstSlot = (ushort)(charaWork.commandBorder + 30);
|
||||
|
||||
for (ushort i = charaWork.commandBorder; i < charaWork.commandBorder + 30; i++)
|
||||
{
|
||||
if (charaWork.command[i] == commandId)
|
||||
{
|
||||
firstSlot = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return firstSlot;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
14
data/scripts/commands/EquipAbilityCommand.lua
Normal file
14
data/scripts/commands/EquipAbilityCommand.lua
Normal file
|
@ -0,0 +1,14 @@
|
|||
require ("global")
|
||||
--player: Player that called this command
|
||||
--equipAbilityWidget: Widget that calls this command
|
||||
--triggername: Event Starter ?
|
||||
--slot: Which slot the ability will go into
|
||||
--ability: Ability being equipped
|
||||
|
||||
|
||||
function onEventStarted(player, equipAbilityWidget, triggername, slot, ability, unkown, arg1, arg2, arg3, arg4, arg5, arg6)
|
||||
if ability then
|
||||
player:EquipAbility(slot, ability, 1);
|
||||
end
|
||||
player:endEvent();
|
||||
end
|
|
@ -1,7 +1,6 @@
|
|||
local initClassItems, initRaceItems;
|
||||
|
||||
function onBeginLogin(player)
|
||||
|
||||
--New character, set the initial quest
|
||||
if (player:GetPlayTime(false) == 0) then
|
||||
initialTown = player:GetInitialTown();
|
||||
|
@ -60,7 +59,6 @@ function onBeginLogin(player)
|
|||
player:GetQuest(110009):ClearQuestData();
|
||||
player:GetQuest(110009):ClearQuestFlags();
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function onLogin(player)
|
||||
|
|
Loading…
Add table
Reference in a new issue