Esempio n. 1
0
    public override string GetStatString(PartSchematic diffSchem)
    {
        bool showDiff = diffSchem != null;

        string retStr = string.Empty;

        if (showDiff)
        {
            HullPartSchematic diffHull = (HullPartSchematic)diffSchem;

            string diffWeightRestrictStr = "(" + String.Join(", ", new List <WeaponTier>(diffHull.WeaponTierRestrictions).ConvertAll(i => i.ToString()).ToArray()) + ")";
            string weightRestrictStr     = "(" + String.Join(", ", new List <WeaponTier>(WeaponTierRestrictions).ConvertAll(i => i.ToString()).ToArray()) + ")";

            string armorStr       = string.Format("Armour:\n{0} => {2}{1}</color>", diffHull.Armour, Armour, getColorBasedChangeInVal(diffHull.Armour, Armour));
            string energyPowerStr = string.Format("Move Force:\n{0} => {2}{1}</color>", diffHull.EnginePower, EnginePower, getColorBasedChangeInVal(diffHull.EnginePower, EnginePower));
            string weightStr      = string.Format("Weight:\n{0} => {2}{1}</color>", diffHull.Weight, Weight, getColorBasedChangeInVal(diffHull.Weight, Weight, false));
            string angularDragStr = string.Format("Angular Drag:\n{0} => {2}{1}</color>", diffHull.AngularDrag, AngularDrag, getColorBasedChangeInVal(diffHull.AngularDrag, AngularDrag, false));

            retStr = string.Format("{0}\n{1}\n{2}\n{3}\nWeapon Weight Restrictions:\n{4} => {5}",
                                   armorStr, energyPowerStr, weightStr, angularDragStr, diffWeightRestrictStr, weightRestrictStr);
        }
        else
        {
            string weightRestrictStr = "(" + String.Join(", ", new List <WeaponTier>(WeaponTierRestrictions).ConvertAll(i => i.ToString()).ToArray()) + ")";
            retStr = string.Format("Armour:\n{0}\nEnergy Power:\n{1}\n Weight:\n{2}\nAngular Drag:\n{3}\nWeapon Weight Restrictions:\n{4}",
                                   Armour, EnginePower, Weight, AngularDrag, weightRestrictStr);
        }

        return(retStr);
    }
Esempio n. 2
0
    public HullPart(HullPartSchematic _schematic, Tank _owner)
    {
        Schematic     = _schematic;
        owner         = _owner;
        LeftCurPower  = 0;
        RightCurPower = 0;
        CurEnergy     = Schematic.Energy;

        weapons = new WeaponPart[Schematic.OrigWeaponDirs.Length];
        Array.Clear(weapons, 0, weapons.Length);
    }
Esempio n. 3
0
    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();
    }
Esempio n. 4
0
    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);
        }
    }
Esempio n. 5
0
    private TankSchematic partSlotsToTankSchematic()
    {
        HullPartSchematic          hullSchem    = null;
        List <WeaponPartSchematic> weaponSchems = new List <WeaponPartSchematic>();

        foreach (PartSlot slot in EquippedParts)
        {
            switch (slot.PartType)
            {
            case PartSchematic.PartType.Hull:
                hullSchem = (HullPartSchematic)slot.Part;
                break;

            case PartSchematic.PartType.Weapon:
                weaponSchems.Add((WeaponPartSchematic)slot.Part);
                break;
            }
        }

        Debug.Assert(hullSchem != null && weaponSchems.Count > 0, "PartSlots to Tank Schematic resulted in invalid tank schematic. Should never happen.");

        return(new TankSchematic(hullSchem, weaponSchems.ToArray()));
    }
Esempio n. 6
0
    public static TankSchematic LoadTankSchematic(JObject tankSchemInfo)
    {
        JObject parts = tankSchemInfo;

        string            hullName = parts.Value <string>("Hull");
        HullPartSchematic hull     = (HullPartSchematic)PartsManager.Instance.GetPartFromName(PartSchematic.PartType.Hull, hullName);

        JArray weapons = parts.Value <JArray>("Weapons");
        List <WeaponPartSchematic> weaponsList = new List <WeaponPartSchematic>();

        foreach (string str in weapons)
        {
            if (!str.Equals(string.Empty))
            {
                weaponsList.Add((WeaponPartSchematic)PartsManager.Instance.GetPartFromName(PartSchematic.PartType.Weapon, str));
            }
            else
            {
                weaponsList.Add(null);
            }
        }

        return(new TankSchematic(hull, weaponsList.ToArray()));
    }
Esempio n. 7
0
    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);
    }
Esempio n. 8
0
 public TankSchematic(HullPartSchematic hull, WeaponPartSchematic[] weapons)
 {
     HullSchematic    = hull;
     WeaponSchematics = weapons;
 }