Beispiel #1
0
        public override void LoadData()
        {
            // amogst the earliest execution points, but not everything is available at this point.

            // These can be used anywhere, not just in this method/class:
            // MyAPIGateway. - main entry point for the API
            // MyDefinitionManager.Static. - reading/editing definitions
            // MyGamePruningStructure. - fast way of finding entities in an area
            // MyTransparentGeometry. and MySimpleObjectDraw. - to draw sprites (from TransparentMaterials.sbc) in world (they usually live a single tick)
            // MyVisualScriptLogicProvider. - mainly designed for VST but has its uses, use as a last resort.
            // System.Diagnostics.Stopwatch - for measuring code execution time.
            // ...and many more things, ask in #programming-modding in keen's discord for what you want to do to be pointed at the available things to use.

            Instance = this;
            InitLogger();

            InitNetwork();
            if (MyAPIGateway.Multiplayer.IsServer)
            {
                BuildCushioningCache(settings_);
            }
            if (!MyAPIGateway.Utilities.IsDedicated)
            {
                hud = new HUDManager();
            }
            InitPlayerManager();

            if (IsMPHost || MyAPIGateway.Utilities.IsDedicated)
            {
                InitPlayerEvents();
            }

            InitAPI();

            if (MyAPIGateway.Multiplayer.IsServer)
            {
                if (!MyAPIGateway.Utilities.IsDedicated)
                {
                    player_.OnJuiceAvalChanged += (p, aval) => hud.CurrJuiceAvalPercent = aval * 100.0;
                }

                storage_for_keen_whitelist_bs_lambda_for_medbay_usage_ = (pid, type, amount) => OnPlayerHealthRecharge(pid, (int)type, amount);
                MyVisualScriptLogicProvider.PlayerHealthRecharging    += storage_for_keen_whitelist_bs_lambda_for_medbay_usage_;
                MyVisualScriptLogicProvider.PlayerSpawned += OnPlayerSpawn;
            }
            else
            {
                player_.OnJuiceAvalChanged += (p, aval) => Net.NetworkAPI.Instance.SendCommand(BOTTLES_UPDATE, data: MyAPIGateway.Utilities.SerializeToBinary(aval * 100.0), steamId: p.SteamUserId);
            }

            cmd_handler_.OnToggleDebug += (debug) =>
            {
                debug_enabled_ = debug;
            };
        }
Beispiel #2
0
        protected override void UnloadData()
        {
            // executed when world is exited to unregister events and stuff

            Instance = null; // important for avoiding this object to remain allocated in memory

            if (IsMPHost || MyAPIGateway.Utilities.IsDedicated)
            {
                MyVisualScriptLogicProvider.PlayerConnected    -= OnPlayerConnect;
                MyVisualScriptLogicProvider.PlayerDisconnected -= OnPlayerDC;
            }
            if (storage_for_keen_whitelist_bs_lambda_for_medbay_usage_ != null)
            {
                MyVisualScriptLogicProvider.PlayerHealthRecharging -= storage_for_keen_whitelist_bs_lambda_for_medbay_usage_;
            }
            hud?.Dispose();
        }
Beispiel #3
0
        private double CalcAccelDamage(IMyCubeBlock parent, float accel, Settings settings)
        {
            var cushionFactor = 0f;

            if (parent != null)
            {
                CushioningMultipliers.TryGetValue(DeadlyAccelSession.FormatCushionLookup(parent.BlockDefinition.TypeId.ToString(), parent.BlockDefinition.SubtypeId), out cushionFactor);
            }
            if (accel > settings.SafeMaximum)
            {
                var rem_accel = (accel - settings.SafeMaximum);
                var dmg       = Math.Pow(rem_accel, settings.DamageScaleBase);
                dmg *= (1 - cushionFactor);
                return(dmg);
            }
            return(0.0);
        }