Example #1
0
        public static void RegisterTypeAdv <T>(System.Object dynv, string typename, string Helptext = "")
        {
            ScriptingCore.InfoLog("RegisterType with Advanced Object: " + typename);
            if (dynv == null)
            {
                ScriptingCore.DebugLogError("The type " + typename + " is null! ");
                throw new ArgumentNullException("The type of " + typename + " is null! ");
            }
            DynValue dynvalue = UserData.Create(dynv);

            try
            {
                UserData.RegisterType <T>();
            }
            catch { return; }
            if (ScriptingCore.typedict.ContainsKey(typename))
            {
                ScriptingCore.DebugLogError("The type " + typename + " is already registered skipping it! ");
            }
            else
            {
                if (dynvalue == null)
                {
                    ScriptingCore.DebugLogError("The  Dynvalue of " + typename + " is null! ");
                    throw new ArgumentNullException("The  Dynvalue of " + typename + " is null! ");
                }
                else
                {
                    ScriptingCore.typedict.Add(typename, dynvalue);
                }
            }
            AddHelpInfo <T>(typename, "Class: " + Helptext, false);
        }
Example #2
0
 public static Storage GetComponentStorage(GameObject go)
 {
     if (go == null)
     {
         ScriptingCore.DebugLogError("The GameObject is Null!");
     }
     return(go.AddOrGet <Storage>());
 }
Example #3
0
        public static BuildingDef GetBuildingDef(string prefab_id)
        {
            BuildingDef returndef = Assets.GetBuildingDef(prefab_id);

            if (returndef == null)
            {
                ScriptingCore.DebugLogError("GetBuildingDef for " + prefab_id + " could not be found!");
            }
            return(returndef);
        }
Example #4
0
        public static PrimaryElement GetBuildingPrimaryElement(GameObject prefab_id)
        {
            PrimaryElement returndef = prefab_id.GetComponent <PrimaryElement>();

            if (returndef == null)
            {
                ScriptingCore.DebugLogError("GetBuildingDef for " + prefab_id + " could not be found!");
            }
            return(returndef);
        }
Example #5
0
        public static BuildingDef GetBuildingDef(GameObject prefab_id)
        {
            BuildingDef returndef = prefab_id.GetComponent <BuildingDef>();

            if (returndef == null)
            {
                ScriptingCore.DebugLogError("GetBuildingDef for " + prefab_id + " could not be found!");
            }
            return(returndef);
        }
Example #6
0
        public static GameObject GetBuildingGameObject(string prefab_id)
        {
            GameObject returndef = Assets.GetPrefab(prefab_id);

            if (returndef == null)
            {
                ScriptingCore.DebugLogError("GameObject for " + prefab_id + " could not be found!");
            }
            return(returndef);
        }
        public static string GetRandomAvailableResearch()
        {
            int counter = 0;

            while (counter++ < 100)
            {
                var tech = Db.Get().Techs.resources.RandomElement();
                if (tech.ArePrerequisitesComplete() && !tech.IsComplete())
                {
                    return(tech.Id);
                }
            }
            ScriptingCore.DebugLogError("GetRandomAvailableResearch failed returning InteriorDecor ");
            return("InteriorDecor");
        }
Example #8
0
 public static void RegisterTypeAdv <T>(string typename, string Helptext = "")
 {
     ScriptingCore.InfoLog("RegisterType: " + typename);
     try
     {
         UserData.RegisterType <T>();
     }
     catch { ScriptingCore.InfoLog("RegisterType: " + typename + " failed! "); return; }
     if (ScriptingCore.typedirectdict.ContainsKey(typename))
     {
         ScriptingCore.DebugLogError("The type " + typename + " is already registered skipping it! ");
     }
     else
     {
         ScriptingCore.typedirectdict.Add(typename, typeof(T));
     }
     AddHelpInfo <T>(typename, "Class: " + Helptext, false);
 }
Example #9
0
 public static void RegisterType <T>(string typename, string Helptext = "") where T : new()
 {
     ScriptingCore.InfoLog("RegisterType: " + typename); DynValue dynv;
     try
     {
         UserData.RegisterType <T>();
         dynv = UserData.Create(new T());
     }
     catch { return; }
     if (ScriptingCore.typedict.ContainsKey(typename))
     {
         ScriptingCore.DebugLogError("The type " + typename + " is already registered skipping it! ");
     }
     else
     {
         ScriptingCore.typedict.Add(typename, dynv);
     }
     AddHelpInfo <T>(typename, "Class: " + Helptext, false);
 }
Example #10
0
        public static Component LuaGetComponent(GameObject go, string componentname)
        {
            Type t = LuaInterface.GetType(componentname);

            if (t == null)
            {
                LuaInterface.RegisterType(componentname);
                t = LuaInterface.GetType(componentname);
            }
            if (t == null)
            {
                ScriptingCore.DebugLogError("The Component " + componentname + " could not be found!");
            }
            if (go == null)
            {
                ScriptingCore.DebugLogError("The GameObject is Null!");
            }
            return(go.GetComponent(t));
        }
Example #11
0
 public void clonebuildindef(string buildingname, string clonename)
 {
     if (TagManager.GetProperName(clonename) != null)
     {
         ScriptingCore.DebugLogError(" The building cannot be cloned, the name " + clonename + " is already used.");
         return;
     }
     foreach (var i in configTable)
     {
         if (i.Value.PrefabID == buildingname)
         {
             clonebuildingdef = i.Value;
         }
     }
     if (clonebuildingdef == null)
     {
         ScriptingCore.DebugLogError(" The configTable did not contain, the name " + clonename + ".");
         return;
     }
 }
        public static bool SetResearchCost(string research, string costtype, float costamount)
        {
            if (Db.Get().Techs.resources == null)
            {
                return(false);
            }
            foreach (Tech techtoadd in Db.Get().Techs.resources)
            {
                if (techtoadd.Id == research)
                {
                    var res = Research.Instance.Get(techtoadd);

                    if (res.tech.costsByResearchTypeID.ContainsKey(costtype))
                    {
                        res.tech.costsByResearchTypeID[costtype] = costamount;
                    }
                    return(true);
                }
            }
            ScriptingCore.DebugLogError("SetResearchCost did not find: " + research);
            return(false);
        }
 public static bool AddResearch(string research)
 {
     foreach (Tech techtoadd in Db.Get().Techs.resources)
     {
         if (techtoadd.Id == research)
         {
             var res = Research.Instance.Get(techtoadd);
             var req = Research.Instance.Get(techtoadd).tech.requiredTech;
             foreach (var i in req)
             {
                 AddResearch(i.Id);
             }
             if (res == null)
             {
                 ScriptingCore.DebugLogError("AddResearch did not find: " + research);
                 return(false);
             }
             res.Purchased();
             return(true);
         }
     }
     ScriptingCore.DebugLogError("AddResearch did not find: " + research);
     return(false);
 }