string GetMapNodeText(MapNodeType nodeType) { switch (nodeType) { case MapNodeType.Start: return("The staircase you came down. You won't be going back that way."); case MapNodeType.Scenario: return("Ghouls, goblins, gold. Take and receive damage. Use mechanics for your pleasure."); case MapNodeType.Event: return("Could be good, could be bad. But one thing's for certain. It'll be good or bad."); case MapNodeType.Store: return("The fundament of commerce...the humble small business."); case MapNodeType.End: return("A staircase leading downward. The only apparent exit."); case MapNodeType.Boss: return("One of the guardians of this place."); default: Debug.LogError("Incompatible nodetype."); return("placeholder"); } }
// So we use the base table values, but modify based on how close we are to our wanted value public int GetGenerationChance(MapNodeType parent, MapNodeType current) { double percentageNodesUsed = (double)m_generatedNumberOfNodes / (double)m_wantedNumberOfNodes; double modifyAmount = Math.Abs((.5 - percentageNodesUsed) * 2) + 1; bool isAboveHalf = percentageNodesUsed > .5; switch (current) { case MapNodeType.None: if (isAboveHalf) return (int)(m_ratioTable[(int)parent, (int)current] * modifyAmount); else return (int)(m_ratioTable[(int)parent, (int)current] / modifyAmount); case MapNodeType.Hall: case MapNodeType.MainRoom: case MapNodeType.SideRoom: case MapNodeType.TreasureRoom: if (isAboveHalf) return (int)(m_ratioTable[(int)parent, (int)current] / modifyAmount); else return (int)(m_ratioTable[(int)parent, (int)current] * modifyAmount); } return m_ratioTable[(int)parent, (int)current]; }
//获取地图节点 private MapNodeBase GetMapNode(MapNodeType nodeType, int nodeIndex) { switch (nodeType) { case MapNodeType.NORMAL_ENEMY: return(new NormalEnemyNode(nodeIndex, 1)); //todo 随机普通怪ID case MapNodeType.ELITE: return(new EliteNode(nodeIndex, 1)); //todo 随机精英怪ID case MapNodeType.ADVANTURE: return(new AdvantureNode(nodeIndex)); case MapNodeType.SHOP: return(new ShopNode(nodeIndex)); case MapNodeType.BOX: return(new BoxNode(nodeIndex)); default: Debug.LogError("unhandle map node:" + nodeType); break; } return(null); }
public MapNode(MapNodeType _nodeType, int _layer) { nodeType = _nodeType; layer = _layer; children = new HashSet <MapNode>(); parents = new HashSet <MapNode>(); }
//根据步数随机生成节点 private MapNodeBase GetRandomNode(int step, int nodeIndex) { if (step == 1) //第一个节点是普通怪 { return(GetMapNode(MapNodeType.NORMAL_ENEMY, nodeIndex)); } List <MapNodeType> lstNodeType; if (step <= 5) //前5个节点只会是普通怪或者奇遇 { lstNodeType = new List <MapNodeType>() { MapNodeType.NORMAL_ENEMY, MapNodeType.ADVANTURE }; } else { lstNodeType = new List <MapNodeType>() { MapNodeType.NORMAL_ENEMY, MapNodeType.ADVANTURE }; TryAddNodeType(lstNodeType, MapNodeType.BOX, step); TryAddNodeType(lstNodeType, MapNodeType.ELITE, step); TryAddNodeType(lstNodeType, MapNodeType.SHOP, step); } MapNodeType nodeType = GetRandomNodeType(lstNodeType); return(GetMapNode(nodeType, nodeIndex)); }
MapNode GenerateNode(int layer, int index) { if (index == 0) { return(new MapNode(MapNodeType.Scenario, layer)); } else if (index == 1) { int typeDeterminant = rand.Next(1, 101); MapNodeType thisNodeType = MapNodeType.Event; if (typeDeterminant < secondNodeScenarioChance) { thisNodeType = MapNodeType.Scenario; } return(new MapNode(thisNodeType, layer)); } else { int typeDeterminant = rand.Next(1, 101); MapNodeType thisNodeType = MapNodeType.Event; if (typeDeterminant < thirdNodeScenarioChance) { thisNodeType = MapNodeType.Scenario; } return(new MapNode(thisNodeType, layer)); } }
public MapNodeType GetNewNode(MapNodeType parent) { List<MapNodeType> possibleList = new List<MapNodeType>(); foreach (MapNodeType t in MapNode.NodeTypes) { if (GetGenerationChance(parent, t) > 0) possibleList.Add(t); } if (possibleList.Count == 0) throw new System.InvalidOperationException("StitchRatio::GetNewNode with all zero values: " + parent.ToString()); int listLength = possibleList.Count; while (true) { MapNodeType attempt = possibleList[m_random.getInt(0, listLength - 1)]; if (m_random.Chance(GetGenerationChance(parent, attempt))) { if (attempt != MapNodeType.None) m_generatedNumberOfNodes++; return attempt; } } }
internal MapNode(MapNodeType type) { Neighbors = new List<MapNode>(); Type = type; Generated = false; Scratch = 0; UniqueID = nextUnqiueID; nextUnqiueID++; }
internal MapNode() { Neighbors = new List<MapNode>(); Type = MapNodeType.NoneGivenYet; Generated = false; Scratch = 0; UniqueID = nextUnqiueID; nextUnqiueID++; }
internal MapChunk(int width, int height, string typeString) { Width = width; Height = height; Seams = new List<Point>(); TreasureChests = new List<Point>(); Doors = new List<Point>(); Cosmetics = new List<Point>(); PlayerPosition = Point.Invalid; Type = (MapNodeType)Enum.Parse(typeof(MapNodeType), typeString, false); MapSegment = new MapTile[Width, Height]; }
//尝试加入节点类型 private void TryAddNodeType(List <MapNodeType> lstNodeType, MapNodeType nodeType, int step) { switch (nodeType) { case MapNodeType.NONE: case MapNodeType.NORMAL_ENEMY: case MapNodeType.ADVANTURE: //do nothing break; case MapNodeType.ELITE: if (_leftElitNum <= 0 && step - _lastElitStep >= 4) { return; } --_leftElitNum; _lastElitStep = step; lstNodeType.Add(MapNodeType.ELITE); break; case MapNodeType.SHOP: if (_leftShopNum <= 0 && step - _lastShopStep >= 7) { return; } --_leftShopNum; _lastShopStep = step; lstNodeType.Add(MapNodeType.SHOP); break; case MapNodeType.BOX: if (_leftBoxNum <= 0 && step - _lastBoxStep >= 7) { return; } --_leftBoxNum; _lastBoxStep = step; lstNodeType.Add(MapNodeType.BOX); break; default: Debug.LogError("unhandle add node type:" + nodeType); break; } }
private int NumberOfNeighborsToGenerate(MapNodeType current) { int neighbors = MapChunk.NumberOfNeighbors(current); switch (current) { case MapNodeType.None: case MapNodeType.Entrance: return neighbors; case MapNodeType.Hall: case MapNodeType.MainRoom: case MapNodeType.SideRoom: case MapNodeType.TreasureRoom: return neighbors - 1; case MapNodeType.NoneGivenYet: default: throw new ArgumentException("NumberOfNeighborsToGenerate - No valid number of neighbors"); } }
internal MapChunk(MapChunk chunk) { Width = chunk.Width; Height = chunk.Height; Seams = new List<Point>(chunk.Seams); TreasureChests = new List<Point>(chunk.TreasureChests); Doors = new List<Point>(chunk.Doors); Cosmetics = new List<Point>(chunk.Cosmetics); PlayerPosition = chunk.PlayerPosition; Type = chunk.Type; MapSegment = new MapTile[Width, Height]; for (int i = 0; i < Width; ++i) { for (int j = 0; j < Height; ++j) { MapSegment[i, j] = new MapTile(chunk.MapSegment[i, j]); } } }
public Battle(sortie_battle api, CombinedFleetType fleettype, MapNodeType battletype, ShipInBattle[] fleet1, ShipInBattle[] fleet2) { FleetType = fleettype; BattleType = battletype; Fleet1 = fleet1; Fleet2 = fleet2; bool isEnemyCombined = battletype == MapNodeType.Combined || battletype == MapNodeType.CombinedBOSS; if (api.api_formation != null) { FriendFormation = (Formation)api.api_formation[0]; EnemyFormation = (Formation)api.api_formation[1]; Direction = (Direction)api.api_formation[2]; } if (api.api_search != null) { FriendSearching = api.api_search[0]; EnemySearching = api.api_search[1]; } EnemyFleet = api.api_ship_ke .Select((x, i) => new ShipInBattle { Index = i + 1, IsEnemy = true, ShipInfo = Staff.Current.MasterData.ShipInfo[x], Level = api.api_ship_lv[i], Equipments = api.api_eSlot[i].Select(y => Staff.Current.MasterData.EquipInfo[y]).Where(y => y != null).Select(y => new EquipInBattle(y)).ToArray(), Firepower = api.api_eParam[i][0], Torpedo = api.api_eParam[i][1], AA = api.api_eParam[i][2], Armor = api.api_eParam[i][3] }) .ToArray(); EnemyFleet2 = api.api_ship_ke_combined? .Select((x, i) => new ShipInBattle { Index = i + 7, IsEnemy = true, ShipInfo = Staff.Current.MasterData.ShipInfo[x], Level = api.api_ship_lv_combined[i], Equipments = api.api_eSlot_combined[i].Select(y => Staff.Current.MasterData.EquipInfo[y]).Where(y => y != null).Select(y => new EquipInBattle(y)).ToArray(), Firepower = api.api_eParam_combined[i][0], Torpedo = api.api_eParam_combined[i][1], AA = api.api_eParam_combined[i][2], Armor = api.api_eParam_combined[i][3] }) .ToArray(); EnemyShipIds = api.api_ship_ke.ConcatNotNull(api.api_ship_ke_combined).ToArray(); SetHPs(Fleet1, api.api_f_nowhps, api.api_f_maxhps); SetHPs(EnemyFleet, api.api_e_nowhps, api.api_e_maxhps); SetHPs(Fleet2, api.api_f_nowhps_combined, api.api_f_maxhps_combined); SetHPs(EnemyFleet2, api.api_e_nowhps_combined, api.api_e_maxhps_combined); api.api_escape_idx?.ForEach(x => Fleet1[x - 1].IsEscaped = true); api.api_escape_idx_combined?.ForEach(x => Fleet2[x - 1].IsEscaped = true); if (api.api_n_support_info != null) { Support = new SupportAttack(this, api.api_n_support_info, api.api_n_support_flag); } if (api.api_n_hougeki1 != null) { NightToDay1 = new FireCombat(this, api.api_n_hougeki1); } if (api.api_n_hougeki2 != null) { NightToDay2 = new FireCombat(this, api.api_n_hougeki2); } if (api.api_air_base_injection != null) { AirBaseJet = new JetPlaneAttack(this, api.api_air_base_injection, true); } if (api.api_injection_kouku != null) { Jet = new JetPlaneAttack(this, api.api_injection_kouku, false); } if (api.api_air_base_attack != null) { AirBaseAttacks = api.api_air_base_attack.Select(x => new AirBaseAttack(this, x)).ToArray(); } if (api.api_kouku != null) { AirCombat1 = new AerialCombat(this, api.api_kouku); } if (api.api_kouku2 != null) { AirCombat2 = new AerialCombat(this, api.api_kouku2); } if (api.api_support_flag != 0) { Support = new SupportAttack(this, api.api_support_info, api.api_support_flag); } if (api.api_opening_taisen != null) { OpeningASW = new FireCombat(this, api.api_opening_taisen); } if (api.api_opening_atack != null) { OpeningTorpedo = new TorpedoCombat(this, api.api_opening_atack); } if (isEnemyCombined) { switch (fleettype) { case CombinedFleetType.None: if (api.api_hougeki1 != null) { FireStage1 = new FireCombat(this, api.api_hougeki1); } if (api.api_raigeki != null) { TorpedoStage = new TorpedoCombat(this, api.api_raigeki); } if (api.api_hougeki2 != null) { FireStage2 = new FireCombat(this, api.api_hougeki2); } if (api.api_hougeki3 != null) { FireStage3 = new FireCombat(this, api.api_hougeki3); } break; case CombinedFleetType.Carrier: case CombinedFleetType.Transport: if (api.api_hougeki1 != null) { FireStage1 = new FireCombat(this, api.api_hougeki1); } if (api.api_hougeki2 != null) { FireStage2 = new FireCombat(this, api.api_hougeki2); } if (api.api_raigeki != null) { TorpedoStage = new TorpedoCombat(this, api.api_raigeki); } if (api.api_hougeki3 != null) { FireStage3 = new FireCombat(this, api.api_hougeki3); } break; case CombinedFleetType.Surface: if (api.api_hougeki1 != null) { FireStage1 = new FireCombat(this, api.api_hougeki1); } if (api.api_hougeki2 != null) { FireStage2 = new FireCombat(this, api.api_hougeki2); } if (api.api_hougeki3 != null) { FireStage3 = new FireCombat(this, api.api_hougeki3); } if (api.api_raigeki != null) { TorpedoStage = new TorpedoCombat(this, api.api_raigeki); } break; } } else { switch (fleettype) { case CombinedFleetType.None: if (api.api_hougeki1 != null) { FireStage1 = new FireCombat(this, api.api_hougeki1); } if (api.api_hougeki2 != null) { FireStage2 = new FireCombat(this, api.api_hougeki2); } if (api.api_raigeki != null) { TorpedoStage = new TorpedoCombat(this, api.api_raigeki); } break; case CombinedFleetType.Carrier: case CombinedFleetType.Transport: if (api.api_hougeki1 != null) { FireStage1 = new FireCombat(this, api.api_hougeki1); } if (api.api_raigeki != null) { TorpedoStage = new TorpedoCombat(this, api.api_raigeki); } if (api.api_hougeki2 != null) { FireStage2 = new FireCombat(this, api.api_hougeki2); } if (api.api_hougeki3 != null) { FireStage3 = new FireCombat(this, api.api_hougeki3); } break; case CombinedFleetType.Surface: if (api.api_hougeki1 != null) { FireStage1 = new FireCombat(this, api.api_hougeki1); } if (api.api_hougeki2 != null) { FireStage2 = new FireCombat(this, api.api_hougeki2); } if (api.api_hougeki3 != null) { FireStage3 = new FireCombat(this, api.api_hougeki3); } if (api.api_raigeki != null) { TorpedoStage = new TorpedoCombat(this, api.api_raigeki); } break; } } if (api.api_hougeki != null || api.api_friendly_info != null) { NightBattle(api); } else { EndApplyBattle(); } }
public static int NumberOfNeighbors(MapNodeType current) { switch (current) { case MapNodeType.Entrance: return 4; case MapNodeType.Hall: return 2; case MapNodeType.MainRoom: case MapNodeType.SideRoom: case MapNodeType.TreasureRoom: return 4; case MapNodeType.None: return 0; case MapNodeType.NoneGivenYet: default: throw new ArgumentException("NumberOfNeighbors - No valid number of neighbors"); } }
public Battle(sortie_battle api, CombinedFleetType fleettype, MapNodeType battletype, BattleManager source) { FleetType = fleettype; BattleType = battletype; Fleet1 = (source.SortieFleet1?.Ships ?? Staff.Current.Homeport.Fleets[api.api_deck_id + api.api_dock_id].Ships) .Select(x => new ShipInBattle(x)).ToArray(); Fleet2 = source.SortieFleet2?.Ships .Select(x => new ShipInBattle(x)).ToArray(); if (source.SortieFleet1 == null)//演习 Staff.Current.Homeport.Fleets[api.api_deck_id + api.api_dock_id].Ships.ForEach(x => x.IgnoreNextCondition()); if (api.api_formation != null) { FriendFormation = (Formation)api.api_formation[0]; EnemyFormation = (Formation)api.api_formation[1]; Direction = (Direction)api.api_formation[2]; } bool iscombined = fleettype != CombinedFleetType.None; bool isenemycombined = battletype == MapNodeType.Combined || battletype == MapNodeType.CombinedBOSS; EnemyFleet = api.api_ship_ke.Where(x => x != -1) .Select((x, i) => new ShipInBattle { ShipInfo = Staff.Current.MasterData.ShipInfo[x], Level = api.api_ship_lv[i + 1], Equipments = api.api_eSlot[i].Select(y => Staff.Current.MasterData.EquipInfo[y]).Where(y => y != null).ToArray(), Firepower = api.api_eParam[i][0], Torpedo = api.api_eParam[i][1], AA = api.api_eParam[i][2], Armor = api.api_eParam[i][3] }) .ToArray(); EnemyFleet2 = api.api_ship_ke_combined?.Where(x => x != -1) .Select((x, i) => new ShipInBattle { ShipInfo = Staff.Current.MasterData.ShipInfo[x], Level = api.api_ship_lv_combined[i + 1], Equipments = api.api_eSlot_combined[i].Select(y => Staff.Current.MasterData.EquipInfo[y]).Where(y => y != null).ToArray(), Firepower = api.api_eParam_combined[i][0], Torpedo = api.api_eParam_combined[i][1], AA = api.api_eParam_combined[i][2], Armor = api.api_eParam_combined[i][3] }) .ToArray(); EnemyShipIds = api.api_ship_ke.Skip(1).ConcatNotNull(api.api_ship_ke_combined?.Skip(1)).ToArray(); Fleet1.ArrayZip(api.api_maxhps, 1, Delegates.SetMaxHP); Fleet2?.ArrayZip(api.api_maxhps_combined, 1, Delegates.SetMaxHP); EnemyFleet.ArrayZip(api.api_maxhps, 7, Delegates.SetMaxHP); EnemyFleet2?.ArrayZip(api.api_maxhps_combined, 7, Delegates.SetMaxHP); Fleet1.ArrayZip(api.api_nowhps, 1, Delegates.SetStartHP); Fleet2?.ArrayZip(api.api_nowhps_combined, 1, Delegates.SetStartHP); EnemyFleet.ArrayZip(api.api_nowhps, 7, Delegates.SetStartHP); EnemyFleet2?.ArrayZip(api.api_nowhps_combined, 7, Delegates.SetStartHP); api.api_escape_idx?.ForEach(x => Fleet1[x - 1].IsEscaped = true); api.api_escape_idx_combined?.ForEach(x => Fleet2[x - 1].IsEscaped = true); AirCombat1 = AirBattle(api.api_kouku, false); AirCombat2 = AirBattle(api.api_kouku2, false); AirBaseAttack(api.api_air_base_attack); SupportAttack(api.api_support_info); FireAttack(api.api_opening_taisen, NightOrTorpedo); if (isenemycombined) ECTorpedoAttack(api.api_opening_atack); else TorpedoAttack(api.api_opening_atack); if (isenemycombined) { ECFireAttack(api.api_hougeki1); ECFireAttack(api.api_hougeki2); ECFireAttack(api.api_hougeki3); } else switch (fleettype) { case CombinedFleetType.None: FireAttack(api.api_hougeki1, Fleet1); FireAttack(api.api_hougeki2, Fleet1); break; case CombinedFleetType.Carrier: case CombinedFleetType.Transport: FireAttack(api.api_hougeki1, Fleet2); FireAttack(api.api_hougeki2, Fleet1); FireAttack(api.api_hougeki3, Fleet1); break; case CombinedFleetType.Surface: FireAttack(api.api_hougeki1, Fleet1); FireAttack(api.api_hougeki2, Fleet1); FireAttack(api.api_hougeki3, Fleet2); break; } if (isenemycombined) ECTorpedoAttack(api.api_raigeki); else TorpedoAttack(api.api_raigeki); NightBattle(api); }
public Battle(sortie_battle api, CombinedFleetType fleettype, MapNodeType battletype, BattleManager source) { FleetType = fleettype; BattleType = battletype; Fleet1 = (source.SortieFleet1?.Ships ?? Staff.Current.Homeport.Fleets[api.api_deck_id + api.api_dock_id].Ships) .Select(x => new ShipInBattle(x)).ToArray(); Fleet2 = source.SortieFleet2?.Ships .Select(x => new ShipInBattle(x)).ToArray(); if (source.SortieFleet1 == null)//演习 { Staff.Current.Homeport.Fleets[api.api_deck_id + api.api_dock_id].Ships.ForEach(x => x.IgnoreNextCondition()); } if (api.api_formation != null) { FriendFormation = (Formation)api.api_formation[0]; EnemyFormation = (Formation)api.api_formation[1]; Direction = (Direction)api.api_formation[2]; } bool iscombined = fleettype != CombinedFleetType.None; bool isenemycombined = battletype == MapNodeType.Combined || battletype == MapNodeType.CombinedBOSS; EnemyFleet = api.api_ship_ke.Where(x => x != -1) .Select((x, i) => new ShipInBattle { ShipInfo = Staff.Current.MasterData.ShipInfo[x], Level = api.api_ship_lv[i + 1], Equipments = api.api_eSlot[i].Select(y => Staff.Current.MasterData.EquipInfo[y]).Where(y => y != null).ToArray(), Firepower = api.api_eParam[i][0], Torpedo = api.api_eParam[i][1], AA = api.api_eParam[i][2], Armor = api.api_eParam[i][3] }) .ToArray(); EnemyFleet2 = api.api_ship_ke_combined?.Where(x => x != -1) .Select((x, i) => new ShipInBattle { ShipInfo = Staff.Current.MasterData.ShipInfo[x], Level = api.api_ship_lv_combined[i + 1], Equipments = api.api_eSlot_combined[i].Select(y => Staff.Current.MasterData.EquipInfo[y]).Where(y => y != null).ToArray(), Firepower = api.api_eParam_combined[i][0], Torpedo = api.api_eParam_combined[i][1], AA = api.api_eParam_combined[i][2], Armor = api.api_eParam_combined[i][3] }) .ToArray(); EnemyShipIds = api.api_ship_ke.Skip(1).ConcatNotNull(api.api_ship_ke_combined?.Skip(1)).ToArray(); Fleet1.ArrayZip(api.api_maxhps, 1, Delegates.SetMaxHP); Fleet2?.ArrayZip(api.api_maxhps_combined, 1, Delegates.SetMaxHP); EnemyFleet.ArrayZip(api.api_maxhps, 7, Delegates.SetMaxHP); EnemyFleet2?.ArrayZip(api.api_maxhps_combined, 7, Delegates.SetMaxHP); Fleet1.ArrayZip(api.api_nowhps, 1, Delegates.SetStartHP); Fleet2?.ArrayZip(api.api_nowhps_combined, 1, Delegates.SetStartHP); EnemyFleet.ArrayZip(api.api_nowhps, 7, Delegates.SetStartHP); EnemyFleet2?.ArrayZip(api.api_nowhps_combined, 7, Delegates.SetStartHP); api.api_escape_idx?.ForEach(x => Fleet1[x - 1].IsEscaped = true); api.api_escape_idx_combined?.ForEach(x => Fleet2[x - 1].IsEscaped = true); JetAttack(api.api_air_base_injection); JetAttack(api.api_injection_kouku); AirBaseAttack(api.api_air_base_attack); AirCombat1 = AirBattle(api.api_kouku, false); AirCombat2 = AirBattle(api.api_kouku2, false); SupportAttack(api.api_support_info); FireAttack(api.api_opening_taisen, NightOrTorpedo); if (isenemycombined) { ECTorpedoAttack(api.api_opening_atack); } else { TorpedoAttack(api.api_opening_atack); } if (isenemycombined) { ECFireAttack(api.api_hougeki1); ECFireAttack(api.api_hougeki2); ECFireAttack(api.api_hougeki3); } else { switch (fleettype) { case CombinedFleetType.None: FireAttack(api.api_hougeki1, Fleet1); FireAttack(api.api_hougeki2, Fleet1); break; case CombinedFleetType.Carrier: case CombinedFleetType.Transport: FireAttack(api.api_hougeki1, Fleet2); FireAttack(api.api_hougeki2, Fleet1); FireAttack(api.api_hougeki3, Fleet1); break; case CombinedFleetType.Surface: FireAttack(api.api_hougeki1, Fleet1); FireAttack(api.api_hougeki2, Fleet1); FireAttack(api.api_hougeki3, Fleet2); break; } } if (isenemycombined) { ECTorpedoAttack(api.api_raigeki); } else { TorpedoAttack(api.api_raigeki); } NightBattle(api); }
public static Sprite GetMapNodeImage(MapNodeType nodeType) { return(instance.mapNodeImages[nodeType]); }
public static bool IsBOSS(this MapNodeType node) => node == MapNodeType.BOSS || node == MapNodeType.CombinedBOSS;
public Battle(sortie_battle api, CombinedFleetType fleettype, MapNodeType battletype, ShipInBattle[] fleet1, ShipInBattle[] fleet2) { FleetType = fleettype; BattleType = battletype; Fleet1 = fleet1; Fleet2 = fleet2; if (api.api_formation != null) { FriendFormation = (Formation)api.api_formation[0]; EnemyFormation = (Formation)api.api_formation[1]; Direction = (Direction)api.api_formation[2]; } if (api.api_search != null) { FriendSearching = api.api_search[0]; EnemySearching = api.api_search[1]; } bool iscombined = fleettype != CombinedFleetType.None; bool isenemycombined = battletype == MapNodeType.Combined || battletype == MapNodeType.CombinedBOSS; EnemyFleet = api.api_ship_ke.Where(x => x != -1) .Select((x, i) => new ShipInBattle { Index = i + 1, IsEnemy = true, ShipInfo = Staff.Current.MasterData.ShipInfo[x], Level = api.api_ship_lv[i + 1], Equipments = api.api_eSlot[i].Select(y => Staff.Current.MasterData.EquipInfo[y]).Where(y => y != null).Select(y => new EquipInBattle(y)).ToArray(), Firepower = api.api_eParam[i][0], Torpedo = api.api_eParam[i][1], AA = api.api_eParam[i][2], Armor = api.api_eParam[i][3] }) .ToArray(); EnemyFleet2 = api.api_ship_ke_combined?.Where(x => x != -1) .Select((x, i) => new ShipInBattle { Index = i + 7, IsEnemy = true, ShipInfo = Staff.Current.MasterData.ShipInfo[x], Level = api.api_ship_lv_combined[i + 1], Equipments = api.api_eSlot_combined[i].Select(y => Staff.Current.MasterData.EquipInfo[y]).Where(y => y != null).Select(y => new EquipInBattle(y)).ToArray(), Firepower = api.api_eParam_combined[i][0], Torpedo = api.api_eParam_combined[i][1], AA = api.api_eParam_combined[i][2], Armor = api.api_eParam_combined[i][3] }) .ToArray(); EnemyShipIds = api.api_ship_ke.Skip(1).ConcatNotNull(api.api_ship_ke_combined?.Skip(1)).ToArray(); void SetHPs(ShipInBattle[] fleet, int index, int[] hps, int[] maxhps) { if (fleet == null) { return; } for (int i = 0; i < fleet.Length; i++) { var ship = fleet[i]; ship.MaxHP = maxhps[i + index]; ship.FromHP = ship.ToHP = hps[i + index]; } } SetHPs(Fleet1, 1, api.api_nowhps, api.api_maxhps); SetHPs(EnemyFleet, 7, api.api_nowhps, api.api_maxhps); SetHPs(Fleet2, 1, api.api_nowhps_combined, api.api_maxhps_combined); SetHPs(EnemyFleet2, 7, api.api_nowhps_combined, api.api_maxhps_combined); api.api_escape_idx?.ForEach(x => Fleet1[x - 1].IsEscaped = true); api.api_escape_idx_combined?.ForEach(x => Fleet2[x - 1].IsEscaped = true); if (api.api_air_base_injection != null) { AirBaseJet = new JetPlaneAttack(this, api.api_air_base_injection, true); } if (api.api_injection_kouku != null) { Jet = new JetPlaneAttack(this, api.api_injection_kouku, false); } if (api.api_air_base_attack != null) { AirBaseAttacks = api.api_air_base_attack.Select(x => new AirBaseAttack(this, x)).ToArray(); } if (api.api_kouku != null) { AirCombat1 = new AerialCombat(this, api.api_kouku); } if (api.api_kouku2 != null) { AirCombat2 = new AerialCombat(this, api.api_kouku2); } if (api.api_support_flag != 0) { Support = new SupportAttack(this, api.api_support_info, api.api_support_flag); } if (isenemycombined) { if (api.api_opening_taisen != null) { OpeningASW = new ECFireCombat(this, api.api_opening_taisen); } if (api.api_opening_atack != null) { OpeningTorpedo = new ECTorpedoCombat(this, api.api_opening_atack); } if (api.api_hougeki1 != null) { FireStage1 = new ECFireCombat(this, api.api_hougeki1); } if (api.api_hougeki2 != null) { FireStage2 = new ECFireCombat(this, api.api_hougeki2); } if (api.api_hougeki3 != null) { FireStage3 = new ECFireCombat(this, api.api_hougeki3); } if (api.api_raigeki != null) { TorpedoStage = new ECTorpedoCombat(this, api.api_raigeki); } } else { if (api.api_opening_taisen != null) { OpeningASW = new FireCombat(api.api_opening_taisen, NightOrTorpedo, EnemyFleet); } if (api.api_opening_atack != null) { OpeningTorpedo = new TorpedoCombat(api.api_opening_atack, NightOrTorpedo, EnemyFleet); } switch (fleettype) { case CombinedFleetType.None: if (api.api_hougeki1 != null) { FireStage1 = new FireCombat(api.api_hougeki1, Fleet1, EnemyFleet); } if (api.api_hougeki2 != null) { FireStage2 = new FireCombat(api.api_hougeki2, Fleet1, EnemyFleet); } break; case CombinedFleetType.Carrier: case CombinedFleetType.Transport: if (api.api_hougeki1 != null) { FireStage1 = new FireCombat(api.api_hougeki1, Fleet2, EnemyFleet); } if (api.api_hougeki2 != null) { FireStage2 = new FireCombat(api.api_hougeki2, Fleet1, EnemyFleet); } if (api.api_hougeki3 != null) { FireStage3 = new FireCombat(api.api_hougeki3, Fleet1, EnemyFleet); } break; case CombinedFleetType.Surface: if (api.api_hougeki1 != null) { FireStage1 = new FireCombat(api.api_hougeki1, Fleet1, EnemyFleet); } if (api.api_hougeki2 != null) { FireStage2 = new FireCombat(api.api_hougeki2, Fleet1, EnemyFleet); } if (api.api_hougeki3 != null) { FireStage3 = new FireCombat(api.api_hougeki3, Fleet2, EnemyFleet); } break; } if (api.api_raigeki != null) { TorpedoStage = new TorpedoCombat(api.api_raigeki, NightOrTorpedo, EnemyFleet); } } if (api.api_hougeki != null) { NightBattle(api); } else { EndApplyBattle(); } }
/// <summary> /// Loads the specified file name. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns>The map.</returns> /// <exception cref="FileFormatException"></exception> /// <exception cref="ArgumentOutOfRangeException"></exception> private WorldMap Load(string fileName) { string workingFolder = Path.GetDirectoryName(fileName); OpenFile(fileName); // File version Reader.ReadUInt32(); // Initialize InitializeRoot(); if (Reader.ReadByte() != NodeTags.StartTag) { throw new FileFormatException("Could not find start node."); } //if (!ParseNode(Root)) // throw new FileFormatException("Could not parse root node."); // TODO: This should probably throw an exception if the return is 'false'(?) ParseNode(Root); Node node = GetRootNode(); if (!ReadProperty(node, out MapStreamReader mapPropertyReader)) { throw new FileFormatException("Could not parse root node properties."); } // First byte of OTB is 0 // TODO: Use propertyReader.Skip(byte.size); - byte.size is unknown mapPropertyReader.ReadByte(); MapMetadata metadata = mapPropertyReader.ReadMetadata(); if (metadata == null) { throw new FileFormatException("Could not read OTBM metadata."); } WorldMap map = new WorldMap { Width = metadata.Width, Height = metadata.Height }; node = node.Child; if ((MapNodeType)node.Type != MapNodeType.MapData) { throw new FileFormatException("Could not find map data node."); } if (!ReadProperty(node, out mapPropertyReader)) { throw new FileFormatException("Could not parse OTBM attribute."); } while (mapPropertyReader.PeekChar() != -1) { MapAttribute attribute = (MapAttribute)mapPropertyReader.ReadByte(); switch (attribute) { case MapAttribute.Description: map.Description = mapPropertyReader.ReadString(); break; case MapAttribute.ExtSpawnFile: string spawnFile = mapPropertyReader.ReadString(); map.SpawnFile = Path.Combine(workingFolder, spawnFile); break; case MapAttribute.ExtHouseFile: string houseFile = mapPropertyReader.ReadString(); map.HouseFile = Path.Combine(workingFolder, houseFile); break; default: throw new ArgumentException($"OTBM attribute '{attribute}' is not supported."); } } Node childNode = node.Child; while (childNode != null) { MapNodeType nodeType = (MapNodeType)childNode.Type; switch (nodeType) { case MapNodeType.Tiles: if (!ParseTiles(childNode, out IDictionary <IVector3, ITile> tiles)) { throw new FileFormatException("Could not parse tiles."); } map.Tiles.AddRange(tiles); break; case MapNodeType.Towns: if (!TryParseTowns(childNode, out IDictionary <uint, ITown> towns)) { throw new FileFormatException("Could not parse towns."); } map.Towns.AddRange(towns); break; case MapNodeType.Waypoints: if (!TryParseWaypoints(childNode, out IDictionary <string, IWaypoint> waypoints)) { throw new FileFormatException("Could not parse waypoints."); } map.Waypoints.AddRange(waypoints); break; default: throw new ArgumentOutOfRangeException(nameof(nodeType), nodeType, "OTBM node type is not supported."); } childNode = childNode.Next; } return(map); }
public MapNodeBase(MapNodeType nodeType, int nodeIndex) { this.nodeType = nodeType; this.nodeIndex = nodeIndex; }
private static void AddNeighborsToNode(MapNode parent, MapNodeType type, Queue<MapNode> nodeQueue) { MapNode neightbor = new MapNode(type); parent.AddNeighbor(neightbor); neightbor.AddNeighbor(parent); nodeQueue.Enqueue(neightbor); }
public MapNode(int row, int col, MapNodeType type) { m_row = row; m_col = col; m_type = type; }