//---------------------------------------------------------------------------

        // Speichere Wichtungsdaten unter den Dateinamen in FileName
        public bool Save(CXml pXml = null)
        {
            // Speichern
            bool iReturn = false;
            CXml pBase   = pXml;

            try
            {
                // Falls NULL, erstelle neues File, ansonsten wird es in eine bereits offene XML gespeichert, z.B. Char-MOX
                if (pXml == null)
                {
                    pBase = new CXml();
                    if (pBase == null)
                    {
                        Utils.DebugPrint("CPlayerWeights::Save = 'pBase = new CXml();' failed, got NULL-Pointer.");
                        return(false);
                    }
                    iReturn = pBase.OpenSaveXml(strFileName);
                }
                else
                {
                    iReturn = true;
                }

                if (iReturn)
                {
                    // Weights-Tag öffnen, Class und Name ist ein MUSS => Attribut
                    String att = "name=\"" + strName + "\"";
                    if (pXml == null)
                    {
                        att += " class=\"" + Unit.xml_config.arClasses[iClass].id + "\"";
                    }
                    pBase.OpenTag("weights", "", att);

                    // Die Wichtungen speichern
                    // Nur Werte die ungleich 100 sind speichern
                    for (int i = 0; i < arWeights.Length; i++)
                    {
                        if (arWeights[i].iWeight != 100)
                        {
                            pBase.OpenTag("weight", arWeights[i].iWeight.ToString(),
                                          "attribute=\"" + Unit.xml_config.arAttributes[i].id + "\"");
                            pBase.CloseTag();
                        }
                    }
                    pBase.CloseTag();   // Weights-Tag schliessen
                    if (pXml == null)
                    {
                        pBase.CloseXml();   // wgt-File schliessen
                    }
                    bModified = false;
                }
            }
            catch (Exception e)
            {
                Utils.DebugPrint("CPlayerWeights::Save = %s\niClass=%d", e.Message, iClass);
                iReturn = false;
            }
            return(iReturn);
        }
Beispiel #2
0
        //---------------------------------------------------------------------------

        private void bnExportClick(object sender, EventArgs e)
        {
            IEnumerator itmodel = vtItems.SelectedObjects.GetEnumerator();

            if (itmodel != null && itmodel.MoveNext())
            {
                if (SaveDialog.ShowDialog() == DialogResult.OK)
                {
                    CXml xFile = new CXml();
                    if (xFile.OpenSaveXml(SaveDialog.FileName))
                    {
                        xFile.OpenTag("daoc_items", "", "");
                        do
                        {
                            CItem pItem = ((SItemLink)itmodel.Current).Item;
                            pItem.Save(xFile);
                        }while (itmodel.MoveNext());
                        xFile.CloseTag();
                        xFile.CloseXml();
                    }
                    vtItems.SelectedObjects = null;
                }
            }
        }
        //---------------------------------------------------------------------------

        // Lade Spielerdaten
        public bool Load(CXml pXml = null)
        {
            // Laden
            bool   bReturn = false;
            String strTemp;
            String strAllErrors;
            int    iErrCnt = 0;
            int    iTemp;
            CXml   pBase = pXml;

            try
            {
                // Falls NULL, wird aus einem eigenen File geladen...
                if (pBase == null)
                {
                    pBase = new CXml();
                    if (pBase == null)
                    {
                        Utils.DebugPrint("CPlayerWeights::Load = 'pBase = new CXml();' failed, got NULL-Pointer.");
                        return(false);
                    }
                    String Ext = Path.GetExtension(strFileName);
                    SetAllWeights(100);
                    if (Ext.Equals(".wgt", StringComparison.CurrentCultureIgnoreCase))
                    {
                        strAllErrors = string.Format(_("Datei: %s\n\n").Replace("%s", "{0}"), pBase.FileName);
                        bReturn      = pBase.OpenXml(strFileName);
                        while (bReturn)
                        {
                            if (pBase.isTag("weights"))
                            {
                                int cid = Unit.xml_config.GetClassId(pBase.AttributeValue["class"]);
                                if (cid >= 0)
                                {
                                    SetClass(cid);
                                }
                                else
                                {
                                    SetClass(0);
                                }

                                SetName(pBase.AttributeValue["name"]);
                            }
                            else if (pBase.isTag("weight"))
                            {
                                int aid = Unit.xml_config.GetAttributeId(pBase.AttributeValue["attribute"]);
                                if (aid >= 0)   // aid ist nur gültig, wenn sie in der aktuellen config gefunden wird
                                {
                                    SetWeight(aid, pBase.Content.ToIntDef(0));
                                }
                                else
                                {       // Warnmeldung ausgeben
                                    String strErr;
                                    iErrCnt++;
                                    strErr        = string.Format(_("Attribut '%s' ist nicht mehr gültig.\n").Replace("%s", "{0}"), pBase.AttributeValue["attribute"]);
                                    strAllErrors += strErr;
                                }
                            }
                            bReturn = pBase.NextTag();
                        }
                        pBase.CloseXml();
                        if (iErrCnt > 0)
                        {
                            strAllErrors += _("\nBitte Wichtungen überprüfen.");
                            Utils.MorasInfoMessage(strAllErrors.Replace("\n", Environment.NewLine), _("Unbekannte Wichtung"));
                        }
                    }
                    else
                    {
                        // Warnmeldung ausgeben
                        String strErr;
                        strErr = string.Format(_("Fehler beim Laden einer Wichtungsdatei. Dateiendung '.wgt' erwartet!"));
                        Utils.MorasErrorMessage(strErr, _("Ungültige Dateiendung"));
                    }
                    bModified = false;
                }
                else
                {
                    if (pBase.isTag("weights"))
                    {
                        int cid = Unit.xml_config.GetClassId(pBase.AttributeValue["class"]);
                        if (cid >= 0)
                        {
                            SetClass(cid);
                        }
                        else
                        {
                            SetClass(0);
                        }

                        SetName(pBase.AttributeValue["name"]);
                    }
                    else if (pBase.isTag("weight"))
                    {
                        int aid = Unit.xml_config.GetAttributeId(pBase.AttributeValue["attribute"]);
                        if (aid >= 0)   // aid ist nur gültig, wenn sie in der aktuellen config gefunden wird
                        {
                            SetWeight(aid, pBase.Content.ToIntDef(0));
                        }
                        else
                        {       // Warnmeldung ausgeben
                            String strErr;

                            if (strLoadMessages.Length == 0)
                            {
                                strLoadMessages = string.Format(_("Datei: %s\n\n").Replace("%s", "{0}"), pBase.FileName);
                            }
                            strErr           = string.Format(_("Attribut '%s' ist nicht mehr gültig.\n").Replace("%s", "{0}"), pBase.AttributeValue["attribute"]);
                            strLoadMessages += strErr;
                        }
                    }
                    bModified = false;
                }
            }
            catch
            {
                Utils.DebugPrint("Es ist ein Fehler in CPlayerWeights::Load aufgetreten!");
                bReturn = false;
            }
            return(bReturn);
        }