Exemple #1
0
	public static SceneItem Create(SaveItem info)
	{
		var tbl = Table.Query<table.TableItem>().First(i => i.id == info.baseid);

		var res = Resources.Load(tbl.model);
		if (res == null)
		{
			Debug.LogError("Load Resources error: " + tbl.model);
			return null;
		}

		var avatar = Object.Instantiate(res) as GameObject;
#if UNITY_EDITOR
		avatar.name = string.Format("SceneItem.{0}({1})", tbl.name, info.thisid);
#endif
		avatar.transform.localScale = new Vector3(5, 5, 5);

		var item = avatar.AddComponent<SceneItem>();
		item.entity = avatar.AddComponent<Entity>();
		//item.animator = avatar.GetComponent<Animator>();
		item.ServerInfo = info;
		item.TableInfo = tbl;
		avatar.AddComponent<Entry>();
		CreateHeadTip(item);

		item.lastPickUpTime = Time.time;
		if (MainRole.Instance != null)
			MainRole.Instance.entity.PositionChanged += item.OnMainRolePositionChanged;
		item.StartCoroutine("WaitAndPickUp", item.deltaPickUpTime);
		return item;
	}
    public static bool TryLoad(string fullFilePath, out SaveItem saveItem)
    {
        bool result = false;

        saveItem = new SaveItem();
        TextReader textReader = null;

        try
        {
            textReader = new StreamReader(fullFilePath);
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(SaveItem));
            saveItem = (SaveItem)xmlSerializer.Deserialize(textReader);
            if (saveItem != null)
            {
                result = true;
            }
        }
        catch (FileNotFoundException)
        {
            if (saveItem != null)
            {
            }
        }
        finally
        {
            if (textReader != null)
            {
                textReader.Close();
            }
        }
        return(result);
    }
        /// <summary>
        /// Set up Pristine/Modified, DatonDef, and handle permissions and validation
        /// </summary>
        /// <returns>true if ok</returns>
        private async Task <bool> Prep(SaveItem item)
        {
            item.DatonDef = Retroverse.DataDictionary.FindDef(item.Diff.Key);

            //security check
            var securityErrors = Guard.GetDisallowedWrites(item.Pristine, item.DatonDef, item.Diff);

            item.Errors.AddRange(securityErrors);

            //get pristine, diff, and modified versions
            if (item.Diff.Key.IsNew)
            {
                item.Modified     = Utils.Construct(item.DatonDef.Type) as Persiston;
                item.Modified.Key = item.Diff.Key;
            }
            else
            {
                item.Pristine = (await Retroverse.GetDaton(item.Diff.Key, null))?.Daton as Persiston;
                item.Modified = item.Pristine.Clone(item.DatonDef) as Persiston;
            }
            item.Diff.ApplyTo(item.DatonDef, item.Modified);

            //validate Modified
            var validator = new Validator(User);
            await validator.ValidatePersiston(item.DatonDef, item.Modified);

            item.Errors.AddRange(validator.Errors);
            return(item.Errors.Count == 0);
        }
    public void Load(string data)
    {
        items = new List <SaveItem> ();
        if (data == "")
        {
            Debug.Log("File is empty?");
            //à cause du load qui ne fonctionne pas, pour continuer le tutoriel j'hardcode le contenu de la liste ici.
            items                = new List <SaveItem> (2);
            items [0].name       = "item1";
            items [0].position.x = 0;
            items [0].position.y = 0;
            items [1].name       = "item2";
            items [1].position.x = 10;
            items [1].position.y = 10;
            return;
        }
        var item_data = data.Split(';');

        var total = item_data.Length;
        var i     = 0;

        while (i < total)
        {
            var values = item_data [i].Split(',');
            var item   = new SaveItem();
            item.name     = values [0];
            item.position = new Vector2(Int32.Parse(values [1]), Int32.Parse(values [2]));
            items.Add(item);
        }
    }
