package com.sb.cdp.ability;

import java.util.HashSet;
import java.util.Set;

import com.sb.cdp.CharacterType;
import com.sb.cdp.PlayerCharacter;

public class CharacterTypeCondition implements Condition {

    private Set<CharacterType> neededTypes;

    public CharacterTypeCondition() {
	neededTypes = new HashSet<>();
    }

    public CharacterTypeCondition(Set<CharacterType> neededTypes) {
	this.neededTypes = neededTypes;
    }

    /**
     * Checks if the PlayerCharacter has at least one of the neededTypes.
     */
    @Override
    public boolean accept(PlayerCharacter pc) {
	for (CharacterType pct : pc.getCharacterTypes())
	    if (neededTypes.contains(pct))
		return true;
	return false;
    }

    @Override
    public String describe() {
	boolean plural = neededTypes.size() > 1;
	StringBuilder sb = new StringBuilder(String.format("%1 classe%2/race%2 suivante%2 doit être possédée: ", plural ? "L'une des" : "La ", plural ? "S" : ""));
	int i = 0;
	for (CharacterType type : neededTypes) {
	    sb.append(type.getName());
	    if (i + 1 < neededTypes.size())
		sb.append(", ");
	}
	return sb.toString();
    }

    /**
     * Returns the neededTypes.
     * @return the neededTypes
     */
    public Set<CharacterType> getNeededTypes() {
        return neededTypes;
    }

    /**
     * Sets the value of neededTypes to that of the parameter.
     * @param neededTypes the neededTypes to set
     */
    public void setNeededTypes(Set<CharacterType> neededTypes) {
        this.neededTypes = neededTypes;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
	return "CharacterTypeCondition [neededTypes=" + neededTypes + "]";
    }

}

@@ -847,16 +847,18 @@
 rmat(%22%251
+$s
  classe%25
@@ -862,15 +862,19 @@
 se%252
+$s
 /race%252
+$s
  sui
@@ -880,16 +880,18 @@
 ivante%252
+$s
  doit %C3%AAt
@@ -905,17 +905,19 @@
 %C3%A9d%C3%A9e: %22,
- 
+%0A%09%09
 plural ?
@@ -948,17 +948,17 @@
 ural ? %22
-S
+s
 %22 : %22%22))
@@ -1170,24 +1170,32 @@
 eededTypes.%0A
+     * %0A
      * @retu
@@ -1270,24 +1270,17 @@
 pes() %7B%0A
-        
+%09
 return n
@@ -1369,16 +1369,24 @@
 ameter.%0A
+     * %0A
      * @
@@ -1402,16 +1402,34 @@
 dedTypes
+%0A     *           
  the nee
@@ -1517,24 +1517,17 @@
 ypes) %7B%0A
-        
+%09
 this.nee
@@ -1563,16 +1563,23 @@
 %0A%0A    /*
+%0A     *
  (non-Ja
@@ -1585,16 +1585,24 @@
 avadoc)%0A
+     * %0A
      * @
@@ -1760,11 +1760,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Fix of a bug when calling String.format