Example #1
0
        private void AddItem(RavenJObject val, Item.ItemClass iclass)
        {
            Item item = null;

            item = new Item(iclass, val);
            Equip.Add(item);
        }
Example #2
0
        public ItemData(Item item)
        {
            itemName    = item.itemName;
            description = item.description;

            itemClass = item.itemClass;
            slot      = item.slot;

            damage   = item.damage;
            defence  = item.defence;
            strength = item.strength;
            agility  = item.agility;
            intel    = item.intel;
        }
Example #3
0
        public static List <ItemMod> CreateMods(Item item, string attribute, Regex numberfilter)
        {
            Item.ItemClass ic     = item.Class;
            var            mods   = new List <ItemMod>();
            var            values = new List <float>();

            foreach (Match match in numberfilter.Matches(attribute))
            {
                values.Add(float.Parse(match.Value, CultureInfo.InvariantCulture));
            }
            string at = numberfilter.Replace(attribute, "#");

            if (at == "+# to all Attributes")
            {
                mods.Add(new ItemMod
                {
                    itemclass = ic,
                    Value     = values,
                    Attribute = "+# to Strength"
                });
                mods.Add(new ItemMod
                {
                    itemclass = ic,
                    Value     = values,
                    Attribute = "+# to Dexterity"
                });
                mods.Add(new ItemMod
                {
                    itemclass = ic,
                    Value     = values,
                    Attribute = "+# to Intelligence"
                });
            }
            else
            {
                mods.Add(new ItemMod
                {
                    itemclass = ic,
                    Value     = values,
                    Attribute = at,
                    isLocal   = DetermineLocal(item, at)
                });
            }
            return(mods);
        }
 /**
  * return the first item with the same name
  * return null if there is no such item with the same name
  *
  */
 public Item GetItem(string itemName, Item.ItemClass itemClass)
 {
     if (itemClass == Item.ItemClass.Consumable)
     {
         foreach (Item item in consumables)
         {
             if (item.name.Equals(itemName))
             {
                 return(item);
             }
         }
     }
     else if (itemClass == Item.ItemClass.Gear)
     {
         foreach (Item item in equipment)
         {
             if (item.name.Equals(itemName))
             {
                 return(item);
             }
         }
     }
     else if (itemClass == Item.ItemClass.Junk)
     {
         foreach (Item item in junks)
         {
             if (item.name.Equals(itemName))
             {
                 return(item);
             }
         }
     }
     else if (itemClass == Item.ItemClass.Resource)
     {
         foreach (Item item in resources)
         {
             if (item.name.Equals(itemName))
             {
                 return(item);
             }
         }
     }
     return(null);
 }
Example #5
0
    public static Item LoadItem(string filename, Item.ItemClass itemClass)
    {
        if (itemClass == Item.ItemClass.Consumable)
        {
            return(Resources.Load("Items/Consumables/" + filename) as Consumable);
        }
        else if (itemClass == Item.ItemClass.Gear)
        {
            return(Resources.Load("Items/Gear/" + filename) as Gear);
        }
        else if (itemClass == Item.ItemClass.Junk)
        {
            return(Resources.Load("Items/Junks/" + filename) as Junk);
        }
        else if (itemClass == Item.ItemClass.Resource)
        {
            return(Resources.Load("Items/Resources/" + filename) as Resource);
        }

        return(null);
    }
 public bool Contain(string itemName, Item.ItemClass itemClass)
 {
     return(GetItem(itemName, itemClass) != null);
 }
