Пример #1
0
    public static void LoadHolding(string reality, Player player)
    {
        if (string.IsNullOrEmpty(reality))
        {
            Debug.LogError("Reality is null or em empty, cannot load held item.");
            return;
        }
        if (player == null)
        {
            Debug.LogError("Null player, cannot perform IO operation for held item.");
            return;
        }

        // Get file path.
        string path = OutputUtils.RealitySaveDirectory + reality + OutputUtils.HeldItemSaveFile;

        // Get the player holding monobehaviour.
        PlayerHolding holding = player.Holding;

        ItemSaveData sd = InputUtils.FileToObject <ItemSaveData>(path);

        // Apply!
        if (sd == null || string.IsNullOrEmpty(sd.Prefab))
        {
            holding.CmdDrop(false, true, player.gameObject, null);
        }
        else
        {
            holding.ServerEquip(sd.Prefab, player.gameObject, sd.Data.Serialize());
        }
    }
Пример #2
0
    public void Save(Item[] ChractorInventory, int playerGold)
    {
        ItemSaveData[] itemSaveData = new ItemSaveData[ChractorInventory.Length];

        for (int i = 0; i < itemSaveData.Length; i++)
        {
            itemSaveData[i].ItemNum         = ChractorInventory[i].ItemNum;
            itemSaveData[i].ItemName        = ChractorInventory[i].ItemName;
            itemSaveData[i].ItemPrice       = ChractorInventory[i].ItemPrice;
            itemSaveData[i].ItemImage       = (int)ChractorInventory[i].ItemNum - 1;
            itemSaveData[i].ItemInvenNum    = ChractorInventory[i].ItemInvenNum;
            itemSaveData[i].ItemCount       = ChractorInventory[i].ItemCount;
            itemSaveData[i].ItemInformation = ChractorInventory[i].ItemInformation;
            itemSaveData[i].soloItem        = ChractorInventory[i].oneItem;
        }

        for (int i = 0; i < itemSaveData.Length; i++)
        {
            var b = new BinaryFormatter();
            var m = new MemoryStream();
            b.Serialize(m, itemSaveData[i]);
            PlayerPrefs.SetString("Setting" + i.ToString(), Convert.ToBase64String(m.GetBuffer()));
        }

        PlayerPrefs.SetInt("PlayerGold", playerGold);
    }
Пример #3
0
    public static void SaveHolding(string reality, Player player)
    {
        if (string.IsNullOrEmpty(reality))
        {
            Debug.LogError("Reality is null or em empty, cannot save held item.");
            return;
        }
        if (player == null)
        {
            Debug.LogError("Null player, cannot perform IO operation for held item.");
            return;
        }

        // Get file path.
        string path = OutputUtils.RealitySaveDirectory + reality + OutputUtils.HeldItemSaveFile;

        // Get the player holding monobehaviour.
        PlayerHolding holding = player.Holding;

        if (holding.Item == null)
        {
            OutputUtils.ObjectToFile(null, path);
        }
        else
        {
            ItemSaveData sd = holding.Item.GetSaveData();
            OutputUtils.ObjectToFile(sd, path);
        }
        // Done!
    }
Пример #4
0
    private void InteractableGUI()
    {
        serializedObject.Update();

        float width = EditorGUIUtility.currentViewWidth / 3f;

        EditorGUILayout.BeginHorizontal();

        int itemSaveDataIndex = AllItemSaveDatasEditor.TryGetItemSaveDataIndex(itemSaveData);

        if (itemSaveDataIndex == -1)
        {
            itemSaveDataIndex = 0;
        }

        itemSaveDataIndex = EditorGUILayout.Popup(itemSaveDataIndex, AllItemSaveDatasEditor.AllItemSaveDataDescriptions,
                                                  GUILayout.Width(width));
        ItemSaveData globalItemSaveData = AllItemSaveDatasEditor.TryGetItemSaveDataAt(itemSaveDataIndex);

        descriptionProperty.stringValue = globalItemSaveData != null ? globalItemSaveData.description : blankDescription;

        hashProperty.intValue = Animator.StringToHash(descriptionProperty.stringValue);

        EditorGUILayout.PropertyField(satisfiedProperty, GUIContent.none, GUILayout.Width(width + toggleOffset));

        if (GUILayout.Button("-", GUILayout.Width(itemSaveDataButtonWidth)))
        {
            itemSaveDatasProperty.RemoveFromObjectArray(itemSaveData);
        }

        EditorGUILayout.EndHorizontal();

        serializedObject.ApplyModifiedProperties();
    }
Пример #5
0
 public void ClearItemIcon()
 {
     KeepData          = null;
     ItemSprite.sprite = null;
     CountText.text    = String.Empty;
     ItemSprite.color  = Color.clear;
 }
