Exemple #1
0
 internal void CallPlugins(frmCareer frmCareer, CustomActivity parentActivity)
 {
     foreach (var plugin in MyActivePlugins)
     {
         using (var op_plugin = Timekeeper.StartSyncron("load_plugin_GetTabPage_Career_" + plugin.ToString(),
                                                        parentActivity, CustomActivity.OperationType.DependencyOperation, plugin.ToString()))
         {
             var pages = plugin.GetTabPages(frmCareer);
             if (pages == null)
             {
                 continue;
             }
             foreach (TabPage page in pages)
             {
                 if (page != null)
                 {
                     if (!frmCareer.TabCharacterTabs.TabPages.Contains(page))
                     {
                         frmCareer.TabCharacterTabs.TabPages.Add(page);
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
 internal void CallPlugins(ToolStripMenuItem menu, CustomActivity parentActivity)
 {
     foreach (var plugin in MyActivePlugins)
     {
         using (var op_plugin = Timekeeper.StartSyncron("load_plugin_GetMenuItems_" + plugin.ToString(),
                                                        parentActivity, CustomActivity.OperationType.DependencyOperation, plugin.ToString()))
         {
             var menuitems = plugin.GetMenuItems(menu);
             if (menuitems == null)
             {
                 continue;
             }
             foreach (ToolStripMenuItem plugInMenu in menuitems)
             {
                 if (plugInMenu != null)
                 {
                     if (!menu.DropDownItems.Contains(plugInMenu))
                     {
                         menu.DropDownItems.Add(plugInMenu);
                     }
                 }
             }
         }
     }
 }
Exemple #3
0
 internal void LoadPlugins(CustomActivity parentActivity = null)
 {
     try
     {
         using (_ = Timekeeper.StartSyncron("LoadPlugins", parentActivity,
                                            CustomActivity.OperationType.DependencyOperation,
                                            _objMyDirectoryCatalog?.FullPath))
             Initialize();
     }
     catch (System.Security.SecurityException e)
     {
         string msg =
             "Well, something went wrong probably because we are not Admins. Let's just ignore it and move on." +
             Environment.NewLine + Environment.NewLine;
         Log.Warn(e, msg);
     }
     catch (ReflectionTypeLoadException e)
     {
         using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool,
                                                        out StringBuilder sbdMessage))
         {
             sbdMessage.AppendLine("Exception loading plugins: ");
             foreach (Exception exp in e.LoaderExceptions)
             {
                 sbdMessage.AppendLine(exp.Message);
             }
             sbdMessage.AppendLine();
             sbdMessage.Append(e);
             Log.Warn(e, sbdMessage.ToString());
         }
     }
     catch (CompositionException e)
     {
         using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool,
                                                        out StringBuilder sbdMessage))
         {
             sbdMessage.AppendLine("Exception loading plugins: ");
             foreach (CompositionError exp in e.Errors)
             {
                 sbdMessage.AppendLine(exp.Exception.ToString());
             }
             sbdMessage.AppendLine();
             sbdMessage.Append(e);
             Log.Error(e, sbdMessage.ToString());
         }
     }
     catch (ApplicationException)
     {
         throw;
     }
     catch (Exception e)
     {
         string msg = "Exception loading plugins: " + Environment.NewLine;
         msg += Environment.NewLine;
         msg += e.ToString();
         Log.Error(e, msg);
     }
 }
        internal void LoadPlugins(CustomActivity parentActivity)
        {
            try
            {
                using (var op_plugin = Timekeeper.StartSyncron("LoadPlugins", parentActivity,
                                                               CustomActivity.OperationType.DependencyOperation, myDirectoryCatalog?.FullPath))
                {
                    this.Initialize();
                }
            }
            catch (System.Security.SecurityException e)
            {
                string msg =
                    "Well, something went wrong probably because we are not Admins. Let's just ignore it and move on." +
                    Environment.NewLine + Environment.NewLine;
                Console.WriteLine(msg + e.Message);
                System.Diagnostics.Trace.TraceWarning(msg + e.Message);
                return;
            }
            catch (ReflectionTypeLoadException e)
            {
                string msg = "Exception loading plugins: " + Environment.NewLine;
                foreach (var exp in e.LoaderExceptions)
                {
                    msg += exp.Message + Environment.NewLine;
                }

                msg += Environment.NewLine;
                msg += e.ToString();
                Log.Warn(e, msg);
            }
            catch (CompositionException e)
            {
                string msg = "Exception loading plugins: " + Environment.NewLine;

                foreach (var exp in e.Errors)
                {
                    msg += exp.Exception + Environment.NewLine;
                }

                msg += Environment.NewLine;
                msg += e.ToString();
                Log.Error(e, msg);
            }
            catch (ApplicationException e)
            {
                throw;
            }
            catch (Exception e)
            {
                string msg = "Exception loading plugins: " + Environment.NewLine;
                msg += Environment.NewLine;
                msg += e.ToString();
                Log.Error(e, msg);
            }
        }
Exemple #5
0
 public void CustomActivityThrowsError()
 {
     var client = new TargetProcessClient
     {
         ApiSiteInfo = new ApiSiteInfo(TargetProcessRoutes.Route.CustomActivities)
     };
     var customActivity = new CustomActivity
     {
     };
 }
        public override Activity ToSdkObject()
        {
            var activity = new CustomActivity(this.Name, this.Command);

            activity.ResourceLinkedService = this.ResourceLinkedService;
            activity.FolderPath            = this.FolderPath;
            activity.ReferenceObjects      = this.ReferenceObjects;
            this.ExtendedProperties?.ForEach(item => activity.ExtendedProperties.Add(item));
            activity.RetentionTimeInDays = this.RetentionTimeInDays;
            activity.LinkedServiceName   = this.LinkedServiceName;
            activity.Policy = this.Policy;
            SetProperties(activity);
            return(activity);
        }
Exemple #7
0
 internal void CallPlugins(CharacterCreate frmCreate, CustomActivity parentActivity)
 {
     foreach (IPlugin plugin in MyActivePlugins)
     {
         using (_ = Timekeeper.StartSyncron("load_plugin_GetTabPage_Create_" + plugin, parentActivity, CustomActivity.OperationType.DependencyOperation, plugin.ToString()))
         {
             IEnumerable <TabPage> pages = plugin.GetTabPages(frmCreate);
             if (pages == null)
             {
                 continue;
             }
             foreach (TabPage page in pages)
             {
                 if (page != null && !frmCreate.TabCharacterTabs.TabPages.Contains(page))
                 {
                     frmCreate.TabCharacterTabs.TabPages.Add(page);
                 }
             }
         }
     }
 }
            public async Task UserInfoAsync([Remainder] CachedMember?member = null)
            {
                member ??= (CachedMember)Context.User;

                var userRoles = member.Roles.Select(x => x.Value).Where(x => !x.IsDefault)
                                .OrderByDescending(x => x.Position)
                                .Take(10)
                                .Select(x => x.Mention)
                                .ToList();

                var activity = "-";

                if (member.Presence != null && member.Presence.Activities.Count != 0)
                {
                    activity = string.Join("\n", member.Presence.Activities.Select(x => x switch
                    {
                        CustomActivity customActivity => $"{customActivity.Emoji} {customActivity.Text}",
                        RichActivity richActivity => GetText(Localization.BotActivity(richActivity.Type.ToString().ToLower()), richActivity.Name),
                        StreamingActivity streamingActivity => GetText(Localization.BotActivity(streamingActivity.Type.ToString().ToLower()), streamingActivity.Name),
                        SpotifyActivity spotifyActivity => $"{GetText(Localization.BotActivity(spotifyActivity.Type.ToString().ToLower()), spotifyActivity.Name)}\n" +
                        $"{spotifyActivity.Artists.Humanize()} - {spotifyActivity.TrackTitle}",
                        _ => GetText(Localization.BotActivity(x.Type.ToString().ToLower()), x.Name)
                    }));
        public void CreateCustomActivityThrowsError()
        {
            var client = CommonMethods.GetClientByRoute(TargetProcessRoutes.Route.CustomActivities);

            var customActivity = new CustomActivity();
        }
Exemple #10
0
        public async Task <bool> Upload(ucSINnerShare.MyUserState myState = null, CustomActivity parentActivity = null)
        {
            using (var op_uploadChummer = Timekeeper.StartSyncron(
                       "Uploading Chummer", parentActivity,
                       CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
            {
                try
                {
                    using (new CursorWait(true, PluginHandler.MainForm))
                    {
                        HttpOperationResponse <ResultSinnerGetSINById> found = null;
                        using (var op_checkalreadyonlineChummer = Timekeeper.StartSyncron(
                                   "Checking if already online Chummer", op_uploadChummer,
                                   CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
                        {
                            if (myState != null)
                            {
//1 Step
                                myState.CurrentProgress += myState.ProgressSteps;
                                myState.StatusText       = "Checking online version of file...";
                                myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
                            }

                            if (MySINnerFile.DownloadedFromSINnersTime > this.MyCharacter.FileLastWriteTime)
                            {
                                if (myState != null)
                                {
                                    myState.CurrentProgress += 4 * myState.ProgressSteps;
                                    myState.StatusText       = "File already uploaded.";
                                    myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
                                }

                                return(true);
                            }

                            var client = StaticUtils.GetClient();
                            found = await client.GetSINByIdWithHttpMessagesAsync(this.MySINnerFile.Id.GetValueOrDefault());

                            await Backend.Utils.HandleError(found, found.Body);
                        }

                        if (myState != null)
                        {
//2 Step
                            myState.CurrentProgress += myState.ProgressSteps;
                        }
                        using (var op_VisibilityChummer = Timekeeper.StartSyncron(
                                   "Setting Visibility for Chummer", op_uploadChummer,
                                   CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
                        {
                            if (found.Response.StatusCode == System.Net.HttpStatusCode.OK)
                            {
                                if (found.Body.MySINner.LastChange >= this.MyCharacter.FileLastWriteTime)
                                {
                                    if (myState != null)
                                    {
                                        myState.StatusText       = "SINner already uploaded and updated online.";
                                        myState.CurrentProgress += 3 * myState.ProgressSteps;
                                        myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
                                    }

                                    return(true);
                                }

                                if (myState != null)
                                {
                                    myState.StatusText = "SINner needs to be uploaded.";
                                    myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
                                }

                                if (!MySINnerFile.SiNnerMetaData.Visibility.UserRights.Any())
                                {
                                    MySINnerFile.SiNnerMetaData.Visibility.UserRights =
                                        found.Body.MySINner.SiNnerMetaData.Visibility.UserRights;
                                }
                            }
                        }

                        using (var op_PopulatingChummer = Timekeeper.StartSyncron(
                                   "Populating Reflection Tags", op_uploadChummer,
                                   CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
                        {
                            this.MySINnerFile.SiNnerMetaData.Tags = this.PopulateTags();
                        }

                        using (var op_PopulatingChummer = Timekeeper.StartSyncron(
                                   "Preparing Model", op_uploadChummer,
                                   CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
                        {
                            await this.PrepareModel();
                        }

                        if (myState != null)
                        {
//3 Step
                            myState.CurrentProgress += myState.ProgressSteps;
                            myState.StatusText       = "Chummerfile prepared for uploading...";
                            myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
                        }

                        HttpOperationResponse <ResultSinnerPostSIN> res = null;
                        using (var op_PopulatingChummer = Timekeeper.StartSyncron(
                                   "Posting SINner", op_uploadChummer,
                                   CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
                        {
                            res = await ChummerHub.Client.Backend.Utils.PostSINnerAsync(this);

                            await Backend.Utils.HandleError(res, res.Body);
                        }

                        if (myState != null)
                        {
//4 Step
                            myState.CurrentProgress += myState.ProgressSteps;
                            myState.StatusText       = "Chummer Metadata stored in DB...";
                            myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
                        }

                        if (res.Response.IsSuccessStatusCode)
                        {
                            using (var op_PopulatingChummer = Timekeeper.StartSyncron(
                                       "Uploading File", op_uploadChummer,
                                       CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
                            {
                                var uploadres = await ChummerHub.Client.Backend.Utils.UploadChummerFileAsync(this);

                                if (uploadres.Response.IsSuccessStatusCode)
                                {
                                    if (myState != null)
                                    {
//5 Step
                                        myState.CurrentProgress += myState.ProgressSteps;
                                        myState.StatusText       = "Chummer uploaded...";
                                        myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
                                    }

                                    return(true);
                                }

                                if (myState != null)
                                {
//5 Step
                                    myState.CurrentProgress += myState.ProgressSteps;
                                    myState.StatusText       = "Chummer upload failed: " + uploadres.Response.ReasonPhrase;
                                    myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
                                }

                                return(false);
                            }
                        }

                        if (myState != null)
                        {
//5 Step
                            myState.CurrentProgress += myState.ProgressSteps;
                            myState.StatusText       = "Chummer upload of Metadata failed: " + res.Response.ReasonPhrase;
                            myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
                        }

                        return(false);
                    }
                }
                catch (Exception e)
                {
                    op_uploadChummer?.tc?.TrackException(e);
                    await Backend.Utils.HandleError(e);

                    throw;
                }
            }
        }
Exemple #11
0
        private async Task <MyUserState> ShareChummerGroup()
        {
            try
            {
                string hash = string.Empty;
                using (CustomActivity op_shareChummer = Timekeeper.StartSyncron("Share Group", null,
                                                                                CustomActivity.OperationType.DependencyOperation, MySINnerSearchGroup?.Groupname))
                {
                    MyUserState   myState = new MyUserState(this);
                    SinnersClient client  = StaticUtils.GetClient();

                    if (string.IsNullOrEmpty(MySINnerSearchGroup?.Id?.ToString()))
                    {
                        myState.StatusText = "Group Id is unknown or not issued!";
                        ReportProgress(30, myState);
                    }
                    else
                    {
                        myState.StatusText      = "Group Id is " + MySINnerSearchGroup?.Id + ".";
                        myState.CurrentProgress = 30;
                        ReportProgress(myState.CurrentProgress, myState);
                    }

                    //check if char is already online and updated
                    using (_ = Timekeeper.StartSyncron(
                               "check if online", op_shareChummer,
                               CustomActivity.OperationType.DependencyOperation, MySINnerSearchGroup?.Groupname))
                    {
                        ResultGroupGetGroupById checkresult = await client.GetGroupByIdAsync(MySINnerSearchGroup?.Id).ConfigureAwait(false);

                        if (checkresult == null)
                        {
                            throw new ArgumentException("Could not parse result from SINners Webservice!");
                        }
                        if (!checkresult.CallSuccess)
                        {
                            if (checkresult.MyException != null)
                            {
                                throw new ArgumentException(
                                          "Error from SINners Webservice: " + checkresult.ErrorText,
                                          checkresult.MyException.ToString());
                            }
                            throw new ArgumentException("Error from SINners Webservice: " +
                                                        checkresult.ErrorText);
                        }

                        hash = checkresult.MyGroup.MyHash;
                    }


                    myState.StatusText      = "Group is online available.";
                    myState.CurrentProgress = 90;
                    ReportProgress(myState.CurrentProgress, myState);

                    string url = client.BaseUrl + "G";
                    url += "/" + hash;
                    if (Settings.Default.OpenChummerFromSharedLinks)
                    {
                        url += "?open=true";
                    }

                    myState.LinkText = url;
                    ReportProgress(100, myState);
                    RunWorkerCompleted(myState);
                    return(myState);
                }
            }
            catch (Exception exception)
            {
                Log.Warn(exception);
                throw;
            }
        }
Exemple #12
0
        private async Task <MyUserState> ShareSingleChummer()
        {
            if (MyCharacterCache == null)
            {
                throw new ArgumentNullException(nameof(MyCharacterCache));
            }
            string hash = string.Empty;

            try
            {
                using (CustomActivity op_shareChummer = Timekeeper.StartSyncron("Share Chummer", null,
                                                                                CustomActivity.OperationType.DependencyOperation, MyCharacterCache.FilePath))
                {
                    MyUserState       myState  = new MyUserState(this);
                    CharacterExtended ce       = null;
                    SinnersClient     client   = StaticUtils.GetClient();
                    string            sinnerid = string.Empty;
                    Guid SINid = Guid.Empty;

                    try
                    {
                        async Task <CharacterExtended> GetCharacterExtended(CustomActivity parentActivity)
                        {
                            using (_ = Timekeeper.StartSyncron("Loading Chummerfile", parentActivity,
                                                               CustomActivity.OperationType.DependencyOperation, MyCharacterCache.FilePath))
                            {
                                Character c          = PluginHandler.MainForm.OpenCharacters.FirstOrDefault(a => a.FileName == MyCharacterCache.FilePath);
                                bool      blnSuccess = true;
                                if (c == null)
                                {
                                    c = new Character {
                                        FileName = MyCharacterCache.FilePath
                                    };
                                    using (LoadingBar frmLoadingForm = new LoadingBar {
                                        CharacterFile = MyCharacterCache.FilePath
                                    })
                                    {
                                        frmLoadingForm.Reset(36);
                                        frmLoadingForm.Show();
                                        myState.StatusText       = "Loading chummer file...";
                                        myState.CurrentProgress += 10;
                                        ReportProgress(myState.CurrentProgress, myState);
                                        blnSuccess = await c.LoadAsync(frmLoadingForm, false);
                                    }
                                }

                                if (!blnSuccess)
                                {
                                    throw new ArgumentNullException("Could not load Character file " +
                                                                    MyCharacterCache.FilePath +
                                                                    ".");
                                }
                                ce = new CharacterExtended(c, null, MyCharacterCache);
                                if (ce?.MySINnerFile?.Id != null)
                                {
                                    sinnerid = ce.MySINnerFile.Id.ToString();
                                }
                                hash = ce?.MySINnerFile?.MyHash;
                                return(ce);
                            }
                        }

                        if (MyCharacterCache.MyPluginDataDic.TryGetValue("SINnerId", out object sinneridobj))
                        {
                            sinnerid = sinneridobj?.ToString() ?? string.Empty;
                        }
                        else
                        {
                            ce = await GetCharacterExtended(op_shareChummer);

                            sinnerid = ce.MySINnerFile.Id.ToString();
                            hash     = ce?.MySINnerFile?.MyHash ?? string.Empty;
                        }


                        if (string.IsNullOrEmpty(sinnerid) || !Guid.TryParse(sinnerid, out SINid))
                        {
                            myState.StatusText = "SINner Id is unknown or not issued!";
                            ReportProgress(30, myState);
                        }
                        else
                        {
                            myState.StatusText      = "SINner Id is " + SINid + ".";
                            myState.CurrentProgress = 30;
                            ReportProgress(myState.CurrentProgress, myState);
                        }


                        try
                        {
                            //check if char is already online and updated
                            ResultSinnerGetSINById checkresult;
                            using (_ = Timekeeper.StartSyncron(
                                       "check if online", op_shareChummer,
                                       CustomActivity.OperationType.DependencyOperation, MyCharacterCache?.FilePath))
                            {
                                checkresult = await client.GetSINByIdAsync(SINid);

                                if (checkresult == null)
                                {
                                    throw new ArgumentException("Could not parse result from SINners Webservice!");
                                }
                                if (!checkresult.CallSuccess)
                                {
                                    if (checkresult.MyException != null)
                                    {
                                        throw new ArgumentException(
                                                  "Error from SINners Webservice: " + checkresult.ErrorText,
                                                  checkresult.MyException.ToString());
                                    }
                                    throw new ArgumentException("Error from SINners Webservice: " +
                                                                checkresult.ErrorText);
                                }

                                hash = checkresult.MySINner.MyHash;
                            }


                            DateTime lastWriteTimeUtc = MyCharacterCache != null?File.GetLastWriteTimeUtc(MyCharacterCache.FilePath) : DateTime.MinValue;

                            if (checkresult.MySINner.LastChange < lastWriteTimeUtc)
                            {
                                if (ce == null)
                                {
                                    myState.StatusText      = "The Chummer is newer and has to be uploaded again.";
                                    myState.CurrentProgress = 30;
                                    ReportProgress(myState.CurrentProgress, myState);
                                    ce = await GetCharacterExtended(op_shareChummer);
                                }

                                if (ce != null)
                                {
                                    using (CustomActivity op_uploadChummer = Timekeeper.StartSyncron(
                                               "Uploading Chummer", op_shareChummer,
                                               CustomActivity.OperationType.DependencyOperation, MyCharacterCache?.FilePath))
                                    {
                                        myState.StatusText      = "Checking SINner availability (and if necessary upload it).";
                                        myState.CurrentProgress = 35;
                                        ReportProgress(myState.CurrentProgress, myState);
                                        myState.ProgressSteps = 10;
                                        await ce.Upload(myState, op_uploadChummer);

                                        if (ce.MySINnerFile.Id != null)
                                        {
                                            SINid = ce.MySINnerFile.Id.Value;
                                        }
                                        ResultSinnerGetSINById result = await client.GetSINByIdAsync(SINid);

                                        if (result == null)
                                        {
                                            throw new ArgumentException(
                                                      "Could not parse result from SINners Webservice!");
                                        }
                                        if (!result.CallSuccess)
                                        {
                                            if (result.MyException != null)
                                            {
                                                throw new ArgumentException(
                                                          "Error from SINners Webservice: " + result.ErrorText,
                                                          result.MyException.ToString());
                                            }
                                            throw new ArgumentException(
                                                      "Error from SINners Webservice: " + result.ErrorText);
                                        }

                                        hash = result.MySINner.MyHash;
                                    }
                                }
                            }
                        }
                        finally
                        {
                            //checkresult?.Dispose();
                        }
                    }
                    finally
                    {
                        ce?.Dispose();
                    }

                    myState.StatusText      = "SINner is online available.";
                    myState.CurrentProgress = 90;
                    ReportProgress(myState.CurrentProgress, myState);

                    string url = client.BaseUrl + "O";
                    url += "/" + hash;
                    if (Settings.Default.OpenChummerFromSharedLinks)
                    {
                        url += "?open=true";
                    }

                    myState.LinkText = url;
                    ReportProgress(100, myState);
                    RunWorkerCompleted(myState);
                    return(myState);
                }
            }
            catch (Exception exception)
            {
                Log.Warn(exception);
                throw;
            }
        }
        public async void LoadFromHeroLab(XmlNode xmlStatBlockBaseNode, CustomActivity parentActivity)
        {
            using (var op_load_char_attrib = Timekeeper.StartSyncron("load_char_attrib", parentActivity))
            {
                foreach (CharacterAttrib objAttribute in AttributeList.Concat(SpecialAttributeList))
                {
                    objAttribute.UnbindAttribute();
                }
                AttributeList.Clear();
                SpecialAttributeList.Clear();
                XmlDocument objXmlDocument =
                    XmlManager.Load(_objCharacter.IsCritter ? "critters.xml" : "metatypes.xml");
                XmlNode xmlMetatypeNode =
                    objXmlDocument.SelectSingleNode("/chummer/metatypes/metatype[name = \"" + _objCharacter.Metatype +
                                                    "\"]");
                XmlNode xmlCharNode =
                    xmlMetatypeNode?.SelectSingleNode("metavariants/metavariant[name = \"" + _objCharacter.Metavariant +
                                                      "\"]") ?? xmlMetatypeNode;
                // We only want to remake attributes for shifters in career mode, because they only get their second set of attributes when exporting from create mode into career mode
                XmlNode xmlCharNodeAnimalForm =
                    _objCharacter.MetatypeCategory == "Shapeshifter" && _objCharacter.Created ? xmlMetatypeNode : null;
                foreach (string strAttribute in AttributeStrings)
                {
                    // First, remake the attribute

                    CharacterAttrib objAttribute = null;
                    switch (CharacterAttrib.ConvertToAttributeCategory(strAttribute))
                    {
                    case CharacterAttrib.AttributeCategory.Special:
                        objAttribute = new CharacterAttrib(_objCharacter, strAttribute,
                                                           CharacterAttrib.AttributeCategory.Special);
                        objAttribute = RemakeAttribute(objAttribute, xmlCharNode);
                        SpecialAttributeList.Add(objAttribute);
                        break;

                    case CharacterAttrib.AttributeCategory.Standard:
                        objAttribute = new CharacterAttrib(_objCharacter, strAttribute,
                                                           CharacterAttrib.AttributeCategory.Standard);
                        objAttribute = RemakeAttribute(objAttribute, xmlCharNode);
                        AttributeList.Add(objAttribute);
                        break;
                    }

                    if (xmlCharNodeAnimalForm != null)
                    {
                        switch (CharacterAttrib.ConvertToAttributeCategory(strAttribute))
                        {
                        case CharacterAttrib.AttributeCategory.Special:
                            objAttribute = new CharacterAttrib(_objCharacter, strAttribute,
                                                               CharacterAttrib.AttributeCategory.Special);
                            objAttribute = RemakeAttribute(objAttribute, xmlCharNodeAnimalForm);
                            SpecialAttributeList.Add(objAttribute);
                            break;

                        case CharacterAttrib.AttributeCategory.Shapeshifter:
                            objAttribute = new CharacterAttrib(_objCharacter, strAttribute,
                                                               CharacterAttrib.AttributeCategory.Shapeshifter);
                            objAttribute = RemakeAttribute(objAttribute, xmlCharNodeAnimalForm);
                            AttributeList.Add(objAttribute);
                            break;
                        }
                    }

                    // Then load in attribute karma levels (we'll adjust these later if the character is in Create mode)
                    if (strAttribute == "ESS"
                        ) // Not Essence though, this will get modified automatically instead of having its value set to the one HeroLab displays
                    {
                        continue;
                    }
                    XmlNode xmlHeroLabAttributeNode =
                        xmlStatBlockBaseNode.SelectSingleNode(
                            "attributes/attribute[@name = \"" + GetAttributeEnglishName(strAttribute) + "\"]");
                    XmlNode xmlAttributeBaseNode = xmlHeroLabAttributeNode?.SelectSingleNode("@base");
                    if (xmlAttributeBaseNode != null &&
                        int.TryParse(xmlAttributeBaseNode.InnerText, out int intHeroLabAttributeBaseValue))
                    {
                        int intAttributeMinimumValue = GetAttributeByName(strAttribute).MetatypeMinimum;
                        if (intHeroLabAttributeBaseValue == intAttributeMinimumValue)
                        {
                            continue;
                        }
                        if (objAttribute != null)
                        {
                            objAttribute.Karma = intHeroLabAttributeBaseValue - intAttributeMinimumValue;
                        }
                    }
                }

                if (!_objCharacter.Created && _objCharacter.BuildMethodHasSkillPoints)
                {
                    // Allocate Attribute Points
                    int             intAttributePointCount = _objCharacter.TotalAttributes;
                    CharacterAttrib objAttributeToPutPointsInto;
                    // First loop through attributes where costs can be 100% covered with points
                    do
                    {
                        objAttributeToPutPointsInto = null;
                        int intAttributeToPutPointsIntoTotalKarmaCost = 0;
                        foreach (CharacterAttrib objLoopAttribute in AttributeList)
                        {
                            if (objLoopAttribute.Karma == 0)
                            {
                                continue;
                            }
                            // Put points into the attribute with the highest total karma cost.
                            // In case of ties, pick the one that would need more points to cover it (the other one will hopefully get picked up at a later cycle)
                            int intLoopTotalKarmaCost = objLoopAttribute.TotalKarmaCost;
                            if (objAttributeToPutPointsInto == null ||
                                (objLoopAttribute.Karma <= intAttributePointCount &&
                                 (intLoopTotalKarmaCost > intAttributeToPutPointsIntoTotalKarmaCost ||
                                  (intLoopTotalKarmaCost == intAttributeToPutPointsIntoTotalKarmaCost &&
                                   objLoopAttribute.Karma > objAttributeToPutPointsInto.Karma))))
                            {
                                objAttributeToPutPointsInto = objLoopAttribute;
                                intAttributeToPutPointsIntoTotalKarmaCost = intLoopTotalKarmaCost;
                            }
                        }

                        if (objAttributeToPutPointsInto != null)
                        {
                            objAttributeToPutPointsInto.Base  = objAttributeToPutPointsInto.Karma;
                            intAttributePointCount           -= objAttributeToPutPointsInto.Karma;
                            objAttributeToPutPointsInto.Karma = 0;
                        }
                    } while (objAttributeToPutPointsInto != null && intAttributePointCount > 0);

                    // If any points left over, then put them all into the attribute with the highest karma cost
                    if (intAttributePointCount > 0 && AttributeList.Any(x => x.Karma != 0))
                    {
                        int intHighestTotalKarmaCost = 0;
                        foreach (CharacterAttrib objLoopAttribute in AttributeList)
                        {
                            if (objLoopAttribute.Karma == 0)
                            {
                                continue;
                            }
                            // Put points into the attribute with the highest total karma cost.
                            // In case of ties, pick the one that would need more points to cover it (the other one will hopefully get picked up at a later cycle)
                            int intLoopTotalKarmaCost = objLoopAttribute.TotalKarmaCost;
                            if (objAttributeToPutPointsInto == null ||
                                intLoopTotalKarmaCost > intHighestTotalKarmaCost ||
                                (intLoopTotalKarmaCost == intHighestTotalKarmaCost &&
                                 objLoopAttribute.Karma > objAttributeToPutPointsInto.Karma))
                            {
                                objAttributeToPutPointsInto = objLoopAttribute;
                                intHighestTotalKarmaCost    = intLoopTotalKarmaCost;
                            }
                        }

                        if (objAttributeToPutPointsInto != null)
                        {
                            objAttributeToPutPointsInto.Base   = intAttributePointCount;
                            objAttributeToPutPointsInto.Karma -= intAttributePointCount;
                        }
                    }

                    // Allocate Special Attribute Points
                    intAttributePointCount = _objCharacter.TotalSpecial;
                    // First loop through attributes where costs can be 100% covered with points
                    do
                    {
                        objAttributeToPutPointsInto = null;
                        int intAttributeToPutPointsIntoTotalKarmaCost = 0;
                        foreach (CharacterAttrib objLoopAttribute in SpecialAttributeList)
                        {
                            if (objLoopAttribute.Karma == 0)
                            {
                                continue;
                            }
                            // Put points into the attribute with the highest total karma cost.
                            // In case of ties, pick the one that would need more points to cover it (the other one will hopefully get picked up at a later cycle)
                            int intLoopTotalKarmaCost = objLoopAttribute.TotalKarmaCost;
                            if (objAttributeToPutPointsInto == null ||
                                (objLoopAttribute.Karma <= intAttributePointCount &&
                                 (intLoopTotalKarmaCost > intAttributeToPutPointsIntoTotalKarmaCost ||
                                  (intLoopTotalKarmaCost == intAttributeToPutPointsIntoTotalKarmaCost &&
                                   objLoopAttribute.Karma > objAttributeToPutPointsInto.Karma))))
                            {
                                objAttributeToPutPointsInto = objLoopAttribute;
                                intAttributeToPutPointsIntoTotalKarmaCost = intLoopTotalKarmaCost;
                            }
                        }

                        if (objAttributeToPutPointsInto != null)
                        {
                            objAttributeToPutPointsInto.Base  = objAttributeToPutPointsInto.Karma;
                            intAttributePointCount           -= objAttributeToPutPointsInto.Karma;
                            objAttributeToPutPointsInto.Karma = 0;
                        }
                    } while (objAttributeToPutPointsInto != null);

                    // If any points left over, then put them all into the attribute with the highest karma cost
                    if (intAttributePointCount > 0 && SpecialAttributeList.Any(x => x.Karma != 0))
                    {
                        int intHighestTotalKarmaCost = 0;
                        foreach (CharacterAttrib objLoopAttribute in SpecialAttributeList)
                        {
                            if (objLoopAttribute.Karma == 0)
                            {
                                continue;
                            }
                            // Put points into the attribute with the highest total karma cost.
                            // In case of ties, pick the one that would need more points to cover it (the other one will hopefully get picked up at a later cycle)
                            int intLoopTotalKarmaCost = objLoopAttribute.TotalKarmaCost;
                            if (objAttributeToPutPointsInto == null ||
                                intLoopTotalKarmaCost > intHighestTotalKarmaCost ||
                                (intLoopTotalKarmaCost == intHighestTotalKarmaCost &&
                                 objLoopAttribute.Karma > objAttributeToPutPointsInto.Karma))
                            {
                                objAttributeToPutPointsInto = objLoopAttribute;
                                intHighestTotalKarmaCost    = intLoopTotalKarmaCost;
                            }
                        }

                        if (objAttributeToPutPointsInto != null)
                        {
                            objAttributeToPutPointsInto.Base   = intAttributePointCount;
                            objAttributeToPutPointsInto.Karma -= intAttributePointCount;
                        }
                    }
                }

                ResetBindings();
                _objCharacter.RefreshAttributeBindings();
                //Timekeeper.Finish("load_char_attrib");
            }
        }
Exemple #14
0
 public Task <IApiResponse <CustomActivity> > CreateCustomActivityAsync(CustomActivity customActivity) => CreateDataAsync <CustomActivity>(customActivity);
Exemple #15
0
 public IApiResponse <CustomActivity> CreateCustomActivity(CustomActivity customActivity) => CreateData <CustomActivity>(customActivity);