示例#1
0
        public static void LoadGunLockers()
        {
            try
            {
                string gunLockersPath = Path.Combine("scripts", Constants.SaveFolder);
                if (Directory.Exists(gunLockersPath))
                {
                    string[] files = Directory.GetFiles(gunLockersPath, "*.xml", SearchOption.TopDirectoryOnly);
                    foreach (string file in files)
                    {
                        try
                        {
                            Locker tempLocker = XmlUtil.Deserialize <Locker>(File.ReadAllText(file));
                            tempLocker.CreateProp();

                            Main.GunLockers.Add(tempLocker.ID, tempLocker);
                        }
                        catch (Exception e)
                        {
                            UI.Notify($"~r~SPGunLocker reading error: {e.Message} ({file})");
                        }
                    }
                }
                else
                {
                    Directory.CreateDirectory(gunLockersPath);
                }
            }
            catch (Exception e)
            {
                UI.Notify($"~r~SPGunLocker loading error: {e.Message}");
            }
        }
示例#2
0
        public void Script_Tick(object sender, EventArgs e)
        {
            // Workaround for gun locker props not being created on mod init
            if (!GunLockersLoaded && !Game.IsLoading && Game.Player.CanControlCharacter)
            {
                GunLockersLoaded = true;
                Methods.LoadAddonWeapons();
                Methods.LoadGunLockers();
            }

            // Process script menus
            SPGLMenuPool.ProcessMenus();

            int gameTime = Game.GameTime;

            if (gameTime - LastHeartbeat >= Constants.HeartbeatInterval)
            {
                // Find the closest gun locker
                InteractableLockerGuid = Game.Player.Character.IsOnFoot ? Methods.FindInteractableGunLocker(Game.Player.Character.Position) : null;

                // Hide the menus if the player can't interact with a gun locker
                if (InteractableLockerGuid == null && SPGLMenuPool.IsAnyMenuOpen())
                {
                    SPGLMenuPool.CloseAllMenus();
                }

                LastHeartbeat = gameTime;
            }

            // Draw a helptext if the player can interact with a gun locker
            if (InteractableLockerGuid != null && !SPGLMenuPool.IsAnyMenuOpen())
            {
                Methods.DisplayHelpText($"Press {HelpTextKeys.Get(InteractionControl)} to interact with the Gun Locker.");
            }

            // Handle script controls
            if (Game.IsControlJustPressed(2, (Control)InteractionControl))
            {
                if (InteractableLockerGuid != null && GunLockers.ContainsKey(InteractableLockerGuid.Value))
                {
                    if (SPGLMenuPool.IsAnyMenuOpen())
                    {
                        SPGLMenuPool.CloseAllMenus();
                    }
                    else
                    {
                        SPGLMainMenu.RefreshIndex();
                        SPGLSellConfirmationMenu.RefreshIndex();
                        SPGLMainMenu.Visible = true;

                        // Update the weapons menu
                        SPGLWeaponsMenu.Clear();

                        for (int i = 0; i < Constants.MaxWeapons; i++)
                        {
                            string title = $"Empty Slot ({Methods.GetSlotWeaponType(i)})";

                            if (GunLockers[InteractableLockerGuid.Value].Weapons[i] != null)
                            {
                                title = Weapons.GetDisplayName(GunLockers[InteractableLockerGuid.Value].Weapons[i].Hash);
                            }

                            SPGLWeaponsMenu.AddItem(new UIMenuItem(title));
                        }

                        // Update the refund menu price
                        SPGLSellConfirmationMenu.MenuItems[0].SetRightLabel($"~HUD_COLOUR_GREENDARK~${GunLockers[ InteractableLockerGuid.Value ].RefundValue}");
                    }
                }
                else
                {
                    if (Game.Player.Character.IsOnFoot)
                    {
                        HoldingTime = gameTime;
                    }
                }
            }

            if (Game.IsControlJustReleased(2, (Control)InteractionControl))
            {
                HoldingTime = 0;
            }

            // Handle holding the interaction key to spawn a gun locker
            if (HoldingTime > 0)
            {
                int diff = gameTime - HoldingTime;
                if (diff >= 500 && InteractableLockerGuid == null)
                {
                    Methods.DrawText($"Buying a Gun Locker: ~b~{(diff * 100) / Constants.RequiredHoldingTime}% ~g~(${GunLockerPrice})", 0, 0.45f, Color.White, 0.05f, 0.05f);

                    if (diff >= Constants.RequiredHoldingTime)
                    {
                        HoldingTime = 0;

                        if (Game.Player.Money >= GunLockerPrice)
                        {
                            Game.Player.Money -= GunLockerPrice;

                            Locker newLocker = new Locker
                            {
                                RefundValue = GunLockerPrice,
                                Position    = Game.Player.Character.Position + Game.Player.Character.ForwardVector * Constants.PropDistance,
                                Rotation    = Game.Player.Character.Rotation
                            };

                            newLocker.CreateProp();
                            newLocker.Save();

                            GunLockers.Add(newLocker.ID, newLocker);
                        }
                        else
                        {
                            UI.Notify("~r~You can't afford a gun locker.");
                        }
                    }
                }
            }
        }