Esempio n. 1
0
 public string ToString(Func <string, string> getName)
 {
     if (Replacement == null)
     {
         return($"This model may take {Wargear.ToString(getName)}");
     }
     else
     {
         return($"This model may replace its {Wargear.ToString(getName)} with {Replacement.ToString(getName)}");
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Creates a new wargear listing based on the wargear sent to it and adds it to the required manifests
        /// </summary>
        /// <param name="armyName"></param>
        /// <param name="wargearName"></param>
        /// <param name="wargear"></param>
        public void addWargear(String armyName, String wargearName, Wargear wargear)
        {
            if (!loaded)
            {
                Logger.instance.log(LogType.ERROR, "Modelstore not loaded");
                return;
            }
            if (!armyCache.ContainsKey(armyName))
            {
                Logger.instance.log(LogType.ERROR, "Army " + armyName + " not found in loaded armies, Wargear " + wargearName + " failed to generate");
                return;
            }
            String fullName = armyName + ":" + wargearName;

            // Check to see if theres already another entry with the same name
            if (wargearCache.ContainsKey(fullName))
            {
                Logger.instance.log(LogType.ERROR, "Wargear " + fullName + " already exists");
                return;
            }
            ((JArray)(armyCache[armyName]["Wargear"])).Add(wargear.serialize());
            wargearCache.Add(fullName, wargear.serialize());
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Logger.instance = new Logger(LogType.INFO, "../../Logs/", 1);

            s = new Simulator(20);
            //mainWindow = new SimulatorWindow();
            //mainWindowApp = new Application();
            //mainWindowApp.Run(mainWindow);

            Model carnifex = new Model("Carnifex");

            carnifex.assignStats(67, new FixedStat(4), new FixedStat(4), new FixedStat(6), new FixedStat(7), new WoundsStat(8), new FixedStat(4), new FixedStat(6), new FixedStat(3), new FixedStat(7),
                                 new List <string> {
                "Bio-Plasma", "Spine banks", "Bone mace", "Monstrous acid maw", "Monstrous crushing claws", "Monstrous scything talons", "Thresher scythe",
                "Stranglethorn cannon", "Heavy venom cannon", "Deathspitter with slimer maggots", "Devourer with brainleech worms"
            },
                                 new List <string> {
                "Toxin sacs", "Adrenal glands", "Enhanced Sensors", "Tusks", "Chitin thorns", "Spore Cysts"
            },
                                 new List <string> {
                "Living Battering Ram"
            });

            Weapon devourer = new Weapon("Devourer with brainleech worms", 7, new FixedStat(18), Weapon.WeaponType.ASSAULT, new FixedStat(6), new FixedStat(0), new FixedStat(1), new FixedStat(6));

            carnifex.addWeapon(devourer.copy(), devourer.copy(), devourer.copy(), devourer.copy());

            Wargear sensors = new Wargear("Enhanced Sensors", 10, false).addModifier(new Modifier(3, ModifierMethod.SET, ModifierTarget.BALLISTICSKILL));

            carnifex.addWargear(sensors);

            ModelStore store = new ModelStore("../../Saves/Manifest.json");

            if (store.load())
            {
                Model marine1 = store.getModel("Space Marines:Tactical Marine", "Space Marines:Boltgun");
                Model term1   = store.getModel("Tyranids:Termagaunt", "Tyranids:Fleshborer");
                Model term2   = store.getModel("Tyranids:Termagaunt", "Tyranids:Fleshborer");
                Model term3   = store.getModel("Tyranids:Termagaunt", "Tyranids:Fleshborer");
                Model term4   = store.getModel("Tyranids:Termagaunt", "Tyranids:Fleshborer");

                Unit spess = new Unit(TargetingMode.ORDER).addModel(marine1);
                Unit tyr   = new Unit(TargetingMode.ORDER).addModel(term1, term2, term3, term4);

                store.getModel("Termagaunt", "Badborer");

                int    numberOfRuns = 10000;
                Battle b            = new Battle(spess, tyr, Player.PLAYER1);
                for (int i = 0; i < numberOfRuns; i++)
                {
                    s.Simulate(b);
                }

                SimulatorResult result = s.processResults();
                result.printResults();

                if (store.incompleteLoad)
                {
                    Console.WriteLine("Manifest Loaded with Errors, writing the manifest will remove erroneous entries, are you sure you want to write the manifest (THIS WILL NOT FIX THE ERRORS, JUST REMOVE THEM) (Y/N): ");
                    String r = Console.ReadLine();
                    if ((r == "y" || r == "Y"))
                    {
                        store.writeManifest(true);
                    }
                }
                else
                {
                    store.writeManifest(false);
                }
            }

            Console.ReadLine();
        }
Esempio n. 4
0
        /// <summary>
        /// Loads all of the data listed in the manifest into the caches
        /// </summary>
        /// <returns>Did the manifest load correctly</returns>
        public bool load()
        {
            try
            {
                Logger.instance.log(LogType.INFO, "Loading Manifest");
                JObject rawManifest = DataReader.readJObjectFromFile(manifestPath + manifestName);

                if (rawManifest == null)
                {
                    Logger.instance.log(LogType.FATAL, "Something went wrong loading the manifest");
                    return(false);
                }

                // Take out just the ArrayList of armies from the manifest
                manifest = (JArray)rawManifest["Armies"];

                if (manifest == null || !manifest.HasValues)
                {
                    Logger.instance.log(LogType.FATAL, "Manifest has no armies listed");
                    return(false);
                }

                armyCache    = new Dictionary <string, JObject>();
                modelCache   = new Dictionary <string, JObject>();
                weaponCache  = new Dictionary <string, JObject>();
                abilityCache = new Dictionary <string, JObject>();
                wargearCache = new Dictionary <string, JObject>();

                List <JValue> badArmies = new List <JValue>();

                // Build the armycache from the armies listed in the manifest, setting aside any that did not load correctly
                foreach (JValue armyListing in manifest)
                {
                    // See if it will load
                    JObject army = DataReader.readJObjectFromFile(getFileName((String)armyListing));
                    if (army == null)
                    {
                        Logger.instance.log(LogType.ERROR, "Army failed to load, likely due to a bad location");
                        incompleteLoad = true;
                        badArmies.Add(armyListing);
                        continue;
                    }
                    // And do a quick check to see if the army itself is proper
                    if (!army.ContainsKey("Models") || !army.ContainsKey("Weapons"))
                    {
                        Logger.instance.log(LogType.ERROR, "Army " + armyListing["Name"] + " is malformed");
                        incompleteLoad = true;
                        badArmies.Add(armyListing);
                        continue;
                    }
                    // Finally check for duplicates, we dont like those
                    if (armyCache.ContainsKey((String)armyListing))
                    {
                        Logger.instance.log(LogType.ERROR, "Army " + armyListing + " already exists in the cache");
                        incompleteLoad = true;
                        badArmies.Add(armyListing);
                        continue;
                    }
                    armyCache.Add((String)armyListing, army);
                }

                // Remove any that did not load correctly from the manifest
                foreach (JValue badArmy in badArmies)
                {
                    manifest.Remove(badArmy);
                }

                // Load the data for each army, setting aside any that doesnt load correctly
                foreach (KeyValuePair <String, JObject> kvp in armyCache)
                {
                    JObject army = kvp.Value;

                    List <JValue>  badModels    = new List <JValue>();
                    List <JValue>  badWeapons   = new List <JValue>();
                    List <JObject> badWargear   = new List <JObject>();
                    List <JObject> badAbilities = new List <JObject>();

                    JArray models    = new JArray();
                    JArray weapons   = new JArray();
                    JArray wargear   = new JArray();
                    JArray abilities = new JArray();

                    // Only load data if the army has it
                    if (army.ContainsKey("Models") && army["Models"].HasValues)
                    {
                        models = (JArray)army["Models"];
                    }
                    else
                    {
                        Logger.instance.log(LogType.WARNING, "Army " + kvp.Key + " has no models");
                    }
                    if (army.ContainsKey("Weapons") && army["Weapons"].HasValues)
                    {
                        weapons = (JArray)army["Weapons"];
                    }
                    else
                    {
                        Logger.instance.log(LogType.WARNING, "Army " + kvp.Key + " has no weapons");
                    }
                    if (army.ContainsKey("Wargear") && army["Wargear"].HasValues)
                    {
                        wargear = (JArray)army["Wargear"];
                    }
                    else
                    {
                        Logger.instance.log(LogType.WARNING, "Army " + kvp.Key + " has no wargear");
                    }
                    if (army.ContainsKey("Abilities") && army["Abilities"].HasValues)
                    {
                        wargear = (JArray)army["Abilities"];
                    }
                    else
                    {
                        Logger.instance.log(LogType.WARNING, "Army " + kvp.Key + " has no abilities");
                    }

                    // Load Models into the cache (after checking they exist)
                    foreach (JValue modelListing in models)
                    {
                        JObject model = DataReader.readJObjectFromFile(getFileName((String)modelListing, kvp.Key));
                        if (model == null)
                        {
                            Logger.instance.log(LogType.ERROR, "Model listing in army " + kvp.Key + " failed to load, likely due to a bad location");
                            incompleteLoad = true;
                            badModels.Add(modelListing);
                            continue;
                        }
                        // Also check for duplicates, we dont like those
                        if (modelCache.ContainsKey(kvp.Key + ":" + (String)modelListing))
                        {
                            Logger.instance.log(LogType.ERROR, "Model " + kvp.Key + ":" + (String)modelListing + " already exists in the cache");
                            incompleteLoad = true;
                            badModels.Add(modelListing);
                            continue;
                        }
                        // Check if the Models are proper
                        try
                        {
                            Model test = new Model(model);
                        }
                        catch (ArgumentNullException)
                        {
                            Logger.instance.log(LogType.ERROR, "Model " + kvp.Key + ":" + (String)modelListing + " did not load because of missing tags");
                            incompleteLoad = true;
                            badModels.Add(modelListing);
                            continue;
                        }
                        catch (Exception e)
                        {
                            Logger.instance.log(LogType.ERROR, "Model " + kvp.Key + ":" + (String)modelListing + " did not load because of an unknown error " + e.Message);
                            incompleteLoad = true;
                            badModels.Add(modelListing);
                            continue;
                        }
                        modelCache.Add(kvp.Key + ":" + (String)modelListing, model);
                    }

                    // Load Weapons into the cache (after checking they exist)
                    foreach (JValue weaponListing in weapons)
                    {
                        JObject weapon = DataReader.readJObjectFromFile(getFileName((String)weaponListing, kvp.Key));
                        if (weapon == null)
                        {
                            Logger.instance.log(LogType.ERROR, "Weapon listing in army " + kvp.Key + " failed to load, likely due to a bad location");
                            incompleteLoad = true;
                            badWeapons.Add(weaponListing);
                            continue;
                        }
                        // Also check for duplicates, we dont like those
                        if (weaponCache.ContainsKey(kvp.Key + ":" + (String)weaponListing))
                        {
                            Logger.instance.log(LogType.ERROR, "Weapon " + kvp.Key + ":" + (String)weaponListing + " already exists in the cache");
                            incompleteLoad = true;
                            badWeapons.Add(weaponListing);
                            continue;
                        }
                        // Check if the Weapons are proper
                        try
                        {
                            Weapon test = new Weapon(weapon, null);
                        }
                        catch (ArgumentNullException)
                        {
                            Logger.instance.log(LogType.ERROR, "Weapon " + kvp.Key + ":" + (String)weaponListing + " did not load because of missing tags");
                            incompleteLoad = true;
                            badWeapons.Add(weaponListing);
                            continue;
                        }
                        catch (Exception e)
                        {
                            Logger.instance.log(LogType.ERROR, "Weapon " + kvp.Key + ":" + (String)weaponListing + " did not load because of an unknown error " + e.Message);
                            incompleteLoad = true;
                            badWeapons.Add(weaponListing);
                            continue;
                        }
                        weaponCache.Add(kvp.Key + ":" + (String)weaponListing, weapon);
                    }

                    //Load Wargear into the cache (after checking it exists)
                    foreach (JObject wargearListing in wargear)
                    {
                        if (wargearListing == null)
                        {
                            Logger.instance.log(LogType.ERROR, "Wargear listing in army " + kvp.Key + " failed to load, likely due to a bad location");
                            incompleteLoad = true;
                            badWargear.Add(wargearListing);
                            continue;
                        }
                        // Check if the Models are proper
                        try
                        {
                            Wargear test = new Wargear(wargearListing);
                        }
                        catch (ArgumentNullException)
                        {
                            Logger.instance.log(LogType.ERROR, "Wargear from " + kvp.Key + " did not load because of missing tags");
                            incompleteLoad = true;
                            badWargear.Add(wargearListing);
                            continue;
                        }
                        catch (Exception e)
                        {
                            Logger.instance.log(LogType.ERROR, "Wargear from" + kvp.Key + " did not load because of an unknown error " + e.Message);
                            incompleteLoad = true;
                            badWargear.Add(wargearListing);
                            continue;
                        }
                        // Also check for duplicates, we dont like those
                        if (wargearCache.ContainsKey(kvp.Key + ":" + (String)wargearListing["Name"]))
                        {
                            Logger.instance.log(LogType.ERROR, "Wargear " + kvp.Key + ":" + (String)wargearListing["Name"] + " already exists in the cache");
                            incompleteLoad = true;
                            badWargear.Add(wargearListing);
                            continue;
                        }
                        wargearCache.Add(kvp.Key + ":" + (String)wargearListing["Name"], wargearListing);
                    }

                    // Load Abilities into the cache (after checking they exist)
                    foreach (JObject abilityListing in abilities)
                    {
                        if (abilityListing == null)
                        {
                            Logger.instance.log(LogType.ERROR, "ability listing in army " + kvp.Key + " failed to load, likely due to a bad location");
                            incompleteLoad = true;
                            badAbilities.Add(abilityListing);
                            continue;
                        }
                        // Check if the Models are proper
                        try
                        {
                            Ability test = new Ability(abilityListing);
                        }
                        catch (ArgumentNullException)
                        {
                            Logger.instance.log(LogType.ERROR, "ability from " + kvp.Key + " did not load because of missing tags");
                            incompleteLoad = true;
                            badAbilities.Add(abilityListing);
                            continue;
                        }
                        catch (Exception e)
                        {
                            Logger.instance.log(LogType.ERROR, "ability from" + kvp.Key + " did not load because of an unknown error " + e.Message);
                            incompleteLoad = true;
                            badAbilities.Add(abilityListing);
                            continue;
                        }
                        // Also check for duplicates, we dont like those
                        if (abilityCache.ContainsKey(kvp.Key + ":" + (String)abilityListing["Name"]))
                        {
                            Logger.instance.log(LogType.ERROR, "ability " + kvp.Key + ":" + (String)abilityListing["Name"] + " already exists in the cache");
                            incompleteLoad = true;
                            badAbilities.Add(abilityListing);
                            continue;
                        }
                        abilityCache.Add(kvp.Key + ":" + (String)abilityListing["Name"], abilityListing);
                    }

                    // Remove the bad data from the army =
                    foreach (JValue badModel in badModels)
                    {
                        ((JArray)army["Models"]).Remove(badModel);
                    }

                    foreach (JValue badWeapon in badWeapons)
                    {
                        ((JArray)army["Weapons"]).Remove(badWeapon);
                    }

                    foreach (JObject badWgear in badWargear)
                    {
                        ((JArray)army["Wargear"]).Remove(badWgear);
                    }

                    foreach (JObject badAbility in badAbilities)
                    {
                        ((JArray)army["Abilities"]).Remove(badAbility);
                    }
                }

                Logger.instance.log(LogType.INFO, "Finished loading manifest");
                loaded = true;
                return(true);
            } catch (Exception e)
            {
                Logger.instance.log(LogType.FATAL, "Something unexpected happened while loading the modelstore, probably due to the jsons being formatted wrong :" + e.Message);
                return(false);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Generates a new Model as specified by its definition in the modelstore with the listed weapons generated and equipped
        /// </summary>
        /// <param name="name">The name of the model to be generated</param>
        /// <param name="weapons">The name(s) of the weapons to be generated for this model</param>
        /// <param name="wargear">The name(s) of the wargear to be generated for this model</param>
        /// <returns></returns>
        public Model getModel(String name, String[] weapons, String[] wargear)
        {
            if (!loaded)
            {
                Logger.instance.log(LogType.ERROR, "Modelstore not loaded");
                return(null);
            }
            JObject modelTemplate = null;

            try
            {
                modelTemplate = modelCache[name];
            }
            catch (KeyNotFoundException)
            {
                Logger.instance.log(LogType.ERROR, "No Model found with the name " + name);
                return(null);
            }
            if (modelTemplate == null)
            {
                Logger.instance.log(LogType.ERROR, "No Model found with the name " + name);
                return(null);
            }

            Model m = new Model(modelTemplate);

            // Add all the units abilities
            foreach (String s in m.abilityList)
            {
                Ability a = getAbility(s);
                if (a == null)
                {
                    Logger.instance.log(LogType.ERROR, "Model loading issue, Ability not obtained, " + a);
                    continue;
                }
                m.addAbility(a);
            }

            // Only add the weapons if the weapons array exists
            if (!(weapons == null) && !(weapons.Length == 0))
            {
                foreach (String s in weapons)
                {
                    Weapon w = getWeapon(s, m);
                    if (w == null)
                    {
                        Logger.instance.log(LogType.ERROR, "Model loading issue, Weapon not obtained, " + s);
                        continue;
                    }
                    m.addWeapon(w);
                }
            }

            // Only add wargear if the wargear array exists
            if (!(wargear == null) && !(wargear.Length == 0))
            {
                foreach (String s in wargear)
                {
                    Wargear w = getWargear(s);
                    if (w == null)
                    {
                        Logger.instance.log(LogType.ERROR, "Model loading issue, Wargear not obtained, " + s);
                        continue;
                    }
                    m.addWargear(w);
                    // If the wargear has a linked ability, add it
                    if (w.linkedAbility)
                    {
                        Ability a = getAbility(s);
                        if (a == null)
                        {
                            Logger.instance.log(LogType.ERROR, "Model loading issue, Ability not obtained, " + a);
                            continue;
                        }
                        m.addAbility(a);
                    }
                }
            }
            return(m);
        }
        //Initialize seeds the database, if it doesn't have the correct columns already.
        public static void Initialize(BattleCompanyContext context)
        {
            context.Database.EnsureCreated();


            //Declared outside if statements so they can be used to join later tables
            Keyword[] keywords;
            Wargear[] wargears;
            Faction[] factions;


            //This table of keywords can be used as-is even if the keyword table has already been created.
            //There should be no difference whatsoever between this array of keywords
            keywords = new Keyword[]
            {
                new Keyword(Keyword.HERO_KEYWORD),
                new Keyword(Keyword.INF_KEYWORD),
                new Keyword(Keyword.CAV_KEYWORD),
                new Keyword(Keyword.BEAST_KEYWORD),
                new Keyword(Keyword.MAN_KEYWORD),
                new Keyword(Keyword.HOBBIT_KEYWORD),
                new Keyword(Keyword.ELF_KEYWORD),
                new Keyword(Keyword.DWARF_KEYWORD),
                new Keyword(Keyword.ORC_KEYWORD),
                new Keyword(Keyword.URUK_KEYWORD)
            };

            if (!context.Keywords.Any())
            {
                foreach (Keyword k in keywords)
                {
                    context.Keywords.Add(k);
                }

                context.SaveChanges();
            }


            wargears = new Wargear[]
            {
                new Wargear("Sword", false, false),          //0
                new Wargear("Axe", false, false),            //1
                new Wargear("Club", false, false),           //2
                new Wargear("Staff", false, false),          //3
                new Wargear("Flail", false, false),          //4
                new Wargear("Spear", false, false),          //5
                new Wargear("Pike", false, false),           //6
                new Wargear("Lance", false, false),          //7
                new Wargear("Shield", false, false),         //8
                new Wargear("Armor", false, false),          //9
                new Wargear("Heavy Armor", false, false),    //10
                new Wargear("Dwarf Armor", false, false),    //11
                new Wargear("Elven Cloak", false, false),    //12
                new Wargear("Banner", false, false),         //13
                new Wargear("War Horn", false, false),       //14
                new Wargear("Twohanded Sword", true, false), //15
                new Wargear("Twohanded Axe", true, false),   //16
                new Wargear("Twohanded Club", true, false),  //17
                new Wargear("Twohanded Staff", true, false), //18
                new Wargear("Twohanded Flail", true, false), //19
                new Wargear("Bow", false, true),             //20
                new Wargear("Crossbow", false, true),        //21
                new Wargear("Longbow", false, true),         //22
                new Wargear("Dwarf Bow", false, true),       //23
                new Wargear("Elf Bow", false, true),         //24
                new Wargear("Orc Bow", false, true),         //25
                new Wargear("Horse", false, false),          //26
                new Wargear("Armored Horse", false, false),  //27
                new Wargear("Warg", false, false),           //28
                new Wargear("Elven Sword", false, false)     //29
            };

            if (!context.Wargears.Any())
            {
                foreach (Wargear w in wargears)
                {
                    context.Wargears.Add(w);
                }

                context.SaveChanges();
            }


            //Additional Factions should have their own entries in this array, as well as their own complete set of wargears
            if (!context.Factions.Any())
            {
                factions = new Faction[]
                {
                    new Faction {
                        FactionName     = "Minas Tirith",
                        FactionWargears = new List <FactionWargear>()
                    },
                    new Faction {
                        FactionName     = "Mordor",
                        FactionWargears = new List <FactionWargear>()
                    }
                };

                List <Wargear> gondorArmory = new List <Wargear>()
                {
                    wargears[0], wargears[5], wargears[7], wargears[8], wargears[9], wargears[10], wargears[13], wargears[14], wargears[20], wargears[22], wargears[26]
                };

                List <Wargear> OrcArmory = new List <Wargear>()
                {
                    wargears[0], wargears[1], wargears[2], wargears[5], wargears[8], wargears[9], wargears[10], wargears[13], wargears[14], wargears[17], wargears[25]
                };

                foreach (Wargear w in gondorArmory)
                {
                    var connection = new FactionWargear()
                    {
                        Faction = factions[0],
                        Wargear = w
                    };

                    factions[0].FactionWargears.Add(connection);
                    w.FactionWargears.Add(connection);
                }

                foreach (Wargear w in OrcArmory)
                {
                    var connection = new FactionWargear()
                    {
                        Faction = factions[1],
                        Wargear = w
                    };

                    factions[1].FactionWargears.Add(connection);
                    w.FactionWargears.Add(connection);
                }


                foreach (Faction f in factions)
                {
                    context.Factions.Add(f);
                }

                context.SaveChanges();
            }
        }