Exemplo n.º 1
0
    private static List <string> GetUpgrades(Upgrade.UpgradeSlot slot)
    {
        List <string> results = new List <string>();

        List <Type> typelist = Assembly.GetExecutingAssembly().GetTypes()
                               .Where(t => String.Equals(t.Namespace, "UpgradesList", StringComparison.Ordinal))
                               .ToList();

        foreach (var type in typelist)
        {
            Upgrade.GenericUpgrade newUpgrade = (Upgrade.GenericUpgrade)System.Activator.CreateInstance(type);
            if (!newUpgrade.IsHidden)
            {
                if (newUpgrade.Type == slot)
                {
                    string upgradeKey = newUpgrade.Name + " (" + newUpgrade.Cost + ")";
                    if (!AllUpgrades.ContainsKey(upgradeKey))
                    {
                        AllUpgrades.Add(upgradeKey, type.ToString());
                    }
                    results.Add(upgradeKey);
                }
            }
        }

        return(results);
    }
Exemplo n.º 2
0
        public List <UpgradeSlot> GetFreeSlots(List <UpgradeType> upgradeTypes)
        {
            // clone the list in order to search
            List <UpgradeSlot> holder = new List <UpgradeSlot>();

            for (int i = 0; i < UpgradeSlots.Count; i++)
            {
                holder.Add(UpgradeSlots [i]);
            }

            List <UpgradeSlot> results = new List <UpgradeSlot>();

            for (int i = 0; i < upgradeTypes.Count; i++)
            {
                UpgradeType uType = upgradeTypes [i];
                for (int j = 0; j < holder.Count; j++)
                {
                    UpgradeSlot uslot = holder [j];
                    if (uType == uslot.Type && uslot.IsEmpty)
                    {
                        results.Add(uslot);
                        holder.Remove(uslot);
                        break;
                    }
                }
            }
            return(results);
        }
