public void UnitType_EqualityTest154() { UnitType expected = unitPro.UnitTypes ["Length"]; UnitType target = null; Assert.IsFalse(expected.Equals((object)target)); }
public void UnitType_EqualityTest11() { UnitType expected = unitPro.UnitTypes ["Length"]; UnitType target = unitPro.UnitTypes ["Mass"]; Assert.IsFalse(expected.Equals(target)); }
private static void CheckTypes(UnitOfMeasure uom1, UnitOfMeasure uom2) { UnitType thisType = uom1.UOMType; UnitType targetType = uom2.UOMType; if (thisType != UnitType.UNCLASSIFIED && targetType != UnitType.UNCLASSIFIED && !thisType.Equals(UnitType.UNITY) && !targetType.Equals(UnitType.UNITY) && !thisType.Equals(targetType)) { string msg = String.Format(MeasurementSystem.GetMessage("must.be.same.as"), uom1, uom1.UOMType, uom2, uom2.UOMType); throw new Exception(msg); } }
private void Update() { if (currentHp <= 0 & status != UnitStatus.UNACTIVE) { if (type.Equals(UnitType.MONSTER)) { Destroy(this.gameObject); Destroy(this); } else { currentHp = 0; this.status = UnitStatus.UNACTIVE; } } }
private Unit Select(List <Unit> units) { float minDistance = (units[0].transform.position - transform.position).sqrMagnitude; Unit target = units[0]; foreach (var unit in units) { float unitDistanceToTower = (unit.transform.position - transform.position).sqrMagnitude; if (unitDistanceToTower <= minDistance && _targetType.Equals(unit.Type)) { minDistance = unitDistanceToTower; target = unit; } } return(target); }
// // Equals & Hashcode // public override bool Equals(object o) { Unit unit = o as Unit; if (unit == null) { return(false); } if (!coordinates.Equals(unit.coordinates)) { return(false); } if (!type.Equals(unit.type)) { return(false); } return(true); }
/// <summary>Get the factor to convert to the unit of measure</summary> /// /// <param name="targetUOM">Target unit of measure</param> /// /// <returns> conversion factor</returns> /// public double GetConversionFactor(UnitOfMeasure targetUOM) { if (targetUOM == null) { throw new Exception(MeasurementSystem.GetMessage("unit.cannot.be.null")); } // first check the cache if (ConversionRegistry.TryGetValue(targetUOM, out double cachedFactor)) { return(cachedFactor); } CheckTypes(this, targetUOM); Reducer fromPowerMap = GetReducer(); Reducer toPowerMap = targetUOM.GetReducer(); Dictionary <UnitOfMeasure, int> fromMap = fromPowerMap.Terms; Dictionary <UnitOfMeasure, int> toMap = toPowerMap.Terms; if (fromMap.Count != toMap.Count) { string msg = String.Format(MeasurementSystem.GetMessage("incompatible.units"), this, targetUOM); throw new Exception(msg); } double fromFactor = fromPowerMap.MapScalingFactor; double toFactor = toPowerMap.MapScalingFactor; double factor = 1; // compute map factor int matchCount = 0; foreach (KeyValuePair <UnitOfMeasure, int> fromEntry in fromMap) { UnitType fromType = fromEntry.Key.UOMType; UnitOfMeasure fromUOM = fromEntry.Key; int fromPower = fromEntry.Value; foreach (KeyValuePair <UnitOfMeasure, int> toEntry in toMap) { UnitType toType = toEntry.Key.UOMType; if (fromType.Equals(toType)) { matchCount++; UnitOfMeasure toUOM = toEntry.Key; double bd = fromUOM.ConvertScalarToScalar(toUOM); bd = Math.Pow(bd, fromPower); factor = factor * bd; break; } } // to map } // from map if (matchCount != fromMap.Count) { string msg = String.Format(MeasurementSystem.GetMessage("incompatible.units"), this, targetUOM); throw new Exception(msg); } cachedFactor = factor * (fromFactor / toFactor); // cache it ConversionRegistry[targetUOM] = cachedFactor; return(cachedFactor); }
/// <summary> /// If the unit of measure is unclassified, from its base unit map find a matching unit type. /// </summary> /// <returns>Unit of measure</returns> public UnitOfMeasure Classify() { if (!UOMType.Equals(UnitType.UNCLASSIFIED)) { // already classified return(this); } // base unit map Dictionary <UnitOfMeasure, int> uomBaseMap = GetReducer().Terms; // try to find this map in the unit types UnitType matchedType = UnitType.UNCLASSIFIED; foreach (UnitType unitType in UnitType.GetValues(typeof(UnitType))) { ConcurrentDictionary <UnitType, int> unitTypeMap = MeasurementSystem.GetSystem().GetTypeMap(unitType); if (unitTypeMap.Count != uomBaseMap.Count) { // not a match continue; } Boolean match = true; // same size, now check base unit types and exponents foreach (KeyValuePair <UnitOfMeasure, int> kvp in uomBaseMap) { UnitType uomBaseType = kvp.Key.UOMType; int uomBaseExponent = kvp.Value; if (unitTypeMap.TryGetValue(uomBaseType, out int unitExponent)) { // value is in map, check exponents if (unitExponent != uomBaseExponent) { // not a match match = false; break; } } else { // value not in map match = false; break; } } if (match) { matchedType = unitType; break; } } if (!matchedType.Equals(UnitType.UNCLASSIFIED)) { this.UOMType = matchedType; } return(this); }
public void UpdateEveryFields() { GameObject tmpShit = (GameObject)AssetDatabase.LoadAssetAtPath(search_results[indexGO], typeof(GameObject)); if (unitType.Equals(UnitType.AttackingUnit)) { AttackingUnit unit = tmpShit.GetComponent <AttackingUnit>(); nameUnit = unit.NameGo; unitType = unit.UnitType; defaultMaterial = unit.DefaultMaterial; //GameObject tmpSkin = new GameObject(); //tmpSkin.AddComponent<MeshFilter>(); //tmpSkin.GetComponent<MeshFilter>().mesh = unit.GetComponent<MeshFilter>().mesh; //skin = tmpSkin; //DestroyImmediate(tmpSkin); //skin regenManaPerSecond = unit.RegenManaPerSecond; healthMax = unit.HealthMax; manaMax = unit.ManaMax; cost = unit.Cost; xpValue = unit.XpValue; bool inventoryEmpty = true; for (int i = 0; i < unit.Inventory.Length; i++) { if (unit.Inventory[i] != null) { inventoryEmpty = false; } } if (!inventoryEmpty) { for (int i = 0; i < unit.Inventory.Length; i++) { inventory[i] = unit.Inventory[i]; } } creationTime = unit.CreationTime; attackSpeed = unit.AttackSpeed; damage = unit.Damage; range = unit.Range; defense = unit.Defense; rangeAggroWhenAttack = unit.RangeAggroWhenAttack; moveSpeed = unit.MoveSpeed; } else if (unitType.Equals(UnitType.Building)) { CreationBuilding unit = tmpShit.GetComponent <CreationBuilding>(); nameUnit = unit.NameGo; unitType = unit.UnitType; defaultMaterial = unit.DefaultMaterial; healthMax = unit.HealthMax; manaMax = unit.ManaMax; cost = unit.Cost; xpValue = unit.XpValue; creation = unit.Creations[0]; //bool creationsEmpties = true; //for (int i = 0; i < unit.Creations.Length; i++) //{ // if (unit.Creations[i] != null) // creationsEmpties = false; //} //if (!creationsEmpties) //{ // for (int i = 0; i < unit.Creations.Length; i++) // { // if (unit.Creations[i] != null) // creations[i] = unit.Creations[i]; // } //} } }
public bool Equals(DestinyHistoricalStatsDefinition input) { if (input == null) { return(false); } return (( StatId == input.StatId || (StatId != null && StatId.Equals(input.StatId)) ) && ( Group == input.Group || (Group != null && Group.Equals(input.Group)) ) && ( PeriodTypes == input.PeriodTypes || (PeriodTypes != null && PeriodTypes.SequenceEqual(input.PeriodTypes)) ) && ( Modes == input.Modes || (Modes != null && Modes.SequenceEqual(input.Modes)) ) && ( Category == input.Category || (Category != null && Category.Equals(input.Category)) ) && ( StatName == input.StatName || (StatName != null && StatName.Equals(input.StatName)) ) && ( StatNameAbbr == input.StatNameAbbr || (StatNameAbbr != null && StatNameAbbr.Equals(input.StatNameAbbr)) ) && ( StatDescription == input.StatDescription || (StatDescription != null && StatDescription.Equals(input.StatDescription)) ) && ( UnitType == input.UnitType || (UnitType != null && UnitType.Equals(input.UnitType)) ) && ( IconImage == input.IconImage || (IconImage != null && IconImage.Equals(input.IconImage)) ) && ( MergeMethod == input.MergeMethod || (MergeMethod.Equals(input.MergeMethod)) ) && ( UnitLabel == input.UnitLabel || (UnitLabel != null && UnitLabel.Equals(input.UnitLabel)) ) && ( Weight == input.Weight || (Weight.Equals(input.Weight)) ) && ( MedalTierHash == input.MedalTierHash || (MedalTierHash.Equals(input.MedalTierHash)) )); }
/// <summary> /// Unit Conversion Method. /// </summary> /// <param name="type"></param> /// <returns></returns> public double Conversion(UnitType type) { if (type.Equals(UnitType.FEET)) { return(1.0 * 12.0); } if (type.Equals(UnitType.YARD)) { return(1.0 * 36.0); } if (type.Equals(UnitType.CENTIMETER)) { return(1.0 / 2.5); } if (type.Equals(UnitType.GALLON)) { return(1.0 * 3.785); } if (type.Equals(UnitType.LITRE)) { return(1.0); } if (type.Equals(UnitType.MILLILITRE)) { return(1.0 / 1000.0); } if (type.Equals(UnitType.KILOGRAM)) { return(1.0); } if (type.Equals(UnitType.GRAM)) { return(1.0 / 1000.0); } if (type.Equals(UnitType.TONNE)) { return(1.0 * 1000.0); } if (type.Equals(UnitType.CELSIUS)) { return(1.8); } if (type.Equals(UnitType.FAHRENHEIT)) { return(1.0); } else { return(1.0); } }