예제 #1
0
        //	static  readonly  object  locker = new object();
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="parent"></param>
        /// <param name="noParseJson"></param>
        /// <returns></returns>
        public static object ToUson(object obj, UObj parent = null, bool noParseJson = false)
        {
            //	lock (locker){
            if (obj is string && !noParseJson)
            {
                var s = obj.ToString().Trim();
                if (0 != s.Length)
                {
                    if (s[0] == '{' && s[s.Length - 1] == '}')
                    {
                        return(new JsonParser().Parse(s).ToUson());
                    }
                }
            }

            if (obj is string)
            {
                var s = obj as string;
                if (s == "0")
                {
                    return(0m);
                }
                var dec = s.ToDecimal(true);
                if (dec != 0 && dec.ToString(CultureInfo.InvariantCulture) == s)
                {
                    return(dec);
                }
                return(s);
            }

            if (obj == null || obj.GetType().IsValueType)
            {
                return(obj);
            }
            var result = new UObj {
                Parent = parent, _srctype = obj.GetType()
            };

            if (obj is UObj)
            {
                result.UObjMode = (obj as UObj).UObjMode;
                foreach (var p in ((UObj)obj).Properties)
                {
                    result.Properties[p.Key] = ToUson(p.Value, null, noParseJson);
                }
                foreach (var p in ((UObj)obj).Array)
                {
                    result.Array.Add(p);
                }
                return(result);
            }
            if (obj is JsonItem)
            {
                if (obj is JsonObject)
                {
                    foreach (var p in ((JsonObject)obj).Properties)
                    {
                        result.Properties[p.Name.Value] = ToUson(p.Value, null, noParseJson);
                    }
                    return(result);
                }
                else if (obj is JsonArray)
                {
                    foreach (var p in ((JsonArray)obj).Values)
                    {
                        result.Array.Add(ToUson(p.Value, null, noParseJson));
                    }
                    return(result);
                }
                else if (obj is JsonValue)
                {
                    var jv = (JsonValue)obj;
                    if (jv.Type == JsonTokenType.String)
                    {
                        return(ToUson(jv.Value, null, noParseJson));
                    }
                    if (jv.Type == JsonTokenType.Number)
                    {
                        return(decimal.Parse(jv.Value));
                    }
                    if (jv.Type == JsonTokenType.Null)
                    {
                        return(null);
                    }
                    if (jv.Type == JsonTokenType.Bool)
                    {
                        return(Boolean.Parse(jv.Value));
                    }
                    return(ToUson(jv.Value, null, noParseJson));
                }
            }
            if (obj is Array)
            {
                result.UObjMode = UObjMode.Array;
                foreach (var item in ((IEnumerable)obj))
                {
                    result.Array.Add(ToUson(item, null, noParseJson));
                }
            }
            else if (obj.GetType().Name.StartsWith("Dictionary"))
            {
                result.UObjMode = UObjMode.Default;
                foreach (dynamic item in ((IEnumerable)obj))
                {
                    result.Properties[item.Key.ToString()] = ToUson(item.Value);
                }
            }
            else if (obj.GetType().Name.StartsWith("List"))
            {
                result.UObjMode = UObjMode.Array;
                foreach (var item in ((IEnumerable)obj))
                {
                    result.Array.Add(ToUson(item, null, noParseJson));
                }
            }

            else
            {
                foreach (var p in SerializableItem.GetSerializableItems(obj))
                {
                    result.Properties[p.Name] = ToUson(p.Value, null, noParseJson);
                }
            }

            return(result);
            //		}
        }
