public void removeConditionsFromUnequippedItem(Player player, ItemType itemType) {
   ItemTraits_OnEquip equipEffects = itemType.effects_equip;
   if (equipEffects == null) return;
   if (equipEffects.addedConditions == null) return;
   for (ActorConditionEffect e : equipEffects.addedConditions) {
     if (e.isRemovalEffect()) continue;
     if (e.magnitude <= 0) continue;
     if (e.conditionType.isStacking) {
       removeStackableActorCondition(
           player, e.conditionType, e.magnitude, ActorCondition.DURATION_FOREVER);
     } else {
       removeNonStackableActorCondition(
           player, e.conditionType, e.magnitude, ActorCondition.DURATION_FOREVER);
     }
   }
 }
 private void applyActorCondition(Actor actor, ActorConditionEffect e, int duration) {
   if (e.isRemovalEffect()) {
     removeAllConditionsOfType(actor, e.conditionType.conditionTypeID);
   } else if (e.magnitude > 0) {
     if (e.conditionType.isStacking) {
       addStackableActorCondition(actor, e, duration);
     } else {
       addNonStackableActorCondition(actor, e, duration);
     }
   }
   recalculateActorCombatTraits(actor);
 }
  private void addNonStackableActorCondition(Actor actor, ActorConditionEffect e, int duration) {
    final ActorConditionType type = e.conditionType;

    for (int i = actor.conditions.size() - 1; i >= 0; --i) {
      ActorCondition c = actor.conditions.get(i);
      if (!type.conditionTypeID.equals(c.conditionType.conditionTypeID)) continue;
      if (c.magnitude > e.magnitude) return;
      if (c.magnitude == e.magnitude) {
        if (c.duration >= duration) return;
      }
      // If the actor already has this condition, but of a lower magnitude, we remove the old one
      // and add this higher magnitude.
      actor.conditions.remove(i);
      actorConditionListeners.onActorConditionRemoved(actor, c);
    }

    ActorCondition c = e.createCondition(duration);
    actor.conditions.add(c);
    actorConditionListeners.onActorConditionAdded(actor, c);
  }