private void deserializeLevel() { //Testing Level Deserialization LevelInfo levelInfo = Serialization.getLevel(level.levelFileName); //TODO: game objective will be serialized in the level editor data. assign it here, and do any other necessary reference assignment objective = new EliminationObjective(battlefield, level, level.characters[playerCharacter], 20); // Uncomment these for the escort objective // (objective as EscortObjective).vips.Add(battlefield.units[0,0]); // (objective as EscortObjective).vips.Add(battlefield.units[1,0]); // (objective as EscortObjective).vips.Add(battlefield.units[0,1]); // Uncomment these for the intercept objective // (objective as InterceptObjective).vips.Add(battlefield.units[3,7]); // objective = new CaptureObjective(battlefield, level, characters[playerCharacter], 20, new List<Coord>(new Coord[] {new Coord(1,1)}), 0); // objective = new DefendObjective(battlefield, level, characters[playerCharacter], 20, new List<Coord>(new Coord[] {new Coord(3,4), new Coord(1,1)}), 0); //For these objectives to work, you must also comment out the lines in the initial battle stage below // objective = new EscortObjective(battlefield, level, characters[playerCharacter], 20); // objective = new InterceptObjective(battlefield, level, characters[playerCharacter], 20); try { Stack <UnitInfo> stack = levelInfo.units; while (stack.Count != 0) { UnitInfo info = stack.Pop(); if (info.getIsPlayer()) { addUnit(info.getUnitType(), level.characters[0], info.getCoord().x, info.getCoord().y, Faction.Xingata); } else { addUnit(info.getUnitType(), level.characters[1], info.getCoord().x, info.getCoord().y, Faction.Tsubin); } } } catch (FileNotFoundException ex) { Debug.Log("Incorrect level name" + ex.ToString()); } }
private void deserializeLevel() { //get all level info for units, objectives and map name LevelInfo levelInfo = Serialization.getLevel(level.levelFileName); //add all units //default enemy faction Faction enemyFaction = Faction.Velgari; try { Stack <UnitInfo> stack = levelInfo.units; while (stack.Count != 0) { UnitInfo info = stack.Pop(); if (info.getFaction() == Faction.Xingata) { addUnit(info.getUnitType(), level.characters[0], info.getCoord().x, info.getCoord().y, Faction.Xingata); } else { addUnit(info.getUnitType(), level.characters[1], info.getCoord().x, info.getCoord().y, info.getFaction()); enemyFaction = info.getFaction(); } } } catch (FileNotFoundException ex) { Debug.Log("Incorrect level name" + ex.ToString()); } //get all goal info List <Coord> goalPositions = levelInfo.goalPositions; switch (levelInfo.objective) { case ObjectiveType.Elimination: objective = new EliminationObjective(battlefield, level, level.characters[playerCharacter], 30); break; case ObjectiveType.Escort: objective = new EscortObjective(battlefield, level, level.characters[playerCharacter], 15); //add vips foreach (Coord pos in goalPositions) { addUnit(UnitType.Knight, level.characters[0], pos.x, pos.y, Faction.Xingata); Unit unit = battlefield.units[pos.x, pos.y]; (objective as EscortObjective).vips.Add(unit); Instantiate(vipCrownPrefab, unit.transform.position + new Vector3(0, 3, 0), vipCrownPrefab.transform.rotation, unit.transform); } break; case ObjectiveType.Intercept: objective = new InterceptObjective(battlefield, level, level.characters[playerCharacter], 30); foreach (Coord pos in goalPositions) { addUnit(UnitType.Knight, level.characters[1], pos.x, pos.y, enemyFaction); Unit unit = battlefield.units[pos.x, pos.y]; (objective as InterceptObjective).vips.Add(unit); foreach (Character c in level.characters) { if (c.agent is DefendAgent) { (c.agent as DefendAgent).VIPs.Add(unit); } } Instantiate(vipCrownPrefab, unit.transform.position + new Vector3(0, 3, 0), vipCrownPrefab.transform.rotation, unit.transform); } break; case ObjectiveType.Capture: objective = new CaptureObjective(battlefield, level, level.characters[playerCharacter], 30, goalPositions, 2); foreach (Coord pos in goalPositions) { foreach (Character c in level.characters) { if (c.agent is DefendAgent) { (c.agent as DefendAgent).capturePoint = pos; } } Instantiate(vipCrownPrefab, battlefield.map[pos.x, pos.y].Peek().transform.position + new Vector3(0, 3, 0), vipCrownPrefab.transform.rotation, battlefield.map[pos.x, pos.y].Peek().transform); } break; case ObjectiveType.Defend: objective = new DefendObjective(battlefield, level, level.characters[playerCharacter], 20, goalPositions, 2); foreach (Coord pos in goalPositions) { Instantiate(vipCrownPrefab, battlefield.map[pos.x, pos.y].Peek().transform.position + new Vector3(0, 3, 0), vipCrownPrefab.transform.rotation, battlefield.map[pos.x, pos.y].Peek().transform); } break; case ObjectiveType.Survival: objective = new SurvivalObjective(battlefield, level, level.characters[playerCharacter], 15); break; default: objective = new EliminationObjective(battlefield, level, level.characters[playerCharacter], 20); break; } }