コード例 #1
0
ファイル: Form1.cs プロジェクト: Dragonfangs/RandoEditor
        private NodeBase PlaceNewNode(NodeType type, Vector2 mousePos)
        {
            NodeBase newNode = null;

            switch (type)
            {
            case NodeType.Blank:
                newNode = new BlankNode();
                break;

            case NodeType.Lock:
                newNode = new LockNode();
                break;

            case NodeType.RandomKey:
                newNode = new RandomKeyNode();
                break;

            case NodeType.EventKey:
                newNode = new EventKeyNode();
                break;

            default:
                return(null);
            }

            newNode.myPos = (mousePos / ZoomScale) - imageBasePos;

            myMementos.Add(myNodeCollection.AddNode(newNode));

            SaveManager.Dirty = true;

            selectedNode = newNode;

            UpdateNodeSettings();

            panel1.Invalidate();

            return(newNode);
        }
コード例 #2
0
        private bool KeyAllowedInLocation(Guid key, FillOptions options, Dictionary <string, Guid> itemMap, ItemPool pool, RandomKeyNode location)
        {
            if (itemBlockedLocationRules.ContainsKey(key) && itemBlockedLocationRules[key].Contains(location.myRandomKeyIdentifier))
            {
                // Blocked from being placed here
                return(false);
            }

            if ((StaticKeys.IsMajorItem(key) && options.majorSwap == FillOptions.ItemSwap.Unchanged) ||
                (StaticKeys.IsMinorItem(key) && options.minorSwap == FillOptions.ItemSwap.Unchanged))
            {
                if (key != location.myOriginalKeyId)
                {
                    return(false);
                }
            }

            if (options.majorSwap == FillOptions.ItemSwap.LocalPool && StaticKeys.IsMajorItem(key) && !StaticKeys.IsMajorItem(location.myOriginalKeyId))
            {
                return(false);
            }

            if (options.minorSwap == FillOptions.ItemSwap.LocalPool && StaticKeys.IsMinorItem(key) && !StaticKeys.IsMinorItem(location.myOriginalKeyId))
            {
                return(false);
            }

            if (options.majorSwap == FillOptions.ItemSwap.LocalPool && !StaticKeys.IsMajorItem(key) && StaticKeys.IsMajorItem(location.myOriginalKeyId))
            {
                var allRandomKeyNodes       = keyNodes.Where(node => node is RandomKeyNode randomNode).Select(node => node as RandomKeyNode).OrderBy(node => node.id);
                var openMajorRandomKeyNodes = allRandomKeyNodes.Count(node => !itemMap.ContainsKey(node.myRandomKeyIdentifier) && StaticKeys.IsMajorItem(node.myOriginalKeyId));

                var poolCount = pool.AvailableItems().Count(item => StaticKeys.IsMajorItem(item));
                if (openMajorRandomKeyNodes <= poolCount)
                {
                    return(false);
                }
            }

            if (options.minorSwap == FillOptions.ItemSwap.LocalPool && !StaticKeys.IsMinorItem(key) && StaticKeys.IsMinorItem(location.myOriginalKeyId))
            {
                var allRandomKeyNodes       = keyNodes.Where(node => node is RandomKeyNode randomNode).Select(node => node as RandomKeyNode).OrderBy(node => node.id);
                var openMinorRandomKeyNodes = allRandomKeyNodes.Count(node => !itemMap.ContainsKey(node.myRandomKeyIdentifier) && StaticKeys.IsMinorItem(node.myOriginalKeyId));

                var poolCount = pool.AvailableItems().Count(item => StaticKeys.IsMinorItem(item));
                if (openMinorRandomKeyNodes <= poolCount)
                {
                    return(false);
                }
            }

            var hasRequirementForLocation = false;
            var requirementFulfilled      = true;

            if (itemRequiredLocationRules.ContainsKey(key))
            {
                requirementFulfilled = itemMap.Any(loc => itemRequiredLocationRules[key].Contains(loc.Key) && loc.Value == key);

                hasRequirementForLocation = itemRequiredLocationRules[key].Contains(location.myRandomKeyIdentifier);
            }

            if (!requirementFulfilled && pool.CountKey(key) == 1 && !hasRequirementForLocation)
            {
                // Has requirement to be placed somewhere else and placing it here would not leave any item to place in that location
                return(false);
            }

            if (restrictedLocations.Contains(location.myRandomKeyIdentifier) && (requirementFulfilled || !hasRequirementForLocation))
            {
                // Location is restricted and this key is not one of the items with a requirement to be here
                return(false);
            }

            return(true);
        }