コード例 #1
0
        public SpriteGroupCollection(RomData romData, Random rand, SpriteRequirementCollection spriteRequirementsCollection)
        {
            this.romData = romData;
            this.rand    = rand;
            this.spriteRequirementsCollection = spriteRequirementsCollection;

            dungeonReqs = new RoomGroupRequirementCollection();

            SpriteGroups = new List <SpriteGroup>();
        }
コード例 #2
0
        public void SetupRequiredDungeonGroups()
        {
            dungeonReqs = new RoomGroupRequirementCollection();

            var rGroup = dungeonReqs.RoomRequirements.Where(x => x.GroupId != null);

            foreach (var g in rGroup)
            {
                DungeonSpriteGroups.Where(x => g.GroupId == x.DungeonGroupId).ToList()
                .ForEach((x) => {
                    if (g.Subgroup0 != null)
                    {
                        x.SubGroup0         = (int)g.Subgroup0;
                        x.PreserveSubGroup0 = true;
                    }
                    if (g.Subgroup1 != null)
                    {
                        x.SubGroup1         = (int)g.Subgroup1;
                        x.PreserveSubGroup1 = true;
                    }
                    if (g.Subgroup2 != null)
                    {
                        x.SubGroup2         = (int)g.Subgroup2;
                        x.PreserveSubGroup2 = true;
                    }
                    if (g.Subgroup3 != null)
                    {
                        x.SubGroup3         = (int)g.Subgroup3;
                        x.PreserveSubGroup3 = true;
                    }
                    if (g.GroupId != null)
                    {
                        x.ForceRoomsToGroup.AddRange(g.Rooms);
                    }
                }
                         );
            }

            var duplicateRooms = dungeonReqs.RoomRequirements.Where(x => x.GroupId == null)
                                 .SelectMany(dr => dr.Rooms, (dr, r) => new RoomReq()
            {
                RoomId = r, Sub0 = dr.Subgroup0, Sub1 = dr.Subgroup1, Sub2 = dr.Subgroup2, Sub3 = dr.Subgroup3
            })
                                 .ToList();

            var roomsDict = new Dictionary <int, RoomReq>();

            foreach (var d in duplicateRooms)
            {
                if (!roomsDict.ContainsKey(d.RoomId))
                {
                    roomsDict[d.RoomId] = d;
                }

                if (d.Sub0 != null)
                {
                    roomsDict[d.RoomId].Sub0 = d.Sub0;
                }
                if (d.Sub1 != null)
                {
                    roomsDict[d.RoomId].Sub1 = d.Sub1;
                }
                if (d.Sub2 != null)
                {
                    roomsDict[d.RoomId].Sub2 = d.Sub2;
                }
                if (d.Sub3 != null)
                {
                    roomsDict[d.RoomId].Sub3 = d.Sub3;
                }
            }

            var rooms = roomsDict.Values.ToList();

            foreach (var r in rooms)
            {
                // UGGGGGGGGGGGGGGGGGGGGGGG
                // TODO: check if we already saved one for another room and skip this room
                if (DungeonSpriteGroups
                    .Where(x => r.Sub0 == null || (x.SubGroup0 == r.Sub0 && x.PreserveSubGroup0 == true))
                    .Where(x => r.Sub1 == null || (x.SubGroup1 == r.Sub1 && x.PreserveSubGroup1 == true))
                    .Where(x => r.Sub2 == null || (x.SubGroup2 == r.Sub2 && x.PreserveSubGroup2 == true))
                    .Where(x => r.Sub3 == null || (x.SubGroup3 == r.Sub3 && x.PreserveSubGroup3 == true))
                    .Any())
                {
                    // skip this room because we already have a subgroup that will work
                    continue;
                }


                var possibleSubs = DungeonSpriteGroups.Where(y => (y.PreserveSubGroup0 == false) ||
                                                             y.PreserveSubGroup1 == false ||
                                                             y.PreserveSubGroup2 == false ||
                                                             y.PreserveSubGroup3 == false)
                                   .ToList();

                if (r.Sub0 != null)
                {
                    possibleSubs = possibleSubs.Where(x => x.PreserveSubGroup0 == false).ToList();
                }
                if (r.Sub1 != null)
                {
                    possibleSubs = possibleSubs.Where(x => x.PreserveSubGroup1 == false).ToList();
                }
                if (r.Sub2 != null)
                {
                    possibleSubs = possibleSubs.Where(x => x.PreserveSubGroup2 == false).ToList();
                }
                if (r.Sub3 != null)
                {
                    possibleSubs = possibleSubs.Where(x => x.PreserveSubGroup3 == false).ToList();
                }

                var updateSub = possibleSubs[rand.Next(possibleSubs.Count)];

                if (r.Sub0 != null)
                {
                    updateSub.SubGroup0         = (int)r.Sub0;
                    updateSub.PreserveSubGroup0 = true;
                }
                if (r.Sub1 != null)
                {
                    updateSub.SubGroup1         = (int)r.Sub1;
                    updateSub.PreserveSubGroup1 = true;
                }
                if (r.Sub2 != null)
                {
                    updateSub.SubGroup2         = (int)r.Sub2;
                    updateSub.PreserveSubGroup2 = true;
                }
                if (r.Sub3 != null)
                {
                    updateSub.SubGroup3         = (int)r.Sub3;
                    updateSub.PreserveSubGroup3 = true;
                }
            }
        }