Esempio n. 1
0
        private void msktxtItemMaxNumber_Validating(object sender, CancelEventArgs e)
        {
            //dwp чтобы не вылетало при некооректном вводе
            int n;

            try {
                n = int.Parse(msktxtItemMaxNumber.Text);
            }
            catch {
                msktxtItemMaxNumber.Text = "0";
                n = 0;
            }
            if (n < 0 || n > 99)
            {
                toolTip1.Show("Number can only be between 0 and 99", msktxtItemMaxNumber, 2000);
                msktxtItemChance.Text = "0";
            }
            TemplateMapObject moSelectedItem = GetSelectedItem();

            if (moSelectedItem != null)
            {
                if (ItemIsChecked(moSelectedItem))
                {
                    moSelectedItem.MaxNumber = msktxtItemMaxNumber.Text;
                }
                else
                {
                    if (msktxtItemMaxNumber.Text != "" || msktxtItemMaxNumber.Text != "0")
                    {
                        msktxtItemMaxNumber.Text = "0";
                        toolTip1.Show("When the selected item is not checked max number can only be 0", msktxtItemMaxNumber, 2000);
                    }
                }
            }
        }
Esempio n. 2
0
        private void msktxtItemChance_Validating(object sender, CancelEventArgs e)
        {
            //dwp чтобы не вылетало при некооректном вводе
            float fChance;

            try { fChance = float.Parse(msktxtItemChance.Text); }
            catch { fChance = 0; }
            if (fChance > 1.0)
            {
                toolTip1.Show("Chance can only be between 0.0 and 1.0", msktxtItemChance, 2000);
                msktxtItemChance.Text = "1.0";
            }
            TemplateMapObject moSelectedItem = GetSelectedItem();

            if (moSelectedItem != null)
            {
                if (ItemIsChecked(moSelectedItem))
                {
                    moSelectedItem.Chance = msktxtItemChance.Text;
                }
                else
                {
                    if (msktxtItemChance.Text != "0.0")
                    {
                        msktxtItemChance.Text = "0.0";
                        toolTip1.Show("When the selected item is not checked chance can only be 0.0", msktxtItemChance, 2000);
                    }
                }
                UpdateStatistics();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// sets the value of object value
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void msktxtItemValue_Validated(object sender, EventArgs e)
        {
            TemplateMapObject moSelectedItem = GetSelectedItem();

            if (moSelectedItem != null)
            {
                moSelectedItem.Value = msktxtItemValue.Text;
                UpdateStatistics();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// update an object data based on gui data
        /// </summary>
        /// <param name="tmoObjectUpdateData">relevant object data</param>
        public void UpdateObjectWithZeroChance(TemplateMapObject tmoObjectUpdateData)
        {
            XmlNode xndObjectToUpdate = this.GetObjectsData().SelectSingleNode("//Object[@Name='" + tmoObjectUpdateData.Name + "']");

            if (xndObjectToUpdate != null)
            {
                ((XmlElement)xndObjectToUpdate).SetAttribute(eObjectData.Chance.ToString(), "0.0");
                ((XmlElement)xndObjectToUpdate).SetAttribute(eObjectData.Value.ToString(), tmoObjectUpdateData.Value.ToString());
                ((XmlElement)xndObjectToUpdate).SetAttribute(eObjectData.MaxNumber.ToString(), "");
            }
        }
Esempio n. 5
0
 /// <summary>
 /// checks is the a member of one of the lists is checked or not
 /// </summary>
 /// <param name="moSelectedItem"></param>
 /// <returns></returns>
 private bool ItemIsChecked(TemplateMapObject moSelectedItem)
 {
     if (chklstArtifacts.CheckedItems.IndexOf(moSelectedItem) >= 0)
     {
         return(true);
     }
     if (chklstBattleObjects.CheckedItems.IndexOf(moSelectedItem) >= 0)
     {
         return(true);
     }
     if (chklstEnhancingObjects.CheckedItems.IndexOf(moSelectedItem) >= 0)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 6
0
        /// <summary>
        /// finds objects appear chance statistics
        /// </summary>
        private void UpdateStatistics()
        {
            //go over all lists and count objects which are selected and their chance is greater then 0.0
            //also total the chance for those objects
            int    iObjectCount       = 0;
            double dTotalObjectChance = 0;


            for (int i = 0; i < chklstArtifacts.CheckedItems.Count; i++)
            {
                TemplateMapObject tmoItem = (TemplateMapObject)chklstArtifacts.CheckedItems[i];
                if (tmoItem.Chance != "0.0" && tmoItem.Chance != null)
                {
                    iObjectCount++;
                    dTotalObjectChance += double.Parse(tmoItem.Chance, System.Globalization.CultureInfo.InvariantCulture);
                }
            }

            for (int i = 0; i < chklstBattleObjects.CheckedItems.Count; i++)
            {
                TemplateMapObject tmoItem = (TemplateMapObject)chklstBattleObjects.CheckedItems[i];
                if (tmoItem.Chance != "0.0" && tmoItem.Chance != null)
                {
                    iObjectCount++;
                    dTotalObjectChance += double.Parse(tmoItem.Chance, System.Globalization.CultureInfo.InvariantCulture);
                }
            }

            for (int i = 0; i < chklstEnhancingObjects.CheckedItems.Count; i++)
            {
                TemplateMapObject tmoItem = (TemplateMapObject)chklstEnhancingObjects.CheckedItems[i];
                if (tmoItem.Chance != "0.0" && tmoItem.Chance != null)
                {
                    iObjectCount++;
                    dTotalObjectChance += double.Parse(tmoItem.Chance, System.Globalization.CultureInfo.InvariantCulture);
                }
            }

            lblObjectsCount.Text = iObjectCount.ToString();

            double d1DevidedObjectCount = (double)1 / iObjectCount;

            lbl1DevidedObjectCount.Text = d1DevidedObjectCount.ToString("P", System.Globalization.CultureInfo.InvariantCulture);

            lbl1DevidedTimesSetChance.Text = (d1DevidedObjectCount * double.Parse(msktxtChance.Text, System.Globalization.CultureInfo.InvariantCulture)).ToString("P", System.Globalization.CultureInfo.InvariantCulture);



            TemplateMapObject tmoSelectedItem = GetSelectedItem();

            if (tmoSelectedItem != null)
            {
                if (tmoSelectedItem.Name != "Select All")
                {
                    double dObjectChace = double.Parse(tmoSelectedItem.Chance, System.Globalization.CultureInfo.InvariantCulture) / dTotalObjectChance;
                    lblObjectSetChance.Text = dObjectChace.ToString("P", System.Globalization.CultureInfo.InvariantCulture);
                    lblZoneChance.Text      = (double.Parse(msktxtChance.Text, System.Globalization.CultureInfo.InvariantCulture) * dObjectChace).ToString("P", System.Globalization.CultureInfo.InvariantCulture);
                }
                else
                {
                    lblObjectSetChance.Text = "None Selected";
                    lblZoneChance.Text      = "None Selected";
                }
            }
            else
            {
                lblObjectSetChance.Text = "None Selected";
                lblZoneChance.Text      = "None Selected";
            }
        }
Esempio n. 7
0
        /// <summary>
        /// fills a chklstbox with objects
        /// </summary>
        /// <param name="xObjects"></param>
        public void Fillcbo(XmlElement xObjects)
        {
            foreach (XmlNode xndObjectTypes in xObjects.ChildNodes)
            {
                if (xndObjectTypes.Name == "BattleObjects")
                {
                    foreach (XmlNode xndObjects in xndObjectTypes.ChildNodes)
                    {
                        TemplateMapObject moItem = new TemplateMapObject(xndObjects.Attributes["Name"].Value);
                        if (xndObjects.Attributes.GetNamedItem("Value") != null)
                        {
                            moItem.Value = xndObjects.Attributes["Value"].Value;
                        }
                        else
                        {
                            moItem.Value = "1000";
                        }
                        if (xndObjects.Attributes.GetNamedItem("Chance") != null)
                        {
                            moItem.Chance = xndObjects.Attributes["Chance"].Value;
                        }
                        else
                        {
                            moItem.Chance = "0.0";
                        }
                        if (xndObjects.Attributes.GetNamedItem("MaxNumber") != null)
                        {
                            moItem.MaxNumber = xndObjects.Attributes["MaxNumber"].Value;
                        }
                        else
                        {
                            moItem.MaxNumber = "0";
                        }

                        chklstBattleObjects.Items.Add(moItem, Convert.ToDouble(moItem.Chance, System.Globalization.CultureInfo.InvariantCulture) > 0.0);
                    }
                }
                else
                {
                    if (xndObjectTypes.Name == "Enhancers")
                    {
                        foreach (XmlNode xndObjects in xndObjectTypes.ChildNodes)
                        {
                            //chklstObjects.ThreeDCheckBoxes
                            //chklstObjects.
                            TemplateMapObject moItem = new TemplateMapObject(xndObjects.Attributes["Name"].Value);
                            if (xndObjects.Attributes.GetNamedItem("Value") != null)
                            {
                                moItem.Value = xndObjects.Attributes["Value"].Value;
                            }
                            else
                            {
                                moItem.Value = "1000";
                            }
                            if (xndObjects.Attributes.GetNamedItem("Chance") != null)
                            {
                                moItem.Chance = xndObjects.Attributes["Chance"].Value;
                            }
                            else
                            {
                                moItem.Chance = "1.0";
                            }
                            if (xndObjects.Attributes.GetNamedItem("MaxNumber") != null)
                            {
                                moItem.MaxNumber = xndObjects.Attributes["MaxNumber"].Value;
                            }
                            else
                            {
                                moItem.MaxNumber = "0";
                            }

                            chklstEnhancingObjects.Items.Add(moItem, Convert.ToDouble(moItem.Chance, System.Globalization.CultureInfo.InvariantCulture) > 0.0);
                            //  cboObjectList.Items.Add(xndObjects.Attributes["Name"].Value);
                        }
                    }
                    else
                    {
                        foreach (XmlNode xndObjects in xndObjectTypes.ChildNodes)
                        {
                            //chklstObjects.ThreeDCheckBoxes
                            //chklstObjects.
                            TemplateMapObject moItem = new TemplateMapObject(xndObjects.Attributes["Name"].Value);
                            if (xndObjects.Attributes.GetNamedItem("Value") != null)
                            {
                                moItem.Value = xndObjects.Attributes["Value"].Value;
                            }
                            else
                            {
                                moItem.Value = "1000";
                            }
                            if (xndObjects.Attributes.GetNamedItem("Chance") != null)
                            {
                                moItem.Chance = xndObjects.Attributes["Chance"].Value;
                            }
                            else
                            {
                                moItem.Chance = "1.0";
                            }
                            if (xndObjects.Attributes.GetNamedItem("MaxNumber") != null)
                            {
                                moItem.MaxNumber = xndObjects.Attributes["MaxNumber"].Value;
                            }
                            else
                            {
                                moItem.MaxNumber = "0";
                            }

                            chklstArtifacts.Items.Add(moItem, Convert.ToDouble(moItem.Chance, System.Globalization.CultureInfo.InvariantCulture) > 0.0);
                            //  cboObjectList.Items.Add(xndObjects.Attributes["Name"].Value);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// updates all data from gui to template
        /// </summary>
        public void UpdateTemplate()
        {
            //used to read object data and update gui changes
            ObjectsReader obrdUpdater = new ObjectsReader();

            //Program.frmTemplateEdit.thTemplate.GetObjectsSet (

            //this updates all gui changes to all objects
            #region iterates through all chklists and update all changes

            for (int i = 1; i < chklstBattleObjects.Items.Count; i++)
            {
                TemplateMapObject tmoObject = (TemplateMapObject)chklstBattleObjects.Items[i];

                if (this.chklstBattleObjects.CheckedItems.Contains(tmoObject))
                {
                    obrdUpdater.UpdateObject(tmoObject);
                }
                else
                {
                    obrdUpdater.UpdateObjectWithZeroChance(tmoObject);
                }
            }

            for (int i = 1; i < chklstEnhancingObjects.Items.Count; i++)
            {
                TemplateMapObject tmoObject = (TemplateMapObject)chklstEnhancingObjects.Items[i];

                if (this.chklstEnhancingObjects.CheckedItems.Contains(tmoObject))
                {
                    obrdUpdater.UpdateObject(tmoObject);
                }
                else
                {
                    obrdUpdater.UpdateObjectWithZeroChance(tmoObject);
                }
            }

            for (int i = 1; i < chklstArtifacts.Items.Count; i++)
            {
                TemplateMapObject tmoObject = (TemplateMapObject)chklstArtifacts.Items[i];

                if (this.chklstArtifacts.CheckedItems.Contains(tmoObject))
                {
                    obrdUpdater.UpdateObject(tmoObject);
                }
                else
                {
                    obrdUpdater.UpdateObjectWithZeroChance(tmoObject);
                }
            }

            #endregion

            //update zones general appear chance
            Program.frmTemplateEdit.thTemplate.UpdateZoneAttribute(iZoneIndex, "ObjectsSet" + iObjectSet.ToString(), msktxtChance.Text, "Appear_Chance");
            Program.frmTemplateEdit.thTemplate.UpdateZoneAttribute(iZoneIndex, "ObjectsSet" + iObjectSet.ToString(), msktxtDwellNumber.Text, "Dwelling_Number");


            //this will insert the new Objects node inside right zone and object set
            Program.frmTemplateEdit.thTemplate.UpdateObjectSetProperty(obrdUpdater.GetObjectsData(), iZoneIndex, iObjectSet);
        }