Beispiel #1
0
        /*private void UpdateConstructions()
         * {
         *  var constructions = Config["Constructions"] as Dictionary<string, object>;
         *  if (constructions == null)
         *  {
         *      LocalPuts("No constructions in config");
         *      return;
         *  }
         *  var componentList = (List<Construction.Common>) ComponentList.GetValue(null);
         *  var protectionProperties = new HashSet<ProtectionProperties>();
         *  var manager = SingletonComponent<ItemManager>.Instance;
         *  foreach (var common in componentList)
         *  {
         *      var construction = ObjectToJsonObject(constructions[common.name]);
         *      var grades = construction.Obj.GetObject("grades");
         *      for (var g = 0; g < common.grades.Length; g++)
         *      {
         *          var gradeType = (BuildingGrade.Enum) g;
         *          if (!grades.ContainsKey(gradeType.ToString()))
         *          {
         *              common.grades[g] = null;
         *              continue;
         *          }
         *          if (common.grades[g] == null) common.grades[g] = new Construction.Grade();
         *          var grade = common.grades[g];
         *          var newGrade = grades.GetObject(gradeType.ToString());
         *          UpdateConstructionHealth(grade, newGrade.GetFloat("maxHealth", 0));
         *          grade.costToBuild.Clear();
         *          var costToBuild = newGrade.GetArray("costToBuild");
         *          foreach (var cost in costToBuild)
         *          {
         *              var itemid = cost.Obj.GetInt("itemid", 0);
         *              var definition = manager.itemList.Find(x => x.itemid == itemid);
         *              grade.costToBuild.Add(new ItemAmount(definition, cost.Obj.GetFloat("amount", 0)));
         *          }
         *          if (grade.damageProtecton != null)
         *          {
         *              protectionProperties.Add(grade.damageProtecton);
         *          }
         *      }
         *  }
         *  var protections = Config["DamageProtections"] as Dictionary<string, object>;
         *  if (protections == null)
         *      return;
         *  foreach (var protectionProperty in protectionProperties)
         *  {
         *      protectionProperty.Clear();
         *      var damageProtection = protections[protectionProperty.name] as Dictionary<string, object>;
         *      if (damageProtection == null) continue;
         *      foreach (var o in damageProtection)
         *      {
         *          protectionProperty.Add((DamageType) Enum.Parse(typeof (DamageType), o.Key), (float)Convert.ToDouble(o.Value));
         *      }
         *  }
         * }
         *
         * private void UpdateConstructionHealth(Construction.Grade grade, float newHealth)
         * {
         *  if (grade.maxHealth == newHealth) return;
         *  grade.maxHealth = newHealth;
         *  var bb = UnityEngine.Object.FindObjectsOfType<BuildingBlock>().Where(b => b.currentGrade == grade);
         *  foreach (var buildingBlock in bb)
         *  {
         *      buildingBlock.SetHealthToMax();
         *  }
         * }*/

        private static void UpdateItem(ItemDefinition definition, JSONObject item)
        {
            definition.shortname = item.GetString("shortname", "unnamed");
            definition.itemid    = item.GetInt("itemid", 0);
            definition.stackable = item.GetInt("stackable", 1);
            definition.category  = (ItemCategory)Enum.Parse(typeof(ItemCategory), item.GetString("category", "Weapon"));
            var condition = item.GetObject("condition");

            definition.condition.enabled    = condition.GetBoolean("enabled", false);
            definition.condition.max        = condition.GetInt("max", 0);
            definition.condition.repairable = condition.GetBoolean("repairable", false);
            definition.rarity = (Rarity)Enum.Parse(typeof(Rarity), item.GetString("rarity", "None"));
            var modules = item.GetArray("modules").Select(m => m.Obj);
            var cook    = 0;

            foreach (var mod in modules)
            {
                var typeName = mod.GetString("type", "");
                if (typeName.Equals("ItemModConsume"))
                {
                    var itemMod     = definition.GetComponent <ItemModConsume>();
                    var itemEffects = itemMod.GetComponent <ItemModConsumable>().effects;
                    var effects     = mod.GetArray("effects");
                    itemEffects.Clear();
                    foreach (var effect in effects)
                    {
                        itemEffects.Add(new ItemModConsumable.ConsumableEffect
                        {
                            type   = (MetabolismAttribute.Type)Enum.Parse(typeof(MetabolismAttribute.Type), effect.Obj.GetString("type", "")),
                            amount = effect.Obj.GetFloat("amount", 0),
                            time   = effect.Obj.GetFloat("time", 0)
                        });
                    }
                }
                else if (typeName.Equals("ItemModContainer"))
                {
                    var itemMod = definition.GetComponent <ItemModContainer>();
                    itemMod.capacity        = mod.GetInt("capacity", 6);
                    itemMod.openInDeployed  = mod.GetBoolean("openInDeployed", true);
                    itemMod.openInInventory = mod.GetBoolean("openInInventory", true);
                    itemMod.defaultContents.Clear();
                    var defaultContents = mod.GetArray("defaultContents");
                    var manager         = SingletonComponent <ItemManager> .Instance;
                    foreach (var content in defaultContents)
                    {
                        var itemid = content.Obj.GetInt("itemid", 0);
                        var def    = manager.itemList.Find(x => x.itemid == itemid);
                        itemMod.defaultContents.Add(new ItemAmount(def, content.Obj.GetFloat("amount", 0)));
                    }
                }
                else if (typeName.Equals("ItemModBurnable"))
                {
                    //definition.gameObject.AddComponent<ItemModBurnable>();
                    var itemMod = definition.GetComponent <ItemModBurnable>();
                    itemMod.fuelAmount      = mod.GetFloat("fuelAmount", 10f);
                    itemMod.byproductAmount = mod.GetInt("byproductAmount", 1);
                    itemMod.byproductChance = mod.GetFloat("byproductChance", 0.5f);
                    var manager = SingletonComponent <ItemManager> .Instance;
                    var itemid  = mod.GetObject("byproductItem").GetInt("itemid", 0);
                    itemMod.byproductItem = manager.itemList.Find(x => x.itemid == itemid);
                }
                else if (typeName.Equals("ItemModCookable"))
                {
                    var itemMods = definition.GetComponents <ItemModCookable>();
                    var itemMod  = itemMods[cook++];
                    itemMod.cookTime       = mod.GetFloat("cookTime", 30f);
                    itemMod.amountOfBecome = mod.GetInt("amountOfBecome", 1);
                    itemMod.lowTemp        = mod.GetInt("lowTemp", 0);
                    itemMod.highTemp       = mod.GetInt("highTemp", 0);
                    itemMod.setCookingFlag = mod.GetBoolean("setCookingFlag", false);
                    var become = mod.GetObject("becomeOnCooked");
                    if (become == null)
                    {
                        itemMod.becomeOnCooked = null;
                        continue;
                    }
                    var manager = SingletonComponent <ItemManager> .Instance;
                    var itemid  = become.GetInt("itemid", 0);
                    itemMod.becomeOnCooked = manager.itemList.Find(x => x.itemid == itemid);
                }
                else if (typeName.Equals("ItemModSwap"))
                {
                    var itemMod = definition.GetComponent <ItemModSwap>();
                    itemMod.sendPlayerDropNotification   = mod.GetBoolean("sendPlayerDropNotification", false);
                    itemMod.sendPlayerPickupNotification = mod.GetBoolean("sendPlayerPickupNotification", false);
                    var items       = new List <ItemAmount>();
                    var becomeItems = mod.GetArray("becomeItem");
                    var manager     = SingletonComponent <ItemManager> .Instance;
                    foreach (var content in becomeItems)
                    {
                        var itemid = content.Obj.GetInt("itemid", 0);
                        var def    = manager.itemList.Find(x => x.itemid == itemid);
                        items.Add(new ItemAmount(def, content.Obj.GetFloat("amount", 0)));
                    }
                    itemMod.becomeItem = items.ToArray();
                }
                else if (typeName.Equals("ItemModProjectile"))
                {
                    var itemMod    = definition.GetComponent <ItemModProjectile>();
                    var projectile = itemMod.projectileObject.targetObject.GetComponent <Projectile>();
                    projectile.drag               = mod.GetFloat("drag", 0);
                    projectile.thickness          = mod.GetFloat("thickness", 0);
                    projectile.remainInWorld      = mod.GetBoolean("remainInWorld", false);
                    projectile.stickProbability   = mod.GetFloat("stickProbability", 0);
                    projectile.breakProbability   = mod.GetFloat("breakProbability", 0);
                    projectile.ricochetChance     = mod.GetFloat("ricochetChance", 0);
                    projectile.fullDamageVelocity = mod.GetFloat("fullDamageVelocity", 200);
                    projectile.damageTypes.Clear();
                    var damageTypes = mod.GetArray("damageTypes");
                    foreach (var damageType in damageTypes)
                    {
                        projectile.damageTypes.Add(new DamageTypeEntry
                        {
                            amount = damageType.Obj.GetFloat("amount", 0),
                            type   = (DamageType)Enum.Parse(typeof(DamageType), damageType.Obj.GetString("type", ""))
                        });
                    }
                }
            }
        }