public override Dictionary <string, object> Save()
    {
        var dataDictionary = base.Save();

        //save json to file
        var UUID = GetComponent <UUID>()?.ID;

        if (string.IsNullOrWhiteSpace(UUID))
        {
            Debug.LogError("CharacterBase doesn't have an UUID (Can't load data from json)");
            return(dataDictionary);
        }

        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "SenseRange", SenseRange);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "AngleOfVision", AngleOfVision);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "WalkDistance", WalkDistance);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "AttackDistance", AttackDistance);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "CurrentPatrolPoint", CurrentPatrolPoint);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "NextPatrolPoint", NextPatrolPoint);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "currentDestination", currentDestination);

        //TODO save transforms and stack of states
        DataPersitanceHelpers.SaveDictionary(ref dataDictionary, UUID);
        return(dataDictionary);
    }
Esempio n. 2
0
    public override Dictionary <string, object> Save()
    {
        Dictionary <string, object> dataDictionary = base.Save();

        //Save armour/weapons slots
        if (armourSlot.equippedSlot.InventoryItem != null && armourSlot.equippedSlot.InventoryItem.Item)
        {
            string path = armourSlot.equippedSlot.InventoryItem.Item
                          .AssetPath.Replace("Resources/", "").Replace(".asset", "");
            DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "armourSlot", path);
        }
        if (leftWeaponSlot.equippedSlot.InventoryItem != null && leftWeaponSlot.equippedSlot.InventoryItem.Item)
        {
            string path = leftWeaponSlot.equippedSlot.InventoryItem.Item
                          .AssetPath.Replace("Resources/", "").Replace(".asset", "");
            DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "leftWeapon", path);
        }
        if (rightWeaponSlot.equippedSlot.InventoryItem != null && rightWeaponSlot.equippedSlot.InventoryItem.Item)
        {
            string path = rightWeaponSlot.equippedSlot.InventoryItem.Item
                          .AssetPath.Replace("Resources/", "").Replace(".asset", "");
            DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "rightWeapon", path);
        }

        DataPersitanceHelpers.SaveDictionary(ref dataDictionary, uuid.ID);
        return(dataDictionary);
    }
Esempio n. 3
0
 private void trigger(bool triggered, InteractionTrigger trigger)
 {
     if (triggered)
     {
         DataPersitanceHelpers.SaveAll();
     }
 }
    public override Dictionary <string, object> Load(bool destroyUnloaded = false)
    {
        var dataDictionary = base.Load(destroyUnloaded);

        SenseRange         = DataPersitanceHelpers.GetValueFromDictionary <float>(ref dataDictionary, "SenseRange");
        AngleOfVision      = DataPersitanceHelpers.GetValueFromDictionary <float>(ref dataDictionary, "AngleOfVision");
        WalkDistance       = DataPersitanceHelpers.GetValueFromDictionary <float>(ref dataDictionary, "WalkDistance");
        AttackDistance     = DataPersitanceHelpers.GetValueFromDictionary <float>(ref dataDictionary, "AttackDistance");
        CurrentPatrolPoint = DataPersitanceHelpers.GetValueFromDictionary <int>(ref dataDictionary, "CurrentPatrolPoint");
        NextPatrolPoint    = DataPersitanceHelpers.GetValueFromDictionary <int>(ref dataDictionary, "NextPatrolPoint");
        currentDestination = DataPersitanceHelpers.GetValueFromDictionary <Vector3?>(ref dataDictionary, "currentDestination");

        //reset states (should really save the state stack instead)
        if (stackOfStates)
        {
            stackOfStates.Clear();
            if (PotentialStates.Length > 0)
            {
                State patrol = PotentialStates.FirstOrDefault(x => x.StateName == StateNames.PatrolState);
                State idle   = PotentialStates.FirstOrDefault(x => x.StateName == StateNames.IdleState);
                if (patrol)
                {
                    stackOfStates.PushState(patrol);
                }
                else if (idle)
                {
                    stackOfStates.PushState(idle);
                }
            }
        }

        return(dataDictionary);
    }
