Esempio n. 1
0
        private void Log_LogReceived(LogSeverity severity, DateTime timestamp, string message)
        {
            switch (severity)
            {
            case LogSeverity.Critical: EmpyrionApi?.LogError(message); break;

            case LogSeverity.Debug: EmpyrionApi?.Log(message); break;

            case LogSeverity.Info: EmpyrionApi?.Log(message); break;

            case LogSeverity.Warn: EmpyrionApi?.LogWarning(message); break;
            }
        }
Esempio n. 2
0
        public void Init(IModApi modAPI)
        {
            ModApi = modAPI;

            ModApi.Log("EmpyrionScripting Mod started: IModApi");
            try
            {
                SetupHandlebarsComponent();

                SaveGameModPath = Path.Combine(ModApi.Application?.GetPathFor(AppFolder.SaveGame), "Mods", EmpyrionConfiguration.ModName);
                ModApi.Application.GameEntered += Application_GameEntered;

                LoadConfiguration();
                SaveGamesScripts = new SaveGamesScripts(modAPI)
                {
                    SaveGameModPath = SaveGameModPath
                };
                SaveGamesScripts.ReadSaveGamesScripts();

                TaskTools.Log = ModApi.LogError;
                StaticCsCompiler.CsCompiler.Log = Log;

                CsCompiler = new CsCompiler.CsCompiler(SaveGameModPath);
                CsCompiler.ConfigurationChanged += CsCompiler_ConfigurationChanged;

                ModApi.Application.OnPlayfieldLoaded    += Application_OnPlayfieldLoaded;
                ModApi.Application.OnPlayfieldUnloading += Application_OnPlayfieldUnloading;

                StopScriptsEvent += (S, E) =>
                {
                    PlayfieldData?.Values.ForEach(P =>
                    {
                        ModApi.Log($"StopScriptsEvent: ({P.PlayfieldName}) {(P.PauseScripts ? "always stopped" : "scripts running")}");
                        P.PauseScripts = true;
                    });
                };

                StartAllScriptsForPlayfieldServer();
            }
            catch (Exception error)
            {
                ModApi.LogError($"EmpyrionScripting Mod init finish: {error}");
            }

            ModApi.Log("EmpyrionScripting Mod init finish");
        }
Esempio n. 3
0
        void IMod.Init(IModApi modAPI)
        {
            modApi            = modAPI;
            modApi.GameEvent += EventGame;

            modApi.Application.OnPlayfieldLoaded    += OnLoadedPlayfield;
            modApi.Application.OnPlayfieldUnloading += OnUnLoadedPlayfield;
            modApi.Application.GameEntered          += EnteredGame;
            modApi.Application.Update += UpdateAll;
            modApi.Log("ModApi Loaded");
            Console.WriteLine("ModApi Loaded");
        }
        public void Init(IModApi modAPI)
        {
            ModApi = modAPI;

            ModApi.Log("EmpyrionScripting Mod started: IModApi");
            try
            {
                SetupHandlebarsComponent();

                Localization    = new Localization(ModApi.Application?.GetPathFor(AppFolder.Content));
                ItemInfos       = new ItemInfos(ModApi.Application?.GetPathFor(AppFolder.Content), Localization);
                SaveGameModPath = Path.Combine(ModApi.Application?.GetPathFor(AppFolder.SaveGame), "Mods", EmpyrionConfiguration.ModName);

                LoadConfiguration();
                SaveGamesScripts = new SaveGamesScripts(modAPI)
                {
                    SaveGameModPath = SaveGameModPath
                };
                SaveGamesScripts.ReadSaveGamesScripts();

                TaskTools.Log = ModApi.LogError;

                ModApi.Application.OnPlayfieldLoaded   += Application_OnPlayfieldLoaded;
                ModApi.Application.OnPlayfieldUnloaded += Application_OnPlayfieldUnloaded;

                StopScriptsEvent += (S, E) =>
                {
                    ModApi.Log($"StopScriptsEvent: {(PauseScripts ? "always stopped" : "scripts running")}");
                    PauseScripts = true;
                };

                StartAllScriptsForPlayfieldServer();
            }
            catch (Exception error)
            {
                ModApi.LogError($"EmpyrionScripting Mod init finish: {error}");
            }

            ModApi.Log("EmpyrionScripting Mod init finish");
        }
