示例#1
0
        private bool ResolveIf(PlayerGameSave gameSave, string command)
        {
            var split = command.Split(null);

            split = split.Where(a => !string.IsNullOrEmpty(a)).ToArray();
            bool andMore       = false;
            bool orMore        = false;
            int  indexMod      = 0;
            bool?initialResult = null;

            if (split.Length > 2 && (split[2] == "=" || split[2] == ">" || split[2] == "<"))
            {
                if (split.Length > 4)
                {
                    andMore = split[4] == "#and";
                    orMore  = split[4] == "#or";
                }

                var data1       = ResolveValue(split[1], gameSave);
                var conditional = split[2];
                var data2       = ConcactSplitAfterxUptoCharacter(split, 3, "#");

                var doesData2Exist = _gameDataService.GetData(gameSave, data2);
                if (doesData2Exist != null)
                {
                    data2 = doesData2Exist;
                }

                data2 = ResolveValue(data2, gameSave);

                if (split[0] == "#ifnot")
                {
                    initialResult = !ResolveOperation(data1, data2, conditional, gameSave);
                }
                if (split[0] == "#if")
                {
                    initialResult = ResolveOperation(data1, data2, conditional, gameSave);
                }
                indexMod = 5;
            }
            else
            {
                if (split.Length > 2)
                {
                    andMore = split[2] == "#and";
                    orMore  = split[2] == "#or";
                }
                bool exists = _gameDataService.DataExists(gameSave, split[1]);
                if (split[0] == "#ifnot")
                {
                    initialResult = !exists;
                }
                if (split[0] == "#if")
                {
                    initialResult = exists;
                }
                indexMod = 3;
            }

            if (andMore)
            {
                return(initialResult.Value && ResolveIf(gameSave, ConcatSplitAfterIndex(split, indexMod)));
            }
            else if (orMore)
            {
                return(initialResult.Value || ResolveIf(gameSave, ConcatSplitAfterIndex(split, indexMod)));
            }
            else
            {
                return(initialResult.Value);
            }
            throw new ApplicationException("Error parsing: " + command);
        }