Пример #1
0
        private void RpgInit()
        {
            //Debug.LogWarning(nameof(RpgInit));

            //TODO better debugging and logging

            //load initial player
            try
            {
                instance.PlayerRpgState = new CharacterModel();
                JsonConvert.PopulateObject(CoreUtils.LoadResource <TextAsset>("Data/RPGDefs/init_player").text, instance.PlayerRpgState, new JsonSerializerSettings
                {
                    Converters        = CCJsonConverters.Defaults.Converters,
                    TypeNameHandling  = TypeNameHandling.Auto,
                    NullValueHandling = NullValueHandling.Ignore
                });
                instance.PlayerRpgState.UpdateStats();
                PlayerFlags.RegisterSource(instance.PlayerRpgState);
            }
            catch (Exception e)
            {
                Debug.LogError("Failed to load initial player");
                Debug.LogException(e);
            }

            //load initial containers (requires some decoding)
            //we will actually need to load additional containers ex post facto when we add mod support
            try
            {
                var rawContainers = CoreUtils.LoadJson <Dictionary <string, SerializableContainerModel> >(CoreUtils.LoadResource <TextAsset>("Data/RPGDefs/init_containers").text);
                foreach (var key in rawContainers.Keys)
                {
                    var value = rawContainers[key];
                    try
                    {
                        var realContainer = SerializableContainerModel.MakeContainerModel(value);
                        instance.ContainerState.Add(key, realContainer);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("Failed to load one container");
                        Debug.LogException(e);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Failed to load initial container state");
                Debug.LogException(e);
            }

            instance.InitialLoaded = true;
        }
Пример #2
0
        /// <summary>
        /// Initializes the player from initial state
        /// </summary>
        public void InitializePlayer(string jsonData)
        {
            if (instance.PlayerRpgState != null && PlayerFlags.HasSource(instance.PlayerRpgState))
            {
                PlayerFlags.UnregisterSource(instance.PlayerRpgState);
            }

            instance.PlayerRpgState = new CharacterModel();
            JsonConvert.PopulateObject(jsonData, instance.PlayerRpgState, new JsonSerializerSettings
            {
                Converters        = CCJsonConverters.Defaults.Converters,
                TypeNameHandling  = TypeNameHandling.Auto,
                NullValueHandling = NullValueHandling.Ignore
            });
            instance.PlayerRpgState.FormID = "Player";
            InventoryModel.AssignUIDs(instance.PlayerRpgState.Inventory.EnumerateItems(), true);
            instance.PlayerRpgState.UpdateStats();
            PlayerFlags.RegisterSource(instance.PlayerRpgState);
        }
Пример #3
0
 private void RpgAfterLoad()
 {
     //need to register this since it's lost on load
     PlayerFlags.RegisterSource(PlayerRpgState);
 }