Esempio n. 5
0
        //check for newly placed or removed lcds
        //the timer for this should be biggish as all this is expensive
        internal void LCDScan(bool bCheckBlockDestroyed, IModApi api, float blockDist)
        {
            if (bCheckBlockDestroyed)
            {
                CheckAssociatedLCDs(api);
            }

            if (mStruct == null)
            {
                api.Log("Null struct in player struct list!");
                return;
            }
            if (!mStruct.IsReady)
            {
                api.Log("Struct: " + mStruct + " not ready...");
                return;
            }
            if (!mStruct.IsPowered)
            {
                //api.Log("Struct: " + mStruct + " not powered...");
                return;
            }

            /*
             * string	[]dTypeNames	=mStruct.GetDeviceTypeNames();
             * foreach(string dname in dTypeNames)
             * {
             *      api.Log("Device: " + dname);
             * }*/

            IDevicePosList idplAmmo      = mStruct.GetDevices("AmmoCntr");
            IDevicePosList idplContainer = mStruct.GetDevices("Container");
            IDevicePosList idplFridge    = mStruct.GetDevices("Fridge");
            IDevicePosList idplHarvest   = mStruct.GetDevices("HarvestCntr");

            CheckLCD(api, idplAmmo, idplContainer, idplFridge, idplHarvest, blockDist);
        }
Esempio n. 6
0
        const int BatteryCheckInterval = 25000;                 //in MS


        public void Init(IModApi modAPI)
        {
            mAPI = modAPI;

            mAPI.Log("SolarHelperNewAPI: Init called.");

            mAPI.GameEvent += OnGameEvent;
            mAPI.Application.OnPlayfieldLoaded   += OnPlayFieldLoaded;
            mAPI.Application.OnPlayfieldUnloaded += OnPlayFieldUnLoaded;
            mAPI.Application.GameEntered         += OnGameEntered;

            mBatTimer = new Timer(BatteryCheckInterval);

            mBatTimer.Elapsed  += OnBatteryTimer;
            mBatTimer.AutoReset = true;
            mBatTimer.Start();
        }
Esempio n. 7
0
        public void Init(IModApi modAPI)
        {
            mAPI = modAPI;

            mAPI.Log("LCDMagicNewAPI: Init called.");

            mAPI.GameEvent += OnGameEvent;
            mAPI.Application.OnPlayfieldLoaded   += OnPlayFieldLoaded;
            mAPI.Application.OnPlayfieldUnloaded += OnPlayFieldUnLoaded;
            mAPI.Application.GameEntered         += OnGameEntered;

            LoadConstants();

            StartTimer(ref mLCDScanTimer, "LCDScanInterval", OnLCDScanTimer);
            StartTimer(ref mContainerTimer, "ContainerUpdateInterval", OnContainerTimer);
            StartTimer(ref mAmmoTimer, "AmmoUpdateInterval", OnAmmoTimer);
            StartTimer(ref mFridgeTimer, "FridgeUpdateInterval", OnFridgeTimer);
            StartTimer(ref mSpecialTimer, "SpecialUpdateInterval", OnSpecialTimer);
        }
Esempio n. 8
0
        public void Init(IModApi modAPI)
        {
            ModAPI = modAPI;

            Interlocked.Increment(ref inst);

            ModAPI.Log($"LoadMod(Init)[{inst}]");

            try
            {
                if (mSingleIModInstance != null)
                {
                    mSingleIModInstance.Init(ModAPI);
                }
                else
                {
                    IMods.ForEach(M => M.Init(ModAPI));
                }
            }
            catch (Exception error)
            {
                ModAPI.LogError($"LoadMod(Init): error : {error}");
            }
        }
