Skip to content

Commit

Permalink
Merge pull request #186 from alborrajo/feature/skills
Browse files Browse the repository at this point in the history
Skill unlocking
  • Loading branch information
alborrajo authored Jun 7, 2023
2 parents db478ab + 8a7ce0c commit 53ac636
Show file tree
Hide file tree
Showing 52 changed files with 12,098 additions and 1,403 deletions.
26 changes: 22 additions & 4 deletions Arrowgene.Ddon.Database/Files/Database/Script/schema_sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,34 @@ CREATE TABLE IF NOT EXISTS `ddon_normal_skill_param`
CONSTRAINT `fk_normal_skill_param_character_common_id` FOREIGN KEY (`character_common_id`) REFERENCES `ddon_character_common` (`character_common_id`) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS `ddon_learned_custom_skill`
(
`character_common_id` INTEGER NOT NULL,
`job` TINYINT NOT NULL,
`skill_id` INT NOT NULL,
`skill_lv` TINYINT NOT NULL,
PRIMARY KEY (`character_common_id`, `job`, `skill_id`),
CONSTRAINT `fk_learned_custom_skill_character_common_id` FOREIGN KEY (`character_common_id`) REFERENCES `ddon_character_common` (`character_common_id`) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS `ddon_equipped_custom_skill`
(
`character_common_id` INTEGER NOT NULL,
`job` TINYINT NOT NULL,
`slot_no` TINYINT NOT NULL,
`skill_id` INT NOT NULL,
`skill_lv` TINYINT NOT NULL,
PRIMARY KEY (`character_common_id`, `job`, `slot_no`),
CONSTRAINT `fk_set_acquirement_param_character_common_id` FOREIGN KEY (`character_common_id`) REFERENCES `ddon_character_common` (`character_common_id`) ON DELETE CASCADE
CONSTRAINT `fk_equipped_custom_skill_character_common_id` FOREIGN KEY (`character_common_id`, `job`, `skill_id`) REFERENCES `ddon_learned_custom_skill` (`character_common_id`, `job`, `skill_id`) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS `ddon_learned_ability`
(
`character_common_id` INTEGER NOT NULL,
`job` TINYINT NOT NULL,
`ability_id` INT NOT NULL,
`ability_lv` TINYINT NOT NULL,
PRIMARY KEY (`character_common_id`, `job`, `ability_id`),
CONSTRAINT `fk_learned_ability_character_common_id` FOREIGN KEY (`character_common_id`) REFERENCES `ddon_character_common` (`character_common_id`) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS `ddon_equipped_ability`
Expand All @@ -330,9 +349,8 @@ CREATE TABLE IF NOT EXISTS `ddon_equipped_ability`
`job` TINYINT NOT NULL,
`slot_no` TINYINT NOT NULL,
`ability_id` INT NOT NULL,
`ability_lv` TINYINT NOT NULL,
PRIMARY KEY (`character_common_id`, `equipped_to_job`, `slot_no`),
CONSTRAINT `fk_set_acquirement_param_character_common_id` FOREIGN KEY (`character_common_id`) REFERENCES `ddon_character_common` (`character_common_id`) ON DELETE CASCADE
CONSTRAINT `fk_equipped_ability_character_common_id` FOREIGN KEY (`character_common_id`, `job`, `ability_id`) REFERENCES `ddon_learned_ability` (`character_common_id`, `job`, `ability_id`) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS `ddon_shortcut`
Expand Down
14 changes: 8 additions & 6 deletions Arrowgene.Ddon.Database/IDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,18 @@ public interface IDatabase
bool DeleteEquipItem(uint commonId, JobId job, EquipType equipType, byte equipSlot, string itemUId);

// CustomSkills
bool InsertEquippedCustomSkill(uint characterId, CustomSkill skill);
bool ReplaceEquippedCustomSkill(uint characterId, CustomSkill skill);
bool UpdateEquippedCustomSkill(uint characterId, JobId oldJob, byte oldSlotNo, CustomSkill skill);
bool ReplaceLearnedCustomSkill(uint commonId, CustomSkill skill);
bool InsertEquippedCustomSkill(uint characterId, byte slotNo, CustomSkill skill);
bool ReplaceEquippedCustomSkill(uint characterId, byte slotNo, CustomSkill skill);
bool UpdateEquippedCustomSkill(uint characterId, JobId oldJob, byte oldSlotNo, byte slotNo, CustomSkill skill);
bool DeleteEquippedCustomSkill(uint characterId, JobId job, byte slotNo);

// Abilities
bool InsertEquippedAbility(uint commonId, Ability skill);
bool ReplaceEquippedAbility(uint commonId, Ability skill);
bool ReplaceLearnedAbility(uint commonId, Ability ability);
bool InsertEquippedAbility(uint commonId, JobId equipptedToJob, byte slotNo, Ability ability);
bool ReplaceEquippedAbility(uint commonId, JobId equipptedToJob, byte slotNo, Ability ability);
bool ReplaceEquippedAbilities(uint commonId, JobId equippedToJob, List<Ability> abilities);
bool UpdateEquippedAbility(uint commonId, JobId oldEquippedToJob, byte oldSlotNo, Ability skill);
bool UpdateEquippedAbility(uint commonId, JobId oldEquippedToJob, byte oldSlotNo, JobId equipptedToJob, byte slotNo, Ability ability);
bool DeleteEquippedAbility(uint commonId, JobId equippedToJob, byte slotNo);
bool DeleteEquippedAbilities(uint commonId, JobId equippedToJob);

Expand Down
80 changes: 71 additions & 9 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacterCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,58 @@ private void QueryCharacterCommonData(TCon conn, CharacterCommon common)
{
while (reader.Read())
{
common.NormalSkills.Add(ReadNormalSkillParam(reader));
common.LearnedNormalSkills.Add(ReadNormalSkillParam(reader));
}
});

// Custom Skills
ExecuteReader(conn, SqlSelectLearnedCustomSkills,
command => { AddParameter(command, "@character_common_id", common.CommonId); },
reader =>
{
while (reader.Read())
{
common.LearnedCustomSkills.Add(ReadLearnedCustomSkill(reader));
}
});
ExecuteReader(conn, SqlSelectEquippedCustomSkills,
command => { AddParameter(command, "@character_common_id", common.CommonId); },
reader =>
{
while (reader.Read())
{
common.CustomSkills.Add(ReadCustomSkill(reader));
uint skillId = GetUInt32(reader, "skill_id");
JobId job = (JobId) GetByte(reader, "job");
CustomSkill skill = common.LearnedCustomSkills.Where(x => x.Job == job && x.SkillId == skillId).Single();

byte slotNo = GetByte(reader, "slot_no");
common.EquippedCustomSkillsDictionary[job][slotNo-1] = skill;
}
});

// Abilities
ExecuteReader(conn, SqlSelectLearnedAbilities,
command => { AddParameter(command, "@character_common_id", common.CommonId); },
reader =>
{
while (reader.Read())
{
common.LearnedAbilities.Add(ReadLearnedAbility(reader));
}
});
ExecuteReader(conn, SqlSelectEquippedAbilities,
command => { AddParameter(command, "@character_common_id", common.CommonId); },
reader =>
{
while (reader.Read())
{
common.Abilities.Add(ReadAbility(reader));
uint abilityId = GetUInt32(reader, "ability_id");
JobId job = (JobId) GetByte(reader, "job");
JobId equippedToJob = (JobId) GetByte(reader, "equipped_to_job");
Ability aug = common.LearnedAbilities.Where(x => x.Job == job && x.AbilityId == abilityId).Single();

byte slotNo = GetByte(reader, "slot_no");
common.EquippedAbilitiesDictionary[equippedToJob][slotNo-1] = aug;
}
});
}
Expand All @@ -210,29 +239,62 @@ private void StoreCharacterCommonData(TCon conn, CharacterCommon common)
}
}

