public void UpdateEquippedParts(PartSchematic newPart) { PartSlot curPickedSlot = PickedPartsItem.Slot; PartSchematic oldPart = curPickedSlot.Part; curPickedSlot.UpdatePart(newPart); if (newPart != null && newPart.PType == PartSchematic.PartType.Hull) { HullPartSchematic oldHull = (HullPartSchematic)oldPart; HullPartSchematic newHull = (HullPartSchematic)newPart; if (oldHull.OrigWeaponDirs.Length != newHull.OrigWeaponDirs.Length) { int lengthDiff = newHull.OrigWeaponDirs.Length - oldHull.OrigWeaponDirs.Length; if (lengthDiff > 0) { for (int i = 0; i < lengthDiff; ++i) { EquippedParts.Add(new PartSlot(null, PartSchematic.PartType.Weapon, EquippedParts.Count)); } } else if (lengthDiff < 0) { for (int i = 0; i < Math.Abs(lengthDiff); ++i) { EquippedParts.RemoveAt(EquippedParts.Count - 1); } } } int count = 0; foreach (PartSlot slot in EquippedParts) { if (slot.PartType == PartSchematic.PartType.Weapon) { PartSchematic.WeaponTier tier = newHull.WeaponTierRestrictions[count]; if (slot.Part != null && ((WeaponPartSchematic)slot.Part).Tier > tier) { slot.UpdatePart(null); } count += 1; } } } updateTankDisplayToCurrent(); }
private void loadWeaponParts() { Dictionary <string, PartSchematic> schematics = new Dictionary <string, PartSchematic>(); TextAsset jsonText = Resources.Load("WeaponPartList") as TextAsset; JObject root = JObject.Parse(jsonText.text); foreach (var partInfo in root) { string name = partInfo.Key; JObject info = (JObject)partInfo.Value; float reloadTime = info.Value <float>("reload_time"); int energyUsage = info.Value <int>("energy_usage"); string tierStr = info.Value <string>("tier"); PartSchematic.WeaponTier tier = PartSchematic.WeaponTier.Light; if (tierStr.Equals("L")) { tier = PartSchematic.WeaponTier.Light; } else if (tierStr.Equals("M")) { tier = PartSchematic.WeaponTier.Medium; } else if (tierStr.Equals("H")) { tier = PartSchematic.WeaponTier.Heavy; } Bullet.BulletTypes bType = (Bullet.BulletTypes)Enum.Parse(typeof(Bullet.BulletTypes), info.Value <string>("bullet_type")); Dictionary <string, object> bulletInfoDict = parseBulletInfoJson(bType, info.Value <JObject>("bullet_info")); WeaponPartSchematic part = TankParSchematictFactory.CreateWeaponPartSchematic(name, reloadTime, energyUsage, tier, bType, bulletInfoDict); schematics.Add(part.Name, part); } partSchematicDics.Add(PartSchematic.PartType.Weapon, schematics); }
private void generateOtherItems() { List <PartSchematic> allParts = new List <PartSchematic>(PartsManager.Instance.GetPartsOfType(handler.PickedPartsItem.Slot.PartType)); List <PartSchematic> parts = new List <PartSchematic>(); if (handler.PickedPartsItem.Slot.PartType == PartSchematic.PartType.Weapon) { parts.Add(null); HullPartSchematic curHull = (HullPartSchematic)handler.EquippedParts[0].Part; PartSchematic.WeaponTier tier = curHull.WeaponTierRestrictions[handler.PickedPartsItem.Slot.Idx - 1]; allParts = allParts.FindAll(w => ((WeaponPartSchematic)w).Tier <= tier); } parts.AddRange(allParts); float itemAnchorStep = 1f / 9f; for (int i = 0; i < parts.Count; ++i) { PartSchematic schem = parts[i]; OtherPartsItem item = handler.OtherPartsItemPool.GetObject().GetComponent <OtherPartsItem>(); item.transform.SetParent(handler.OtherPartsItemsRoot, false); Vector2 anchorMin = new Vector2(0, 1 - (i + 1) * itemAnchorStep); Vector2 anchorMax = new Vector2(1, 1 - (i) * itemAnchorStep); RectTransform rect = item.GetComponent <RectTransform>(); rect.anchorMin = anchorMin; rect.anchorMax = anchorMax; rect.offsetMin = new Vector2(); rect.offsetMax = new Vector2(); rect.localScale = new Vector3(1, 1, 1); item.Init(schem, handler); item.GetComponent <Button>().onClick.AddListener(delegate { ownedItemSelected(item); }); items.Add(item); } }
private void loadHullParts() { Dictionary <string, PartSchematic> schematics = new Dictionary <string, PartSchematic>(); TextAsset jsonText = Resources.Load("HullPartList") as TextAsset; JObject root = JObject.Parse(jsonText.text); foreach (var partInfo in root) { string name = partInfo.Key; JObject info = (JObject)partInfo.Value; int weight = info.Value <int>("weight"); int armour = info.Value <int>("armor"); int enginePower = info.Value <int>("engine_pow"); Vector2 size = new Vector2(); size.x = info.Value <float>("size_x"); size.y = info.Value <float>("size_y"); float angularDrag = info.Value <float>("angular_drag"); float energy = info.Value <float>("energy"); float energyRefresh = info.Value <float>("energy_refresh"); float jetImpulse = info.Value <float>("jet_impulse"); float jetEnergyUsage = info.Value <float>("jet_energy_usage"); List <Vector2> weaponDirs = new List <Vector2>(); List <Vector2> weaponPos = new List <Vector2>(); List <PartSchematic.WeaponTier> tierRestrictions = new List <PartSchematic.WeaponTier>(); foreach (JObject jo in info.Value <JArray>("weapons")) { Vector2 dir = new Vector2(); dir.x = jo.Value <float>("x_dir"); dir.y = jo.Value <float>("y_dir"); weaponDirs.Add(dir); Vector2 pos = new Vector2(); pos.x = jo.Value <float>("x_pos"); pos.y = jo.Value <float>("y_pos"); weaponPos.Add(pos); string weaponTier = jo.Value <string>("tier"); PartSchematic.WeaponTier tier = PartSchematic.WeaponTier.Light; if (weaponTier.Equals("L")) { tier = PartSchematic.WeaponTier.Light; } else if (weaponTier.Equals("M")) { tier = PartSchematic.WeaponTier.Medium; } else if (weaponTier.Equals("H")) { tier = PartSchematic.WeaponTier.Heavy; } tierRestrictions.Add(tier); } HullPartSchematic part = TankParSchematictFactory.CreateHullPartSchematic(name, armour, enginePower, size, weight, angularDrag, energy, energyRefresh, jetImpulse, jetEnergyUsage, weaponDirs.ToArray(), weaponPos.ToArray(), tierRestrictions.ToArray()); schematics.Add(part.Name, part); } partSchematicDics.Add(PartSchematic.PartType.Hull, schematics); }
public static WeaponPartSchematic CreateWeaponPartSchematic(string name, float reloadTime, int energyUsage, PartSchematic.WeaponTier weaponTier, Bullet.BulletTypes bulletType, Dictionary <string, object> bulletInfos) { return(new WeaponPartSchematic(name, reloadTime, energyUsage, weaponTier, bulletType, bulletInfos)); }