Exemplo n.º 1
0
        public IUpgrade CreateUpgrade(UpgradeJson upgrade)
        {
            System.Diagnostics.Debug.WriteLine(upgrade.Name);
            var upgradeSlotFactory       = new UpgradeSlotFactory(this);
            UpgradeModifierParser parser = new UpgradeModifierParser(upgradeSlotFactory, GetUpgradeType, GetUpgrade, GetAction);

            return(new Upgrade(upgrade.Name, upgrade.Cost,
                               upgrade.Description, upgrade.Unique, upgrade.Limited,
                               GetFaction(upgrade.Faction),
                               GetUpgradeType(upgrade.Type),
                               new Structures.UpgradeModifierPackage(
                                   parser.ParseAddedActions(upgrade.AddedActions?.ToArray() ?? new string[0]),
                                   parser.ParseRemovedActions(upgrade.RemovedActions?.ToArray() ?? new string[0]),
                                   parser.ParseAddedUpgrades(upgrade.AddedUpgrades?.ToArray() ?? new AddedUpgradeJson[0]),
                                   parser.ParseRemovedUpgrades(upgrade.RemovedUpgrades?.ToArray() ?? new string[0]),
                                   parser.ParseChangedStats(upgrade.StatChanges?.ToArray() ?? new StatChangeJson[0]),
                                   parser.ParseSelectableUpgrades(upgrade.ChooseUpgrade?.ToArray() ?? new ChooseUpgradeJson[0])),
                               UpgradeRestrictionParser.ParseRestrictionsForUpgrade(GetUpgradeType, GetAction, upgrade)));
        }
Exemplo n.º 2
0
        public static IReadOnlyList <IXWingSpecification <IPilot> > ParseRestrictionsForUpgrade(
            Func <string, IUpgradeType> getUpgradeType,
            Func <string, IAction> getAction,
            UpgradeJson upgradeJson)
        {
            var specList    = new List <IXWingSpecification <IPilot> >();
            var upgradeType = getUpgradeType(upgradeJson.Type);

            foreach (var restriction in upgradeJson.Restrictions)
            {
                switch (restriction.Attribute)
                {
                case "ShipName":
                {
                    if (restriction.Operand == "Contains")
                    {
                        specList.Add(new ContainsShipNameSpecification(restriction.Value));
                    }
                    else if (restriction.Operand == "Contains Double")
                    {
                        specList.Add(new ContainsShipNameDoubleSpecification(restriction.Value));
                    }
                    else
                    {
                        throw new NotImplementedException($"Found a restriction not implemented\n {restriction.Operand}");
                    }
                    break;
                }

                case "ShipSize":
                {
                    if (restriction.Operand == "Equals")
                    {
                        specList.Add(new EqualsShipSizeSpecification(restriction.Value));
                    }
                    else if (restriction.Operand == "Not Contains")
                    {
                        specList.Add(new NotContainsShipSizeSpecification(new ShipSize(restriction.Value)));
                    }
                    else
                    {
                        throw new NotImplementedException($"Found a restriction not implemented\n {restriction.Operand}");
                    }
                    break;
                }

                case "PilotSkill":
                {
                    if (restriction.Operand == ">")
                    {
                        specList.Add(new PilotSkillGreaterThanSpecification(int.Parse(restriction.Value)));
                    }
                    else
                    {
                        throw new NotImplementedException($"Found a restriction not implemented\n {restriction.Operand}");
                    }
                    break;
                }

                case "UpgradeSlots":
                {
                    if (restriction.Operand == "Not Contains")
                    {
                        specList.Add(new NotContainsUpgradeSlotsSpecification(getUpgradeType(restriction.Value)));
                    }
                    else if (restriction.Operand == "Contains")
                    {
                        specList.Add(new ContainsUpgradeSlotsSpecification(getUpgradeType(restriction.Value)));
                    }
                    else
                    {
                        throw new NotImplementedException($"Found a restriction not implemented\n {restriction.Operand}");
                    }
                    break;
                }

                case "SlotsRequired":
                {
                    if (restriction.Operand == "Count")
                    {
                        specList.Add(new PilotHasRequiredUpgradeSlotsSpecification(upgradeType, int.Parse(restriction.Value)));
                    }
                    else
                    {
                        throw new NotImplementedException($"Found a restriction not implemented\n {restriction.Operand}");
                    }
                    break;
                }

                case "Actions":
                {
                    if (restriction.Operand == "Contains")
                    {
                        specList.Add(new ContainsActionSpecification(getAction(restriction.Value)));
                    }
                    else
                    {
                        throw new NotImplementedException($"Found a restriction not implemented\n {restriction.Operand}");
                    }
                    break;
                }

                default:
                {
                    throw new NotImplementedException($"Found a restriction not implemented\n {restriction.Attribute}");
                }
                }
            }
            return(specList);
        }