Example #1
0
        protected static void reflectiveInit(SkillFile sf)
        {
            // create instances
            foreach (AbstractStoragePool t in sf.allTypesStream())
            {
                try
                {
                    for (int j = reflectiveInitSize; j != 0; j--)
                    {
                        t.make();
                    }
                }
                catch (SkillException e)
                {
                    // the type can not have more instances
                }
            }

            // set fields
            foreach (AbstractStoragePool t in sf.allTypesStream())
            {
                foreach (SkillObject o in t)
                {
                    StaticFieldIterator it = t.fields();
                    while (it.hasNext())
                    {
                        AbstractFieldDeclaration f = it.next();
                        if (!(f is IAutoField) && !(f.Type is IConstantIntegerType) && !(f is InterfaceField))
                        {
                            set <object, SkillObject>(sf, o, f);
                        }
                    }
                }
            }
        }
Example #2
0
        private static void set <T, Obj>(SkillFile sf, Obj o, AbstractFieldDeclaration f) where Obj : SkillObject
        {
            T v = value <T>(sf, ([email protected])f.Type);

            // System.out.printf("%s#%d.%s = %s\n", o.getClass().getName(),
            // o.getSkillID(), f.name(), v.toString());
            o.set(f, v);
        }
Example #3
0
 public static void InitSkill()
 {
     string[] skills = Directory.GetFiles(SKL_PATH, DATAEXT);
     SKILLS = new List <Skill>();
     foreach (string path in skills)
     {
         SkillFile sf = new SkillFile(path);
         SKILLS.AddRange(sf.skills);
     }
 }
Example #4
0
 public static void forceFullCheck(SkillFile skillFile)
 {
     loadAll(skillFile);
     try
     {
         skillFile.check();
     }
     catch (SkillException e)
     {
         // convert to parse exception
         throw new ParseException(e, "a check failed");
     }
 }
Example #5
0
 public static void loadAll(SkillFile skillFile)
 {
     foreach (IAccess t in skillFile.allTypes())
     {
         StaticFieldIterator fs = t.fields();
         while (fs.hasNext())
         {
             AbstractFieldDeclaration f = fs.next();
             if (f is ILazyField)
             {
                 ((ILazyField)f).ensureLoaded();
             }
         }
     }
 }
Example #6
0
        ///////////////////////////////////////////////////
        // Member Functions
        ///////////////////////////////////////////////////
        /// <summary>
        /// Loads all game assets
        /// </summary>
        public bool load(CfgInfo zoneConf, string configFilename)
        {
            _singleton = this;

            _assetList = new List <AssetInfo>();

            //Add the game config
            addAssetData(AssetFileFactory.CreateFromFile <AssetFile>(configFilename));

            //Load shit up
            ItemFile    itms = AssetFileFactory.CreateFromFile <ItemFile>(zoneConf.level.itmFile);
            LioFile     lios = AssetFileFactory.CreateFromFile <LioFile>(zoneConf.level.lioFile);
            SkillFile   rpgs = AssetFileFactory.CreateFromFile <SkillFile>(zoneConf.level.rpgFile);
            VehicleFile vehs = AssetFileFactory.CreateFromFile <VehicleFile>(zoneConf.level.vehFile);
            LevelFile   lvl  = AssetFileFactory.CreateFromFile <LevelFile>(zoneConf.level.lvlFile);

            if (itms == null || lios == null || rpgs == null || vehs == null || lvl == null)
            {                   //Missing a core file
                foreach (string missing in AssetFileFactory._missingFiles)
                {
                    Log.write(TLog.Error, "Missing file: {0}", missing);
                }
                return(false);
            }

            Level = lvl.Data;

            //Save checksums to send to clients
            addAssetData(itms);
            addAssetData(lios);
            addAssetData(rpgs);
            addAssetData(vehs);
            addAssetData(lvl);

            //Make item maps
            _idToItem   = new SortedDictionary <int, ItemInfo>();
            _nameToItem = new SortedDictionary <string, ItemInfo>();
            foreach (ItemInfo it in itms.Data)
            {
                _idToItem.Add(it.id, it);
            }
            foreach (ItemInfo it in itms.Data)
            {
                if (!_nameToItem.ContainsKey(it.name.ToLower()))
                {
                    _nameToItem.Add(it.name.ToLower(), it);
                }
            }

            //Make skill maps
            _idToSkill   = new SortedDictionary <int, SkillInfo>();
            _nameToSkill = new SortedDictionary <string, SkillInfo>();
            foreach (SkillInfo it in rpgs.Data)
            {
                _idToSkill.Add(it.SkillId, it);
            }
            foreach (SkillInfo it in rpgs.Data)
            {
                if (!_nameToSkill.ContainsKey(it.Name.ToLower()))
                {
                    _nameToSkill.Add(it.Name.ToLower(), it);
                }
            }

            //Make lio map
            _idToLio = new SortedDictionary <int, LioInfo>();
            foreach (LioInfo it in lios.Data)
            {
                _idToLio.Add(it.GeneralData.Id, it);
            }

            //Load blo files
            _bloList = new List <string>();

            foreach (string file in ItemInfo.BlobsToLoad)
            {
                loadBloFile(file + ".blo");
            }
            foreach (string file in CfgInfo.BlobsToLoad)
            {
                loadBloFile(file + ".blo");
            }
            foreach (string file in LioInfo.BlobsToLoad)
            {
                loadBloFile(file + ".blo");
            }
            foreach (string file in SkillInfo.BlobsToLoad)
            {
                loadBloFile(file + ".blo");
            }
            foreach (LvlInfo.BlobReference blob in Level.ObjectBlobs)
            {
                loadBloFile(blob.FileName);
            }
            foreach (LvlInfo.BlobReference blob in Level.FloorBlobs)
            {
                loadBloFile(blob.FileName);
            }

            //Make vehicle map
            _idToVehicle = new SortedDictionary <int, VehInfo>();
            foreach (VehInfo it in vehs.Data)
            {
                _idToVehicle.Add(it.Id, it);
                foreach (string blo in it.blofiles)
                {
                    loadBloFile(blo + ".blo");
                }
            }
            foreach (string blo in _bloList)
            {                   //Attempt to load it
                BloFile blof = AssetFileFactory.LoadBlobFromFile <BloFile>(blo);
                if (blof != null)
                {
                    addAssetData(blof);
                }
            }

            //For debugging
            _bloList.Sort();
            _bloListFileName = "bloList_" + configFilename + ".txt";
            System.IO.File.WriteAllLines(string.Format("{0}/{1}", Environment.CurrentDirectory, _bloListFileName), _bloList);

            //Update our asset server
            sendDataToDirectory();

            //Initialize our lio data
            Lios = new Lio(this);

            //Load news file
            AssetFile nws = AssetFileFactory.CreateFromFile <AssetFile>(zoneConf.level.nwsFile);

            if (nws != null)
            {
                addAssetData(nws);
            }

            //Load the helpMenu files
            for (int i = 0; i <= zoneConf.helpMenu.links.Count - 1; i++)
            {
                AssetFile helpMenu = AssetFileFactory.CreateFromFile <AssetFile>(zoneConf.helpMenu.links[i].name);
                if (helpMenu != null)
                {
                    addAssetData(helpMenu);
                }
            }

            //Load everything else
            loadAdditionalAssets();

            //Are we missing files?
            if (AssetFileFactory.IsIncomplete)
            {                   //Missing a core file
                foreach (string missing in AssetFileFactory._missingFiles)
                {
                    Log.write(TLog.Error, "Missing file: {0}", missing);
                }
                return(false);
            }

            //Cache all our assets
            AssetCache = new Cache(this);
            AssetCache.prepareCache(_assetList);
            return(true);
        }