Пример #6
0
    public Item[] Load(Item[] ChractorInventory)
    {
        ItemSaveData[] itemLoadData = new ItemSaveData[ChractorInventory.Length];

        for (int i = 0; i < itemLoadData.Length; i++)
        {
            var data = PlayerPrefs.GetString("Setting" + i.ToString());
            if (!string.IsNullOrEmpty(data))
            {
                var b = new BinaryFormatter();
                var m = new MemoryStream(Convert.FromBase64String(data));
                itemLoadData[i] = (ItemSaveData)b.Deserialize(m);
            }
        }

        for (int i = 0; i < itemLoadData.Length; i++)
        {
            if (itemInformation)
            {
                ChractorInventory[i].ItemNum         = itemLoadData[i].ItemNum;
                ChractorInventory[i].ItemName        = itemLoadData[i].ItemName;
                ChractorInventory[i].ItemPrice       = itemLoadData[i].ItemPrice;
                ChractorInventory[i].ItemImage       = itemInformation.SearchImage((int)itemLoadData[i].ItemNum - 1);
                ChractorInventory[i].ItemInvenNum    = itemLoadData[i].ItemInvenNum;
                ChractorInventory[i].ItemCount       = itemLoadData[i].ItemCount;
                ChractorInventory[i].ItemInformation = itemLoadData[i].ItemInformation;
                ChractorInventory[i].oneItem         = itemLoadData[i].soloItem;
            }
        }
        return(ChractorInventory);
    }
Пример #7
0
    public static ItemSaveData CreateItemSaveData(string description)
    {
        ItemSaveData newItemSaveData = CreateInstance <ItemSaveData>();

        newItemSaveData.description = description;
        SetHash(newItemSaveData);
        return(newItemSaveData);
    }
Пример #8
0
 public void DrawItemIcon(ItemSaveData data)
 {
     KeepData          = data;
     ItemSprite.sprite = data.Data.ItemImage;
     ItemSprite.SetNativeSize();
     CountText.text   = data.Count.ToString();
     ItemSprite.color = Color.white;
 }
Пример #9
0
    public override SaveData GetSaveData()
    {
        ItemSaveData saveData = new ItemSaveData();

        saveData.Name     = Utils.GetCleanName(gameObject.name);
        saveData.Position = this.Position;
        return(saveData);
    }
Пример #10
0
 public void convertToMono(ItemSaveData isd)
 {
     itemName     = isd.itemName;
     quantity     = isd.quantity;
     itemFunction = isd.itemFunction;
     debuff       = isd.debuff;
     value        = isd.value;
 }
Пример #11
0
    public override void LoadItemData(ItemSaveData data)
    {
        base.LoadItemData(data);

        if (data is BiosampleSaveData biosampleData)
        {
            sampleWorldType = biosampleData.sampleWorldType;
        }
    }
Пример #12
0
 public ItemSaveData GetDataForItem(PrimeItem item)
 {
     if (!SavedData.TryGetValue(item.Name, out ItemSaveData data))
     {
         data = new ItemSaveData();
         SavedData[item.Name] = data;
     }
     return(data);
 }
Пример #13
0
    public static ItemSaveData CreateItemSaveData()
    {
        ItemSaveData newItemSaveData    = CreateInstance <ItemSaveData>();
        string       blankDescription   = "No itemSaveDatas set.";
        ItemSaveData globalItemSaveData = AllItemSaveDatasEditor.TryGetItemSaveDataAt(0);

        newItemSaveData.description = globalItemSaveData != null ? globalItemSaveData.description : blankDescription;
        SetHash(newItemSaveData);
        return(newItemSaveData);
    }
Пример #14
0
    public virtual ItemSaveData GetSaveData()
    {
        ItemSaveData data = new ItemSaveData
        {
            itemName   = itemName,
            identified = identified,
            rarity     = rarity
        };

        return(data);
    }
Пример #15
0
 public Item(ItemSaveData saveData)
 {
     SkillNames = saveData.SkillNames;
     Effects    = EffectTracker.IDStoEffects(saveData.EffectIDS);
     IsEquipped = saveData.IsEquipped;
     Damage     = saveData.Damage;
     Weight     = saveData.Weight;
     Name       = saveData.Name;
     Value      = saveData.Value;
     TL         = saveData.TL;
     Quantity   = saveData.Quantity;
 }
Пример #16
0
    public static int TryGetItemSaveDataIndex(ItemSaveData itemSaveData)
    {
        for (int i = 0; i < TryGetItemSaveDatasLength(); i++)
        {
            if (TryGetItemSaveDataAt(i).hash == itemSaveData.hash)
            {
                return(i);
            }
        }

        return(-1);
    }
