|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
[FriendClass(typeof(Unit))]
|
|
|
|
|
public static class CuisineOperate
|
|
|
|
|
{
|
|
|
|
|
public static int StartCuisine(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 (unit.GetOrAddComponent<MenuComponent>().CheckoutMenu(config.Id) != 2)
|
|
|
|
|
{
|
|
|
|
|
return ErrorCode.ERR_ConfigError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ConstructOperate.CheckOutBuildingByIds(unit, config.StructureID))
|
|
|
|
|
{
|
|
|
|
|
return ErrorCode.ERR_NotProductionBuilding;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// todo 厨师判断
|
|
|
|
|
// if (config.SkillCondition > 0)
|
|
|
|
|
// {
|
|
|
|
|
// return ErrorCode.ERR_CuisineError;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
var store = unit.GetComponent<StoreComponent>();
|
|
|
|
|
var err = CheckoutItem(unit, store, config.ItemId, config.ItemNum, maxAmount);
|
|
|
|
|
if (err != ErrorCode.ERR_Success)
|
|
|
|
|
{
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeleteItem(unit, store, config.ItemId, config.ItemNum, maxAmount);
|
|
|
|
|
|
|
|
|
|
var mixtureId = config.MixtureID;
|
|
|
|
|
// todo 厨师判断
|
|
|
|
|
if (config.SkillCondition > 0)
|
|
|
|
|
{
|
|
|
|
|
mixtureId = config.QualityMixtureID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
store.Add(mixtureId, maxAmount);
|
|
|
|
|
|
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void DeleteItem(Unit unit, StoreComponent store, int[] itemId, int[] itemNum, long maxAmount)
|
|
|
|
|
{
|
|
|
|
|
for (var i = 0; i < itemId.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (itemId[i] == 1003)
|
|
|
|
|
{
|
|
|
|
|
// 扣清水
|
|
|
|
|
if (itemNum == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unit.Water -= itemNum[i];
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var needItem = itemNum == null? 1 : itemNum[i];
|
|
|
|
|
store.Remove(itemId[i], (int) (needItem * maxAmount));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int CheckoutItem(Unit unit, StoreComponent store, int[] itemId, int[] itemNum, long maxAmount)
|
|
|
|
|
{
|
|
|
|
|
for (var i = 0; i < itemId.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
long num = 0;
|
|
|
|
|
if (itemId[i] == 1003)
|
|
|
|
|
{
|
|
|
|
|
// 扣清水
|
|
|
|
|
if (itemNum == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
num = unit.Water;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
num = store.GetItemNum(itemId[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var needItem = (itemNum==null? 1 : itemNum[i]);
|
|
|
|
|
if (num < needItem * maxAmount)
|
|
|
|
|
{
|
|
|
|
|
return ErrorCode.ERR_MaterialNotEnough;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static (int, int) DevelopRecipes(Unit unit, List<int> ids)
|
|
|
|
|
{
|
|
|
|
|
int configId = 0;
|
|
|
|
|
int state = 1;
|
|
|
|
|
var cc = unit.GetComponent<CuisineComponent>();
|
|
|
|
|
if (cc != null && cc.checkCuisine())
|
|
|
|
|
{
|
|
|
|
|
return (ErrorCode.ERR_CuisineError, configId);
|
|
|
|
|
}
|
|
|
|
|
if (!ConstructOperate.CheckOutBuildingBySpecialType(unit, Constant.ConstStructureSpecialType.KITCHEN))
|
|
|
|
|
{
|
|
|
|
|
return (ErrorCode.ERR_CuisineError, configId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var store = unit.GetComponent<StoreComponent>();
|
|
|
|
|
var config = SynthesisConfigCategory.Instance.GetSynthesisConfigByItemId(ids.ToArray(), Constant.ConstSynthesisMixtureType.FOOD);
|
|
|
|
|
// 存在菜谱
|
|
|
|
|
if (config != null && unit.GetOrAddComponent<MenuComponent>().CheckoutMenu(config.Id) > 0)
|
|
|
|
|
{
|
|
|
|
|
if (!ConstructOperate.CheckOutBuildingByIds(unit, config.StructureID))
|
|
|
|
|
{
|
|
|
|
|
return (ErrorCode.ERR_NotProductionBuilding, configId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// todo 厨师判断 不需要, 需要且存在 && 需要且不存在
|
|
|
|
|
if (config.SkillCondition == 0 || config.SkillCondition > 0)
|
|
|
|
|
{
|
|
|
|
|
configId = config.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var err = CheckoutItem(unit, store, config.ItemId, config.ItemNum, 1);
|
|
|
|
|
if (err != ErrorCode.ERR_Success)
|
|
|
|
|
{
|
|
|
|
|
return (err, configId);
|
|
|
|
|
}
|
|
|
|
|
state = 3;
|
|
|
|
|
}
|
|
|
|
|
else // 不存在菜谱
|
|
|
|
|
{
|
|
|
|
|
// todo 厨师判断
|
|
|
|
|
if (config != null && CheckOutCondition(unit, config) &&
|
|
|
|
|
(config.SkillCondition == 0 || (config.SkillCondition > 0 && config.SkillCondition > 0)))
|
|
|
|
|
{
|
|
|
|
|
configId = config.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var err = CheckoutItem(unit, store, ids.ToArray(), null, 1);
|
|
|
|
|
if (err != ErrorCode.ERR_Success)
|
|
|
|
|
{
|
|
|
|
|
return (err, configId);
|
|
|
|
|
}
|
|
|
|
|
state = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cuisine = unit.GetOrAddComponent<CuisineComponent>().StartCuisine(configId);
|
|
|
|
|
if (cuisine == null)
|
|
|
|
|
{
|
|
|
|
|
return (ErrorCode.ERR_CuisineError, configId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state == 2)
|
|
|
|
|
{
|
|
|
|
|
DeleteItem(unit, store, ids.ToArray(), null, 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DeleteItem(unit, store, config.ItemId, config.ItemNum, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (ErrorCode.ERR_Success, configId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool CheckOutCondition(Unit unit, SynthesisConfig config)
|
|
|
|
|
{
|
|
|
|
|
var res = false;
|
|
|
|
|
switch (config.UnlockCondition)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
{ // TODO 规模解锁
|
|
|
|
|
if (config.Parameter2 <= unit.Scale)
|
|
|
|
|
{
|
|
|
|
|
res = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
{ // TODO 道具解锁
|
|
|
|
|
if (config.MixtureTpye == 3)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
res = unit.GetComponent<MenuComponent>().CheckoutMenu(config.Id) > 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// todo 断线重连 添加
|
|
|
|
|
public static (int, int) EndCuisine(Unit unit, int result)
|
|
|
|
|
{
|
|
|
|
|
CuisineComponent cc = unit.GetComponent<CuisineComponent>();
|
|
|
|
|
if (cc == null)
|
|
|
|
|
{
|
|
|
|
|
return (ErrorCode.ERR_CuisineError, 0);
|
|
|
|
|
}
|
|
|
|
|
Cuisine cuisine = cc.GetChild<Cuisine>(0);
|
|
|
|
|
if (cuisine == null)
|
|
|
|
|
{
|
|
|
|
|
return (ErrorCode.ERR_CuisineError, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var configId = 0;
|
|
|
|
|
int mixtureId = Constant.NORMAL_FOOD;
|
|
|
|
|
if (result == 1)
|
|
|
|
|
{
|
|
|
|
|
SynthesisConfig config = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
config = cuisine.Config;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config != null)
|
|
|
|
|
{
|
|
|
|
|
if (ConstructOperate.CheckOutBuildingByIds(unit, config.StructureID) && CheckOutCondition(unit, config))
|
|
|
|
|
{
|
|
|
|
|
var state = 0;
|
|
|
|
|
var checkMenu = unit.GetComponent<MenuComponent>().CheckoutMenu(config.Id) > 0;
|
|
|
|
|
// todo 判断厨师
|
|
|
|
|
if (config.SkillCondition == 0)
|
|
|
|
|
{
|
|
|
|
|
if (checkMenu && config.SkillCondition > 0)
|
|
|
|
|
{
|
|
|
|
|
state = 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
state = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (config.SkillCondition > 0)
|
|
|
|
|
{
|
|
|
|
|
if (checkMenu) // 制作
|
|
|
|
|
{
|
|
|
|
|
state = 2;
|
|
|
|
|
}
|
|
|
|
|
else // 研发
|
|
|
|
|
{
|
|
|
|
|
state = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state == 1)
|
|
|
|
|
{
|
|
|
|
|
mixtureId = config.MixtureID;
|
|
|
|
|
configId = config.Id;
|
|
|
|
|
}
|
|
|
|
|
else if (state == 2)
|
|
|
|
|
{
|
|
|
|
|
mixtureId = config.QualityMixtureID;
|
|
|
|
|
configId = config.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (configId != 0)
|
|
|
|
|
{
|
|
|
|
|
unit.GetComponent<MenuComponent>().Add(config.Id, state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StoreOperate.AddItem(unit, mixtureId, 1);
|
|
|
|
|
cuisine.Dispose();
|
|
|
|
|
cc.Dispose();
|
|
|
|
|
|
|
|
|
|
return (ErrorCode.ERR_Success, mixtureId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|