Added a load player character function to the database class. As I went through, changed the various properties to their correct datatype. Also added Work object to Character.

This commit is contained in:
Filip Maj 2016-01-09 23:22:10 -05:00
parent c9f35a207b
commit 4dec77aa69
8 changed files with 353 additions and 16 deletions

View File

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using FFXIVClassic_Lobby_Server.common;
using FFXIVClassic_Map_Server.dataobjects.database;
using FFXIVClassic_Map_Server.dataobjects.chara.npc;
using FFXIVClassic_Map_Server.dataobjects.chara;
namespace FFXIVClassic_Lobby_Server
{
@ -158,5 +159,306 @@ namespace FFXIVClassic_Lobby_Server
}
}
public static void loadPlayerCharacter(Player player, bool isMe)
{
//Load basic info
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();
if (isMe)
{
query = @"
SELECT
name,
positionX,
positionY,
positionZ,
rotation,
actorState,
currentZoneId,
currentClassJob,
gcCurrent,
gcLimsaRank,
gcGridaniaRank,
gcUldahRank,
currentTitle,
guardian,
birthDay,
birthMonth,
initialNation,
currentParty,
restBonus,
achievementPoints
FROM characters WHERE id = @charId";
}
else
{
query = @"
SELECT
name,
positionX,
positionY,
positionZ,
rotation,
actorState,
currentZoneId,
currentClassJob,
gcCurrent,
gcLimsaRank,
gcGridaniaRank,
gcUldahRank,
currentTitle
FROM characters WHERE id = @charId";
}
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
player.displayNameId = 0xFFFFFFFF;
player.customDisplayName = reader.GetString(0);
player.oldPositionX = player.positionX = reader.GetFloat(1);
player.oldPositionY = player.positionY = reader.GetFloat(2);
player.oldPositionZ = player.positionZ = reader.GetFloat(3);
player.oldRotation = player.rotation = reader.GetFloat(4);
player.currentMainState = reader.GetUInt16(5);
player.currentZoneId = reader.GetUInt32(6);
reader.GetByte(7);
player.gcCurrent = reader.GetByte(8);
player.gcRankLimsa = reader.GetByte(9);
player.gcRankGridania = reader.GetByte(10);
player.gcRankUldah = reader.GetByte(11);
player.currentTitle = reader.GetUInt32(12);
if (isMe)
{
player.playerWork.guardian = reader.GetByte(13);
player.playerWork.birthdayDay = reader.GetByte(14);
player.playerWork.birthdayMonth = reader.GetByte(15);
player.playerWork.initialTown = reader.GetByte(16);
player.playerWork.restBonusExpRate = reader.GetInt32(17);
player.achievementPoints = reader.GetUInt32(18);
}
}
//Load appearance
query = @"
SELECT
baseId,
tribe,
size,
voice,
skinColor,
hairStyle,
hairColor,
hairHighlightColor,
eyeColor,
faceType,
faceEyebrows,
faceEyeShape,
faceIrisSize,
faceNose,
faceMouth,
faceFeatures,
ears,
characteristics,
characteristicsColor,
mainHand,
offHand,
head,
body,
hands,
legs,
feet,
waist,
leftFinger,
rightFinger,
leftEars,
rightEars
FROM characters_appearance WHERE characterId = @charId";
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
reader.GetUInt32(0);
}
//Load Status Effects
query = @"
SELECT
statusId,
expireTime
FROM characters_statuseffect WHERE characterId = %u";
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
int count = 0;
while (reader.Read())
{
player.charaWork.status[count] = reader.GetUInt16(0);
player.charaWork.statusShownTime[count] = reader.GetUInt32(1);
}
}
//Load Chocobo
query = @"
SELECT
hasChocobo,
hasGoobbue,
chocoboAppearance,
chocoboName
FROM characters_chocobo WHERE characterId = @charId";
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
player.hasChocobo = reader.GetBoolean(0);
player.hasGoobbue = reader.GetBoolean(1);
player.chocoboAppearance = reader.GetByte(2);
player.chocoboName = reader.GetString(3);
}
//Load Achievements
query = @"
SELECT
achievementId
FROM characters_achievements WHERE characterId = %u AND timeDone NOT NULL";
//Load Last 5 Completed
query = @"
SELECT
achievementId
FROM characters_achievements WHERE characterId = %u ORDER BY timeDone DESC LIMIT 5";
//Load Timers
query = @"
SELECT
thousandmaws,
dzemaeldarkhold,
bowlofembers_hard,
bowlofembers,
thornmarch,
aurumvale,
cutterscry,
battle_aleport,
battle_hyrstmill,
battle_goldenbazaar,
howlingeye_hard,
howlingeye,
castrumnovum,
bowlofembers_extreme,
rivenroad,
rivenroad_hard,
behests,
companybehests,
returntimer,
skirmish,
FROM characters_timers WHERE characterId = @charId";
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
for (int i = 0; i < player.timers.Length; i++)
player.timers[i] = reader.GetUInt32(i);
}
//Load Hotbar
query = @"
SELECT
hotbarIndex,
commandId,
recastTime
FROM characters_hotbar WHERE characterId = @charId AND classId = @classId ORDER BY hotbarIndex DESC";
cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@charId", player.actorId);
//cmd.Parameters.AddWithValue("@classId", player.currentClassId);
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);
}
}
//Load Scenario Quests
query = @"
SELECT
index,
questId
FROM characters_quest_scenario WHERE characterId = %u";
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
int index = reader.GetUInt16(0);
player.playerWork.questScenario[index] = reader.GetUInt32(1);
}
}
//Load Guildleve Quests
query = @"
SELECT
index,
questId,
abandoned,
completed
FROM characters_quest_scenario WHERE characterId = %u";
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
int index = reader.GetUInt16(0);
player.playerWork.questGuildLeve[index] = reader.GetUInt32(1);
player.work.guildleveDone[index] = reader.GetBoolean(2);
player.work.guildleveChecked[index] = reader.GetBoolean(3);
}
}
//Load NPC Linkshell
query = @"
SELECT
npcLinkshellId,
isCalling,
isExtra
FROM characters_quest_scenario WHERE characterId = %u ORDER BY npcLinkshellId DESC";
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
int npcLSId = reader.GetUInt16(0);
player.playerWork.npcLinkshellChatCalling[npcLSId] = reader.GetBoolean(1);
player.playerWork.npcLinkshellChatExtra[npcLSId] = reader.GetBoolean(2);
}
}
}
catch (MySqlException e)
{ Console.WriteLine(e); }
finally
{
conn.Dispose();
}
}
}
}
}