Пример #17
0
 public void ShowItemInfo(ItemSaveData data)
 {
     ItemIconRenderer.sprite = data.Data.ItemImage;
     ItemIconRenderer.SetNativeSize();
     Name.text  = String.Format("名称:{0}", data.Data.ItemName);
     Count.text = String.Format("数量:{0}", data.Count.ToString());
     Info.text  = data.Data.ItemInfo;
     UseButton.gameObject.SetActive(data.Data.CanUse);
     DropButton.gameObject.SetActive(data.Data.CanDrop);
     UseButton.onClick.AddListener(data.Data.OnUse);
     DropButton.onClick.AddListener(data.Data.OnDrop);
 }
Пример #18
0
    public ItemSaveData convertToSerializable()
    {
        ItemSaveData isd = new ItemSaveData();

        isd.itemName     = itemName;
        isd.quantity     = quantity;
        isd.itemFunction = itemFunction;
        isd.debuff       = debuff;
        isd.value        = value;

        return(isd);
    }
Пример #19
0
    private void OnEnable()
    {
        itemSaveData = (ItemSaveData)target;

        if (target == null)
        {
            DestroyImmediate(this);
            return;
        }

        descriptionProperty = serializedObject.FindProperty(itemSaveDataPropDescriptionName);
        satisfiedProperty   = serializedObject.FindProperty(itemSaveDataPropSatisfiedName);
        hashProperty        = serializedObject.FindProperty(itemSaveDataPropHashName);
    }
Пример #20
0
    public static ItemSaveData ItemToSaveData(Item i)
    {
        if (i == null)
        {
            Debug.LogError("Null item to get save data from.");
            return(null);
        }

        ItemSaveData sd = i.GetSaveData();

        if (sd == null)
        {
            Debug.LogError("Null save data returned by item '" + i.Prefab + "'");
            return(null);
        }

        return(sd);
    }
Пример #21
0
    public PlayerSaveData(Player player)
    {
        playerName = player.entityName;

        currentHealth = player.Health.currentHealth;
        baseHP        = player.Health.baseHP;

        classType = player.playerClass.classType;
        Debug.Log("Saving player with Data " + classType);
        playerLevel      = player.playerLevel;
        playerExperience = player.playerExperience;

        talents = new List <TalentSaveData>();

        foreach (Talent talent in player.talentTree.GetAllTalents())
        {
            if (talent.isLearned)
            {
                Debug.Log("Saving Talent " + talent.talentName);
                talents.Add(talent.GetSaveData());
            }
        }

        items = new List <ItemSaveData>();

        foreach (InventorySlot slot in player.Inventory.slots)
        {
            if (slot.item != null)
            {
                for (int i = 0; i < slot.amount; i++)
                {
                    ItemSaveData data = slot.item.GetSaveData();
                    items.Add(data);
                }
            }
        }

        colors = new List <SerializableColor>();
        foreach (Color color in ((PlayerRenderer)player.Renderer).colorSwap.mBaseColors)
        {
            colors.Add(color);
        }
    }
Пример #22
0
    // static function to generate items from treasure save data
    public static List <ItemSaveData> GenerateItems(TreasureSaveData saveData)
    {
        List <ItemSaveData> itemsSaveData = new List <ItemSaveData>();

        // get treasure object from resources
        GameObject treasurePrefab = Resources.Load <GameObject>("Treasures/" + saveData.Name);
        GameObject treasureObj    = Instantiate(treasurePrefab);
        Treasure   treasure       = treasureObj.GetComponent <Treasure>();

        // check if create treasure
        if (!Utils.IsChanceOccured(treasure.Chance2Create))
        {
            return(itemsSaveData);
        }

        foreach (string path in treasure.Paths)
        {
            // get rnadom item from current resources path
            GameObject[] itemPrefabs = Resources.LoadAll <GameObject>("Items/" + path);
            if (itemPrefabs.Length == 0)
            {
                Debug.LogError("no prefabs inside path: " + path);
            }
            GameObject randomItemPrefab = itemPrefabs[Random.Range(0, itemPrefabs.Length)];

            // check the chance to create the current item
            if (!Utils.IsChanceOccured(treasure.Chance2CreateEachMemebr))
            {
                continue;
            }

            GameObject itemObj = Instantiate(randomItemPrefab);

            ItemSaveData itemSaveData = itemObj.GetComponent <Item>().GetSaveData() as ItemSaveData;
            Item.AddRandomness(ref itemSaveData);
            itemsSaveData.Add(itemSaveData);

            Destroy(itemObj.gameObject);
        }

        Destroy(treasureObj.gameObject);
        return(itemsSaveData);
    }