예제 #2
0
        /// <summary>
        /// Adds the traits.
        /// </summary>
        /// <param name="srcItem">The source item.</param>
        /// <param name="item">The item.</param>
        private static void AddTraits(InvTypes srcItem, SerializableItem item)
        {
            if (Database.InvGroupsTable[srcItem.GroupID].CategoryID != DBConstants.ShipCategoryID)
            {
                return;
            }

            var skillBonusesText = new StringBuilder(512);
            var roleBonusesText = new StringBuilder(512);
            var miscBonusesText = new StringBuilder(512);
            int numSkillBonuses = 0, numRoleBonuses, numMiscBonuses;

            // Group by the bonusing skill
            foreach (IGrouping <int?, InvTraits> bonuses in Database.InvTraitsTable
                     .Where(x => x.typeID == srcItem.ID && x.skillID > 0)
                     .GroupBy(x => x.skillID))
            {
                int skillID = bonuses.Key ?? 0;
                skillBonusesText.Append(Database.InvTypesTable[skillID].Name);
                skillBonusesText.AppendLine(" bonuses (per skill level):");

                numSkillBonuses += AddBonuses(bonuses, skillBonusesText);
            }
            skillBonusesText.AppendLine();

            // Find the role bonuses
            var RoleBonuses = Database.InvTraitsTable.Where(x => x.typeID == srcItem.ID &&
                                                            x.skillID == -1);

            roleBonusesText.AppendLine("Role bonus:");
            numRoleBonuses = AddBonuses(RoleBonuses, roleBonusesText);

            // Find the misc bonuses
            var MiscBonuses = Database.InvTraitsTable.Where(x => x.typeID == srcItem.ID &&
                                                            x.skillID == -2);

            miscBonusesText.AppendLine("Misc bonus:");
            numMiscBonuses = AddBonuses(MiscBonuses, miscBonusesText);

            // For any T3 destroyer, we need to deal with CCP being horrific cheats. The 'ship
            // traits' are actually derived through some epic hacking from some hidden items.
            // Hard coding some things in the short term, but need to make this MOAR BETTER.
#if false
            List <long> T3DIDs = new List <long> {
                34562, 35683, 34317, 34828
            };
            if (T3DIDs.Contains(item.ID))
            {
                Dictionary <string, int> T3DModeInfo = new Dictionary <string, int>();
                T3DModeInfo.Add("Sharpshooter", 0);
                T3DModeInfo.Add("Defense", 0);
                T3DModeInfo.Add("Propulsion", 0);

                // Determine which T3D we have, and get the relevant sub-item IDs
                switch (item.ID)
                {
                case 34562:
                    // Svipul
                    T3DModeInfo["Sharpshooter"] = 34570;
                    T3DModeInfo["Propulsion"]   = 34566;
                    T3DModeInfo["Defense"]      = 34564;
                    break;

                case 35683:
                    // Hecate
                    T3DModeInfo["Sharpshooter"] = 35688;
                    T3DModeInfo["Propulsion"]   = 35687;
                    T3DModeInfo["Defense"]      = 35686;
                    break;

                case 34317:
                    // Confessor
                    T3DModeInfo["Sharpshooter"] = 34321;
                    T3DModeInfo["Propulsion"]   = 34323;
                    T3DModeInfo["Defense"]      = 34319;
                    break;

                case 34828:
                    // Jackdaw
                    T3DModeInfo["Sharpshooter"] = 35678;
                    T3DModeInfo["Propulsion"]   = 35677;
                    T3DModeInfo["Defense"]      = 35676;
                    break;

                default:
                    break;
                }

                foreach (var T3DMode in T3DModeInfo)
                {
                    int id = T3DMode.Value;
                    if (id > 0)
                    {
                        var DBRecord = Database.InvTypesTable[id];
                        miscBonusesText.Append(T3DMode.Key).AppendLine(" Mode:");
                        miscBonusesText.AppendLine(DBRecord.Description).AppendLine();
                    }
                }
            }
#endif
            // Skip if no bonuses
            if (numSkillBonuses <= 0 && numRoleBonuses <= 0 && numMiscBonuses <= 0)
            {
                return;
            }

            var sb = new StringBuilder(1024);
            sb.AppendLine().AppendLine().AppendLine("--- Traits ---");
            if (numSkillBonuses > 0)
            {
                sb.Append(skillBonusesText.ToString());
            }
            if (numRoleBonuses > 0)
            {
                sb.Append(roleBonusesText.ToString());
            }
            if (numMiscBonuses > 0)
            {
                sb.Append(miscBonusesText.ToString());
            }

            // Add to item description
            item.Description += sb.ToString();
        }