Esempio n. 5
0
    public virtual Dictionary <string, object> Load(bool destroyUnloaded = false)
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //load dictionary
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        Dictionary <string, int> itemPaths;

        itemPaths = DataPersitanceHelpers.GetValueFromDictionary <Dictionary <string, int> >(ref dataDictionary, "items");

        //Remove all items;
        RemoveAll();

        //add loaded items
        foreach (var itemPath in itemPaths)
        {
            //load asset
            var item = Resources.Load <Item>(itemPath.Key);

            for (int i = 0; i < itemPath.Value; i++)
            {
                AddItem(item as Item, false);
            }
        }

        return(dataDictionary);
    }
Esempio n. 6
0
    public virtual Dictionary <string, object> Save()
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //Load currently saved values
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        //TODO save path of items
        Dictionary <string, int> itemPaths = new Dictionary <string, int>();

        foreach (var inventoryItem in items)
        {
            var item = inventoryItem.InventoryItem?.Item;
            if (item)
            {
                itemPaths.Add(item.AssetPath.Replace("Resources/", "").Replace(".asset", ""), inventoryItem.InventoryItem.Quantity);
            }
        }
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "items", itemPaths);

        //save json to file
        DataPersitanceHelpers.SaveDictionary(ref dataDictionary, uuid.ID);

        return(dataDictionary);
    }
    public Dictionary <string, object> Load(bool destroyUnloaded = false)
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //load dictionary
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        IsInteractable = DataPersitanceHelpers.GetValueFromDictionary <bool>(ref dataDictionary, "IsInteractable");
        Toggle         = DataPersitanceHelpers.GetValueFromDictionary <bool>(ref dataDictionary, "Toggle");
        triggered      = DataPersitanceHelpers.GetValueFromDictionary <bool>(ref dataDictionary, "triggered");

        if (TriggerAnimator != null)
        {
            TriggerAnimator.SetBool(OnTriggerAnimation, triggered);
        }

        //OnTrigger?.Invoke(triggered, this);

        return(dataDictionary);
    }
 public void Awake()
 {
     Trigger.OnTrigger += trigger;
     uuid = GetComponent <UUID>();
     if (!InventorySection)
     {
         InventorySection = DataPersitanceHelpers.FindAllGameObjects <InventorySectionHandler>().FirstOrDefault();
     }
 }
Esempio n. 9
0
    public override Dictionary <string, object> Load(bool disableUnloaded = false)
    {
        var dataDictionary = base.Load(disableUnloaded);

        playerVelocity = DataPersitanceHelpers.GetValueFromDictionary <Vector3>(ref dataDictionary, "velocity");
        onGround       = DataPersitanceHelpers.GetValueFromDictionary <bool>(ref dataDictionary, "onGround");
        isCrouching    = DataPersitanceHelpers.GetValueFromDictionary <bool>(ref dataDictionary, "isCrouching");

        return(dataDictionary);
    }
Esempio n. 10
0
    public override Dictionary <string, object> Load(bool destroyUnloaded = false)
    {
        Dictionary <string, object> dataDictionary = base.Load(destroyUnloaded);

        //remove current slots
        for (int i = 0; i < leftHand.Length; i++)
        {
            leftHand[i].RemoveItem();
        }
        for (int i = 0; i < rightHand.Length; i++)
        {
            rightHand[i].RemoveItem();
        }

        //save left hand
        Dictionary <int, string> leftHandPaths = DataPersitanceHelpers
                                                 .GetValueFromDictionary <Dictionary <int, string> >(ref dataDictionary, "leftHand");

        for (int i = 0; i < leftHand.Length; i++)
        {
            if (leftHandPaths != null && leftHandPaths.ContainsKey(i))
            {
                var ability = Resources.Load <Item>(leftHandPaths[i]);
                //To improve this we can equip the ability in the slot it was saved in
                if (ability)
                {
                    var invItem = AddItem(ability, false);
                    invItem.LeftClick(this, character);
                }
                ;
            }
        }

        //save right hand
        Dictionary <int, string> rightHandPaths = DataPersitanceHelpers
                                                  .GetValueFromDictionary <Dictionary <int, string> >(ref dataDictionary, "rightHand");

        for (int i = 0; i < rightHand.Length; i++)
        {
            if (rightHandPaths != null && rightHandPaths.ContainsKey(i))
            {
                var ability = Resources.Load <Item>(rightHandPaths[i]);
                //To improve this we can equip the ability in the slot it was saved in
                if (ability)
                {
                    var invItem = AddItem(ability, false);
                    invItem.RightClick(this, character);
                }
                ;
            }
        }

        return(dataDictionary);
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.F6))
        {
            DataPersitanceHelpers.SaveAll();
        }

        if (Input.GetKeyUp(KeyCode.F7))
        {
            DataPersitanceHelpers.LoadAll();
        }
    }
