Example #1
0
        protected override void UpdateAfterSim(int tick)
        {
            if (spawnedRifles.Count > 0)
            {
                for (int i = spawnedRifles.Count - 1; i >= 0; --i)
                {
                    IMyAutomaticRifleGun rifle = spawnedRifles[i];

                    if (!rifle.MarkedForClose && rifle.Owner != null)
                    {
                        AddTool(rifle);
                    }
                }

                spawnedRifles.Clear();

                if (Tools.Count == 0)
                {
                    SetUpdateMethods(UPDATE_METHODS, false);
                }
            }

            for (int i = Tools.Count - 1; i >= 0; --i)
            {
                PaintGunItem item = Tools[i];

                if (!item.UpdateSimulation())
                {
                    RemoveTool(item, i);
                    continue;
                }
            }
        }
Example #2
0
        void AddTool(IMyAutomaticRifleGun rifle)
        {
            PaintGunItem item = itemPool.Get();

            if (!item.Init(rifle))
            {
                itemPool.Return(item);
                return;
            }

            Tools.Add(item);
            ToolSpawned?.Invoke(item);

            SetUpdateMethods(UPDATE_METHODS, true);
        }
Example #3
0
        private void PreventIronSight()
        {
            IMyAutomaticRifleGun holdingTool = Main.LocalToolHandler?.LocalTool?.Rifle;

            if (holdingTool == null)
            {
                return;
            }

            // if the bind involves pressing rifle aim then revert action by doing it again.
            if (MyAPIGateway.Input.IsNewGameControlPressed(MyControlsSpace.SECONDARY_TOOL_ACTION))
            {
                holdingTool.EndShoot(MyShootActionEnum.SecondaryAction);

                holdingTool.Shoot(MyShootActionEnum.SecondaryAction, Vector3.Forward, null, null);
                holdingTool.EndShoot(MyShootActionEnum.SecondaryAction);
            }
        }
Example #4
0
        void EntityAdded(IMyEntity entity)
        {
            try
            {
                IMyAutomaticRifleGun rifle = entity as IMyAutomaticRifleGun;

                if (rifle != null && rifle.DefinitionId.SubtypeName == Constants.PAINTGUN_ID)
                {
                    if (spawnedRifles.Contains(rifle))
                    {
                        return;
                    }

                    spawnedRifles.Add(rifle);
                    SetUpdateMethods(UpdateFlags.UPDATE_AFTER_SIM, true);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Example #5
0
        /// <summary>
        /// Called when object is being retrieved from the pool.
        /// </summary>
        public bool Init(IMyAutomaticRifleGun entity)
        {
            if (entity == null)
            {
                throw new ArgumentException($"{GetType().Name} :: got created with null entity!");
            }

            Rifle = entity;

            if (!Rifle.TryGetSubpart("magazine", out MagazineSubpart))
            {
                throw new Exception($"PaintGun model doesn't have the expected magazine subpart, restarting game or re-subscribing to mod could fix.");
            }

            if (Rifle.GunBase == null)
            {
                throw new NullReferenceException($"{GetType().Name} :: Rifle.GunBase == null; ent={Rifle}; owner={Rifle.Owner}/{Rifle.OwnerIdentityId.ToString()}");
            }

            // HACK: prevent tool from ever reloading, which breaks animations for other things
            if (Rifle.GunBase.CurrentAmmo <= 0)
            {
                Rifle.GunBase.CurrentAmmo = 1;
            }

            if (Rifle.Owner == null)
            {
                Log.Error($"Can't find holder of a PaintGun entity because it's null! OwnerIdentityId={Rifle.OwnerIdentityId.ToString()} entId={Rifle.EntityId.ToString()}", Log.PRINT_MESSAGE);
                return(false);
            }

            if (MyAPIGateway.Multiplayer == null)
            {
                throw new NullReferenceException($"{GetType().Name} :: MyAPIGateway.Multiplayer == null");
            }

            if (MyAPIGateway.Session == null)
            {
                throw new NullReferenceException($"{GetType().Name} :: MyAPIGateway.Session == null");
            }

            IMyCharacter charEnt = MyAPIGateway.Session.ControlledObject as IMyCharacter;

            if (charEnt != null && charEnt == Rifle.Owner)
            {
                OwnerSteamId       = MyAPIGateway.Multiplayer.MyId;
                OwnerIsLocalPlayer = true;
            }

            if (OwnerSteamId == 0)
            {
                List <IMyPlayer> players = Main.Caches?.Players.Get();

                if (players == null)
                {
                    throw new NullReferenceException($"{GetType().Name} :: players cache is null");
                }

                if (MyAPIGateway.Players == null)
                {
                    throw new NullReferenceException($"{GetType().Name} :: MyAPIGateway.Players == null");
                }

                MyAPIGateway.Players.GetPlayers(players);

                foreach (IMyPlayer player in players)
                {
                    if (player?.Character != null && player.Character.EntityId == Rifle.Owner.EntityId)
                    {
                        OwnerSteamId = player.SteamUserId;
                        break;
                    }
                }

                Main.Caches.Players.Return(players);
            }

            if (OwnerSteamId == 0)
            {
                Log.Error($"Can't find holder of a PaintGun entity! entId={Rifle.EntityId.ToString()}", Log.PRINT_MESSAGE);
                return(false);
            }

            if (Main.Palette == null)
            {
                throw new NullReferenceException($"{GetType().Name} :: Palette == null");
            }

            OwnerInfo = Main.Palette.GetOrAddPlayerInfo(OwnerSteamId);

            if (OwnerInfo == null)
            {
                throw new NullReferenceException($"{GetType().Name} :: OwnerInfo == null");
            }

            OwnerInfo.ColorSlotSelected    += OwnerColorSlotSelected;
            OwnerInfo.ColorListChanged     += OwnerColorListChanged;
            OwnerInfo.SkinSelected         += OwnerSkinSelected;
            OwnerInfo.ApplyColorChanged    += OwnerPaletteUpdate;
            OwnerInfo.ApplySkinChanged     += OwnerPaletteUpdate;
            OwnerInfo.ColorPickModeChanged += OwnerColorPickModeChanged;

            UpdatePaintCanMaterial();
            return(true);
        }
Example #6
0
 public void HolsterTool()
 {
     holdingTool = null;
     selectedVoxelMap = null;
     SetCrosshairColor(null);
     toolStatus?.Hide();
 }
Example #7
0
        public void DrawTool(IMyAutomaticRifleGun gun)
        {
            holdingTool = gun;
            lastShotTick = gun.GunBase.LastShootTime.Ticks;

            if(toolStatus == null)
                toolStatus = Utilities.CreateNotification("", 500, MyFontEnum.White);

            SetToolStatus("For key combination help, type in chat: /concrete help", MyFontEnum.Blue, 1000);
        }