public void updateTreasures() { GameBattleDTL dtl = activeBattleStage.DTL; string path = "Prefab/Misc/TREASURE"; GameObject gameObject = Resources.Load <GameObject>(path); bool[] bc = new bool[activeBattleStage.MEVT.Length]; for (int i = 0; i < bc.Length; i++) { bc[i] = false; } int ii = 0; for (int i = 0; i < dtl.Height; i++) { for (int j = 0; j < dtl.Width; j++) { if (mapEvent.ContainsKey(dtl.Points[ii].MapEvent)) { bc[dtl.Points[ii].MapEvent] = true; if (mapEvent[dtl.Points[ii].MapEvent].EventType == GameBattleMapEventType.Event) { ii++; continue; } GameObject obj = Instantiate <GameObject>(gameObject, transTreasures); obj.name = dtl.Points[ii].MapEvent.ToString(); Transform trans = obj.transform; trans.localPosition = new Vector3(j * GameDefine.TEXTURE_WIDTH, -i * GameDefine.TEXTURE_HEIGHT + layerHeight, 0.0f); GameAnimation gameAnimation = obj.GetComponent <GameAnimation>(); gameAnimation.playAnimation(); gameAnimation.offsetX = GameDefine.BATTLE_OFFSET_X; gameAnimation.offsetY = GameDefine.BATTLE_OFFSET_Y; } ii++; } } for (int i = 0; i < bc.Length; i++) { if (!bc[i]) { mapEvent.Remove(i); } } }
public void clear() { clearAnimations(); clearTreasures(); clearStage(); activeDTL = null; activeBattleStage = null; activeBattleStart = null; layerHeight = 0; lastEffectID = GameDefine.INVALID_ID; onEventOver = null; }
public void active() { activeBattleStage = GameBattleData.instance.getStage(GameUserData.instance.Stage); activeBattleStart = GameBattleData.instance.getStartData(GameUserData.instance.Stage); activeDTL = activeBattleStage.DTL; GameCameraManager.instance.MapWidth = activeDTL.Width * GameDefine.TEXTURE_WIDTH; GameCameraManager.instance.MapHeight = activeDTL.Height * GameDefine.TEXTURE_HEIGHT; byte[] block = new byte[activeDTL.Width * activeDTL.Height]; for (int i = 0; i < activeDTL.Width * activeDTL.Height; i++) { block[i] = activeDTL.Points[i].Move; } GameBattlePathFinder.instance.initMap(activeDTL.Width, activeDTL.Height, block); }
void loadDTL(int stage) { string path = stage < 10 ? "0" + stage.ToString() : stage.ToString(); string pathDir = Application.dataPath + "/Objects/DAT/Stage/Stage" + path + "/"; string pathDTL = pathDir + "map" + path + ".dtl"; FileStream fs = File.OpenRead(pathDTL); byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, (int)fs.Length); fs.Close(); GameBattleDTL dtl = data[stage].DTL; int index = 3; dtl.Unknow0 = bytes[index]; index += 1; dtl.Unknow1 = bytes[index]; index += 1; dtl.Unknow2 = bytes[index]; index += 1; dtl.Unknow3 = bytes[index]; index += 1; dtl.Width = BitConverter.ToInt16(bytes, index); index += 2; dtl.Height = BitConverter.ToInt16(bytes, index); index += 2; for (int i = 0; i < dtl.Unknow.Length; i++) { dtl.Unknow[i] = bytes[index]; index += 1; } dtl.Points = new GameBattleDTL.Point[dtl.Height * dtl.Width]; int ii = 0; for (int i = 0; i < dtl.Height; i++) { for (int j = 0; j < dtl.Width; j++) { dtl.Points[ii] = new GameBattleDTL.Point(); dtl.Points[ii].Move = bytes[index]; index += 1; dtl.Points[ii].Floor = bytes[index]; index += 1; dtl.Points[ii].MapEvent = BitConverter.ToInt16(bytes, index); index += 2; // editor test // GameObject imgObject = Resources.Load<GameObject>( "Prefab/Image" ); // GameObject obj = Instantiate( imgObject , GameObject.Find( "Cells" ).transform ); // obj.name = i + "-" + j; // // RectTransform trans = obj.GetComponent<RectTransform>(); // trans.localPosition = new Vector3( j * 30 , -i * 24 , 0.0f ); // trans.localScale = new Vector3( 1.0f , 1.0f , 1.0f ); // trans.sizeDelta = new Vector2( 30 , 24 ); // // Image image = obj.GetComponent<Image>(); // float c = ( dtl.Points[ ii ].Value0 * 25 ) / 255.0f; // image.color = new Color( c , c , c , ( c > 0.5f ? 0.5f : c ) ); // // if ( dtl.Points[ ii ].MapEvent != -1 && // data[ stage ].MEVT.Length > dtl.Points[ ii ].MapEvent ) // { // if ( data[ stage ].MEVT[ dtl.Points[ ii ].MapEvent ].EventType == 0 ) // { // image.color = new Color( 0.0f , 1.0f , 0.0f , 0.7f ); // } // else if ( data[ stage ].MEVT[ dtl.Points[ ii ].MapEvent ].EventType == 1 ) // { // image.color = new Color( 1.0f , 1.0f , 0.0f , 0.7f ); // } // } ii++; } } }
int getCost(int x, int y, GameUnitMove unitMove, GameUnitCampType camp, out bool bd) { // byte baseCost = 0; // byte block = 0; // bool addMove = false; // sbyte subMove = 0; // // switch ( moveType ) // { // case GameUnitMoveType.Walk0: // baseCost = 5; // block = 7; // addMove = true; // subMove = 0; // break; // case GameUnitMoveType.Walk1: // baseCost = 6; // block = 7; // addMove = true; // subMove = 0; // break; // case GameUnitMoveType.Walk2: // baseCost = 5; // block = 7; // addMove = true; // subMove = 0; // break; // case GameUnitMoveType.Walk3: // baseCost = 6; // block = 7; // addMove = true; // subMove = 1; // break; // case GameUnitMoveType.Fly4: // baseCost = 6; // block = 7; // addMove = false; // subMove = 0; // break; // case GameUnitMoveType.Fly5: // baseCost = 7; // block = 9; // addMove = false; // subMove = 0; // break; // case GameUnitMoveType.Fly6: // baseCost = 5; // block = 9; // addMove = false; // subMove = 0; // break; // case GameUnitMoveType.Walk7: // baseCost = 6; // block = 7; // addMove = true; // subMove = -1; // break; // case GameUnitMoveType.Fly8: // baseCost = 6; // block = 7; // addMove = true; // subMove = -2; // break; // case GameUnitMoveType.Fly9: // baseCost = 6; // block = 7; // addMove = true; // subMove = -2; // break; // case GameUnitMoveType.Walk10: // baseCost = 6; // block = 7; // addMove = true; // subMove = -2; // break; // case GameUnitMoveType.None: // baseCost = 100; // block = 7; // addMove = true; // subMove = 0; // break; // } bd = false; int cost = unitMove.baseCost; GameBattleDTL dtl = GameBattleManager.instance.ActiveDTL; int index1 = dtl.Width * y + x; GameBattleDTL.Point point = dtl.Points[index1]; int subMove = point.Move + unitMove.subMove; if (subMove < 0) { subMove = 0; } if (unitMove.addMove) { cost = unitMove.baseCost + subMove; } // right int index = dtl.Width * y + x + 1; if (index >= 0 && index < dtl.Points.Length) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(x + 1, y); if (unit != null) { if (unitMove.addMove && unit.IsAlive && unit.UnitCampType != camp) { bd = true; } } } // left index = dtl.Width * y + x - 1; if (index >= 0 && index < dtl.Points.Length) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(x - 1, y); if (unit != null) { if (unitMove.addMove && unit.IsAlive && unit.UnitCampType != camp) { bd = true; } } } // top index = dtl.Width * (y - 1) + x; if (index >= 0 && index < dtl.Points.Length) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(x, y - 1); if (unit != null) { if (unitMove.addMove && unit.IsAlive && unit.UnitCampType != camp) { bd = true; } } } // bottom index = dtl.Width * (y + 1) + x; if (index >= 0 && index < dtl.Points.Length) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(x, y + 1); if (unit != null) { if (unitMove.addMove && unit.IsAlive && unit.UnitCampType != camp) { bd = true; } } } return(cost); }
void findCell(int move, GameUnitMoveType moveType, bool fly, GameUnitCampType camp) { GameUnitMove unitMove = GameUnitMoveTypeData.instance.getData(moveType); bool user = (camp == GameUnitCampType.User); GameBattleDTL dtl = GameBattleManager.instance.ActiveDTL; closeList.Add(openList[0]); while (openList.Count > 0) { List <Cell> newOpenList = new List <Cell>(); for (int i = 0; i < openList.Count; i++) { Cell cell = openList[i]; GameBattleDTL.Point point = null; // right int index = dtl.Width * cell.y + cell.x + 1; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x + 1, cell.y, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x + 1, cell.y, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x + 1; newCell.y = cell.y; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } // left index = dtl.Width * cell.y + cell.x - 1; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x - 1, cell.y, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x - 1, cell.y, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x - 1; newCell.y = cell.y; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } // top index = dtl.Width * (cell.y - 1) + cell.x; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x, cell.y - 1, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x, cell.y - 1, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x; newCell.y = cell.y - 1; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } // bottom index = dtl.Width * (cell.y + 1) + cell.x; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x, cell.y + 1, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x, cell.y + 1, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x; newCell.y = cell.y + 1; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } } openList.Clear(); openList = null; openList = newOpenList; } for (int i = 1; i < closeList.Count;) { if (isUnit(closeList[i].x, closeList[i].y)) { closeList.RemoveAt(i); } else { i++; } } for (int i = 0; i < closeList.Count; i++) { addCell(closeList[i], user); } }
public void showLayer(int id, bool b) { // clearAnimations(); layerList.Add(id); string path = GameDefine.getString2(GameUserData.instance.Stage); if (objsLayer0 == null || objsLayer0.Length != activeBattleStage.Layer.L0.Length) { objsLayer0 = new GameObject[activeBattleStage.Layer.L0.Length]; } int lastLayer = 0; float lastWidth = 0.0f; float lastHeight = 0.0f; for (int j = 0; j < activeBattleStage.Layer.L0.Length; j++) { if (activeBattleStage.Layer.L0[j].ID == id) { if (objsLayer0[j] != null) { continue; } lastLayer = activeBattleStage.Layer.L0[j].Lyaer; layerHeight = id * 5000; if (id > 1 && GameUserData.instance.Stage == 34) { // fix stage 34 bug. layerHeight = 5000; } if (layerList.Count == 1) { GameBattleSceneMovement.instance.moveToEvent(0, 0); } if (activeBattleStage.Layer.L0[j].Name.Contains(".saf")) { string pathDir = "Prefab/Stage/Stage" + path + "/"; string pathTexture = pathDir + activeBattleStage.Layer.L0[j].Name.Replace(".saf", ""); GameObject imgObject = Resources.Load <GameObject>(pathTexture); GameObject obj = Instantiate(imgObject, GameCameraManager.instance.transform); obj.name = activeBattleStage.Layer.L0[j].Name; float z = GameDefine.getZ(activeBattleStage.Layer.L0[j].Unknow0); Transform trans = obj.transform; trans.localPosition = new Vector3(-GameCameraManager.instance.sceneWidthHalf, GameCameraManager.instance.sceneHeightHalf , z + 20); trans.localScale = new Vector3(1.0f, 1.0f, 1.0f); GameAnimation animation = obj.GetComponent <GameAnimation>(); animation.playAnimation(); objsLayer0[j] = obj; } else { string pathDir = "Texture/Map/Stage" + path + "/"; string pathTexture = pathDir + activeBattleStage.Layer.L0[j].Name; GameObject imgObject = Resources.Load <GameObject>("Prefab/Map"); GameObject obj = Instantiate(imgObject, transBackground); obj.name = activeBattleStage.Layer.L0[j].Name; float z = GameDefine.getZ(activeBattleStage.Layer.L0[j].Unknow0); Transform trans = obj.transform; trans.localPosition = new Vector3(0.0f, layerHeight, z); trans.localScale = new Vector3(1.0f, 1.0f, 1.0f); SpriteRenderer sprite = obj.GetComponent <SpriteRenderer>(); sprite.sprite = Resources.Load <Sprite>(pathTexture); float w = activeBattleStage.Layer.L0[j].Width * GameDefine.TEXTURE_WIDTH; float h = activeBattleStage.Layer.L0[j].Height * GameDefine.TEXTURE_HEIGHT; if (w > 4096 || h > 4096) { w = w / activeBattleStage.DTL.Width * GameDefine.TEXTURE_WIDTH; h = w / activeBattleStage.DTL.Height * GameDefine.TEXTURE_HEIGHT; trans.localScale = new Vector3(w, h, 1.0f); } if (activeBattleStage.Layer.L0[j].Unknow4 != 10 && activeBattleStage.Layer.L0[j].Unknow5 != 8) { if (GameUserData.instance.Stage == 18) { // fix stage 18 bug trans.localPosition = new Vector3(0.0f, layerHeight, 10.0f); } trans.localScale = new Vector3(lastWidth / w, lastHeight / h, 1.0f); } else { lastWidth = w; lastHeight = h; } objsLayer0[j] = obj; } } } if (objsLayer1 == null || objsLayer1.Length != activeBattleStage.Layer.L1.Length) { objsLayer1 = new GameObject[activeBattleStage.Layer.L1.Length]; } for (int j = 0; j < activeBattleStage.Layer.L1.Length; j++) { if (activeBattleStage.Layer.L1[j].ID != id) { continue; } string pathDir = "Prefab/Stage/Stage" + path + "/"; string pathTexture = pathDir + activeBattleStage.Layer.L1[j].Name; GameObject imgObject = Resources.Load <GameObject>(pathTexture); GameObject obj = Instantiate(imgObject, transBackground); obj.name = activeBattleStage.Layer.L1[j].Name; Transform trans = obj.transform; trans.localPosition = new Vector3(activeBattleStage.Layer.L1[j].OffsetX, -activeBattleStage.Layer.L1[j].OffsetY + layerHeight, -1000 - j); trans.localScale = new Vector3(1.0f, 1.0f, 1.0f); GameAnimation animation = obj.GetComponent <GameAnimation>(); if (activeBattleStage.Layer.L1[j].VisibleBattle == 0) { bool bVisible = true; if (activeBattleStage.Layer.L1[j].ParmEffect != GameDefine.INVALID_ID) { bVisible = GameUserData.instance.getGameData(activeBattleStage.Layer.L1[j].ParmEffect) > 0; } if (bVisible) { switch (activeBattleStage.Layer.L1[j].Pause) { case 0: animation.playAnimation(); break; case 1: animation.playAnimation(); // Debug.LogError( "activeBattleStage.Layer.L1[ j ].Pause" + j ); break; case 2: animation.playSound = false; animation.showFrame(0); animation.playSound = true; break; } } } // // 夏侯婴加入? // if ( GameUserData.instance.Stage == 28 && // activeBattleStage.Layer.L1[ j ].Parm == 7 ) // 8 // { // continue; // } // if ( GameUserData.instance.Stage == 29 && // activeBattleStage.Layer.L1[ j ].Parm == 1 ) // 3 // { // continue; // } objsLayer1[j] = obj; } #if UNITY_EDITOR if (id == 1) { GameBattleDTL dtl = activeBattleStage.DTL; int ii = 0; Sprite spriteObject = Resources.Load <Sprite>("White"); for (int i = 0; i < dtl.Height; i++) { for (int j = 0; j < dtl.Width; j++) { // editor test // return; GameObject imgObject = Resources.Load <GameObject>("Prefab/Sprite"); GameObject obj = Instantiate(imgObject, transCell); obj.name = i + "-" + j; Transform trans = obj.transform; trans.localPosition = new Vector3(j * 30, -i * 24 + layerHeight, 0.0f); // trans.localScale = new Vector3( 1.0f , 1.0f , 1.0f ); SpriteRenderer sprite = obj.GetComponent <SpriteRenderer>(); float c = (dtl.Points[ii].Move * 25) / 255.0f; sprite.color = new Color(c, c, c, (c > 0.25f ? 0.25f : c)); sprite.sprite = spriteObject; if (dtl.Points[ii].MapEvent != -1 && activeBattleStage.MEVT.Length > dtl.Points[ii].MapEvent) { if (activeBattleStage.MEVT[dtl.Points[ii].MapEvent].EventType == GameBattleMapEventType.Event) { sprite.color = new Color(0.0f, 1.0f, 0.0f, 0.25f); } else if (activeBattleStage.MEVT[dtl.Points[ii].MapEvent].EventType == GameBattleMapEventType.Item) { sprite.color = new Color(1.0f, 1.0f, 0.0f, 0.25f); } } GamePointTset test = obj.AddComponent <GamePointTset>(); test.Value0 = dtl.Points[ii].Move; test.Value1 = dtl.Points[ii].Floor; test.Value2 = dtl.Points[ii].MapEvent; // obj = Instantiate( imgObject , transUnit ); // obj.name = i + "-" + j; // // trans = obj.GetComponent<RectTransform>(); // trans.localPosition = new Vector3( j * 30 , -i * 24 , 0.0f ); // trans.localScale = new Vector3( 1.0f , 1.0f , 1.0f ); // trans.sizeDelta = new Vector2( 30 , 24 ); // // image = obj.GetComponent<Image>(); // image.enabled = false; ii++; } } } #endif }