Пример #1
0
        private void DoLogicRoomChange(Game game, Save save)
        {
            //get the zone to change to
            string newRoomId = ((LogicRoomChange)save.CurrentLogic).RoomId;
            Room   room      = game.Rooms.Find(a => a.Id == newRoomId);

            //get the logic after the logiczonechange
            LogicNode nextLogic = save.CurrentLogic.GetNextLogic();

            //if there is no logic after the logiczonechange or the next logic is an ignore
            if (nextLogic == null || nextLogic is LogicIgnorePoint)
            {
                //set the new current logic to the first logic of the new zone
                save.CurrentLogic = room.LogicList.Clone(null);
            }
            else                  //if there is logic after the logiczonechange
                                  //the first logic in the new chain
            {
                LogicNode newCurrentLogic = nextLogic;

                //the final logic in the old chain
                LogicNode finalLogic = nextLogic;

                //get the final logic in the old chain
                while (true)
                {
                    nextLogic = finalLogic.GetNextLogic();

                    if (nextLogic == null || nextLogic is LogicIgnorePoint)
                    {
                        break;
                    }

                    finalLogic = nextLogic;
                }

                //clone the new zone into the new chain
                finalLogic.Next      = room.LogicList.Clone(finalLogic.Parent);
                finalLogic.Next.Prev = finalLogic.Next;

                //finally set the new logic
                save.CurrentLogic = newCurrentLogic;
            }

            if (this.RoomChanged != null)
            {
                this.RoomChanged(this, new LogicRoomChangeEventArgs(room.Name));
            }
        }