// Use this for initialization void Start () { tabPawnCode = this.GetComponentsInChildren<MovingPerso>(); mapScript = GameObject.Find("MapMaster").GetComponent<MapMaster>(); // mapScript = GameObject.Find("MapMaster").GetComponent<MapMaster>(); Debug.Log("ICI"); }
private void ClickHex() // checks if a valid hex was clicked { ray = Camera.main.ScreenPointToRay(Input.mousePosition); HexCell h; if (Physics.Raycast(ray, out rayHit)) { h = rayHit.transform.gameObject.GetComponent <HexCell>(); if (h != null) // it might be tempting to but this and the nested if statment together with an &&, but that'll throw an error if h is null when it check h.Unit { if (h.Unit == null && h.Passable) { List <HexCell> CellsToChange = MapMaster.CellsWithinArea(h, multCellRadius); foreach (HexCell cell in CellsToChange) { if (cell.R < 2 || cell.R > 3 && cell.R < MapMaster.MapRadius - 4 || cell.R > MapMaster.MapRadius - 3) { if (cell.Passable) { ChangeHex(cell); } } } } } } }
public static void SetCannon(Cannon c) { int fI = 0; int fC = 0; int speed; foreach (HexCell h in MapMaster.CellsWithinArea(c.CurrentHex, 1)) { if (h.passable) { continue; } if (h.Unit != null) { if (h.Unit.Player == c.player) { string name = h.Unit.UName; if (name == "Infantry") { fI++; } else if (name == "Cavalry") { fC++; } } } } c.Manned = DecideManned(fI, fC, out speed); c.shots = Cannon.Clip; c.SetMove(speed); c.Moved = speed == 0 ? true : false; }
static IEnumerator MoveFollowers() { moving = true; target = otherlist[0]; for (int n = 1; n < otherlist.Count; ++n) { MoveMaster.SetTarget(otherlist[n]); moveTo = otherlist[n].CurrentHex; moves = otherlist[n].MoveSpeed; openSpaces = MapMaster.CellsWithinArea(moveTo, moves); //finds nearby hexcells distance = Vector3.Distance(target.CurrentHex.transform.position, otherlist[n].CurrentHex.transform.position); //distance between current hex and target hex. for (int i = 1; i < openSpaces.Count; ++i) //loops through the rest of the cells { if (openSpaces[i].Unit == null && distance > Vector3.Distance(target.CurrentHex.transform.position, openSpaces[i].transform.position)) { moveTo = openSpaces[i]; distance = Vector3.Distance(target.CurrentHex.transform.position, openSpaces[i].transform.position); } } yield return(new WaitForSeconds(.2f)); MoveMaster.EvaluateTile(moveTo); //Actually moves unit } Debug.Log("1"); moving = false; }
/// <summary> /// MapMasterを指定して敵Viewの生成等、開始処理を行う /// </summary> public void Startup(MapMaster mapMaster, int mapLevel) { _mapMaster = mapMaster; _mapLevel = mapLevel; for (int i = 0, size = _mapMaster.InitCreateNum.GetRandomValue(); i < size; ++i) { // プールから敵を取得する var enemyControl = GetEnemyByPool(); var mapEnemyData = _mapMaster.GetRandomEnemyDataFromPopRate(); var enemyMaster = _masterHolder.EnemyRepository.Find(mapEnemyData.EnemyType); EnemyFactory.Create(this, enemyControl, enemyMaster); Models.Add(enemyControl.Model); _keyModelValueControl.Add(enemyControl.Model, enemyControl); // 削除時 var subject = new Subject <EnemyControl>(); subject.Subscribe(enemy_ => { RemoveChara(enemy_); }); enemyControl.OnDestroyed = subject; ++_enemyCount; } }
// if a given file name exists, load it. If not, make a blank map and save it under the given file name. All maps go to their sub-folder in the resources folder. void ReadyHexmap() { mM = new MapMaster(); string path = Application.dataPath + "/Resources/Maps/" + CurrentMap + ".txt"; if (!File.Exists(path)) { //MapMaster.SetMap(MapMaster.MapRadius); MapMaster.SetMap(mapRadius); Debug.Log("Making"); CreateBlankMap(); File.Create(path).Close(); SaveMap(path); } else { mL = new MapLoader(); mL.LoadMapFromTextFile(path); } foreach (HexCell h in MapMaster.Map) { h.gameObject.isStatic = false; } }
void Awake() { fogCtrl = GetComponent <DarknessFogControl>(); netManCtrl = GetComponent <NetworkManagerControl>(); lvlCrtrCtrl = GetComponent <LevelCreatorControl>(); mapMstr = GameObject.Find("LevelLoadingControl").GetComponent <MapMaster>(); }
private static void BuildCluster(ref List <Unit> cluster, ref List <Unit> points) { while (points.Count != 0) { instance.combatPoints.Remove(points[0].CurrentHex); cluster.Add(points[0]); Unit center = points[0]; foreach (HexCell h in MapMaster.CellsWithinArea(center.CurrentHex, 1)) { if (h.Passable) { continue; } if (cluster.Contains(h.Unit)) { continue; } if (h.Unit != null) { if (h.Unit.UName != "Cannon") { if (h.Unit.Player == PlayerMaster.PriorTurn) { cluster.Add(h.Unit); } } } } points.RemoveAt(0); } }
public static void BuildCombatPoints(HexCell checkCell) { if (checkCell.Unit != null && checkCell.Unit.UName == "Cannon") { return; } foreach (HexCell h in MapMaster.CellsWithinArea(checkCell, 1)) { if (h.Passable) { continue; } else if (h.Unit != null) { if (h.Unit.Player == PlayerMaster.PriorTurn && h.Unit.UName != "Cannon") { Debug.Log("PointAdded" + h.Unit.Player); instance.combatPoints.Add(checkCell); break; } } } // foreach(Unit u in PlayerMaster.CurrentPlayer) }
private void AwakeMapMaster() { if (this._masterAwoken == false) { this._mapMaster = GameObject.FindGameObjectWithTag("MapMaster").GetComponent <MapMaster>(); this._masterAwoken = true; } }
void ITerrain.ResetTiles() { List <HexCell> cells = MapMaster.CellsWithinArea(currentHex, moveSpeed); foreach (HexCell h in cells) { h.Passable = true; } }
public static void ClearMoveVariables() { if (target != null) { HighlightMaster.ToggleTileHighlights(false, MapMaster.CellsWithinArea(target.CurrentHex, target.MoveSpeed)); } target = null; }
// called if the desired map to read does not exsist, building a plain one instead. private void CreateBlankMap() { for (int x = 0; x < MapMaster.MapRadius; x++) { for (int z = 0; z < MapMaster.MapRadius; z++) { MapMaster.MakeTile(x, z); } } }
public static void EvaluateTile(HexCell h) { if (target != null && h.passable) { List <HexCell> path = HexStar.GetPath(target.CurrentHex, h, target.MoveSpeed); HighlightMaster.ToggleTileHighlights(false, MapMaster.CellsWithinArea(target.CurrentHex, target.MoveSpeed)); if (path.Count > 0) { target.StartCoroutine(FollowPath(path, target)); SoundMaster.SelectUnit(); } target = null; } }
//initialize void Start() { instance = this; // canSkip = false; uiM = new UIMaster(); sM = new ScoreMaster(); mM = new MapMaster(); pM = new PlayerMaster(); dM = new DeployMaster(); mvM = new MoveMaster(); aM = new AttackMaster(); acceptInput = true; turnNum = 0; CannonMaster.ResetCurrent(); gP = GamePhase.Deploy; ScoreMaster.ResetScore(); mL = new MapLoader(); mL.LoadMapFromTextAsset(((TextAsset)Resources.Load("Maps/" + mapName))); PlayerMaster.SetBackLines(MapMaster.Map); TopDownCamera.ActivateMainCamera(MapMaster.Height, MapMaster.Width, MapMaster.MapRadius); UIMaster.SetGeneralUI(); UIMaster.SetDeployUI(); UIMaster.SetCannonUI(); UIMaster.DisplayScore(); UIMaster.SetPanelAlpha(false, (int)UIPannels.Cannon); UIMaster.SetPanelAlpha(false, (int)UIPannels.Phase); UIMaster.SetPanelAlpha(false, (int)UIPannels.View); UIMaster.SetPanelAlpha(false, (int)UIPannels.Fight); UIMaster.SetActionPanel(true); if (!tutorial) { UIMaster.DisplayState(gP, PlayerMaster.CurrentTurn); } // norton = VS_AI ? new AIBrain() : null; // must be called after UIMaster.SetGeneralUI to percive turns properly }
private static void FeelForPoints(ref List <Unit> points) { List <Unit> open = new List <Unit>() { points[0] }; List <Unit> closed = new List <Unit>() { points[0] }; while (open.Count != 0) { Unit center = open[0]; HexCell origin = points[0].CurrentHex; foreach (HexCell h in MapMaster.CellsWithinArea(center.CurrentHex, 1)) { if (h.Passable) { continue; } if (closed.Contains(h.Unit)) { continue; } if (h.Unit != null) { if (h.Unit.Player != -1) { open.Add(h.Unit); closed.Add(h.Unit); if (instance.combatPoints.Contains(h)) { points.Add(h.Unit); } } } } open.RemoveAt(0); } }
//Finds and returns a list of valid neighbors around a given point private static List <OddQPoint> Neighbors(OddQPoint center) { List <OddQPoint> items = new List <OddQPoint>(); int parity = center.q & 1; OddQPoint n; foreach (OddQPoint dir in directions[parity]) { n = new OddQPoint(center.q + dir.q, center.r + dir.r); if (MapMaster.IsCellOnMap(n.q, n.r)) { items.Add(n); } } return(items); }
static void MoveCannon() { Debug.Log("Move Cannons"); HexCell moveTo; List <Unit> inRangeTargets = new List <Unit>(); for (int i = 0; i < otherlist.Count; ++i) //searches squad list for the cannon. { if (otherlist[i].gameObject.tag == "cannon") { Debug.Log("Found Cannon"); if (GameBrain.turnNum < 4) { otherlist[i].Moved = false; otherlist[i].MoveSpeed = 2; } HexCell cannonCell = otherlist[i].CurrentHex; List <HexCell> inRangeCells = MapMaster.CellsWithinArea(cannonCell, 11); //Gets all HexCells within "range" of the current cannon for (int j = 0; j < inRangeCells.Count; ++j) { //If the cell has an enemy unit on it that is not a cannon it is added to the list if (inRangeCells[j].Unit != null && inRangeCells[j].Unit.Player != PlayerMaster.CurrentTurn && inRangeCells[j].Unit.gameObject.tag != "Cannon") { inRangeTargets.Add(inRangeCells[j].Unit); } } //if(inRangeTargets.Count < 0) // { MoveMaster.SetTarget(otherlist[i]); target = otherlist[i]; moveTo = MapMaster.Map[target.CurrentHex.R - 2, target.CurrentHex.Q]; MoveMaster.EvaluateTile(moveTo); //Actually moves unit // } } } }
public HttpResponseMessage AddMapMaster(MapMaster objMapMaster, string Token, string AppKey) { string strJson = string.Empty; var response = this.Request.CreateResponse(HttpStatusCode.OK); try { Accountmeg objaccountmegment = new Accountmeg(); string result = objaccountmegment.Getresult(AppKey, Token); if (result == "true") { using (TTPAPIDataContext DB = new TTPAPIDataContext()) { MapMaster objMapMasters = new MapMaster(); objMapMasters.MapName = objMapMaster.MapName; objMapMasters.MapDesc = objMapMaster.MapDesc; objMapMasters.CreatedDateTime = DateTime.Now; objMapMasters.CreatedBy = String.Format("{0}{1}", Token.Substring(0, 36), DateTime.Now.ToShortDateString()); DB.MapMasters.InsertOnSubmit(objMapMasters); DB.SubmitChanges(); } strJson = "{\"Result\":\"204\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } else { strJson = "{\"Result\":\"Invalide AppKey\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } } catch (Exception ex) { strJson = "{\"Result\":\"" + ex.Message + "\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } }
static void MoveLeadSoldier() { MoveMaster.SetTarget(otherlist[0]); //Which unit it's about to move //moveTo is hexcell unit is trying to move to. Starts as the cell the Unit is already on moveTo = otherlist[0].CurrentHex; moves = otherlist[0].MoveSpeed; openSpaces = MapMaster.CellsWithinArea(moveTo, moves); //finds nearby hexcells distance = Vector3.Distance(target.CurrentHex.transform.position, otherlist[0].CurrentHex.transform.position); //distance between current hex and target hex. for (int i = 1; i < openSpaces.Count; ++i) //loops through the rest of the cells { if (openSpaces[i].Unit == null && distance > Vector3.Distance(target.CurrentHex.transform.position, openSpaces[i].transform.position)) { moveTo = openSpaces[i]; distance = Vector3.Distance(target.CurrentHex.transform.position, openSpaces[i].transform.position); } } openSpaces.Clear(); MoveMaster.EvaluateTile(moveTo); //Actually moves unit }
private static void MoveToTile(HexCell h, ref Unit u) { HighlightMaster.ToggleTileHighlights(false, MapMaster.CellsWithinArea(u.CurrentHex, u.MoveSpeed)); MapMaster.Map[u.CurrentHex.R, u.CurrentHex.Q].Passable = true; MapMaster.Map[u.CurrentHex.R, u.CurrentHex.Q].Unit = null; u.gameObject.transform.position = h.SpawnVector; MapMaster.Map[h.R, h.Q].Unit = u; MapMaster.Map[h.R, h.Q].Passable = false; u.Moved = true; u.CurrentHex = MapMaster.Map[h.R, h.Q]; HighlightMaster.HighlightUnitToggle(false, u); AttackMaster.BuildCombatPoints(u.CurrentHex); u = null; UnitsToMove--; }
private static void ExpandCluster(ref List <Unit> area, ref List <Unit> cluster) { List <Unit> open = new List <Unit>(cluster); area = new List <Unit>(cluster); while (open.Count != 0) { Unit center = open[0]; foreach (HexCell h in MapMaster.CellsWithinArea(center.CurrentHex, 1)) { if (h.Passable) { continue; } if (area.Contains(h.Unit)) { continue; } if (h.Unit != null) { if (h.Unit.UName != "Cannon") { if (h.Unit.Player != -1) { if (WithinClusterRange(ref cluster, h, 1)) { open.Add(h.Unit); area.Add(h.Unit); } } } } } open.RemoveAt(0); } }
public static void SetTarget(Unit u) { if (!u.Moved && u.Player == PlayerMaster.CurrentTurn) { if (target != null) { HighlightMaster.ToggleTileHighlights(false, MapMaster.CellsWithinArea(target.CurrentHex, target.MoveSpeed)); if (target.UName != "Cannon" && !target.Equals(u)) { target.GetComponentInChildren <Animator>().Play("GoToIdle"); } } target = u; instance.timePressed = 0; SoundMaster.SelectUnit(); if (u.UName != "Cannon") { u.GetComponentInChildren <Animator>().Play("AtenHut"); } foreach (HexCell h in MapMaster.CellsWithinArea(u.CurrentHex, u.MoveSpeed)) { if (HexStar.GetPath(u.CurrentHex, h, u.MoveSpeed).Count > 0) { HighlightMaster.HighlightTile(h); } } if (instance.uQue.Count != 0) { instance.uQue.Clear(); } //playthatfunkysound(h.Unit.UName); } }
private void ClickHex() // checks if a valid hex was clicked { ray = Camera.main.ScreenPointToRay(Input.mousePosition); HexCell h; if (Physics.Raycast(ray, out rayHit)) { h = rayHit.transform.gameObject.GetComponent <HexCell>(); if (h != null) // it might be tempting to put this and the nested if statment together with an &&, but that'll throw an error if h is null when it check h.Unit { if (h.Unit == null && h.Passable) { //code to place current terrain object. Unit u = MapMaster.MakeTerrain(terrainArray[(int)currTerrain]); u.CurrentHex = h; h.Unit = u; ITerrain uIT = u.GetComponent <ITerrain>(); uIT.SetTiles(); uIT.SetPosition(); uIT.SetCollider(); } } } }
public MapMaster() { map = new HexCell[0, 0]; g_map = GameObject.Find("MapControl"); instance = this; }
public void Parse(Dictionary <ushort, List <ulong> > track, Dictionary <ulong, Record> map, CASCHandler handler, bool quiet, OverToolFlags flags) { List <ulong> masters = track[0x9F]; foreach (ulong masterKey in masters) { Console.Out.WriteLine(""); if (!map.ContainsKey(masterKey)) { continue; } STUD masterStud = new STUD(Util.OpenFile(map[masterKey], handler), true, STUDManager.Instance, false, true); if (masterStud.Instances == null) { continue; } MapMaster master = (MapMaster)masterStud.Instances[0]; if (master == null) { continue; } string name = Util.GetString(master.Header.name.key, map, handler); if (string.IsNullOrWhiteSpace(name)) { name = $"Unknown{GUID.Index(masterKey):X}"; } Console.Out.WriteLine(name); Console.Out.WriteLine("\tID: {0:X8}", GUID.Index(masterKey)); string subline = Util.GetString(master.Header.subline.key, map, handler); if (subline == null) { subline = ""; } if (master.Header.subline.key != master.Header.subline2.key && master.Header.subline2.key != 0) { subline += " " + Util.GetString(master.Header.subline2.key, map, handler); } subline = subline.Trim(); if (subline.Length > 0) { Console.Out.WriteLine("\tSubline: {0}", subline); } TryString("State", Util.GetString(master.Header.stateA.key, map, handler)); TryString("State", Util.GetString(master.Header.stateB.key, map, handler)); string description = Util.GetString(master.Header.description1.key, map, handler); if (description == null) { description = ""; } if (master.Header.description1.key != master.Header.description2.key && master.Header.description2.key != 0) { description += " " + Util.GetString(master.Header.description2.key, map, handler); } description = description.Trim(); if (description.Length > 0) { Console.Out.WriteLine("\tDescription: {0}", description); } } }
//Finds all nearby enemies and figures out where to aim. Called from Camera Control during Cannon phase and after a single cannon shot public void FindTargets(Cannon can) { if (can == null) { return; } HexCell cannonCell = can.CurrentHex; List <HexCell> inRangeCells = MapMaster.CellsWithinArea(cannonCell, range); //Gets all HexCells within "range" of the current cannon // int l = 0; for (int i = 0; i < inRangeCells.Count; ++i) { //If the cell has an enemy unit on it that is not a cannon it is added to the list if (inRangeCells[i].Unit != null && inRangeCells[i].Unit.Player != 1 && inRangeCells[i].Unit.gameObject.tag != "cannon") { inRangeTargets.Add(inRangeCells[i].Unit); } } //For loop for inrange while (inRangeTargets.Count != 0) //runs through all aquired nearby targets { Debug.Log("Looping"); currentCluster.Add(inRangeTargets[0]); //adds first one to current cluster inRangeTargets.RemoveAt(0); //removes that same one from inRangeTargets to prevent overlap inRangeCells = MapMaster.CellsWithinArea(currentCluster[0].CurrentHex, 1); //gets all cells that are 1 cell within the first target for (int i = 0; i < inRangeCells.Count; ++i) //loops through previously aquired list of cells { if (inRangeCells[i].Unit != null && inRangeCells[i].Unit.gameObject.tag != "cannon" && !currentCluster.Contains(inRangeCells[i].Unit)) //if that cell has a unit that is not in the cluster { currentCluster.Add(inRangeCells[i].Unit); //adds it too the current cluster if (inRangeTargets.Contains(inRangeCells[i].Unit)) //if that unit was in the inRangeTarget list { inRangeTargets.Remove(inRangeCells[i].Unit); //remove that unit } } //This loop is similiar to the one above. After it gets one enemy, it checks the cells around it for more //Then, after adding a new enemy, it checks the cells around THAT one for even more enemies, countinously adding them to the cluster for (int j = 0; j < currentCluster.Count; ++j) { List <HexCell> inRangeCellsTwo = MapMaster.CellsWithinArea(currentCluster[j].CurrentHex, 1); //Cells surrounding the unit for (int k = 0; k < inRangeCellsTwo.Count; ++k) { if (inRangeCellsTwo[k].Unit != null && !currentCluster.Contains(inRangeCellsTwo[k].Unit) && inRangeCellsTwo[k].Unit.gameObject.tag != "cannon") //if that cell has a unit that is not in the cluster { currentCluster.Add(inRangeCellsTwo[k].Unit); //adds it too the current cluster if (inRangeTargets.Contains(inRangeCellsTwo[k].Unit)) //if that unit was in the inRangeTarget list { inRangeTargets.Remove(inRangeCellsTwo[k].Unit); //remove that unit } } } } } //When the cluster is finished, we compare it to the biggest cluster we've found so far if (biggestCluster.Count < currentCluster.Count) //If the current cluster has more enemies than the biggest cluster, we make that cluster the new biggest { biggestCluster.Clear(); for (int i = 0; i < currentCluster.Count; ++i) { biggestCluster.Add(currentCluster[i]); } } currentCluster.Clear(); } if (biggestCluster.Count == 0) { Debug.Log("reached 1"); inRangeTargets.Clear(); currentCluster.Clear(); biggestCluster.Clear(); while (currentCannon < PlayerMaster.CurrentPlayer.Can.Count && PlayerMaster.CurrentPlayer.Can[currentCannon].shots == 0) //Moves through cannons until we are out of available cannons or we find one with enough shots { ++currentCannon; } Debug.Log("reached 2"); if (currentCannon < PlayerMaster.CurrentPlayer.Can.Count && (PlayerMaster.OtherPlayer.Inf.Count > 0 || PlayerMaster.OtherPlayer.Cav.Count > 0)) //If we found a cannon that can be shot { FindTargets(PlayerMaster.CurrentPlayer.Can[currentCannon]); //Find the targets within it's range and continue from there } else { Debug.Log("Reached 3"); //StartCoroutine(CannonMaster.LeaveCannon()); //If we are out of cannons then zoom back out // GameBrain.ChangeTurn(); } } else { StartCoroutine(HandleCannons(can)); } //AimAndShoot(can); }
private void LoadMap(string [] lines) { string rawData; // the entire line of text read from the file string[] dData; // the data after being split up based on the given delim above. string data = lines[0]; int rad = System.Int32.Parse(data); MapMaster.SetMap(rad); for (int i = 1; i < lines.Length - 1; i++) { rawData = lines[i]; dData = rawData.Split(DELIM); if (dData.Length >= 5) { int q = int.Parse(dData[(int)CellData.q]); int r = int.Parse(dData[(int)CellData.r]); Unit u = ((dData[(int)CellData.unit] == "null") ? null : MapMaster.MakeTerrain(dData[(int)CellData.unit])); // if the hex has any terrain, the Get Terrain method returns the related type after spawning it. if (u != null) { u.UDirection = int.Parse(dData[(int)CellData.unitRotation]); // rotation of the unit } HexSize s = (HexSize)int.Parse((dData[(int)CellData.size])); TileType type; if (dData.Length <= (int)CellData.type) { type = 0; } else { type = (TileType)int.Parse((dData[(int)CellData.type])); } MapMaster.MakeTile(q, r); if (u != null) // depending on the natue of how we handle loading terrain, we might be checking for the string "null" here instead and not loading the object itself until we get to TerranPass { MapMaster.Map[r, q].Unit = u; MapMaster.Map[r, q].Unit.CurrentHex = MapMaster.Map[r, q]; toBuild.Add(MapMaster.Map[r, q]); } if ((int)s != 0) { MapMaster.Map[r, q].Size = s; toSize.Add(MapMaster.Map[r, q]); } if ((int)type != 0) { MapMaster.Map[r, q].Type = type; toType.Add(MapMaster.Map[r, q]); } } } SizePass(); // any cells needing to have their scale changed are handled here. TerrainPass(); // any cells that are to have terrain is handled here. TypePass(); //any cells that need to have their cost and matieral changed are handled here. ViewMaster.PlaceCubes(); }
public static void DecideMove() { if (target != null) { if (Input.GetKey(KeyCode.Mouse0)) { instance.BuildMarker(); } else if (Input.GetKeyUp(KeyCode.Mouse0) && instance.radiusMarker != null) { instance.timePressed = 0; foreach (HexCell h in MapMaster.CellsWithinArea(target.CurrentHex, instance.uSize)) { Unit u = h.Unit; if (u != null) { if (!u.Moved && u.Player == PlayerMaster.CurrentTurn) { instance.uQue.Add(u); } } } GameObject.Destroy(instance.radiusMarker); instance.radiusMarker = null; instance.uSize = 0; // target = null; } } if (Input.GetKeyDown(KeyCode.Mouse0) /*&& Events.GetComponent<Pause>().paused == false*/) { Ray ray; RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { Unit u = hit.transform.gameObject.GetComponent <Unit>(); HexCell h = hit.transform.gameObject.GetComponent <HexCell>(); //Debug.Log(u == null ? "" : u.UName); if (u != null) { SetTarget(u); } else if (h != null) { if (instance.uQue.Count == 0) { EvaluateTile(h); } else { if (target != null) { HighlightMaster.ToggleTileHighlights(false, MapMaster.CellsWithinArea(target.CurrentHex, target.MoveSpeed)); Vector3 directionVector = HexCell.TravelDirection(target.CurrentHex.Cube, h.Cube); Vector2 endpoint; HexCell goal; List <HexCell> newPath; List <KeyValuePair <Unit, List <HexCell> > > paths = new List <KeyValuePair <Unit, List <HexCell> > >(); foreach (Unit un in instance.uQue) { un.CurrentHex.passable = true; } foreach (Unit un in instance.uQue) { endpoint = HexCell.NewLocationInOffset(un.CurrentHex.Cube, directionVector); if (!MapMaster.IsCellOnMap((int)endpoint.y, (int)endpoint.x)) { continue; } goal = MapMaster.Map[(int)endpoint.y, (int)endpoint.x]; newPath = HexStar.GetPath(un.CurrentHex, goal, un.MoveSpeed); if (newPath.Count > 0) { paths.Add(new KeyValuePair <Unit, List <HexCell> >(un, newPath)); } else { un.CurrentHex.passable = false; } } EvaluateTileGroup(paths); instance.uQue.Clear(); if (!target.Moved && target.UName == "Infantry") { target.GetComponentInChildren <Animator>().Play("GoToIdle"); } target = null; } } } } } }
public void Parse(Dictionary <ushort, List <ulong> > track, Dictionary <ulong, Record> map, CASCHandler handler, bool quiet, OverToolFlags flags) { string output = flags.Positionals[2]; List <string> maps = flags.Positionals.Skip(3).ToList(); bool skipCmodel = !flags.ExportCollision; for (int i = 0; i < maps.Count; ++i) { maps[i] = maps[i].ToUpperInvariant().TrimStart('0'); } bool mapWildcard = maps.Count == 0; if (maps.Count > 0 && maps.Contains("*")) { mapWildcard = true; } char animEncoding = flags.AnimFormat; if (flags.Raw) { animEncoding = '+'; } bool suppressAnimations = flags.SkipAnimations; if (animEncoding == '+' && !flags.RawAnimation) { suppressAnimations = true; } char modelEncoding = flags.ModelFormat; if (flags.Raw) { modelEncoding = '+'; } bool suppressModels = flags.SkipModels; if (modelEncoding == '+' && !flags.RawModel) { suppressModels = true; } IDataWriter animWriter = null; if (animEncoding != 0 && animEncoding != '+') { Assembly asm = typeof(IDataWriter).Assembly; Type t = typeof(IDataWriter); List <Type> types = asm.GetTypes().Where(tt => tt != t && t.IsAssignableFrom(tt)).ToList(); foreach (Type tt in types) { if (animWriter != null) { break; } if (tt.IsInterface) { continue; } IDataWriter tmp = (IDataWriter)Activator.CreateInstance(tt); for (int i = 0; i < tmp.Identifier.Length; ++i) { if (tmp.Identifier[i] == animEncoding) { animWriter = tmp; break; } } } } IDataWriter modelWriter = null; if (modelEncoding != 0 && modelEncoding != '+') { Assembly asm = typeof(IDataWriter).Assembly; Type t = typeof(IDataWriter); List <Type> types = asm.GetTypes().Where(tt => tt != t && t.IsAssignableFrom(tt)).ToList(); foreach (Type tt in types) { if (modelWriter != null) { break; } if (tt.IsInterface) { continue; } IDataWriter tmp = (IDataWriter)Activator.CreateInstance(tt); for (int i = 0; i < tmp.Identifier.Length; ++i) { if (tmp.Identifier[i] == modelEncoding) { modelWriter = tmp; break; } } } } List <ulong> masters = track[0x9F]; List <byte> LODs = new List <byte>(new byte[5] { 0, 1, 128, 254, 255 }); Dictionary <ulong, ulong> replace = new Dictionary <ulong, ulong>(); foreach (ulong masterKey in masters) { if (!map.ContainsKey(masterKey)) { continue; } STUD masterStud = new STUD(Util.OpenFile(map[masterKey], handler)); if (masterStud.Instances == null) { continue; } MapMaster master = (MapMaster)masterStud.Instances[0]; if (master == null) { continue; } string name = Util.GetString(master.Header.name.key, map, handler); if (string.IsNullOrWhiteSpace(name)) { name = $"Unknown{GUID.Index(master.Header.data.key):X}"; } if (!mapWildcard && !(maps.Contains(name.ToUpperInvariant()) || maps.Contains($"{GUID.Index(masterKey):X}"))) { continue; } string outputPath = string.Format("{0}{1}{2}{1}{3:X}{1}", output, Path.DirectorySeparatorChar, Util.SanitizePath(name), GUID.Index(master.Header.data.key)); if (!map.ContainsKey(master.Header.data.key)) { continue; } HashSet <ulong> parsed = new HashSet <ulong>(); Dictionary <ulong, ulong> animList = new Dictionary <ulong, ulong>(); Dictionary <ulong, List <ulong> > soundData = new Dictionary <ulong, List <ulong> >(); if (!map.ContainsKey(master.DataKey(1))) { continue; } if (!map.ContainsKey(master.DataKey(2))) { continue; } if (!map.ContainsKey(master.DataKey(8))) { continue; } if (!map.ContainsKey(master.DataKey(0xB))) { continue; } if (!map.ContainsKey(master.DataKey(0x11))) { continue; } if (!map.ContainsKey(master.DataKey(0x10))) { continue; } using (Stream mapStream = Util.OpenFile(map[master.DataKey(1)], handler)) { Console.Out.WriteLine("Extracting map {0} with ID {1:X8}", name, GUID.Index(master.Header.data.key)); Map mapData = new Map(mapStream); IDataWriter owmap = new OWMAPWriter(); Dictionary <ulong, List <string> >[] used = null; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } HashSet <ulong> soundDone = new HashSet <ulong>(); Sound.FindSoundsEx(master.Header.audio.key, soundDone, soundData, map, handler, replace, master.Header.data.key); using (Stream map2Stream = Util.OpenFile(map[master.DataKey(2)], handler)) { if (map2Stream != null) { Map map2Data = new Map(map2Stream); using (Stream map8Stream = Util.OpenFile(map[master.DataKey(8)], handler)) { if (map8Stream != null) { Map map8Data = new Map(map8Stream); using (Stream mapBStream = Util.OpenFile(map[master.DataKey(0xB)], handler)) { if (mapBStream != null) { Map mapBData = new Map(mapBStream, true); using (Stream map11Stream = Util.OpenFile(map[master.DataKey(0x11)], handler)) { if (map11Stream != null) { Map11 map11 = new Map11(map11Stream); Sound.FindSoundsSTUD(map11.main, soundDone, soundData, map, handler, replace, masterKey, master.DataKey(0x11)); Sound.FindSoundsSTUD(map11.secondary, soundDone, soundData, map, handler, replace, masterKey, master.DataKey(0x11)); } } mapBStream.Position = (long)(Math.Ceiling((float)mapBStream.Position / 16.0f) * 16); // Future proofing for (int i = 0; i < mapBData.STUDs.Count; ++i) { STUD stud = mapBData.STUDs[i]; Sound.FindSoundsSTUD(stud, soundDone, soundData, map, handler, replace, master.DataKey(0xB), master.DataKey(0xB)); } for (int i = 0; i < mapBData.Records.Length; ++i) { if (mapBData.Records[i] != null && mapBData.Records[i].GetType() != typeof(MapEntity)) { continue; } MapEntity mapprop = (MapEntity)mapBData.Records[i]; if (!map.ContainsKey(mapprop.Header.Entity)) { continue; } Sound.FindSoundsEx(mapprop.Header.Entity, soundDone, soundData, map, handler, replace, master.DataKey(0xB)); HashSet <ulong> bindingModels = new HashSet <ulong>(); Dictionary <ulong, List <ImageLayer> > bindingTextures = new Dictionary <ulong, List <ImageLayer> >(); using (Stream bindingFile = Util.OpenFile(map[mapprop.Header.Entity], handler)) { STUD binding = new STUD(bindingFile, true, STUDManager.Instance, false, true); foreach (ISTUDInstance instance in binding.Instances) { if (instance == null) { continue; } if (instance.Name != binding.Manager.GetName(typeof(ComplexModelRecord))) { continue; } ComplexModelRecord cmr = (ComplexModelRecord)instance; mapprop.ModelLook = cmr.Data.material.key; mapprop.Model = cmr.Data.model.key; Skin.FindAnimations(cmr.Data.animationList.key, soundData, animList, replace, parsed, map, handler, bindingModels, bindingTextures, mapprop.Model); Skin.FindAnimations(cmr.Data.secondaryAnimationList.key, soundData, animList, replace, parsed, map, handler, bindingModels, bindingTextures, mapprop.Model); break; } } mapBData.Records[i] = mapprop; } using (Stream mapLStream = Util.OpenFile(map[master.DataKey(9)], handler)) { Map mapLData = new Map(mapLStream); using (Stream outputStream = File.Open($"{outputPath}{Util.SanitizePath(name)}{owmap.Format}", FileMode.Create, FileAccess.Write)) { used = owmap.Write(outputStream, mapData, map2Data, map8Data, mapBData, mapLData, name, modelWriter); } } } } } } } } IDataWriter owmat = new OWMATWriter(); using (Stream map10Stream = Util.OpenFile(map[master.DataKey(0x10)], handler)) { Map10 physics = new Map10(map10Stream); using (Stream outputStream = File.Open($"{outputPath}physics{modelWriter.Format}", FileMode.Create, FileAccess.Write)) { modelWriter.Write(physics, outputStream, new object[0]); } } if (used != null) { Dictionary <ulong, List <string> > models = used[0]; Dictionary <ulong, List <string> > materials = used[1]; Dictionary <ulong, Dictionary <ulong, List <ImageLayer> > > cache = new Dictionary <ulong, Dictionary <ulong, List <ImageLayer> > >(); if (!suppressModels) { foreach (KeyValuePair <ulong, List <string> > modelpair in models) { if (!map.ContainsKey(modelpair.Key)) { continue; } if (!parsed.Add(modelpair.Key)) { continue; } HashSet <string> extracted = new HashSet <string>(); using (Stream modelStream = Util.OpenFile(map[modelpair.Key], handler)) { Chunked mdl = new Chunked(modelStream, true); modelStream.Position = 0; if (modelEncoding != '+' && modelWriter != null) { foreach (string modelOutput in modelpair.Value) { if (!extracted.Add(modelOutput)) { continue; } using (Stream outputStream = File.Open($"{outputPath}{modelOutput}", FileMode.Create, FileAccess.Write)) { if (modelWriter.Write(mdl, outputStream, LODs, new Dictionary <ulong, List <ImageLayer> >(), new object[5] { null, null, null, null, skipCmodel })) { if (!quiet) { Console.Out.WriteLine("Wrote model {0}", modelOutput); } } else { if (!quiet) { Console.Out.WriteLine("Failed to write model"); } } } } } if (flags.RawModel) { using (Stream outputStream = File.Open($"{outputPath}{GUID.LongKey(modelpair.Key):X12}.{GUID.Type(modelpair.Key):X3}", FileMode.Create, FileAccess.Write)) { if (modelWriter.Write(mdl, outputStream, LODs, new Dictionary <ulong, List <ImageLayer> >(), new object[5] { null, null, null, null, skipCmodel })) { if (!quiet) { Console.Out.WriteLine("Wrote raw model {0:X12}.{1:X3}", GUID.LongKey(modelpair.Key), GUID.Type(modelpair.Key)); } } else { if (!quiet) { Console.Out.WriteLine("Failed to write model"); } } } } } } } if (!suppressAnimations) { foreach (KeyValuePair <ulong, ulong> kv in animList) { ulong parent = kv.Value; ulong key = kv.Key; Stream animStream = Util.OpenFile(map[key], handler); if (animStream == null) { continue; } Animation anim = new Animation(animStream); animStream.Position = 0; string outpath = string.Format("{0}Animations{1}{2:X12}{1}{5}{1}{3:X12}.{4:X3}", outputPath, Path.DirectorySeparatorChar, GUID.Index(parent), GUID.LongKey(key), GUID.Type(key), anim.Header.priority); if (!Directory.Exists(Path.GetDirectoryName(outpath))) { Directory.CreateDirectory(Path.GetDirectoryName(outpath)); } if (flags.RawAnimation) { using (Stream outp = File.Open(outpath, FileMode.Create, FileAccess.Write)) { animStream.CopyTo(outp); if (!quiet) { Console.Out.WriteLine("Wrote raw animation {0}", outpath); } } } if (animEncoding != '+' && animWriter != null) { outpath = string.Format("{0}Animations{1}{2:X12}{1}{5}{1}{3:X12}.{4}", outputPath, Path.DirectorySeparatorChar, GUID.Index(parent), GUID.LongKey(key), animWriter.Format, anim.Header.priority); using (Stream outp = File.Open(outpath, FileMode.Create, FileAccess.Write)) { animWriter.Write(anim, outp); if (!quiet) { Console.Out.WriteLine("Wrote animation {0}", outpath); } } } } } if (!flags.SkipSound) { Console.Out.WriteLine("Dumping sounds..."); string soundPath = $"{outputPath}Sounds{Path.DirectorySeparatorChar}"; if (!Directory.Exists(soundPath)) { Directory.CreateDirectory(soundPath); } DumpVoice.Save(soundPath, soundData, map, handler, quiet); } if (!flags.SkipTextures) { foreach (KeyValuePair <ulong, List <string> > matpair in materials) { Dictionary <ulong, List <ImageLayer> > tmp = new Dictionary <ulong, List <ImageLayer> >(); if (cache.ContainsKey(matpair.Key)) { tmp = cache[matpair.Key]; } else { Skin.FindTextures(matpair.Key, tmp, new Dictionary <ulong, ulong>(), new HashSet <ulong>(), map, handler); cache.Add(matpair.Key, tmp); } Dictionary <string, TextureType> types = new Dictionary <string, TextureType>(); foreach (KeyValuePair <ulong, List <ImageLayer> > kv in tmp) { ulong materialId = kv.Key; List <ImageLayer> sublayers = kv.Value; HashSet <ulong> materialParsed = new HashSet <ulong>(); foreach (ImageLayer layer in sublayers) { if (!materialParsed.Add(layer.Key)) { continue; } KeyValuePair <string, TextureType> pair = Skin.SaveTexture(layer.Key, materialId, map, handler, outputPath, quiet, $"Textures/{GUID.Index(matpair.Key):X8}"); if (pair.Key == null) { continue; } types.Add(pair.Key, pair.Value); } } foreach (string matOutput in matpair.Value) { if (File.Exists($"{outputPath}{matOutput}")) { continue; } using (Stream outputStream = File.Open($"{outputPath}{matOutput}", FileMode.Create, FileAccess.Write)) { if (owmat.Write(null, outputStream, null, tmp, new object[1] { types })) { if (!quiet) { Console.Out.WriteLine("Wrote material {0}", matOutput); } } else { if (!quiet) { Console.Out.WriteLine("Failed to write material"); } } } } } } } } } }