Ejemplo n.º 1
0
        public SessionManager DeepCopy()
        {
            var clone = new SessionManager();

            clone.currentTimelineKey  = currentTimelineKey;
            clone.currentTimelineTime = currentTimelineTime;
            clone.Description         = Description;
            clone.FirstKeyedEvent     = FirstKeyedEvent;
            var cloneGenericMeteors = new GenericMeteor[GenericMeteors.Length];

            for (int i = 0; i < GenericMeteors.Length; i++)
            {
                cloneGenericMeteors[i] = GenericMeteors[i].DeepCopy();
            }
            clone.GenericMeteors   = cloneGenericMeteors;
            clone.LatestMessage    = LatestMessage;
            clone.NullSession      = NullSession;
            clone.PlayerWorldCount = PlayerWorldCount;
            clone.playing          = playing;
            clone.ReckoningActive  = ReckoningActive;
            clone.Scratched        = Scratched;
            var cloneTimeline = new TimelineEvent[Timeline.Length];

            for (int i = 0; i < Timeline.Length; i++)
            {
                cloneTimeline[i] = Timeline[i].ShallowCopy();
            }
            clone.Timeline = cloneTimeline;
            var cloneVisibleEvents = new int[VisibleEvents.Length];

            for (int i = 0; i < VisibleEvents.Length; i++)
            {
                cloneVisibleEvents[i] = VisibleEvents[i];
            }
            clone.VisibleEvents = cloneVisibleEvents;
            clone.VoidSession   = VoidSession;
            var cloneWorlds = new Dictionary <string, Location>(Worlds.Count);

            foreach (var keyValue in Worlds)
            {
                if (keyValue.Value is SessionLocation)
                {
                    cloneWorlds.Add(keyValue.Key, (keyValue.Value as SessionLocation).DeepCopy());
                }
                else if (keyValue.Value is PlayerWorld)
                {
                    cloneWorlds.Add(keyValue.Key, (keyValue.Value as PlayerWorld).DeepCopy());
                }
                else if (keyValue.Value is Skaia)
                {
                    cloneWorlds.Add(keyValue.Key, (keyValue.Value as Skaia).DeepCopy());
                }
                else
                {
                    throw new NotImplementedException("The type " + keyValue.Value.GetType().Name + " is not implemented in SessionManager");
                }
            }
            clone.Worlds = cloneWorlds;
            return(clone);
        }
Ejemplo n.º 2
0
        public SessionManager(string filePath, DynamicContentManager Content)
        {
            SessionBuilder builder = SessionBuilder.BuilderRead(filePath);

            if (builder.OtherLocations == null)
            {
                builder.OtherLocations = new string[0];
            }
            Worlds           = new Dictionary <string, Location>(3 + builder.Lands.Length + builder.OtherLocations.Length);
            GenericMeteors   = new GenericMeteor[builder.GenericMeteors.Length];
            Description      = builder.Description;
            PlayerWorldCount = builder.Lands.Length;

            if (builder.Scratched)
            {
                Timeline = new TimelineEvent[builder.Timeline.Length + PlayerWorldCount + builder.OtherLocations.Length + 4];
            }
            else
            {
                Timeline = new TimelineEvent[builder.Timeline.Length + PlayerWorldCount + builder.OtherLocations.Length + 3];
            }

            Skaia tempSkaia = Content.Load <Skaia>(builder.Skaia);

            Worlds.Add("Skaia", tempSkaia);
            SessionLocation tempProspit = Content.Load <SessionLocation>(builder.Prospit);

            Worlds.Add("Prospit", tempProspit);
            SessionLocation tempDerse = Content.Load <SessionLocation>(builder.Derse);

            Worlds.Add("Derse", tempDerse);
            PlayerWorld[] tempLands = new PlayerWorld[PlayerWorldCount];
            for (int i = 0; i < builder.Lands.Length; i++)
            {
                tempLands[i]    = Content.Load <PlayerWorld>(builder.Lands[i]);
                Timeline[i + 2] = new TimelineEvent(tempLands[i].Name, EventTypes.Reload, "None", builder.Lands[i]);
                Worlds.Add(tempLands[i].Name, tempLands[i]);
            }
            SessionLocation[] tempMeteors = new SessionLocation[builder.OtherLocations.Length];
            for (int i = 0; i < tempMeteors.Length; i++)
            {
                tempMeteors[i] = Content.Load <SessionLocation>(builder.OtherLocations[i]);
                Timeline[i + 2 + tempLands.Length] = new TimelineEvent(tempMeteors[i].Name, EventTypes.Reload, "None", builder.OtherLocations[i]);
                Worlds.Add(tempMeteors[i].Name, tempMeteors[i]);
            }
            for (int i = 0; i < GenericMeteors.Length; i++)
            {
                GenericMeteors[i] = new GenericMeteor(Path.Combine(Content.BaseDirectory, builder.GenericMeteors[i]), Content);
            }

            Timeline[0] = new TimelineEvent("Prospit", EventTypes.Reload, "None", builder.Prospit);
            Timeline[1] = new TimelineEvent("Derse", EventTypes.Reload, "None", builder.Derse);

            Timeline[tempLands.Length + tempMeteors.Length + 2] = new TimelineEvent("Skaia", EventTypes.Reload, true, "None", builder.Skaia);
            if (builder.Scratched)
            {
                for (int i = tempLands.Length + tempMeteors.Length + 3; i < Timeline.Length - 1; i++)
                {
                    Timeline[i] = builder.Timeline[i - (tempLands.Length + tempMeteors.Length + 3)];
                }
                Timeline[Timeline.Length - 1] = new TimelineEvent("Session", EventTypes.ScratchComplete, true, "", "");
            }
            else
            {
                for (int i = tempLands.Length + tempMeteors.Length + 3; i < Timeline.Length; i++)
                {
                    Timeline[i] = builder.Timeline[i - (tempLands.Length + tempMeteors.Length + 3)];
                }
            }

            List <int> visibleEvents = new List <int>();

            for (int i = 0; i < Timeline.Length; i++)
            {
                if (Timeline[i].IsVisible)
                {
                    visibleEvents.Add(i);
                }
            }
            VisibleEvents   = visibleEvents.ToArray();
            Scratched       = builder.Scratched;
            VoidSession     = builder.VoidSession;
            NullSession     = builder.NullSession;
            ReckoningActive = false;
        }