using Newtonsoft.Json; using ServerCore; using ServerBase; using ServerCommon; namespace GameServer { public class TaskReservation : EntityBase { public TaskReservation(Player parent) : base(EntityType.TaskReservationAction, parent) { } public override async Task onInit() { var direct_parent = getDirectParent(); NullReferenceCheckHelper.throwIfNull(direct_parent, () => $"direct_parent is null !!!"); addEntityAttribute(new TaskReservationAttribute(this, direct_parent)); return await base.onInit(); } public static async Task<(Result, TaskReservation?)> createTaskReservationFromDoc(Player parent, TaskReservationDoc doc) { var task_reservation = new TaskReservation(parent); var result = await task_reservation.onInit(); if (result.isFail()) { return (result, null); } var err_msg = string.Empty; var task_reservation_attribute = task_reservation.getEntityAttribute(); NullReferenceCheckHelper.throwIfNull(task_reservation_attribute, () => $"task_reservation_attribute is null !!! - {parent.toBasicString()}"); if (task_reservation_attribute.copyEntityAttributeFromDoc(doc) == false) { err_msg = $"Failed to copyEntityAttributeFromDoc !!! : doc_type {doc.GetType()} - {task_reservation.getRootParent()?.toBasicString()}"; result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg); Log.getLogger().error(err_msg); return (result, null); } return (result, task_reservation); } public static async Task<(Result, TaskReservation?)> createTaskReservationForBeamCharge(Player parent, double beam_amount, string pointType, string order_guid) { var charge_beam_data = new TaskReservationChargePointData() { BeamAmount = beam_amount, PointType = pointType, orderGuid = order_guid }; return await createTaskReservation(parent, order_guid, TaskReservationActionType.AiChatBeamCharge, JsonConvert.SerializeObject(charge_beam_data)); } private static async Task<(Result, TaskReservation?)> createTaskReservation(Player parent, string order_guid, TaskReservationActionType taskReservationActionType, string json_value) { var task_reservation = new TaskReservation(parent); var result = await task_reservation.onInit(); if (result.isFail()) { return (result, null); } var err_msg = string.Empty; var task_reservation_attribute = task_reservation.getEntityAttribute(); NullReferenceCheckHelper.throwIfNull(task_reservation_attribute, () => $"task_reservation_attribute is null !!! - {parent.toBasicString()}"); task_reservation_attribute.ReservationGuid = order_guid; task_reservation_attribute.ReservationType = taskReservationActionType; task_reservation_attribute.JsonValue = json_value; task_reservation_attribute.newEntityAttribute(); return (result, task_reservation); } public override string toBasicString() { return $"{this.getTypeName()} - {getRootParent()?.toBasicString()}"; } public override string toSummaryString() { return $"{this.getTypeName()} - {getRootParent()?.toSummaryString()}"; } } }