foreach(CDataNormalSkillParam normalSkillParam in common.NormalSkills)
foreach(CDataNormalSkillParam normalSkillParam in common.LearnedNormalSkills)
{
ExecuteNonQuery(conn, SqlReplaceNormalSkillParam, command =>
{
AddParameter(command, common.CommonId, normalSkillParam);
});
}

foreach(CustomSkill skill in common.CustomSkills)
foreach(CustomSkill learnedSkills in common.LearnedCustomSkills)
{
ExecuteNonQuery(conn, SqlReplaceEquippedCustomSkill, command =>
ExecuteNonQuery(conn, SqlReplaceLearnedCustomSkill, command =>
{
AddParameter(command, common.CommonId, skill);
AddParameter(command, common.CommonId, learnedSkills);
});
}

foreach(Ability ability in common.Abilities)
foreach(KeyValuePair<JobId, List<CustomSkill>> jobAndSkills in common.EquippedCustomSkillsDictionary)
{
for(int i=0; i<jobAndSkills.Value.Count; i++)
{
CustomSkill? skill = jobAndSkills.Value[i];
byte slotNo = (byte)(i+1);
if(skill != null)
{
ExecuteNonQuery(conn, SqlReplaceEquippedCustomSkill, command =>
{
AddParameter(command, common.CommonId, slotNo, skill);
});
}
}
}

foreach(Ability ability in common.LearnedAbilities)
{
ExecuteNonQuery(conn, SqlReplaceEquippedAbility, command =>
ExecuteNonQuery(conn, SqlReplaceLearnedAbility, command =>
{
AddParameter(command, common.CommonId, ability);
});
}

foreach(KeyValuePair<JobId, List<Ability>> jobAndAugs in common.EquippedAbilitiesDictionary)
{
JobId equippedToJob = jobAndAugs.Key;
for(int i=0; i<jobAndAugs.Value.Count; i++)
{
Ability? ability = jobAndAugs.Value[i];
byte slotNo = (byte)(i+1);
if(ability != null)
{
ExecuteNonQuery(conn, SqlReplaceEquippedAbility, command =>
{
AddParameter(command, common.CommonId, equippedToJob, slotNo, ability);
});
}
}
}
}

private void ReadAllCharacterCommonData(DbDataReader reader, CharacterCommon common)
Expand Down
37 changes: 14 additions & 23 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbEquippedAbility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract partial class DdonSqlDb<TCon, TCom> : SqlDb<TCon, TCom>
{
private static readonly string[] EquippedAbilityFields = new string[]
{
"character_common_id", "equipped_to_job", "job", "slot_no", "ability_id", "ability_lv"
"character_common_id", "equipped_to_job", "job", "slot_no", "ability_id"
};

private readonly string SqlInsertEquippedAbility = $"INSERT INTO `ddon_equipped_ability` ({BuildQueryField(EquippedAbilityFields)}) VALUES ({BuildQueryInsert(EquippedAbilityFields)});";
Expand All @@ -20,19 +20,19 @@ public abstract partial class DdonSqlDb<TCon, TCom> : SqlDb<TCon, TCom>
private const string SqlDeleteEquippedAbility = "DELETE FROM `ddon_equipped_ability` WHERE `character_common_id`=@character_common_id AND `equipped_to_job`=@equipped_to_job AND `slot_no`=@slot_no;";
private const string SqlDeleteEquippedAbilities = "DELETE FROM `ddon_equipped_ability` WHERE `character_common_id`=@character_common_id AND `equipped_to_job`=@equipped_to_job;";

public bool InsertEquippedAbility(uint commonId, Ability ability)
public bool InsertEquippedAbility(uint commonId, JobId equippedToJob, byte slotNo, Ability ability)
{
return ExecuteNonQuery(SqlInsertEquippedAbility, command =>
{
AddParameter(command, commonId, ability);
AddParameter(command, commonId, equippedToJob, slotNo, ability);
}) == 1;
}

public bool ReplaceEquippedAbility(uint commonId, Ability ability)
public bool ReplaceEquippedAbility(uint commonId, JobId equippedToJob, byte slotNo, Ability ability)
{
ExecuteNonQuery(SqlReplaceEquippedAbility, command =>
{
AddParameter(command, commonId, ability);
AddParameter(command, commonId, equippedToJob, slotNo, ability);
});
return true;
}
Expand All @@ -49,21 +49,23 @@ public bool ReplaceEquippedAbilities(uint commonId, JobId equippedToJob, List<Ab
});

// Insert new ones
foreach(Ability ability in abilities)
for(byte i = 0; i < abilities.Count; i++)
{
Ability ability = abilities[i];
byte slotNo = (byte)(i+1);
ExecuteNonQuery(connection, SqlInsertEquippedAbility, command =>
{
AddParameter(command, commonId, ability);
AddParameter(command, commonId, equippedToJob, slotNo, ability);
});
}
});
}

