초기커밋
This commit is contained in:
185
GameServer/Entity/Npc/UgcNpc/Action/UgcNpcBeaconShopAction.cs
Normal file
185
GameServer/Entity/Npc/UgcNpc/Action/UgcNpcBeaconShopAction.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
using System.Collections.Concurrent;
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using ITEM_GUID = System.String;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class UgcNpcBeaconShopAction : EntityActionBase
|
||||
{
|
||||
private bool m_isUpdateBeaconShopItem = false;
|
||||
private ConcurrentDictionary<ITEM_GUID, BeaconShopItem> m_beaconShopItems = new ConcurrentDictionary<ITEM_GUID, BeaconShopItem>();
|
||||
|
||||
public UgcNpcBeaconShopAction(UgcNpc owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
return await Task.FromResult(new Result());
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<Result> ReloadBeaconShopInventoryFromDb()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var ugc_npc = getOwner() as UgcNpc;
|
||||
NullReferenceCheckHelper.throwIfNull(ugc_npc, () => $"ugc_npc is null !!! - {toBasicString()}");
|
||||
|
||||
if (m_isUpdateBeaconShopItem == false)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
NullReferenceCheckHelper.throwIfNull(server_logic, () => $"server_logic is null !!! - {toBasicString()}");
|
||||
var dbClient = server_logic.getDynamoDbClient();
|
||||
|
||||
var ugcNpcMetaGuid = ugc_npc.getUgcNpcMetaGuid();
|
||||
if (ugcNpcMetaGuid == string.Empty)
|
||||
{
|
||||
result.setFail(ServerErrorCode.BeaconShopFailedReloadBeaconShopInven);
|
||||
return result;
|
||||
}
|
||||
|
||||
(result, var make_primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<BeaconShopItemDoc>(ugcNpcMetaGuid);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(make_primary_key, () => $"make_primary_key is null !!! - {toBasicString()}");
|
||||
|
||||
var beacon_shop_item_query_config = dbClient.makeQueryConfigForReadByPKOnly(make_primary_key.PK);
|
||||
(var beacon_shop_item_result, var beacon_shop_item_read_docs) = await dbClient.simpleQueryDocTypesWithQueryOperationConfig<BeaconShopItemDoc>(beacon_shop_item_query_config);
|
||||
if (beacon_shop_item_result.isFail() || beacon_shop_item_read_docs == null)
|
||||
{
|
||||
result.setFail(ServerErrorCode.BeaconShopFailedReloadBeaconShopInven);
|
||||
return result;
|
||||
}
|
||||
|
||||
m_beaconShopItems.Clear();
|
||||
|
||||
foreach (var read_doc in beacon_shop_item_read_docs)
|
||||
{
|
||||
var beacon_shop_item_attrib = read_doc.getAttrib<BeaconShopItemAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_item_attrib, () => $"beacon_shop_item_attrib is null !!! - {toBasicString()}");
|
||||
|
||||
if(beacon_shop_item_attrib.ItemStackCount == 0)
|
||||
{
|
||||
await dbClient.simpleDeleteDocumentWithDocType(read_doc);
|
||||
continue;
|
||||
}
|
||||
|
||||
(result, var beaconShopItem) = await BeaconShopItem.createBeaconShopFromDoc(ugc_npc, read_doc);
|
||||
if (result.isFail() || beaconShopItem == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var beacon_shop_item_attribute = beaconShopItem.getEntityAttribute<BeaconShopItemAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_item_attribute, () => $"beacon_shop_item_attribute is null !!! - {toBasicString()}");
|
||||
|
||||
m_beaconShopItems.TryAdd(beacon_shop_item_attribute.ItemGuid, beaconShopItem);
|
||||
}
|
||||
|
||||
m_isUpdateBeaconShopItem = false;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<Result> addBeaconShopItem(BeaconShopItemDoc beaconShopItemDoc)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
var ugc_npc = getOwner() as UgcNpc;
|
||||
NullReferenceCheckHelper.throwIfNull(ugc_npc, () => $"ugc_npc is null !!! - {toBasicString()}");
|
||||
|
||||
var beacon_shop_item_attrib = beaconShopItemDoc.getAttrib<BeaconShopItemAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_item_attrib, () => $"beacon_shop_item_attrib is null !!! - {toBasicString()}");
|
||||
|
||||
if (beacon_shop_item_attrib.ItemStackCount == 0)
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
NullReferenceCheckHelper.throwIfNull(server_logic, () => $"server_logic is null !!! - {toBasicString()}");
|
||||
var dbClient = server_logic.getDynamoDbClient();
|
||||
|
||||
await dbClient.simpleDeleteDocumentWithDocType(beaconShopItemDoc);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (m_beaconShopItems.TryGetValue(beacon_shop_item_attrib.ItemGuid, out var beaconShopItem) == true)
|
||||
{
|
||||
err_msg = $"Found duplicated Item from BeaconShopItemDoc !!! : duplicatedItem:{beaconShopItem.toBasicString()} - {beaconShopItemDoc.toBasicString()}, {toBasicString()}";
|
||||
result.setFail(ServerErrorCode.ItemDocLoadDuplicatedItem, err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
(result, var new_beacon_shop_item) = await BeaconShopItem.createBeaconShopFromDoc(ugc_npc, beaconShopItemDoc);
|
||||
if (result.isFail() || new_beacon_shop_item == null)
|
||||
{
|
||||
err_msg = $"Failed to create Item !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
m_beaconShopItems.TryAdd(beacon_shop_item_attrib.ItemGuid, new_beacon_shop_item);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addBeaconShopItem(ITEM_GUID itemGuid, BeaconShopItem beaconShopItem)
|
||||
{
|
||||
m_beaconShopItems.TryAdd(itemGuid, beaconShopItem);
|
||||
}
|
||||
|
||||
public void removeBeaconShopItem(ITEM_GUID itemGuid)
|
||||
{
|
||||
m_beaconShopItems.TryRemove(itemGuid, out var beaconShopItem);
|
||||
writeBeaconShopItemLog("removeBeaconShopItem");
|
||||
}
|
||||
|
||||
public List<BeaconShopItem> getHasBeaconShopItem()
|
||||
{
|
||||
return m_beaconShopItems.Select(x => x.Value).ToList();
|
||||
}
|
||||
|
||||
public BeaconShopItem? getBeaconShopItem(ITEM_GUID itemGuid)
|
||||
{
|
||||
if (m_beaconShopItems.TryGetValue(itemGuid, out var beaconShopItem) == false)
|
||||
{
|
||||
writeBeaconShopItemLog("Failed getBeaconShopItem");
|
||||
return null;
|
||||
}
|
||||
|
||||
return beaconShopItem;
|
||||
}
|
||||
|
||||
public void writeBeaconShopItemLog(string function)
|
||||
{
|
||||
var item_list = string.Empty;
|
||||
foreach (var item in m_beaconShopItems.Values)
|
||||
{
|
||||
var str = JsonConvert.SerializeObject(item.getEntityAttribute<BeaconShopItemAttribute>());
|
||||
item_list += $"{str},";
|
||||
}
|
||||
|
||||
Log.getLogger().Debug($"BeaconShop - {function}, Selling items : {item_list}");
|
||||
}
|
||||
|
||||
public bool hasBeaconShopItem()
|
||||
{
|
||||
return m_beaconShopItems.Count > 0 ? true : false;
|
||||
}
|
||||
public void setUpdateBeaconShopItem()
|
||||
{
|
||||
m_isUpdateBeaconShopItem = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user