Giter VIP home page Giter VIP logo

Comments (3)

sven-n avatar sven-n commented on August 13, 2024 1

Thanks for your greatly detailled report. πŸ‘πŸ»

This issue looks strange indeed... My first idea is that it fails to resolve the Skill when loading the GameConfiguration through the JsonObjectLoader, otherwise the SkillId would be null, too.
I will look into it ;)

from openmu.

sven-n avatar sven-n commented on August 13, 2024

I can reproduce the error, but didn't find the reason yet.

What I checked:

  • The json query contains SkillId and RawSkill elements
  • The json result contains the id in SkillId and the correct $ref-element in RawSkill
  • The IdReferenceResolver resolves the relevant ItemDefinitions with a Skill assigned in the relevant second pass
  • No breakpoint got hit in case the Skill get set from something to null
  • In BuyNpcItemAction:
    • The ItemDefinition of the learnable contains the skill in both GameConfiguration.Items and GameConfiguration.Monsters.MerchantStore.Items.Definition and they're the same instance πŸ‘
    • The instance of the MonsterDefinition in the GameConfiguration doesn't match with the one assigned to the npc instance, so e.g. gameContext.Configuration.Monsters.First(npc => npc.Number == 255) == npcDefinition is false.

from openmu.

sven-n avatar sven-n commented on August 13, 2024

The issue is most likely caused by the JsonObjectDeserializer. It loads the GameConfiguration in two passes. The first pass fills up references in the IdReferenceResolver, in case there might be any circular references:

        public T Deserialize<T>(TextReader textReader, IReferenceResolver referenceResolver)
        {
            var serializer = new JsonSerializer();
            serializer.ReferenceResolver = referenceResolver;
            serializer.Converters.Add(new BinaryAsHexJsonConverter());

            if (this.AreCircularReferencesExpected)
            {
                // This is a very naive approach to fix references to objects which occur later in the document.
                // The first run just have the task to fills the references in the IdReferenceResolver.
                // Unfortunately there is currently no better way, because we have circular references.
                var jsonString = textReader.ReadToEnd();
                using (var stringReader = new StringReader(jsonString))
                using (var jsonReader = new JsonTextReader(stringReader))
                {
                    serializer.Deserialize<T>(jsonReader);
                }

                textReader = new StringReader(jsonString);
            }

            using (textReader)
            using (var jsonReader = new JsonTextReader(textReader))
            {
                var result = serializer.Deserialize<T>(jsonReader);
                return result;
            }
        }

The issue here is, that the first pass adds an incomplete MonsterDefinition to the IdReferenceResolver, which is then returned at the second pass when resolving it for the MonsterSpawnAreas until the same MonsterDefinition is read again.

from openmu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.