초기커밋
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class TaskReservationAction : EntityActionBase
|
||||
{
|
||||
private List<TaskReservation> m_TaskReservation = new();
|
||||
|
||||
public TaskReservationAction(Player owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override Task<Result> onInit()
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
m_TaskReservation.Clear();
|
||||
}
|
||||
|
||||
public void AddTask(TaskReservation taskReservation)
|
||||
{
|
||||
m_TaskReservation.Add(taskReservation);
|
||||
}
|
||||
|
||||
public async Task<Result> AddTaskReservationFromDoc(List<TaskReservationDoc> taskReservationDocs)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var player = getOwner() as Player;
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
|
||||
foreach (var task_reservation_doc in taskReservationDocs)
|
||||
{
|
||||
(result, var taskReverstion) = await TaskReservation.createTaskReservationFromDoc(player, task_reservation_doc);
|
||||
if (result.isFail())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(taskReverstion, () => $"taskReverstion is null !!! - {player.toBasicString()}");
|
||||
|
||||
AddTask(taskReverstion);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task UpdateTick()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var player = getOwner() as Player;
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
List<TaskReservation> copyTaskReservation = new List<TaskReservation>(m_TaskReservation.ToList());
|
||||
List<TaskReservation> removeTaskReservation = new List<TaskReservation>();
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
foreach (var taskReservation in copyTaskReservation)
|
||||
{
|
||||
var task_reservation_attribute = taskReservation.getEntityAttribute<TaskReservationAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(task_reservation_attribute, () => $"task_reservation_attribute is null !!! - {player.toBasicString()}");
|
||||
|
||||
switch (task_reservation_attribute.ReservationType)
|
||||
{
|
||||
case TaskReservationActionType.AiChatBeamCharge:
|
||||
{
|
||||
result = await ChargeBeamAction(task_reservation_attribute.JsonValue);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Fail to task Action !!! errorCode : {result.ErrorCode} task_action_type : {task_reservation_attribute.ReservationType}, task_action_value {task_reservation_attribute.JsonValue}";
|
||||
Log.getLogger().error(err_msg);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
removeTaskReservation.Add(taskReservation);
|
||||
}
|
||||
|
||||
if(removeTaskReservation.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var invokers = new List<ILogInvoker>();
|
||||
var fn_task_reservation = async delegate ()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
foreach (var remove_task in removeTaskReservation)
|
||||
{
|
||||
var task_reservation_attribute = remove_task.getEntityAttribute<TaskReservationAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(task_reservation_attribute, () => $"task_reservation_attribute is null !!! - {player.toBasicString()}");
|
||||
|
||||
task_reservation_attribute.deleteEntityAttribute();
|
||||
|
||||
var task_reservation_log_data = TaskReservationBusinessLogHelper.toLogInfo(task_reservation_attribute);
|
||||
invokers.Add(new TaskReservationBusinessLog(task_reservation_log_data));
|
||||
}
|
||||
|
||||
var batch = new QueryBatchEx<QueryRunnerWithDocument>(player, LogActionType.TaskReservationComplete
|
||||
, server_logic.getDynamoDbClient(), true);
|
||||
{
|
||||
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
|
||||
}
|
||||
|
||||
batch.appendBusinessLogs(invokers);
|
||||
|
||||
result = await QueryHelper.sendQueryAndBusinessLog(batch);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (var remove_task in removeTaskReservation)
|
||||
{
|
||||
m_TaskReservation.Remove(remove_task);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
result = await player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "RemoveTaskReservation", fn_task_reservation);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to runTransactionRunnerSafely() !!! : RemoveTaskReservation, {result.toBasicString()} - {player.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private async Task<Result> ChargeBeamAction(string action_data_json)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var player = getOwner() as Player;
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
|
||||
var ai_chat_action = player.getEntityAction<AIChatAction>();
|
||||
ArgumentNullException.ThrowIfNull(ai_chat_action);
|
||||
|
||||
var task_reservation_data = JsonConvert.DeserializeObject<TaskReservationChargePointData>(action_data_json);
|
||||
if (task_reservation_data == null)
|
||||
{
|
||||
Log.getLogger().error($"Failed to JsonConvert.DeserializeObject<TaskReservationChargePointData> !!! : value:{action_data_json}");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await ai_chat_action.pointChargeCheckByOrderGuid(task_reservation_data.orderGuid);
|
||||
if(result.ErrorCode == ServerErrorCode.AiChatServerChargeOrderNotFoundError)
|
||||
{
|
||||
result = await ai_chat_action.pointCharge(new AIChatPointCharge() { userGuid = player.getUserGuid(), points = task_reservation_data.BeamAmount, pointType = task_reservation_data.PointType, orderGuid = task_reservation_data.orderGuid, description = "" });
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (result.isSuccess())
|
||||
{
|
||||
MoneyNotifyHelper.send_GS2C_NTF_BEAM_CHARGE(player);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using Amazon.Runtime.Internal.Transform;
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using System;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class DBQTaskReservationReadAll : QueryExecutorBase
|
||||
{
|
||||
private string m_combination_key_for_pk = string.Empty;
|
||||
private string m_pk = string.Empty;
|
||||
|
||||
private List<TaskReservationDoc> m_to_read_task_reservation_docs = new();
|
||||
|
||||
public DBQTaskReservationReadAll(string combinationKeyForPK)
|
||||
: base(typeof(DBQTaskReservationReadAll).Name)
|
||||
{
|
||||
m_combination_key_for_pk = combinationKeyForPK;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
|
||||
//=====================================================================================
|
||||
public override Task<Result> onPrepareQuery()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var doc = new TaskReservationDoc();
|
||||
doc.setCombinationKeyForPK(m_combination_key_for_pk);
|
||||
|
||||
var error_code = doc.onApplyPKSK();
|
||||
if (error_code.isFail())
|
||||
{
|
||||
err_msg = $"Failed to onApplyPKSK() !!! : {error_code.toBasicString()} - {toBasicString()}, {owner.toBasicString()}";
|
||||
result.setFail(error_code, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
m_pk = doc.getPK();
|
||||
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// onPrepareQuery()를 성공할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task<Result> onQuery()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var query_batch = getQueryBatch();
|
||||
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!!");
|
||||
|
||||
var db_connector = query_batch.getDynamoDbConnector();
|
||||
var query_config = db_connector.makeQueryConfigForReadByPKOnly(m_pk);
|
||||
|
||||
(result, var read_docs) = await db_connector.simpleQueryDocTypesWithQueryOperationConfig<TaskReservationDoc>(query_config, eventTid: query_batch.getTransId());
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var task_reservation_action = owner.getEntityAction<TaskReservationAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(task_reservation_action, () => $"task_reservation_action is null !!!");
|
||||
|
||||
result = await task_reservation_action.AddTaskReservationFromDoc(read_docs);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
m_to_read_task_reservation_docs.AddRange(read_docs);
|
||||
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public List<TaskReservationDoc> getToReadItemDocs() => m_to_read_task_reservation_docs;
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리를 성공하고, doFnCommit()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task onQueryResponseCommit()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리를 실패하고, doFnRollback()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task onQueryResponseRollback(Result errorResult)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
public new Player? getOwner() => getQueryBatch()?.getLogActor() as Player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class TaskReservationBusinessLog : ILogInvokerEx
|
||||
{
|
||||
private TaskReservationLogData m_data_to_log;
|
||||
public TaskReservationBusinessLog(TaskReservationLogData log_data_param)
|
||||
: base(LogDomainType.TaskReservation)
|
||||
{
|
||||
m_data_to_log = log_data_param;
|
||||
}
|
||||
|
||||
public override bool hasLog()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void fillup(ref BusinessLog.LogBody body)
|
||||
{
|
||||
body.append(new TaskReservationLogData(this, m_data_to_log));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
static public class TaskReservationBusinessLogHelper
|
||||
{
|
||||
static public TaskReservationLogData toLogInfo(TaskReservationAttribute task_reservation_attribute)
|
||||
{
|
||||
var taskReservation = new TaskReservationLogData();
|
||||
taskReservation.setInfo(task_reservation_attribute);
|
||||
return taskReservation;
|
||||
}
|
||||
|
||||
static public void setInfo(this TaskReservationLogData logData, TaskReservationAttribute task_reservation_attribute)
|
||||
{
|
||||
logData.ReservationGuid = task_reservation_attribute.ReservationGuid;
|
||||
logData.ReservationType = task_reservation_attribute.ReservationType;
|
||||
logData.JsonValue = task_reservation_attribute.JsonValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
92
GameServer/Contents/TaskReservation/TaskReservation.cs
Normal file
92
GameServer/Contents/TaskReservation/TaskReservation.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
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<Result> 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<TaskReservationAttribute>();
|
||||
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<TaskReservationAttribute>();
|
||||
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()}";
|
||||
}
|
||||
}
|
||||
}
|
||||
19
GameServer/Contents/TaskReservation/TaskReservationSchema.cs
Normal file
19
GameServer/Contents/TaskReservation/TaskReservationSchema.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class TaskReservationChargePointData
|
||||
{
|
||||
public double BeamAmount { get; set; } = 0;
|
||||
public string PointType { get; set; } = string.Empty;
|
||||
|
||||
public string orderGuid { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user