Exemplo n.º 1
0
    private void OnConfirm()
    {
        var encounter = Game.Instance.campaign.encounter.playerEncounter;
        // TODO Use enum instead of string here
        VesselAbility ability = encounter.GetAbility(abilityName);

        if (ability.TryTrigger())
        {
            //Game.Instance.audioManager.Play("success");

            var pm = Game.Instance.pageManager;
            //while (!(pm.GetActivePage() is PageEncounter))
            pm.PopPage();
        }
        else
        {
            Game.Instance.audioManager.Play("failure");
        }
    }
Exemplo n.º 2
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");
        }
    }