Exemple #1
0
        public static IEventNode Load(BinaryReader br, int id)
        {
            var initialPosition = br.BaseStream.Position;
            var type            = (MapEventType)br.ReadByte(); // +0

            EventNode result;

            switch (type) // Individual parsers handle byte range [1,9]
            {
            case MapEventType.Action: result = ActionEvent.Load(br, id, type); break;

            case MapEventType.AskSurrender: result = AskSurrenderEvent.Load(br, id, type); break;

            case MapEventType.ChangeIcon: result = ChangeIconEvent.Load(br, id, type); break;

            case MapEventType.ChangeUsedItem: result = ChangeUsedItemEvent.Load(br, id, type); break;

            case MapEventType.Chest: result = OpenChestEvent.Load(br, id, type); break;

            case MapEventType.CloneAutomap: result = CloneAutomapEvent.Load(br, id, type); break;

            case MapEventType.CreateTransport: result = CreateTransportEvent.Load(br, id, type); break;

            case MapEventType.DataChange: result = DataChangeEvent.Load(br, id, type); break;

            case MapEventType.DoScript: result = DoScriptEvent.Load(br, id); break;

            case MapEventType.Door: result = DoorEvent.Load(br, id, type); break;

            case MapEventType.Encounter: result = EncounterEvent.Load(br, id, type); break;

            case MapEventType.EndDialogue: result = EndDialogueEvent.Load(br, id, type); break;

            case MapEventType.Execute: result = ExecuteEvent.Load(br, id, type); break;

            case MapEventType.MapExit: result = TeleportEvent.Load(br, id, type); break;

            case MapEventType.Modify: result = ModifyEvent.Load(br, id, type); break;

            case MapEventType.Offset: result = OffsetEvent.Load(br, id, type); break;

            case MapEventType.Pause: result = PauseEvent.Load(br, id, type); break;

            case MapEventType.PlaceAction: result = PlaceActionEvent.Load(br, id, type); break;

            case MapEventType.PlayAnimation: result = PlayAnimationEvent.Load(br, id, type); break;

            case MapEventType.Query: result = QueryEvent.Load(br, id, type); break;

            case MapEventType.RemovePartyMember: result = RemovePartyMemberEvent.Load(br, id, type); break;

            case MapEventType.Script: result = RunScriptEvent.Load(br, id, type); break;

            case MapEventType.Signal: result = SignalEvent.Load(br, id, type); break;

            case MapEventType.SimpleChest: result = SimpleChestEvent.Load(br, id, type); break;

            case MapEventType.Sound: result = SoundEvent.Load(br, id, type); break;

            case MapEventType.Spinner: result = SpinnerEvent.Load(br, id, type); break;

            case MapEventType.StartDialogue: result = StartDialogueEvent.Load(br, id, type); break;

            case MapEventType.Text: result = TextEvent.Load(br, id, type); break;

            case MapEventType.Trap: result = TrapEvent.Load(br, id, type); break;

            case MapEventType.UnkFF: result = DummyMapEvent.Load(br, id, type); break;

            case MapEventType.Wipe: result = WipeEvent.Load(br, id, type); break;

            default: throw new ArgumentOutOfRangeException();
            }

            long expectedPosition = initialPosition + 10;
            long actualPosition   = br.BaseStream.Position;

            Debug.Assert(expectedPosition == actualPosition,
                         $"Expected to have read {expectedPosition - initialPosition} bytes, but {actualPosition - initialPosition} have been read.");

            result.NextEventId = br.ReadUInt16(); // +A
            if (result.NextEventId == 0xffff)
            {
                result.NextEventId = null;
            }

            return(result);
        }