Exemple #5
0
    public void delete(SaveItem ItemInfo)
    {
        //bool isInList = false;
        foreach (SaveItem _savedItem in _listData)
        {
            if (ItemInfo.species == _savedItem.species)              //in list
            {
                if (_savedItem.num - ItemInfo.num > 0)
                {
                    _savedItem.num -= ItemInfo.num;                    //&& num is enough
                }
                else if (_savedItem.num - ItemInfo.num == 0)
                {
                    _listData.Remove(_savedItem); // ==0 remove it
                }
                else                              //unenough
                {
                    Debug.Log(_savedItem.species + " is not enough");
                }
                break;
                Debug.Log("species: " + _savedItem.species + " \\ num: " + _savedItem.num);
            }
        }
        //if(!isInList)  _listData.Add(ItemInfo);

        foreach (SaveItem _savedItem in _listData)          //print list data
        {
        }
    }
        void ExecuteCommandSaveProject(object o)
        {
            try
            {
                var si = new SaveItem();
                si.Layer = HeightmapPresenter.HeightmapLayer;
                si.World = FieldPresenter.World;

                var sPath = MasterView.GetSaveFilePath();
                SaveLoadManager.Save(si, sPath);
                MasterView.ShowInfoOKMessage("Saved");
            }
            catch (XmlException xe)
            {
                MasterView.ShowErrorOKMessage("Not saved due to xml error: " + xe.Message);
            }
            catch (InvalidOperationException ioe)
            {
                MasterView.ShowErrorOKMessage("Not saved due to Invalid Operation: " + ioe.Message);
            }
            catch (IOException ie)
            {
                MasterView.ShowErrorOKMessage("Not saved due to IO error: " + ie.Message);
            }
            catch (Exception e)
            {
                MasterView.ShowErrorOKMessage("Not saved due to: " + e.Message);
            }
        }
Exemple #7
0
        private async void Generator_SaveResult_btn_ClickAsync(object sender, RoutedEventArgs e)
        {
            Generator_SaveResult_btn.IsEnabled = false;
            save_item         = new SaveItem();
            save_item.Address = Generator_Address.Text;
            save_item.Account = Generator_Account.Text;
            save_item.Text    = Generator_Text.Text;
            RadioButton checkBtn = Generator_Select.Children.OfType <RadioButton> ().FirstOrDefault(r => r.IsChecked.Value);

            switch (checkBtn.Name[checkBtn.Name.Length - 1])
            {
            case '1':
                save_item.Password = Generator_Password_lv1.Text;
                break;

            case '2':
                save_item.Password = Generator_Password_lv2.Text;
                break;

            case '3':
                save_item.Password = Generator_Password_lv3.Text;
                break;

            case 'x':
                save_item.Password = Generator_Password_lv_max.Text;
                break;
            }
            await Task.Run(new Action (Generator_SaveResult_btn_Click__Work));

            Generator_SaveResult_btn.IsEnabled = true;
        }
Exemple #8
0
    public static SceneItem Create(SaveItem info)
    {
        var tbl = Table.Query <table.TableItem>().First(i => i.id == info.baseid);

        var res = Resources.Load(tbl.model);

        if (res == null)
        {
            Debug.LogError("Load Resources error: " + tbl.model);
            return(null);
        }

        var avatar = Object.Instantiate(res) as GameObject;

#if UNITY_EDITOR
        avatar.name = string.Format("SceneItem.{0}({1})", tbl.name, info.thisid);
#endif
        avatar.transform.localScale = new Vector3(5, 5, 5);

        var item = avatar.AddComponent <SceneItem>();
        item.entity = avatar.AddComponent <Entity>();
        //item.animator = avatar.GetComponent<Animator>();
        item.ServerInfo = info;
        item.TableInfo  = tbl;
        avatar.AddComponent <Entry>();
        CreateHeadTip(item);

        item.lastPickUpTime = Time.time;
        if (MainRole.Instance != null)
        {
            MainRole.Instance.entity.PositionChanged += item.OnMainRolePositionChanged;
        }
        item.StartCoroutine("WaitAndPickUp", item.deltaPickUpTime);
        return(item);
    }
        private void ListSaves()
        {
            string        savePath  = CoreParams.SavePath;
            DirectoryInfo saveDInfo = new DirectoryInfo(savePath);

            FileInfo[] savesFInfo = saveDInfo.GetFiles().OrderBy(f => f.CreationTime).Reverse().ToArray();

            List <SaveItem> allSaves = new List <SaveItem>(savesFInfo.Length); //we don't go straight into the array in case of invalids...

            foreach (FileInfo saveFI in savesFInfo)
            {
                try
                {
                    SaveType type     = SaveType.Manual;
                    string   niceName = Path.GetFileNameWithoutExtension(saveFI.Name);
                    if (niceName.Contains("_"))
                    {
                        //split nicename
                        string[] splitName = niceName.Split('_');
                        if (splitName.Length >= 2)
                        {
                            niceName = splitName[1];
                            if (splitName[0] == "q")
                            {
                                type = SaveType.Quick;
                            }
                            else if (splitName[0] == "a")
                            {
                                type = SaveType.Auto;
                            }
                            else
                            {
                                niceName = Path.GetFileNameWithoutExtension(saveFI.Name); //undo our oopsie if it turns out someone is trolling with prefixes
                            }
                        }
                    }

                    var save = new SaveItem(niceName, saveFI.Name, type, string.Empty, saveFI.CreationTime);
                    allSaves.Add(save);
                }
                catch (Exception e)
                {
                    Debug.LogError("Failed to load save!" + saveFI.ToString(), this);
                    Debug.LogException(e);
                }
            }

            Saves = allSaves.ToArray();

            //inefficient but probably safer
            for (int i = 0; i < Saves.Length; i++)
            {
                var        save   = Saves[i];
                GameObject saveGO = Instantiate <GameObject>(SaveItemPrefab, ScrollContent);
                saveGO.GetComponentInChildren <Text>().text = save.NiceName;
                Button b    = saveGO.GetComponent <Button>();
                int    lexI = i;
                b.onClick.AddListener(delegate { OnSaveSelected(lexI, b); }); //scoping is weird here
            }
        }
