Ejemplo n.º 1
0
    void Start()
    {
        if (loadIfExists)
        {
            // Load test
            if (SaveGameManager.SaveGameExists)
            {
                Debug.Log("Save exists, loading.");
                testSaveGame = SaveGameManager.LoadGame();
            }
            else
            {
                Debug.Log("Save file does not exist.");
                SaveGameManager.SaveGame(testSaveGame);
            }
        }

        if (deleteIfExists)
        {
            // Delete test
            SaveGameManager.DeleteSaveGame();
            if (SaveGameManager.SaveGameExists)
            {
                Debug.Log("Save still exists, deleting failed.");
            }
            else
            {
                Debug.Log("Save deleted.");
            }
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Attempts to use an ability. Does nothing if the ability is on cooldown. Awaits
    /// a target if the ability requires one.
    /// </summary>
    /// <param name="ability">The ability to perform.</param>
    public void UseAbility(Ability ability)
    {
        if (HeroCombatController.AbilityCooldowns.ContainsKey(ability.name))
        {
            Debug.Log(gameObject.name + ": " + ability.name + " is on cooldown.");
            return;
        }

        if (ability.AbilityRange == AbilityRange.Self)
        {
            PerformAbility(ability, this);
        }

        if (ability.AbilityRange == AbilityRange.Melee || ability.AbilityRange == AbilityRange.Ranged)
        {
            if (HeroCombatController.TargetController == null)
            {
                Debug.Log(gameObject.name + ": Awaiting target for " + ability.name + ".");
                HeroInputController.AwaitTarget(ability);
            }
            else
            {
                PerformAbility(ability, CombatController.TargetController);
            }
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Spawns the assigned allies.
    /// </summary>
    protected void SpawnAllies()
    {
        if (spawnPoints == null)
        {
            spawnPoints = new List <Transform>();
        }

        try
        {
            for (int i = 0; i < GameManager.RosterManager.Assigned.Count && i < spawnPoints.Count; i++)
            {
                var allyName = GameManager.RosterManager.Assigned[i];

                var allyGameObject = Instantiate(GameManager.GameSettings.Prefab.Ally, spawnPoints[i].position, Quaternion.identity) as GameObject;
                allyGameObject.name = allyName;

                var allyController = allyGameObject.GetComponent <AllyController>();
                allyController.AllyObject = GameManager.RosterManager.GetEntityObject(allyName) as Ally;

                Debug.Log(gameObject.name + " spawned " + allyName + " as an ally.");
            }
        }
        catch (NullReferenceException e)
        {
            Debug.LogWarning(gameObject.name + ": Could not spawn allies.");
            Debug.LogException(e);
        }
        finally
        {
            foreach (var spawnPoint in spawnPoints)
            {
                Destroy(spawnPoint.gameObject);
            }
        }
    }
    /// <summary>
    /// Resets the game when the button is clicked.
    /// </summary>
    public void ResetGame()
    {
        DestroyImmediate(GameManager.Instance.gameObject);
        var wasDeleted = SaveGameManager.DeleteSaveGame();

        Debug.Log("DELETED GAME: " + wasDeleted);
        SceneManager.LoadScene("Start");
    }
 /// <summary>
 /// Unlocks a zone.
 /// </summary>
 /// <param name="zone">The name of the zone to unlock.</param>
 public void UnlockZone(string zone)
 {
     if (!unlockedZones.Contains("Scenes/Zones/" + zone))
     {
         unlockedZones.Add("Scenes/Zones/" + zone);
         Debug.Log("Unlocked zone: " + zone);
     }
 }
 /// <summary>
 /// Unlocks a stage.
 /// </summary>
 /// <param name="stage">The name of the stage to unlock.</param>
 public void UnlockStage(string stage)
 {
     if (!unlockedStages.Contains("Scenes/Stages/" + stage))
     {
         unlockedStages.Add("Scenes/Stages/" + stage);
         Debug.Log("Unlocked stage: " + stage);
     }
 }
Ejemplo n.º 7
0
 private void OnDestroy()
 {
     if (saveOnDestroy)
     {
         Debug.Log("Saving.");
         testSaveGame.IsFilled = true;
         SaveGameManager.SaveGame(testSaveGame);
     }
 }
 /// <summary>
 /// Updates the state of the hero's defend ability.
 /// </summary>
 public void UpdateDefend()
 {
     if (isDefending)
     {
         defenseDuration -= Time.deltaTime;
         if (defenseDuration < 0)
         {
             isDefending = false;
             Debug.Log(gameObject.name + ": Stopped defending.");
         }
     }
 }
 /// <summary>
 /// Registers the enemy with the enemy manager.
 /// </summary>
 protected override void Register()
 {
     try
     {
         GameManager.EnemyManager.Register(this);
     }
     catch (NullReferenceException e)
     {
         Debug.LogWarning(gameObject.name + ": Enemy attempted to register with an EnemyManager that doesn't exist.");
         Debug.LogException(e);
     }
 }
 /// <summary>
 /// Unregisters the enemy with the enemy manager.
 /// </summary>
 public override void Unregister()
 {
     try
     {
         GameManager.EnemyManager.Unregister(this);
     }
     catch (NullReferenceException e)
     {
         Debug.LogWarning(gameObject.name + ": GameManager destroyed before Enemy could unregister; this should only happen in the editor.");
         Debug.LogException(e);
     }
 }
    /// <summary>
    /// Sets up the combat controller.
    /// </summary>
    protected virtual void Start()
    {
        characterControllerReference = GetComponent <GameCharacterController>();
        if (characterControllerReference == null)
        {
            Debug.LogError(gameObject.name + ": Combat controller could not find a reference to the character controller.");
            return;
        }

        currentHealth  = CharacterController.Attributes.Health;
        currentEnergy  = CharacterController.Attributes.Energy;
        lastAttackTime = Time.time - (1 / CharacterController.Attributes.AttackSpeed);
    }
    /// <summary>
    /// Updates all ability cooldowns based on time passed.
    /// </summary>
    public void UpdateCooldowns()
    {
        var cooldownsToUpdate = new List <string>(AbilityCooldowns.Keys);

        foreach (var cooldown in cooldownsToUpdate)
        {
            AbilityCooldowns[cooldown] -= Time.deltaTime;
            if (AbilityCooldowns[cooldown] < 0)
            {
                AbilityCooldowns.Remove(cooldown);
                Debug.Log(gameObject.name + ": " + cooldown + " came off cooldown.");
            }
        }
    }
    /// <summary>
    /// Sets up the enemy controller.
    /// </summary>
    private void Start()
    {
        if (characterObjectReference == null)
        {
            Debug.LogError(gameObject.name + ": EnemyController was not provided an EnemyObject.");
        }

        CreateDerivedAttributes();
        CreateCombatController();
        CreateSpriteRenderer();
        CreateAnimator();
        CreateGraphicsController();
        CreateMovementController();
        CreateRigidbody2D();
        CreateCapsuleCollider2D();
        CreateFloatingHealthBar();

        Register();
    }
Ejemplo n.º 14
0
    /// <summary>
    /// Performs a shield ability on a target.
    /// </summary>
    /// <param name="ability">The ability to perform.</param>
    /// <param name="target">The target of the ability.</param>
    protected void PerformShieldAbility(Ability ability, GameCharacterController target)
    {
        Debug.Log(gameObject.name + ": Performing shield ability " + ability.name + " on " + target.name);
        switch (ability.AbilityRange)
        {
        case AbilityRange.Melee:
            // Not implemented
            break;

        case AbilityRange.Ranged:
            // Not implemented
            break;

        case AbilityRange.Self:
            HeroCombatController.PerformDefendAbility(ability);
            break;

        default: break;
        }
    }
Ejemplo n.º 15
0
    /// <summary>
    /// Performs a heal ability on a target. Placeholder.
    /// </summary>
    /// <param name="ability">The ability to perform.</param>
    /// <param name="target">The target of the ability.</param>
    protected void PerformHealAbility(Ability ability, GameCharacterController target)
    {
        Debug.Log(gameObject.name + ": Performing heal ability " + ability.name + " on " + target.name);

        switch (ability.AbilityRange)
        {
        case AbilityRange.Melee:
            // Not implemented
            break;

        case AbilityRange.Ranged:
            // Not implemented
            break;

        case AbilityRange.Self:
            // Not implemented
            break;

        default: break;
        }
    }
Ejemplo n.º 16
0
    /// <summary>
    /// Performs a direct ability on a target.
    /// </summary>
    /// <param name="ability">The ability to perform.</param>
    /// <param name="target">The target of the ability.</param>
    protected void PerformDirectAbility(Ability ability, GameCharacterController target)
    {
        Debug.Log(gameObject.name + ": Performing direct ability " + ability.name + " on " + target.name);

        switch (ability.AbilityRange)
        {
        case AbilityRange.Melee:
            HeroCombatController.PerformMeleeAttack();
            break;

        case AbilityRange.Ranged:
            HeroCombatController.PerformFireball(ability, target);
            break;

        case AbilityRange.Self:
            // Not implemented
            break;

        default: break;
        }
    }
    /// <summary>
    /// Updates the hero input every frame.
    /// </summary>
    protected void Update()
    {
        if (EventSystem.current == null)
        {
            Debug.LogError("Stage does not have event system; exiting. Add an event system to be able to play this stage.");
            GameManager.LoadZone(GameManager.WorldManager.LastZone);
        }

        // Process touch input
        if (Input.touchCount > 0)
        {
            foreach (var touch in Input.touches)
            {
                if (touch.phase == TouchPhase.Ended)
                {
                    if (!IsPointerOverUIObject())
                    {
                        ProcessTap(touch.position);
                    }
                }
            }
        }

        if (Input.GetMouseButton(0))
        {
            if (!IsPointerOverUIObject())
            {
                ProcessTap(Input.mousePosition);
            }
        }

        // This works with the mobile back button too
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (GameManager.OnStage)
            {
                GameManager.LoadZone(GameManager.WorldManager.LastZone);
            }
        }
    }
Ejemplo n.º 18
0
    /// <summary>
    /// Sets up the hero controller.
    /// </summary>
    private void Start()
    {
        if (heroObject == null)
        {
            Debug.LogError(gameObject.name + ": HeroController was not provided a HeroObject.");
        }

        CreateDerivedAttributes();
        CreateSpriteRenderer();
        CreateAnimator();
        CreateGraphicsController();
        CreateCombatController();
        CreateRigidbody2D();
        CreateCapsuleCollider2D();
        CreateMovementController();

        CreateHeroInputController();

        Register();

        SpawnAllies();
    }
 /// <summary>
 /// Sets the last stage the hero was on.
 /// </summary>
 /// <param name="stage">The name of the stage.</param>
 public void SetLastStage(string stage)
 {
     lastStage = stage;
     Debug.Log("Last stage set: " + stage);
 }
 /// <summary>
 /// Sets the last zone the hero was on.
 /// </summary>
 /// <param name="zone">The name of the zone.</param>
 public void SetLastZone(string zone)
 {
     lastZone = zone;
     Debug.Log("Last zone set: " + zone);
 }
    public override Vector2 CalculateDesiredVelocity()
    {
        var desiredVelocity = movementBehaviour.CalculateDesiredVelocity();

        var layerMask = LayerMask.GetMask("Hazard", "Obstacle");

        var centerDirection = desiredVelocity.normalized;
        var leftDirection   = (Vector2)(Quaternion.Euler(0, 0, 45) * centerDirection);
        var rightDirection  = (Vector2)(Quaternion.Euler(0, 0, -45) * centerDirection);

        var avoidCenter = false;
        var avoidLeft   = false;
        var avoidRight  = false;

        RaycastHit2D hit = Physics2D.Raycast(agent.transform.position, centerDirection, radius, layerMask);

        if (hit.collider != null)
        {
            var hazard = hit.transform.gameObject.GetComponent <HazardController>();
            if ((hazard != null && hazard.IsPathable) || hazard == null)
            {
                avoidCenter = true;
                //desiredVelocity += -centerDirection * radius * hit.fraction;
            }
        }

        hit = Physics2D.Raycast(agent.transform.position, leftDirection, radius, layerMask);
        if (hit.collider != null)
        {
            var hazard = hit.transform.gameObject.GetComponent <HazardController>();
            if ((hazard != null && hazard.IsPathable) || hazard == null)
            {
                //desiredVelocity += -leftDirection * radius * hit.fraction;
                avoidLeft = true;
            }
        }

        hit = Physics2D.Raycast(agent.transform.position, rightDirection, radius, layerMask);
        if (hit.collider != null)
        {
            var hazard = hit.transform.gameObject.GetComponent <HazardController>();
            if ((hazard != null && hazard.IsPathable) || hazard == null)
            {
                //desiredVelocity += -rightDirection * radius * hit.fraction;
                avoidRight = true;
            }
        }

        Debug.DrawRay(agent.transform.position, centerDirection * radius, avoidCenter ? Color.red : Color.blue);
        Debug.DrawRay(agent.transform.position, leftDirection * radius, avoidLeft ? Color.red : Color.blue);
        Debug.DrawRay(agent.transform.position, rightDirection * radius, avoidRight ? Color.red : Color.blue);

        var angle = 0.0f;

        // Center only
        if ((avoidCenter && !avoidLeft && !avoidRight) ||
            (avoidCenter && avoidLeft && avoidRight))
        {
            angle = 70;
            if (avoidCenter && avoidLeft && avoidRight)
            {
                angle = 90;
            }

            if (centerDirection.x < 0)
            {
                angle *= -1;
            }
            if (agent.transform.position.y >= 0)
            {
                angle *= -1;
            }
        }
        // Center and left
        else if (avoidCenter && avoidLeft && !avoidRight)
        {
            angle = -50;
        }
        // Center and right
        else if (avoidCenter && !avoidLeft && avoidRight)
        {
            angle = 50;
        }
        // Left only
        else if (!avoidCenter && avoidLeft && !avoidRight)
        {
            angle = -30;
        }
        // Right only
        else if (!avoidCenter && !avoidLeft && avoidRight)
        {
            angle = 30;
        }
        // All
        else if (avoidCenter && avoidLeft && avoidRight)
        {
            angle = 180;
        }

        desiredVelocity = (Vector2)(Quaternion.Euler(0, 0, angle) * desiredVelocity);

        return(desiredVelocity);
    }
 /// <summary>
 /// Performs a defend ability.
 /// </summary>
 /// <param name="ability">The ability to perform.</param>
 public void PerformDefendAbility(Ability ability)
 {
     isDefending     = true;
     defenseDuration = ability.Potency * GameManager.GameSettings.Constants.DefenseLength;
     Debug.Log(gameObject.name + ": Started defending.");
 }