Example #1
0
        public static MapEventZone Serdes(MapEventZone existing, ISerializer s, byte y)
        {
            bool global = y == 0xff;
            var  zone   = existing ?? new MapEventZone
            {
                Global = global,
                Y      = global ? (byte)0 : y
            };

            s.Begin();
            zone.X = s.Transform <byte, byte>(nameof(X), zone.X, s.UInt8, StoreIncremented.Instance);
            // ApiUtil.Assert(global && zone.X == 0xff || !global && zone.X != 0xff);
            zone.Unk1    = s.UInt8(nameof(Unk1), zone.Unk1);
            zone.Trigger = s.EnumU16(nameof(Trigger), zone.Trigger);
            ushort?nodeId = ConvertMaxToNull.Serdes(nameof(Node), zone.Node?.Id, s.UInt16);

            if (nodeId != null && zone.Node == null)
            {
                zone.Node = new DummyEventNode(nodeId.Value);
            }

            s.End();
            return(zone);
        }
Example #2
0
        public static MapNpc Serdes(int _, MapNpc existing, ISerializer s)
        {
            var npc = existing ?? new MapNpc();

            s.Begin();
            npc.Id = s.Transform <byte, byte?>(nameof(Id), npc.Id, s.UInt8, Tweak.Instance);
            // npc.Sound = (SampleId?)Tweak.Serdes(nameof(Sound), (byte?)npc.Sound, s.UInt8);
            npc.Sound = s.UInt8(nameof(Sound), npc.Sound);

            ushort?eventNumber = ConvertMaxToNull.Serdes(nameof(npc.Node), npc.Node?.Id, s.UInt16);

            if (eventNumber != null && npc.Node == null)
            {
                npc.Node = new DummyEventNode(eventNumber.Value);
            }

            npc.ObjectNumber = s.Transform <ushort, ushort?>(nameof(ObjectNumber), npc.ObjectNumber, s.UInt16, Tweak.Instance) ?? 0;
            npc.Flags        = s.EnumU8(nameof(Flags), npc.Flags);
            npc.Movement     = s.EnumU8(nameof(Movement), npc.Movement);
            npc.Unk8         = s.UInt8(nameof(Unk8), npc.Unk8);
            npc.Unk9         = s.UInt8(nameof(Unk9), npc.Unk9);
            s.End();
            return(npc);
        }