Exemple #10
0
    public void save(SaveItem ItemInfo)
    {
        bool isInList = false;

        foreach (SaveItem _savedItem in _listData)
        {
            if (ItemInfo.species == _savedItem.species)  //in list
            {
                _savedItem.num++;
                isInList = true;
                break;
            }
        }
        if (!isInList)
        {
            _listData.Add(ItemInfo);
        }

        foreach (SaveItem _savedItem in _listData)  //print list data
        {
            Debug.Log("species: " + _savedItem.species + " \\ num: " + _savedItem.num);
        }
        //Debug.Log(_listData.IndexOf(ItemInfo));
        //Debug.Log(_listData[_listData.IndexOf(ItemInfo)].species);
        //Debug.Log(_listData[_listData.IndexOf(ItemInfo)].num);
    }
Exemple #11
0
 public static SaveItem getInstance()
 {
     if (saveItem == null)
     {
         saveItem = new SaveItem();
     }
     return(saveItem);
 }
        public override void SignalPaint()
        {
            base.SignalPaint();

            SelectedSave = null;

            ClearList();
            ListSaves();
        }
Exemple #13
0
 public SaveItem material(string name)
 {
     if (name == "Donut")
     {
         SaveItem item = new SaveItem();
         item.species = "Carrot";
         item.num     = 1;
         return(item);
     }
     return(null);
 }
Exemple #14
0
 //}
 //public items [] itemsUI;
 // Use this for initialization
 void Start()
 {
     SaveItem.getInstance().check();
     itemImg = GetComponentsInChildren <RawImage> ();
     itemNum = GetComponentsInChildren <Text> ();
     for (int i = 0; i < itemImg.Length; i++)
     {
         itemImg [i].texture = items[14];
         itemNum [i].text    = "";
     }
 }
        public void OnSaveSelected(int i, Button b)
        {
            SelectedSave = Saves[i];

            DetailName.text     = SelectedSave.NiceName;
            DetailType.text     = SelectedSave.Type.ToString();
            DetailLocation.text = SelectedSave.Location;
            DetailDate.text     = SelectedSave.Date.ToString();

            LoadButton.interactable = true;
        }
    public void RecreateSavedRunnerMod(SaveItem saveItem)
    {
        itemName = saveItem.itemName;
        SetVariablesAndGetCards(itemName);

        itemId       = saveItem.itemId;
        itemLevel    = saveItem.itemLevel;
        itemMaxLevel = 5;
        itemType     = (Item.ItemTypes)saveItem.itemType;

        hackerOrRunner = HackerRunner.Runner;
    }
Exemple #17
0
 private void DeleteItem(SaveItem item, bool removeFromList)
 {
     item.Deleted  -= OnItemDeleted;
     item.Selected -= OnItemSelected;
     if (removeFromList)
     {
         _items.Remove(item);
     }
     item.FreeResources();
     Destroy(item.gameObject);
     _saver.DeleteSave(item.Id);
 }