public bool UpdateEquippedAbility(uint commonId, JobId oldEquippedToJob, byte oldSlotNo, Ability updatedability)
public bool UpdateEquippedAbility(uint commonId, JobId oldEquippedToJob, byte oldSlotNo, JobId equippedToJob, byte slotNo, Ability updatedability)
{
return ExecuteNonQuery(SqlDeleteEquippedAbility, command =>
{
AddParameter(command, commonId, updatedability);
AddParameter(command, commonId, equippedToJob, slotNo, updatedability);
AddParameter(command, "@old_character_common_id", commonId);
AddParameter(command, "@old_equipped_to_job", (byte) oldEquippedToJob);
AddParameter(command, "@old_slot_no", oldSlotNo);
Expand All @@ -89,23 +91,12 @@ public bool DeleteEquippedAbilities(uint commonId, JobId equippedToJob)
}) == 1;
}

private Ability ReadAbility(DbDataReader reader)
{
Ability ability = new Ability();
ability.EquippedToJob = (JobId) GetByte(reader, "equipped_to_job");
ability.Job = (JobId) GetByte(reader, "job");
ability.SlotNo = GetByte(reader, "slot_no");
ability.AbilityId = GetUInt32(reader, "ability_id");
ability.AbilityLv = GetByte(reader, "ability_lv");
return ability;
}

