|
| 1 | +using Arrowgene.Ddon.Shared.Entity.PacketStructure; |
| 2 | +using Arrowgene.Ddon.Shared.Entity.Structure; |
| 3 | +using Arrowgene.Ddon.Shared.Model; |
| 4 | +using Arrowgene.Ddon.Shared.Model.Quest; |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Data.Common; |
| 8 | +using System.Linq; |
| 9 | +using System.Text; |
| 10 | +using System.Threading.Tasks; |
| 11 | + |
| 12 | +namespace Arrowgene.Ddon.Database.Sql.Core |
| 13 | +{ |
| 14 | + public partial class DdonSqlDb : SqlDb |
| 15 | + { |
| 16 | + private static readonly string[] DdonLightQuestFields = |
| 17 | + [ |
| 18 | + "variant_id", |
| 19 | + "quest_schedule_id", "quest_id", "target", "level", "count", |
| 20 | + "reward_xp", "reward_g", "reward_r", "reward_ap", |
| 21 | + "distribution_end" |
| 22 | + ]; |
| 23 | + |
| 24 | + private readonly string SqlInsertLightQuestRecord = |
| 25 | + $"INSERT INTO \"ddon_light_quests\" ({BuildQueryField(DdonLightQuestFields)}) VALUES ({BuildQueryInsert(DdonLightQuestFields)});"; |
| 26 | + private readonly string SqlSelectLightQuestRecords = |
| 27 | + $"SELECT {BuildQueryField(DdonLightQuestFields)} FROM \"ddon_light_quests\";"; |
| 28 | + private readonly string SqlDeleteLightQuestRecord = |
| 29 | + $"DELETE FROM \"ddon_light_quests\" WHERE \"quest_schedule_id\"=@quest_schedule_id;"; |
| 30 | + |
| 31 | + private void AddParameter(DbCommand command, LightQuestRecord record) |
| 32 | + { |
| 33 | + AddParameter(command, "variant_id", record.VariantIndex); |
| 34 | + AddParameter(command, "quest_schedule_id", record.QuestScheduleId); |
| 35 | + AddParameter(command, "quest_id", (uint)record.QuestId); |
| 36 | + AddParameter(command, "target", record.Target); |
| 37 | + AddParameter(command, "level", record.Level); |
| 38 | + AddParameter(command, "count", record.Count); |
| 39 | + AddParameter(command, "reward_xp", record.RewardXP); |
| 40 | + AddParameter(command, "reward_g", record.RewardG); |
| 41 | + AddParameter(command, "reward_r", record.RewardR); |
| 42 | + AddParameter(command, "reward_ap", record.RewardAP); |
| 43 | + AddParameter(command, "distribution_end", record.DistributionEnd.UtcDateTime); |
| 44 | + } |
| 45 | + |
| 46 | + private LightQuestRecord ReadLightQuestRecord(DbDataReader reader) |
| 47 | + { |
| 48 | + LightQuestRecord record = new(); |
| 49 | + record.VariantIndex = GetUInt32(reader, "variant_id"); |
| 50 | + record.QuestId = (QuestId)GetUInt32(reader, "quest_id"); |
| 51 | + record.Target = GetInt32(reader, "target"); |
| 52 | + record.Level = GetUInt16(reader, "level"); |
| 53 | + record.Count = GetInt32(reader, "count"); |
| 54 | + record.RewardXP = GetUInt32(reader, "reward_xp"); |
| 55 | + record.RewardG = GetUInt32(reader, "reward_g"); |
| 56 | + record.RewardR = GetUInt32(reader, "reward_r"); |
| 57 | + record.RewardAP = GetUInt32(reader, "reward_ap"); |
| 58 | + record.DistributionEnd = GetDateTime(reader, "distribution_end"); |
| 59 | + |
| 60 | + return record; |
| 61 | + } |
| 62 | + |
| 63 | + public override bool InsertLightQuestRecord(LightQuestRecord record, DbConnection? connectionIn = null) |
| 64 | + { |
| 65 | + return ExecuteQuerySafe(connectionIn, connection => |
| 66 | + { |
| 67 | + return ExecuteNonQuery(connection, SqlInsertLightQuestRecord, command => |
| 68 | + { |
| 69 | + AddParameter(command, record); |
| 70 | + }) == 1; |
| 71 | + }); |
| 72 | + } |
| 73 | + |
| 74 | + public override List<LightQuestRecord> SelectLightQuestRecords(DbConnection? connectionIn = null) |
| 75 | + { |
| 76 | + List<LightQuestRecord> results = new(); |
| 77 | + ExecuteQuerySafe(connectionIn, connection => |
| 78 | + { |
| 79 | + ExecuteReader(connection, SqlSelectLightQuestRecords, command => |
| 80 | + {}, |
| 81 | + reader => |
| 82 | + { |
| 83 | + while (reader.Read()) |
| 84 | + { |
| 85 | + results.Add(ReadLightQuestRecord(reader)); |
| 86 | + } |
| 87 | + }); |
| 88 | + }); |
| 89 | + return results; |
| 90 | + } |
| 91 | + |
| 92 | + public override bool DeleteLightQuestRecord(uint scheduleId, DbConnection? connectionIn = null) |
| 93 | + { |
| 94 | + return ExecuteQuerySafe(connectionIn, connection => |
| 95 | + { |
| 96 | + return ExecuteNonQuery(connection, SqlDeleteLightQuestRecord, command => |
| 97 | + { |
| 98 | + AddParameter(command, "@quest_schedule_id", scheduleId); |
| 99 | + }) == 1; |
| 100 | + }); |
| 101 | + } |
| 102 | + |
| 103 | + |
| 104 | + } |
| 105 | +} |
0 commit comments