static void CreateWizard() { //ScriptableWizard.DisplayWizard<CreateAvatar>("Create Light", "Create"); CreateAvatar window = (CreateAvatar)EditorWindow.GetWindow(typeof(CreateAvatar)); window.Show(); //If you don't want to use the secondary button simply leave it out: //ScriptableWizard.DisplayWizard<WizardCreateLight>("Create Light", "Create"); }
public void Execute() { var action = new CreateAvatar() { avatarAddress = _avatarAddress, index = 0, hair = 0, ear = 0, lens = 0, tail = 0, name = "test", }; var gold = new GoldCurrencyState(new Currency("NCG", 2, minter: null)); var ranking = new RankingState(); for (var i = 0; i < RankingState.RankingMapCapacity; i++) { ranking.RankingMap[RankingState.Derive(i)] = new HashSet <Address>().ToImmutableHashSet(); } var sheets = TableSheetsImporter.ImportSheets(); var state = new State() .SetState(GoldCurrencyState.Address, gold.Serialize()) .SetState( Addresses.GoldDistribution, GoldDistributionTest.Fixture.Select(v => v.Serialize()).Serialize() ) .SetState( Addresses.GameConfig, new GameConfigState(sheets[nameof(GameConfigSheet)]).Serialize() ) .SetState(Addresses.Ranking, ranking.Serialize()) .MintAsset(GoldCurrencyState.Address, gold.Currency * 100000000000); foreach (var(key, value) in sheets) { state = state.SetState(Addresses.TableSheet.Derive(key), value.Serialize()); } var nextState = action.Execute(new ActionContext() { PreviousStates = state, Signer = _agentAddress, BlockIndex = 0, }); Assert.Equal( 0, nextState.GetBalance(default, gold.Currency).MajorUnit
public void Execute() { var action = new CreateAvatar() { index = 0, hair = 0, ear = 0, lens = 0, tail = 0, name = "test", }; var gold = new GoldCurrencyState(new Currency("NCG", 2, minter: null)); var sheets = TableSheetsImporter.ImportSheets(); var state = new State() .SetState( Addresses.GameConfig, new GameConfigState(sheets[nameof(GameConfigSheet)]).Serialize() ); foreach (var(key, value) in sheets) { state = state.SetState(Addresses.TableSheet.Derive(key), value.Serialize()); } var nextState = action.Execute(new ActionContext() { PreviousStates = state, Signer = _agentAddress, BlockIndex = 0, }); var avatarAddress = _agentAddress.Derive( string.Format( CultureInfo.InvariantCulture, CreateAvatar2.DeriveFormat, 0 ) ); Assert.True(nextState.TryGetAgentAvatarStatesV2(
public ActionMutation(NineChroniclesNodeService service) { Field <NonNullGraphType <TxIdType> >("createAvatar", description: "Create new avatar.", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "avatarName", Description = "Avatar name." }, new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "avatarIndex", Description = "The index of character slot. 0 ~ 2" }, new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "hairIndex", Description = "The index of character hair color. 0 ~ 8" }, new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "lensIndex", Description = "The index of character eye color. 0 ~ 8" }, new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "earIndex", Description = "The index of character ear color. 0 ~ 8" }, new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "tailIndex", Description = "The index of character tail color. 0 ~ 8" } ), resolve: context => { try { if (!(service.MinerPrivateKey is { } privateKey)) { throw new InvalidOperationException($"{nameof(service.MinerPrivateKey)} is null."); } if (!(service.Swarm?.BlockChain is { } blockChain)) { throw new InvalidOperationException($"{nameof(service.Swarm.BlockChain)} is null."); } var avatarName = context.GetArgument <string>("avatarName"); var avatarIndex = context.GetArgument <int>("avatarIndex"); var hairIndex = context.GetArgument <int>("hairIndex"); var lensIndex = context.GetArgument <int>("lensIndex"); var earIndex = context.GetArgument <int>("earIndex"); var tailIndex = context.GetArgument <int>("tailIndex"); var action = new CreateAvatar { index = avatarIndex, hair = hairIndex, lens = lensIndex, ear = earIndex, tail = tailIndex, name = avatarName, }; var actions = new NCAction[] { action }; Transaction <NCAction> tx = blockChain.MakeTransaction(privateKey, actions); return(tx.Id); }
public ActionMutation() { Field <NonNullGraphType <BooleanGraphType> >("createAvatar", resolve: context => { try { NineChroniclesNodeService service = context.Source; PrivateKey privatekey = service.PrivateKey; BlockChain <NineChroniclesActionType> blockChain = service.Swarm.BlockChain; Address userAddress = privatekey.PublicKey.ToAddress(); Address avatarAddress = userAddress.Derive("avatar_0"); var action = new CreateAvatar { avatarAddress = avatarAddress, index = 0, hair = 0, lens = 0, ear = 0, tail = 0, name = "createbymutation", }; var actions = new PolymorphicAction <ActionBase>[] { action }; blockChain.MakeTransaction(privatekey, actions); } catch (Exception e) { var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}"; context.Errors.Add(new ExecutionError(msg, e)); Log.Error(msg, e); return(false); } return(true); }); Field <NonNullGraphType <BooleanGraphType> >("hackAndSlash", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "weeklyArenaAddress", }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "rankingArenaAddress", }), resolve: context => { try { NineChroniclesNodeService service = context.Source; PrivateKey privatekey = service.PrivateKey; BlockChain <NineChroniclesActionType> blockChain = service.Swarm.BlockChain; Address userAddress = privatekey.PublicKey.ToAddress(); Address avatarAddress = userAddress.Derive("avatar_0"); Address weeklyArenaAddress = new Address(context.GetArgument <string>("weeklyArenaAddress")); Address rankingArenaAddress = new Address(context.GetArgument <string>("rankingArenaAddress")); var action = new HackAndSlash { avatarAddress = avatarAddress, worldId = 1, stageId = 1, WeeklyArenaAddress = weeklyArenaAddress, RankingMapAddress = rankingArenaAddress, costumes = new List <int>(), equipments = new List <Guid>(), foods = new List <Guid>(), }; var actions = new PolymorphicAction <ActionBase>[] { action }; blockChain.MakeTransaction(privatekey, actions); } catch (Exception e) { var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}"; context.Errors.Add(new ExecutionError(msg, e)); Log.Error(msg, e); return(false); } return(true); }); Field <NonNullGraphType <BooleanGraphType> >("combinationEquipment", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <DecimalGraphType> > { Name = "recipeId", }, new QueryArgument <NonNullGraphType <DecimalGraphType> > { Name = "slotIndex", }, new QueryArgument <DecimalGraphType> { Name = "subRecipeId", }), resolve: context => { try { NineChroniclesNodeService service = context.Source; PrivateKey privatekey = service.PrivateKey; BlockChain <NineChroniclesActionType> blockChain = service.Swarm.BlockChain; Address userAddress = privatekey.PublicKey.ToAddress(); Address avatarAddress = userAddress.Derive("avatar_0"); int recipeId = context.GetArgument <int>("recipeId"); int slotIndex = context.GetArgument <int>("slotIndex"); int?subRecipeId = context.GetArgument <int>("subRecipeId"); var action = new CombinationEquipment { AvatarAddress = avatarAddress, RecipeId = recipeId, SlotIndex = slotIndex, SubRecipeId = subRecipeId }; var actions = new PolymorphicAction <ActionBase>[] { action }; blockChain.MakeTransaction(privatekey, actions); } catch (Exception e) { var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}"; context.Errors.Add(new ExecutionError(msg, e)); Log.Error(msg, e); return(false); } return(true); }); Field <NonNullGraphType <BooleanGraphType> >("itemEnhancement", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "itemId", }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "materialIds", }), resolve: context => { try { NineChroniclesNodeService service = context.Source; PrivateKey privatekey = service.PrivateKey; BlockChain <NineChroniclesActionType> blockChain = service.Swarm.BlockChain; Address userAddress = privatekey.PublicKey.ToAddress(); Address avatarAddress = userAddress.Derive("avatar_0"); Guid itemId = Guid.Parse(context.GetArgument <string>("itemId")); Guid materialId = Guid.Parse(context.GetArgument <string>("materialIds")); var action = new ItemEnhancement { avatarAddress = avatarAddress, slotIndex = 0, itemId = itemId, materialIds = new[] { materialId } }; var actions = new PolymorphicAction <ActionBase>[] { action }; blockChain.MakeTransaction(privatekey, actions); } catch (Exception e) { var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}"; context.Errors.Add(new ExecutionError(msg, e)); Log.Error(msg, e); return(false); } return(true); }); Field <NonNullGraphType <BooleanGraphType> >("buy", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "sellerAgentAddress", }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "sellerAvatarAddress", }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "productId", }), resolve: context => { try { NineChroniclesNodeService service = context.Source; PrivateKey privatekey = service.PrivateKey; BlockChain <NineChroniclesActionType> blockChain = service.Swarm.BlockChain; Address userAddress = privatekey.PublicKey.ToAddress(); Address avatarAddress = userAddress.Derive("avatar_0"); Address sellerAgentAddress = new Address(context.GetArgument <string>("sellerAgentAddress")); Address sellerAvatarAddress = new Address(context.GetArgument <string>("sellerAvatarAddress")); Guid productId = Guid.Parse(context.GetArgument <string>("productId")); var action = new Buy { buyerAvatarAddress = avatarAddress, sellerAgentAddress = sellerAgentAddress, sellerAvatarAddress = sellerAvatarAddress, productId = productId, }; var actions = new PolymorphicAction <ActionBase>[] { action }; blockChain.MakeTransaction(privatekey, actions); } catch (Exception e) { var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}"; context.Errors.Add(new ExecutionError(msg, e)); Log.Error(msg, e); return(false); } return(true); }); Field <NonNullGraphType <BooleanGraphType> >("sell", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "sellerAvatarAddress", }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "productId", }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "itemId", }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "price", }), resolve: context => { try { NineChroniclesNodeService service = context.Source; PrivateKey privatekey = service.PrivateKey; BlockChain <NineChroniclesActionType> blockChain = service.Swarm.BlockChain; Address sellerAvatarAddress = new Address(context.GetArgument <string>("sellerAvatarAddress")); Guid itemId = Guid.Parse(context.GetArgument <string>("itemId")); var currency = new GoldCurrencyState( (Dictionary)blockChain.GetState(GoldCurrencyState.Address) ).Currency; FungibleAssetValue price = FungibleAssetValue.Parse(currency, context.GetArgument <string>("price")); var action = new Sell { sellerAvatarAddress = sellerAvatarAddress, itemId = itemId, price = price }; var actions = new PolymorphicAction <ActionBase>[] { action }; blockChain.MakeTransaction(privatekey, actions); } catch (Exception e) { var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}"; context.Errors.Add(new ExecutionError(msg, e)); Log.Error(msg, e); return(false); } return(true); }); Field <NonNullGraphType <BooleanGraphType> >("dailyReward", resolve: context => { try { NineChroniclesNodeService service = context.Source; PrivateKey privatekey = service.PrivateKey; BlockChain <NineChroniclesActionType> blockChain = service.Swarm.BlockChain; Address userAddress = privatekey.PublicKey.ToAddress(); Address avatarAddress = userAddress.Derive("avatar_0"); var action = new DailyReward { avatarAddress = avatarAddress }; var actions = new PolymorphicAction <ActionBase>[] { action }; blockChain.MakeTransaction(privatekey, actions); } catch (Exception e) { var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}"; context.Errors.Add(new ExecutionError(msg, e)); Log.Error(msg, e); return(false); } return(true); }); }