Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VBL Excluding #4838

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.awt.geom.PathIterator;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.function.BiConsumer;
import net.rptools.maptool.client.MapTool;
Expand Down Expand Up @@ -163,7 +164,16 @@ private Topology_Functions() {
"transferHillVBL",
"transferPitVBL",
"transferCoverVBL",
"transferMBL");
"transferMBL",
"setTokenVBLImmunity",
"addTokenVBLImmunity",
"removeTokenVBLImmunity",
"getTokenVBLImmunity",
"setGlobalVBLImmunity",
"toggleGlobalVBLImmunity",
"getGlobalVBLImmunity",
"clearTokenVBLImmunity",
"clearGlobalVBLImmunity");
}

public static Topology_Functions getInstance() {
Expand Down Expand Up @@ -214,6 +224,17 @@ public Object childEvaluate(
|| functionName.equalsIgnoreCase("transferCoverVBL")
|| functionName.equalsIgnoreCase("transferMBL")) {
childEvaluateTransferTopology(resolver, functionName, parameters);
} else if (functionName.equalsIgnoreCase("setTokenVBLImmunity")
|| functionName.equalsIgnoreCase("addTokenVBLImmunity")
|| functionName.equalsIgnoreCase("removeTokenVBLImmunity")
|| functionName.equalsIgnoreCase("setGlobalVBLImmunity")
|| functionName.equalsIgnoreCase("toggleGlobalVBLImmunity")
|| functionName.equalsIgnoreCase("clearTokenVBLImmunity")
|| functionName.equalsIgnoreCase("clearGlobalVBLImmunity")) {
childEvaluateSetTopologyImmunity(resolver, functionName, parameters);
} else if (functionName.equalsIgnoreCase("getTokenVBLImmunity")
|| functionName.equalsIgnoreCase("getGlobalVBLImmunity")) {
return childEvaluateGetTopologyImmunity(resolver, functionName, parameters).toString();
} else {
throw new ParserException(
I18N.getText("macro.function.general.unknownFunction", functionName));
Expand Down Expand Up @@ -614,6 +635,117 @@ private void childEvaluateTransferTopology(
}
}

public void childEvaluateSetTopologyImmunity(
VariableResolver resolver, String functionName, List<Object> parameters)
throws ParserException {

if (parameters.size() > 3) {
throw new ParserException(
I18N.getText("macro.function.general.tooManyParam", functionName, 1, parameters.size()));
}

if (parameters.isEmpty()) {
throw new ParserException(
I18N.getText(
"macro.function.general.notEnoughParam", functionName, 1, parameters.size()));
}

if (!MapTool.getParser().isMacroTrusted()) {
throw new ParserException(I18N.getText("macro.function.general.noPerm", functionName));
}

Token token = FindTokenFunctions.findToken(parameters.get(0).toString(), null);
if (token == null) {
throw new ParserException(
I18N.getText(
"macro.function.general.unknownToken", functionName, parameters.get(0).toString()));
}

if (functionName.equalsIgnoreCase("setTokenVBLImmunity")) {
JsonArray setList =
net.rptools.maptool.util.FunctionUtil.paramAsJsonArray(functionName, parameters, 1);
HashSet<String> newSet = new HashSet<String>();
for (JsonElement entry : setList) {
newSet.add(entry.getAsString());
}
MapTool.serverCommand()
.updateTokenProperty(
token, Token.Update.setTokenVBLImmunity, newSet.toString().replaceAll("^\\[|]$", ""));
} else if (functionName.equalsIgnoreCase("addTokenVBLImmunity")) {
MapTool.serverCommand()
.updateTokenProperty(
token, Token.Update.addTokenVBLImmunity, parameters.get(1).toString());
} else if (functionName.equalsIgnoreCase("removeTokenVBLImmunity")) {
MapTool.serverCommand()
.updateTokenProperty(
token, Token.Update.removeTokenVBLImmunity, parameters.get(1).toString());
} else if (functionName.equalsIgnoreCase("setGlobalVBLImmunity")) {
MapTool.serverCommand()
.updateTokenProperty(
token,
Token.Update.setGlobalVBLImmunity,
parameters.get(1).toString(),
BigDecimal.ONE.equals(parameters.get(2)));
} else if (functionName.equalsIgnoreCase("toggleGlobalVBLImmunity")) {
MapTool.serverCommand()
.updateTokenProperty(
token, Token.Update.toggleGlobalVBLImmunity, parameters.get(1).toString());
} else if (functionName.equalsIgnoreCase("clearTokenVBLImmunity")) {
MapTool.serverCommand().updateTokenProperty(token, Token.Update.clearTokenVBLImmunity);
} else if (functionName.equalsIgnoreCase("clearGlobalVBLImmunity")) {
MapTool.serverCommand().updateTokenProperty(token, Token.Update.clearGlobalVBLImmunity);
}
}

public JsonArray childEvaluateGetTopologyImmunity(
VariableResolver resolver, String functionName, List<Object> parameters)
throws ParserException {

if (parameters.size() > 3) {
throw new ParserException(
I18N.getText("macro.function.general.tooManyParam", functionName, 1, parameters.size()));
}

if (parameters.isEmpty()) {
throw new ParserException(
I18N.getText(
"macro.function.general.notEnoughParam", functionName, 1, parameters.size()));
}

if (!MapTool.getParser().isMacroTrusted()) {
throw new ParserException(I18N.getText("macro.function.general.noPerm", functionName));
}

Token token = FindTokenFunctions.findToken(parameters.get(0).toString(), null);
if (token == null) {
throw new ParserException(
I18N.getText(
"macro.function.general.unknownToken", functionName, parameters.get(0).toString()));
}

JsonArray returnValue = new JsonArray();

if (functionName.equalsIgnoreCase("getTokenVBLImmunity")) {
token
.getTokenVBLImmunity()
.forEach(
(value) -> {
returnValue.add(value);
});
} else if (functionName.equalsIgnoreCase("getGlobalVBLImmunity")) {
token
.getGlobalVBLImmunity()
.forEach(
(key, value) -> {
if (value) {
returnValue.add(key);
}
});
}

return returnValue;
}

/**
* Auto generate topology using token topology optimzation options
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package net.rptools.maptool.client.script.javascript.api;

import com.google.gson.JsonArray;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -350,4 +351,63 @@ public void setNPC() {
public String getType() {
return this.token.getType().name();
}

@HostAccess.Export
public String getGlobalVBLImmunity() {
JsonArray returnValue = new JsonArray();
token
.getGlobalVBLImmunity()
.forEach(
(key, value) -> {
if (value) {
returnValue.add(key);
}
});
return returnValue.toString();
}

@HostAccess.Export
public String getTokenVBLImmunity() {
JsonArray returnValue = new JsonArray();
token
.getTokenVBLImmunity()
.forEach(
(value) -> {
returnValue.add(value);
});
return returnValue.toString();
}

@HostAccess.Export
public void setGlobalVBLImmunity(String vblSelector, boolean setTo) {
MapTool.serverCommand()
.updateTokenProperty(token, Token.Update.setGlobalVBLImmunity, vblSelector, setTo);
}

@HostAccess.Export
public void toggleGlobalVBLImmunity(String vblSelector) {
MapTool.serverCommand()
.updateTokenProperty(token, Token.Update.toggleGlobalVBLImmunity, vblSelector);
}

@HostAccess.Export
public void addTokenVBLImmunity(String tokenID) {
MapTool.serverCommand().updateTokenProperty(token, Token.Update.addTokenVBLImmunity, tokenID);
}

@HostAccess.Export
public void removeTokenVBLImmunity(String tokenID) {
MapTool.serverCommand()
.updateTokenProperty(token, Token.Update.removeTokenVBLImmunity, tokenID);
}

@HostAccess.Export
public void clearTokenVBLImmunity() {
MapTool.serverCommand().updateTokenProperty(token, Token.Update.clearTokenVBLImmunity);
}

@HostAccess.Export
public void clearGlobalVBLImmunity() {
MapTool.serverCommand().updateTokenProperty(token, Token.Update.clearGlobalVBLImmunity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ public void paintOverlay(ZoneRenderer renderer, Graphics2D g) {
g2.scale(renderer.getScale(), renderer.getScale());

g2.setColor(AppStyle.tokenMblColor);
g2.fill(zone.getTokenMaskTopology(Zone.TopologyType.MBL, null));
g2.fill(zone.getTokenMaskTopology(Zone.TopologyType.MBL));
g2.setColor(AppStyle.tokenTopologyColor);
g2.fill(zone.getTokenMaskTopology(Zone.TopologyType.WALL_VBL, null));
g2.fill(zone.getTokenMaskTopology(Zone.TopologyType.WALL_VBL));
g2.setColor(AppStyle.tokenHillVblColor);
g2.fill(zone.getTokenMaskTopology(Zone.TopologyType.HILL_VBL, null));
g2.fill(zone.getTokenMaskTopology(Zone.TopologyType.HILL_VBL));
g2.setColor(AppStyle.tokenPitVblColor);
g2.fill(zone.getTokenMaskTopology(Zone.TopologyType.PIT_VBL, null));
g2.fill(zone.getTokenMaskTopology(Zone.TopologyType.PIT_VBL));
g2.setColor(AppStyle.tokenCoverVblColor);
g2.fill(zone.getTokenMaskTopology(Zone.TopologyType.COVER_VBL, null));
g2.fill(zone.getTokenMaskTopology(Zone.TopologyType.COVER_VBL));

g2.setColor(AppStyle.topologyTerrainColor);
g2.fill(zone.getMaskTopology(Zone.TopologyType.MBL));
Expand Down
Loading
Loading