You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

91 lines
3.2 KiB

using System;
namespace ET
{
[FriendClass(typeof(Synthesis))]
public static class SynthesisHelper
{
public static async ETTask<int> StartSynthesis(Unit unit, int configId, long maxAmount)
{
try
{
C2M_StartSynthesis msg = new C2M_StartSynthesis() { ConfigId = configId, MaxAmount = maxAmount };
M2C_StartSynthesis resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_StartSynthesis;
if (resp.Error == ErrorCode.ERR_Success)
{
var synthesis = unit.GetOrAddComponent<SynthesisComponent>().StartSynthesis(configId, maxAmount);
Log.Debug($"M2C_StartSynthesis_Success: {unit.GetComponent<SynthesisComponent>().Children.Count}");
}
else
{
Log.Error(resp.Error.ToString());
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
public static async ETTask<int> UpdateSynthesis(Unit unit)
{
try
{
C2M_GetSynthesis msg = new C2M_GetSynthesis();
M2C_GetSynthesis resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_GetSynthesis;
if (resp.Error != ErrorCode.ERR_Success)
{
Log.Error(resp.Error.ToString());
return resp.Error;
}
SynthesisComponent component = unit.GetOrAddComponent<SynthesisComponent>();
component.Dispose();
component = unit.GetOrAddComponent<SynthesisComponent>();
foreach (var v in resp.SynthesisList)
{
var synthesis = component.AddChildWithId<Synthesis>(v.ConfigId);
synthesis.Progress = v.Progress;
synthesis.CurrAmount = v.CurrAmount;
synthesis.MaxAmount = v.MaxAmount;
synthesis.UpdateTime = v.UpdateTime;
synthesis.ConfigId = v.ConfigId;
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
public static async ETTask<int> EndSynthesis(Unit unit, int configId)
{
try
{
C2M_EndSynthesis msg = new C2M_EndSynthesis() { ConfigId = configId };
M2C_EndSynthesis resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_EndSynthesis;
if (resp.Error == ErrorCode.ERR_Success)
{
var err = SynthesisOperate.EndSynthesis(unit, configId);
}
else
{
Log.Error(resp.Error.ToString());
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
}
}