private string LoseOrKeepString(WLD result, int total) { if (total < 0 && result != WLD.WIN) { return("lose some"); } else if (total > 0 && result != WLD.LOSE) { return("wins some new"); } else { return("keep their"); } }
// constructor using @ seperated string instead of JSON to meet server 1000 byte PlayFab requirement public MatchBrief(string specialString) { var splitString = specialString.Split('@'); DateTime = Int32.Parse(splitString[0]); Opponent = splitString[1]; OpponentId = splitString[2]; PlayerId = splitString[3]; // parsing result like "RSW" (rock beats scissors, win) var resultCode = splitString[4]; MyWeapon = ParseWeapon(resultCode[0]); OpponentWeapon = ParseWeapon(resultCode[1]); Result = ParseWLD(resultCode[2]); }
public override IEnumerable <LogRecord> Convert(Ffb.Dto.Reports.FanFactorRoll report) { int totalHome = report.fanFactorRollHome.Sum(); int resultHome = totalHome + report.fanFactorModifierHome; WLD wldHome = CalcResult(FFB.Instance.Model.ScoreHome, FFB.Instance.Model.ScoreAway); yield return(new LogRecord($"<b>Fan Factor Roll Home Team {CreateRollString(report.fanFactorRollHome)}</b>")); yield return(new LogRecord($"Fan Factor {FFB.Instance.Model.TeamHome.FanFactor} Result: {totalHome} + {report.fanFactorModifierHome} = {totalHome + report.fanFactorModifierHome}", 1)); yield return(new LogRecord($"{FFB.Instance.Model.TeamHome.FormattedName} {LoseOrKeepString(wldHome, resultHome - FFB.Instance.Model.TeamHome.FanFactor)} fans", 1)); int totalAway = report.fanFactorRollAway.Sum(); int resultAway = totalAway + report.fanFactorModifierAway; WLD wldAway = CalcResult(FFB.Instance.Model.ScoreAway, FFB.Instance.Model.ScoreHome); yield return(new LogRecord($"<b>Fan Factor Roll Away Team {CreateRollString(report.fanFactorRollAway)}</b>")); yield return(new LogRecord($"Fan Factor {FFB.Instance.Model.TeamAway.FanFactor} Result: {totalAway} + {report.fanFactorModifierAway} = {totalAway + report.fanFactorModifierAway}", 1)); yield return(new LogRecord($"{FFB.Instance.Model.TeamAway.FormattedName} {LoseOrKeepString(wldAway, resultAway - FFB.Instance.Model.TeamAway.FanFactor)} fans", 1)); }
public static void ImportWLD(WLD world, string[] mshDirs, bool[] layersToImport, bool importTerrain) { if (mshDirs == null || mshDirs.Length == 0) { Debug.LogError("No msh directorys specified!"); return; } if (layersToImport == null || layersToImport.Length == 0) { Debug.LogError("No layers to import specified!"); return; } if (world.Layers.Count != layersToImport.Length) { Debug.LogError(string.Format("Number of Layers ({0}) does not match Muber of bool[] layersToImport ({1})!", world.Layers.Count, layersToImport.Length)); return; } for (int i = 0; i < world.Layers.Count; i++) { if (!layersToImport[i]) { Debug.Log("Skip Layer[" + i + "]: " + world.Layers[i].Name); continue; } Debug.Log("Layer " + world.Layers[i].Name + " has " + world.Layers[i].WorldObjects.Count + " objects in it"); for (int j = 0; j < world.Layers[i].WorldObjects.Count; j++) { WorldObject obj = world.Layers[i].WorldObjects[j]; bool found = false; foreach (string dir in mshDirs) { if (!Directory.Exists(dir)) { continue; } string mshPath = dir + "/" + obj.meshName + ".msh"; if (File.Exists(mshPath)) { GameObject msh = ImportMSH(mshPath); msh.transform.position = Vector2Unity(obj.position); msh.transform.rotation = Quaternion2Unity(obj.rotation); found = true; } } if (!found) { Debug.LogWarning("Could not find mesh: " + obj.meshName); } } } //Import Terrain if (importTerrain) { TER terrain = world.Terrain; TerrainData data = new TerrainData(); //gridSize data.heightmapResolution = terrain.GridSize + 1; //texture res data.baseMapResolution = 1024; data.SetDetailResolution(1024, 8); float[,] heights = new float[terrain.GridSize, terrain.GridSize]; //save min and max values from imported terrain float min = 0; float max = 0; for (int x = 0; x < heights.GetLength(0); x++) { for (int y = 0; y < heights.GetLength(1); y++) { float h = terrain.GetHeight(x, y); if (h < min) { min = h; } if (h > max) { max = h; } heights[x, y] = h; } } //e.g. min = -10 & max = 120, then //range = 120 - (-10) = 130 //or e.g. min = -10 & max = -3, then //range = -3 - (-10) = 7 float range = max - min; Debug.Log("Terrain Min: " + min); Debug.Log("Terrain Max: " + max); Debug.Log("Terrain Range: " + range); //Normalize given Terrain heights for (int x = 0; x < heights.GetLength(0); x++) { for (int y = 0; y < heights.GetLength(1); y++) { //since unity's terrain range goes from 0 to 1, we have to lift everything up. //so we're in a range of 0-666 (or whatever) heights[x, y] -= min; //normalize by full range to get heights between 0 and 1 heights[x, y] /= range; } } data.SetHeights(0, 0, heights); //calc true size float size = terrain.GridSize * terrain.GridScale; data.size = new Vector3(size, range, size); //Load textures onto terrain SplatPrototype[] splats = new SplatPrototype[terrain.Layers.Where(l => !string.IsNullOrEmpty(parseChars(l.DiffuseTexture))).ToArray().Length]; for (int i = 0; i < splats.Length; i++) { SplatPrototype splat = new SplatPrototype(); splat.texture = Resources.Load("Textures/" + parseChars(terrain.Layers[i].DiffuseTexture.Replace(".tga", ""))) as Texture2D; splat.tileSize = new Vector2(8, 8);//Not sure if correct. splat.metallic = 0f; splat.specular = new Color(1f, 1f, 1f); splats[i] = splat; } data.splatPrototypes = splats; GameObject terrainObj = Terrain.CreateTerrainGameObject(data); //since we normalized everything, we have to shift to the former offset, //so lift everything down by min again. //and of course we have to set the terrain into the center, so shift by half the size terrainObj.transform.Translate(-size / 2, min, -size / 2); //we're ignoring the Terrains extend window. just display the whole terrain } }
private void OnGUI() { EditorGUIUtility.labelWidth = 250; scrollPos = EditorGUILayout.BeginScrollView(scrollPos); EditorGUILayout.Space(); EditorGUILayout.Space(); if (GUILayout.Button("Open *.wld File")) { worldFile = new FileInfo(EditorUtility.OpenFilePanelWithFilters("Open Battlefront 2 World", "", new string[] { "SWBF2 World (*.wld)", "wld" })); if (worldFile.Exists) { try { world = WLD.LoadFromFile(worldFile.FullName); } catch (Exception ex) { EditorUtility.DisplayDialog("Error", "Error: " + ex.Message, "ok"); world = null; return; } layerSelected = new bool[world.Layers.Count]; } else { EditorUtility.DisplayDialog("Not Found", worldFile.FullName + " could not be found!", "ok"); } } EditorGUILayout.Space(); string path = ""; if (worldFile != null && worldFile.Exists) { path = worldFile.FullName; } EditorGUILayout.LabelField("Specify alternate MSH Directorys (Optional)", EditorStyles.boldLabel); for (int i = 0; i < altMshDirs.Length; i++) { altMshDirs[i] = EditorGUILayout.TextField("Alternate MSH Directory", altMshDirs[i]); } EditorGUILayout.Space(); if (world != null) { EditorGUILayout.LabelField("WLD File", path); EditorGUILayout.Space(); EditorGUILayout.Space(); //Display Terrain Info EditorGUILayout.LabelField("Terrain Information", EditorStyles.boldLabel); if (world.Terrain != null) { EditorGUILayout.LabelField("Terrain Version", world.Terrain.Version.ToString()); EditorGUILayout.LabelField("Terrain Size", world.Terrain.GridSize + "x" + world.Terrain.GridSize); EditorGUILayout.LabelField("Terrain Scale", world.Terrain.GridScale.ToString()); EditorGUILayout.LabelField("Terrain Height Multiplier", world.Terrain.HeightMultiplier.ToString()); importTerrain = EditorGUILayout.Toggle("Import Terrain", importTerrain); EditorGUILayout.Space(); } else { EditorGUILayout.LabelField("No Terrain available!"); } // Display Layer Selection EditorGUILayout.LabelField("Layers to import", EditorStyles.boldLabel); for (int i = 0; i < world.Layers.Count; i++) { layerSelected[i] = EditorGUILayout.Toggle( world.Layers[i].Name + " (" + world.Layers[i].WorldObjects.Count + ")", layerSelected[i] ); } EditorGUILayout.Space(); //Import Button if (GUILayout.Button("IMPORT")) { bool goOn = true; if (!AtLeastOneLayerSelected() && !importTerrain) { EditorUtility.DisplayDialog("Nothing to import", "Nothing selected to import!", "OK"); goOn = false; } if (goOn) { string[] mshDirs = new string[altMshDirs.Length + 4]; mshDirs[0] = worldFile.DirectoryName; mshDirs[1] = worldFile.DirectoryName + "/PC"; mshDirs[2] = Directory.GetParent(worldFile.DirectoryName).FullName + "/msh"; mshDirs[3] = Directory.GetParent(worldFile.DirectoryName).FullName + "/msh/PC"; for (int i = 4; i < mshDirs.Length; i++) { mshDirs[i] = altMshDirs[i - 4]; } SWBF2Import.ImportWLD(world, mshDirs, layerSelected, importTerrain); //foreach (string s in LibSWBF2.Log.GetAllLines(LibSWBF2.LogType.Info)) //Debug.Log(s); } } } EditorGUILayout.EndScrollView(); }
private void OnGUI() { EditorGUIUtility.labelWidth = 250; scrollPos = EditorGUILayout.BeginScrollView(scrollPos); EditorGUILayout.Space(); EditorGUILayout.Space(); if (GUILayout.Button("Open *.wld File")) { string worldPath = EditorUtility.OpenFilePanelWithFilters("Open Battlefront 2 World", "", new string[] { "SWBF2 World (*.wld)", "wld" }); if (worldPath == null || worldPath.Length == 0) { return; } worldFile = new FileInfo(worldPath); if (worldFile.Exists) { try { world = WLD.LoadFromFile(worldFile.FullName); } catch (Exception ex) { EditorUtility.DisplayDialog("Error", "Error: " + ex.Message, "ok"); world = null; return; } layerSelected = new bool[world.Layers.Count]; } else { EditorUtility.DisplayDialog("Not Found", worldFile.FullName + " could not be found!", "ok"); } } EditorGUILayout.Space(); string path = ""; if (worldFile != null && worldFile.Exists) { path = worldFile.FullName; } EditorGUILayout.LabelField("Specify alternate MSH Directorys (Optional)", EditorStyles.boldLabel); EditorGUILayout.LabelField("The importer will look there for meshes it can't find in the worlds own msh folder."); EditorGUILayout.LabelField("This e.g. applies for health droids, command posts, etc."); EditorGUILayout.LabelField("Adapt the default paths below if necessary, or leave them empty:"); for (int i = 0; i < altMshDirs.Length; i++) { string previous = altMshDirs[i]; altMshDirs[i] = EditorGUILayout.TextField("Alternate MSH Directory", altMshDirs[i]); if (altMshDirs[i] != previous) { PlayerPrefs.SetString("SWBF2Import_AltDirs_" + i, altMshDirs[i]); } } EditorGUILayout.Space(); if (world != null) { EditorGUILayout.LabelField("WLD File", path); EditorGUILayout.Space(); EditorGUILayout.Space(); //Display Terrain Info EditorGUILayout.LabelField("Terrain Information", EditorStyles.boldLabel); if (world.Terrain != null) { EditorGUILayout.LabelField("Terrain Version", world.Terrain.Version.ToString()); EditorGUILayout.LabelField("Terrain Size", world.Terrain.GridSize + "x" + world.Terrain.GridSize); EditorGUILayout.LabelField("Terrain Scale", world.Terrain.GridScale.ToString()); EditorGUILayout.LabelField("Terrain Height Multiplier", world.Terrain.HeightMultiplier.ToString()); importTerrain = EditorGUILayout.Toggle("Import Terrain", importTerrain); EditorGUILayout.Space(); } else { EditorGUILayout.LabelField("No Terrain available!"); } // Display Layer Selection EditorGUILayout.LabelField("Layers to import", EditorStyles.boldLabel); for (int i = 0; i < world.Layers.Count; i++) { layerSelected[i] = EditorGUILayout.Toggle( world.Layers[i].Name + " (" + world.Layers[i].WorldObjects.Count + ")", layerSelected[i] ); } EditorGUILayout.Space(); //Import Button if (GUILayout.Button("IMPORT")) { if (SWBF2Import.DEFAULT_MATERIAL == null) { EditorUtility.DisplayDialog("ERROR", "Please specify a default Material first in the Mesh Import Options!", "ok"); return; } bool goOn = true; if (!AtLeastOneLayerSelected() && !importTerrain) { EditorUtility.DisplayDialog("Nothing to import", "Nothing selected to import! Select Terrain or at least one Layer to import!", "OK"); goOn = false; } if (goOn) { string[] mshDirs = new string[4 + altMshDirs.Length]; mshDirs[0] = worldFile.DirectoryName; mshDirs[1] = worldFile.DirectoryName + "/PC"; mshDirs[2] = Directory.GetParent(worldFile.DirectoryName).FullName + "/msh"; mshDirs[3] = Directory.GetParent(worldFile.DirectoryName).FullName + "/msh/PC"; for (int i = 0; i < altMshDirs.Length; i++) { mshDirs[i + 4] = altMshDirs[i]; } SWBF2Import.ImportWLD(world, mshDirs, layerSelected, importTerrain); //foreach (string s in LibSWBF2.Log.GetAllLines(LibSWBF2.LogType.Info)) //Debug.Log(s); } } } EditorGUILayout.EndScrollView(); }
public static void ImportWLD(WLD world, string[] mshDirs, bool[] layersToImport, bool importTerrain) { if (mshDirs == null || mshDirs.Length == 0) { Debug.LogError("No msh directorys specified!"); return; } if (layersToImport == null || layersToImport.Length == 0) { Debug.LogError("No layers to import specified!"); return; } if (world.Layers.Count != layersToImport.Length) { Debug.LogError(string.Format("Number of Layers ({0}) does not match Muber of bool[] layersToImport ({1})!", world.Layers.Count, layersToImport.Length)); return; } PrefabMap.Clear(); EditorUtility.DisplayProgressBar("Import world", "Import world", 0.0f); for (int i = 0; i < world.Layers.Count; i++) { if (!layersToImport[i]) { //Debug.Log("Skip Layer[" + i + "]: " + world.Layers[i].Name); continue; } //Debug.Log("Layer " + world.Layers[i].Name + " has " + world.Layers[i].WorldObjects.Count + " objects in it"); for (int j = 0; j < world.Layers[i].WorldObjects.Count; j++) { WorldObject obj = world.Layers[i].WorldObjects[j]; bool found = false; foreach (string dir in mshDirs) { if (!Directory.Exists(dir)) { continue; } string mshPath = dir + "/" + obj.meshName + ".msh"; if (File.Exists(mshPath)) { EditorUtility.DisplayProgressBar("Import Mesh", "'" + obj.meshName + ".msh' (" + (j + 1) + "/" + world.Layers[i].WorldObjects.Count + ") in Layer '" + world.Layers[i].Name + "' (" + (i + 1) + "/" + world.Layers.Count + ")", j / (float)world.Layers[i].WorldObjects.Count); GameObject msh = ImportMSH(mshPath, mshDirs, true); if (msh != null) { msh.transform.position = Vector2Unity(obj.position); msh.transform.rotation = Quaternion2Unity(obj.rotation); msh.name = obj.name; found = true; break; } else { Debug.LogWarning("COULD NOT IMPORT: " + mshPath); } } } if (!found) { Debug.LogWarning("Could not find mesh: " + obj.meshName); } } } //Import Terrain if (importTerrain) { EditorUtility.DisplayProgressBar("Import Terrain", "Import Terrain...", 0.9f); TER terrain = world.Terrain; TerrainData data = new TerrainData(); //gridSize data.heightmapResolution = terrain.GridSize + 1; //texture res data.baseMapResolution = 1024; data.SetDetailResolution(1024, 8); float[,] heights = new float[terrain.GridSize, terrain.GridSize]; //save min and max values from imported terrain float min = 0; float max = 0; int xLen = heights.GetLength(0); int yLen = heights.GetLength(1); for (int x = 0; x < xLen; x++) { for (int y = 0; y < yLen; y++) { float h = terrain.GetHeight(x, y); if (h < min) { min = h; } if (h > max) { max = h; } heights[x, y] = h; } } //e.g. min = -10 & max = 120, then //range = 120 - (-10) = 130 //or e.g. min = -10 & max = -3, then //range = -3 - (-10) = 7 float range = max - min; //Debug.Log("Terrain Min: " + min); //Debug.Log("Terrain Max: " + max); //Debug.Log("Terrain Range: " + range); //Normalize given Terrain heights for (int x = 0; x < xLen; x++) { for (int y = 0; y < yLen; y++) { //since unity's terrain range goes from 0 to 1, we have to lift everything up. //so we're in a range of 0-666 (or whatever) heights[x, y] -= min; //normalize by full range to get heights between 0 and 1 heights[x, y] /= range; } } data.SetHeights(0, 0, heights); //calc true size float size = terrain.GridSize * terrain.GridScale; data.size = new Vector3(size, range, size); GameObject terrainObj = Terrain.CreateTerrainGameObject(data); //since we normalized everything, we have to shift to the former offset, //so lift everything down by min again. //and of course we have to set the terrain into the center, so shift by half the size terrainObj.transform.Translate(-size / 2, min, -size / 2); //we're ignoring the Terrains extend window. just display the whole terrain } EditorUtility.ClearProgressBar(); }