Exemple #1
0
 /// <summary>
 /// Are the conditions for firing this trigger met?
 /// </summary>
 /// <param name="character">Character.</param>
 virtual protected bool ConditionsMet(Character character)
 {
     if (requiredItemType != null && requiredItemType != "")
     {
         ItemManager itemManager = character.GetComponentInChildren <ItemManager>();
         if (itemManager == null)
         {
             Debug.LogWarning("Trigger requires an item but the character has no item manager");
             return(false);
         }
         if (itemManager.HasItem(requiredItemType))
         {
             return(true);
         }
         return(false);
     }
     if (requiredComponent != null)
     {
         if (!requiredComponent.gameObject.activeInHierarchy)
         {
             return(false);
         }
         if (!requiredComponent.enabled)
         {
             return(false);
         }
     }
     return(true);
 }
 /// <summary>
 /// Activate the specified itemId.
 /// </summary>
 /// <param name="itemId">Item identifier.</param>
 /// <returns>true if the item was activated or the item was already activated</returns>
 virtual public bool Activate(string itemId)
 {
     if (!items.Contains(itemId))
     {
         Debug.LogWarning("Tried to activate item " + itemId + " but it was not found in the list of items.");
         return(false);
     }
     if (activeItems.Contains(itemId))
     {
         return(true);
     }
     if (requireMatchingItem)
     {
         if (!itemManager.HasItem(itemId))
         {
             return(false);
         }
     }
     if (onlyOneActive)
     {
         itemsToDeactivate.Clear();
         foreach (string i in activeItems)
         {
             if (i != itemId)
             {
                 itemsToDeactivate.Add(i);
             }
         }
         foreach (string i in itemsToDeactivate)
         {
             activeItems.Remove(i);
             OnDeactivated(i);
         }
     }
     activeItems.Add(itemId);
     OnActivated(itemId);
     if (activeItems.Count == items.Count)
     {
         OnAllActivated();
     }
     if (saveOnChange)
     {
         Save(this);
     }
     return(true);
 }
Exemple #3
0
 /// <summary>
 /// Checks the condition. For example a check when entering a trigger.
 /// </summary>
 /// <returns><c>true</c>, if enter trigger was shoulded, <c>false</c> otherwise.</returns>
 /// <param name="character">Character.</param>
 /// <param name="other">Other.</param>
 override public bool CheckCondition(Character character, object other)
 {
     if (requiredItemType != null && requiredItemType != "")
     {
         ItemManager itemManager = character.GetComponentInChildren <ItemManager>();
         if (itemManager == null)
         {
             Debug.LogWarning("Conditions requires an item but the character has no item manager.");
             return(false);
         }
         if (itemManager.HasItem(requiredItemType))
         {
             return(true);
         }
         return(false);
     }
     Debug.LogWarning("MustHaveItemCondition has no item configured.");
     return(false);
 }