초기커밋
This commit is contained in:
@@ -0,0 +1,294 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Google.Protobuf.Collections;
|
||||
using Nettention.Proud;
|
||||
using Amazon.Runtime.Internal;
|
||||
using Amazon.Runtime.Internal.Endpoints.StandardLibrary;
|
||||
|
||||
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
|
||||
using GameServer.PacketHandler;
|
||||
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
||||
using static Pipelines.Sockets.Unofficial.SocketConnection;
|
||||
|
||||
|
||||
using UI_KEY = System.String;
|
||||
using MongoDB.Bson;
|
||||
using Amazon.S3.Model;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class CustomDefinedUiAction : EntityActionBase
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, CustomDefinedUi> m_custom_defined_uis = new();
|
||||
|
||||
public CustomDefinedUiAction(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override Task<Result> onInit()
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public async Task<Result> tryLoadCustomDefinedUiFromDoc(CustomDefinedUiDoc toLoadCustomDefinedUiDoc)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var owner = getOwner();
|
||||
var root_parent = owner.getRootParent();
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_load_custom_defined_ui_attrib = toLoadCustomDefinedUiDoc.getAttrib<CustomDefinedUiAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(to_load_custom_defined_ui_attrib, () => $"to_load_custom_defined_ui_attrib is null !!! - {owner.toBasicString()}, {root_parent.toBasicString()}");
|
||||
|
||||
var ui_key = to_load_custom_defined_ui_attrib.UiKey;
|
||||
var ui_value = to_load_custom_defined_ui_attrib.CustomDefinedUi;
|
||||
|
||||
result = await tryUpdateCustomDefinedUi(ui_key, ui_value, false);
|
||||
if(result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<Result> tryUpdateCustomDefinedUi(UI_KEY uiKey, string customDefinedUi, bool isApplyToDb = true)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var owner = getOwner();
|
||||
var root_parent = owner.getRootParent();
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var item_string = uiKey + customDefinedUi;
|
||||
result = await checkCustomDefinedUiSize(item_string);
|
||||
if(result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var add_custom_defined_ui = delegate (string uiKey)
|
||||
{
|
||||
var custom_defined_ui = new CustomDefinedUi(owner);
|
||||
result = custom_defined_ui.onInit().GetAwaiter().GetResult();
|
||||
if(result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to CustomDefinedUi.onInit() !!!, CustomDefinedUIAction.updateCustomDefinedUi() - {owner.toBasicString()}, {root_parent.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return null;
|
||||
}
|
||||
|
||||
var custom_defined_attribute = custom_defined_ui.getEntityAttribute<CustomDefinedUiAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(custom_defined_attribute, () => $"custom_defined_attribute is null !!! - {owner.toBasicString()}, {root_parent.toBasicString()}");
|
||||
|
||||
custom_defined_attribute.UiKey = uiKey;
|
||||
custom_defined_attribute.CustomDefinedUi = customDefinedUi;
|
||||
|
||||
if(true == isApplyToDb)
|
||||
{
|
||||
custom_defined_attribute.newEntityAttribute();
|
||||
}
|
||||
|
||||
return custom_defined_ui;
|
||||
};
|
||||
|
||||
var update_custom_defined_ui = delegate (string uiKey, CustomDefinedUi currCustomDefinedUi)
|
||||
{
|
||||
var custom_defined_ui_attribute = currCustomDefinedUi.getEntityAttribute<CustomDefinedUiAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(custom_defined_ui_attribute, () => $"custom_defined_ui_attribute is null !!! - {owner.toBasicString()}, {root_parent.toBasicString()}");
|
||||
|
||||
custom_defined_ui_attribute.UiKey = uiKey;
|
||||
custom_defined_ui_attribute.CustomDefinedUi = customDefinedUi;
|
||||
|
||||
if (true == isApplyToDb)
|
||||
{
|
||||
custom_defined_ui_attribute.modifiedEntityAttribute();
|
||||
}
|
||||
|
||||
return currCustomDefinedUi;
|
||||
};
|
||||
|
||||
m_custom_defined_uis.AddOrUpdate(uiKey, add_custom_defined_ui, update_custom_defined_ui);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void removeCustomDefinedUi(UI_KEY uiKey)
|
||||
{
|
||||
var owner = getOwner();
|
||||
var root_parent = owner.getRootParent();
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
if (false == m_custom_defined_uis.TryRemove(uiKey, out _))
|
||||
{
|
||||
err_msg = $"Failed to Remove() !!!, not found UIKey : UIKey:{uiKey} - {owner.toBasicString()}, {root_parent.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
public bool findCustomDefinedUi(UI_KEY uiKey, [MaybeNullWhen(false)] out CustomDefinedUi customDefinedUi)
|
||||
{
|
||||
return m_custom_defined_uis.TryGetValue(uiKey, out customDefinedUi);
|
||||
}
|
||||
|
||||
public bool getTattooVisible(TattooSlotType slotType, out bool foundVisible)
|
||||
{
|
||||
var owner = getOwner();
|
||||
var root_parent = owner.getRootParent();
|
||||
|
||||
var err_msg = string.Empty;
|
||||
|
||||
foundVisible = false;
|
||||
|
||||
var ui_key = slotType.convertEnumToEnumTypeAndValueString();
|
||||
|
||||
if (false == m_custom_defined_uis.TryGetValue(ui_key, out var found_custom_defined_ui))
|
||||
{
|
||||
err_msg = $"Failed to TryGetValue() !!!, CustomDefinedUIAction.getTattooVisible() : uiKey:{ui_key} - {owner.toBasicString()}, {root_parent.toBasicString()}";
|
||||
Log.getLogger().info(err_msg);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
var custom_defined_ui_attribute = found_custom_defined_ui.getEntityAttribute<CustomDefinedUiAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(custom_defined_ui_attribute, () => $"custom_defined_ui_attribute is null !!! - uiKey:{ui_key}, {owner.toBasicString()}, {root_parent.toBasicString()}");
|
||||
|
||||
if(false == custom_defined_ui_attribute.CustomDefinedUi.toBool(out var is_visible))
|
||||
{
|
||||
err_msg = $"Failed to toBool() !!!, CustomDefinedUIAction.getTattooVisible() - uiKey:{ui_key}, {owner.toBasicString()}, {root_parent.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
foundVisible = is_visible;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<Result> setTattooVisible(TattooSlotType slotType, bool foundVisible)
|
||||
{
|
||||
var owner = getOwner();
|
||||
var root_parent = owner.getRootParent();
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var ui_key = slotType.convertEnumToEnumTypeAndValueString();
|
||||
var item_string = ui_key + foundVisible.ToString();
|
||||
result = await checkCustomDefinedUiSize(item_string);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var add_custom_defined_ui = delegate (string uiKey)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var custom_defined_ui = new CustomDefinedUi(owner);
|
||||
result = custom_defined_ui.onInit().GetAwaiter().GetResult();
|
||||
if(result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to CustomDefinedUi.onInit() !!!, CustomDefinedUIAction.setTattooVisible() - {owner.toBasicString()}, {root_parent.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return null;
|
||||
}
|
||||
var custom_defined_ui_attribute = custom_defined_ui.getEntityAttribute<CustomDefinedUiAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(custom_defined_ui_attribute, () => $"custom_defined_ui_attribute is null !!! - {owner.toBasicString()}, {root_parent.toBasicString()}");
|
||||
|
||||
custom_defined_ui_attribute.UiKey = uiKey;
|
||||
custom_defined_ui_attribute.CustomDefinedUi = foundVisible.ToString();
|
||||
|
||||
custom_defined_ui_attribute.newEntityAttribute();
|
||||
|
||||
return custom_defined_ui;
|
||||
};
|
||||
|
||||
var update_custom_defined_ui = delegate (string uiKey, CustomDefinedUi currValue)
|
||||
{
|
||||
var custom_defined_ui_attribute = currValue.getEntityAttribute<CustomDefinedUiAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(custom_defined_ui_attribute, () => $"custom_defined_ui_attribute is null !!! - {owner.toBasicString()}, {root_parent.toBasicString()}");
|
||||
|
||||
custom_defined_ui_attribute.UiKey = uiKey;
|
||||
custom_defined_ui_attribute.CustomDefinedUi = foundVisible.ToString();
|
||||
|
||||
custom_defined_ui_attribute.modifiedEntityAttribute();
|
||||
|
||||
return currValue;
|
||||
};
|
||||
|
||||
m_custom_defined_uis.AddOrUpdate(ui_key, add_custom_defined_ui, update_custom_defined_ui);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<Result> checkCustomDefinedUiSize(string itemString)
|
||||
{
|
||||
var owner = getOwner();
|
||||
var root_parent = owner.getRootParent();
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_save_data = itemString + CustomDefinedUiDoc.getPrefixOfPK() + CustomDefinedUiDoc.getPrefixOfSK();
|
||||
|
||||
if (false == DynamoDbConnectorBase.checkItemSizeLimit(to_save_data))
|
||||
{
|
||||
err_msg = $"Failed to DynamoDbConnectorBase.checkItemSizeLimit() !!! - {owner.toBasicString()}, {root_parent.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.DynamoDbItemSizeExceeded, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public MapField<UI_KEY, string> toCustomDefinedUiAll()
|
||||
{
|
||||
var map_field = new MapField<UI_KEY, string>();
|
||||
|
||||
foreach (var each in m_custom_defined_uis)
|
||||
{
|
||||
var custom_defined_ui_attribute = each.Value.getEntityAttribute<CustomDefinedUiAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(custom_defined_ui_attribute, () => $"custom_defined_ui_attribute is null !!!");
|
||||
|
||||
var ui_key = each.Key;
|
||||
var ui_value = custom_defined_ui_attribute.CustomDefinedUi;
|
||||
|
||||
map_field.Add(each.Key, ui_value);
|
||||
}
|
||||
|
||||
return map_field;
|
||||
}
|
||||
}
|
||||
}
|
||||
48
GameServer/Entity/CustomDefinedUi/CustomDefinedUi.cs
Normal file
48
GameServer/Entity/CustomDefinedUi/CustomDefinedUi.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class CustomDefinedUi : EntityBase
|
||||
{
|
||||
public CustomDefinedUi(EntityBase parent)
|
||||
: base(EntityType.CustomDefinedUi, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
var parent = getDirectParent();
|
||||
NullReferenceCheckHelper.throwIfNull(parent, () => $"parent is null !!!");
|
||||
|
||||
addEntityAttribute(new CustomDefinedUiAttribute(this, parent));
|
||||
|
||||
return await base.onInit();
|
||||
}
|
||||
|
||||
public override string toBasicString()
|
||||
{
|
||||
var custom_defined_ui_attribute = getOriginEntityAttribute<CustomDefinedUiAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(custom_defined_ui_attribute, () => $"custom_defined_ui_attribute is null !!!");
|
||||
|
||||
return $"{this.getTypeName()}, UIKey:{custom_defined_ui_attribute.UiKey}, UILength:{custom_defined_ui_attribute.CustomDefinedUi.Length}";
|
||||
}
|
||||
|
||||
public override string toSummaryString()
|
||||
{
|
||||
var custom_defined_ui_attribute = getOriginEntityAttribute<CustomDefinedUiAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(custom_defined_ui_attribute, () => $"custom_defined_ui_attribute is null !!!");
|
||||
|
||||
return $"{this.getTypeName()}, {custom_defined_ui_attribute.toBasicString()}";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user