예제 #3
0
        /// <summary>
        /// Adds the item properties and prerequisites.
        /// </summary>
        /// <param name="srcItem">The source item.</param>
        /// <param name="item">The serializable item.</param>
        /// <returns></returns>
        private static void AddItemPropsAndPrereq(InvTypes srcItem, SerializableItem item)
        {
            Int64[] prereqSkills = new Int64[DBConstants.RequiredSkillPropertyIDs.Count];
            Int64[] prereqLevels = new Int64[DBConstants.RequiredSkillPropertyIDs.Count];
            List <SerializablePropertyValue> props = new List <SerializablePropertyValue>();
            double warpSpeedMultiplier             = 1;

            foreach (DgmTypeAttributes srcProp in Database.DgmTypeAttributesTable.Where(x => x.ItemID == srcItem.ID))
            {
                Int64 propInt64Value = srcProp.GetInt64Value;

                // Is it a prereq skill ?
                int prereqIndex = DBConstants.RequiredSkillPropertyIDs.IndexOf(srcProp.AttributeID);
                if (prereqIndex > -1)
                {
                    prereqSkills[prereqIndex] = propInt64Value;
                    continue;
                }

                // Is it a prereq level ?
                prereqIndex = DBConstants.RequiredSkillLevelPropertyIDs.IndexOf(srcProp.AttributeID);
                if (prereqIndex > -1)
                {
                    prereqLevels[prereqIndex] = propInt64Value;
                    continue;
                }

                // Launcher group ?
                int launcherIndex = DBConstants.LauncherGroupPropertyIDs.IndexOf(srcProp.AttributeID);
                if (launcherIndex > -1)
                {
                    props.Add(new SerializablePropertyValue
                    {
                        ID    = srcProp.AttributeID,
                        Value = Database.InvGroupsTable.HasValue(propInt64Value)
                                                        ? Database.InvGroupsTable[propInt64Value].Name
                                                        : String.Empty
                    });
                    continue;
                }

                // Charge group ?
                int chargeIndex = DBConstants.ChargeGroupPropertyIDs.IndexOf(srcProp.AttributeID);
                if (chargeIndex > -1)
                {
                    props.Add(new SerializablePropertyValue
                    {
                        ID    = srcProp.AttributeID,
                        Value = Database.InvGroupsTable.HasValue(propInt64Value)
                                                        ? Database.InvGroupsTable[propInt64Value].Name
                                                        : String.Empty
                    });
                    continue;
                }

                // CanFitShip group ?
                int canFitShipIndex = DBConstants.CanFitShipGroupPropertyIDs.IndexOf(srcProp.AttributeID);
                if (canFitShipIndex > -1)
                {
                    props.Add(new SerializablePropertyValue
                    {
                        ID    = srcProp.AttributeID,
                        Value = Database.InvGroupsTable.HasValue(propInt64Value)
                                                        ? Database.InvGroupsTable[propInt64Value].Name
                                                        : String.Empty
                    });
                    continue;
                }

                // ModuleShip group ?
                int moduleShipIndex = DBConstants.ModuleShipGroupPropertyIDs.IndexOf(srcProp.AttributeID);
                if (moduleShipIndex > -1)
                {
                    props.Add(new SerializablePropertyValue
                    {
                        ID    = srcProp.AttributeID,
                        Value = Database.InvGroupsTable.HasValue(propInt64Value)
                                                        ? Database.InvGroupsTable[propInt64Value].Name
                                                        : String.Empty
                    });
                    continue;
                }

                // SpecialisationAsteroid group ?
                int specialisationAsteroidIndex = DBConstants.SpecialisationAsteroidGroupPropertyIDs.IndexOf(srcProp.AttributeID);
                if (specialisationAsteroidIndex > -1)
                {
                    props.Add(new SerializablePropertyValue
                    {
                        ID    = srcProp.AttributeID,
                        Value = Database.InvGroupsTable.HasValue(propInt64Value)
                                                        ? Database.InvGroupsTable[propInt64Value].Name
                                                        : String.Empty
                    });
                    continue;
                }

                // Reaction group ?
                int reactionIndex = DBConstants.ReactionGroupPropertyIDs.IndexOf(srcProp.AttributeID);
                if (reactionIndex > -1)
                {
                    props.Add(new SerializablePropertyValue
                    {
                        ID    = srcProp.AttributeID,
                        Value = Database.InvGroupsTable.HasValue(propInt64Value)
                                                        ? Database.InvGroupsTable[propInt64Value].Name
                                                        : String.Empty
                    });
                    continue;
                }

                // PosCargobayAccept group ?
                int posCargobayAcceptIndex = DBConstants.PosCargobayAcceptGroupPropertyIDs.IndexOf(srcProp.AttributeID);
                if (posCargobayAcceptIndex > -1)
                {
                    props.Add(new SerializablePropertyValue
                    {
                        ID    = srcProp.AttributeID,
                        Value = Database.InvGroupsTable.HasValue(propInt64Value)
                                                        ? Database.InvGroupsTable[propInt64Value].Name
                                                        : String.Empty
                    });
                    continue;
                }

                // Get the warp speed multiplier
                if (srcProp.AttributeID == DBConstants.WarpSpeedMultiplierPropertyID && srcProp.ValueFloat != null)
                {
                    warpSpeedMultiplier = srcProp.ValueFloat.Value;
                }

                // We calculate and add the ships warp speed
                if (srcProp.AttributeID == DBConstants.ShipWarpSpeedPropertyID)
                {
                    props.Add(new SerializablePropertyValue
                    {
                        ID    = srcProp.AttributeID,
                        Value = warpSpeedMultiplier.ToString(CultureConstants.InvariantCulture)
                    });

                    // Also add packaged volume as a prop as only ships have 'ship warp speed' attribute
                    props.Add(new SerializablePropertyValue
                    {
                        ID    = Properties.PackagedVolumePropertyID,
                        Value = GetPackagedVolume(srcItem.GroupID).ToString(CultureConstants.InvariantCulture)
                    });
                }

                // Other props
                props.Add(new SerializablePropertyValue {
                    ID = srcProp.AttributeID, Value = srcProp.FormatPropertyValue()
                });

                AddMetaData(item, propInt64Value, srcProp);
            }

            CompleteItemPropertiesAddition(srcItem, props);

            // Add properties info to item
            item.Properties.AddRange(props);

            // Prerequisites completion
            List <SerializablePrerequisiteSkill> prereqs = new List <SerializablePrerequisiteSkill>();

            for (int i = 0; i < prereqSkills.Length; i++)
            {
                if (prereqSkills[i] != 0)
                {
                    prereqs.Add(new SerializablePrerequisiteSkill {
                        ID = prereqSkills[i], Level = prereqLevels[i]
                    });
                }
            }

            // Add prerequisite skills info to item
            item.PrerequisiteSkills.AddRange(prereqs);
        }
