|
| 1 | +using Arrowgene.Ddon.Shared.Model; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Data.Common; |
| 4 | + |
| 5 | +namespace Arrowgene.Ddon.Database.Sql.Core; |
| 6 | + |
| 7 | +public partial class DdonSqlDb : SqlDb |
| 8 | +{ |
| 9 | + /* ddon_job_emblem */ |
| 10 | + protected static readonly string[] JobEmblemFields = new[] |
| 11 | + { |
| 12 | + "character_id", "job_id", "emblem_level", "emblem_points_used", |
| 13 | + "physical_attack", "magick_attack", "physical_defense", "magick_defense", |
| 14 | + "max_hp", "max_stamina", "healing_power", "endurance", "blow_power", "chance_attack", "exhaust_attack", |
| 15 | + "knockout_power", "fire_resist", "ice_resist", "thunder_resist", "holy_resist", "dark_resist" |
| 16 | + }; |
| 17 | + |
| 18 | + private readonly string SqlUpsertJobEmblemData = $""" |
| 19 | + INSERT INTO ddon_job_emblem ({BuildQueryField(JobEmblemFields)}) |
| 20 | + VALUES ({BuildQueryInsert(JobEmblemFields)}) |
| 21 | + ON CONFLICT (character_id, job_id) |
| 22 | + DO UPDATE SET {BuildQueryUpdate(JobEmblemFields)}; |
| 23 | + """; |
| 24 | + |
| 25 | + private readonly string SqlSelectAllJobEmblemData = |
| 26 | + $"SELECT {BuildQueryField(JobEmblemFields)} FROM \"ddon_job_emblem\" WHERE \"character_id\"=@character_id;"; |
| 27 | + |
| 28 | + private readonly string SqlSelectJobEmblemData = |
| 29 | + $"SELECT {BuildQueryField(JobEmblemFields)} FROM \"ddon_job_emblem\" WHERE \"character_id\"=@character_id AND \"job_id\"=@job_id;"; |
| 30 | + |
| 31 | + public override bool UpsertJobEmblemData(uint characterId, JobEmblem jobEmblem, DbConnection? connectionIn = null) |
| 32 | + { |
| 33 | + return ExecuteQuerySafe(connectionIn, connection => |
| 34 | + { |
| 35 | + return ExecuteNonQuery(connection, SqlUpsertJobEmblemData, command => |
| 36 | + { |
| 37 | + AddParameter(command, "character_id", characterId); |
| 38 | + AddParameter(command, "job_id", (byte)jobEmblem.JobId); |
| 39 | + AddParameter(command, "emblem_level", jobEmblem.EmblemLevel); |
| 40 | + AddParameter(command, "emblem_points_used", jobEmblem.EmblemPointsUsed); |
| 41 | + AddParameter(command, "physical_attack", jobEmblem.StatLevels[EquipStatId.PhysicalAttack]); |
| 42 | + AddParameter(command, "magick_attack", jobEmblem.StatLevels[EquipStatId.MagickAttack]); |
| 43 | + AddParameter(command, "physical_defense", jobEmblem.StatLevels[EquipStatId.PhysicalDefense]); |
| 44 | + AddParameter(command, "magick_defense", jobEmblem.StatLevels[EquipStatId.MagickDefense]); |
| 45 | + AddParameter(command, "max_hp", jobEmblem.StatLevels[EquipStatId.MaxHp]); |
| 46 | + AddParameter(command, "max_stamina", jobEmblem.StatLevels[EquipStatId.MaxStamina]); |
| 47 | + AddParameter(command, "healing_power", jobEmblem.StatLevels[EquipStatId.HealingPower]); |
| 48 | + AddParameter(command, "endurance", jobEmblem.StatLevels[EquipStatId.Endurance]); |
| 49 | + AddParameter(command, "blow_power", jobEmblem.StatLevels[EquipStatId.BlowPower]); |
| 50 | + AddParameter(command, "chance_attack", jobEmblem.StatLevels[EquipStatId.ChanceAttack]); |
| 51 | + AddParameter(command, "exhaust_attack", jobEmblem.StatLevels[EquipStatId.ExhaustAttack]); |
| 52 | + AddParameter(command, "knockout_power", jobEmblem.StatLevels[EquipStatId.KnockoutPower]); |
| 53 | + AddParameter(command, "fire_resist", jobEmblem.StatLevels[EquipStatId.FireResist]); |
| 54 | + AddParameter(command, "ice_resist", jobEmblem.StatLevels[EquipStatId.IceResist]); |
| 55 | + AddParameter(command, "thunder_resist", jobEmblem.StatLevels[EquipStatId.ThunderResist]); |
| 56 | + AddParameter(command, "holy_resist", jobEmblem.StatLevels[EquipStatId.HolyResist]); |
| 57 | + AddParameter(command, "dark_resist", jobEmblem.StatLevels[EquipStatId.DarkResist]); |
| 58 | + }) == 1; |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | + public override List<JobEmblem> GetAllJobEmblemData(uint characterId, DbConnection? connectionIn = null) |
| 63 | + { |
| 64 | + List<JobEmblem> results = new(); |
| 65 | + ExecuteQuerySafe(connectionIn, connection => |
| 66 | + { |
| 67 | + ExecuteReader(connection, SqlSelectAllJobEmblemData, command => |
| 68 | + { |
| 69 | + AddParameter(command, "character_id", characterId); |
| 70 | + }, |
| 71 | + reader => |
| 72 | + { |
| 73 | + while (reader.Read()) |
| 74 | + { |
| 75 | + results.Add(ReadEmblemData(reader)); |
| 76 | + } |
| 77 | + }); |
| 78 | + }); |
| 79 | + return results; |
| 80 | + } |
| 81 | + |
| 82 | + public override JobEmblem GetJobEmblemData(uint characterId, JobId jobId, DbConnection? connectionIn = null) |
| 83 | + { |
| 84 | + JobEmblem result = null; |
| 85 | + ExecuteQuerySafe(connectionIn, connection => |
| 86 | + { |
| 87 | + ExecuteReader(connection, SqlSelectJobEmblemData, command => |
| 88 | + { |
| 89 | + AddParameter(command, "character_id", characterId); |
| 90 | + AddParameter(command, "job_id", (byte)jobId); |
| 91 | + }, reader => |
| 92 | + { |
| 93 | + if (reader.Read()) |
| 94 | + { |
| 95 | + result = ReadEmblemData(reader); |
| 96 | + } |
| 97 | + }); |
| 98 | + }); |
| 99 | + return result; |
| 100 | + } |
| 101 | + |
| 102 | + private JobEmblem ReadEmblemData(DbDataReader reader) |
| 103 | + { |
| 104 | + var result = new JobEmblem |
| 105 | + { |
| 106 | + JobId = (JobId)GetByte(reader, "job_id"), |
| 107 | + EmblemLevel = GetByte(reader, "emblem_level"), |
| 108 | + EmblemPointsUsed = GetUInt16(reader, "emblem_points_used"), |
| 109 | + }; |
| 110 | + |
| 111 | + result.StatLevels[EquipStatId.PhysicalAttack] = GetByte(reader, "physical_attack"); |
| 112 | + result.StatLevels[EquipStatId.PhysicalDefense] = GetByte(reader, "physical_defense"); |
| 113 | + result.StatLevels[EquipStatId.MagickAttack] = GetByte(reader, "magick_attack"); |
| 114 | + result.StatLevels[EquipStatId.MagickDefense] = GetByte(reader, "magick_defense"); |
| 115 | + result.StatLevels[EquipStatId.MaxHp] = GetByte(reader, "max_hp"); |
| 116 | + result.StatLevels[EquipStatId.MaxStamina] = GetByte(reader, "max_stamina"); |
| 117 | + result.StatLevels[EquipStatId.HealingPower] = GetByte(reader, "healing_power"); |
| 118 | + result.StatLevels[EquipStatId.Endurance] = GetByte(reader, "endurance"); |
| 119 | + result.StatLevels[EquipStatId.BlowPower] = GetByte(reader, "blow_power"); |
| 120 | + result.StatLevels[EquipStatId.ChanceAttack] = GetByte(reader, "chance_attack"); |
| 121 | + result.StatLevels[EquipStatId.ExhaustAttack] = GetByte(reader, "exhaust_attack"); |
| 122 | + result.StatLevels[EquipStatId.KnockoutPower] = GetByte(reader, "knockout_power"); |
| 123 | + result.StatLevels[EquipStatId.FireResist] = GetByte(reader, "fire_resist"); |
| 124 | + result.StatLevels[EquipStatId.IceResist] = GetByte(reader, "ice_resist"); |
| 125 | + result.StatLevels[EquipStatId.ThunderResist] = GetByte(reader, "thunder_resist"); |
| 126 | + result.StatLevels[EquipStatId.HolyResist] = GetByte(reader, "holy_resist"); |
| 127 | + result.StatLevels[EquipStatId.DarkResist] = GetByte(reader, "dark_resist"); |
| 128 | + |
| 129 | + return result; |
| 130 | + } |
| 131 | +} |
0 commit comments