Ejemplo n.º 1
0
 //persistence
 //should be fixed now
 public override void SetExtraData(Dictionary <string, object> data) //this either isn't called or doesn't work
 {
     if (UseLocalContainer && UsePersistentContainer)
     {
         MyContainer = SerializableContainerModel.MakeContainerModel((SerializableContainerModel)data["Container"]);
     }
 }
Ejemplo n.º 2
0
        public void Init()
        {
            FindComponents();

            if (CorpseContainer == null && CorpseItems?.Items != null && CorpseItems.Items.Length > 0)
            {
                CorpseContainer = SerializableContainerModel.MakeContainerModel(CorpseItems);
            }
        }
Ejemplo n.º 3
0
        public override void RestoreEntityData(Dictionary <string, object> data)
        {
            base.RestoreEntityData(data);

            if (data.ContainsKey("Actor"))
            {
                ActorExtraData actorData = data["Actor"] as ActorExtraData;
                if (actorData != null)
                {
                    //restore!

                    CurrentAiState = actorData.CurrentAiState;
                    LastAiState    = actorData.LastAiState;
                    LockAiState    = actorData.LockAiState;
                    if (AnimationComponent != null)
                    {
                        AnimationComponent.CurrentAnimState = actorData.CurrentAnimState;
                        AnimationComponent.LockAnimState    = actorData.LockAnimState;
                    }
                    SavedTarget = actorData.SavedTarget;
                    TimeInState = actorData.TimeInState;

                    Health  = actorData.Health;
                    BeenHit = actorData.BeenHit;

                    LastHit         = actorData.LastHit;
                    LastHitDamage   = actorData.LastHitDamage;
                    WasExtremeDeath = actorData.WasExtremeDeath;

                    MovementComponent.BeforeRestore(data);
                    MovementComponent.MovementTarget = actorData.AltTarget;
                    MovementComponent.IsRunning      = actorData.IsRunning;
                    if (CurrentAiState == ActorAiState.Dead)
                    {
                        MovementComponent.HandleDeath();
                    }

                    if (InteractionComponent != null)
                    {
                        InteractionComponent.InteractionDisabledByHit = actorData.InteractionForceDisabled;

                        if (data.ContainsKey("Container"))
                        {
                            InteractionComponent.CorpseContainer = SerializableContainerModel.MakeContainerModel((SerializableContainerModel)data["Container"]);
                        }
                    }
                }
                else
                {
                    CDebug.LogEx(string.Format("Invalid actor data for {0} found on restore!", this.name), LogLevel.Error, this);
                }
            }
            else
            {
                CDebug.LogEx(string.Format("No actor data for {0} found on restore!", this.name), LogLevel.Error, this);
            }
        }
Ejemplo n.º 4
0
        private void RpgInit()
        {
            //Debug.LogWarning(nameof(RpgInit));

            //TODO better debugging and logging

            //load initial player
            try
            {
                InitializePlayer();
            }
            catch (Exception e)
            {
                Debug.LogError("Failed to load initial player");
                Debug.LogException(e);
            }

            //hookup factions
            try
            {
                FactionState = FactionModel.CloneFactionModel(FactionModel.BaseModel);
            }
            catch (Exception e)
            {
                Debug.LogError("Failed to load faction model");
                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;
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        public override void Start()
        {
            base.Start();

            if (!UseLocalContainer)
            {
                MyContainer = GameState.Instance.ContainerState[SharedContainer];
            }
            else if (MyContainer == null)                                                    //should fix...
            {
                MyContainer = SerializableContainerModel.MakeContainerModel(LocalContainer); //called after and overriding save?
            }
        }
Ejemplo n.º 7
0
        public override void Start()
        {
            base.Start();

            if (!UseLocalContainer)
            {
                MyContainer = GameState.Instance.ContainerState[SharedContainer];
            }
            else if (MyContainer == null)                                                    //should fix...
            {
                MyContainer = SerializableContainerModel.MakeContainerModel(LocalContainer); //called after and overriding save?
            }
            TryExecuteOnComponents(component => component.Init(this));
            Initialized = true;
        }