Skip to content

Commit

Permalink
Merge pull request #2652 from planetarium/bugfix/adv-boss/add-breakth…
Browse files Browse the repository at this point in the history
…rough-floor

Use floorId to add breakthrough event
  • Loading branch information
U-lis authored Jun 26, 2024
2 parents dcb0c0f + f439a3c commit 9ded8e4
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 36 deletions.
46 changes: 30 additions & 16 deletions .Lib9c.Tests/Model/AdventureBoss/AdventureBossSimulatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Lib9c.Tests.Model.AdventureBoss
using Lib9c.Tests.Action;
using Libplanet.Action;
using Nekoyume.Battle.AdventureBoss;
using Nekoyume.Data;
using Nekoyume.Model.BattleStatus;
using Nekoyume.Model.BattleStatus.AdventureBoss;
using Nekoyume.Model.EnumType;
Expand Down Expand Up @@ -92,22 +91,31 @@ public AdventureBossSimulator Simulate()
}

[Theory]
[InlineData(true, 1, 1)]
[InlineData(true, 1, 5)]
[InlineData(true, 1, 3)]
[InlineData(false, 1, 1)]
[InlineData(false, 1, 5)]
[InlineData(false, 1, 3)]
[InlineData(false, 21, 23)] // For Boss ID 2
public void AddBreakthrough(bool simulate, int firstFloorId, int lastFloorId)
[InlineData(true, 1, 1, 1)]
[InlineData(true, 1, 1, 5)]
[InlineData(true, 1, 1, 3)]
[InlineData(false, 1, 1, 1)]
[InlineData(false, 1, 1, 5)]
[InlineData(false, 1, 1, 3)]
[InlineData(true, 2, 1, 1)]
[InlineData(true, 2, 1, 5)]
[InlineData(true, 2, 1, 3)]
[InlineData(false, 2, 1, 1)]
[InlineData(false, 2, 1, 5)]
[InlineData(false, 2, 1, 3)]
public void AddBreakthrough(bool simulate, int bossId, int fristFloor, int lastFloor)
{
AdventureBossSimulator simulator;
var floorRows = _tableSheets.AdventureBossFloorSheet.Values
.Where(row => row.AdventureBossId == bossId).ToList();

if (simulate)
{
simulator = Simulate();
}
else
{
var floorId = floorRows.First(row => row.Floor == lastFloor).Id;
var adventureBossData = _tableSheets.AdventureBossSheet.Values.First();
var row = _tableSheets.CostumeStatSheet.Values.First(
r => r.StatType == StatType.ATK);
Expand All @@ -118,20 +126,20 @@ public void AddBreakthrough(bool simulate, int firstFloorId, int lastFloorId)

simulator = new AdventureBossSimulator(
adventureBossData.BossId,
1,
floorId,
_random,
_avatarState,
new List<Guid>(),
new AllRuneState(),
new RuneSlotState(BattleType.Adventure),
_tableSheets.AdventureBossFloorSheet[lastFloorId],
_tableSheets.AdventureBossFloorWaveSheet[lastFloorId],
_tableSheets.AdventureBossFloorSheet[floorId],
_tableSheets.AdventureBossFloorWaveSheet[floorId],
_tableSheets.GetSimulatorSheets(),
_tableSheets.EnemySkillSheet,
_tableSheets.CostumeStatSheet,
AdventureBossSimulator.GetWaveRewards(
_random,
_tableSheets.AdventureBossFloorSheet[1],
_tableSheets.AdventureBossFloorSheet[floorId],
_tableSheets.MaterialItemSheet
),
new List<StatModifier>
Expand All @@ -142,17 +150,23 @@ public void AddBreakthrough(bool simulate, int firstFloorId, int lastFloorId)
);
}

simulator.AddBreakthrough(firstFloorId, lastFloorId, _tableSheets.AdventureBossFloorWaveSheet);
var floorIdList = new List<int>();
for (var fl = fristFloor; fl <= lastFloor; fl++)
{
floorIdList.Add(floorRows.First(row => row.Floor == fl).Id);
}

simulator.AddBreakthrough(floorIdList, _tableSheets.AdventureBossFloorWaveSheet);

Assert.Equal(typeof(SpawnPlayer), simulator.Log.events.First().GetType());
if (!simulate)
{
// +2: 1 for last floor, 1 for SpawnPlayer
Assert.Equal(lastFloorId - firstFloorId + 2, simulator.Log.events.Count);
Assert.Equal(lastFloor - fristFloor + 2, simulator.Log.events.Count);
}

var filtered = simulator.Log.events.OfType<Breakthrough>();
Assert.Equal(lastFloorId - firstFloorId + 1, filtered.Count());
Assert.Equal(lastFloor - fristFloor + 1, filtered.Count());

if (simulate)
{
Expand Down
20 changes: 11 additions & 9 deletions Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using Nekoyume.Action.Exceptions.AdventureBoss;
using Nekoyume.Battle;
using Nekoyume.Battle.AdventureBoss;
using Nekoyume.Data;
using Nekoyume.Exceptions;
using Nekoyume.Extensions;
using Nekoyume.Helper;
using Nekoyume.Model.AdventureBoss;
Expand Down Expand Up @@ -243,7 +241,7 @@ public override IWorld Execute(IActionContext context)

AdventureBossSimulator simulator = null;
var firstFloorId = 0;
var lastFloorId = 0;
var floorIdList = new List<int>();

// Claim floors from last failed
var exploreAp = sheets.GetSheet<AdventureBossSheet>().OrderedList
Expand All @@ -260,7 +258,6 @@ public override IWorld Execute(IActionContext context)
if (firstFloorId == 0)
{
firstFloorId = floorRow.Id;
lastFloorId = firstFloorId;
}

var rewards =
Expand All @@ -278,10 +275,10 @@ public override IWorld Execute(IActionContext context)

simulator = new AdventureBossSimulator(
bossId: latestSeason.BossId,
floorId: fl,
floorId: floorRow.Id,
random,
avatarState,
fl == firstFloorId ? Foods : new List<Guid>(),
floorRow.Id == firstFloorId ? Foods : new List<Guid>(),
runeStates,
runeSlotState,
floorRow,
Expand All @@ -297,7 +294,6 @@ public override IWorld Execute(IActionContext context)
);

simulator.Simulate();
lastFloorId = floorRow.Id;

// Get Reward if cleared
if (simulator.Log.IsClear)
Expand Down Expand Up @@ -331,16 +327,22 @@ public override IWorld Execute(IActionContext context)
selected.ItemId,
random.Next(selected.Min, selected.Max + 1))
);