Exemple #18
0
    public void RecreateSavedHackerModChip(SaveItem saveItem)
    {
        itemName = saveItem.itemName;
        SetChipProperties();

        itemId       = saveItem.itemId;
        itemLevel    = saveItem.itemLevel;
        itemMaxLevel = 3;
        itemType     = (Item.ItemTypes)saveItem.itemType;

        hackerOrRunner = HackerRunner.Hacker;
    }
    public void OpenAndAddItem(SaveItem i)
    {
        GameObject go = Instantiate(item, itemContainer.transform);

        Item instantiatedItem = go.GetComponent <Item>();

        instantiatedItem.nameInput.text        = i.itemName;
        instantiatedItem.quantityInput.text    = i.quantity.ToString();
        instantiatedItem.descriptionInput.text = i.description;

        instantiatedItem.saveItem = i;
    }
    public void RecreateSavedHackerMod(SaveItem saveItem)
    {
        itemId         = saveItem.itemId;
        itemName       = saveItem.itemName;
        itemLevel      = saveItem.itemLevel;
        itemMaxLevel   = 5;
        itemType       = (Item.ItemTypes)saveItem.itemType;
        hackerOrRunner = HackerRunner.Hacker;

        modChips = new List <HackerModChip>();
        GetModProperties();
    }
Exemple #21
0
 public void InsertStack(SaveItem _item)
 {
     if (_item.amount > 0)
     {
         stack = new ItemStack(_item.id, _item.amount);
         uiItemSlot.UpdateSlot();
     }
     else
     {
         EmptySlot();
     }
 }
Exemple #22
0
        public ActionResult Delete_C(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopTymDBContext context = new ShopTymDBContext();
            SaveItem         item    = context.SaveItems.SingleOrDefault(s => s.SaveItemId == id);

            context.SaveItems.Remove(item);
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #23
0
 public ItemSlot(UIItemSlot _uIItemSlot, SaveItem _item)
 {
     if (_item.amount < 0)
     {
         stack      = new ItemStack(_item.id, -1);
         isCreative = true;
     }
     else if (_item.amount > 0)
     {
         stack = new ItemStack(_item.id, _item.amount);
     }
     uiItemSlot = _uIItemSlot;
     uiItemSlot.Link(this);
 }
Exemple #24
0
 void checkEatItem(string summonName)
 {
     if (summonName == "Donut")
     {
         //check cd
         //check material
         MakeItem make     = new MakeItem();
         SaveItem itemInfo = make.material(summonName);
         SaveItem.getInstance().check();
         bool isEnough = SaveItem.getInstance().checkDelete(itemInfo);
         if (isEnough)
         {
             SaveItem.getInstance().delete(itemInfo);
         }
         //set cd
         //set fairy
         //set talk
     }
     else if (summonName == "baoIcon")
     {
         //summon
         //delete
         //cd
     }
     else if (summonName == "IceCream")
     {
     }
     else if (summonName == "HamEgg")
     {
         MakeItem    make     = new MakeItem();
         SaveItem [] itemInfo = make.material(summonName, 1);
         SaveItem.getInstance().check();
         bool[] isEnough = new bool[itemInfo.Length];
         for (int i = 0; i < itemInfo.Length; i++)
         {
             isEnough[i] = SaveItem.getInstance().checkDelete(itemInfo[i]);
         }
         if (isEnough [0] && isEnough [1])
         {
             for (int i = 0; i < itemInfo.Length; i++)
             {
                 SaveItem.getInstance().delete(itemInfo [i]);
             }
         }
     }
     else if (summonName == "summon2Icon")
     {
     }
 }
Exemple #25
0
 void FillList()
 {
     for (int i = 0; i < listContent.childCount; i++)
     {
         Destroy(listContent.GetChild(i).gameObject);
     }
     string[] paths = Directory.GetFiles(Application.persistentDataPath, "*.map");
     Array.Sort(paths);
     for (int i = 0; i < paths.Length; i++)
     {
         SaveItem item = Instantiate(itemPrefab);
         item.menu    = this;
         item.MapName = Path.GetFileNameWithoutExtension(paths [i]);
         item.transform.SetParent(listContent, false);
     }
 }
Exemple #26
0
    public void runLoad(string data)
    {
        Debug.Log("Load" + data);
        var itemData = data.Split(';');

        items = new List <SaveItem>();
        var total = itemData.Length;

        for (var i = 0; i < total; i++)
        {
            var values = itemData[i].Split(',');
            var item   = new SaveItem();
            item.name = values[0];
            item.pos  = new Vector3(Int32.Parse(values[1]), Int32.Parse(values[2]), Int32.Parse(values[3]));
            items.Add(item);
        }
    }
Exemple #27
0
 public static void Set <T>(string key, T item, bool commitSave = true)
 {
     if (!isInit)
     {
         Init();
     }
     if (!items.ContainsKey(key))
     {
         items.Add(key, null);
     }
     items[key] = new SaveItem <T>()
     {
         item = item, Key = key
     };
     if (commitSave)
     {
         Save();
     }
 }
Exemple #28
0
 public bool checkDelete(SaveItem ItemInfo)
 {
     foreach (SaveItem _savedItem in _listData)
     {
         if (ItemInfo.species == _savedItem.species)              //in list
         {
             if (_savedItem.num - ItemInfo.num >= 0)
             {
                 return(true);
             }
             else                  //unenough
             {
                 Debug.Log(_savedItem.species + " is not enough");
                 return(false);
             }
         }
     }
     return(false);
 }
Exemple #29
0
        public void SaveKnowledge(SantoriniQLearn ql)
        {
            System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(SaveItem));
            List <DictObject> dd = new List <DictObject>();

            foreach (var item in ql.Policies)
            {
                DictObject d = new DictObject(item.Key, item.Value);
                dd.Add(d);
            }
            SaveItem s    = new SaveItem(dd);
            var      path = "../../save" + ".xml";

            System.IO.FileStream file = System.IO.File.Create(path);


            writer.Serialize(file, s);

            file.Close();
        }
    public void Load(string data)
    {
        if (data == null)
        {
            return;
        }
        var itemData = data.Split(';');

        items = new List <SaveItem>();
        var total = itemData.Length;

        for (var i = 0; i < total; i++)
        {
            var values = itemData[i].Split(',');
            var item   = new SaveItem {
                name = values[0], pos = new Vector2(float.Parse(values[1]), float.Parse(values[2]))
            };
            items.Add(item);
        }
    }