Esempio n. 12
0
    public Dictionary <string, object> Load(bool destroyUnloaded = false)
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //load dictionary
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        AlertMeter = DataPersitanceHelpers.GetValueFromDictionary <int>(ref dataDictionary, "AlertMeter");

        return(dataDictionary);
    }
Esempio n. 13
0
    public Dictionary <string, object> Load(bool destroyUnloaded = false)
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //load dictionary
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        TargetPortalIndex    = DataPersitanceHelpers.GetValueFromDictionary <int>(ref dataDictionary, "TargetPortalIndex");
        previousTargetPortal = DataPersitanceHelpers.GetValueFromDictionary <int>(ref dataDictionary, "previousTargetPortal");

        return(dataDictionary);
    }
    public Dictionary <string, object> Load(bool destroyUnloaded = false)
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //load dictionary
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        TriggeredPositionOffset = DataPersitanceHelpers.GetValueFromDictionary <Vector3>(ref dataDictionary, "TriggeredPositionOffset");
        targetPosition          = DataPersitanceHelpers.GetValueFromDictionary <Vector3>(ref dataDictionary, "targetPosition");

        return(dataDictionary);
    }
Esempio n. 15
0
    public override Dictionary <string, object> Save()
    {
        var dataDictionary = base.Save();

        var UUID = GetComponent <UUID>()?.ID;

        if (string.IsNullOrWhiteSpace(UUID))
        {
            Debug.LogError("CharacterBase doesn't have an UUID (Can't load data from json)");
            return(dataDictionary);
        }

        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "velocity", playerVelocity);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "onGround", onGround);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "isCrouching", isCrouching);

        DataPersitanceHelpers.SaveDictionary(ref dataDictionary, UUID);
        return(dataDictionary);
    }
Esempio n. 16
0
    public override Dictionary <string, object> Load(bool destroyUnloaded = false)
    {
        Dictionary <string, object> dataDictionary = base.Load(destroyUnloaded);

        armourSlot.equippedSlot.InventoryItem?.UnapplyModifiers(character);
        leftWeaponSlot.equippedSlot.InventoryItem?.UnapplyModifiers(character);
        rightWeaponSlot.equippedSlot.InventoryItem?.UnapplyModifiers(character);

        armourSlot.equippedSlot.Clear();
        leftWeaponSlot.equippedSlot.Clear();
        rightWeaponSlot.equippedSlot.Clear();

        var armourPath      = DataPersitanceHelpers.GetValueFromDictionary <string>(ref dataDictionary, "armourSlot");
        var leftWeaponPath  = DataPersitanceHelpers.GetValueFromDictionary <string>(ref dataDictionary, "leftWeapon");
        var rightWeaponPath = DataPersitanceHelpers.GetValueFromDictionary <string>(ref dataDictionary, "rightWeapon");

        if (!string.IsNullOrWhiteSpace(armourPath))
        {
            var item = Resources.Load <Item>(armourPath);
            if (item)
            {
                AddItem(item, false).LeftClick(this, character);
            }
        }
        if (!string.IsNullOrWhiteSpace(leftWeaponPath))
        {
            var item = Resources.Load <Item>(leftWeaponPath);
            if (item)
            {
                AddItem(item, false).LeftClick(this, character);
            }
        }
        if (!string.IsNullOrWhiteSpace(rightWeaponPath))
        {
            var item = Resources.Load <Item>(rightWeaponPath);
            if (item)
            {
                AddItem(item, false).RightClick(this, character);
            }
        }

        return(dataDictionary);
    }
Esempio n. 17
0
    public Dictionary <string, object> Save()
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //Load currently saved values
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "AlertMeter", AlertMeter);

        //save json to file
        DataPersitanceHelpers.SaveDictionary(ref dataDictionary, uuid.ID);

        return(dataDictionary);
    }