Example #7
0
    private void LoadGame()
    {
        GameData data = SaveSystem.Load();

        if (data != null)
        {
            PlayerController.IS_FIRST_GAME = data.is_firstGame;
            loaded = data;
            PlayerController.Player.currentStats[(int)StatType.Health] = data.health;
            PlayerController.Player.currentStats[(int)StatType.Hunger] = data.hunger;
            PlayerController.Player.currentStats[(int)StatType.Thirst] = data.thirst;
            PlayerController.Player.currentStats[(int)StatType.Energy] = data.energy;

            UpdateGameClock(data.gameClock);

            foreach (string s in data.consumables)
            {
                Consumable c = Instantiate(Resources.Load("Items/Consumables/" + s) as Consumable);
                if (c != null)
                {
                    InventoryManager.Inventory.AddItem(c);
                }
            }

            for (int i = 0; i < data.equipment.Count; i++)
            {
                Gear g = Instantiate(Resources.Load("Items/Gear/" + data.equipment[i]) as Gear);
                g.liveGear = data.equipementLife[i];
                if (g != null)
                {
                    InventoryManager.Inventory.AddItem(g);
                }
            }

            foreach (string s in data.junks)
            {
                Junk j = Instantiate(Resources.Load("Items/Junks/" + s) as Junk);
                if (j != null)
                {
                    InventoryManager.Inventory.AddItem(j);
                }
            }
            foreach (string s in data.resources)
            {
                Resource r = Instantiate(Resources.Load("Items/Resources/" + s) as Resource);
                if (r != null)
                {
                    InventoryManager.Inventory.AddItem(r);
                }
            }

            for (int i = 0; i < data.equippedGear.Count; i++)
            {
                Gear equipped = Resources.Load("Items/Gear/" + data.equippedGear[i]) as Gear;
                if (equipped != null)
                {
                    Debug.Log(equipped + " is equipped");
                    foreach (Gear g in InventoryManager.Inventory.GetItems(typeof(Gear)))
                    {
                        if (g.IsSameAs(equipped) && g.liveGear == data.equippedGearLife[i])
                        {
                            Debug.Log(g + " is equivalent to " + equipped);
                            PlayerController.Player.EquipGear(g);
                        }
                    }
                }
            }

            Debug.Log("Save loaded!");
            NewGame = false;

            if (data.isSleeping)
            {
                BackgroundTasks.Tasks.IsSleeping    = true;
                BackgroundTasks.Tasks.StartSleeping = GameData.ConvertStringToDateTime(data.sleepingStartTime);
                BackgroundTasks.Tasks.EndSleeping   = GameData.ConvertStringToDateTime(data.sleepingEndTime);
            }

            /*=====    SCAVENGING    =======*/
            if (data.isScavenging)
            {
                BackgroundTasks.Tasks.actualScavengingStep = data.scavengingActualStep;
                BackgroundTasks.Tasks.totalScavengingSteps = data.scavengingTotalSteps;

                Scavenging scavenging = new Scavenging();
                //load itemsfound
                List <(Item item, Item.ItemClass itemClass)> itemsFound = new List <(Item item, Item.ItemClass itemClass)>();
                for (int i = 0; i < data.scavengingItemsFound_itemName.Count; i++)
                {
                    Item.ItemClass itemC = Item.ConvertStringToItemCLass(data.scavengingItemsFound_itemClass[i]);
                    itemsFound.Add((Item.LoadItem(data.scavengingItemsFound_itemName[i], itemC), itemC));
                }

                scavenging.itemsFound   = itemsFound;
                scavenging.scavengeLog  = data.ScavengeLog;
                scavenging.oldStatusBar = (data.scavengingOldStatusBar[0], data.scavengingOldStatusBar[1],
                                           data.scavengingOldStatusBar[2], data.scavengingOldStatusBar[3]);

                BackgroundTasks.Tasks.lastScavenging = scavenging;

                List <DateTime> scavengepalier = new List <DateTime>();
                foreach (var palier in data.scavengingPalier)
                {
                    scavengepalier.Add(GameData.ConvertStringToDateTime(palier));
                }


                if (data.scavengingStartTime != null && data.scavengingEndTime != null)
                {
                    BackgroundTasks.Tasks.StartScavenging = GameData.ConvertStringToDateTime(data.scavengingStartTime);
                    BackgroundTasks.Tasks.EndScavenging   = GameData.ConvertStringToDateTime(data.scavengingEndTime);
                    Debug.Log("After loading : " + BackgroundTasks.Tasks.StartScavenging + " - " + BackgroundTasks.Tasks.EndScavenging);
                }


                BackgroundTasks.Tasks.scavengingPalier = scavengepalier;
                BackgroundTasks.Tasks.IsScavenging     = true;
            }
            else
            {
                BackgroundTasks.Tasks.IsScavenging = false;
            }
            Debug.Log("New State Of IsScavenging because loaddata" + BackgroundTasks.Tasks.IsScavenging);

            /*========    END SCAVENGING    ========*/
        }
        else
        {
            NewGame = true;
        }
    }