use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class TriggerAttachment method triggerProductionChange.
public static void triggerProductionChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, prodMatch());
if (testWhen) {
trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
}
if (testUses) {
trigs = CollectionUtils.getMatches(trigs, availableUses);
}
final CompositeChange change = new CompositeChange();
for (final TriggerAttachment t : trigs) {
if (testChance && !t.testChance(bridge)) {
continue;
}
if (useUses) {
t.use(bridge);
}
for (final PlayerID player : t.getPlayers()) {
change.add(ChangeFactory.changeProductionFrontier(player, t.getFrontier()));
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": " + player.getName() + " has their production frontier changed to: " + t.getFrontier().getName());
}
}
if (!change.isEmpty()) {
bridge.addChange(change);
}
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class TriggerAttachment method triggerUnitPropertyChange.
public static void triggerUnitPropertyChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, unitPropertyMatch());
if (testWhen) {
trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
}
if (testUses) {
trigs = CollectionUtils.getMatches(trigs, availableUses);
}
final CompositeChange change = new CompositeChange();
for (final TriggerAttachment t : trigs) {
if (testChance && !t.testChance(bridge)) {
continue;
}
if (useUses) {
t.use(bridge);
}
for (final Tuple<String, String> property : t.getUnitProperty()) {
for (final UnitType unitType : t.getUnitType()) {
String newValue = property.getSecond();
boolean clearFirst = false;
// test if we are resetting the variable first, and if so, remove the leading "-reset-" or "-clear-"
if (newValue.length() > 0 && (newValue.startsWith(PREFIX_CLEAR) || newValue.startsWith(PREFIX_RESET))) {
newValue = newValue.replaceFirst(PREFIX_CLEAR, "").replaceFirst(PREFIX_RESET, "");
clearFirst = true;
}
// covers UnitAttachment, UnitSupportAttachment
if (t.getUnitAttachmentName().getFirst().equals("UnitAttachment")) {
final UnitAttachment attachment = UnitAttachment.get(unitType, t.getUnitAttachmentName().getSecond());
if (newValue.equals(attachment.getRawPropertyString(property.getFirst()))) {
continue;
}
if (clearFirst && newValue.length() < 1) {
change.add(ChangeFactory.attachmentPropertyReset(attachment, property.getFirst()));
} else {
change.add(ChangeFactory.attachmentPropertyChange(attachment, newValue, property.getFirst(), clearFirst));
}
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Setting " + property.getFirst() + (newValue.length() > 0 ? " to " + newValue : " cleared ") + " for " + t.getUnitAttachmentName().getSecond() + " attached to " + unitType.getName());
} else if (t.getUnitAttachmentName().getFirst().equals("UnitSupportAttachment")) {
final UnitSupportAttachment attachment = UnitSupportAttachment.get(unitType, t.getUnitAttachmentName().getSecond());
if (newValue.equals(attachment.getRawPropertyString(property.getFirst()))) {
continue;
}
if (clearFirst && newValue.length() < 1) {
change.add(ChangeFactory.attachmentPropertyReset(attachment, property.getFirst()));
} else {
change.add(ChangeFactory.attachmentPropertyChange(attachment, newValue, property.getFirst(), clearFirst));
}
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Setting " + property.getFirst() + (newValue.length() > 0 ? " to " + newValue : " cleared ") + " for " + t.getUnitAttachmentName().getSecond() + " attached to " + unitType.getName());
}
// TODO add other attachment changes here if they attach to a unitType
}
}
}
if (!change.isEmpty()) {
bridge.addChange(change);
}
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class TriggerAttachment method triggerSupportChange.
public static void triggerSupportChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
final GameData data = bridge.getData();
Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, supportMatch());
if (testWhen) {
trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
}
if (testUses) {
trigs = CollectionUtils.getMatches(trigs, availableUses);
}
final CompositeChange change = new CompositeChange();
for (final TriggerAttachment t : trigs) {
if (testChance && !t.testChance(bridge)) {
continue;
}
if (useUses) {
t.use(bridge);
}
for (final PlayerID player : t.getPlayers()) {
for (final String usaString : t.getSupport().keySet()) {
UnitSupportAttachment usa = null;
for (final UnitSupportAttachment support : UnitSupportAttachment.get(data)) {
if (support.getName().equals(usaString)) {
usa = support;
break;
}
}
if (usa == null) {
throw new IllegalStateException("Could not find unitSupportAttachment. name:" + usaString);
}
final List<PlayerID> p = new ArrayList<>(usa.getPlayers());
if (p.contains(player)) {
if (!t.getSupport().get(usa.getName())) {
p.remove(player);
change.add(ChangeFactory.attachmentPropertyChange(usa, p, "players"));
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": " + player.getName() + " is removed from " + usa.toString());
}
} else {
if (t.getSupport().get(usa.getName())) {
p.add(player);
change.add(ChangeFactory.attachmentPropertyChange(usa, p, "players"));
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": " + player.getName() + " is added to " + usa.toString());
}
}
}
}
}
if (!change.isEmpty()) {
bridge.addChange(change);
}
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class TriggerAttachment method triggerPlayerPropertyChange.
public static void triggerPlayerPropertyChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, playerPropertyMatch());
if (testWhen) {
trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
}
if (testUses) {
trigs = CollectionUtils.getMatches(trigs, availableUses);
}
final CompositeChange change = new CompositeChange();
for (final TriggerAttachment t : trigs) {
if (testChance && !t.testChance(bridge)) {
continue;
}
if (useUses) {
t.use(bridge);
}
for (final Tuple<String, String> property : t.getPlayerProperty()) {
for (final PlayerID player : t.getPlayers()) {
String newValue = property.getSecond();
boolean clearFirst = false;
// test if we are resetting the variable first, and if so, remove the leading "-reset-" or "-clear-"
if (newValue.length() > 0 && (newValue.startsWith(PREFIX_CLEAR) || newValue.startsWith(PREFIX_RESET))) {
newValue = newValue.replaceFirst(PREFIX_CLEAR, "").replaceFirst(PREFIX_RESET, "");
clearFirst = true;
}
// covers PlayerAttachment, TriggerAttachment, RulesAttachment, TechAttachment
if (t.getPlayerAttachmentName().getFirst().equals("PlayerAttachment")) {
final PlayerAttachment attachment = PlayerAttachment.get(player, t.getPlayerAttachmentName().getSecond());
if (newValue.equals(attachment.getRawPropertyString(property.getFirst()))) {
continue;
}
if (clearFirst && newValue.length() < 1) {
change.add(ChangeFactory.attachmentPropertyReset(attachment, property.getFirst()));
} else {
change.add(ChangeFactory.attachmentPropertyChange(attachment, newValue, property.getFirst(), clearFirst));
}
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Setting " + property.getFirst() + (newValue.length() > 0 ? " to " + newValue : " cleared ") + " for " + t.getPlayerAttachmentName().getSecond() + " attached to " + player.getName());
} else if (t.getPlayerAttachmentName().getFirst().equals("RulesAttachment")) {
final RulesAttachment attachment = RulesAttachment.get(player, t.getPlayerAttachmentName().getSecond());
if (newValue.equals(attachment.getRawPropertyString(property.getFirst()))) {
continue;
}
if (clearFirst && newValue.length() < 1) {
change.add(ChangeFactory.attachmentPropertyReset(attachment, property.getFirst()));
} else {
change.add(ChangeFactory.attachmentPropertyChange(attachment, newValue, property.getFirst(), clearFirst));
}
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Setting " + property.getFirst() + (newValue.length() > 0 ? " to " + newValue : " cleared ") + " for " + t.getPlayerAttachmentName().getSecond() + " attached to " + player.getName());
} else if (t.getPlayerAttachmentName().getFirst().equals("TriggerAttachment")) {
final TriggerAttachment attachment = TriggerAttachment.get(player, t.getPlayerAttachmentName().getSecond());
if (newValue.equals(attachment.getRawPropertyString(property.getFirst()))) {
continue;
}
if (clearFirst && newValue.length() < 1) {
change.add(ChangeFactory.attachmentPropertyReset(attachment, property.getFirst()));
} else {
change.add(ChangeFactory.attachmentPropertyChange(attachment, newValue, property.getFirst(), clearFirst));
}
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Setting " + property.getFirst() + (newValue.length() > 0 ? " to " + newValue : " cleared ") + " for " + t.getPlayerAttachmentName().getSecond() + " attached to " + player.getName());
} else if (t.getPlayerAttachmentName().getFirst().equals("TechAttachment")) {
final TechAttachment attachment = TechAttachment.get(player, t.getPlayerAttachmentName().getSecond());
if (newValue.equals(attachment.getRawPropertyString(property.getFirst()))) {
continue;
}
if (clearFirst && newValue.length() < 1) {
change.add(ChangeFactory.attachmentPropertyReset(attachment, property.getFirst()));
} else {
change.add(ChangeFactory.attachmentPropertyChange(attachment, newValue, property.getFirst(), clearFirst));
}
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Setting " + property.getFirst() + (newValue.length() > 0 ? " to " + newValue : " cleared ") + " for " + t.getPlayerAttachmentName().getSecond() + " attached to " + player.getName());
} else if (t.getPlayerAttachmentName().getFirst().equals("PoliticalActionAttachment")) {
final PoliticalActionAttachment attachment = PoliticalActionAttachment.get(player, t.getPlayerAttachmentName().getSecond());
if (newValue.equals(attachment.getRawPropertyString(property.getFirst()))) {
continue;
}
if (clearFirst && newValue.length() < 1) {
change.add(ChangeFactory.attachmentPropertyReset(attachment, property.getFirst()));
} else {
change.add(ChangeFactory.attachmentPropertyChange(attachment, newValue, property.getFirst(), clearFirst));
}
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Setting " + property.getFirst() + (newValue.length() > 0 ? " to " + newValue : " cleared ") + " for " + t.getPlayerAttachmentName().getSecond() + " attached to " + player.getName());
} else if (t.getPlayerAttachmentName().getFirst().equals("UserActionAttachment")) {
final UserActionAttachment attachment = UserActionAttachment.get(player, t.getPlayerAttachmentName().getSecond());
if (newValue.equals(attachment.getRawPropertyString(property.getFirst()))) {
continue;
}
if (clearFirst && newValue.length() < 1) {
change.add(ChangeFactory.attachmentPropertyReset(attachment, property.getFirst()));
} else {
change.add(ChangeFactory.attachmentPropertyChange(attachment, newValue, property.getFirst(), clearFirst));
}
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Setting " + property.getFirst() + (newValue.length() > 0 ? " to " + newValue : " cleared ") + " for " + t.getPlayerAttachmentName().getSecond() + " attached to " + player.getName());
}
// TODO add other attachment changes here if they attach to a player
}
}
}
if (!change.isEmpty()) {
bridge.addChange(change);
}
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class TriggerAttachment method triggerRelationshipTypePropertyChange.
public static void triggerRelationshipTypePropertyChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, relationshipTypePropertyMatch());
if (testWhen) {
trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
}
if (testUses) {
trigs = CollectionUtils.getMatches(trigs, availableUses);
}
final CompositeChange change = new CompositeChange();
for (final TriggerAttachment t : trigs) {
if (testChance && !t.testChance(bridge)) {
continue;
}
if (useUses) {
t.use(bridge);
}
for (final Tuple<String, String> property : t.getRelationshipTypeProperty()) {
for (final RelationshipType relationshipType : t.getRelationshipTypes()) {
String newValue = property.getSecond();
boolean clearFirst = false;
// test if we are resetting the variable first, and if so, remove the leading "-reset-" or "-clear-"
if (newValue.length() > 0 && (newValue.startsWith(PREFIX_CLEAR) || newValue.startsWith(PREFIX_RESET))) {
newValue = newValue.replaceFirst(PREFIX_CLEAR, "").replaceFirst(PREFIX_RESET, "");
clearFirst = true;
}
// covers RelationshipTypeAttachment
if (t.getRelationshipTypeAttachmentName().getFirst().equals("RelationshipTypeAttachment")) {
final RelationshipTypeAttachment attachment = RelationshipTypeAttachment.get(relationshipType, t.getRelationshipTypeAttachmentName().getSecond());
if (newValue.equals(attachment.getRawPropertyString(property.getFirst()))) {
continue;
}
if (clearFirst && newValue.length() < 1) {
change.add(ChangeFactory.attachmentPropertyReset(attachment, property.getFirst()));
} else {
change.add(ChangeFactory.attachmentPropertyChange(attachment, newValue, property.getFirst(), clearFirst));
}
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Setting " + property.getFirst() + (newValue.length() > 0 ? " to " + newValue : " cleared ") + " for " + t.getRelationshipTypeAttachmentName().getSecond() + " attached to " + relationshipType.getName());
}
// TODO add other attachment changes here if they attach to a territory
}
}
}
if (!change.isEmpty()) {
bridge.addChange(change);
}
}
Aggregations