Skip to content

Commit

Permalink
Merge pull request #970 from planetarium/bug-fix/enter-invalid-stage
Browse files Browse the repository at this point in the history
Bug fix/enter invalid stage
  • Loading branch information
boscohyun authored Nov 18, 2021
2 parents fb8cca9 + e9877d1 commit fc121cf
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 53 deletions.
61 changes: 31 additions & 30 deletions nekoyume/Assets/_Scripts/Game/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
using UnityEngine.Serialization;
using Menu = Nekoyume.UI.Menu;


namespace Nekoyume.Game
{
using Nekoyume.GraphQL;
Expand Down Expand Up @@ -440,6 +439,7 @@ private void QuitWithAgentConnectionError(RPCAgent rpcAgent)
);
}

// FIXME: Leave one between this or CoSyncTableSheets()
private IEnumerator CoInitializeTableSheets()
{
yield return null;
Expand All @@ -461,6 +461,36 @@ private IEnumerator CoInitializeTableSheets()
TableSheets = new TableSheets(csv);
}

// FIXME: Leave one between this or CoInitializeTableSheets()
private IEnumerator CoSyncTableSheets()
{
yield return null;
var request =
Resources.LoadAsync<AddressableAssetsContainer>(AddressableAssetsContainerPath);
yield return request;
if (!(request.asset is AddressableAssetsContainer addressableAssetsContainer))
{
throw new FailedToLoadResourceException<AddressableAssetsContainer>(
AddressableAssetsContainerPath);
}

var task = Task.Run(() =>
{
List<TextAsset> csvAssets = addressableAssetsContainer.tableCsvAssets;
var csv = new ConcurrentDictionary<string, string>();
Parallel.ForEach(csvAssets, asset =>
{
if (Agent.GetState(Addresses.TableSheet.Derive(asset.name)) is Text tableCsv)
{
var table = tableCsv.ToDotnetString();
csv[asset.name] = table;
}
});
TableSheets = new TableSheets(csv);
});
yield return new WaitUntil(() => task.IsCompleted);
}

public static IDictionary<string, string> GetTableCsvAssets()
{
var container =
Expand Down Expand Up @@ -690,35 +720,6 @@ public void ResetKeyStore()
confirm.Show("UI_CONFIRM_RESET_KEYSTORE_TITLE", "UI_CONFIRM_RESET_KEYSTORE_CONTENT");
}

private IEnumerator CoSyncTableSheets()
{
yield return null;
var request =
Resources.LoadAsync<AddressableAssetsContainer>(AddressableAssetsContainerPath);
yield return request;
if (!(request.asset is AddressableAssetsContainer addressableAssetsContainer))
{
throw new FailedToLoadResourceException<AddressableAssetsContainer>(
AddressableAssetsContainerPath);
}

var task = Task.Run(() =>
{
List<TextAsset> csvAssets = addressableAssetsContainer.tableCsvAssets;
var csv = new ConcurrentDictionary<string, string>();
Parallel.ForEach(csvAssets, asset =>
{
if (Agent.GetState(Addresses.TableSheet.Derive(asset.name)) is Text tableCsv)
{
var table = tableCsv.ToDotnetString();
csv[asset.name] = table;
}
});
TableSheets = new TableSheets(csv);
});
yield return new WaitUntil(() => task.IsCompleted);
}

private async void UploadLog(string logString, string stackTrace, LogType type)
{
// Avoid NRE
Expand Down
99 changes: 78 additions & 21 deletions nekoyume/Assets/_Scripts/UI/Widget/StageInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,42 @@ public enum StageType
Quest,
Mimisbrunnr,
}
[SerializeField] private HelpButton stageHelpButton = null;
[SerializeField] private TextMeshProUGUI titleText = null;
[SerializeField] private TextMeshProUGUI monstersAreaText = null;
[SerializeField] private List<VanillaCharacterView> monstersAreaCharacterViews = null;
[SerializeField] private TextMeshProUGUI rewardsAreaText = null;
[SerializeField] private List<StageRewardItemView> rewardsAreaItemViews = null;
[SerializeField]private TextMeshProUGUI expText = null;
[SerializeField]private TextMeshProUGUI closeButtonText = null;
[SerializeField] private SubmitButton submitButton = null;
[SerializeField] private WorldMapWorld world = null;
[SerializeField] private GameObject buttonNotification = null;
[SerializeField] private Button closeButton;

[SerializeField]
private HelpButton stageHelpButton;

[SerializeField]
private TextMeshProUGUI titleText;

[SerializeField]
private TextMeshProUGUI monstersAreaText;

[SerializeField]
private List<VanillaCharacterView> monstersAreaCharacterViews;

[SerializeField]
private TextMeshProUGUI rewardsAreaText;

[SerializeField]
private List<StageRewardItemView> rewardsAreaItemViews;

[SerializeField]
private TextMeshProUGUI expText;

