Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce and apply States.NCG #3214

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void OnGUI()
return null;
}

return _ncg ??= Game.instance.States?.GoldBalanceState?.Gold.Currency;
return _ncg ??= Game.instance.States?.NCG;
}

public TableSheets? GetTableSheets()
Expand Down Expand Up @@ -167,7 +167,7 @@ private void InitializeStateProxy()
_stateProxy.RegisterAlias("me", states.CurrentAvatarState.address);
}

_ncg = states.GoldBalanceState.Gold.Currency;
_ncg = states.NCG;
}
}
}
5 changes: 2 additions & 3 deletions nekoyume/Assets/_Scripts/Blockchain/ActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace Nekoyume.Blockchain
public abstract class ActionHandler
{
public bool Pending { get; set; }
public Currency GoldCurrency { get; internal set; }

public abstract void Start(ActionRenderer renderer);

Expand Down Expand Up @@ -51,7 +50,7 @@ protected GoldBalanceState GetGoldBalanceState<T>(ActionEvaluation<T> evaluation

return StateGetter.GetGoldBalanceState(
agentAddress,
GoldCurrency,
States.Instance.NCG,
evaluation.OutputState);
}

Expand Down Expand Up @@ -80,7 +79,7 @@ protected GoldBalanceState GetGoldBalanceState<T>(ActionEvaluation<T> evaluation
return (stakeAddr, null, new FungibleAssetValue(), 0, null, null);
}

var balance = await agent.GetBalanceAsync(stakeAddr, GoldCurrency);
var balance = await agent.GetBalanceAsync(stakeAddr, States.Instance.NCG);
var sheetAddrArr = new[]
{
Addresses.GetSheetAddress(
Expand Down
4 changes: 1 addition & 3 deletions nekoyume/Assets/_Scripts/Blockchain/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,7 @@ public IObservable<ActionEvaluation<EventDungeonBattle>> EventDungeonBattle(
? TableSheets.Instance.EventScheduleSheet.TryGetValue(
eventScheduleId,
out var scheduleRow)
? scheduleRow.GetDungeonTicketCost(
numberOfTicketPurchases,
States.Instance.GoldBalanceState.Gold.Currency)
? scheduleRow.GetDungeonTicketCost(numberOfTicketPurchases, States.Instance.NCG)
.GetQuantityString(true)
: "0"
: "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2943,7 +2943,7 @@ private void ResponseUnloadFromMyGarages(ActionEvaluation<UnloadFromMyGarages> e
balanceAddr,
value.Currency,
states);
if (value.Currency.Equals(GoldCurrency))
if (value.Currency.Equals(States.Instance.NCG))
{
var goldState = new GoldBalanceState(balanceAddr, balance);
gameStates.SetGoldBalanceState(goldState);
Expand Down
20 changes: 13 additions & 7 deletions nekoyume/Assets/_Scripts/Blockchain/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,17 +461,23 @@ await InitAsync(
PreloadEndedAsync += async () =>
{
// 에이전트의 상태를 한 번 동기화 한다.
var goldCurrency = new GoldCurrencyState(
(Dictionary)await GetStateAsync(GoldCurrencyState.Address)
).Currency;
ActionRenderHandler.Instance.GoldCurrency = goldCurrency;
if (await GetStateAsync(GoldCurrencyState.Address) is Dictionary goldDict)
{
var goldCurrencyState = new GoldCurrencyState(goldDict);
States.Instance.SetGoldCurrencyState(goldCurrencyState);
}
else
{
throw new FailedToInstantiateStateException<GoldCurrencyState>();
}

var ncg = States.Instance.NCG;
await States.Instance.SetAgentStateAsync(
await GetStateAsync(Address) is Dictionary agentDict
? new AgentState(agentDict)
: new AgentState(Address));
States.Instance.SetGoldBalanceState(new GoldBalanceState(Address,
await GetBalanceAsync(Address, goldCurrency)));
await GetBalanceAsync(Address, ncg)));
States.Instance.SetCrystalBalance(
await GetBalanceAsync(Address, CrystalCalculator.CRYSTAL));

Expand All @@ -497,13 +503,13 @@ await GetStateAsync(Address) is Dictionary agentDict
}
else
{
var balance = new FungibleAssetValue(goldCurrency);
var balance = new FungibleAssetValue(ncg);
var level = 0;
var stakeRegularFixedRewardSheet = new StakeRegularFixedRewardSheet();
var stakeRegularRewardSheet = new StakeRegularRewardSheet();
try
{
balance = await GetBalanceAsync(stakeAddr, goldCurrency);
balance = await GetBalanceAsync(stakeAddr, ncg);
var sheetAddrArr = new[]
{
Addresses.GetSheetAddress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static async UniTaskVoid UpdateWhenEveryBlockRenderBeginningAsync()
FungibleAssetValue garage;
try
{
var ncg = States.Instance.GoldBalanceState.Gold.Currency;
var ncg = States.Instance.NCG;
var favArr = await Task.WhenAll(
agent.GetBalanceAsync(agentState.address, ncg),
agent.GetBalanceAsync(agentState.address, Currencies.Crystal),
Expand Down
21 changes: 13 additions & 8 deletions nekoyume/Assets/_Scripts/Blockchain/RPCAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,21 +546,26 @@ private IEnumerator CoJoin(Action<bool> callback)
// 에이전트의 상태를 한 번 동기화 한다.
var currencyTask = Task.Run(async () =>
{
var goldCurrency = new GoldCurrencyState(
(Dictionary)await GetStateAsync(GoldCurrencyState.Address)
).Currency;
ActionRenderHandler.Instance.GoldCurrency = goldCurrency;

await States.Instance.SetAgentStateAsync(
await GetStateAsync(Address) is Dictionary agentDict
? new AgentState(agentDict)
: new AgentState(Address));
var ncg = States.Instance.NCG;
States.Instance.SetGoldBalanceState(
new GoldBalanceState(
Address,
await GetBalanceAsync(Address, goldCurrency)));
await GetBalanceAsync(Address, ncg)));
States.Instance.SetCrystalBalance(
await GetBalanceAsync(Address, Currencies.Crystal));
if (await GetStateAsync(GoldCurrencyState.Address) is Dictionary goldDict)
{
var goldCurrencyState = new GoldCurrencyState(goldDict);
States.Instance.SetGoldCurrencyState(goldCurrencyState);
}
else
{
throw new FailedToInstantiateStateException<GoldCurrencyState>();
}

if (await GetStateAsync(GameConfigState.Address) is Dictionary configDict)
{
Expand All @@ -584,13 +589,13 @@ await GetStateAsync(Address) is Dictionary agentDict
}
else
{
var balance = new FungibleAssetValue(goldCurrency);
var balance = new FungibleAssetValue(ncg);
var level = 0;
var stakeRegularFixedRewardSheet = new StakeRegularFixedRewardSheet();
var stakeRegularRewardSheet = new StakeRegularRewardSheet();
try
{
balance = await GetBalanceAsync(stakeAddr, goldCurrency);
balance = await GetBalanceAsync(stakeAddr, ncg);
var sheetAddrArr = new[]
{
Addresses.GetSheetAddress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ await Game.Game.instance.MarketServiceClient.GetProductInfo(
var price = item?.Price ?? fav?.Price ?? 0;
var tax = decimal.Divide(price, 100) * Buy.TaxRate;
var tp = price - tax;
var currency = States.Instance.GoldBalanceState.Gold.Currency;
var ncg = States.Instance.NCG;
var majorUnit = (int)tp;
var minorUnit = (int)((tp - majorUnit) * 100);
var fungibleAsset = new FungibleAssetValue(currency, majorUnit, minorUnit);
var fungibleAsset = new FungibleAssetValue(ncg, majorUnit, minorUnit);
return L10nManager.Localize("UI_SELLER_MAIL_FORMAT", fungibleAsset,
sellProductName);
case UnloadFromMyGaragesRecipientMail unloadFromMyGaragesRecipientMail:
Expand Down Expand Up @@ -698,8 +698,7 @@ public static string GetPaymentFormatText(this FungibleAssetValue asset,
BigInteger cost)
{
// NCG
if (asset.Currency.Equals(
Game.Game.instance.States.GoldBalanceState.Gold.Currency))
if (asset.Currency.Equals(States.Instance.NCG))
{
var ncgText = L10nManager.Localize("UI_NCG");
return L10nManager.Localize(
Expand Down
3 changes: 2 additions & 1 deletion nekoyume/Assets/_Scripts/Helper/PetFrontHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public static bool HasNotification(int id)
return false;
}

var ncgCost = States.Instance.GoldBalanceState.Gold.Currency * nextCost.NcgQuantity;
var ncg = States.Instance.NCG;
var ncgCost = ncg * nextCost.NcgQuantity;
var soulStoneCost =
PetHelper.GetSoulstoneCurrency(TableSheets.Instance.PetSheet[id].SoulStoneTicker) *
nextCost.SoulStoneQuantity;
Expand Down
5 changes: 1 addition & 4 deletions nekoyume/Assets/_Scripts/State/LocalLayerModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public static void ModifyAgentGold(Address agentAddress, BigInteger gold)
return;
}

var fav = new FungibleAssetValue(
States.Instance.GoldBalanceState.Gold.Currency,
gold,
0);
var fav = new FungibleAssetValue(States.Instance.NCG, gold, 0);
ModifyAgentGoldAsync(agentAddress, fav).Forget();
}

Expand Down
13 changes: 11 additions & 2 deletions nekoyume/Assets/_Scripts/State/States.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@
namespace Nekoyume.State
{
/// <summary>
/// 클라이언트가 참조할 상태를 포함한다.
/// 체인의 상태를 Setter를 통해서 받은 후, 로컬의 상태로 필터링해서 사용한다.
/// The blockchain state for game client.
/// - Set blockchain state by setter methods here.
/// - The blockchain state modified by <see cref="LocalLayer"/> in setter methods.
/// - Get modified blockchain state by getter methods here.
/// </summary>
public class States
{
public static States Instance => Game.Game.instance.States;

public GoldCurrencyState GoldCurrencyState { get; private set; }
public Currency NCG => GoldCurrencyState.Currency;
public AgentState AgentState { get; private set; }

public GoldBalanceState GoldBalanceState { get; private set; }
Expand Down Expand Up @@ -104,6 +108,11 @@ public States()

#region Setter

public void SetGoldCurrencyState(GoldCurrencyState state)
{
GoldCurrencyState = state;
}

/// <summary>
/// 에이전트 상태를 할당한다.
/// 로컬 세팅을 거친 상태가 최종적으로 할당된다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static AgentStateSubject()

public static void OnNextGold(FungibleAssetValue gold)
{
if (gold.Currency.Equals(States.Instance.GoldBalanceState.Gold.Currency))
if (gold.Currency.Equals(States.Instance.NCG))
{
_gold.OnNext(gold);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ItemCountAndPricePopup : ItemCountPopup<ItemCountAndPricePopup>

public ItemCountAndPricePopup()
{
var currency = States.Instance.GoldBalanceState.Gold.Currency;
var currency = States.Instance.NCG;
Price = new ReactiveProperty<FungibleAssetValue>(new FungibleAssetValue(currency, 10, 0));
}

Expand Down
5 changes: 3 additions & 2 deletions nekoyume/Assets/_Scripts/UI/Shop/CartView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ public void UpdateCart(List<ShopItem> selectedItems, System.Action onClick)
return;
}

var ncg = States.Instance.NCG;
var sortedItems = selectedItems.Where(x => !x.Expired.Value).ToList();
var price = new FungibleAssetValue(States.Instance.GoldBalanceState.Gold.Currency, 0 ,0);
var price = new FungibleAssetValue(ncg, 0 ,0);
for (var i = 0; i < cartItems.Count; i++)
{
if (i < sortedItems.Count)
{
var p = sortedItems[i].ItemBase is not null
? (BigInteger)sortedItems[i].Product.Price
: (BigInteger)sortedItems[i].FungibleAssetProduct.Price;
price += p * States.Instance.GoldBalanceState.Gold.Currency;
price += p * ncg;
cartItems[i].gameObject.SetActive(true);
cartItems[i].Set(sortedItems[i], (item) =>
{
Expand Down
2 changes: 1 addition & 1 deletion nekoyume/Assets/_Scripts/UI/Widget/BattlePreparation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ private void OnClickBattle()
var cost = RxProps.EventScheduleRowForDungeon.Value
.GetDungeonTicketCost(
RxProps.EventDungeonInfo.Value?.NumberOfTicketPurchases ?? 0,
States.Instance.GoldBalanceState.Gold.Currency);
States.Instance.NCG);
var purchasedCount = RxProps.EventDungeonInfo.Value?.NumberOfTicketPurchases ?? 0;

Find<TicketPurchasePopup>().Show(
Expand Down
5 changes: 1 addition & 4 deletions nekoyume/Assets/_Scripts/UI/Widget/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,7 @@ protected override void Update()
{
(
states.AgentState.address,
new FungibleAssetValue(
states.GoldBalanceState.Gold.Currency,
9,
99)
new FungibleAssetValue(states.NCG, 9, 99)
),
(states.CurrentAvatarState.address, 99 * Currencies.Crystal),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private IEnumerator OnClickNext()
var cost = RxProps.EventScheduleRowForDungeon.Value
.GetDungeonTicketCost(
RxProps.EventDungeonInfo.Value?.NumberOfTicketPurchases ?? 0,
States.Instance.GoldBalanceState.Gold.Currency);
States.Instance.NCG);
var purchasedCount =
RxProps.EventDungeonInfo.Value?.NumberOfTicketPurchases ?? 0;

Expand Down Expand Up @@ -295,7 +295,7 @@ private IEnumerator OnClickRepeat()
var cost = RxProps.EventScheduleRowForDungeon.Value
.GetDungeonTicketCost(
RxProps.EventDungeonInfo.Value?.NumberOfTicketPurchases ?? 0,
States.Instance.GoldBalanceState.Gold.Currency);
States.Instance.NCG);
var purchasedCount =
RxProps.EventDungeonInfo.Value?.NumberOfTicketPurchases ?? 0;

Expand Down
2 changes: 1 addition & 1 deletion nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public async void Read(ProductSellerMail productSellerMail)
var avatarAddress = States.Instance.CurrentAvatarState.address;
var agentAddress = States.Instance.AgentState.address;
var (_, itemProduct, favProduct) = await Game.Game.instance.MarketServiceClient.GetProductInfo(productSellerMail.ProductId);
var currency = States.Instance.GoldBalanceState.Gold.Currency;
var currency = States.Instance.NCG;
var price = itemProduct?.Price ?? favProduct.Price;
var fav = new FungibleAssetValue(currency, (int)price, 0);
var taxedPrice = fav.DivRem(100, out _) * Action.Buy.TaxRate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private void SetObjectByTargetLevel(int petId, int currentLevel, int targetLevel
}

soulStoneCostText.text = soulStone.ToString();
var ncgCost = States.Instance.GoldBalanceState.Gold.Currency * ncg;
var ncgCost = States.Instance.NCG * ncg;
var soulStoneCost =
PetHelper.GetSoulstoneCurrency(_petRow.SoulStoneTicker) *
soulStone;
Expand Down
2 changes: 1 addition & 1 deletion nekoyume/Assets/_Scripts/UI/Widget/RaidPreparation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ private void ShowTicketPurchasePopup(long currentBlockIndex)

var avatarState = States.Instance.CurrentAvatarState;
var raiderState = WorldBossStates.GetRaiderState(avatarState.address);
var cur = States.Instance.GoldBalanceState.Gold.Currency;
var cur = States.Instance.NCG;
var cost = WorldBossHelper.CalculateTicketPrice(row, raiderState, cur);
var balance = States.Instance.GoldBalanceState;
Find<TicketPurchasePopup>().Show(
Expand Down
6 changes: 3 additions & 3 deletions nekoyume/Assets/_Scripts/UI/Widget/ShopBuy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ private void ShowBuyPopup(List<ShopItem> models)
{
if (model.ItemBase is not null)
{
sumPrice += (BigInteger)model.Product.Price * States.Instance.GoldBalanceState.Gold.Currency;
sumPrice += (BigInteger)model.Product.Price * States.Instance.NCG;
}
else
{
sumPrice += (BigInteger)model.FungibleAssetProduct.Price * States.Instance.GoldBalanceState.Gold.Currency;
sumPrice += (BigInteger)model.FungibleAssetProduct.Price * States.Instance.NCG;
}
}

Expand All @@ -207,7 +207,7 @@ private void Buy(List<ShopItem> models)
{
var productInfos = new List<IProductInfo>();
var avatarAddress = States.Instance.CurrentAvatarState.address;
var currency = States.Instance.GoldBalanceState.Gold.Currency;
var currency = States.Instance.NCG;
foreach (var model in models)
{
var itemProduct = model.Product;
Expand Down
Loading