コード例 #1
0
        //todo xml, ignores given init if first/last/__current is used
        public Initiative CreateInitiative(RelativeInitiativeOrder relativeOrder, Initiative targetInitiative)
        {
            switch (relativeOrder)
            {
            case RelativeInitiativeOrder.BeforeCurrent:
            case RelativeInitiativeOrder.Current:
            case RelativeInitiativeOrder.AfterCurrent:
                if (currentlyExecuting == null)
                {
                    throw new InvalidOperationException("There is no currently executing event from which to get an initiative");
                }
                break;

            case RelativeInitiativeOrder.BeforeTarget:
            case RelativeInitiativeOrder.Target:
            case RelativeInitiativeOrder.AfterTarget:
                if (targetInitiative == null)
                {
                    throw new ArgumentNullException(nameof(targetInitiative), "The chosen RelativeInitiativeOrder requires a target initiative, but no initiative was passed in.");
                }
                break;
            }

            InternalInitiative init = new InternalInitiative();

            InsertInitiative(relativeOrder, init, targetInitiative);
            return(init);
        }
コード例 #2
0
        //todo - definitely needs xml doc notes about what it does.
        public Initiative GetCurrentInitiative()
        {
            InternalInitiative init = currentlyExecuting?.Initiative as InternalInitiative;

            if (init == null)
            {
                throw new InvalidOperationException("There is no currently executing event from which to get an initiative");
            }
            init.AutoRemove = false;
            return(init);
        }
コード例 #3
0
        private EventScheduling ScheduleWithRelativeInitiativeInternal(IEvent scheduledEvent, long ticksInFuture, RelativeInitiativeOrder relativeInitiativeOrder, Initiative targetInitiative)
        {
            if (scheduledEvent == null)
            {
                throw new ArgumentNullException(nameof(scheduledEvent));
            }
            switch (relativeInitiativeOrder)
            {
            case RelativeInitiativeOrder.BeforeCurrent:
            case RelativeInitiativeOrder.Current:
            case RelativeInitiativeOrder.AfterCurrent:
                if (currentlyExecuting == null)
                {
                    throw new InvalidOperationException("There is no currently executing event from which to get an initiative");
                }
                break;

            case RelativeInitiativeOrder.BeforeTarget:
            case RelativeInitiativeOrder.Target:
            case RelativeInitiativeOrder.AfterTarget:
                if (targetInitiative == null)
                {
                    throw new ArgumentNullException(nameof(targetInitiative), "The chosen RelativeInitiativeOrder requires a target initiative, but no initiative was passed in.");
                }
                break;
            }
            Initiative init;

            if (relativeInitiativeOrder == RelativeInitiativeOrder.Current)
            {
                init = currentlyExecuting.Initiative;
            }
            else if (relativeInitiativeOrder == RelativeInitiativeOrder.Target)
            {
                init = targetInitiative;
                if (!oc.Contains(init))
                {
                    throw new InvalidOperationException("Target initiative must exist in this event scheduler");
                }
            }
            else
            {
                init = new InternalInitiative {
                    AutoRemove = true
                };
                InsertInitiative(relativeInitiativeOrder, init);
            }
            return(CreateAndSchedule(scheduledEvent, ticksInFuture, init));
        }
コード例 #4
0
        //todo - definitely needs xml doc notes about what it does.
        public Initiative GetInitiativeFromEventScheduling(EventScheduling eventScheduling)
        {
            if (eventScheduling == null)
            {
                throw new ArgumentNullException(nameof(eventScheduling));
            }
            if (!eventScheduling.IsLive)
            {
                throw new InvalidOperationException("This event scheduling has already executed or been canceled, and can't be reused");
            }
            InternalInitiative init = (eventScheduling as InternalEventScheduling)?.Initiative as InternalInitiative;

            if (init == null)
            {
                throw new InvalidOperationException("No initiative found");
            }
            init.AutoRemove = false;
            return(init);
        }
