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