public void recheck(PerkPrototype other)
 {
     if (other == perkInfo || taken)
     {
         taken = true;
     }
     else if (other.Blocks.Contains(perkInfo))
     {
         blocked = true;
     }
     else if (!perkInfo.RequireAll && !available && !blocked)
     {
         if (other.Children.Contains(perkInfo))
         {
             available = true;
         }
     }
     else if (perkInfo.RequireAll && !available && !blocked)
     {
         bool req = true;
         foreach (PerkPrototype p in perkInfo.Require)
         {
             if (!(p == other || playerClass.TakenPerks.Contains(p)))
             {
                 req = false;
             }
         }
         available = req;
     }
 }
    public static bool CheckPrereq(PerkPrototype p, IList <PerkPrototype> taken)
    {
        if (taken.Contains(p))
        {
            //Debug.LogError("Attempted to take perk that is already owned");
            return(false);
        }
        int matched = 0;

        foreach (PerkPrototype t in taken)
        {
            if (p.BlockedBy.Contains(t))
            {
                return(false);
            }
            if (p.Require.Contains(t))
            {
                ++matched;
            }
        }
        if (p.RequireAll)
        {
            return(matched >= p.Require.Count);
        }
        else
        {
            int req = p.Require.Count > 0 ? 1 : 0;
            return(matched >= req);
        }
    }
Example #3
0
 public void AddPerk(PerkPrototype p)
 {
     if (filename != "")
     {
         data.Perks.Add(p);
     }
 }
Example #4
0
    void OnPerkEnter(PointerEventData data)
    {
        PerkHolder clickedEvent = data.pointerCurrentRaycast.gameObject.GetComponent <PerkHolder>();

        mousedOver         = clickedEvent.perkInfo;
        descText.text      = mousedOver.Desc + "\n\n";
        skillTitle.text    = mousedOver.Name;
        spriteImage.sprite = mousedOver.sprite;
        foreach (PerkStatEntry stat in mousedOver.Stats)
        {
            descText.text = descText.text + stat.StatInst.Name + ": " + stat.StatInst.Value + "\n";
        }
        selected = true;
    }
    public Color precheck(PerkPrototype other)
    {
        Color ret = Color.white;

        if (other == perkInfo || taken)
        {
            ret = Color.green;
        }
        else if (other.Blocks.Contains(perkInfo))
        {
            ret = Color.red;
        }
        else if (blocked)
        {
            ret = Color.red;
        }
        else if (available)
        {
            ret = Color.yellow;
        }
        else if (!perkInfo.RequireAll)
        {
            if (other.Children.Contains(perkInfo))
            {
                ret = Color.yellow;
            }
        }
        else if (perkInfo.RequireAll)
        {
            bool req = true;
            foreach (PerkPrototype p in perkInfo.Require)
            {
                if (!(p == other || playerClass.TakenPerks.Contains(p)))
                {
                    req = false;
                }
            }
            if (req)
            {
                ret = Color.yellow;
            }
        }
        return(ret);
    }
    public bool TakePerk(PerkPrototype p, bool needsPerkPoint = true)
    {
        if (!needsPerkPoint || (PlayerLevelExp != null && PlayerLevelExp.PerkPoints > 0))
        {
            if (CheckPrereq(p, TakenPerks))
            {
                if (needsPerkPoint)
                {
                    --PlayerLevelExp.PerkPoints;
                }
                TakenPerks.Add(p);
                stats.StatsChanged();
                if (abilities != null && abilDict != null)
                {
                    foreach (AbilityPrototype a in p.grants)
                    {
                        var ability = Ability.FromPrototype(a);
                        abilities.Set.Add(ability.AbilityName, ability);

                        //TODO: repalce with ui thing
                        if (abilDict.GetAbility(AbilitySlot.One).AbilityName == Ability.Null.AbilityName)
                        {
                            abilDict.SetSlotAbility(AbilitySlot.One, ability);
                            AddAbilityToParent(gameObject, ability.TypeString);
                        }
                        else if (abilDict.GetAbility(AbilitySlot.Two).AbilityName == Ability.Null.AbilityName)
                        {
                            abilDict.SetSlotAbility(AbilitySlot.Two, ability);
                            AddAbilityToParent(gameObject, ability.TypeString);
                        }
                        else if (abilDict.GetAbility(AbilitySlot.Three).AbilityName == Ability.Null.AbilityName)
                        {
                            abilDict.SetSlotAbility(AbilitySlot.Three, ability);
                            AddAbilityToParent(gameObject, ability.TypeString);
                        }
                        else if (abilDict.GetAbility(AbilitySlot.Four).AbilityName == Ability.Null.AbilityName)
                        {
                            abilDict.SetSlotAbility(AbilitySlot.Four, ability);
                            AddAbilityToParent(gameObject, ability.TypeString);
                        }
                        else if (abilDict.GetAbility(AbilitySlot.Five).AbilityName == Ability.Null.AbilityName)
                        {
                            abilDict.SetSlotAbility(AbilitySlot.Five, ability);
                            AddAbilityToParent(gameObject, ability.TypeString);
                        }
                        else if (abilDict.GetAbility(AbilitySlot.Six).AbilityName == Ability.Null.AbilityName)
                        {
                            abilDict.SetSlotAbility(AbilitySlot.Six, ability);
                            AddAbilityToParent(gameObject, ability.TypeString);
                        }
                    }
                    foreach (AbilityModifier aMod in p.Changes)
                    {
                        if (abilities.Set.ContainsKey(aMod.AbilityName))
                        {
                            Ability abil = abilities.Set[aMod.AbilityName];
                            Stat    stat = abil.Stats.Find(item => item.Name == aMod.StatName.InternalStatName);
                            stat.Value += aMod.Value;
                            abil.update = true;
                        }
                    }
                }
                return(true);
            }
        }
        return(false);
    }