public void Reload(BasicMap m, GameContentDataBase gcdb) { buildingCompleteRender = new RenderTarget2D(Game1.graphics.GraphicsDevice, boundingZone.Height * 3, boundingZone.Height); buildingRender = new RenderTarget2D(Game1.graphics.GraphicsDevice, boundingZone.Width, boundingZone.Height); int layer = 0; //location.Y *= -1; foreach (var item in buildingTilesPositions) { buildingTiles.Add(new List <BasicTile>()); foreach (var position in item) { // var chunk = m.testChunk[layer].Find(kv => kv.Key.Contains(position * 64 + location)); var chunk = m.Chunks.Find(c => c.region.Contains(position * 64 + location)); BasicTile tempTIle = chunk.returnLayer(layer).Find(tile => tile.positionGrid == position + location / 64); tempTIle.Reload(gcdb); tempTIle = tempTIle.BClone(); tempTIle.positionGrid = position; tempTIle.BReload(); buildingTiles[layer].Add(tempTIle); } layer++; } }
static public List <BasicTile> returnMapRadius(int r, List <BasicTile> bt, Vector2 bs) { Point loc = ((bs / 64).ToPoint().ToVector2() * 64).ToPoint(); List <Rectangle> temp = new List <Rectangle>(); List <BasicTile> tempTiles = new List <BasicTile>(); for (int i = 0; i < r + 1; i++) { for (int j = -(r - i); j < (r - i) + 1; j++) { temp.Add(new Rectangle(loc.X + i * 64, loc.Y + j * 64, 64, 64)); } } for (int i = -r; i != 0; i++) { for (int j = -(i + r); j < i + r + 1; j++) { temp.Add(new Rectangle(loc.X + i * 64, loc.Y + j * 64, 64, 64)); } } foreach (var item in temp) { BasicTile tempTile = bt.Find(t => t.mapPosition == item); if (tempTile != null) { tempTiles.Add(tempTile); } } return(tempTiles); }
public void FinalizeEnemyRound() { currentEnemy.character.attackedAsAI = false; BattleGUI.End(); bTest = false; AITarget = null; AIbtba = default(KeyValuePair <BasicTile, BasicAbility>); currentEnemy.character.attackedAsAI = false; currentEnemy.bIsCompleted = true; //var MaxAP = currentEnemy.character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.AP]; //BasicTile finalTile = currentEnemy.returnCompleteArea().Find(t => t.mapPosition.Location == PathMoveHandler.finalPos.ToPoint()); //var expendedAP = currentEnemy.characterArea.IndexOf(currentEnemy.characterArea.Find(area => area.Contains(finalTile))) + 1; //currentEnemy.character.statChart.currentActiveStats[(int)STATChart.ACTIVESTATS.STORED_AP] += MaxAP - expendedAP; if (currentEnemy.character.bSaveAP || true) { var MaxAP = currentEnemy.character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.AP]; BasicTile finalTile = currentEnemy.returnCompleteArea().Find(t => t.mapPosition.Location == PathMoveHandler.finalPos.ToPoint()); var expendedAP = currentEnemy.characterArea.IndexOf(currentEnemy.characterArea.Find(area => area.Contains(finalTile))) + 1; currentEnemy.character.statChart.currentActiveStats[(int)STATChart.ACTIVESTATS.STORED_AP] += MaxAP - expendedAP; } if (currentEnemy.character.bAIExecuteDefend) { BattleGUI.DefendOption(currentEnemy.character, currentEnemy.character); } // Console.WriteLine(currentEnemy.character.statChart.currentActiveStats[(int)STATChart.ACTIVESTATS.STORED_AP]); BattleScriptHandler.Execute(LUA.LuaBScriptEvent.EventType.postCT, this.toLuaTurnSetInfo()); TBAGW.EncounterInfo.currentTurn().bPlayerTurnEnemyOverriden = false; //This line must always be after the Execute line EncounterInfo.ClearDeathChars(); EncounterInfo.UpdateAllStats(); }
public int TileDistance(BasicTile other) { int deltaX = (int)(other.positionGrid.X - positionGrid.X); int deltaY = (int)(other.positionGrid.Y - positionGrid.Y); return(Math.Abs(deltaX) + Math.Abs(deltaY)); }
static internal bool bShouldRecheck(BasicTile t) { bMustDraw = true; if (lastCheckedTile == null || t.mapPosition != lastCheckedTile.mapPosition) { return(true); } return(false); }
public static List <Building> Generate(BasicMap bm) { var test = AnyBuildingTilesLeft(bm, new List <BasicTile>()); bool bHasBuildingTile = test.Key; if (!test.Key) { return(new List <Building>()); } List <Building> final = new List <Building>(); List <BasicTile> allBuildingTiles = FindBuildingTiles(bm); List <List <BasicTile> > groupedTiles = new List <List <BasicTile> >(); if (allBuildingTiles.Count > 1) { groupedTiles = GroupProximityTiles(allBuildingTiles); } else { groupedTiles.Add(new List <BasicTile>()); groupedTiles[0].Add(allBuildingTiles[0]); } int index = 0; foreach (var group in groupedTiles) { final.Add(new Building()); float firstX = group.Min(t => t.positionGrid.X); float firstY = group.Min(t => t.positionGrid.Y); Vector2 firstPos = new Vector2(firstX, firstY); final[index].location = firstPos * 64; var temp = group.OrderBy(t => t.tileLayer).Select(tile => tile.tileLayer).Distinct(); int layer = 0; foreach (var item in temp) { final[index].buildingTiles.Add(new List <BasicTile>()); foreach (var t in group.FindAll(tile => tile.tileLayer == item)) { BasicTile tempTIle = t.BClone(); tempTIle.positionGrid -= firstPos; final[index].buildingTiles[layer].Add(tempTIle); } layer++; } index++; } final.ForEach(b => b.Generate()); return(final); }
static internal void Start(BasicTile t, CharacterTurn ct) { if (bMustInitialize) { Initialize(); } lai.Clear(); CalculatePossiblePath(ct); lastCheckedTile = t; }
static public List <SpotNode> returnURDL(List <SpotNode> openNodes, List <SpotNode> closedNodes, List <BasicTile> tiles, SpotNode selectedNode) { BasicTile tileAbove = tiles.Find(t => t.mapPosition.Location == new Point(selectedNode.nodeLoc.X, selectedNode.nodeLoc.Y - 64)); BasicTile tileBelow = tiles.Find(t => t.mapPosition.Location == new Point(selectedNode.nodeLoc.X, selectedNode.nodeLoc.Y + 64)); BasicTile tileLeft = tiles.Find(t => t.mapPosition.Location == new Point(selectedNode.nodeLoc.X - 64, selectedNode.nodeLoc.Y)); BasicTile tileRight = tiles.Find(t => t.mapPosition.Location == new Point(selectedNode.nodeLoc.X + 64, selectedNode.nodeLoc.Y)); List <SpotNode> temp = new List <SpotNode>(); if (tileAbove != null) { temp.Add(new SpotNode(selectedNode.NodeCost + 1, new Point(selectedNode.nodeLoc.X, selectedNode.nodeLoc.Y - 64))); var temp1 = openNodes.Find(on => on.nodeLoc == tileAbove.mapPosition.Location); var temp2 = closedNodes.Find(on => on.nodeLoc == tileAbove.mapPosition.Location); if (temp1 != null || temp2 != null) { temp.RemoveAt(temp.Count - 1); } } if (tileBelow != null) { temp.Add(new SpotNode(selectedNode.NodeCost + 1, new Point(selectedNode.nodeLoc.X, selectedNode.nodeLoc.Y + 64))); var temp1 = openNodes.Find(on => on.nodeLoc == tileBelow.mapPosition.Location); var temp2 = closedNodes.Find(on => on.nodeLoc == tileBelow.mapPosition.Location); if (temp1 != null || temp2 != null) { temp.RemoveAt(temp.Count - 1); } } if (tileLeft != null) { temp.Add(new SpotNode(selectedNode.NodeCost + 1, new Point(selectedNode.nodeLoc.X - 64, selectedNode.nodeLoc.Y))); var temp1 = openNodes.Find(on => on.nodeLoc == tileLeft.mapPosition.Location); var temp2 = closedNodes.Find(on => on.nodeLoc == tileLeft.mapPosition.Location); if (temp1 != null || temp2 != null) { temp.RemoveAt(temp.Count - 1); } } if (tileRight != null) { temp.Add(new SpotNode(selectedNode.NodeCost + 1, new Point(selectedNode.nodeLoc.X + 64, selectedNode.nodeLoc.Y))); var temp1 = openNodes.Find(on => on.nodeLoc == tileRight.mapPosition.Location); var temp2 = closedNodes.Find(on => on.nodeLoc == tileRight.mapPosition.Location); if (temp1 != null || temp2 != null) { temp.RemoveAt(temp.Count - 1); } } return(temp); }
public static void Start(List <BasicTile> ats) { availableTiles = ats; selectedChar = null; secondaryChar = null; foreach (var item in CombatProcessor.encounterEnemies) { ats.RemoveAll(t => t.mapPosition.Intersects(item.spriteGameSize) || t.mapPosition.Contains(item.spriteGameSize) || t.mapPosition == item.spriteGameSize); } BasicTile temp = new BasicTile(); temp.mapPosition = PlayerController.selectedSprite.spriteGameSize; ats.Add(temp); }
private static List <List <BasicTile> > GroupProximityTiles(List <BasicTile> allBuildingTiles) { List <List <BasicTile> > tempList = new List <List <BasicTile> >(); int tilesLeftToCheck = allBuildingTiles.Count; int groupIndex = 0; while (allBuildingTiles.Count != 0) { tempList.Add(new List <BasicTile>()); List <BasicTile> handledTiles = new List <BasicTile>(); BasicTile selectedTile = allBuildingTiles[0]; handledTiles.Add(selectedTile); tempList[groupIndex].Add(selectedTile); allBuildingTiles.Remove(selectedTile); if (allBuildingTiles.Count != 0) { var temp = allBuildingTiles.FindAll(bt => bt.TileDistance(selectedTile) <= 1); tempList[groupIndex].AddRange(temp); foreach (var item in temp) { allBuildingTiles.Remove(item); } } if (allBuildingTiles.Count != 0) { while (handledTiles.Count != tempList[groupIndex].Count) { selectedTile = tempList[groupIndex].Except(handledTiles).First(); handledTiles.Add(selectedTile); if (allBuildingTiles.Count != 0) { var temp = allBuildingTiles.FindAll(bt => bt.TileDistance(selectedTile) <= 1); tempList[groupIndex].AddRange(temp); foreach (var item in temp) { allBuildingTiles.Remove(item); } } } } groupIndex++; } return(tempList); }
public void FinalizeCharacterRound() { BattleGUI.End(); bPlayerMustSelectAction = false; selectedCharTurn.bIsCompleted = true; if (selectedCharTurn.character.bSaveAP) { var MaxAP = selectedCharTurn.character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.AP]; BasicTile finalTile = selectedCharTurn.returnCompleteArea().Find(t => t.mapPosition.Location == PathMoveHandler.finalPos.ToPoint()); var expendedAP = selectedCharTurn.characterArea.IndexOf(selectedCharTurn.characterArea.Find(area => area.Contains(finalTile))) + 1; selectedCharTurn.character.statChart.currentActiveStats[(int)STATChart.ACTIVESTATS.STORED_AP] += MaxAP - expendedAP; } //Console.WriteLine(selectedCharTurn.character.statChart.currentActiveStats[(int)STATChart.ACTIVESTATS.STORED_AP]); BattleScriptHandler.Execute(LUA.LuaBScriptEvent.EventType.postCT, this.toLuaTurnSetInfo()); EncounterInfo.ClearDeathChars(); selectedCharTurn = null; EncounterInfo.UpdateAllStats(); }
internal static DangerTile Convert(LuaDangerTile luaDangerTile) { DangerTile temp = null; try { BasicTile t = LuaHelp.PointToTile(luaDangerTile.tile); temp = new DangerTile(t, luaDangerTile.function); } catch (Exception) { return(null); } if (temp != null) { if (temp.callFunction == null) { //return null } return(temp); } return(null); }
static public List <BasicTile> returnValidMapRadius2(int r, List <BasicTile> bt, Vector2 bs) { Point loc = ((bs / 64).ToPoint().ToVector2() * 64).ToPoint(); List <Rectangle> temp = new List <Rectangle>(); List <BasicTile> tempTiles = new List <BasicTile>(); for (int i = 0; i < r + 1; i++) { for (int j = -(r - i); j < (r - i) + 1; j++) { temp.Add(new Rectangle(loc.X + i * 64, loc.Y + j * 64, 64, 64)); } } for (int i = -r; i != 0; i++) { for (int j = -(i + r); j < i + r + 1; j++) { temp.Add(new Rectangle(loc.X + i * 64, loc.Y + j * 64, 64, 64)); } } foreach (var item in temp) { BasicTile tempTile = bt.Find(t => t.mapPosition == item); if (tempTile != null) { tempTiles.Add(tempTile); } } List <SpotNode> openNodes = new List <SpotNode>(); List <SpotNode> closedNodes = new List <SpotNode>(); SpotNode startNode = new SpotNode(0, ((bs / 64).ToPoint().ToVector2() * 64).ToPoint()); SpotNode selectedNode; openNodes.AddRange(returnURDL(openNodes, closedNodes, tempTiles, startNode)); while (openNodes.Count != 0) { for (int i = 1; i < r + 1; i++) { selectedNode = openNodes.Find(on => on.NodeCost == i); if (selectedNode != null) { openNodes.Remove(selectedNode); closedNodes.Add(selectedNode); if (i != r) { openNodes.AddRange(returnURDL(openNodes, closedNodes, tempTiles, selectedNode)); } break; } } } List <BasicTile> toDeleteTiles = new List <BasicTile>(); foreach (var tile in tempTiles) { bool bCanReach = false; foreach (var cn in closedNodes) { if (tile.mapPosition.Location == cn.nodeLoc) { bCanReach = true; } } if (!bCanReach) { toDeleteTiles.Add(tile); } } foreach (var item in toDeleteTiles) { tempTiles.Remove(item); } return(tempTiles); }
static public bool TryCalculatePath(NPC npc, NPCMoveToCommand NPCtc, BasicMap parentMap, BasicTile start, BasicTile end) { BasicMap mapToCheckIn; if (NPCtc.mapID == 0) { mapToCheckIn = parentMap; } else { mapToCheckIn = parentMap.subMaps.Find(m => m.identifier == NPCtc.mapID); } var chunks = MapChunk.returnChunkRadius(mapToCheckIn, start.mapPosition.Location.ToVector2(), 2); if (chunks.Count != 0) { List <BasicTile> tiles = new List <BasicTile>(); foreach (var chunk in chunks) { tiles.AddRange(mapToCheckIn.possibleTilesWithController(chunk.region, mapToCheckIn)); } tiles = tiles.Distinct().ToList(); var test = PathFinder.NewPathSearch(start, end, tiles); if (test != null && test.Count != 0) { return(true); } } return(false); }
internal DangerTile(BasicTile tile, NLua.LuaFunction f) { parentLocation = tile; callFunction = f; }