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.
57 lines
2.0 KiB
57 lines
2.0 KiB
3 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace ET
|
||
|
{
|
||
|
[FriendClass(typeof(Menu))]
|
||
|
public static class MenuHelper
|
||
|
{
|
||
|
public static async ETTask<int> GetMenu(Unit unit)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
M2C_GetMenu resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(new C2M_GetMenu() { }) as M2C_GetMenu;
|
||
|
if (resp.Error != ErrorCode.ERR_Success)
|
||
|
{
|
||
|
Log.Error(resp.Error.ToString());
|
||
|
return resp.Error;
|
||
|
}
|
||
|
|
||
|
MenuComponent menuComponent = unit.GetOrAddComponent<MenuComponent>();
|
||
|
menuComponent.Dispose();
|
||
|
menuComponent = unit.GetOrAddComponent<MenuComponent>();
|
||
|
foreach (var v in resp.MenuList)
|
||
|
{
|
||
|
Menu menu = menuComponent.AddChildWithId<Menu>(v.ConfigId);
|
||
|
menu.FromMessage(v);
|
||
|
}
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
Console.WriteLine(e);
|
||
|
throw;
|
||
|
}
|
||
|
|
||
|
await ETTask.CompletedTask;
|
||
|
return ErrorCode.ERR_Success;
|
||
|
}
|
||
|
|
||
|
public static List<Menu> GetUnlockedMenuWithType(Unit unit, int type)
|
||
|
{
|
||
|
List<Menu> result = new List<Menu>();
|
||
|
MenuComponent menuComponent = unit.GetOrAddComponent<MenuComponent>();
|
||
|
foreach (var v in menuComponent.Children.Values)
|
||
|
{
|
||
|
Menu menu = (Menu)v;
|
||
|
SynthesisConfig synthesisConfig = SynthesisConfigCategory.Instance.Get(menu.ConfigId);
|
||
|
AllItemConfig allItemConfig = AllItemConfigCategory.Instance.Get(synthesisConfig.MixtureID);
|
||
|
CuisineConfig cuisineConfig = CuisineConfigCategory.Instance.Get(allItemConfig.RelatedId);
|
||
|
if(cuisineConfig.Type == type)
|
||
|
{
|
||
|
result.Add(menu);
|
||
|
}
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
}
|
||
|
}
|