Esempio n. 1
0
        private Dictionary <int, TriadGameModifier> ParseGameRules(string folderPath)
        {
            Dictionary <int, TriadGameModifier> ruleMap = new Dictionary <int, TriadGameModifier>();
            List <string[]> cardRules = ParseCSVFile(folderPath + "TripleTriadRule.csv");

            if (cardRules.Count > 0 && cardRules[0].Length == 7)
            {
                List <TriadGameModifier> modList = new List <TriadGameModifier>();
                foreach (Type type in Assembly.GetAssembly(typeof(TriadGameModifier)).GetTypes())
                {
                    if (type.IsSubclassOf(typeof(TriadGameModifier)))
                    {
                        TriadGameModifier modInst = (TriadGameModifier)Activator.CreateInstance(type);
                        modList.Add(modInst);
                    }
                }

                for (int modIdx = 0; modIdx < modList.Count; modIdx++)
                {
                    bool assigned = false;
                    for (int Idx = 0; Idx < cardRules.Count; Idx++)
                    {
                        if (cardRules[Idx][1] == modList[modIdx].GetName())
                        {
                            ruleMap.Add(int.Parse(cardRules[Idx][0]), modList[modIdx]);
                            assigned = true;
                            break;
                        }
                    }

                    if (!assigned && modList[modIdx].GetName() != "None")
                    {
                        throw new Exception("Unable to parse types from csv: missing rule type '" + modList[modIdx].GetName() + "' [1]");
                    }
                }

                for (int Idx = 0; Idx < cardRules.Count; Idx++)
                {
                    if (cardRules[Idx][1].Length > 0)
                    {
                        bool bFound = false;
                        for (int modIdx = 0; modIdx < modList.Count && !bFound; modIdx++)
                        {
                            bFound = modList[modIdx].GetName() == cardRules[Idx][1];
                        }

                        if (!bFound)
                        {
                            throw new Exception("Unable to parse types from csv: missing rule type '" + cardRules[Idx][1] + "' [2]");
                        }
                    }
                }
            }
            else
            {
                throw new Exception("Unable to parse rules from csv!");
            }

            return(ruleMap);
        }
Esempio n. 2
0
 public int CompareTo(TriadGameModifier otherMod)
 {
     if (otherMod != null)
     {
         string locStrA = GetLocalizedName();
         string locStrB = otherMod.GetLocalizedName();
         return(locStrA.CompareTo(locStrB));
     }
     return(0);
 }
Esempio n. 3
0
        private Dictionary <string, TriadGameModifier> BuildRuleNameMap()
        {
            var ruleMap = new Dictionary <string, TriadGameModifier>();

            foreach (Type type in Assembly.GetAssembly(typeof(TriadGameModifier)).GetTypes())
            {
                if (type.IsSubclassOf(typeof(TriadGameModifier)) && type != typeof(TriadGameModifierNone))
                {
                    TriadGameModifier modInst = (TriadGameModifier)Activator.CreateInstance(type);
                    ruleMap.Add(modInst.GetCodeName(), modInst);
                }
            }

            return(ruleMap);
        }
Esempio n. 4
0
        public void Update(TriadGameSession currentGame, TriadNpc npc)
        {
            bool isDirty = true;

            if (session != null && session.modifiers.Count == currentGame.modifiers.Count)
            {
                int numMatching = 0;
                for (int Idx = 0; Idx < currentGame.modifiers.Count; Idx++)
                {
                    TriadGameModifier currentMod = session.modifiers[Idx];
                    TriadGameModifier reqMod     = currentGame.modifiers[Idx];

                    if (currentMod.GetType() == reqMod.GetType())
                    {
                        numMatching++;
                    }
                }

                isDirty = (numMatching != session.modifiers.Count);
            }

            if (npc != this.npc)
            {
                this.npc = npc;
                isDirty  = true;
            }

            if (isDirty)
            {
                session            = new TriadGameSession();
                session.solverName = "Fav #" + (contextId + 1);

                foreach (TriadGameModifier mod in currentGame.modifiers)
                {
                    TriadGameModifier modCopy = (TriadGameModifier)Activator.CreateInstance(mod.GetType());
                    modCopy.OnMatchInit();

                    session.modifiers.Add(modCopy);
                }

                session.UpdateSpecialRules();
                CalcWinChance();
            }
        }