예제 #4
0
        /// <summary>
        /// Add properties to an item.
        /// </summary>
        /// <param name="srcItem"></param>
        /// <param name="groupItems"></param>
        /// <returns></returns>
        private static void CreateItem(InvTypes srcItem, ICollection <SerializableItem> groupItems)
        {
            Util.UpdatePercentDone(Database.ItemsTotalCount);

            srcItem.Generated = true;

            InvGroups itemGroup = Database.InvGroupsTable[srcItem.GroupID];

            // Creates the item with base informations
            SerializableItem item = new SerializableItem
            {
                ID          = srcItem.ID,
                Name        = srcItem.Name,
                Description = srcItem.Description ?? String.Empty,
                Icon        = srcItem.IconID.HasValue
                                        ? Database.EveIconsTable[srcItem.IconID.Value].Icon
                                        : String.Empty,
                PortionSize = srcItem.PortionSize,
                MetaGroup   = ItemMetaGroup.None,
                Group       = itemGroup.Name,
                Category    = Database.InvCategoriesTable[itemGroup.CategoryID].Name,
                Race        = (Race)Enum.ToObject(typeof(Race), srcItem.RaceID ?? 0)
            };


            // Set race to Faction if item race is Jovian or belongs to a Faction market group
            if (item.Race == Race.Jove || Database.InvMarketGroupsTable.Any(group =>
                                                                            srcItem.MarketGroupID == group.ID && (DBConstants.FactionMarketGroupIDs.Any(
                                                                                                                      id => id == group.ID) || DBConstants.FactionMarketGroupIDs.Any(id => id ==
                                                                                                                                                                                     group.ParentID))))
            {
                item.Race = Race.Faction;
            }

            // Add traits
            AddTraits(srcItem, item);

            // Add the properties and prereqs
            AddItemPropsAndPrereq(srcItem, item);

            // Metagroup
            AddMetaGroup(srcItem, item);

            // Look for slots
            if (Database.DgmTypeEffectsTable.Contains(srcItem.ID, 0, DBConstants.LowSlotEffectID))
            {
                item.Slot = ItemSlot.Low;
            }
            else if (Database.DgmTypeEffectsTable.Contains(srcItem.ID, 0, DBConstants.MedSlotEffectID))
            {
                item.Slot = ItemSlot.Medium;
            }
            else if (Database.DgmTypeEffectsTable.Contains(srcItem.ID, 0, DBConstants.HiSlotEffectID))
            {
                item.Slot = ItemSlot.High;
            }
            else
            {
                item.Slot = ItemSlot.NoSlot;
            }

            // Add reaction info for reactions
            if (Database.InvGroupsTable[srcItem.GroupID].CategoryID == DBConstants.ReactionCategoryID)
            {
                AddReactionInfo(srcItem, item);
            }

            // Add fuel info for control towers
            if (srcItem.GroupID == DBConstants.ControlTowerGroupID)
            {
                AddControlTowerFuelInfo(srcItem, item);
            }

            // Add this item
            groupItems.Add(item);

            // If the current item isn't in a market group then we are done
            if (srcItem.MarketGroupID == DBConstants.RootNonMarketGroupID)
            {
                return;
            }

            // Look for variations which are not in any market group
            foreach (InvTypes srcVariationItem in Database.InvMetaTypesTable.Where(x => x.ParentItemID == srcItem.ID).Select(
                         variation => Database.InvTypesTable[variation.ItemID]).Where(
                         srcVariationItem => srcVariationItem.Published &&
                         srcVariationItem.MarketGroupID == DBConstants.RootNonMarketGroupID))
            {
                srcVariationItem.RaceID = (int)Race.Faction;
                CreateItem(srcVariationItem, groupItems);
            }
        }
예제 #5
0
		public void bug_0_int_was_treated_as_serializable() {
			var test = new test();
			var item = new SerializableItem(test.GetType().GetField("intf"), test);
			Assert.False(item.IsSerializable);
		}
예제 #6
0
 public void add(SerializableItem seri)
 {
     _items.Add(seri);
     onUpdateCount();
 }
예제 #7
0
 public ItemStack(SerializableItem seri) : this(new List <SerializableItem>() { seri })
 {
 }
예제 #8
0
        public void ignore_items_are_ignored()
        {
            var items = SerializableItem.GetSerializableItems(new test());

            Assert.Null(items.FirstOrDefault(x => x.Name == "iintf"), "iintf");
        }