Ejemplo n.º 1
0
        public static QueryEvent Serdes(QueryEvent e, AssetMapping mapping, ISerializer s, TextId textSourceId)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            if (s.IsWriting() && e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            var queryType = s.EnumU8(nameof(QueryType), e?.QueryType ?? 0);

            return(queryType switch
            {
                QueryType.Switch => QuerySwitchEvent.Serdes((QuerySwitchEvent)e, mapping, s),
                QueryType.Unk1 => QueryUnk1Event.Serdes((QueryUnk1Event)e, s),
                QueryType.Unk4 => QueryUnk4Event.Serdes((QueryUnk4Event)e, s),
                QueryType.HasPartyMember => QueryHasPartyMemberEvent.Serdes((QueryHasPartyMemberEvent)e, mapping, s),
                QueryType.HasItem => QueryHasItemEvent.Serdes((QueryHasItemEvent)e, mapping, s),
                QueryType.UsedItem => QueryUsedItemEvent.Serdes((QueryUsedItemEvent)e, mapping, s),
                QueryType.PreviousActionResult => QueryPreviousActionResultEvent.Serdes((QueryPreviousActionResultEvent)e, s),
                QueryType.ScriptDebugMode => QueryScriptDebugModeEvent.Serdes((QueryScriptDebugModeEvent)e, s),
                QueryType.UnkC => QueryUnkCEvent.Serdes((QueryUnkCEvent)e, s),
                QueryType.NpcActive => QueryNpcActiveEvent.Serdes((QueryNpcActiveEvent)e, s),
                QueryType.Gold => QueryGoldEvent.Serdes((QueryGoldEvent)e, s),
                QueryType.RandomChance => QueryRandomChanceEvent.Serdes((QueryRandomChanceEvent)e, s),
                QueryType.Unk12 => QueryUnk12Event.Serdes((QueryUnk12Event)e, s),
                QueryType.ChosenVerb => QueryChosenVerbEvent.Serdes((QueryChosenVerbEvent)e, s),
                QueryType.Conscious => QueryConsciousEvent.Serdes((QueryConsciousEvent)e, mapping, s),
                QueryType.Leader => QueryLeaderEvent.Serdes((QueryLeaderEvent)e, mapping, s),
                QueryType.Ticker => QueryTickerEvent.Serdes((QueryTickerEvent)e, mapping, s),
                QueryType.Map => QueryMapEvent.Serdes((QueryMapEvent)e, mapping, s),
                QueryType.Unk1E => QueryUnk1EEvent.Serdes((QueryUnk1EEvent)e, s),
                QueryType.PromptPlayer => PromptPlayerEvent.Serdes((PromptPlayerEvent)e, textSourceId, s),
                QueryType.Unk19 => QueryUnk19Event.Serdes((QueryUnk19Event)e, s),
                QueryType.TriggerType => QueryTriggerTypeEvent.Serdes((QueryTriggerTypeEvent)e, s),
                QueryType.Unk21 => QueryUnk21Event.Serdes((QueryUnk21Event)e, s),
                QueryType.EventUsed => QueryEventUsedEvent.Serdes((QueryEventUsedEvent)e, s),
                QueryType.DemoVersion => QueryDemoVersionEvent.Serdes((QueryDemoVersionEvent)e, s),
                QueryType.Unk29 => QueryUnk29Event.Serdes((QueryUnk29Event)e, s),
                QueryType.Unk2A => QueryUnk2AEvent.Serdes((QueryUnk2AEvent)e, s),
                QueryType.PromptPlayerNumeric => PromptPlayerNumericEvent.Serdes((PromptPlayerNumericEvent)e, textSourceId, s),
                _ => throw new FormatException($"Unexpected query type \"queryType\"")
            });
Ejemplo n.º 2
0
        public static QueryHasItemEvent Serdes(QueryHasItemEvent e, AssetMapping mapping, ISerializer s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            e ??= new QueryHasItemEvent();
            e.Operation = s.EnumU8(nameof(Operation), e.Operation);
            e.Immediate = s.UInt8(nameof(Immediate), e.Immediate);
            int zeroes = s.UInt8(null, 0);

            zeroes  += s.UInt8(null, 0);
            e.ItemId = ItemId.SerdesU16(nameof(ItemId), e.ItemId, AssetType.Item, mapping, s);
            // field 8 is the next event id when the condition is and is deserialised as part of the BranchEventNode that this event should belong to.

            s.Assert(zeroes == 0, "QueryHasItemEvent: Expected fields 3,4 to be 0");
            return(e);
        }