Example #1
0
        internal void PersistNpcData()
        {
            foreach (var npc in Npcs)
            {
                if (!_npcData.TryGetValue(npc.Guid, out NpcSaveData npcData))
                {
                    npcData = new NpcSaveData {
                        Id = npc.Guid.ToString()
                    };
                    _npcData.Add(npc.Guid, npcData);
                }

                npc.Save(npcData);
            }
        }
Example #2
0
        public virtual void Save(NpcSaveData saveData)
        {
            _variables.SaveTo(saveData.NpcTraits, VariableDefinition.Saved);

            if (Controller)
            {
                saveData.Position       = Controller.Mover.CurrentGridPosition;
                saveData.Direction      = Controller.Mover.MovementDirection;
                saveData.ControllerData = Controller.Save();
            }

            if (Trainer)
            {
                Trainer.Traits.SaveTo(saveData.TrainerTraits, VariableDefinition.Saved);
            }
        }
Example #3
0
        public virtual void Load(NpcSaveData saveData)
        {
            SetupVariables();

            if (saveData != null)
            {
                _variables.LoadFrom(saveData.NpcTraits, VariableDefinition.Saved);

                if (Controller)
                {
                    Controller.Mover.WarpToPosition(saveData.Position, saveData.Direction, CollisionLayer.None);
                    Controller.Load(saveData.ControllerData);
                }

                if (Trainer)
                {
                    Trainer.Traits.LoadFrom(saveData.TrainerTraits, VariableDefinition.Saved);
                }
            }
        }