Exemple #1
0
        public static bool TryGetModel(string codeName, out ModelDef model)
        {
            if (codeName == null)
            {
                throw new ArgumentNullException("CodeName is null!");
            }

            return(names.TryGetValue(codeName, out model));
        }
Exemple #2
0
        public static bool TryGetModel(int id, out ModelDef model)
        {
            ModelInstance m;

            if (ModelInstance.TryGet(id, out m))
            {
                model = (ModelDef)m.ScriptObject;
                return(true);
            }
            model = null;
            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Create ModelDef-objects from diverse prepared input and output them as Dictionary modelDefByID.
        /// Finalize initialization of all input objects.
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="overlayByID"></param>
        /// <param name="aniJobByID"></param>
        /// <param name="overlayIDByModelDefID"></param>
        /// <param name="aniJobIDByModelDefID"></param>
        /// <param name="modelDefByID"></param>
        /// <returns></returns>
        public bool TryGenerateModelDefs(List <List <object> > dataTable,
                                         Dictionary <int, ScriptOverlay> overlayByID, Dictionary <int, ScriptAniJob> aniJobByID,
                                         Dictionary <int, List <int> > overlayIDByModelDefID, Dictionary <int, List <int> > aniJobIDByModelDefID,
                                         Dictionary <int, int> nextIDByAniJobID, out Dictionary <int, ModelDef> modelDefByID)
        {
            modelDefByID = new Dictionary <int, ModelDef>(dataTable.Count);

            List <ColumnGetTypeInfo> info;

            TryGetColGetTypeInfo("ModelDef", out info);

            try
            {
                foreach (List <object> row in dataTable)
                {
                    var modelDef = new ModelDef();
                    var id       = -1;
                    for (int c = 0; c < row.Count; c++)
                    {
                        switch (info[c].colName)
                        {
                        case "ModelDefID":
                            id = (int)row[c];
                            break;

                        case "ModelDefName":
                            modelDef.CodeName = (string)row[c];
                            break;

                        case "Visual":
                            modelDef.Visual = (string)row[c];
                            break;

                        case "AniCatalog":
                            var aniCatalog = (string)row[c];
                            switch (aniCatalog)
                            {
                            case "NPCCatalog":
                                modelDef.SetAniCatalog(new AniCatalogs.NPCCatalog());
                                break;
                            }
                            break;

                        case "Radius":
                            modelDef.Radius = (float)row[c];
                            break;

                        case "Height":
                            modelDef.HalfHeight = (float)row[c];
                            break;

                        case "FistRange":
                            modelDef.FistRange = (float)row[c];
                            break;
                        }
                    }

                    if (id < 0)
                    {
                        throw new Exception("No ModelDefID found in db-data!");
                    }

                    modelDefByID.Add(id, modelDef);
                }

                // finalize initialization by adding ScriptOverlays and ScriptAniJobs
                foreach (var kv in overlayIDByModelDefID)
                {
                    var modelDefID = kv.Key;
                    var overlayIDs = kv.Value;
                    foreach (var overlayID in overlayIDs)
                    {
                        modelDefByID[modelDefID].AddOverlay(overlayByID[overlayID]);
                    }
                }

                foreach (var kv in aniJobIDByModelDefID)
                {
                    var modelDefID = kv.Key;
                    var remains    = new List <int>(kv.Value);
                    var added      = new List <int>(remains.Count);
                    int next;

                    while (remains.Count > 0)
                    {
                        var newlyAdded = new List <int>();
                        foreach (var r in remains)
                        {
                            // if ScriptAniJob has a followup animation
                            // and it is still missing from the current ModelDef
                            // then wait up until it possibly is
                            if (nextIDByAniJobID.TryGetValue(r, out next))
                            {
                                if (!added.Contains(next))
                                {
                                    continue;
                                }
                            }
                            // otherwise proceed with initialization
                            modelDefByID[modelDefID].AddAniJob(aniJobByID[r]);
                            newlyAdded.Add(r);
                        }
                        added.AddRange(newlyAdded);
                        remains = remains.Except(newlyAdded).ToList();
                        if (newlyAdded.Count < 1)
                        {
                            MakeLogError("Cannor resolve NextAni-dependencies"
                                         + " while adding ScriptAniJobs to ModelDef with database-id: " + modelDefID);
                        }
                    }
                }

                foreach (var kv in modelDefByID)
                {
                    kv.Value.Create();
                }
            }
            catch (Exception ex)
            {
                info = null;
                MakeLogError(ex);
                return(false);
            }
            finally { }

            return(true);
        }