namespace ET { [FriendClass(typeof(Unit))] [FriendClass(typeof(Synthesis))] [FriendClass(typeof(Construct))] public static class StoreOperate { public static void AddItem(Unit unit, int configId, long Amount) { if (configId == 6001) { // todo 最大值待定 if (unit.SilverTael + Amount > 99999999999) { return; } unit.SilverTael += (int)Amount; return; } if (configId == 6002) { // todo 最大值待定 if (unit.GoldIngot + Amount > 99999999999) { return; } unit.GoldIngot += (int)Amount; return; } StoreComponent sc = unit.GetComponent(); sc.Add(configId, Amount); } public static int DropItem(Unit unit, int configId, int amount) { StoreComponent store = unit.GetComponent(); var allItemConfig = AllItemConfigCategory.Instance.Get(configId); if (store.GetItemNum(configId) < amount || allItemConfig.AbleThrow == 0) { return ErrorCode.ERR_DropError; } store.Remove(configId, amount); return ErrorCode.ERR_Success; } public static bool UseItem(Unit unit, int configId, int amount, long synthesisId) { StoreComponent store = unit.GetComponent(); var allItemConfig = AllItemConfigCategory.Instance.Get(configId); if (store.GetItemNum(configId) < amount) { return false; } switch (allItemConfig.RelatedTable) { case 2: { FunctionItemConfig fConfig = FunctionItemConfigCategory.Instance.Get(allItemConfig.RelatedId); switch (fConfig.UseType) { case 1: { } break; case 2: { SynthesisComponent synthesisComponent = unit.GetComponent(); Synthesis synthesis = synthesisComponent.GetChild(synthesisId); synthesis.Progress += fConfig.UseTypeParameter * amount * 60 * 1000; } break; case 3: { MenuComponent menuComponent = unit.GetComponent(); menuComponent.initMenu(fConfig.UseTypeParameter); } break; case 4: { ConstructComponent cc = unit.GetComponent(); Construct construct = cc.GetChild(synthesisId); construct.AddEfficiency += fConfig.UseTypeParameter * amount; } break; } } break; case 3: { CuisineConfig cConfig = CuisineConfigCategory.Instance.Get(allItemConfig.RelatedId); if (cConfig != null) { unit.Food += cConfig.FoodNum * amount; } } break; default: break; } store.Remove(configId, amount); return true; } public static ResourcePoint UseSaplingItem(Unit unit, int itemId, float posX, float posY) { StoreComponent sc = unit.GetComponent(); if (sc.GetItemNum(itemId) < 1) { return null; } if (sc.Remove(itemId, 1)) { var itemConfig = AllItemConfigCategory.Instance.Get(itemId); FunctionItemConfig funcItemConfig = FunctionItemConfigCategory.Instance.Get(itemConfig.RelatedId); if (funcItemConfig.UseType != 1) { return null; } var saplingConfigId = funcItemConfig.UseTypeParameter; var saplingConfig = SaplingConfigCategory.Instance.Get(saplingConfigId); return ResourceOperate.CreateResource(unit, saplingConfig.RelatedResourcesPoint, posX, posY); } return null; } } }