public override void ShowList() { base.ShowList(); if (BattleModel.Instance.crtBattle == null) { return; } int i; for (i = 0; i < BattleModel.Instance.crtBattle.battle_height; i++) { for (int j = 0; j < BattleModel.Instance.crtBattle.battle_width; j++) { BattleCellInfo cell = BattleModel.Instance.crtBattle.allCells[i][j]; GameObject bgItem = CreateBaseItem(j, i, cell.bg_id); FightBaseItem itemCtr = bgItem.GetComponent <FightBaseItem>(); if (cell.bg_id == 10202) { //DestroyObject(bgItem); itemCtr.iconImage.color = ColorUtil.GetColor(ColorUtil.COLOR_BLACK, 0.3f); itemCtr.iconImage.rectTransform.sizeDelta = new Vector2(PosUtil.CELL_VIEW_W * 0.95f, PosUtil.CELL_W * 0.94f); } else { itemCtr.iconImage.rectTransform.sizeDelta = new Vector2(PosUtil.CELL_VIEW_W * 0.9f, PosUtil.CELL_W * 0.9f); } } } }
public void InitRoadCrawl() { CellInfo centerCell = CellModel.Instance.GetCellByPos(posX, posY); List <CellInfo> cellNeighbors = CellModel.Instance.GetNeighbors(centerCell); CellInfo findCellPoint = null; for (int i = 0; i < cellNeighbors.Count; i++) { CellInfo cellNeighbor = cellNeighbors[i]; if (cellNeighbor == null) { continue; } BattleCellInfo bcellInfo = BattleModel.Instance.crtBattle.GetBattleCellByPos(cellNeighbor.posX, cellNeighbor.posY); if (bcellInfo.bg_id != special1) { continue; } findCellPoint = cellNeighbor; Vector2 fromPos = PosMgr.GetFightCellPos(posX, posY); Vector2 toPos = PosMgr.GetFightCellPos(findCellPoint.posX, findCellPoint.posY); rotate = PosMgr.VectorAngle(new Vector2(fromPos.x, fromPos.y), new Vector2(toPos.x, toPos.y)) / FightConst.ROTATE_BASE; break; } }
public void SaveBattleInfo() { string filePath = FileUtil.Instance().FullName("dat/map/" + mapId); File.Delete(filePath + ".bytes"); FileStream fs = new FileStream(filePath + ".bytes", FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(start_x); bw.Write(start_y); bw.Write(end_x); bw.Write(end_y); bw.Write(battle_width); bw.Write(battle_height); for (int i = 0; i < battle_height; i++) { List <BattleCellInfo> xcells = allCells[i]; for (int j = 0; j < battle_width; j++) { BattleCellInfo battleCellInfo = xcells[j]; bw.Write(battleCellInfo.bg_id); bw.Write(battleCellInfo.monster_id); bw.Write(battleCellInfo.floor_id); bw.Write(battleCellInfo.cell_id); bw.Write(battleCellInfo.cover_id); bw.Write(battleCellInfo.walls[0]); bw.Write(battleCellInfo.walls[1]); bw.Write(battleCellInfo.walls[2]); } } int index = 0; for (int i = (int)PosMgr.Y_HALF_COUNT; i >= -PosMgr.Y_HALF_COUNT; i--) { for (int j = -(int)PosMgr.X_HALF_COUNT; j <= PosMgr.X_HALF_COUNT; j++) { bw.Write(fgIds[index]); index++; } } bw.Flush(); bw.Close(); fs.Close(); Debug.Log(mapId + " save complete"); }
public void FillNew(short set_start_x, short set_start_y, short set_end_x, short set_end_y, short set_battle_width, short set_battle_height) { allCells = new List <List <BattleCellInfo> > (); fgIds = new List <int> (); start_x = set_start_x; start_y = set_start_y; end_x = set_end_x; end_y = set_end_y; battle_width = set_battle_width; battle_height = set_battle_height; for (int i = 0; i < battle_height; i++) { List <BattleCellInfo> xcells = new List <BattleCellInfo>(); allCells.Add(xcells); for (int j = 0; j < battle_width; j++) { BattleCellInfo battleCellInfo = new BattleCellInfo(); xcells.Add(battleCellInfo); battleCellInfo.bg_id = 10202; battleCellInfo.monster_id = 0; battleCellInfo.floor_id = 0; battleCellInfo.cell_id = UnityEngine.Random.Range(10101, 10101 + 5); battleCellInfo.cover_id = 0; battleCellInfo.walls.Add(0); battleCellInfo.walls.Add(0); battleCellInfo.walls.Add(0); } } for (int i = (int)PosMgr.Y_HALF_COUNT; i >= -PosMgr.Y_HALF_COUNT; i--) { for (int j = -(int)PosMgr.X_HALF_COUNT; j <= PosMgr.X_HALF_COUNT; j++) { if (i <= start_y && i >= end_y && j >= start_x && j <= end_x) { fgIds.Add(0); } else { fgIds.Add(10302); } } } }
public void FillByte(byte[] bytes) { readIndex = 0; allCells = new List <List <BattleCellInfo> >(); fgIds = new List <int>(); start_x = ReadShort(bytes); start_y = ReadShort(bytes); end_x = ReadShort(bytes); end_y = ReadShort(bytes); battle_width = ReadShort(bytes); battle_height = ReadShort(bytes); if (HideHeight() > 0) { clearCaching = true; } for (int i = 0; i < battle_height; i++) { List <BattleCellInfo> xcells = new List <BattleCellInfo>(); allCells.Add(xcells); for (int j = 0; j < battle_width; j++) { BattleCellInfo battleCellInfo = new BattleCellInfo(); xcells.Add(battleCellInfo); battleCellInfo.bg_id = ReadInt(bytes); battleCellInfo.monster_id = ReadInt(bytes); battleCellInfo.floor_id = ReadInt(bytes); battleCellInfo.cell_id = ReadInt(bytes); battleCellInfo.cover_id = ReadInt(bytes); battleCellInfo.walls.Add(ReadInt(bytes)); battleCellInfo.walls.Add(ReadInt(bytes)); battleCellInfo.walls.Add(ReadInt(bytes)); } } for (int i = (int)PosMgr.Y_HALF_COUNT; i >= -PosMgr.Y_HALF_COUNT; i--) { for (int j = -(int)PosMgr.X_HALF_COUNT; j <= PosMgr.X_HALF_COUNT; j++) { fgIds.Add(ReadInt(bytes)); } } }
public bool RoadEnd() { if (!IsRoadCrawl()) { return(false); } CellInfo centerCell = CellModel.Instance.GetCellByPos(posX, posY); List <CellInfo> cellNeighbors = CellModel.Instance.GetNeighbors(centerCell); for (int i = 0; i < cellNeighbors.Count; i++) { CellInfo cellNeighbor = cellNeighbors[i]; if (cellNeighbor == null) { continue; } BattleCellInfo bcellInfo = BattleModel.Instance.crtBattle.GetBattleCellByPos(cellNeighbor.posX, cellNeighbor.posY); if (bcellInfo.bg_id == special1) { bool isPassed = false; for (int j = 0; j < crawlPassPoints.Count; j++) { Vector2 passPoint = crawlPassPoints[j]; if (passPoint.x == cellNeighbor.posX && passPoint.y == cellNeighbor.posY) { isPassed = true; break; } } if (isPassed == false) { return(false); } } } return(true); }
void OnEnable() { if (BattleModel.Instance.crtBattle != null) { switch (type) { case FightLayerType.bg: int i; for (i = 0; i < BattleModel.Instance.crtBattle.battle_height; i++) { for (int j = 0; j < BattleModel.Instance.crtBattle.battle_width; j++) { BattleCellInfo cell = BattleModel.Instance.crtBattle.allCells[i][j]; CreateCellItem(j + BattleModel.Instance.crtBattle.start_x, -i + BattleModel.Instance.crtBattle.start_y, cell.bg_id); } } break; case FightLayerType.monster: for (i = 0; i < BattleModel.Instance.crtBattle.battle_height; i++) { for (int j = 0; j < BattleModel.Instance.crtBattle.battle_width; j++) { BattleCellInfo cell = BattleModel.Instance.crtBattle.allCells[i][j]; config_monster_item config_monster = (config_monster_item)GridMain.resourceMgr.config_monster.GetItem(cell.monster_id); if (config_monster != null) { CreateCellItem(j + BattleModel.Instance.crtBattle.start_x, -i + BattleModel.Instance.crtBattle.start_y, config_monster.icon, config_monster.rotate); } else { CreateCellItem(j + BattleModel.Instance.crtBattle.start_x, -i + BattleModel.Instance.crtBattle.start_y, cell.monster_id); } } } break; case FightLayerType.floor: for (i = 0; i < BattleModel.Instance.crtBattle.battle_height; i++) { for (int j = 0; j < BattleModel.Instance.crtBattle.battle_width; j++) { BattleCellInfo cell = BattleModel.Instance.crtBattle.allCells[i][j]; CreateCellItem(j + BattleModel.Instance.crtBattle.start_x, -i + BattleModel.Instance.crtBattle.start_y, cell.floor_id); } } break; case FightLayerType.cell: for (i = 0; i < BattleModel.Instance.crtBattle.battle_height; i++) { for (int j = 0; j < BattleModel.Instance.crtBattle.battle_width; j++) { BattleCellInfo cell = BattleModel.Instance.crtBattle.allCells[i][j]; config_cell_item config_cell = (config_cell_item)GridMain.resourceMgr.config_cell.GetItem(cell.cell_id); CreateCellItem(j + BattleModel.Instance.crtBattle.start_x, -i + BattleModel.Instance.crtBattle.start_y, config_cell.icon, config_cell.rotate); } } break; case FightLayerType.fence: for (i = 0; i < BattleModel.Instance.crtBattle.battle_height; i++) { for (int j = 0; j < BattleModel.Instance.crtBattle.battle_width; j++) { BattleCellInfo cell = BattleModel.Instance.crtBattle.allCells[i][j]; CreateWallItem(j + BattleModel.Instance.crtBattle.start_x, -i + BattleModel.Instance.crtBattle.start_y, 0, cell.walls[0]); CreateWallItem(j + BattleModel.Instance.crtBattle.start_x, -i + BattleModel.Instance.crtBattle.start_y, 1, cell.walls[1]); CreateWallItem(j + BattleModel.Instance.crtBattle.start_x, -i + BattleModel.Instance.crtBattle.start_y, 2, cell.walls[2]); } } break; case FightLayerType.cover: for (i = 0; i < BattleModel.Instance.crtBattle.battle_height; i++) { for (int j = 0; j < BattleModel.Instance.crtBattle.battle_width; j++) { BattleCellInfo cell = BattleModel.Instance.crtBattle.allCells[i][j]; config_cover_item config_cover = (config_cover_item)GridMain.resourceMgr.config_cover.GetItem(cell.cover_id); if (config_cover != null) { CreateCoverItem(j + BattleModel.Instance.crtBattle.start_x, -i + BattleModel.Instance.crtBattle.start_y, config_cover.icon); } else { CreateCoverItem(j + BattleModel.Instance.crtBattle.start_x, -i + BattleModel.Instance.crtBattle.start_y, cell.cover_id); } } } break; case FightLayerType.fg: int index = 0; for (i = (int)PosMgr.Y_HALF_COUNT; i >= -PosMgr.Y_HALF_COUNT; i--) { for (int j = -(int)PosMgr.X_HALF_COUNT; j <= PosMgr.X_HALF_COUNT; j++) { int id = BattleModel.Instance.crtBattle.fgIds[index]; CreateCellItem(j, i, id); index++; } } break; } } }
public void InitFight() { FightModel.Instance.InitFightInfo(); CellInfo.start_x = crtBattle.start_x; MonsterModel.Instance.Destroy(); FloorModel.Instance.Destroy(); CellModel.Instance.Destroy(); WallModel.Instance.Destroy(); CoverModel.Instance.Destroy(); InvadeModel.Instance.Destroy(); int i; for (i = 0; i < crtBattle.battle_height; i++) { List <MonsterInfo> yMonsters = new List <MonsterInfo>(); List <FloorInfo> yFloors = new List <FloorInfo>(); List <CellInfo> yCells = new List <CellInfo>(); List <List <WallInfo> > yWalls = new List <List <WallInfo> >(); List <CoverInfo> yCovers = new List <CoverInfo>(); MonsterModel.Instance.allMonsters.Add(yMonsters); FloorModel.Instance.allFloors.Add(yFloors); CellModel.Instance.allCells.Add(yCells); WallModel.Instance.allWalls.Add(yWalls); CoverModel.Instance.allCovers.Add(yCovers); for (int j = 0; j < crtBattle.battle_width; j++) { BattleCellInfo battleCellInfo = crtBattle.allCells[i][j]; MonsterInfo monsterInfo = new MonsterInfo(); monsterInfo.configId = battleCellInfo.monster_id; monsterInfo.SetConfig(battleCellInfo.monster_id); monsterInfo.posX = j; monsterInfo.posY = i; yMonsters.Add(monsterInfo); FloorInfo floorInfo = new FloorInfo(); floorInfo.SetConfig(battleCellInfo.floor_id); floorInfo.posX = j; floorInfo.posY = i; yFloors.Add(floorInfo); CellInfo cellInfo = new CellInfo(); cellInfo.SetConfig(battleCellInfo.cell_id); cellInfo.posX = j; cellInfo.posY = i; yCells.Add(cellInfo); if (cellInfo.isBlank == false && cellInfo.config.cell_type == (int)CellType.changer) { cellInfo.changer = cellInfo.config.icon; cellInfo.SetConfig(cellInfo.config.hide_id); cellInfo.originalConfigId = cellInfo.config.hide_id; } if (cellInfo.config != null) { if (cellInfo.config.cell_type == (int)CellType.invade || cellInfo.config.id == 10007) { InvadeModel.Instance.AddInvade(cellInfo); } } CoverInfo coverInfo = new CoverInfo(); coverInfo.SetConfig(battleCellInfo.cover_id); coverInfo.posX = j; coverInfo.posY = i; yCovers.Add(coverInfo); List <WallInfo> xWalls = new List <WallInfo>(); for (int n = 0; n < 3; n++) { WallInfo wallInfo = new WallInfo(); wallInfo.SetConfig(battleCellInfo.walls[n]); wallInfo.posX = j; wallInfo.posY = i; wallInfo.posN = n; xWalls.Add(wallInfo); } yWalls.Add(xWalls); } } MonsterModel.Instance.RandomPos(); MonsterModel.Instance.HoldAll(); HideModel.Instance.LoadHider(); }
private void RecursionRoadCrawl() { if (crawlCount > 0) { CellInfo centerCell = CellModel.Instance.GetCellByPos(posX, posY); List <CellInfo> cellNeighbors = CellModel.Instance.GetNeighbors(centerCell); CellInfo findCellPoint = null; for (int i = 0; i < cellNeighbors.Count; i++) { CellInfo cellNeighbor = cellNeighbors[i]; if (cellNeighbor == null) { continue; } if (cellNeighbor.CanCrawl() == false) { continue; } CoverInfo coverInfo = CoverModel.Instance.GetCoverByPos(cellNeighbor.posY, cellNeighbor.posY); if (coverInfo != null && coverInfo.IsOpen() == false) { continue; } WallInfo wall = WallModel.Instance.GetWall(centerCell, cellNeighbor); if (wall.IsNull() == false) { continue; } BattleCellInfo bcellInfo = BattleModel.Instance.crtBattle.GetBattleCellByPos(cellNeighbor.posX, cellNeighbor.posY); if (bcellInfo.bg_id != special1) { continue; } bool isPassed = false; for (int j = 0; j < crawlPassPoints.Count; j++) { Vector2 passPoint = crawlPassPoints[j]; if (passPoint.x == cellNeighbor.posX && passPoint.y == cellNeighbor.posY) { isPassed = true; break; } } if (isPassed == false) { findCellPoint = cellNeighbor; break; } } if (findCellPoint != null) { Hold(false); MonsterInfo toMonsterInfo = MonsterModel.Instance.GetMonsterByPos(findCellPoint.posY, findCellPoint.posX); MonsterModel.Instance.SwitchPos(this, toMonsterInfo); this.SwitchPos(toMonsterInfo); Hold(); crawlCount--; crawlPassPoints.Add(new Vector2(findCellPoint.posX, findCellPoint.posY)); MonsterModel.Instance.AddCrawAnim(this, findCellPoint); if (crawlCount > 0) { RecursionRoadCrawl(); } } } }
public void OnItemClick(int posx, int posy, int posn) { if (mapId <= 0) { return; } if (brushType == FightLayerType.none) { return; } if (brushId <= 0) { return; } //Debug.Log ("mapId " + mapId + " brushType " + brushType + " brushId " + brushId + " posx " + posx + " posy " + posy + " posn " + posn); //Debug.Log (" x " + posx + " y " + posy + " n " + posn); if (brushType == FightLayerType.fg) { int fgId = BattleModel.Instance.crtBattle.fgIds[(posy + (int)PosMgr.Y_HALF_COUNT) * (int)PosMgr.X_FULL_COUNT + (posx + (int)PosMgr.X_HALF_COUNT)]; if (fgId != brushId && !BattleModel.Instance.crtBattle.InViewRect(posx, posy)) { BattleModel.Instance.crtBattle.fgIds[(posy + (int)PosMgr.Y_HALF_COUNT) * (int)PosMgr.X_FULL_COUNT + (posx + (int)PosMgr.X_HALF_COUNT)] = brushId; UpdateAndSaveItem(posx, posy, posn); } } else { int gridx = posx - BattleModel.Instance.crtBattle.start_x; int gridy = -posy + BattleModel.Instance.crtBattle.start_y; //Debug.Log (" gridx " + gridx + " gridy " + gridy); BattleCellInfo cell = BattleModel.Instance.crtBattle.allCells[gridy][gridx]; if (brushType == FightLayerType.bg) { if (cell.bg_id != brushId) { //Debug.Log(cell.cell_id + " to " + brushId); cell.bg_id = brushId; UpdateAndSaveItem(posx, posy, posn); } } if (brushType == FightLayerType.monster) { if (cell.monster_id != brushId) { //Debug.Log(cell.cell_id + " to " + brushId); cell.monster_id = brushId; UpdateAndSaveItem(posx, posy, posn); } } if (brushType == FightLayerType.floor) { if (cell.floor_id != brushId) { //Debug.Log(cell.cell_id + " to " + brushId); cell.floor_id = brushId; UpdateAndSaveItem(posx, posy, posn); } } if (brushType == FightLayerType.cover) { if (cell.cover_id != brushId) { //Debug.Log(cell.cell_id + " to " + brushId); cell.cover_id = brushId; UpdateAndSaveItem(posx, posy, posn); } } if (brushType == FightLayerType.cell) { if (cell.cell_id != brushId) { //Debug.Log(cell.cell_id + " to " + brushId); cell.cell_id = brushId; UpdateAndSaveItem(posx, posy, posn); } } if (brushType == FightLayerType.fence) { if (cell.walls[posn] != brushId) { //Debug.Log(cell.cell_id + " to " + brushId); cell.walls[posn] = brushId; UpdateAndSaveItem(posx, posy, posn); } } } }
private void Save(int cellId = -2) { GridModel.Instance.set_start_x = GetItemValueshort("start_x"); GridModel.Instance.set_start_y = GetItemValueshort("start_y"); GridModel.Instance.set_end_x = GetItemValueshort("end_x"); GridModel.Instance.set_end_y = GetItemValueshort("end_y"); GridModel.Instance.set_battle_width = GetItemValueshort("battle_width"); GridModel.Instance.set_battle_height = GetItemValueshort("battle_height"); bool needBuild = false; if (BattleModel.Instance.crtBattle.start_x != GridModel.Instance.set_start_x) { needBuild = true; } BattleModel.Instance.crtBattle.start_x = GridModel.Instance.set_start_x; if (BattleModel.Instance.crtBattle.start_y != GridModel.Instance.set_start_y) { needBuild = true; } BattleModel.Instance.crtBattle.start_y = GridModel.Instance.set_start_y; if (BattleModel.Instance.crtBattle.end_x != GridModel.Instance.set_end_x) { needBuild = true; } BattleModel.Instance.crtBattle.end_x = GridModel.Instance.set_end_x; if (BattleModel.Instance.crtBattle.end_y != GridModel.Instance.set_end_y) { needBuild = true; } BattleModel.Instance.crtBattle.end_y = GridModel.Instance.set_end_y; if (BattleModel.Instance.crtBattle.battle_width != GridModel.Instance.set_battle_width) { needBuild = true; } BattleModel.Instance.crtBattle.battle_width = GridModel.Instance.set_battle_width; if (BattleModel.Instance.crtBattle.battle_height != GridModel.Instance.set_battle_height) { needBuild = true; } BattleModel.Instance.crtBattle.battle_height = GridModel.Instance.set_battle_height; BattleModel.Instance.crtConfig.id = GetItemValueint("id"); BattleModel.Instance.crtConfig.icon = GetItemValueint("icon"); BattleModel.Instance.crtConfig.name = GetItemValuestring("name"); BattleModel.Instance.crtConfig.desc = GetItemValuestring("desc"); BattleModel.Instance.crtConfig.pre_id = GetItemValueint("pre_id"); BattleModel.Instance.crtConfig.task = GetItemValuestring("task"); BattleModel.Instance.crtConfig.step = GetItemValueint("step"); BattleModel.Instance.crtConfig.build = GetItemValueint("build"); BattleModel.Instance.crtConfig.fill = GetItemValueint("fill"); BattleModel.Instance.crtConfig.judge = GetItemValuestring("judge"); BattleModel.Instance.crtConfig.forbid_skill = GetItemValuestring("forbid_skill"); BattleModel.Instance.crtConfig.forbid_prop = GetItemValuestring("forbid_prop"); gameObject.SetActive(false); Debug.Log("needBuild " + needBuild); if (needBuild) { BattleModel.Instance.crtBattle.FillNew(GridModel.Instance.set_start_x, GridModel.Instance.set_start_y, GridModel.Instance.set_end_x, GridModel.Instance.set_end_y, GridModel.Instance.set_battle_width, GridModel.Instance.set_battle_height); GameObject EditPart = GameObject.FindGameObjectWithTag("EditPart"); EditPart.GetComponent <EditPart>().ShowList(FightLayerType.none); EditPart.GetComponent <EditPart>().ShowList(FightLayerType.all); } else { List <List <BattleCellInfo> > allCells = BattleModel.Instance.crtBattle.allCells; for (int i = 0; i < allCells.Count; i++) { List <BattleCellInfo> xcells = allCells[i]; for (int j = 0; j < xcells.Count; j++) { BattleCellInfo battleCellInfo = xcells[j]; if (battleCellInfo.cell_id >= 10101 && battleCellInfo.cell_id <= 10105) { if (cellId == -1) { battleCellInfo.cell_id = UnityEngine.Random.Range(10101, 10101 + 5); } if (cellId == 0) { battleCellInfo.cell_id = 10000; } if (cellId > 0) { battleCellInfo.cell_id = cellId; } } } } GameObject EditPart = GameObject.FindGameObjectWithTag("EditPart"); EditPart.GetComponent <EditPart>().ShowList(FightLayerType.none); EditPart.GetComponent <EditPart>().ShowList(FightLayerType.all); } }