Exemplo n.º 1
0
 public CoreMod(HarmonyInstance harmonyInstance, string directory, string settings, string name) : base(
         harmonyInstance, directory, settings, name, new List <IModFeature <IModFeatureSettings> >())
 {
     MechAppearanceData =
         MechModel.ProcessAvailabilityFile(ModHelpers.ModResourceFilePath(this.ModSettings.MechAppearanceFile));
     CoreModSingleton = this;
 }
Exemplo n.º 2
0
        public static MechModel GenerateMechModel(MechClasses mechClass, string modelName, string variantName,
                                                  string weightIncrement, Factions faction)
        {
            MechModel mechModel = null;

            switch (mechClass)
            {
            case MechClasses.LIGHT:
                mechModel = new LightMech(modelName, variantName, faction,
                                          (LightMechWeightIncrements)System.Enum.Parse(typeof(LightMechWeightIncrements), weightIncrement));
                break;

            case MechClasses.MEDIUM:
                mechModel = new MediumMech(modelName, variantName, faction,
                                           (MediumMechWeightIncrements)System.Enum.Parse(typeof(MediumMechWeightIncrements), weightIncrement));
                break;

            case MechClasses.HEAVY:
                mechModel = new HeavyMech(modelName, variantName, faction,
                                          (HeavyMechWeightIncrements)System.Enum.Parse(typeof(HeavyMechWeightIncrements), weightIncrement));
                break;

            case MechClasses.ASSAULT:
                mechModel = new AssaultMech(modelName, variantName, faction,
                                            (AssaultMechWeightIncrements)System.Enum.Parse(typeof(AssaultMechWeightIncrements), weightIncrement));
                break;
            }

            return(mechModel);
        }
Exemplo n.º 3
0
        private void HandleAddMechResults(AddMechResult result, MechModel mechForAddition)
        {
            switch (result)
            {
            case AddMechResult.CHASSIS_AND_VARIANT_EXIST:
                this.ResponseMessage.Text = String.Format("{0} - {1} already in inventory",
                                                          mechForAddition.MechModelName, mechForAddition.ModelVariantName);
                this.ResponseMessage.ForeColor = Color.Red;
                break;

            case AddMechResult.SUCCESSFULLY_ADDED_NEW_CHASSIS_AND_VARIANT:
                this.ResponseMessage.Text = String.Format("Successfully added {0} - {1} to inventory!",
                                                          mechForAddition.MechModelName, mechForAddition.ModelVariantName);
                UpdateExistingMechsDropdown(mechForAddition);
                this.ResponseMessage.ForeColor = Color.Green;
                break;

            case AddMechResult.SUCCESSFULLY_ADDED_NEW_VARIANT:
                this.ResponseMessage.Text = String.Format("Successfully added {0} variant to {1}",
                                                          mechForAddition.ModelVariantName, mechForAddition.MechModelName);
                this.ResponseMessage.ForeColor = Color.Green;
                break;
            }
            this.ResponseMessage.Visible = true;
        }