Esempio n. 9
0
        public void Shutdown()
        {
            mAPI.Log("SolarHelperNewAPI: Shutdown called.");

            mAPI.GameEvent -= OnGameEvent;
            mAPI.Application.OnPlayfieldLoaded   -= OnPlayFieldLoaded;
            mAPI.Application.OnPlayfieldUnloaded -= OnPlayFieldUnLoaded;
            mAPI.Application.GameEntered         -= OnGameEntered;
        }
Esempio n. 10
0
 void OnLoadedPlayfield(IPlayfield playfield)
 {
     playfield.SpawnTestPlayer(new Vector3(0, 0, 0));
     modApi.Log("Test Player Spawned");
 }
Esempio n. 11
0
        //normally called when a block is deleted
        void CheckAssociatedLCDs(IModApi api)
        {
            List <IDevice> toNuke = new List <IDevice>();

            //check ammo
            ConfirmStillThere(mAmmoLCD, toNuke);

            //check container
            ConfirmStillThere(mContainerLCD, toNuke);

            //check fridge
            ConfirmStillThere(mFridgeLCD, toNuke);

            //check harvest
            ConfirmStillThere(mHarvestLCD, toNuke);

            //check tanks
            ConfirmStillThere(mTankLCDs, toNuke);

            //check farm
            ConfirmStillThere(mFarmLCDs, toNuke);

            if (toNuke.Count <= 0)
            {
                return;
            }

            api.Log("CheckAssociatedLCDs found " + toNuke.Count + " nuked items...");

            for (int i = 0; i < toNuke.Count; i++)
            {
                if (toNuke[i] is ILcd)
                {
                    ILcd lcd = toNuke[i] as ILcd;

                    NukeLCD(mAmmoLCD, lcd);
                    NukeLCD(mContainerLCD, lcd);
                    NukeLCD(mFridgeLCD, lcd);
                    NukeLCD(mHarvestLCD, lcd);
                    NukeLCD(mTankLCDs, lcd);
                    NukeLCD(mFarmLCDs, lcd);
                }
                else if (toNuke[i] is IContainer)
                {
                    IContainer con = toNuke[i] as IContainer;
                    ILcd       lcd = null;

                    if (mAmmoLCD.ContainsKey(con))
                    {
                        lcd = mAmmoLCD[con];
                        mAmmoLCD.Remove(con);
                    }
                    if (mContainerLCD.ContainsKey(con))
                    {
                        lcd = mContainerLCD[con];
                        mContainerLCD.Remove(con);
                    }
                    if (mFridgeLCD.ContainsKey(con))
                    {
                        lcd = mFridgeLCD[con];
                        mFridgeLCD.Remove(con);
                    }
                    if (mHarvestLCD.ContainsKey(con))
                    {
                        lcd = mHarvestLCD[con];
                        mHarvestLCD.Remove(con);
                    }

                    //make sure if one device is gone
                    //to remove the associated stuff as well
                    if (lcd != null)
                    {
                        mDevicePositions.Remove(lcd);
                        mDeviceBlocks.Remove(lcd);
                        mDevicePositions.Remove(con);
                        mDeviceBlocks.Remove(con);
                    }
                }
            }
        }
