초기커밋
This commit is contained in:
185
ServerCommon/Entity/Attribute/PartyAttribute.cs
Normal file
185
ServerCommon/Entity/Attribute/PartyAttribute.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Nettention.Proud;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
|
||||
|
||||
using PARTY_GUID = System.String;
|
||||
using USER_GUID = System.String;
|
||||
|
||||
|
||||
namespace ServerCommon;
|
||||
|
||||
public class PartyVoteInfo
|
||||
{
|
||||
public string VoteTitle { get; set; } = string.Empty;
|
||||
public Dictionary<USER_GUID, VoteType> Votes { get; set; } = new();
|
||||
|
||||
public Timestamp StartVoteTime { get; set; } = new();
|
||||
|
||||
public PartyVoteInfo cloned()
|
||||
{
|
||||
var cloned = new PartyVoteInfo
|
||||
{
|
||||
VoteTitle = VoteTitle,
|
||||
StartVoteTime = StartVoteTime
|
||||
};
|
||||
|
||||
foreach (var vote in Votes)
|
||||
{
|
||||
cloned.Votes.Add(vote.Key, vote.Value);
|
||||
}
|
||||
|
||||
return cloned;
|
||||
}
|
||||
}
|
||||
|
||||
public class PartyAttribute : EntityAttributeBase, ICopyEntityAttributeFromCache
|
||||
{
|
||||
// 파티 정보
|
||||
public string PartyName { get; set; } = string.Empty;
|
||||
public string PartyLeaderCharGuid { get; set; } = string.Empty;
|
||||
|
||||
public string PartyLeaderNickname { get; set; } = string.Empty;
|
||||
|
||||
public DateTime CreatePartyTime { get; set; } = DateTimeHelper.Current;
|
||||
|
||||
public PartyVoteInfo? PartyVote { get; set; }
|
||||
public Timestamp? LastVoteTime { get; set; }
|
||||
|
||||
public HostID P2PGroup = HostID.HostID_None;
|
||||
|
||||
public PartyAttribute(EntityBase owner, NetServer? net_server) : base(owner)
|
||||
{
|
||||
onInit(net_server);
|
||||
}
|
||||
|
||||
private void onInit(NetServer? net_server)
|
||||
{
|
||||
if (null == net_server) return;
|
||||
|
||||
var byArray = new ByteArray();
|
||||
var p2PGroupType = new P2PGroupType();
|
||||
p2PGroupType.Type = 1;
|
||||
|
||||
ServerBase.ProudNetHelper.convertP2PGroupToByteArray(byArray, p2PGroupType);
|
||||
var arrHostId = Array.Empty<HostID>();
|
||||
P2PGroup = net_server.CreateP2PGroup(arrHostId, byArray);
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
PartyName = string.Empty;
|
||||
PartyLeaderCharGuid = string.Empty;
|
||||
PartyLeaderNickname = string.Empty;
|
||||
|
||||
PartyVote = null;
|
||||
P2PGroup = HostID.HostID_None;
|
||||
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override EntityAttributeBase onCloned()
|
||||
{
|
||||
var cloned = new PartyAttribute(getOwner(), null)
|
||||
{
|
||||
PartyName = PartyName,
|
||||
PartyLeaderCharGuid = PartyLeaderCharGuid,
|
||||
PartyLeaderNickname = PartyLeaderNickname,
|
||||
CreatePartyTime = CreatePartyTime,
|
||||
|
||||
P2PGroup = P2PGroup,
|
||||
PartyVote = PartyVote?.cloned()
|
||||
};
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public int getVoteCount(VoteType vote_type)
|
||||
{
|
||||
var count = 0;
|
||||
return null == PartyVote
|
||||
? count
|
||||
: PartyVote.Votes.Count(vote => vote.Value == vote_type);
|
||||
}
|
||||
public bool copyEntityAttributeFromCache(CacheBase? cacheBase)
|
||||
{
|
||||
var party_cache = cacheBase as PartyCache;
|
||||
if(null == party_cache)
|
||||
{
|
||||
var err_msg = $"Failed to copyEntityAttributeFromCache() !!!, party_cache is null :{nameof(PartyCache)}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// Cache => Attribute
|
||||
//=====================================================================================
|
||||
|
||||
PartyName = party_cache.PartyName;
|
||||
PartyLeaderCharGuid = party_cache.PartyLeaderCharGuid;
|
||||
PartyLeaderNickname = party_cache.PartyLeaderNickname;
|
||||
LastVoteTime = party_cache.LastVoteTime;
|
||||
CreatePartyTime = party_cache.CreatePartyTime;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new PartyAttributeTransactor(getOwner());
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
return (new Result(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public class PartyAttributeTransactor : EntityAttributeTransactorBase<PartyAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
||||
{
|
||||
public PartyAttributeTransactor(EntityBase owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase entityAttributeBase)
|
||||
{
|
||||
string err_msg;
|
||||
|
||||
var copy_from_party_attribute = entityAttributeBase as PartyAttribute;
|
||||
if (null == copy_from_party_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_party_attribute is null :{nameof(PartyAttribute)}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
var copy_to_party_attribute = getClonedEntityAttribute() as PartyAttribute;
|
||||
if (null == copy_to_party_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_party_attribute is null :{nameof(PartyAttribute)}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
copy_to_party_attribute.PartyName = copy_from_party_attribute.PartyName;
|
||||
copy_to_party_attribute.PartyLeaderCharGuid = copy_from_party_attribute.PartyLeaderCharGuid;
|
||||
copy_to_party_attribute.PartyLeaderNickname = copy_from_party_attribute.PartyLeaderNickname;
|
||||
copy_to_party_attribute.CreatePartyTime = copy_from_party_attribute.CreatePartyTime;
|
||||
copy_to_party_attribute.P2PGroup = copy_from_party_attribute.P2PGroup;
|
||||
copy_to_party_attribute.PartyVote = copy_from_party_attribute.PartyVote?.cloned();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user