private void AddParameter(TCom command, uint commonId, Ability ability)
private void AddParameter(TCom command, uint commonId, JobId equippedToJob, byte slotNo, Ability ability)
{
AddParameter(command, "character_common_id", commonId);
AddParameter(command, "equipped_to_job", (byte) ability.EquippedToJob);
AddParameter(command, "equipped_to_job", (byte) equippedToJob);
AddParameter(command, "job", (byte) ability.Job);
AddParameter(command, "slot_no", ability.SlotNo);
AddParameter(command, "slot_no", slotNo);
AddParameter(command, "ability_id", ability.AbilityId);
AddParameter(command, "ability_lv", ability.AbilityLv);
}
Expand Down
27 changes: 8 additions & 19 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbEquippedCustomSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public abstract partial class DdonSqlDb<TCon, TCom> : SqlDb<TCon, TCom>
{
private static readonly string[] EquippedCustomSkillFields = new string[]
{
"character_common_id", "job", "slot_no", "skill_id", "skill_lv"
"character_common_id", "job", "slot_no", "skill_id"
};

private readonly string SqlInsertEquippedCustomSkill = $"INSERT INTO `ddon_equipped_custom_skill` ({BuildQueryField(EquippedCustomSkillFields)}) VALUES ({BuildQueryInsert(EquippedCustomSkillFields)});";
Expand All @@ -18,24 +18,24 @@ public abstract partial class DdonSqlDb<TCon, TCom> : SqlDb<TCon, TCom>
private static readonly string SqlSelectEquippedCustomSkills = $"SELECT {BuildQueryField(EquippedCustomSkillFields)} FROM `ddon_equipped_custom_skill` WHERE `character_common_id`=@character_common_id;";
private const string SqlDeleteEquippedCustomSkill = "DELETE FROM `ddon_equipped_custom_skill` WHERE `character_common_id`=@character_common_id AND `job`=@job AND `slot_no`=@slot_no;";

public bool InsertEquippedCustomSkill(uint commonId, CustomSkill skill)
public bool InsertEquippedCustomSkill(uint commonId, byte slotNo, CustomSkill skill)
{
return ExecuteNonQuery(SqlInsertEquippedCustomSkill, command =>
{
AddParameter(command, commonId, skill);
AddParameter(command, commonId, slotNo, skill);
}) == 1;
}

public bool ReplaceEquippedCustomSkill(uint commonId, CustomSkill skill)
public bool ReplaceEquippedCustomSkill(uint commonId, byte slotNo, CustomSkill skill)
{
ExecuteNonQuery(SqlReplaceEquippedCustomSkill, command =>
{
AddParameter(command, commonId, skill);
AddParameter(command, commonId, slotNo, skill);
});
return true;
}

public bool UpdateEquippedCustomSkill(uint commonId, JobId oldJob, byte oldSlotNo, CustomSkill updatedSkill)
public bool UpdateEquippedCustomSkill(uint commonId, JobId oldJob, byte oldSlotNo, byte slotNo, CustomSkill updatedSkill)
{
return ExecuteNonQuery(SqlDeleteEquippedCustomSkill, command =>
{
Expand All @@ -56,23 +56,12 @@ public bool DeleteEquippedCustomSkill(uint commonId, JobId job, byte slotNo)
}) == 1;
}

private CustomSkill ReadCustomSkill(DbDataReader reader)
{
CustomSkill skill = new CustomSkill();
skill.Job = (JobId) GetByte(reader, "job");
skill.SlotNo = GetByte(reader, "slot_no");
skill.SkillId = GetUInt32(reader, "skill_id");
skill.SkillLv = GetByte(reader, "skill_lv");
return skill;
}

private void AddParameter(TCom command, uint commonId, CustomSkill skill)
private void AddParameter(TCom command, uint commonId, byte slotNo, CustomSkill skill)
{
AddParameter(command, "character_common_id", commonId);
AddParameter(command, "job", (byte) skill.Job);
AddParameter(command, "slot_no", skill.SlotNo);
AddParameter(command, "slot_no", slotNo);
AddParameter(command, "skill_id", skill.SkillId);
AddParameter(command, "skill_lv", skill.SkillLv);
}
}
}
Loading

0 comments on commit 53ac636

Please sign in to comment.