Exemplo n.º 1
0
    public void GambitLoop()
    {
        if (CurrentValidatedRule == null)
        {
            ValidateNextRuleFromGambits();
        }

        if (CurrentValidatedRule != null && CurrentValidatedRule.TargetCondition.ResultUnit != null)
        {
            StartDelay -= Time.deltaTime;

            if (StartDelay > 0.01)
            {
                return;
            }

            //Time to attack set in ValidateNextRuleFromGambits()
            TimeToAttack -= Time.deltaTime;

            if (TimeToAttack <= 0)
            {
                Debug.Log("Unit " + Name + " is using action: " + CurrentValidatedRule.GambitAction.Name);
                CurrentValidatedRule.GambitAction.DoAction(this, CurrentValidatedRule.TargetCondition.ResultUnit);
                ChangeMana(-CurrentValidatedRule.GambitAction.MPCost);

                CurrentValidatedRule = null;
                TimeToAttack         = 0;
                StartDelay           = startDelayCache;
            }
        }
        else
        {
            CurrentValidatedRule = null;
        }
    }
Exemplo n.º 2
0
    /*************** GAMBITS ***********/
    public void AddGambitRule(GambitRule rule)
    {
        if (GambitRules == null)
        {
            GambitRules = new List <GambitRule>();
        }

        GambitRules.Add(rule);
    }
    public override bool IsConditionMet(Unit instigator, GambitRule currentRule)
    {
        var result = GameManager.Instance.GetPartyMembers().Where(p => p.HealthPercentage <= 70);

        if (result.Count() > 0)
        {
            ResultUnit = result.First();
            return(true);
        }
        return(false);
    }
    public override bool IsConditionMet(Unit instigator, GambitRule currentRule)
    {
        var result = GameManager.Instance.GetNearestUnitsInRangeBasedOnSourceTag(instigator);

        if (result != null && result.Count > 0)
        {
            ResultUnit = result.First();
            return(true);
        }
        return(false);
    }
 public override bool IsConditionMet(Unit instigator, GambitRule currentRule)
 {
     foreach (var unitGO in GameManager.Instance.CurrentPartyMembers)
     {
         Unit unit = unitGO.GetComponent <Unit>();
         if (unit.IsLeader && unit.CurrentValidatedRule != null && unit.CurrentValidatedRule.TargetCondition.TargetType == GambitTargetType.Enemy)
         {
             ResultUnit = unit.CurrentValidatedRule.TargetCondition.ResultUnit;
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 6
0
    private void SetDefaultGambitsForEnemies()
    {
        GambitRule attackRule = new GambitRule();

        attackRule.TargetCondition = new TargetNearestVisible();
        attackRule.GambitAction    = new AttackAction();
        attackRule.IsEnabled       = true;

        foreach (var enemy in CurrentEnemies)
        {
            enemy.GetComponent <Unit>().GambitRules.Add(attackRule);
        }
    }
Exemplo n.º 7
0
    public void ValidateNextRuleFromGambits()
    {
        CurrentValidatedRule = null;

        foreach (var gambit in GambitRules)
        {
            //if it's enabled, the condition is met and we have enough MP
            if (gambit.IsEnabled && gambit.TargetCondition.IsConditionMet(this, gambit) && this.Mana >= gambit.GambitAction.MPCost)
            {
                CurrentValidatedRule = gambit;
                TimeToAttack         = gambit.GambitAction.CastTime * Speed; //default speed modifier for player is 1
                MaxTimeToAttack      = TimeToAttack;
                return;
            }
        }
    }
    public override bool IsConditionMet(Unit instigator, GambitRule currentRule)
    {
        var result = GameManager.Instance.GetNearestUnitsInRangeBasedOnSourceTag(instigator);

        if (result != null)
        {
            foreach (var unit in result)
            {
                if (unit.Weakness == weaknessToCheck)
                {
                    ResultUnit = unit;
                    return(true);
                }
            }
        }

        return(false);
    }
    public void SwitchGambits(int index)
    {
        //we already clicked it before and thus selected a rule to switch
        if (isSwitching)
        {
            GambitRule back = UnitToShow.GambitRules[switchIndex];
            UnitToShow.GambitRules[switchIndex] = UnitToShow.GambitRules[index];
            UnitToShow.GambitRules[index]       = back;

            UnitToShow.GambitsChanged();
            isSwitching = false;
            ConstructGambitRuleUI();
        }
        else //we clicked the switch button for the first time, mark this rule to be switched
        {
            switchIndex = index;
            isSwitching = true;
            ConstructGambitRuleUI();
        }
    }
Exemplo n.º 10
0
    private void SetDefaultGambitsForPlayer(Unit u, int index)
    {
        GambitRule attackRule = new GambitRule();

        attackRule.TargetCondition = new TargetNearestVisible();
        attackRule.GambitAction    = new AttackAction();
        attackRule.IsEnabled       = true;

        GambitRule attackPartyLeaderTargetRule = new GambitRule();

        attackPartyLeaderTargetRule.TargetCondition = new TargetPartyLeaderTarget();
        attackPartyLeaderTargetRule.GambitAction    = new AttackAction();
        attackPartyLeaderTargetRule.IsEnabled       = true;

        GambitRule cureRule = new GambitRule();

        cureRule.TargetCondition = new AllyHPBelowValuePercentage("Ally: HP <= 50%", 50);
        cureRule.GambitAction    = new CureAction();
        cureRule.IsEnabled       = true;

        GambitRule emptyRule  = new GambitRule();
        GambitRule emptyRule2 = new GambitRule();

        if (index == 0)
        {
            u.GambitRules.Add(cureRule);
            u.GambitRules.Add(attackRule);
            u.IsLeader = true; //make this one the leader
        }

        if (index > 0)
        {
            u.GambitRules.Add(attackPartyLeaderTargetRule);
        }

        u.GambitRules.Add(emptyRule);
        u.GambitRules.Add(emptyRule2);
    }
    public override bool IsConditionMet(Unit instigator, GambitRule currentRule)
    {
        int maxPartySize = GameManager.Instance.CurrentPartyMembers.Count;

        if (currentRule.GambitAction == currentAction && currentIndex < maxPartySize)
        {
            //same action, assign a target, if needed continuing where we left off the last time when this rule was used.
            ResultUnit = GameManager.Instance.GetPartyMembers()[currentIndex];
            currentIndex++;
            return(true);
        }
        else if (currentAction != currentRule.GambitAction)
        {
            //different action (probably a buff or heal) so we save the action and start counting from the first party member in the list again
            currentAction = currentRule.GambitAction;
            currentIndex  = 0;
            ResultUnit    = GameManager.Instance.GetPartyMembers()[currentIndex];
            currentIndex++;
            return(true);
        }

        return(false);
    }
 public abstract bool IsConditionMet(Unit instigator, GambitRule currentRule);
 public override bool IsConditionMet(Unit instigator, GambitRule currentRule)
 {
     ResultUnit = instigator;
     return(true);
 }
Exemplo n.º 14
0
 public void GambitsChanged()
 {
     //triggers the system to go over the gambits again and pick a new rule.
     CurrentValidatedRule = null;
 }