Exemplo n.º 4
0
        private void AddMechButton_Click(object sender, EventArgs e)
        {
            if (ValidateForm())
            {
                string mechModel;
                if (this.ExistingMechs.SelectedIndex == 0)
                {
                    mechModel = this.NewChassisName.Text;
                }
                else
                {
                    mechModel = ((DropDownItem)this.ExistingMechs.Items[this.ExistingMechs.SelectedIndex]).DisplayValue;
                }
                string   mechVariant = this.VariantName.Text;
                Factions faction     = (Factions)System.Enum.Parse(typeof(Factions),
                                                                   ((DropDownItem)this.FactionSelector.Items[this.FactionSelector.SelectedIndex]).Value);
                string      weightIncrement = ((DropDownItem)this.WeightIncrement.Items[this.WeightIncrement.SelectedIndex]).Value;
                MechClasses mechClass       = (MechClasses)System.Enum.Parse(typeof(MechClasses),
                                                                             ((DropDownItem)this.WeightClassSelector.Items[this.WeightClassSelector.SelectedIndex]).Value);

                MechModel mechForAddition = MechModelMaker.GenerateMechModel(mechClass, mechModel, mechVariant,
                                                                             weightIncrement, faction);

                AddMechResult result = MChooserXMLWriter.AddMechToFile(mechForAddition);

                HandleAddMechResults(result, mechForAddition);
            }
            else
            {
                this.ResponseMessage.Text      = "Please fill out all relevent data for new mech or variant";
                this.ResponseMessage.ForeColor = Color.Red;
                this.ResponseMessage.Visible   = true;
            }
        }
        public static AddMechResult AddMechToFile(MechModel mech)
        {
            AddMechResult result   = AddMechResult.CHASSIS_AND_VARIANT_EXIST;
            FileInfo      fileInfo = new FileInfo(Constants.StaticValues.OwnedMechsFile);
            XDocument     doc      = XDocument.Load(fileInfo.FullName);
            XElement      model    = (from el in doc.Root.Elements(mech.MechClass.ToString().ToLower())
                                      .Elements(StaticValues.XMLMechTag)
                                      where (string)el.Attribute(StaticValues.XMLModelNameTag) == mech.MechModelName
                                      select el)
                                     .FirstOrDefault();

            if (CheckEntryExists(model, mech) == false)
            {
                if (model == null)
                {
                    XElement weightClass = doc.Root.Element(mech.MechClass.ToString().ToLower());

                    weightClass.Add(
                        new XElement(StaticValues.XMLMechTag, new object[] {
                        new XAttribute(StaticValues.XMLMechfactionTag, mech.MechFaction),
                        new XAttribute(StaticValues.XMLWeightIncrementTag, mech.GetMechWeight()),
                        new XAttribute(StaticValues.XMLModelNameTag, mech.MechModelName),
                        new XElement(StaticValues.XMLModelVariantTag, mech.ModelVariantName)
                    }));
                    result = AddMechResult.SUCCESSFULLY_ADDED_NEW_CHASSIS_AND_VARIANT;
                }
                else
                {
                    model.Add(
                        new XElement(StaticValues.XMLModelVariantTag, mech.ModelVariantName));
                    result = AddMechResult.SUCCESSFULLY_ADDED_NEW_VARIANT;
                }

                doc.Save(fileInfo.FullName);
            }
            else
            {
                result = AddMechResult.CHASSIS_AND_VARIANT_EXIST;
            }

            return(result);
        }