// Add floorId for breakthrough
if (fl < explorer.MaxFloor + 1)
{
floorIdList.Add(floorRow.Id);
}
}
else
{
break;
}
}

if (simulator is not null && simulator.LogEvent && lastFloorId > firstFloorId)
if (simulator is not null && simulator.LogEvent && floorIdList.Count > 0)
{
simulator.AddBreakthrough(firstFloorId, lastFloorId, floorWaveSheet);
simulator.AddBreakthrough(floorIdList, floorWaveSheet);
}

states = AdventureBossHelper.AddExploreRewards(
Expand Down
11 changes: 8 additions & 3 deletions Lib9c/Action/AdventureBoss/SweepAdventureBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,21 @@ public override IWorld Execute(IActionContext context)
var adventureBossId = states.GetSheet<AdventureBossSheet>().OrderedList
.First(row => row.BossId == latestSeason.BossId).Id;
var floorRows = states.GetSheet<AdventureBossFloorSheet>().OrderedList
.Where(row => row.AdventureBossId == adventureBossId);
.Where(row => row.AdventureBossId == adventureBossId).ToList();
var firstFloorId = floorRows.First(r => r.Floor == 1).Id;
var floorId = floorRows.First(r => r.Floor == explorer.Floor).Id;

var simulator = new AdventureBossSimulator(
latestSeason.BossId, floorId, context.GetRandom(),
avatarState, sheets.GetSimulatorSheets(), logEvent: false
);
simulator.AddBreakthrough(firstFloorId, floorId,
sheets.GetSheet<AdventureBossFloorWaveSheet>());
var floorIdList = new List<int>();
for (var fl = 1; fl <= explorer.MaxFloor; fl++)
{
floorIdList.Add(floorRows.First(row => row.Floor == fl).Id);
}

simulator.AddBreakthrough(floorIdList, sheets.GetSheet<AdventureBossFloorWaveSheet>());

// Add point, reward
var point = 0;
Expand Down
4 changes: 2 additions & 2 deletions Lib9c/Battle/AdventureBoss/AdventureBossSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public Player Simulate()
return Player;
}

public void AddBreakthrough(int firstFloorId, int lastFloorId,
public void AddBreakthrough(IEnumerable<int> floorIdList,
AdventureBossFloorWaveSheet adventureBossFloorWaveSheet)
{
if (Log.events.Count == 0)
Expand All @@ -255,7 +255,7 @@ public void AddBreakthrough(int firstFloorId, int lastFloorId,
}

// Add event in reversed order to keep insert position
for (var floorId = lastFloorId; floorId >= firstFloorId; floorId--)
foreach (var floorId in floorIdList)
{
var floorWave = adventureBossFloorWaveSheet[floorId].Waves[0];
Log.events.Insert(1, new Breakthrough(Player, floorId, floorWave.Monsters));
Expand Down
8 changes: 4 additions & 4 deletions Lib9c/Model/BattleStatus/AdventureBoss/Breakthrough.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ namespace Nekoyume.Model.BattleStatus.AdventureBoss
[Serializable]
public class Breakthrough : EventBase
{
public readonly int Floor;
public readonly int FloorId;
public readonly List<AdventureBossFloorWaveSheet.MonsterData> Monsters;

public Breakthrough(CharacterBase character, int floor,
public Breakthrough(CharacterBase character, int floorId,
List<AdventureBossFloorWaveSheet.MonsterData> monsters
) : base(character)
{
Floor = floor;
FloorId = floorId;
Monsters = monsters;
}

public override IEnumerator CoExecute(IStage stage)
{
yield return stage.CoBreakthrough((Player)Character, Floor, Monsters);
yield return stage.CoBreakthrough((Player)Character, FloorId, Monsters);
}
}
}
3 changes: 1 addition & 2 deletions Lib9c/Model/IStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using Nekoyume.Model.BattleStatus;
using Nekoyume.Model.Item;
using Nekoyume.TableData;
using Nekoyume.TableData.AdventureBoss;

namespace Nekoyume.Model
Expand Down Expand Up @@ -37,7 +36,7 @@ public interface IStage
IEnumerator CoCustomEvent(CharacterBase character, EventBase eventBase);

#region AdvetureBoss
IEnumerator CoBreakthrough(CharacterBase character, int floor, List<AdventureBossFloorWaveSheet.MonsterData> monsters);
IEnumerator CoBreakthrough(CharacterBase character, int floorId, List<AdventureBossFloorWaveSheet.MonsterData> monsters);
IEnumerator CoStageBuff(CharacterBase affected, int skillId, IEnumerable<BattleStatus.Skill.SkillInfo> skillInfos, IEnumerable<BattleStatus.Skill.SkillInfo> buffInfos);
#endregion
}
Expand Down

0 comments on commit 9ded8e4

Please sign in to comment.