Ejemplo n.º 1
0
    /// <summary>
    /// Saves the current Player Stats to the specific file.
    ///
    /// Do not use.
    ///
    /// Use Game.SavePlayerStats() instead.
    ///
    /// Invokes OnSave Event
    /// </summary>
    /// <param name="file"></param>
    public static void Save(string file)
    {
        Debug.Log("Saving Player Stats to " + file);

        PlayerStats stats = new PlayerStats();

        stats.Coins        = Player.Instance.Coins;
        stats.CurrentLevel = LevelManager.Instance.GetLevelName();
        stats.Weapons      = new List <string>();
        Player.Instance.weapons.ForEach(x => {
            if (x is AdvancedWeapon)
            {
                AdvancedWeapon w = (AdvancedWeapon)x;
                stats.Weapons.Add(w.OldWeaponName);
            }
            stats.Weapons.Add(x.name);
        });

        stats.Levels = LevelManager.Instance.Levels;

        stats.Dialogues = DialogueTrigger.DialoguesHit;

        string data = JsonUtility.ToJson(stats, true);

        File.WriteAllText(file, data);

        OnSave?.Invoke();
    }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        if (interactable == null)
        {
            interactable = GetComponentInChildren <Interactable>(true);
        }
        interactable.OnInteract += this.Pickup;

        // Checks if the Player has a weapon that has the same name as this pickup,
        //  or if they have an Advanced Weapon with the old weapon name as this pickup...
        bool hasPickedUp = Player.Instance.weapons.Find(x => {
            if (x is AdvancedWeapon)
            {
                AdvancedWeapon w = (AdvancedWeapon)x;
                return((WeaponName == w.name) || (WeaponName == w.OldWeaponName));
            }
            else
            {
                return(WeaponName == x.name);
            }
        }) != null;

        // If Player has already picked up weapon, delete this
        if (hasPickedUp)
        {
            Destroy(this.gameObject);
        }

        origin = this.transform.position;
    }
Ejemplo n.º 3
0
    public void AddWeapon(Weapon newWeapon)
    {
        if (newWeapon is AdvancedWeapon)
        {
            AdvancedWeapon w     = (AdvancedWeapon)newWeapon;
            int            index = weapons.FindIndex(x => x.name == w.OldWeaponName);

            Weapon oldWeapon = weapons[index];
            Destroy(oldWeapon.gameObject);

            weapons[index] = newWeapon;

            oldWeapon.gameObject.SetActive(false);
        }
        else
        {
            weapons.Add(newWeapon);
        }

        newWeapon.gameObject.SetActive(false);
        newWeapon.transform.SetParent(WeaponParent.transform, false);

        // This works if we are adding MagicMagic, but holding Magic, MagicMagic will be enabled
        Weapon currWeapon = GetCurrentWeapon();

        currWeapon.gameObject.SetActive(true);
        currWeapon.transform.SetParent(camera.transform, false);

        string[] weaponNames = weapons.Select(x => x.name).ToArray();
        int      nextIndex   = CurrWeaponIndex + 1 >= weapons.Count ? 0 : CurrWeaponIndex + 1;
        int      prevIndex   = CurrWeaponIndex - 1 < 0 ? weapons.Count - 1 : CurrWeaponIndex - 1;

        PlayerHud.Instance.SetWeaponToggle(weapons[prevIndex].name,
                                           weapons[CurrWeaponIndex].name, weapons[nextIndex].name);
        PlayerHud.Instance.SetWeaponWheel(weaponNames);
        PlayerHud.Instance.DisableWeaponWheel();

        if (weapons.Count > 1)
        {
            PlayerHud.Instance.EnableWeaponToggle();
            Player.Instance.CanSwapWeapon = true;
        }
        else
        {
            PlayerHud.Instance.DisableWeaponToggle();
            Player.Instance.CanSwapWeapon = false;
        }
    }
 private void UpdateSecondResourceBarColor(AdvancedWeapon weapon)
 {
     secondResourceBarFill.color =
         secondResourceBarColors.First(color => color.MatchingWeaponType == weapon.WeaponType).BarColor;
 }