Example #7
0
        /**
         * unchecked, because the insane amount of casts is necessary to reflect the
         * implicit value based type system
         */
        private static T value <T>(SkillFile sf, [email protected] type)
        {
            if (type is IGeneralAccess)
            {
                // get a random object
                IEnumerator @is = ((IGeneralAccess)type).GetEnumerator();
                for (int i = new Random().Next(reflectiveInitSize) % 200; i != 0; i--)
                {
                    @is.MoveNext();
                }
                return((T)@is.Current);
            }

            switch (type.TypeID)
            {
            case 5:
                // random type
                IEnumerator ts = sf.allTypes().GetEnumerator();
                ts.MoveNext();
                IAccess t = (IAccess)ts.Current;
                for (int i = new Random().Next(200); i != 0 && ts.MoveNext(); i--)
                {
                    t = (IAccess)ts.Current;
                }

                // random object
                IEnumerator @is = t.GetEnumerator();
                for (int i = new Random().Next(Math.Min(200, reflectiveInitSize)); i != 0; i--)
                {
                    @is.MoveNext();
                }
                @is.MoveNext();
                return((T)@is.Current);

            case 6:
                return((T)(object)(Boolean)(new Random().Next(1) != 0));

            case 7:
                return((T)(object)(SByte) new Random().Next(reflectiveInitSize));

            case 8:
                return((T)(object)(Int16) new Random().Next(reflectiveInitSize));

            case 9:
                return((T)(object)(Int32) new Random().Next(reflectiveInitSize));

            case 10:
            case 11:
                return((T)(object)(Int64)(new Random().Next() % reflectiveInitSize));

            case 12:
                return((T)(object)(Single) new Random().NextDouble());

            case 13:
                return((T)(object)(Double) new Random().NextDouble());

            case 14:
                return((T)(object)"☢☢☢");

            case 15:
            {
                IConstantLengthArray cla  = (IConstantLengthArray)type;
                ArrayList            rval = new ArrayList(cla.GetLength());
                for (int i = cla.GetLength(); i != 0; i--)
                {
                    rval.Add(value <object>(sf, cla.GetGroundType()));
                }
                return((T)(object)rval);
            }

            case 17:
            {
                ISingleArgumentType cla = (ISingleArgumentType)type;
                int       length        = (int)Math.Sqrt(reflectiveInitSize);
                ArrayList rval          = new ArrayList(length);
                while (0 != length--)
                {
                    rval.Add(value <object>(sf, cla.GetGroundType()));
                }
                return((T)(object)rval);
            }

            case 18:
            {
                ISingleArgumentType cla = (ISingleArgumentType)type;
                int           length    = (int)Math.Sqrt(reflectiveInitSize);
                List <Object> rval      = new List <Object>();
                while (0 != length--)
                {
                    rval.Add(value <object>(sf, cla.GetGroundType()));
                }
                return((T)(object)rval);
            }

            case 19:
            {
                ISingleArgumentType cla = (ISingleArgumentType)type;
                int length            = (int)Math.Sqrt(reflectiveInitSize);
                HashSet <Object> rval = new HashSet <Object>();
                while (0 != length--)
                {
                    rval.Add(value <object>(sf, cla.GetGroundType()));
                }
                return((T)(object)rval);
            }

            case 20:
                return((T)(object)new Dictionary <Object, Object>());

            default:
                throw new Exception();
            }
        }