Replies: 2 (Who?), Viewed: 212 times.
Virtual gardener
staff: administrator
Original Poster
#1 Old 10th May 2021 at 12:32 PM Last edited by Lyralei : 10th May 2021 at 4:18 PM. Reason: Named it custom because that just sounds cooler :p
Default (Finished) Custom OpportunityLoader
Hey everyone!

I was talking to some people about adding your own custom opportunities and been using the Skill's way of parsing the xml file as a reference  After a lot of wrestling (And you might have known that if you saw the first version of this thread ;p) It's currently working flawlessly!

Before we get to the code, I really want to thank Arsil for creating a function that lets you add Enum Values to Enums! This isn't usually possible due to the nature of Enums

Here's the code for loading (And even specifically firing a particular opportunity, which can also be written to work for EA's own Opportunity!)

NOTE: THIS is SUPER long! So make sure to mentally prepare yourself for that :p



And of course, an example use! Sims:



Objects:



I've added the Solution with it's examples and code in the thread as well! And the example package so you know how to use it with the XML!

If you have any questions about adding your own custom opportunity or my code sets your computer on fire, then let me know too!
Download - please read all instructions before downloading any files!
File Type: zip OpportunityLoader.zip (366.0 KB, 7 downloads)
Description: Source Code VSproject
File Type: zip OpportunityLoaderExample.zip (15.5 KB, 4 downloads)
Description: Example package
Advertisement
Lab Assistant
#2 Old 13th May 2021 at 8:27 AM
There is a function to add enums?
Could you give me the link to that? I would really like to create custom Commodity Types to use in Ituns.
Virtual gardener
staff: administrator
Original Poster
#3 Old 13th May 2021 at 12:14 PM Last edited by Lyralei : 13th May 2021 at 12:26 PM.
Quote:
Originally Posted by KittyTheSnowcat
There is a function to add enums?
Could you give me the link to that? I would really like to create custom Commodity Types to use in Ituns.
No problem! 

It's actually inlined in the code, but here it is again, since it's a loooot of code, so It's hard to miss:

Code:
         // Arsil's enum function.
        public static void AddEnumValue<T>(string key, object value) where T : struct
        {
            Type typeFromHandle = typeof(T);
            EnumParser enumParser;
            if (!ParserFunctions.sCaseInsensitiveEnumParsers.TryGetValue(typeFromHandle, out enumParser))
            {
                enumParser = new EnumParser(typeFromHandle, true);
                ParserFunctions.sCaseInsensitiveEnumParsers.Add(typeFromHandle, enumParser);
            }
            EnumParser enumParser2;
            if (!ParserFunctions.sCaseSensitiveEnumParsers.TryGetValue(typeFromHandle, out enumParser2))
            {
                enumParser2 = new EnumParser(typeFromHandle, false);
                ParserFunctions.sCaseSensitiveEnumParsers.Add(typeFromHandle, enumParser2);
            }
            if (!enumParser.mLookup.ContainsKey(key.ToLowerInvariant()) && !enumParser2.mLookup.ContainsKey(key))
            {
                enumParser.mLookup.Add(key.ToLowerInvariant(), value);
                enumParser2.mLookup.Add(key, value);
            }
        }

// Usage would be something like:
// Do convert "MyCustomCommodityType" to a FNV64 in S3PE (Tools > FNV64) and then the converter below will convert it to a 16-numeric decimal for you 
AddEnumValue<OpportunityNames>("MyCustomCommodityType", Convert.ToUInt64(0x5BC056891B5FA161, 16));
Again, this is Arsil's way of parsing a custom Enum, so all credits goes to him! And Zoe for pointing it out :p 
Back to top