Esempio n. 5
0
        private TriadGameModifier ParseRule(string ruleName)
        {
            TriadGameModifier result = null;

            foreach (TriadGameModifier mod in modObjects)
            {
                if (ruleName.Equals(mod.GetName(), StringComparison.InvariantCultureIgnoreCase))
                {
                    result = (TriadGameModifier)Activator.CreateInstance(mod.GetType());
                    break;
                }
            }

            if (result == null)
            {
                Logger.WriteLine("Loading failed! Can't parse rule: " + ruleName);
            }

            return(result);
        }
Esempio n. 6
0
        public ImageHashData LoadHashEntry(XmlElement xmlElem)
        {
            ImageHashData result = null;

            if (xmlElem != null && xmlElem.Name == "hash" && xmlElem.HasAttribute("type") && (xmlElem.HasAttribute("value") || xmlElem.HasAttribute("valueS")))
            {
                string typeName = xmlElem.GetAttribute("type");

                string hashValueC = xmlElem.HasAttribute("value") ? xmlElem.GetAttribute("value") : null;
                string hashValueS = xmlElem.HasAttribute("valueS") ? xmlElem.GetAttribute("valueS") : null;

                HashCollection hashData = new HashCollection(hashValueC, hashValueS);

                if (typeName.Equals("rule", StringComparison.InvariantCultureIgnoreCase))
                {
                    string            ruleName = xmlElem.GetAttribute("name");
                    TriadGameModifier ruleMod  = ParseRule(ruleName);

                    result = new ImageHashData(ruleMod, hashData, EImageHashType.Rule);
                }
                else if (typeName.Equals("card", StringComparison.InvariantCultureIgnoreCase))
                {
                    string    cardIdName = xmlElem.GetAttribute("id");
                    int       cardId     = int.Parse(cardIdName);
                    TriadCard cardOb     = TriadCardDB.Get().cards[cardId];

                    result = new ImageHashData(cardOb, hashData, EImageHashType.Card);
                }
                else if (typeName.Equals("cactpot", StringComparison.InvariantCultureIgnoreCase))
                {
                    string numIdName = xmlElem.GetAttribute("id");
                    int    numId     = int.Parse(numIdName);
                    if (numId >= 1 && numId <= 9)
                    {
                        result = new ImageHashData(CactpotGame.hashDB[numId - 1], hashData, EImageHashType.Cactpot);
                    }
                }
            }

            return(result);
        }
Esempio n. 7
0
        public TriadGameModifierDB()
        {
            mods = new List <TriadGameModifier>();
            foreach (Type type in Assembly.GetAssembly(typeof(TriadGameModifier)).GetTypes())
            {
                if (type.IsSubclassOf(typeof(TriadGameModifier)))
                {
                    TriadGameModifier modOb = (TriadGameModifier)Activator.CreateInstance(type);
                    mods.Add(modOb);
                }
            }

            mods.Sort((a, b) => (a.GetLocalizationId().CompareTo(b.GetLocalizationId())));

            for (int idx = 0; idx < mods.Count; idx++)
            {
                if (mods[idx].GetLocalizationId() != idx)
                {
                    Logger.WriteLine("FAILED to initialize modifiers!");
                    break;
                }
            }
        }
Esempio n. 8
0
 public HashOwnerItem(TriadGameModifier mod)
 {
     SourceObject = mod;
     Description  = mod.ToString();
 }
Esempio n. 9
0
 public void SetRuleInstance(TriadGameModifier RuleInstance)
 {
     RuleInst = RuleInstance;
 }
Esempio n. 10
0
 public int CompareTo(TriadGameModifier otherMod)
 {
     return((otherMod != null) ? RuleName.CompareTo(otherMod.RuleName) : 0);
 }