예제 #1
0
 public static string ValidateDefenceSystem(DefenceSystem defence)
 {
     if (defence.DefenceValue < 0)
     {
         return(FailureReasons.VALUE_NOT_IN_RANGE + "Defence value");
     }
     if (defence.DefMultAgainstWepTypeMap[WeaponType.KINETIC] < 0)
     {
         return(FailureReasons.VALUE_NOT_IN_RANGE + "kinetic multilpier");
     }
     if (defence.DefMultAgainstWepTypeMap[WeaponType.LASER] != 0 && defence.SystemType == DefenceSystemType.POINT_DEFENCE)
     {
         return(FailureReasons.VALUE_NOT_IN_RANGE + "laser multilpier for PD");
     }
     if (defence.DefMultAgainstWepTypeMap[WeaponType.LASER] < 0)
     {
         return(FailureReasons.VALUE_NOT_IN_RANGE + "laser multiplier");
     }
     if (defence.DefMultAgainstWepTypeMap[WeaponType.MISSILE] < 0)
     {
         return(FailureReasons.VALUE_NOT_IN_RANGE + "missile multiplier");
     }
     if (defence.Faction == null)
     {
         return(FailureReasons.VALUE_NOT_IN_RANGE + "Faction");
     }
     if (string.IsNullOrWhiteSpace(defence.Name))
     {
         return(FailureReasons.VALUE_NOT_IN_RANGE + "Name");
     }
     return(OK);
 }
 public DbDefenceSystem(DefenceSystem defenceSystem)
 {
     Name              = defenceSystem.Name;
     Faction           = defenceSystem.Faction;
     DefenceValue      = defenceSystem.DefenceValue;
     SystemType        = defenceSystem.SystemType;
     DefAgainstKinetic = defenceSystem.DefMultAgainstWepTypeMap[WeaponType.KINETIC];
     DefAgainstLaser   = defenceSystem.DefMultAgainstWepTypeMap[WeaponType.LASER];
     DefAgainstMissile = defenceSystem.DefMultAgainstWepTypeMap[WeaponType.MISSILE];
     if (defenceSystem.Id > 0)
     {
         Id = defenceSystem.Id;
     }
     Ships = new List <DbShipTemplate>();
 }
        private static void AddDefenceSystemToTable(DefenceSystem defence, TableLayoutPanel table, bool addModifyButton = false, Dictionary <Button, int> buttonToIdMap = null, EventHandler modifyButtonHandler = null, double shipSize = 1,
                                                    Dictionary <CheckBox, int> checkBoxToIdMap = null)
        {
            RowStyle temp = table.RowStyles[table.RowCount - 1];

            table.RowCount++;
            table.RowStyles.Add(new RowStyle(temp.SizeType, temp.Height));

            int chg = 4;

            table.Controls.Add(new Label()
            {
                Text = defence.Id.ToString()
            }, 0, table.RowCount - 1);
            table.Controls.Add(new Label()
            {
                Text = defence.Name, AutoSize = true
            }, 1, table.RowCount - 1);
            table.Controls.Add(new Label()
            {
                Text = defence.Faction.Name
            }, 2, table.RowCount - 1);
            table.Controls.Add(new Label()
            {
                Text = defence.DefenceValue.ToString()
            }, 3, table.RowCount - 1);
            if (!addModifyButton)
            {
                table.Controls.Add(new Label()
                {
                    Text = (defence.DefenceValue * shipSize).ToString()
                }, chg, table.RowCount - 1);
                chg++;
            }
            table.Controls.Add(new Label()
            {
                Text = defence.SystemType.GetDefenceSystemTypeName()
            }, chg, table.RowCount - 1);
            table.Controls.Add(new Label()
            {
                Text = defence.DefMultAgainstWepTypeMap[WeaponType.KINETIC].ToString()
            }, chg + 1, table.RowCount - 1);
            table.Controls.Add(new Label()
            {
                Text = defence.DefMultAgainstWepTypeMap[WeaponType.LASER].ToString()
            }, chg + 2, table.RowCount - 1);
            table.Controls.Add(new Label()
            {
                Text = defence.DefMultAgainstWepTypeMap[WeaponType.MISSILE].ToString()
            }, chg + 3, table.RowCount - 1);
            if (addModifyButton)
            {
                Button modifyButton = new Button()
                {
                    Text = "Modify this defence", AutoSize = true
                };
                modifyButton.Click += new EventHandler(modifyButtonHandler);
                buttonToIdMap.Add(modifyButton, defence.Id);
                table.Controls.Add(modifyButton, chg + 4, table.RowCount - 1);
            }
            else
            {
                table.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
                CheckBox selectThisDefence = new CheckBox();
                checkBoxToIdMap.Add(selectThisDefence, defence.Id);
                table.Controls.Add(selectThisDefence, chg + 4, table.RowCount - 1);
            }
        }