Exemplo n.º 1
0
    public HealthSystemAnimation healthSystemAnimation;     // the health system of this character

    /// <summary>
    /// Responsible for setting up the health system of this character.
    /// </summary>
    /// <param name="healthSystemAnimation">the health system to set as current</param>

    public void SetHealthSystemAnimation(HealthSystemAnimation healthSystemAnimation)
    {
        this.healthSystemAnimation = healthSystemAnimation;

        // subscribe to the on health changed, callback
        healthSystemAnimation.OnHealthChanged += HealthSystemAnimation_OnHealthChanged;
    }
    /// <summary>
    /// Responsible for creating a new player.
    /// </summary>

    public void NewPlayer()
    {
        if (playerWindow == null)
        {
            playerWindow = PlayerWindow.instance;
        }

        // LEVEL SYSTEM

        levelSystem          = new LevelSystem(1, 0);
        levelSystemAnimation = new LevelSystemAnimation(levelSystem);

        playerWindow.SetLevelSystemAnimation(levelSystemAnimation);
        SetLevelSystemAnimation(levelSystemAnimation);

        // HEALTH SYSTEM

        healthSystem          = new HealthSystem(levelSystem.GetLevelNumber(), 0);
        healthSystemAnimation = new HealthSystemAnimation(healthSystem);

        playerWindow.SetHealthSystemAnimation(healthSystemAnimation);
        SetHealthSystemAnimation(healthSystemAnimation);

        // UPDATE UI

        UpdateUI();
    }
    /// <summary>
    /// Loads the player data from the save file.
    /// </summary>
    /// <param name="data"></param>

    public void LoadPlayer(PlayerData data)
    {
        if (data != null)
        {
            // INFO

            characterName = data.name;

            // LEVEL

            int level      = data.level;
            int experience = data.experience;

            levelSystem = new LevelSystem(level, experience);

            levelSystemAnimation = new LevelSystemAnimation(levelSystem);
            SetLevelSystemAnimation(levelSystemAnimation);
            playerWindow.SetLevelSystemAnimation(levelSystemAnimation);

            // HEALTH

            int currentHealth = data.currentHealth;

            healthSystem = new HealthSystem(level, currentHealth);

            healthSystemAnimation = new HealthSystemAnimation(healthSystem);
            SetHealthSystemAnimation(healthSystemAnimation);
            playerWindow.SetHealthSystemAnimation(healthSystemAnimation);

            // ABILITIES

            strength     = data.strength;
            stamina      = data.stamina;
            intelligence = data.intelligence;
            dexterity    = data.dexterity;
            charisma     = data.charisma;
            luck         = data.luck;
            attack       = data.attack;
            defence      = data.defence;

            // POSITION

            float x = data.position[0];
            float y = data.position[1];

            playerTransform.position = new Vector2(x, y);

            CameraReset.instance.ResetCamera();
        }
        else
        {
            Debug.LogError("Save file not found...");
        }
    }
    /// <summary>
    /// Responsible for setting a reference to a health system animator.
    /// </summary>
    /// <param name="healthSystemAnimation">the health system animator to animate the health bar</param>

    public void SetHealthSystemAnimation(HealthSystemAnimation healthSystemAnimation)
    {
        // set the health system animation object
        this.healthSystemAnimation = healthSystemAnimation;

        // update the starting values
        UpdateHealth();

        // subscribe to the health changed, callbacks
        healthSystemAnimation.OnHealthChanged    += HealthSystemAnimation_OnHealthChanged;
        healthSystemAnimation.OnMaxHealthChanged += HealthSystemAnimation_OnMaxHealthChanged;
    }