Re: Forlage zu Erweiterte Befehle
Verfasst: Sa 26. Mär 2016, 20:29
Keine Sorge in Entwicklung werde ich sicher auch noch tätig, so viele Baustellen wie es in Fantasya gibt. Aber erstmal an kleinen Projekten Java lernen.
Code: Alles auswählen
// mOrdersauswertung
String regex = "(?<mPrefix>// #)(?<mOrder>[A-Za-z_]{3,10})(?<mCounter>[\\d]{0,4})(?<mSubOrders>.*$)?";
Pattern p = Pattern.compile(regex);
Matcher m;
for (Region region : world.regions().values()) {
for (Unit unit : region.units()) {
int index = 0;
for (String subOrder : unit.getOrders()) {
m = p.matcher(subOrder);
if (m.find()) {
String mPrefix = m.group("mPrefix");
String mOrder = m.group("mOrder");
int mCounter = 0;
if (!(m.group("mCounter").isEmpty()))
mCounter = Integer.parseInt(m.group("mCounter"));
String mSubOrders = m.group("mSubOrders");
ArrayList mOrdersListe = new ArrayList();
switch (mOrder) {
case "efficency":
eff = mCounter;
break;
case "magbest":
if (!unit.isOrdersConfirmed()) {
unit.setOrdersConfirmed(true);
}
case "immer":
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so.trim());
} else {
mOrdersListe.add(mSubOrders.trim());
}
break;
case "next":
mCounter--;
unit.removeOrderAt(index);
if (mCounter > 0) {
mOrdersListe.add(mPrefix + mOrder + mCounter + mSubOrders);
} else {
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so.trim());
} else {
mOrdersListe.add(mSubOrders.trim());
}
}
break;
case "mal":
mCounter--;
unit.removeOrderAt(index);
if (mCounter > 0) {
mOrdersListe.add(mPrefix + mOrder + mCounter + mSubOrders);
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so.trim());
} else {
mOrdersListe.add(mSubOrders.trim());
}
}
break;
case "rotate":
mCounter++;
String[] mso = mSubOrders.split(":");
int numRotate = mso.length;
if (mCounter > numRotate) mCounter = 1;
unit.removeOrderAt(index);
mOrdersListe.add(mPrefix + mOrder + mCounter + mSubOrders);
int i = 1;
for (String so : mso) {
if (i == mCounter) mOrdersListe.add(so.trim());
i++;
}
break;
default:
}
unit.addOrders(mOrdersListe);
}
index++;
}
}
}
Code: Alles auswählen
int rTrees = unit.getRegion().getResourceAmount("Holz");
Fehler bei der Ausführung
Sourced file: inline evaluation of: ``import magellan.client.*; import magellan.client.extern.*; import magellan.libra . . . '' : Typed variable declaration : Error in method invocation: Method getResourceAmount( java.lang.String ) not found in class'magellan.library.impl.MagellanRegionImpl'
Sourced file: inline evaluation of: ``import magellan.client.*; import magellan.client.extern.*; import magellan.libra . . . '' : Typed variable declaration : Error in method invocation: Method getResourceAmount( java.lang.String ) not found in class'magellan.library.impl.MagellanRegionImpl' : at Line: 84 : in file: inline evaluation of: ``import magellan.client.*; import magellan.client.extern.*; import magellan.libra . . . '' : .getResourceAmount ( "Holz" )
Code: Alles auswählen
int rTrees = unit.getRegion().getResource(region.data.getRules().getItemType(StringID.create("Holz"))).getAmount();
// int rTrees = unit.getRegion().getResource(region.data.getRules().getItemType("Holz")).getAmount();
Code: Alles auswählen
public ItemType getItemType(String typeName) {
return world.getRules().getItemType(StringID.create(typeName));
}
Code: Alles auswählen
// mOrdersauswertung
String regex = "(?<mPrefix>// #)(?<mOrder>[A-Za-z_]{3,10})(?<mCounter>[\\d]{0,4})(?<mSubOrders>.*$)?";
Pattern p = Pattern.compile(regex);
Matcher m;
int eff = 100;
for (Region region : world.regions().values()) {
for (Unit unit : region.units()) {
int index = 0;
for (String subOrder : unit.getOrders()) {
m = p.matcher(subOrder);
if (m.find()) {
String mPrefix = m.group("mPrefix");
String mOrder = m.group("mOrder");
int mCounter = 0;
if (!(m.group("mCounter").isEmpty()))
mCounter = Integer.parseInt(m.group("mCounter"));
String mSubOrders = m.group("mSubOrders");
ArrayList mOrdersListe = new ArrayList();
switch (mOrder) {
case "efficency":
eff = mCounter;
break;
case "magbest":
if (!unit.isOrdersConfirmed()) {
unit.setOrdersConfirmed(true);
}
case "immer":
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so.trim());
} else {
mOrdersListe.add(mSubOrders.trim());
}
break;
case "next":
mCounter--;
unit.removeOrderAt(index);
if (mCounter > 0) {
mOrdersListe.add(mPrefix + mOrder + mCounter + mSubOrders);
} else {
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so.trim());
} else {
mOrdersListe.add(mSubOrders.trim());
}
}
break;
case "mal":
mCounter--;
unit.removeOrderAt(index);
if (mCounter > 0) {
mOrdersListe.add(mPrefix + mOrder + mCounter + mSubOrders);
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so.trim());
} else {
mOrdersListe.add(mSubOrders.trim());
}
}
break;
case "rotate":
mCounter++;
String[] mso = mSubOrders.split(":");
int numRotate = mso.length;
if (mCounter > numRotate)
mCounter = 1;
unit.removeOrderAt(index);
mOrdersListe.add(mPrefix + mOrder + mCounter + mSubOrders);
int i = 1;
for (String so : mso) {
if (i == mCounter)
mOrdersListe.add(so.trim());
i++;
}
break;
case "forst":
int rTrees = unit.getRegion()
.getResource(region.data.getRules().getItemType(StringID.create("Holz")))
.getAmount();
int uCap = helper.getLevel(unit, "Holzfällen") * unit.getPersons();
if ((int) (0.01 * (uCap * eff + mCounter)) >= rTrees) {
mOrdersListe.add("MACHE " + (rTrees - mCounter) + " Holz");
} else {
mOrdersListe.add(mSubOrders.trim());
}
break;
default:
}
unit.addOrders(mOrdersListe);
}
index++;
}
}
}
Code: Alles auswählen
// mOrdersauswertung
String regex = "(?<mPrefix>// #)(?<mOrder>[A-Za-z_]{3,10})\\u0020?(?<mCounter>[\\d]{0,4})\\u0020(?<mCounter2>[\\d]{0,4})\\u0020?(?<mSubOrders>.*$)?";
Pattern p = Pattern.compile(regex);
Matcher m;
int eff = 100;
for (Region region : world.regions().values()) {
for (Unit unit : region.units()) {
int index = 0;
for (String subOrder : unit.getOrders()) {
m = p.matcher(subOrder);
if (m.find()) {
String mPrefix = m.group("mPrefix");
String mOrder = m.group("mOrder");
int mCounter = 0;
if (!(m.group("mCounter").isEmpty()))
mCounter = Integer.parseInt(m.group("mCounter"));
String mSubOrders = m.group("mSubOrders");
ArrayList mOrdersListe = new ArrayList();
switch (mOrder) {
case "auslastung":
eff = mCounter;
break;
case "magbest":
if (!unit.isOrdersConfirmed()) {
unit.setOrdersConfirmed(true);
}
case "immer":
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so.trim());
} else {
mOrdersListe.add(mSubOrders.trim());
}
break;
case "next":
mCounter--;
unit.removeOrderAt(index);
if (mCounter > 0) {
mOrdersListe.add(mPrefix + mOrder + " " + mCounter + " " + mSubOrders);
} else {
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so);
} else {
mOrdersListe.add(mSubOrders);
}
}
break;
case "mal":
mCounter--;
unit.removeOrderAt(index);
if (mCounter > 0) {
mOrdersListe.add(mPrefix + mOrder + " " + mCounter + " " + mSubOrders);
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so);
} else {
mOrdersListe.add(mSubOrders);
}
}
break;
case "rotate":
mCounter++;
String[] mso = mSubOrders.split(":");
int numRotate = mso.length;
if (mCounter > numRotate)
mCounter = 1;
unit.removeOrderAt(index);
mOrdersListe.add(mPrefix + mOrder + " " + mCounter + " " + mSubOrders);
int i = 1;
for (String so : mso) {
if (i == mCounter)
mOrdersListe.add(so);
i++;
}
break;
case "forst":
int rTrees = unit.getRegion()
.getResource(region.data.getRules().getItemType(StringID.create("Holz")))
.getAmount();
int mCounter2 = -1;
if (!(m.group("mCounter2").isEmpty()))
mCounter2 = Integer.parseInt(m.group("mCounter2"));
int uCap = helper.getLevel(unit, "Holzfällen") * unit.getPersons();
int fellTrees = 0;
// int fellTrees = (mCounter2 > 0) ?
// ((mCounter2-mCounter)>uCap) ?
// uCap : mCounter2-mCounter : (rTrees>mCounter) ?
// rTrees-mCounter : 0;
if (mCounter2 > 0) {
if (rTrees > mCounter2) {
if ((mCounter2 - mCounter) > uCap) {
fellTrees = uCap;
} else {
fellTrees = mCounter2 - mCounter;
}
}
} else {
if (rTrees > mCounter) {
fellTrees = rTrees - mCounter;
}
}
if (fellTrees > 0) {
mOrdersListe.add("MACHE " + fellTrees + " Holz");
} else {
mOrdersListe.add(mSubOrders);
}
break;
default:
}
unit.addOrders(mOrdersListe);
}
index++;
}
}
}
Code: Alles auswählen
import magellan.client.*;
import magellan.client.extern.*;
import magellan.library.*;
import magellan.library.rules.*;
import magellan.plugin.extendedcommands.*;
import java.util.ArrayList;
import java.util.regex.*;
// mOrdersauswertung
String regex = "(?<mPrefix>// #)(?<mOrder>[A-Za-z_]{3,10})\\u0020?(?<mCounter>[\\d]{0,4})\\u0020(?<mCounter2>[\\d]{0,4})\\u0020?(?<mSubOrders>.*$)?";
Pattern p = Pattern.compile(regex);
Matcher m;
int eff = 100;
for (Region region : world.regions().values()) {
for (Unit unit : region.units()) {
int index = 0;
for (String subOrder : unit.getOrders()) {
m = p.matcher(subOrder);
if (m.find()) {
String mPrefix = m.group("mPrefix");
String mOrder = m.group("mOrder");
int mCounter = 0;
if (!(m.group("mCounter").isEmpty()))
mCounter = Integer.parseInt(m.group("mCounter"));
String mSubOrders = m.group("mSubOrders");
ArrayList mOrdersListe = new ArrayList();
switch (mOrder) {
case "auslastung":
eff = mCounter;
break;
case "magbest":
if (!unit.isOrdersConfirmed()) {
unit.setOrdersConfirmed(true);
}
case "immer":
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so.trim());
} else {
mOrdersListe.add(mSubOrders.trim());
}
break;
case "next":
mCounter--;
unit.removeOrderAt(index);
if (mCounter > 0) {
mOrdersListe.add(mPrefix + mOrder + " " + mCounter + " " + mSubOrders);
} else {
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so);
} else {
mOrdersListe.add(mSubOrders);
}
}
break;
case "mal":
mCounter--;
unit.removeOrderAt(index);
if (mCounter > 0) {
mOrdersListe.add(mPrefix + mOrder + " " + mCounter + " " + mSubOrders);
if (mSubOrders.contains(":")) {
for (String so : mSubOrders.split(":"))
mOrdersListe.add(so);
} else {
mOrdersListe.add(mSubOrders);
}
}
break;
case "rotate":
mCounter++;
String[] mso = mSubOrders.split(":");
int numRotate = mso.length;
if (mCounter > numRotate)
mCounter = 1;
unit.removeOrderAt(index);
mOrdersListe.add(mPrefix + mOrder + " " + mCounter + " " + mSubOrders);
int i = 1;
for (String so : mso) {
if (i == mCounter)
mOrdersListe.add(so);
i++;
}
break;
case "forst":
int rTrees = unit.getRegion()
.getResource(region.data.getRules().getItemType(StringID.create("Holz")))
.getAmount();
int mCounter2 = -1;
if (!(m.group("mCounter2").isEmpty()))
mCounter2 = Integer.parseInt(m.group("mCounter2"));
int uCapWood = helper.getLevel(unit, "Holzfällen") * unit.getPersons();
int fellTrees = 0;
if (mCounter2 > 0) {
if (rTrees > mCounter2) {
if ((mCounter2 - mCounter) > uCapWood) {
fellTrees = uCapWood;
} else {
fellTrees = mCounter2 - mCounter;
}
}
} else {
if (rTrees > mCounter) {
fellTrees = rTrees - mCounter;
}
}
if (fellTrees > 0) {
mOrdersListe.add("MACHE " + fellTrees + " Holz");
} else {
mOrdersListe.add(mSubOrders);
}
break;
case "herde":
String mAnimSO;
String mAnim;
int uCapAnimal = helper.getLevel(unit, "Pferdedressur") * unit.getPersons();
int herdAnimals = 0;
for (String so : mSubOrders.split(":")) {
String animRegex = "(?i)(?<mAnim>pferd|kamel|elefant|zotte|alpaka|mastodon)\\u0020(?<mAnimC1>[\\d]{1,4})\\u0020(?<mAnimC2>[\\d]{1,4})?\\u0020?(?<mAnimSO>.*$)?";
Pattern animP = Pattern.compile(animRegex);
Matcher animM;
animM = animP.matcher(so);
if (animM.find()) {
mAnim = animM.group("mAnim");
int rHerd = unit.getRegion().getResource(region.data.getRules().getItemType(StringID.create(mAnim))).getAmount();
int mAnimC1 = Integer.parseInt(animM.group("mAnimC1"));
int mAnimC2 = (animM.group("mAnimC2") != null) ? Integer.parseInt(animM.group("mAnimC2")) : mAnimC1;
if (rHerd > mAnimC2) {
String s = mAnim.toLowerCase();
int eFactor = (s.contains("elefant") || s.contains("mastodon")) ? 2 : 1;
herdAnimals = Math.min((int)(uCapAnimal/eFactor), rHerd - mAnimC2);
break;
}
}
}
if (herdAnimals > 0) {
mOrdersListe.add("MACHE " + herdAnimals + " " + mAnim);
} else {
mOrdersListe.add(mAnimSO);
}
break;
default:
}
unit.addOrders(mOrdersListe);
}
index++;
}
}
}
Fehler gefunden.Tsaria hat geschrieben:Solltet ihr Fehler finden, oder herausfinden warum diese eine verf... line nicht geht, wäre ich über eine Rückmeldung sehr dankbar:
Code: Alles auswählen
int rTrees = helper.getResourceAmount("Holz");