View File

@ -24,8 +24,8 @@ namespace FFXIVClassic_Map_Server.dataobjects
public uint displayNameId = 0xFFFFFFFF;
public string customDisplayName;
public uint currentMainState = SetActorStatePacket.MAIN_STATE_PASSIVE;
public uint currentSubState = SetActorStatePacket.SUB_STATE_NONE;
public ushort currentMainState = SetActorStatePacket.MAIN_STATE_PASSIVE;
public ushort currentSubState = SetActorStatePacket.SUB_STATE_NONE;
public float positionX = SetActorPositionPacket.INNPOS_X, positionY = SetActorPositionPacket.INNPOS_Y, positionZ = SetActorPositionPacket.INNPOS_Z, rotation = SetActorPositionPacket.INNPOS_ROT;
public float oldPositionX, oldPositionY, oldPositionZ, oldRotation;
public ushort moveState, oldMoveState;

View File

@ -23,7 +23,7 @@ namespace FFXIVClassic_Map_Server.dataobjects.chara
public ushort[] status = new ushort[20];
public uint[] statusShownTime = new uint[20];
public int[] command = new int[64];
public uint[] command = new uint[64];
public int[] commandCategory = new int[64];
public int commandBorder = 0x20;
public bool commandAcquired = false;

View File

@ -1,4 +1,5 @@
using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic_Map_Server.actors.chara;
using FFXIVClassic_Map_Server.packets.send.actor;
using System;
using System.Collections.Generic;
@ -46,6 +47,7 @@ namespace FFXIVClassic_Map_Server.dataobjects.chara
public uint currentActorIcon = 0;
public Work work = new Work();
public CharaWork charaWork = new CharaWork();
public PlayerWork playerWork = new PlayerWork();

View File

@ -19,7 +19,7 @@ namespace FFXIVClassic_Map_Server.dataobjects.chara
public int[] state_boostPointForSkill;
public int[] commandSlot_compatibility;
public int[] commandSlot_recastTime;
public uint[] commandSlot_recastTime = new uint[40];
public int[] giftCommandSlot_commandId;
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.actors.chara
{
class Work
{
public bool[] guildleveDone = new bool[16];
public bool[] guildleveChecked = new bool[16];
public bool betacheck = false;
}
}

View File

@ -5,6 +5,7 @@ using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic_Map_Server.dataobjects.database;
using FFXIVClassic_Map_Server.lua;
using FFXIVClassic_Map_Server.packets.send.actor;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
@ -39,6 +40,20 @@ namespace FFXIVClassic_Map_Server.dataobjects.chara
public uint[] timers = new uint[20];
public uint currentTitle;
public byte gcCurrent;
public byte gcRankLimsa;
public byte gcRankGridania;
public byte gcRankUldah;
public bool hasChocobo;
public bool hasGoobbue;
public byte chocoboAppearance;
public string chocoboName;
public uint achievementPoints;
PlayerWork playerWork = new PlayerWork();
public Player(uint actorID) : base(actorID)
@ -151,5 +166,8 @@ namespace FFXIVClassic_Map_Server.dataobjects.chara
{
return actorId == otherActorId;
}
}
}

View File

@ -8,16 +8,16 @@ namespace FFXIVClassic_Map_Server.dataobjects.chara
{
class PlayerWork
{
public int tribe;
public int guardian;
public int birthdayMonth;
public int birthdayDay;
public int initialTown;
public byte tribe;
public byte guardian;
public byte birthdayMonth;
public byte birthdayDay;
public byte initialTown;
public int restBonusExpRate;
public int[] questScenario = new int[16];
public int[] questGuildLeve = new int[8];
public uint[] questScenario = new uint[16];
public uint[] questGuildLeve = new uint[8];
public int questScenarioComplete;
public int questGuildleveComplete;
@ -32,8 +32,8 @@ namespace FFXIVClassic_Map_Server.dataobjects.chara
public bool isRemainBonusPoint;
public int[] npcLinkshellChatCalling = new int[64];
public int[] npcLinkshellChatExtra = new int[64];
public bool[] npcLinkshellChatCalling = new bool[64];
public bool[] npcLinkshellChatExtra = new bool[64];
public int variableCommandConfirmWarp;
public int variableCommandConfirmWarpSender;