[SerializeField]
private TextMeshProUGUI closeButtonText;

[SerializeField]
private SubmitButton submitButton;

[SerializeField]
private WorldMapWorld world;

[SerializeField]
private GameObject buttonNotification;

[SerializeField]
private Button closeButton;

private WorldMap.ViewModel _sharedViewModel;
private StageType _stageType = StageType.None;
Expand Down Expand Up @@ -89,21 +113,24 @@ private void OnClickClose()
{
Game.Event.OnRoomEnter.Invoke(true);
}

base.Close(true);
}

public void Show(WorldMap.ViewModel viewModel, WorldSheet.Row worldRow, StageType stageType)
{
_sharedViewModel = viewModel;
UpdateStageInformation(_sharedViewModel.SelectedStageId.Value, States.Instance.CurrentAvatarState.level);
_sharedViewModel.WorldInformation.TryGetWorld(worldRow.Id, out var worldModel);
_sharedViewModel.SelectedStageId
.Subscribe(stageId => UpdateStageInformation(
stageId,
States.Instance.CurrentAvatarState?.level ?? 1)
)
.AddTo(gameObject);
_sharedViewModel.WorldInformation.TryGetWorld(worldRow.Id, out var worldModel);

closeButtonText.text = L10nManager.Localize($"WORLD_NAME_{worldModel.Name.ToUpper()}");
UpdateStageInformation(_sharedViewModel.SelectedStageId.Value, States.Instance.CurrentAvatarState.level);

if (_sharedViewModel.SelectedStageId.Value == 1)
{
stageHelpButton.Show();
Expand All @@ -126,7 +153,15 @@ public void Show(WorldMap.ViewModel viewModel, WorldSheet.Row worldRow, StageTyp

if (worldModel.IsUnlocked)
{
UnlockWorld(worldModel.GetNextStageIdForPlay(), worldModel.GetNextStageId());
var openedStageId = worldModel.GetNextStageIdForPlay();
if (worldModel.StageEnd < worldRow.StageEnd &&
openedStageId == worldModel.StageEnd &&
openedStageId == worldModel.StageClearedId)
{
openedStageId += 1;
}

UnlockWorld(openedStageId, worldModel.GetNextStageId());
}
else
{
Expand All @@ -140,15 +175,38 @@ public void Show(WorldMap.ViewModel viewModel, WorldSheet.Row worldRow, StageTyp

private void UpdateStageInformation(int stageId, int characterLevel)
{
var worldInfo = _sharedViewModel.WorldInformation;
var isSubmittable = false;
if (!(_sharedViewModel.WorldInformation is null))
if (!(worldInfo is null))
{
if (!_sharedViewModel.WorldInformation.TryGetWorldByStageId(stageId, out var world))
throw new ArgumentException(nameof(stageId));

isSubmittable = world.IsPlayable(stageId);
if (worldInfo.TryGetWorldByStageId(stageId, out var innerWorld))
{
isSubmittable = innerWorld.IsPlayable(stageId);
}
else
{
// NOTE: Consider expanding the world.
if (Game.Game.instance.TableSheets.WorldSheet.TryGetByStageId(stageId, out var worldRow))
{
worldInfo.UpdateWorld(worldRow);
if (worldInfo.TryGetWorldByStageId(stageId, out var world2))
{
isSubmittable = world2.IsPlayable(stageId);
}
else
{
throw new ArgumentException(nameof(stageId));
}
}
else
{
throw new ArgumentException(nameof(stageId));
}
}
}

submitButton.SetSubmittable(isSubmittable);

var stageWaveSheet = Game.Game.instance.TableSheets.StageWaveSheet;
stageWaveSheet.TryGetValue(stageId, out var stageWaveRow, true);
titleText.text = $"Stage {GetStageIdString(stageWaveRow.StageId, true)}";
Expand Down Expand Up @@ -189,7 +247,6 @@ private void UpdateStageInformation(int stageId, int characterLevel)
var exp = StageRewardExpHelper.GetExp(characterLevel, stageId);
expText.text = $"EXP +{exp}";

submitButton.SetSubmittable(isSubmittable);
buttonNotification.SetActive(stageId == Find<WorldMap>().StageIdToNotify);
}

Expand Down
3 changes: 1 addition & 2 deletions nekoyume/Assets/_Scripts/UI/Widget/WorldMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ private void ShowWorld(int worldId, int stageId, bool showWorld, bool callByShow
SelectedWorldStageBegin = worldRow.StageBegin;
SelectedStageId = stageId;

var stageInfo = Find<UI.StageInformation>();
SharedViewModel.WorldInformation.TryGetWorld(worldId, out var world);
var stageInfo = Find<StageInformation>();
stageInfo.Show(SharedViewModel, worldRow, StageInformation.StageType.Quest);
}

Expand Down

0 comments on commit fc121cf

Please sign in to comment.