Exemplo n.º 6
0
        private void ExistingMechs_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = this.ExistingMechs.SelectedIndex;

            if (index == 0)
            {
                this.NewChassisLabel.Visible = true;
                this.NewChassisName.Visible  = true;
                this.FactionSelector.Enabled = true;

                UpdateWeightClassDropdown(MechClasses.LIGHT);
                this.WeightClassSelector.Enabled = true;
                UpdateWeightIncrement(LightMechWeightIncrements.TWENTY.ToString());
                this.WeightIncrement.Enabled = true;
            }
            else
            {
                this.NewChassisLabel.Visible = false;
                this.NewChassisName.Visible  = false;

                DropDownItem item  = (DropDownItem)ExistingMechs.Items[index];
                MechModel    model = XMLRetriever.PerformChassisLookup(item.DisplayValue, item.Value);

                if (model.MechFaction == Factions.INNER_SPHERE)
                {
                    this.FactionSelector.SelectedIndex = 0;
                    this.FactionSelector.Enabled       = false;
                }
                else
                {
                    this.FactionSelector.SelectedIndex = 1;
                    this.FactionSelector.Enabled       = false;
                }

                UpdateWeightClassDropdown(model.MechClass);
                this.WeightClassSelector.Enabled = false;
                UpdateWeightIncrement(model.GetMechWeight());
                this.WeightIncrement.Enabled = false;
            }
        }
 private static bool CheckEntryExists(XElement model, MechModel mech)
 {
     if (model == null)
     {
         return(false);
     }
     else
     {
         XElement variant = (from el in model.Elements(StaticValues.XMLModelVariantTag)
                             where (string)el.Value == mech.ModelVariantName
                             select el)
                            .FirstOrDefault();
         if (variant == null)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }
Exemplo n.º 8
0
        private static List <MechModel> ConvertXElementsToMechModels(IEnumerable <XElement> xelements,
                                                                     MechClasses mechClass, Factions[] selectedFactions)
        {
            List <MechModel> mechs = new List <MechModel>();

            foreach (XElement xel in xelements)
            {
                Factions faction = (Factions)System.Enum.Parse(typeof(Factions), (string)xel.Attribute(StaticValues.XMLMechfactionTag));
                if (selectedFactions.Contains(faction))
                {
                    string modelName = (string)xel.Attribute(StaticValues.XMLModelNameTag);
                    string weight    = (string)xel.Attribute(StaticValues.XMLWeightIncrementTag);

                    foreach (XElement subXel in xel.Elements())
                    {
                        string    variant = subXel.Value;
                        MechModel model   = GenerateMechModel(mechClass, modelName, variant, weight, faction);
                        mechs.Add(model);
                    }
                }
            }
            return(mechs);
        }
 // Start is called before the first frame update
 void Start()
 {
     rewiredPlayer = ReInput.players.GetPlayer(PlayerNum);
     mechModel     = GetComponent <MechModel>();
 }
Exemplo n.º 10
0
        private void ChooseMechButton_Click(object sender, EventArgs e)
        {
            if (ValidateFactionCheckboxes() && ValidateWeightClassCheckboxes())
            {
                StrongRandom       rand          = new StrongRandom();
                List <MechClasses> chosenClasses = new List <MechClasses>();
                if (this.LightCheckbox.Checked)
                {
                    chosenClasses.Add(MechClasses.LIGHT);
                }
                if (this.MediumCheckbox.Checked)
                {
                    chosenClasses.Add(MechClasses.MEDIUM);
                }
                if (this.HeavyCheckbox.Checked)
                {
                    chosenClasses.Add(MechClasses.HEAVY);
                }
                if (this.AssaultCheckbox.Checked)
                {
                    chosenClasses.Add(MechClasses.ASSAULT);
                }

                List <Factions> chosenFactions = new List <Factions>();
                if (this.ClanCheckbox.Checked)
                {
                    chosenFactions.Add(Factions.CLAN);
                }
                if (this.InnerSphereCheckbox.Checked)
                {
                    chosenFactions.Add(Factions.INNER_SPHERE);
                }

                List <MechModel> choosableModels = XMLRetriever.GetMechModels(chosenClasses.ToArray(), chosenFactions.ToArray());

                if (choosableModels.Count > 0)
                {
                    int  mechSelectAttempts       = 0;
                    bool successfullySelectedMech = false;
                    while (!successfullySelectedMech && mechSelectAttempts < NoRepeatsFailoverLimit)
                    {
                        int       randomMechIndex = rand.Next(choosableModels.Count);
                        MechModel chosenMech      = choosableModels[randomMechIndex];

                        if (!AlreadySelectedMechs.Contains(chosenMech))
                        {
                            this.ChassisName.Text     = chosenMech.MechModelName;
                            this.VariantName.Text     = chosenMech.ModelVariantName;
                            this.NoMechsError.Visible = false;
                            AlreadySelectedMechs.Add(chosenMech);
                            successfullySelectedMech = true;
                        }
                        else
                        {
                            mechSelectAttempts++;
                            //Simple cleanout: if reached no repeat failover limit minus 1,
                            //assume already selected mech list should be emptied so that last
                            //attempt in while loop *should* succeed if any mech matches criteria
                            if (mechSelectAttempts == (NoRepeatsFailoverLimit - 1))
                            {
                                AlreadySelectedMechs.Clear();
                            }
                        }
                    }
                }
                else
                {
                    this.ChassisName.Text     = "";
                    this.VariantName.Text     = "";
                    this.NoMechsError.Visible = true;
                }
            }
        }
Exemplo n.º 11
0
 private void UpdateExistingMechsDropdown(MechModel addedMech)
 {
     this.ExistingMechs.Items.Add(new DropDownItem(addedMech.MechModelName, addedMech.MechClass.ToString()));
 }