Пример #23
0
    public static void RemoveItemSaveData(ItemSaveData itemSaveData)
    {
        if (!AllItemSaveDatas.Instance)
        {
            Debug.LogError("AllItemSaveDatas has not been created yet.");
            return;
        }

        Undo.RecordObject(AllItemSaveDatas.Instance, "Removing itemSaveData");

        ArrayUtility.Remove(ref AllItemSaveDatas.Instance.itemSaveDatas, itemSaveData);

        DestroyImmediate(itemSaveData, true);
        AssetDatabase.SaveAssets();

        EditorUtility.SetDirty(AllItemSaveDatas.Instance);

        SetAllItemSaveDataDescriptions();
    }
Пример #24
0
    public static void ItemsToFile(string reality, params Item[] items)
    {
        items = FilterItems(items);
        ItemSaveData[] saveData = new ItemSaveData[items.Length];

        for (int i = 0; i < items.Length; i++)
        {
            items[i].RequestDataUpdate();
            ItemSaveData sd = ItemToSaveData(items[i]);
            saveData[i] = sd;
        }

        string filePath = OutputUtils.RealitySaveDirectory + reality + OutputUtils.WorldItemSaveFile;

        Debug.Log("Saving " + items.Length + " items to '" + filePath + "'");
        OutputUtils.ObjectToFile(saveData, filePath, new JsonSerializerSettings()
        {
            Formatting = Formatting.Indented, ReferenceLoopHandling = ReferenceLoopHandling.Ignore
        });
    }
Пример #25
0
    public static void SaveDataToWorldItems(ItemSaveData[] data)
    {
        if (data == null)
        {
            Debug.LogError("Save data array is null! Cannot spawn world items!");
            return;
        }
        // Should only be called on server!
        for (int i = 0; i < data.Length; i++)
        {
            ItemSaveData save = data[i];
            if (!Item.ItemExists(save.Prefab))
            {
                Debug.LogError("Item '" + save.Prefab + "' not found when loading items from item save data! (Item #" + i + ")");
                continue;
            }

            Item instance = Item.NewInstance(save.Prefab, new Vector2(save.X, save.Y), save.Data);
            NetworkServer.Spawn(instance.gameObject);
            instance.LoadSaveData(save);
        }
    }
Пример #26
0
/// <summary>
    /// 储存物品数据到本地
    /// </summary>
    /// <param name="data">数据</param>
    /// <returns></returns>
    private bool SaveItemData(InventoryItem data)
    {
        bool SaveResult = false;
        var  Data       = GetData(data); //获取已存储的物品数据

        if (Data != null)                //如果物品数据不为空
        {
            if (Data.Count < data.MaxItemNumber)
            {
                Data.Count++;//增加物品数量
                SaveResult = true;
            }
            else
            {
                OnItemCountFull?.Invoke(data);
            }
        }
        else
        {//如果没有存储过呢新增加一个物品存储数据
            Data       = new ItemSaveData();
            Data.Data  = data;
            Data.Count = 1;
            SaveData.Datas.Add(Data);
            if (Data.Data.JustCanPickUpOnce)
            {
                if (!SaveData.OnceItemSaveData.Contains(Data.Data))
                {
                    SaveData.OnceItemSaveData.Add(Data.Data);
                }
            }


            SaveResult = true;
        }
        ES3.Save <InventorySaveData>(GetSaveName, SaveData);
        OnItemSave?.Invoke(SaveData);
        return(SaveResult);
    }
Пример #27
0
    private void AddItemSaveData(string description)
    {
        if (!AllItemSaveDatas.Instance)
        {
            Debug.LogError("AllItemSaveDatas has not been created yet.");
            return;
        }

        ItemSaveData newItemSaveData = ItemSaveDataEditor.CreateItemSaveData(description);

        newItemSaveData.name = description;

        Undo.RecordObject(newItemSaveData, "Created new ItemSaveData");

        AssetDatabase.AddObjectToAsset(newItemSaveData, AllItemSaveDatas.Instance);
        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newItemSaveData));

        ArrayUtility.Add(ref AllItemSaveDatas.Instance.itemSaveDatas, newItemSaveData);

        EditorUtility.SetDirty(AllItemSaveDatas.Instance);

        SetAllItemSaveDataDescriptions();
    }
Пример #28
0
 public virtual void LoadSaveData(ItemSaveData saveData)
 {
     // Used for custom data that may need to be saved for particular types of items.
     // Called only on the server just after the item has been spawned.
     return;
 }
Пример #29
0
 private static void SetHash(ItemSaveData itemSaveData)
 {
     itemSaveData.hash = Animator.StringToHash(itemSaveData.description);
 }
Пример #30
0
 // ================================================================================================== //
 public static void AddRandomness(ref ItemSaveData itemSaveData)
 {
     itemSaveData.Durability = getRandomItemDurability();
     itemSaveData.Condition  = getRandomItemCondition();
 }