Exemple #31
0
    void OnTriggerStay(Collider col)
    {
        if (isFloor)
        {
            if (col.tag == "Player")            //剪取
            //音效
            //讀黨 檢查物品種類 數量
            {
                SaveItem itemInfo = new SaveItem();
                itemInfo.num     = num;
                itemInfo.species = species;
                SaveItem.getInstance().check();
                SaveItem.getInstance().save(itemInfo);

                //存檔 更新物品列表
                //物品種類 數量
                Destroy(this.gameObject);
            }
        }
    }
Exemple #32
0
//	public static void TestInventory(){
//		inventory.Add(new Item("Toy"));
//		inventory.Add(new Item("Toy"));
//		inventory.Add(new Item("Toy"));
//	}

	public static void Save(){
		/***** Monster */
		// TODO: set properties saveData.monster.prop = GameData.activeMonster.prop;
		SaveMonster savemon = new SaveMonster();
		if(!activeMonster.hatched){
			savemon.hatchTimeLeft = (int)activeMonster.hatchTime;
		}
		savemon.name = activeMonster.name;
		savemon.hatched = activeMonster.hatched;
		savemon.birthday = activeMonster.birthday;
		savemon.hunger = activeMonster.hunger;
		savemon.care = activeMonster.care;

		if(activeMonster.monsterController != null){
			Vector3 mpos = activeMonster.position;
			savemon.x = mpos.x;
			savemon.y = mpos.y;
			savemon.z = mpos.z;
		}

		saveData.monster = savemon;

		/***** Items */
		List<SaveItem> saveItems = new List<SaveItem>();
		foreach(Item item in items){
			SaveItem si = new SaveItem();
			Vector3 pos = item.position;
			si.x = pos.x;
			si.y = pos.y;
			si.z = pos.z;
			si.type = (int)item.type;
			si.foodType = item.foodType;
			saveItems.Add (si);
		}
		saveData.items = saveItems;

		/***** Tasks */
		List<SaveTask> saveTasks = new List<SaveTask>();
		foreach(Task t in tasks){
			SaveTask st = new SaveTask(t.name, t.id);
			st.difficulty = t.difficulty;
			foreach(Task subt in t.subtasks){
				SaveTask sst = new SaveTask(subt.name, subt.id);
				sst.difficulty = subt.difficulty;
				st.subtasks.Add(sst);
			}
			saveTasks.Add(st);
		}
		saveData.tasks = saveTasks;

		/***** Completed Tasks */
		List<SaveTask> cTasks = new List<SaveTask>();
		foreach(Task c in completedTasks){
			SaveTask st = new SaveTask(c.name, c.id);
			st.difficulty = c.difficulty;
			cTasks.Add(st);
			// TODO: parent task somehow? to display what the task was a child of?
		}
		saveData.completedTasks = cTasks;

		Serializer.Save(saveData);
	}