Esempio n. 1
0
    public void BeginEncounter(Campaign owner, EncounterDescriptor descriptor)
    {
        this.owner      = owner;
        this.descriptor = descriptor;

        // setup opponent
        opponentStats = gameObject.AddComponent <VesselStats>();
        InitialiseOpponentStats();
        opponentStatus = gameObject.AddComponent <VesselStatus>();
        InitialiseOpponentStatus();

        // activate page
        pageEncounter = (PageEncounter)Game.Instance.pageManager.PushPage("Encounter");
        // disable input
        pageEncounter.IsInputEnabled = false;

        // initialise health bars
        pageEncounter.healthBarPlayer.SetFill(owner.playerStatus.GetHealthPercentage());
        pageEncounter.healthBarOpponent.SetFill(opponentStatus.GetHealthPercentage());

        // setup vessel encounters
        playerEncounter   = new VesselEncounter(true, "player", this, owner.gameBalance, pageEncounter.playerVisuals, owner.playerStats, owner.playerStatus, descriptor.playerModifiers);
        opponentEncounter = new VesselEncounter(false, "opponent", this, owner.gameBalance, pageEncounter.opponentVisuals, opponentStats, opponentStatus, descriptor.enemyModifiers);
        VesselEncounter.SetOpponents(playerEncounter, opponentEncounter);

        opponentAiBehaviour = Instantiate(descriptor.enemyAiBehaviour, transform);

        // start
        BeginPlayerTurn();
    }
Esempio n. 2
0
    private void OnDestroy()
    {
        Destroy(opponentStats);
        Destroy(opponentStatus);

        playerEncounter   = null;
        opponentEncounter = null;
    }
Esempio n. 3
0
    public OpponentVesselInformation(bool hasScanned, VesselEncounter opponent)
    {
        Hitpoints = opponent.Status.health;
        ShieldsUp = opponent.AbilityShields?.IsActive == true;
        IsBoarded = opponent.AbilityBoard?.IsActive == true;

        if (hasScanned)
        {
            ScanInformation = new OpponentVesselScanInformation(opponent);
        }
    }
Esempio n. 4
0
    // animations
    private static IEnumerator AnimateShield(VesselEncounter vessel, bool state)
    {
        float interval = .8f;

        for (int i = 0; i < 8; ++i)
        {
            yield return(new WaitForSeconds(interval));

            vessel.visuals.ShieldVisible = state;
            Game.Instance.audioManager.Play("shield");
            yield return(new WaitForSeconds(.05f));

            vessel.visuals.ShieldVisible = !state;
            interval *= .5f;
        }
        Game.Instance.audioManager.Play("shield");
        vessel.visuals.ShieldVisible = state;
    }
Esempio n. 5
0
    public void OnVesselEndTurn(VesselEncounter vessel)
    {
        Debug.Assert(turnState == TurnState.Deciding);

        // disable input
        pageEncounter.IsInputEnabled = false;

        // enqueue health bar animations
        EnqueueAnimation(CoroutineComposer.MakeParallel(
                             this,
                             pageEncounter.healthBarPlayer.AnimateFill(owner.playerStatus.GetHealthPercentage(), 1),
                             pageEncounter.healthBarOpponent.AnimateFill(opponentStatus.GetHealthPercentage(), 1)
                             ));

        // luck roll to prevent player death
        if (playerEncounter.Status.health <= 0)
        {
            float luckRoll = playerEncounter.Stats.RollLuck();
            Debug.Log($"Anti-death luck roll: {luckRoll}");
            if (luckRoll > 0.9f)
            {
                // repair
                playerEncounter.Status.Repair(true);

                // repair and health bar animations
                EnqueueAnimation(CoroutineComposer.MakeParallel(this,
                                                                Game.Instance.effects.Create <EffectRepair>("Repair").Setup(pageEncounter.playerVisuals.transform.position, pageEncounter.playerVisuals.hull.sprite.rect).Run(),
                                                                pageEncounter.healthBarPlayer.AnimateFill(owner.playerStatus.GetHealthPercentage(), 1)
                                                                ));
            }
        }

        // enqueue end of turn
        pendingCoroutines.Add(CoroutineComposer.MakeAction(OnFinishAnimating));

        // run coroutines
        turnState = TurnState.Animating;
        StartCoroutine(CoroutineComposer.MakeSequence(pendingCoroutines.ToArray()));
    }
Esempio n. 6
0
 public abstract void Act(VesselEncounter self);
Esempio n. 7
0
 public static void SetOpponents(VesselEncounter a, VesselEncounter b)
 {
     a.opponent = b;
     b.opponent = a;
 }
Esempio n. 8
0
 public OpponentVesselScanInformation(VesselEncounter opponent)
 {
     Stats  = opponent.Stats;
     Status = opponent.Status;
 }
Esempio n. 9
0
 private void BeginTurn(VesselEncounter vessel)
 {
     Debug.Assert(turnState == TurnState.NotStarted);
     vessel.BeginTurn();
     turnState = TurnState.Deciding;
 }
Esempio n. 10
0
    public override void Act(VesselEncounter self)
    {
        enemy     = self.GetOpponentInformation();
        this.self = self;

        var list = new List <(VesselAbility ability, int score)>();

        if (self.AbilityShields?.CanTrigger == true)
        {
            list.Add((self.AbilityShields, GetRaiseShieldScore()));
        }
        if (self.AbilityScan?.CanTrigger == true)
        {
            list.Add((self.AbilityScan, GetScanScore()));
        }
        if (self.AbilityLaser?.CanTrigger == true)
        {
            list.Add((self.AbilityLaser, GetFireLaserScore()));
        }
        if (self.AbilityRepel?.CanTrigger == true)
        {
            list.Add((self.AbilityRepel, GetRepelScore()));
        }
        if (self.AbilityBoard?.CanTrigger == true)
        {
            list.Add((self.AbilityBoard, GetBoardScore()));
        }
        if (self.AbilityTorpedo?.CanTrigger == true)
        {
            list.Add((self.AbilityTorpedo, GetTorpedoScore()));
        }
        if (self.AbilityRepair?.CanTrigger == true)
        {
            list.Add((self.AbilityRepair, GetRepairScore()));
        }
        if (self.AbilityFlee?.CanTrigger == true)
        {
            list.Add((self.AbilityFlee, GetFleeScore()));
        }
        if (self.AbilityEvade?.CanTrigger == true)
        {
            list.Add((self.AbilityEvade, GetEvadeScore()));
        }

        VesselAbility chosenAction = null;
        bool          pickAction   = Random.value < 0.98f;

        if (pickAction && list.Count > 0)
        {
            var choices = list.Where(e => e.score > 0).OrderBy(e => e.score).ToArray();
            if (choices.Length > 0)
            {
                var index = Mathf.Min(
                    Mathf.FloorToInt((Mathf.Sqrt(1f - Random.value)) * choices.Length),
                    choices.Length - 1);

                chosenAction = choices[index].ability;
            }
        }

        if (chosenAction == null)
        {
            chosenAction = self.AbilitySkipTurn;
        }

        if (!chosenAction.TryTrigger())
        {
            throw new System.Exception("Failed to trigger ability which reported CanTrigger true");
        }
    }