Exemple #1
0
 public virtual void SetUnits(ConfigGameUnit[] cns)
 {
     units = new MyDictionary <string, IGameUnit>();
     while (cns.Length > units.Count)
     {
         int            size = units.Count;
         IList <string> msg  = new List <string>();
         foreach (ConfigGameUnit u in cns)
         {
             IGameUnit unit = u.ToGameUnit();
             if (IsNullOrEmpty(u.GetParent()) && IsNullOrEmpty(u.GetTriggerParent()) && IsNullOrEmpty(u.GetParaParent()))
             {
                 units[u.GetKey()] = unit;
             }
             else
             {
                 bool all = true;
                 MyDictionary <string, int> pMap = new MyDictionary <string, int>();
                 if (!IsNullOrEmpty(u.GetParent()))
                 {
                     string[] ps = u.GetParent().Split(",");
                     foreach (string p in ps)
                     {
                         if (!units.ContainsKey(p.Trim()))
                         {
                             all = false;
                             msg.Add(unit.GetKey() + " is depend on " + p);
                             break;
                         }
                         pMap[p] = 0;
                     }
                 }
                 if (all && !IsNullOrEmpty(u.GetParaParent()))
                 {
                     string[] ps = u.GetParaParent().Split(",");
                     foreach (string p in ps)
                     {
                         if (!units.ContainsKey(p.Trim()))
                         {
                             all = false;
                             msg.Add(unit.GetKey() + " is depend on " + p);
                             break;
                         }
                         pMap[p] = 1;
                     }
                 }
                 if (all && !IsNullOrEmpty(u.GetTriggerParent()))
                 {
                     string[] ps = u.GetTriggerParent().Split(",");
                     foreach (string p in ps)
                     {
                         if (!units.ContainsKey(p.Trim()))
                         {
                             all = false;
                             msg.Add(unit.GetKey() + " is depend on " + p);
                             break;
                         }
                         pMap[p] = 2;
                     }
                 }
                 if (all)
                 {
                     foreach (string p in pMap.Keys)
                     {
                         MergeParent(unit, p, pMap[p]);
                     }
                     units[u.GetKey()] = unit;
                 }
             }
         }
         if (size == units.Count && cns.Length > units.Count)
         {
             throw new GameConfigExpception("units have dependency issues\n" + StringUtil.GetStringFromStrings(msg, "\n"));
         }
     }
 }