|
|
|
@@ -30,6 +30,8 @@ namespace WorldOfPeacecraft
|
|
|
|
|
private Regex LastLineRegex;
|
|
|
|
|
private Backend backend;
|
|
|
|
|
|
|
|
|
|
enum Decision {DRAGON, STAGHUNT, SKIRMISH};
|
|
|
|
|
|
|
|
|
|
public Parser ()
|
|
|
|
|
{
|
|
|
|
|
ParserThread = new Thread (new ThreadStart (this.RunParser));
|
|
|
|
@@ -56,15 +58,24 @@ namespace WorldOfPeacecraft
|
|
|
|
|
if (IsCompletePackage ()) {
|
|
|
|
|
Parse ();
|
|
|
|
|
}
|
|
|
|
|
// TODO Try-catch. IMPORTANT!
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Parse ()
|
|
|
|
|
{
|
|
|
|
|
String[] aMessage = Enumerable.ToArray (Message);
|
|
|
|
|
Block mainBlock = new Block (aMessage, 0, aMessage.Length - 1);
|
|
|
|
|
ProcessData (mainBlock);
|
|
|
|
|
string[] aMessage = Enumerable.ToArray (Message);
|
|
|
|
|
Message.Clear();
|
|
|
|
|
try {
|
|
|
|
|
Block mainBlock = new Block (aMessage, 0, aMessage.Length - 1);
|
|
|
|
|
ProcessData (mainBlock);
|
|
|
|
|
} catch (ParsingException e) {
|
|
|
|
|
string errormsg = "Error while parsing message: " + e.Message + "\n";
|
|
|
|
|
errormsg += "Message:";
|
|
|
|
|
foreach (string line in aMessage) {
|
|
|
|
|
errormsg += "\n\t" + line;
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine(errormsg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessData (Block parentBlock)
|
|
|
|
@@ -153,6 +164,9 @@ namespace WorldOfPeacecraft
|
|
|
|
|
Dragon dragon = MapDragon (block);
|
|
|
|
|
backend.removeDragon (dragon);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ThrowUnknownBlockException(deleteBlock, block);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -179,11 +193,13 @@ namespace WorldOfPeacecraft
|
|
|
|
|
int srcid = mesBlock.GetIntValue ("srcid");
|
|
|
|
|
string src = mesBlock.GetStringValue ("src");
|
|
|
|
|
string txt = mesBlock.GetStringValue ("txt");
|
|
|
|
|
//Message m = new Message (srcid, src, txt);
|
|
|
|
|
Message m = new Message (srcid, src, txt);
|
|
|
|
|
//TODO Herausfinden wie wir das oben lösen (gilt für alle Funktionenstümpfe)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessAnswer (Block block)
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessResult (Block procBlock)
|
|
|
|
@@ -192,19 +208,56 @@ namespace WorldOfPeacecraft
|
|
|
|
|
int round = procBlock.GetIntValue ("round");
|
|
|
|
|
bool running = procBlock.GetBoolValue ("running");
|
|
|
|
|
int delay = procBlock.GetIntValue ("delay");
|
|
|
|
|
//ProcessOpponent (procBlock.GetBlocks ());
|
|
|
|
|
LinkedList <Block> block = procBlock.GetBlocks ();
|
|
|
|
|
ProcessOpponent (block.First.Value);
|
|
|
|
|
//Result r = new Result(round, running, delay);
|
|
|
|
|
}
|
|
|
|
|
//"round:",INT,"running:",BOOLEAN,"delay:",INT,"begin:opponents:"OPPONENT,OPPONENT","end:opponents",
|
|
|
|
|
|
|
|
|
|
private void ProcessOpponent(Block block)
|
|
|
|
|
private void ProcessOpponent(Block oppBlock)
|
|
|
|
|
{
|
|
|
|
|
//TODO
|
|
|
|
|
int id = oppBlock.GetIntValue ("id");
|
|
|
|
|
int points = oppBlock.GetIntValue ("points");
|
|
|
|
|
int total = oppBlock.GetIntValue ("total");
|
|
|
|
|
LinkedList <string> unnamedValue = oppBlock.GetUnnamedValues ();
|
|
|
|
|
string stringValue = unnamedValue.First.Value;
|
|
|
|
|
Decision d;
|
|
|
|
|
if (stringValue == "DRAGON")
|
|
|
|
|
d = Decision.DRAGON;
|
|
|
|
|
if (stringValue == "STAGHUNT")
|
|
|
|
|
d = Decision.STAGHUNT;
|
|
|
|
|
if (stringValue == "SKIRMISH")
|
|
|
|
|
d = Decision.SKIRMISH;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//DRAGON|STAGHUNT|SKIRMISH
|
|
|
|
|
|
|
|
|
|
private void ProcessDecision(Block block)
|
|
|
|
|
{
|
|
|
|
|
//TODO -> Wafa
|
|
|
|
|
//OK das ist hier so'n bissle der gleiche scheiß wie "Answer" wie soll das gehn, ohne Block!?
|
|
|
|
|
//Maybe not TODO?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessChallenge (Block block)
|
|
|
|
|
private void ProcessChallenge (Block challengeBlock)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//TODO -> Samed
|
|
|
|
|
int id = challengeBlock.GetIntValue("id");
|
|
|
|
|
String type;
|
|
|
|
|
switch (challengeBlock.GetStringValue())
|
|
|
|
|
{
|
|
|
|
|
case "DRAGON":
|
|
|
|
|
type = "Dragon";
|
|
|
|
|
break;
|
|
|
|
|
case "STAGHUNT":
|
|
|
|
|
type = "Staghunt";
|
|
|
|
|
break;
|
|
|
|
|
case "SKIRMISCH":
|
|
|
|
|
type = "Skirmisch";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
bool accepted = challengeBlock.GetBoolValue("accepted");
|
|
|
|
|
//Challenge c = new Challenge(id, type, accepted);
|
|
|
|
|
//CHALLENGE: "begin:challenge","id:",INT,"type:",("DRAGON"|"STAGHUNT"|"SKIRMISH"),"accepted:",BOOLEAN,"end:challenge"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessPlayer (Block playerBlock)
|
|
|
|
@@ -217,8 +270,11 @@ namespace WorldOfPeacecraft
|
|
|
|
|
int y = playerBlock.GetIntValue ("y");
|
|
|
|
|
//Player p = new Player(points, id, busy, desc, x, y,);
|
|
|
|
|
}
|
|
|
|
|
//"points:",INT, "id:",INT,"type:Player","busy:"BOOLEAN,"desc:"STRING,"x:",INT,"y:",INT,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ProcessMapcell (Block mapcellBlock)
|
|
|
|
|
{
|
|
|
|
|
backend.getMapObject().SetTile(MapMapcell(mapcellBlock));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessYourid (Block yourIdBlock)
|
|
|
|
|
{
|
|
|
|
@@ -226,26 +282,55 @@ namespace WorldOfPeacecraft
|
|
|
|
|
string stringValue = unnamedValues.First.Value;
|
|
|
|
|
int intValue = int.Parse (stringValue);
|
|
|
|
|
//YourID id = new YourID (intValue);
|
|
|
|
|
//TODO Herausfinden wie wir das oben lösen
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessTime (Block block)
|
|
|
|
|
private void ProcessTime (Block timeBlock)
|
|
|
|
|
{
|
|
|
|
|
LinkedList <string> unnamedValues = timeBlock.GetUnnamedValues ();
|
|
|
|
|
string stringValue = unnamedValues.First.Value;
|
|
|
|
|
long longValue = long.Parse (stringValue);
|
|
|
|
|
//Time t = new Time(longValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessOnline (Block block)
|
|
|
|
|
private void ProcessOnline (Block onlineBlock)
|
|
|
|
|
{
|
|
|
|
|
LinkedList <string> unnamedValues = onlineBlock.GetUnnamedValues ();
|
|
|
|
|
string stringValue = unnamedValues.First.Value;
|
|
|
|
|
int intValue = int.Parse (stringValue);
|
|
|
|
|
//Online o = new Online(intValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessEntities (Block block)
|
|
|
|
|
private void ProcessEntities (Block entitiesBlock)
|
|
|
|
|
{
|
|
|
|
|
backend.clearDragons ();
|
|
|
|
|
backend.clearPlayers ();
|
|
|
|
|
foreach (Block entityBlock in entitiesBlock.GetBlocks ()) {
|
|
|
|
|
switch (entityBlock.GetName()) {
|
|
|
|
|
case MessPlayer:
|
|
|
|
|
backend.SetPlayer(MapPlayer(entityBlock));
|
|
|
|
|
break;
|
|
|
|
|
case MessDragon:
|
|
|
|
|
backend.SetDragon(MapDragon(entityBlock));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ThrowUnknownBlockException(entitiesBlock, entityBlock);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessPlayers (Block block)
|
|
|
|
|
private void ProcessPlayers (Block playersBlock)
|
|
|
|
|
{
|
|
|
|
|
backend.clearPlayers ();
|
|
|
|
|
foreach (Block playerBlock in playersBlock.GetBlocks ()) {
|
|
|
|
|
backend.SetPlayer(MapPlayer(playerBlock));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessDragon (Block block)
|
|
|
|
|
private void ProcessDragon (Block dragonBlock)
|
|
|
|
|
{
|
|
|
|
|
backend.SetDragon(MapDragon(dragonBlock));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Dragon MapDragon (Block dragonBlock)
|
|
|
|
@@ -298,7 +383,7 @@ namespace WorldOfPeacecraft
|
|
|
|
|
huntable = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ParsingException("Unknown mapcell-property '" + prop + "'");
|
|
|
|
|
throw new ParsingException("Unknown mapcell property '" + prop + "'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new Tile(x,y,walkable, wall, forest, huntable, water);
|
|
|
|
@@ -401,22 +486,48 @@ namespace WorldOfPeacecraft
|
|
|
|
|
|
|
|
|
|
public string GetStringValue (string name)
|
|
|
|
|
{
|
|
|
|
|
return Values [name];
|
|
|
|
|
try {
|
|
|
|
|
return Values [name];
|
|
|
|
|
} catch (ArgumentOutOfRangeException e) {
|
|
|
|
|
throw new ParsingException("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetIntValue (string name)
|
|
|
|
|
{
|
|
|
|
|
return int.Parse (Values [name]);
|
|
|
|
|
try {
|
|
|
|
|
return int.Parse (Values [name]);
|
|
|
|
|
} catch (ArgumentOutOfRangeException e) {
|
|
|
|
|
throw new ParsingException("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
|
|
|
|
|
} catch (FormatException e) {
|
|
|
|
|
throw new ParsingException("The parameter '" + name + "' in block '" + Name + "' is not an integer (it was '" + Values [name] + "')", e);
|
|
|
|
|
} catch (OverflowException e) {
|
|
|
|
|
throw new ParsingException("The parameter '" + name + "' in blo '" + Name + "' does not fit into an integer (it was '" + Values [name] + "')", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long GetLongValue (string name)
|
|
|
|
|
{
|
|
|
|
|
return long.Parse (Values [name]);
|
|
|
|
|
try {
|
|
|
|
|
return long.Parse (Values [name]);
|
|
|
|
|
} catch (ArgumentOutOfRangeException e) {
|
|
|
|
|
throw new ParsingException("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
|
|
|
|
|
} catch (FormatException e) {
|
|
|
|
|
throw new ParsingException("The parameter '" + name + "' in block '" + Name + "' is not a long (it was '" + Values [name] + "')", e);
|
|
|
|
|
} catch (OverflowException e) {
|
|
|
|
|
throw new ParsingException("The parameter '" + name + "' in blo '" + Name + "' does not fit into a long (it was '" + Values [name] + "')", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GetBoolValue (string name)
|
|
|
|
|
{
|
|
|
|
|
return bool.Parse (Values [name]);
|
|
|
|
|
try {
|
|
|
|
|
return bool.Parse (Values [name]);
|
|
|
|
|
} catch (ArgumentOutOfRangeException e) {
|
|
|
|
|
throw new ParsingException ("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
|
|
|
|
|
} catch (FormatException e) {
|
|
|
|
|
throw new ParsingException ("The parameter '" + name + "' in block '" + Name + "' is not a bool (it was '" + Values [name] + "')", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|