コード例 #5
0
        public Initiative CreateInitiative(RelativeInitiativeOrder relativeOrder)
        {
            switch (relativeOrder)
            {
            case RelativeInitiativeOrder.BeforeCurrent:
            case RelativeInitiativeOrder.Current:
            case RelativeInitiativeOrder.AfterCurrent:
                if (currentlyExecuting == null)
                {
                    throw new InvalidOperationException("There is no currently executing event from which to get an initiative");
                }
                break;

            case RelativeInitiativeOrder.BeforeTarget:
            case RelativeInitiativeOrder.Target:
            case RelativeInitiativeOrder.AfterTarget:
                throw new ArgumentException("The chosen RelativeInitiativeOrder requires a target initiative - use other overload");
            }

            InternalInitiative init = new InternalInitiative();

            InsertInitiative(relativeOrder, init);
            return(init);
        }
コード例 #6
0
        public static EventScheduler Deserialize(BinaryReader reader,
                                                 Action <EventScheduling, BinaryReader> onLoadEventScheduling,
                                                 Action <Initiative, BinaryReader> onLoadInitiative,
                                                 Func <BinaryReader, IEvent> loadIEvent)
        {
            if (loadIEvent == null)
            {
                throw new ArgumentNullException(nameof(loadIEvent));
            }
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            //dict of id -> obj this time...
            var objectsById = new Dictionary <int, object>();
            //read OC count...for each one...
            int ocCount = reader.ReadInt32();
            var inits   = new List <Initiative>();

            for (int i = 0; i < ocCount; ++i)
            {
                int        id     = reader.ReadInt32();
                bool       isAuto = reader.ReadBoolean();
                Initiative init   = new InternalInitiative {
                    AutoRemove = isAuto
                };
                if (!isAuto)
                {
                    onLoadInitiative?.Invoke(init, reader);
                }
                objectsById.Add(id, init);
                inits.Add(init);
            }
            // 'inits' now ready for use
            // (the OC should now be complete, and all non-auto inits have been associated with their user-assigned IDs again)
            //read PQ count...for each...
            int pqCount = reader.ReadInt32();
            var events  = new List <InternalEventScheduling>();

            for (int i = 0; i < pqCount; ++i)
            {
                //read the ID...
                int id = reader.ReadInt32();
                //call loadIEvent...
                IEvent ievent = loadIEvent(reader);
                //read creation tick, delay, and init ID.
                long       creationTick = reader.ReadInt64();
                long       delay        = reader.ReadInt64();
                int        initId       = reader.ReadInt32();
                Initiative init         = (objectsById[initId] as Initiative) ?? throw new Exception("Initiative not loaded properly");
                var        es           = new InternalEventScheduling(ievent, creationTick, delay, init);
                objectsById.Add(id, es);
                // then call onLoadEventScheduling.
                onLoadEventScheduling?.Invoke(es, reader);
                events.Add(es);
            }
            // 'events' now ready for use
            // (the PQ should now be complete)
            // finally, the MVD:
            //read a count of groups...
            int eventsForInitsCount = reader.ReadInt32();
            var eventsForInits      = new List <IGrouping <Initiative, InternalEventScheduling> >();

            for (int i = 0; i < eventsForInitsCount; ++i)
            {
                //read an init ID for each group...
                int initId = reader.ReadInt32();
                var init   = (objectsById[initId] as Initiative) ?? throw new Exception("Initiative not loaded correctly");
                //read a count for each group...
                int groupCount = reader.ReadInt32();
                var esGroup    = new List <InternalEventScheduling>();
                //read ES ids
                for (int j = 0; j < groupCount; ++j)
                {
                    int esId = reader.ReadInt32();
                    var es   = (objectsById[esId] as InternalEventScheduling) ?? throw new Exception("Event scheduling not loaded correctly");
                    esGroup.Add(es);
                }
                eventsForInits.Add(new Grouping <Initiative, InternalEventScheduling>(init, esGroup));
            }
            // 'eventsForInits' now ready for use
            return(new EventScheduler(inits, events, eventsForInits));
        }