Ejemplo n.º 1
0
    private void Update()
    {
        var           encounter = Game.Instance.campaign.encounter.playerEncounter;
        VesselAbility ability   = encounter.GetAbility(abilityName);

        bool flashState = (Time.time % 1f) <= .5f;

        if (ability == null)
        {
            display.Text = (flashState ? "!!! null !!!" : displayName);
        }
        else if (ability.IsActive)
        {
            display.Text = (flashState ? "[active]" : displayName);
        }
        else if (ability.CooldownTurnsRemaining > 0)
        {
            display.Text = (flashState ? "[cooldown-" + ability.CooldownTurnsRemaining + "]" : displayName);
        }
        else if (!ability.CanTrigger)
        {
            display.Text = (flashState ? "[disabled]" : displayName);
        }
        else
        {
            display.Text = displayName;
        }
    }
Ejemplo n.º 2
0
    private void OnShowDescription()
    {
        var encounter = Game.Instance.campaign.encounter.playerEncounter;
        // TODO Use enum instead of string here
        VesselAbility ability = encounter.GetAbility(abilityName);

        PageAbilityDescription page = Game.Instance.pageManager.GetPage <PageAbilityDescription>();

        page.Display(ability);
    }
    public void Display(VesselAbility ability)
    {
        string[] text = ability.Description.Split('\n');
        Debug.Assert(text.Length <= lines.Length);

        for (int i = 0; i < lines.Length; ++i)
        {
            lines[i].Text = (i < text.Length ? text[i] : "");
        }

        Game.Instance.pageManager.PushPage(this);
    }
Ejemplo n.º 4
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");
        }
    }
Ejemplo n.º 5
0
    // ability setup
    private void InitialiseAbilities()
    {
        AbilityLaser = new VesselAbilityDelegated(
            0, 0,
            () => "Fire lasers\nHit shields.\nCannot evade.\nSystem: " + Status.weapons + "%",
            () => (Status.weapons > 0 && modifiers.CanLaser),
            OnActivateLaser,
            null,
            null
            );
        abilities["laser"] = AbilityLaser;

        AbilityTorpedo = new VesselAbilityDelegated(
            0, 0,
            () => "Fire torpedo\nBypass shields.\nSystem: " + Status.weapons + "%\nAmmo: " + Status.ammo,
            () => (Status.weapons > 0 && modifiers.CanMissle && Status.ammo > 0),
            OnActivateTorpedo,
            null,
            null
            );
        abilities["torpedo"] = AbilityTorpedo;

        AbilityBoard = new VesselAbilityDelegated(
            int.MaxValue, 0,
            () => "Board enemy\nBypass shields.\nDamage systems\nover time.",
            () => modifiers.CanBoard,
            OnActivateBoarding,
            OnDeactivateBoarding,
            OnTickBoarding
            );
        abilities["board"] = AbilityBoard;

        AbilityShields = new VesselAbilityDelegated(
            int.MaxValue, 1,
            () => "Raise shields\nAbsorb lasers.\nSystem: " + Status.shields + "%",
            () => (Status.shields > 0 && modifiers.CanRaiseShields),
            OnActivateShields,
            () => owner.EnqueueAnimation(AnimateShield(this, false)),
            null
            );
        abilities["shields"] = AbilityShields;

        AbilityEvade = new VesselAbilityDelegated(
            int.MaxValue, 1,
            () => "Evade\nAttempt to\nevade the next\ntorpedo.\nSystem: " + Status.engines + "%",
            () => (Status.engines > 0 && modifiers.CanEvade),
            OnActivateEvade,
            OnDeactivateEvade,
            null
            );
        abilities["evade"] = AbilityEvade;

        AbilityRepel = new VesselAbilityDelegated(
            1, 1,
            () => "Repel\nRepel enemy\nboarders.",
            () => (modifiers.CanRepel && opponent.AbilityBoard.IsActive),
            OnActivateRepel,
            null,
            null
            );
        abilities["repel"] = AbilityRepel;

        AbilityScan = new VesselAbilityDelegated(
            int.MaxValue, 0,
            () => "Scan\nMake enemy\ninfo available.",
            () => modifiers.CanScan,
            OnActivateScan,
            null,
            null);
        abilities["scan"] = AbilityScan;

        AbilitySkipTurn = new VesselAbilityDelegated(
            0, 0,
            () => "Skip turn\nAI only!",
            () => true,
            OnSkipTurn,
            null,
            null);
        abilities["skipturn"] = AbilitySkipTurn;

        AbilityRepair = new VesselAbilityDelegated(
            1, 1,
            () => "Repair\nRepair hull\nand systems.",
            () => Status.CanRepair && modifiers.CanRepair,
            OnActivateRepair,
            null,
            null);
        abilities["repair"] = AbilityRepair;

        AbilityFlee = new VesselAbilityDelegated(
            1, 1,
            () => $"Flee\nTry to escape\nthe encounter.\nSystem: {Status.engines}%",
            () => Status.CanFlee && modifiers.CanFlee,
            OnFlee,
            null,
            null);
        abilities["flee"] = AbilityFlee;
    }
Ejemplo n.º 6
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");
        }
    }