コード例 #1
0
        private async Task <bool> TakeCharacterAction(string charid, Action <ResultHandler, Character> handler)
        {
            return(await TakeAction((res) =>
            {
                Guid id;

                Character ch = null;

                if (charid == "current")

                {
                    id = Guid.Empty;
                }
                else
                {
                    if (!Guid.TryParse(charid, out id))
                    {
                        res.Failed = true;
                        return;
                    }
                }


                if (id == Guid.Empty)
                {
                    ch = state.CurrentCharacter;
                }
                else
                {
                    ch = state.GetCharacterByID(id);
                }
                if (ch != null)
                {
                    try
                    {
                        handler(res, ch);
                    }
                    catch
                    {
                        res.Failed = true;
                    }
                }
                else
                {
                    res.Failed = true;
                }
            }));
        }