초기커밋
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
internal class OwnedBuildingAgentAction : EntityActionBase
|
||||
{
|
||||
ConcurrentDictionary<int, OwnedBuilding> m_owned_buildings = new();
|
||||
|
||||
public OwnedBuildingAgentAction(Player owner)
|
||||
: base(owner)
|
||||
{ }
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
var result = new Result();
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
m_owned_buildings.Clear();
|
||||
}
|
||||
|
||||
public bool tryGetOwnedBuilding(int buildingMetaId, [MaybeNullWhen(false)] out OwnedBuilding ownedBuilding)
|
||||
{
|
||||
return m_owned_buildings.TryGetValue(buildingMetaId, out ownedBuilding);
|
||||
}
|
||||
|
||||
public List<OwnedBuilding> getOwnedBuildings()
|
||||
{
|
||||
return m_owned_buildings.Values.ToList();
|
||||
}
|
||||
|
||||
public bool isOwnedBuilding(int buildingMetaId)
|
||||
{
|
||||
return m_owned_buildings.ContainsKey(buildingMetaId);
|
||||
}
|
||||
|
||||
public void addOwnedBuilding(int buildingMetaId, OwnedBuilding ownedBuilding)
|
||||
{
|
||||
m_owned_buildings[buildingMetaId] = ownedBuilding;
|
||||
}
|
||||
|
||||
public void removeOwnedBuilding(int buildingMetaId)
|
||||
{
|
||||
m_owned_buildings.TryRemove(buildingMetaId, out _);
|
||||
}
|
||||
|
||||
public async Task<Result> tryAddOwnedBuildingFromDoc(OwnedBuildingDoc ownedBuildingDoc)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var player = getOwner() as Player;
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
|
||||
OwnedBuilding owned_building = new(player);
|
||||
await owned_building.onInit();
|
||||
|
||||
var owned_building_attribute = owned_building.getEntityAttribute<OwnedBuildingAttribute>();
|
||||
ArgumentNullException.ThrowIfNull(owned_building_attribute);
|
||||
|
||||
if (!owned_building_attribute.copyEntityAttributeFromDoc(ownedBuildingDoc))
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!! to:{owned_building_attribute.getTypeName()}, from:{ownedBuildingDoc.getTypeName()} : {this.getTypeName()}";
|
||||
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!m_owned_buildings.TryAdd((int)owned_building_attribute.BuildingMetaId, owned_building))
|
||||
{
|
||||
err_msg = $"Failed to TryAdd() !!! : {owned_building_attribute.toBasicString()} : {this.getTypeName()}";
|
||||
result.setFail(ServerErrorCode.BuildingDocLoadDuplicatedBuilding, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user