Exemple #1
0
        void DisablePaintGunVanillaShoot()
        {
            // make the paintgun (which is a rifle) not be able to shoot normally, to avoid needing to add ammo back and skips that stupid hardcoded screen shake
            MyWeaponDefinition weaponDef = MyDefinitionManager.Static.GetWeaponDefinition(new MyDefinitionId(typeof(MyObjectBuilder_WeaponDefinition), Constants.PAINTGUN_WEAPONID));

            for (int i = 0; i < weaponDef.WeaponAmmoDatas.Length; i++)
            {
                MyWeaponDefinition.MyWeaponAmmoData ammoData = weaponDef.WeaponAmmoDatas[i];
                if (ammoData != null)
                {
                    ammoData.ShootIntervalInMiliseconds = int.MaxValue;
                }
            }
        }
        private void Init(IMyEntity Entity)
        {
            try
            {
                m_entity            = Entity;
                m_entityId          = Entity.EntityId;
                Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
                m_functionalBlock   = Entity as IMyFunctionalBlock;
                m_cubeBlock         = Entity as IMyCubeBlock;
                m_myCubeBlock       = Entity as MyCubeBlock;
                CubeGrid            = m_myCubeBlock.CubeGrid;
                _cubeGridEntityId   = CubeGrid.EntityId;
                m_terminalBlock     = Entity as IMyTerminalBlock;
                m_gunObject         = m_cubeBlock as IMyGunObject <MyGunBase>;

                MyWeaponBlockDefinition weaponBlockDef = null; Debug.Write($"def == null ? {weaponBlockDef == null}", 1, debug);
                MyDefinitionManager.Static.TryGetDefinition <MyWeaponBlockDefinition>(new SerializableDefinitionId(m_functionalBlock.BlockDefinition.TypeId, m_functionalBlock.BlockDefinition.SubtypeId), out weaponBlockDef);
                m_weaponDef = MyDefinitionManager.Static.GetWeaponDefinition(weaponBlockDef.WeaponDefinitionId); Debug.Write($"weaponDef == null ? {m_weaponDef == null}", 1, debug);
                Debug.Write($"Attempting to get magDefId from {m_weaponDef.AmmoMagazinesId[0]} ...", 1, debug);
                m_magDefId = m_weaponDef.AmmoMagazinesId[0]; Debug.Write($"Complete. magDefId == null ? {m_magDefId == null}", 1, debug);
                m_magDef   = MyDefinitionManager.Static.GetAmmoMagazineDefinition(m_magDefId); Debug.Write($"m_magDef == null ? {m_magDef == null}", 1, debug);
                Debug.Write($"m_weaponDef.WeaponAmmoDatas == null ? {m_weaponDef.WeaponAmmoDatas == null}", 1, debug);
                Debug.Write($"m_weaponDef.WeaponAmmoDatas.Count == {m_weaponDef.WeaponAmmoDatas.Count()}", 1, debug);

                MyWeaponDefinition.MyWeaponAmmoData data = null;
                var i = -1;
                while (i < m_weaponDef.WeaponAmmoDatas.Count() - 1)
                {
                    i++;
                    Debug.Write($"m_weaponDef.WeaponAmmoDatas[{i}] == null ? {m_weaponDef.WeaponAmmoDatas[i] == null }", 1, debug);
                    if (m_weaponDef.WeaponAmmoDatas[i] == null)
                    {
                        continue;
                    }

                    data = m_weaponDef.WeaponAmmoDatas[i];
                    break;
                }

                m_timeoutMult        = 60f / data.RateOfFire;
                m_chargeDefinitionId = m_magDefId;
                Debug.Write($"Attempting to get ammoDef from {m_magDef.AmmoDefinitionId} ...", 1, debug);
                var ammoDef = MyDefinitionManager.Static.GetAmmoDefinition(m_magDef.AmmoDefinitionId);
                Debug.Write($"Complete. ammoDef == null ? {ammoDef == null}", 1, debug);
                var damagePerShot = ammoDef.GetDamageForMechanicalObjects();
                Debug.Write($"Damage per shot = {damagePerShot}", 1, debug);

                m_heatPerShot = (damagePerShot + ammoDef.MaxTrajectory + ammoDef.DesiredSpeed) * 0.01f;
                m_heatMax     = m_cubeBlock.SlimBlock.MaxIntegrity;
                Debug.Write($"m_heatMax/m_heatPerShot = {m_heatMax}/{m_heatPerShot} = {m_heatMax / m_heatPerShot} shots", 1, debug);
                m_operationalPower = m_heatPerShot * 0.01f;
                m_maxAmmo          = (int)(m_heatMax / m_heatPerShot);

                m_inventory    = ((Sandbox.ModAPI.Ingame.IMyTerminalBlock)(Entity)).GetInventory(0) as IMyInventory;
                m_resourceSink = Entity.Components.Get <MyResourceSinkComponent>();

                if (!LogicCore.Instance.BeamLogics.ContainsKey(Entity.EntityId))
                {
                    LogicCore.Instance.BeamLogics.Add(Entity.EntityId, this);
                    Debug.Write("Added new beamlogic to BeamLogics dictionary.", 1, debug);
                }

                MyAPIGateway.Utilities.InvokeOnGameThread(() => RemoveSmokeEffects());
                m_terminalBlock.AppendingCustomInfo += AppendCustomInfo;
                m_initialized = true;
                Debug.Write("Weapon initialization complete.", 1, debug);
            }
            catch (Exception e)
            {
                Debug.HandleException(e);
                MyAPIGateway.Parallel.Sleep(1000);
                Init(Entity);
            }
        }