Пример #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);
            }
        }
Пример #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);
            }
        }
Пример #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);
                }
            }
        }