forked from planetarium/libplanet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request planetarium#79 from Unengine/bugfix/ring-inventory…
…-notification Fix bug in ring notification condition.
- Loading branch information
Showing
3 changed files
with
209 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
namespace Lib9c.Tests.Model | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Libplanet; | ||
using Libplanet.Crypto; | ||
using Nekoyume; | ||
using Nekoyume.Action; | ||
using Nekoyume.Battle; | ||
using Nekoyume.Model.Item; | ||
using Nekoyume.Model.State; | ||
using Xunit; | ||
|
||
public class ItemNotificationTest | ||
{ | ||
private readonly Address _agentAddress; | ||
private readonly TableSheets _tableSheets; | ||
private readonly ItemSubType[] _itemSubTypesForEquipments | ||
= new ItemSubType[] | ||
{ | ||
ItemSubType.Weapon, | ||
ItemSubType.Armor, | ||
ItemSubType.Belt, | ||
ItemSubType.Necklace, | ||
ItemSubType.Ring, | ||
}; | ||
|
||
public ItemNotificationTest() | ||
{ | ||
var sheets = TableSheetsImporter.ImportSheets(); | ||
|
||
var privateKey = new PrivateKey(); | ||
_agentAddress = privateKey.PublicKey.ToAddress(); | ||
_tableSheets = new TableSheets(sheets); | ||
} | ||
|
||
[Fact] | ||
public void EquipItems() | ||
{ | ||
var avatarAddress = _agentAddress.Derive("avatar_1"); | ||
var avatarState = new AvatarState( | ||
avatarAddress, | ||
_agentAddress, | ||
0, | ||
_tableSheets.GetAvatarSheets(), | ||
new GameConfigState(), | ||
default | ||
); | ||
|
||
avatarState.level = GameConfig.RequireCharacterLevel.CharacterEquipmentSlotRing1; | ||
var equipmentList = new List<Guid>(); | ||
avatarState.EquipEquipments(equipmentList); | ||
|
||
var inventory = avatarState.inventory; | ||
var hasNotification = inventory.HasNotification(avatarState.level); | ||
// When inventory is empty. | ||
Assert.False(hasNotification); | ||
|
||
foreach (var type in _itemSubTypesForEquipments) | ||
{ | ||
var rows = _tableSheets.EquipmentItemSheet.Values | ||
.Where(r => r.ItemSubType == type && r.Grade == 1); | ||
foreach (var row in rows) | ||
{ | ||
var guid = Guid.NewGuid(); | ||
var equipment = (Equipment)ItemFactory.CreateItemUsable(row, guid, 0, 0); | ||
inventory.AddItem(equipment); | ||
} | ||
|
||
hasNotification = inventory.HasNotification(avatarState.level); | ||
// When all of the items are unequipped. | ||
Assert.True(hasNotification); | ||
|
||
var ordered = inventory.Equipments | ||
.Where(i => i.ItemSubType == type) | ||
.OrderBy(i => CPHelper.GetCP(i)); | ||
|
||
var weakest = ordered.First(); | ||
equipmentList.Add(weakest.ItemId); | ||
avatarState.EquipEquipments(equipmentList); | ||
hasNotification = inventory.HasNotification(avatarState.level); | ||
// When weakest item is equipped. | ||
Assert.True(hasNotification); | ||
|
||
equipmentList.Remove(weakest.ItemId); | ||
|
||
var strongest = ordered.Last(); | ||
equipmentList.Add(strongest.ItemId); | ||
avatarState.EquipEquipments(equipmentList); | ||
hasNotification = inventory.HasNotification(avatarState.level); | ||
// When strongest item is equipped. | ||
Assert.False(hasNotification); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void EquipTwoRings() | ||
{ | ||
var avatarAddress = _agentAddress.Derive("avatar_2"); | ||
var avatarState = new AvatarState( | ||
avatarAddress, | ||
_agentAddress, | ||
0, | ||
_tableSheets.GetAvatarSheets(), | ||
new GameConfigState(), | ||
default | ||
); | ||
|
||
avatarState.level = GameConfig.RequireCharacterLevel.CharacterEquipmentSlotRing2; | ||
var equipmentList = new List<Guid>(); | ||
avatarState.EquipEquipments(equipmentList); | ||
|
||
var inventory = avatarState.inventory; | ||
var hasNotification = inventory.HasNotification(avatarState.level); | ||
// When inventory is empty. | ||
Assert.False(hasNotification); | ||
|
||
var rows = _tableSheets.EquipmentItemSheet.Values | ||
.Where(r => r.ItemSubType == ItemSubType.Ring && r.Grade == 1); | ||
foreach (var row in rows) | ||
{ | ||
var guid = Guid.NewGuid(); | ||
var equipment = (Equipment)ItemFactory.CreateItemUsable(row, guid, 0, 0); | ||
inventory.AddItem(equipment); | ||
} | ||
|
||
hasNotification = inventory.HasNotification(avatarState.level); | ||
// When all of the items are unequipped. | ||
Assert.True(hasNotification); | ||
|
||
var ordered = inventory.Equipments.OrderBy(i => CPHelper.GetCP(i)); | ||
|
||
var strongest = ordered.Last(); | ||
equipmentList.Add(strongest.ItemId); | ||
avatarState.EquipEquipments(equipmentList); | ||
hasNotification = inventory.HasNotification(avatarState.level); | ||
// When one strongest ring is equipped. | ||
Assert.True(hasNotification); | ||
|
||
equipmentList.Clear(); | ||
|
||
var strongests = ordered.TakeLast(2).Select(i => i.ItemId); | ||
equipmentList.AddRange(strongests); | ||
avatarState.EquipEquipments(equipmentList); | ||
hasNotification = inventory.HasNotification(avatarState.level); | ||
// When the 1st strongest, the 2nd strongest items are equipped. | ||
Assert.False(hasNotification); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Nekoyume.Model.Item; | ||
using System.Collections.Generic; | ||
|
||
namespace Nekoyume | ||
{ | ||
public static class UnlockHelper | ||
{ | ||
public static List<(ItemSubType, int)> GetAvailableEquipmentSlots(int level) | ||
{ | ||
var availableSlots = new List<(ItemSubType, int)>(); | ||
|
||
if (level >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotWeapon) | ||
{ | ||
availableSlots.Add((ItemSubType.Weapon, 1)); | ||
} | ||
if (level >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotArmor) | ||
{ | ||
availableSlots.Add((ItemSubType.Armor, 1)); | ||
} | ||
if (level >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotBelt) | ||
{ | ||
availableSlots.Add((ItemSubType.Belt, 1)); | ||
} | ||
if (level >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotNecklace) | ||
{ | ||
availableSlots.Add((ItemSubType.Necklace, 1)); | ||
} | ||
if (level >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotRing1) | ||
{ | ||
if (level >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotRing2) | ||
{ | ||
availableSlots.Add((ItemSubType.Ring, 2)); | ||
} | ||
else | ||
{ | ||
availableSlots.Add((ItemSubType.Ring, 1)); | ||
} | ||
} | ||
|
||
return availableSlots; | ||
} | ||
} | ||
} |