182 lines
7.0 KiB
C#
182 lines
7.0 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|