초기커밋

This commit is contained in:
2025-05-01 07:20:41 +09:00
commit 98bb2e3c5c
2747 changed files with 646947 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameServer
{
internal class RentalAction : EntityActionBase
{
public RentalAction(Rental owner)
: base(owner)
{ }
public override async Task<Result> onInit()
{
var result = new Result();
return await Task.FromResult(result);
}
public override void onClear()
{
return;
}
public bool isRentalFinsh()
{
var rental = getOwner() as Rental;
NullReferenceCheckHelper.throwIfNull(rental, () => $"rental is null !!!");
var rental_attribute = rental.getEntityAttribute<RentalAttribute>();
NullReferenceCheckHelper.throwIfNull(rental_attribute, () => $"rental_attribute is null !!!");
if (DateTime.UtcNow > rental_attribute.RentalFinishTime)
return true;
return false;
}
}
}

View File

@@ -0,0 +1,140 @@
using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ClientToGameReq.Types;
namespace GameServer
{
internal class RentalAgentAction : EntityActionBase
{
ConcurrentDictionary<(int, int, int), Rental> m_rentals = new();
public RentalAgentAction(Player owner)
: base(owner)
{ }
public override async Task<Result> onInit()
{
var result = new Result();
return await Task.FromResult(result);
}
public override void onClear()
{
return;
}
public List<Rental> getRentals()
{
return m_rentals.Values.ToList();
}
public async Task<Result> tryAddRentalFromDoc(RentalDoc rentalDoc)
{
var result = new Result();
var err_msg = string.Empty;
var player = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
var server_logic = GameServerApp.getServerLogic();
var rental = new Rental(player);
await rental.onInit();
var rental_attribute = rental.getEntityAttribute<RentalAttribute>();
NullReferenceCheckHelper.throwIfNull(rental_attribute, () => $"rental_attribute is null !!! - {player.toBasicString()}");
if (!rental_attribute.copyEntityAttributeFromDoc(rentalDoc))
{
err_msg = $"Failed to copyEntityAttributeFromDoc() !!! to:{rental_attribute.getTypeName()}, from:{rentalDoc.getTypeName()} : {this.getTypeName()}";
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
if (!m_rentals.TryAdd((rental_attribute.LandMetaId, rental_attribute.BuildingMetaId, rental_attribute.Floor), rental))
{
err_msg = $"Failed to TryAdd() !!! : {rental.toBasicString()} : {this.getTypeName()}";
result.setFail(ServerErrorCode.RentalDocLoadDuplicatedRental, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
return result;
}
public void addRental(int landMetaId, int buildingMetaId, int floor, Rental rental)
{
m_rentals[(landMetaId, buildingMetaId, floor)] = rental;
}
public bool isRentalMyhome(string myhomeGuid)
{
foreach (var rental in m_rentals.Values)
{
var rental_attribute = rental.getEntityAttribute<RentalAttribute>();
if (rental_attribute == null)
continue;
if (rental_attribute.MyhomeGuid == myhomeGuid)
return true;
}
return false;
}
public (int, int, int) getAddrressFromMyhome(string myhomeGuid)
{
var land_meta_id = 0;
var building_meta_id = 0;
var floor = 0;
foreach (var rental in m_rentals.Values)
{
var rental_attribute = rental.getEntityAttribute<RentalAttribute>();
if (rental_attribute == null)
continue;
if (rental_attribute.MyhomeGuid == myhomeGuid)
{
land_meta_id = rental_attribute.LandMetaId;
building_meta_id = rental_attribute.BuildingMetaId;
floor = rental_attribute.Floor;
}
}
return (land_meta_id, building_meta_id, floor);
}
public override async Task onTick()
{
await Task.CompletedTask;
var remove_address = new List<(int, int, int)>();
foreach (var (address, rental) in m_rentals)
{
var rental_action = rental.getEntityAction<RentalAction>();
NullReferenceCheckHelper.throwIfNull(rental_action, () => $"rental_action is null !!!");
if (rental_action.isRentalFinsh())
{
remove_address.Add(address);
}
}
foreach (var address in remove_address)
{
m_rentals.TryRemove(address, out _);
}
}
}
}

View File

@@ -0,0 +1,91 @@
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using ServerCore;
using ServerBase;
using ServerCommon;
using ServerCommon.BusinessLogDomain;
using MetaAssets;
namespace GameServer;
public class RentalVisitAction : EntityActionBase
{
public RentalVisitAction(Player owner)
: base(owner)
{ }
public override async Task<Result> onInit()
{
var result = new Result();
return await Task.FromResult(result);
}
public override void onClear()
{
return;
}
public Result setRentalInstanceVisitFromDoc(RentalInstanceVisitDoc doc)
{
var result = new Result();
var owner = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var rental_instance_visit_attribute = owner.getEntityAttribute<RentalInstanceVisitAttribute>();
if (rental_instance_visit_attribute is null)
{
var err_msg = $"Fail to get rental_instance_visit_attribute";
result.setFail(ServerErrorCode.EntityAttributeNotFound, err_msg);
return result;
}
if (false == doc.getAttribWrappers().TryGetValue(typeof(RentalInstanceVisitAttrib), out var to_copy_doc_attrib))
{
var err_msg = $"Fail to get RentalInstanceVisitAttrib";
result.setFail(ServerErrorCode.EntityAttributeNotFound, err_msg);
return result;
}
var attrib_base = to_copy_doc_attrib.getAttribBase();
var doc_attrib = attrib_base as RentalInstanceVisitAttrib;
if (doc_attrib is null)
{
var err_msg = $"Fail to get RentalInstanceVisitAttrib";
result.setFail(ServerErrorCode.EntityAttributeNotFound, err_msg);
return result;
}
foreach (var visitor in doc_attrib.m_rental_instance_visit_guid)
{
rental_instance_visit_attribute.m_rental_instance_visit.AddOrUpdate(visitor.Key, visitor.Value, (key, oldValue) => visitor.Value);
}
rental_instance_visit_attribute.m_next_refresh_time = doc_attrib.m_next_refresh_time;
rental_instance_visit_attribute.syncOriginDocBaseWithNewDoc<RentalInstanceVisitAttribute>(doc);
return result;
}
public void refresh(RentalInstanceVisitAttribute attribute)
{
var player = getOwner();
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
var now = DateTimeHelper.Current;
//시간 안됐으므로 리턴
if (attribute.m_next_refresh_time > now) return;
attribute.m_next_refresh_time = DateTimeHelper.Current.Date.AddDays(1);
attribute.m_rental_instance_visit = new();
attribute.modifiedEntityAttribute(true);
}
}