Exemplo n.º 3
0
        /**
         * Checks if the ship has free upgrade slots for the list of upgrade types.
         * @param upgradeTypes the list of upgrades types to check.
         * @return true if there are slots for all upgrade types open and false otherwise.
         */
        public bool HasFreeUpgradeSlot(List <UpgradeType> upgradeTypes)
        {
            // clone the list in order to search
            List <UpgradeSlot> slots = new List <UpgradeSlot> ();

            for (int i = 0; i < UpgradeSlots.Count; i++)
            {
                slots.Add(UpgradeSlots[i]);
            }

            // the number of slots available
            int count = 0;

            for (int i = 0; i < upgradeTypes.Count; i++)
            {
                UpgradeType type = upgradeTypes [i];

                for (int j = 0; j < slots.Count; j++)
                {
                    UpgradeSlot slot = slots [j];
                    if (slot.Type == type && slot.InstalledUpgrade == null)
                    {
                        slots.Remove(slot);
                        count++;
                        break;
                    }
                }
            }
            if (count == upgradeTypes.Count)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        public void TryInstallUpgrade(GenericUpgrade upgrade)
        {
            List <UpgradeSlot> freeSlots = GetFreeSlots(upgrade.UpgradeInfo.UpgradeTypes);

            if (freeSlots.Count != upgrade.UpgradeInfo.UpgradeTypes.Count)
            {
                Debug.Log("No free slot: " + upgrade.getTypesAsString());
            }
            else
            {
                for (int i = 0; i < freeSlots.Count; i++)
                {
                    UpgradeSlot freeSlot = freeSlots [i];
                    for (int j = 0; j < upgrade.UpgradeInfo.UpgradeTypes.Count; j++)
                    {
                        UpgradeType type = upgrade.UpgradeInfo.UpgradeTypes[j];
                        if (type == freeSlot.Type)
                        {
                            freeSlot.TryInstallUpgrade(upgrade, HostShip);
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public UpgradeSlot GetFreeSlot(UpgradeType upgradeType)
        {
            UpgradeSlot result = null;

            result = UpgradeSlots.Find(n => (n.Type == upgradeType && n.IsEmpty));
            return(result);
        }
Exemplo n.º 6
0
        public void AddSlot(UpgradeType slotType)
        {
            UpgradeSlot slot = new UpgradeSlot(slotType);

            slot.OnPreInstallUpgrade       += HostShip.CallOnPreInstallUpgrade;
            slot.OnRemovePreInstallUpgrade += HostShip.CallOnRemovePreInstallUpgrade;
            AddSlot(slot);
        }
Exemplo n.º 7
0
        public void RemoveSlot(UpgradeType upgradeType, object grantedBy = null)
        {
            UpgradeSlot slot = UpgradeSlots.Find(n => (n.Type == upgradeType) && (n.GrantedBy == grantedBy));

            if (slot != null)
            {
                UpgradeSlots.Remove(slot);
            }
        }
Exemplo n.º 8
0
        public void TryInstallUpgrade(GenericUpgrade upgrade)
        {
            UpgradeSlot freeSlot = GetFreeSlot(upgrade.Type);

            if (freeSlot != null)
            {
                freeSlot.TryInstallUpgrade(upgrade, Host);
            }
            else
            {
                Debug.Log("No free slot: " + upgrade.Type);
            }
        }
Exemplo n.º 9
0
        public void RemoveSlot(UpgradeType upgradeType, object grantedBy = null)
        {
            UpgradeSlot slot = UpgradeSlots.Find(n => (n.Type == upgradeType) && (n.GrantedBy == grantedBy));

            if (slot != null)
            {
                if (slot.InstalledUpgrade != null)
                {
                    if (slot.InstalledUpgrade is EmptyUpgrade)
                    {
                        UpgradeSlot realUpgradeSlot = UpgradeSlots.Find(n => (n.InstalledUpgrade != null) && (n.InstalledUpgrade.UpgradeInfo.Name == slot.InstalledUpgrade.UpgradeInfo.Name) && (!(n.InstalledUpgrade is EmptyUpgrade)));
                        realUpgradeSlot.RemovePreInstallUpgrade();
                    }
                    else
                    {
                        slot.RemovePreInstallUpgrade();
                    }
                }
                UpgradeSlots.Remove(slot);
            }
        }
Exemplo n.º 10
0
        public bool HasEnoughSlotsInShip(GenericShip ship)
        {
            if (Types.Count > 1)
            {
                List <UpgradeSlot> freeSlots = ship.UpgradeBar.GetFreeSlots(Types);

                foreach (var requiredSlotType in Types)
                {
                    UpgradeSlot freeSlotByType = freeSlots.FirstOrDefault(n => n.Type == requiredSlotType);
                    if (freeSlotByType != null)
                    {
                        freeSlots.Remove(freeSlotByType);
                    }
                    else
                    {
                        //No free slots for this upgrade
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 11
0
        public void PreInstallUpgrade(GenericUpgrade upgrade, GenericShip host)
        {
            HostShip         = host;
            InstalledUpgrade = upgrade;
            upgrade.Slot     = this;
            InstalledUpgrade.PreAttachToShip(host);

            if (upgrade.UpgradeInfo.UpgradeTypes.Count > 1)
            {
                List <UpgradeType> extraSlots = new List <UpgradeType>(upgrade.UpgradeInfo.UpgradeTypes);
                extraSlots.Remove(extraSlots.First(n => n == this.Type));

                foreach (UpgradeType upgradeType in extraSlots)
                {
                    // Clone upgrade to fill extra slots
                    UpgradesList.EmptyUpgrade emptyUpgrade = new UpgradesList.EmptyUpgrade();
                    emptyUpgrade.SetUpgradeInfo(upgradeType, upgrade.UpgradeInfo.Name, 0);

                    UpgradeSlot tempSlot = host.UpgradeBar.GetUpgradeSlots().First(n => n.IsEmpty && emptyUpgrade.HasType(n.Type));
                    tempSlot.PreInstallUpgrade(emptyUpgrade, host);
                }
            }

            if (DebugManager.FreeMode)
            {
                if (!host.UpgradeBar.HasFreeUpgradeSlot(new List <UpgradeType>()
                {
                    UpgradeType.Omni
                }))
                {
                    host.UpgradeBar.AddSlot(UpgradeType.Omni);
                }
            }

            OnPreInstallUpgrade?.Invoke(upgrade);
        }
Exemplo n.º 12
0
        public UpgradeCardInfo(
            string name,
            UpgradeType type         = UpgradeType.None,
            List <UpgradeType> types = null,
            int cost         = 0,
            bool isLimited   = false,
            int limited      = 0,
            Type abilityType = null,
            UpgradeCardRestriction restriction   = null,
            UpgradeCardRestrictions restrictions = null,
            int charges                    = 0,
            bool regensCharges             = false,
            bool cannotBeRecharged         = false,
            int seImageNumber              = 0,
            SpecialWeaponInfo weaponInfo   = null,
            ShipArcInfo addArc             = null,
            ActionInfo addAction           = null,
            LinkedActionInfo addActionLink = null,
            UpgradeSlot addSlot            = null,
            List <UpgradeSlot> addSlots    = null,
            bool feIsLimitedPerShip        = false,
            UpgradeType forbidSlot         = UpgradeType.None,
            List <UpgradeType> forbidSlots = null,
            Dictionary <UpgradeType, int> costReductionByType = null,
            int addShields = 0,
            int addHull    = 0,
            int addForce   = 0
            )
        {
            Name              = name;
            Cost              = cost;
            Charges           = charges;
            RegensCharges     = regensCharges;
            CannotBeRecharged = cannotBeRecharged;
            SEImageNumber     = seImageNumber;
            WeaponInfo        = weaponInfo;
            AddAction         = addAction;
            AddActionLink     = addActionLink;

            AbilityTypes = new List <Type>();
            if (abilityType != null)
            {
                AbilityTypes.Add(abilityType);
            }

            Limited = (isLimited) ? 1 : 0;
            if (limited != 0)
            {
                Limited = limited;
            }

            FeIsLimitedPerShip = feIsLimitedPerShip;

            UpgradeTypes = new List <UpgradeType>();
            if (type != UpgradeType.None)
            {
                UpgradeTypes.Add(type);
            }
            if (types != null)
            {
                UpgradeTypes.AddRange(types);
            }

            Restrictions = new UpgradeCardRestrictions();
            if (restriction != null)
            {
                Restrictions = new UpgradeCardRestrictions(restriction);
            }
            if (restrictions != null)
            {
                Restrictions = restrictions;
            }

            AddedSlots = new List <UpgradeSlot>();
            if (addSlot != null)
            {
                AddedSlots.Add(addSlot);
            }
            if (addSlots != null)
            {
                AddedSlots.AddRange(addSlots);
            }

            ForbiddenSlots = new List <UpgradeType>();
            if (forbidSlot != UpgradeType.None)
            {
                ForbiddenSlots.Add(forbidSlot);
            }
            if (forbidSlots != null)
            {
                ForbiddenSlots.AddRange(forbidSlots);
            }

            CostReductionByType = new Dictionary <UpgradeType, int>();
            if (costReductionByType != null)
            {
                CostReductionByType = costReductionByType;
            }

            AddHull    = addHull;
            AddShields = addShields;
            AddForce   = addForce;

            AddArc = addArc;
        }
Exemplo n.º 13
0
 public void AddSlot(UpgradeSlot slot)
 {
     slot.Counter = UpgradeSlots.Count(n => n.Type == slot.Type) + 1;
     UpgradeSlots.Add(slot);
 }