<commit_before>package net.zomis.cardshifter.ecs.systems;

import java.util.function.ToIntFunction;
import java.util.function.UnaryOperator;

import net.zomis.cardshifter.ecs.actions.ActionAllowedCheckEvent;
import net.zomis.cardshifter.ecs.actions.ActionPerformEvent;
import net.zomis.cardshifter.ecs.actions.SpecificActionSystem;
import net.zomis.cardshifter.ecs.base.Entity;
import net.zomis.cardshifter.ecs.resources.ECSResource;
import net.zomis.cardshifter.ecs.resources.ECSResourceData;
import net.zomis.cardshifter.ecs.resources.ResourceRetriever;

public class UseCostSystem extends SpecificActionSystem {

	private final ToIntFunction<Entity> cost;
	private final UnaryOperator<Entity> whoPays;
	private final ResourceRetriever useResource;

	public UseCostSystem(String action, ECSResource useResource, ToIntFunction<Entity> cost, UnaryOperator<Entity> whoPays) {
		super(action);
		this.useResource = ResourceRetriever.forResource(useResource);
		this.cost = cost;
		this.whoPays = whoPays;
	}

	@Override
	protected void isAllowed(ActionAllowedCheckEvent event) {
		ECSResourceData have = useResource.resFor(whoPays.apply(event.getEntity()));
		int want = cost.applyAsInt(event.getEntity());
		if (!have.has(want)) {
			event.setAllowed(false);
		}
	}
	
	@Override
	protected void onPerform(ActionPerformEvent event) {
		if (event.getEntity().isRemoved()) {
			return;
		}
		ECSResourceData have = useResource.resFor(whoPays.apply(event.getEntity()));
		int want = cost.applyAsInt(event.getEntity());
		have.change(-want);
	}

}<commit_msg>Added toString to UseCostSystem<commit_after>package net.zomis.cardshifter.ecs.systems;

import java.util.function.ToIntFunction;
import java.util.function.UnaryOperator;

import net.zomis.cardshifter.ecs.actions.ActionAllowedCheckEvent;
import net.zomis.cardshifter.ecs.actions.ActionPerformEvent;
import net.zomis.cardshifter.ecs.actions.SpecificActionSystem;
import net.zomis.cardshifter.ecs.base.Entity;
import net.zomis.cardshifter.ecs.resources.ECSResource;
import net.zomis.cardshifter.ecs.resources.ECSResourceData;
import net.zomis.cardshifter.ecs.resources.ResourceRetriever;

public class UseCostSystem extends SpecificActionSystem {

	private final ToIntFunction<Entity> cost;
	private final UnaryOperator<Entity> whoPays;
	private final ResourceRetriever useResource;

	public UseCostSystem(String action, ECSResource useResource, ToIntFunction<Entity> cost, UnaryOperator<Entity> whoPays) {
		super(action);
		this.useResource = ResourceRetriever.forResource(useResource);
		this.cost = cost;
		this.whoPays = whoPays;
	}

	@Override
	protected void isAllowed(ActionAllowedCheckEvent event) {
		ECSResourceData have = useResource.resFor(whoPays.apply(event.getEntity()));
		int want = cost.applyAsInt(event.getEntity());
		if (!have.has(want)) {
			event.setAllowed(false);
		}
	}
	
	@Override
	protected void onPerform(ActionPerformEvent event) {
		if (event.getEntity().isRemoved()) {
			return;
		}
		ECSResourceData have = useResource.resFor(whoPays.apply(event.getEntity()));
		int want = cost.applyAsInt(event.getEntity());
		have.change(-want);
	}

	@Override
	public String toString() {
		return "UseCostSystem [action=" + getActionName() + ", useResource=" + useResource + "]";
	}

}
{'fraction_non_alphanumeric': 0.11077017490027616, 'fraction_numerical': 0.0, 'mean_word_length': 6.0562770562770565, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3876540', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1075, 'n_words': 177}