Esempio n. 12
0
        void CheckLCD(IModApi api, IDevicePosList ammo, IDevicePosList container,
                      IDevicePosList fridge, IDevicePosList harvest, float blockScanDist)
        {
            IDevicePosList idpl = mStruct.GetDevices("LCD");

            for (int i = 0; i < idpl.Count; i++)
            {
                VectorInt3 pos = idpl.GetAt(i);

                ILcd lcd = mStruct.GetDevice <ILcd>(pos);

                if (mAmmoLCD.ContainsValue(lcd))
                {
                    continue;                           //already in use
                }
                if (mContainerLCD.ContainsValue(lcd))
                {
                    continue;                           //already in use
                }
                if (mFridgeLCD.ContainsValue(lcd))
                {
                    continue;                           //already in use
                }
                if (mHarvestLCD.ContainsValue(lcd))
                {
                    continue;                           //already in use
                }

                api.Log("Unattached LCD Device at pos: " + pos);

                //find the closest device within BlockScanDistance
                float      blockDist = blockScanDist;
                float      bestDist  = float.MaxValue;
                VectorInt3 bestPos   = new VectorInt3(-1, -1, -1);
                int        bestType  = -1;
                IDevice    assoc     = null;

                for (int j = 0; j < ammo.Count; j++)
                {
                    VectorInt3 pos2 = ammo.GetAt(j);

                    float dist = VecDistance(pos, pos2);
                    if (dist < blockDist && dist < bestDist)
                    {
                        assoc    = mStruct.GetDevice <IContainer>(pos2);
                        bestDist = dist;
                        bestType = 0;
                        bestPos  = pos2;
                    }
                }

                for (int j = 0; j < container.Count; j++)
                {
                    VectorInt3 pos2 = container.GetAt(j);

                    float dist = VecDistance(pos, pos2);
                    if (dist < blockDist && dist < bestDist)
                    {
                        assoc    = mStruct.GetDevice <IContainer>(pos2);
                        bestDist = dist;
                        bestType = 1;
                        bestPos  = pos2;
                    }
                }

                for (int j = 0; j < fridge.Count; j++)
                {
                    VectorInt3 pos2 = fridge.GetAt(j);

                    float dist = VecDistance(pos, pos2);
                    if (dist < blockDist && dist < bestDist)
                    {
                        assoc    = mStruct.GetDevice <IContainer>(pos2);
                        bestDist = dist;
                        bestType = 2;
                        bestPos  = pos2;
                    }
                }

                for (int j = 0; j < harvest.Count; j++)
                {
                    VectorInt3 pos2 = harvest.GetAt(j);

                    float dist = VecDistance(pos, pos2);
                    if (dist < blockDist && dist < bestDist)
                    {
                        assoc    = mStruct.GetDevice <IContainer>(pos2);
                        bestDist = dist;
                        bestType = 3;
                        bestPos  = pos2;
                    }
                }

                IBlock lcdBlock = mStruct.GetBlock(pos);

                if (assoc == null)
                {
                    api.Log("Null Assoc");

                    //maybe since this isn't near a device
                    //it can be used for fuel or something
                    CheckForSpecialLCD(lcdBlock, lcd);
                    continue;
                }

                if (!mDevicePositions.ContainsKey(lcd))
                {
                    mDevicePositions.Add(lcd, pos);
                }
                if (!mDevicePositions.ContainsKey(assoc))
                {
                    mDevicePositions.Add(assoc, bestPos);
                }

                IBlock devBlock = mStruct.GetBlock(bestPos);

                if (lcdBlock == null)
                {
                    api.Log("Null block for lcd!");
                }
                else
                {
                    if (mDeviceBlocks.ContainsKey(lcd))
                    {
                        api.Log("BadCleanup!  Device blocks already has lcd: " + lcd + "!!");
                    }
                    else
                    {
                        mDeviceBlocks.Add(lcd, lcdBlock);
                    }
                }

                if (devBlock == null)
                {
                    api.Log("Null block for device!");
                }
                else
                {
                    if (mDeviceBlocks.ContainsKey(assoc))
                    {
                        api.Log("BadCleanup!  Device blocks already has assoc: " + assoc + "!!");
                    }
                    else
                    {
                        mDeviceBlocks.Add(assoc, devBlock);
                    }
                }

                if (bestType == 0)
                {
                    api.Log("Ammo Assoc");
                    mAmmoLCD.Add(assoc as IContainer, lcd);
                }
                else if (bestType == 1)
                {
                    api.Log("Con Assoc");
                    mContainerLCD.Add(assoc as IContainer, lcd);
                }
                else if (bestType == 2)
                {
                    api.Log("Fridge Assoc");
                    mFridgeLCD.Add(assoc as IContainer, lcd);
                }
                else if (bestType == 3)
                {
                    api.Log("Harv Assoc");
                    mHarvestLCD.Add(assoc as IContainer, lcd);
                }
            }
        }
 private void _nlogMemoryTarget_OnLog(object sender, string e) => _modApi.Log(e);