Esempio n. 18
0
    public Dictionary <string, object> Save()
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //Load currently saved values
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "TargetPortalIndex", TargetPortalIndex);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "previousTargetPortal", previousTargetPortal);

        //save json to file
        DataPersitanceHelpers.SaveDictionary(ref dataDictionary, uuid.ID);

        return(dataDictionary);
    }
    public Dictionary <string, object> Save()
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //Load currently saved values
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "TriggeredPositionOffset", TriggeredPositionOffset);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "targetPosition", targetPosition);

        //save json to file
        DataPersitanceHelpers.SaveDictionary(ref dataDictionary, uuid.ID);

        return(dataDictionary);
    }
    public Dictionary <string, object> Save()
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //Load currently saved values
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        //save transform
        DataPersitanceHelpers.SaveTransform(ref dataDictionary, transform, "persistantTransform");

        //save json to file
        DataPersitanceHelpers.SaveDictionary(ref dataDictionary, uuid.ID);

        return(dataDictionary);
    }
Esempio n. 21
0
    public Dictionary <string, object> Load(bool destroyUnloaded = false)
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //load dictionary
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        IsLocked = DataPersitanceHelpers.GetValueFromDictionary <bool>(ref dataDictionary, "IsLocked");

        if (Animator != null)
        {
            Animator.SetBool(OnTriggerAnimation, InteractionTrigger.AnyTrue(InteractTriggers));
        }

        return(dataDictionary);
    }
    public Dictionary <string, object> Load(bool destroyUnloaded = false)
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //load dictionary
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        ////if dictionary is empty then we assume no saved data for the object, so destroy it
        //if (destroyUnloaded && (dataDictionary == null || dataDictionary.Count == 0))
        //    gameObject.SetActive(false);

        //load transform
        DataPersitanceHelpers.LoadTransform(ref dataDictionary, transform, "persistantTransform");

        return(dataDictionary);
    }
    public Dictionary <string, object> Save()
    {
        //create new dictionary to contain data for characterbase
        Dictionary <string, object> dataDictionary = new Dictionary <string, object>();

        if (!uuid)
        {
            return(dataDictionary);
        }

        //Load currently saved values
        DataPersitanceHelpers.LoadDictionary(ref dataDictionary, uuid.ID);

        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "IsInteractable", IsInteractable);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "Toggle", Toggle);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "triggered", triggered);

        //save json to file
        DataPersitanceHelpers.SaveDictionary(ref dataDictionary, uuid.ID);

        return(dataDictionary);
    }
Esempio n. 24
0
    public override Dictionary <string, object> Save()
    {
        Dictionary <string, object> dataDictionary = base.Save();

        //save left hand
        Dictionary <int, string> leftHandPaths = new Dictionary <int, string>();

        for (int i = 0; i < leftHand.Length; i++)
        {
            EquipSlot slot = leftHand[i];
            if (slot.equippedSlot.InventoryItem != null && slot.equippedSlot.InventoryItem.Item)
            {
                leftHandPaths.Add(i, slot.equippedSlot.InventoryItem.Item
                                  .AssetPath.Replace("Resources/", "").Replace(".asset", ""));
            }
        }

        //save right hand
        Dictionary <int, string> rightHandPaths = new Dictionary <int, string>();

        for (int i = 0; i < rightHand.Length; i++)
        {
            EquipSlot slot = rightHand[i];
            if (slot.equippedSlot.InventoryItem != null && slot.equippedSlot.InventoryItem.Item)
            {
                rightHandPaths.Add(i, slot.equippedSlot.InventoryItem.Item
                                   .AssetPath.Replace("Resources/", "").Replace(".asset", ""));
            }
        }

        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "leftHand", leftHandPaths);
        DataPersitanceHelpers.SaveValueToDictionary(ref dataDictionary, "rightHand", rightHandPaths);

        DataPersitanceHelpers.SaveDictionary(ref dataDictionary, uuid.ID);
        return(dataDictionary);
    }
Esempio n. 25
0
 private void onDeath()
 {
     DataPersitanceHelpers.LoadAll();
 }