using System.Collections.Generic; namespace ET { [FriendClass(typeof(Synthesis))] public static class SynthesisOperate { public static int StartSynthesis(Unit unit, int configId, long maxAmount) { if (maxAmount <= 0) { return ErrorCode.ERR_OperateFail; } var config = SynthesisConfigCategory.Instance.Get(configId); if (config == null) { return ErrorCode.ERR_ConfigError; } if (config.MixtureTpye != Constant.ConstSynthesisMixtureType.MATERIAL) { return ErrorCode.ERR_OperateFail; } if (!unit.GetComponent().CheckOutBuildingByIds(config.StructureID)) { return ErrorCode.ERR_NotProductionBuilding; } var store = unit.GetComponent(); for (var i = 0; i < config.ItemId.Length; i++) { long num = store.GetItemNum(config.ItemId[i]); if (num < config.ItemNum[i] * maxAmount) { return ErrorCode.ERR_MaterialNotEnough; } } var synthesis = unit.GetOrAddComponent().StartSynthesis(configId, maxAmount); if (synthesis == null) { return ErrorCode.ERR_SynthesisError; } for (var i = 0; i < config.ItemId.Length; i++) { store.Remove(config.ItemId[i], (int) (config.ItemNum[i] * maxAmount)); } return ErrorCode.ERR_Success; } public static int EndSynthesis(Unit unit, int configId) { Synthesis synthesis = unit.GetComponent().GetChild(configId); if (synthesis == null) { return ErrorCode.ERR_SynthesisNotFound; } SynthesisConfig config = synthesis.Config; long leftAmount = synthesis.MaxAmount - synthesis.CurrAmount; synthesis.Dispose(); if (leftAmount > 0) { StoreComponent storeComponent = unit.GetComponent(); for (int i = 0; i < config.ItemId.Length; i++) { storeComponent.Add(config.ItemId[i], config.ItemNum[i] * leftAmount); } } return ErrorCode.ERR_Success; } public static bool CheckOutBuildingByIds(Unit unit, int[] StructureID) { BuildingComponent bc = unit.GetComponent(); return bc.CheckOutBuildingByIds(StructureID); } public static void AddItem(Unit unit, SynthesisConfig config) { StoreComponent sc = unit.GetComponent(); sc.Add(config.MixtureID, config.Copies); } } }