private static IEnumerator MtxExplorerListTournaments(RoutineContext context) { var tournaments = new List <Tournament>(); var param = (object[])context.param; var page = (long)param[0]; var offset = page * 10; using (WWW www = new WWW(explorerEndpt + allTournamentsEndpt)) { yield return(www); // Debug.Log(www.text); var jsonObj = serializer.Deserialize <object>(www.bytes) as Dictionary <string, object>; var tournamentList = jsonObj["data"] as List <object>; for (int i = 0; i < 10; i++) { try { var tourna = tournamentList[i + (int)offset] as Dictionary <string, object>; var tournament = new Tournament(); tournament.title = tourna["tournamentTitle"] as string; tournament.description = tourna["tournamentDescription"] as string; tournament.bounty = (long)Convert.ToDouble(tourna["mtx"]); tournament.address = tourna["address"] as string; tournaments.Add(tournament); } catch (System.ArgumentOutOfRangeException e) { break; } catch (Exception e) { Debug.Log(e); } } Debug.Log("Fetched tournaments: " + tournaments.Count); context.done(tournaments); } }
protected override IEnumerable <RunStatus> Execute(object context) { RoutineContext ctx = context as RoutineContext; if (ctx != null) { if (ctx.SkillNames.Contains(SpellName)) { Gw2Skill spell = ctx.GetSpell(SpellName); if (spell != null) { bool currentCondition = Condition == null || Condition(ctx); if (currentCondition) { if (spell.IsReady && BuddyGw.IsVisible(Object)) { Logger.WriteVerbose("Casting {0} on position {1}.", spell.Name, Object.Position); SpellManager.Cast(spell.Name, Object); return(new List <RunStatus>() { RunStatus.Success }); } } } } } return(new List <RunStatus>() { RunStatus.Failure }); }
public override RunStatus Tick(object context) { RoutineContext ctx = (RoutineContext)context; try { ctx.Update(); } catch (Exception e) { Logger.WriteVerbose(e.Message); } _CurrentPosition = _TargetPosition(ctx); if (_IsInRange(ctx)) { Typhon.Navigation.Movement.StopMoving(); return(RunStatus.Failure); } else { if (_CurrentPosition != Vector3.Zero) { MoveResult movement = Navigator.MoveTo(_CurrentPosition, _DestinationName); if (movement == MoveResult.Failure) { _LastDistance = -1; return(RunStatus.Failure); } else if (movement == MoveResult.Done) { _LastDistance = -1; return(RunStatus.Failure); } else { float currentDistance = ctx.CurrentPlayerPosition.Distance(_CurrentPosition); if (_LastDistance != -1 && currentDistance > _LastDistance) { _LastDistance = -1; return(RunStatus.Success); } else { _LastDistance = ctx.CurrentPlayerPosition.Distance(_CurrentPosition); return(RunStatus.Running); } } } else { _LastDistance = -1; return(RunStatus.Failure); } } }
internal static Composite CreateWaitForCast() { return(new Decorator( ctx => { RoutineContext context = (RoutineContext)ctx; return context.IsCasting; }, new Typhon.BehaviourTree.Action(ctx => RunStatus.Success) )); }
internal static Composite MoveIntoRangeBehavior(float range) { return (new PrioritySelector( //new Decorator( // context => { // RoutineContext ctx = (RoutineContext)context; // Vector3 realPos = Gw2Math.VectorToLarge(ctx.CurrentPlayerPosition); // if (ArchitectusSettings.Instance.Debug.IsMovementDebuggingActive) // Logger.Write("Current player position: {0}", realPos); // if (ctx.CurrentTargetPosition == Vector3.Zero) // return false; // Vector3 realTargetPos = Gw2Math.VectorToLarge(ctx.CurrentTargetPosition); // if (ArchitectusSettings.Instance.Debug.IsMovementDebuggingActive) // Logger.Write("Current target position: {0}", realTargetPos); // float currentDistance = realPos.Distance(realTargetPos); // if (ArchitectusSettings.Instance.Debug.IsMovementDebuggingActive) // Logger.Write("Current distance: {0}", currentDistance); // return !ctx.CurrentTargetIsVisible || range < currentDistance; // }, // CommonBehaviors.CreateMoveTo(ret => BuddyGw.Me.CurrentTarget.Position, "Combat position") //), new MoveToComposite( ctx => { return ctx.CurrentTargetPosition; }, ctx => { return ctx.CurrentTargetIsVisible && range > ctx.DistanceToTarget; }, "Combat position" ), new Decorator( ctx => { RoutineContext context = (RoutineContext)ctx; if (context.CurrentTargetPosition == Vector3.Zero) { return false; } return !BuddyGw.Me.Agent.IsFacing(context.CurrentTargetPosition); }, new Action( ctx => { RoutineContext context = (RoutineContext)ctx; Navigator.Face(context.CurrentTargetPosition); } ) ) )); }
private static IEnumerator MtxExplorerListSubmissions(RoutineContext context) { var submissions = new List <Submission>(); var param = (object[])context.param; var tournamentAddress = (string)param[0]; var page = (long)param[1]; var offset = page * 10; var url = explorerEndpt + tournamentDetailByIdEndpt + tournamentAddress; using (WWW www = new WWW(url)) { yield return(www); // Debug.Log(www.text); var jsonObj = serializer.Deserialize <object>(www.bytes) as Dictionary <string, object>; if (jsonObj["error"] != null) { context.done(submissions); } else { Debug.Log(url + " - " + jsonObj["message"] as string); var dataObj = jsonObj["data"] as Dictionary <string, object>; var title = dataObj["tournamentTitle"] as string; var bounty = Convert.ToDouble(dataObj["mtx"] as string); var description = dataObj["tournamentDescription"] as string; var submissionList = dataObj["recentSubmissions"] as List <object>; for (int i = 0; i < 10; i++) { try { var sub = submissionList[i + (int)offset] as Dictionary <string, object>; var submission = new Submission(); submission.address = tournamentAddress + ":" + sub["submissionAddress"] as string; submission.title = sub["submissionTitle"] as string; submission.address += submission.title; submission.author = sub["authorName"] as string; submissions.Add(submission); } catch (System.ArgumentOutOfRangeException e) { break; } catch (Exception e) { Debug.Log(e); } } Debug.Log("Fetched submissions: " + submissions.Count); context.done(submissions); } } }
private static IEnumerator CoroutineListSumbissions(RoutineContext context) { // Prepare var function = platformContract.GetFunction("submissionByIndex"); var submissions = new List <Submission>(); // Parse routine params var param = (object[])context.param; var tournamentAddress = (string)param[0]; var page = (long)param[1]; // Loop over every needed indexes var offset = page * 10; Debug.Log("Loading submissions at: " + offset + " in tournament: " + tournamentAddress); for (var i = 0; i < 10; i++) { // Make input var input = function.CreateCallInput(new BigInteger(Convert.ToInt64(tournamentAddress)), i + offset); // Request the specific submission within tournament address at index var request = new EthCallUnityRequest(mtxNode); yield return(SimpleCall(request, input)); // Read results try { var parsedResults = function.DecodeDTOTypeOutput <SubmissionDTO>(request.Result); // Read results var submission = new Submission(); submission.tournamentAddress = tournamentAddress; submission.address = tournamentAddress + ":" + parsedResults.id.ToString(); submission.title = parsedResults.title; submission.body = parsedResults.body; submission.references = parsedResults.references; submission.contributors = parsedResults.contributors; submission.author = parsedResults.author; // Add to list of submissions submissions.Add(submission); } catch (Exception e) { Debug.Log("Could not read submission at index: " + (offset + i)); //Debug.Log(e); //break; } } Debug.Log("Fetched submissions: " + submissions.Count); // Done context.done(submissions); }
protected override IEnumerable <RunStatus> Execute(object context) { RoutineContext ctx = (RoutineContext)context; _CurrentPosition = _TargetPosition(ctx); if (_IsInRange(ctx)) { Typhon.Navigation.Movement.StopMoving(); yield return(RunStatus.Failure); } else { if (_CurrentPosition != Vector3.Zero) { MoveResult movement = Navigator.MoveTo(_CurrentPosition, _DestinationName); if (movement == MoveResult.Failure) { _LastDistance = -1; yield return(RunStatus.Failure); } else if (movement == MoveResult.Done) { _LastDistance = -1; yield return(RunStatus.Failure); } else { float currentDistance = ctx.CurrentPlayerPosition.Distance(_CurrentPosition); if (_LastDistance != -1 && currentDistance > _LastDistance) { _LastDistance = -1; yield return(RunStatus.Success); } else { _LastDistance = ctx.CurrentPlayerPosition.Distance(_CurrentPosition); yield return(RunStatus.Running); } } } else { _LastDistance = -1; yield return(RunStatus.Failure); } } }
private static IEnumerator CoroutineListTournaments(RoutineContext context) { // Prepare var function = platformContract.GetFunction("tournamentByIndex"); var tournaments = new List <Tournament>(); // Parse routine params var param = (object[])context.param; var page = (long)param[0]; // Loop over every needed indexes var offset = page * 10; Debug.Log("Loading tournaments at: " + offset); for (var i = 0; i < 10; i++) { // Make input var input = function.CreateCallInput(new BigInteger(i + offset)); // Request the specific tournament at the index var request = new EthCallUnityRequest(mtxNode); yield return(SimpleCall(request, input)); try { var parsedResults = function.DecodeDTOTypeOutput <TournamentDTO>(request.Result); // Read results var tournament = new Tournament(); tournament.address = parsedResults.id.ToString(); tournament.title = parsedResults.title; tournament.description = parsedResults.description; tournament.bounty = (long)parsedResults.bounty; // Add to list of tournaments tournaments.Add(tournament); } catch (Exception e) { Debug.Log("Could not read tournament at index:" + (offset + i)); Debug.Log(e); //break; } } Debug.Log("Fetched tournaments: " + tournaments.Count); // Done context.done(tournaments); }
private static IEnumerator CoroutineUploadSubmission(RoutineContext context) { // Prepare var function = mtxContract.GetFunction("createSubmission"); // Get accounts var requestAccounts = new EthAccountsUnityRequest(mtxNode); yield return(requestAccounts.SendRequest()); var resultsAccounts = requestAccounts.Result; var usedAccount = resultsAccounts[0]; // Parse routine params var param = (object[])context.param; var submission = (Submission)param[0]; var tournamentAddress = Convert.ToInt64(submission.tournamentAddress); var title = submission.title; var body = submission.body; var references = submission.references + "\n"; var contributors = submission.contributors + "\n"; // Make input var transactionInput = function.CreateTransactionInput(usedAccount, tournamentAddress, title, body, references, contributors); transactionInput.Gas = new HexBigInteger(3000000); // Do request var requestTransaction = new EthSendTransactionUnityRequest(mtxNode); yield return(requestTransaction.SendRequest(transactionInput)); // Results try { var resultsTransaction = requestTransaction.Result; // Success context.done(resultsTransaction); } catch (Exception e) { // Error Debug.Log("Could not submit submission"); //Debug.Log(e); context.done(null); } }
private static IEnumerator CoroutineDetailSubmission(RoutineContext context) { // Prepare var function = tournamentContract.GetFunction("submissionByAddress"); // Parse routine params var param = (object[])context.param; var tournamentAddress = (string)param[0]; var submissionAddress = (string)param[1]; // Make input var input = function.CreateCallInput(Convert.ToInt64(tournamentAddress), Convert.ToInt64(submissionAddress)); // Request the specific submission at address var request = new EthCallUnityRequest(mtxNode); yield return(SimpleCall(request, input)); // Read results try { var parsedResults = function.DecodeDTOTypeOutput <SubmissionDTO>(request.Result); // Read results var submission = new Submission(); submission.tournamentAddress = tournamentAddress; submission.address = tournamentAddress + ":" + parsedResults.id.ToString(); submission.title = parsedResults.title; submission.body = parsedResults.body; submission.references = parsedResults.references; submission.contributors = parsedResults.contributors; submission.author = parsedResults.author; // Done context.done(submission); } catch (Exception e) { Debug.Log("Could not read submission at:" + submissionAddress + " tournament: " + tournamentAddress); //Debug.Log(e); context.done(null); } }
private static IEnumerator MtxExplorerDetailSubmission(RoutineContext context) { var param = context.param as object[]; var tournamentAddress = param[0] as string; var submissionAddress = param[1] as string; var url = explorerEndpt + submissionDetailByAddressEndpt + submissionAddress; using (var www = new WWW(url)) { yield return(www); Debug.Log(www.text); var jsonObj = serializer.Deserialize <object>(www.bytes) as Dictionary <string, object>; Debug.Log(url + " - " + jsonObj["message"] as string); var dataObj = jsonObj["data"] as Dictionary <string, object>; try { var submission = new Submission(); submission.tournamentAddress = tournamentAddress; submission.title = dataObj["submissionTitle"] as string; submission.address = tournamentAddress + ":" + dataObj["submissionAddress"] as string; submission.author = dataObj["submissionAuthor"] as string; submission.references = (dataObj["submissionReferences"] as List <object>)[0] as string; submission.contributors = (dataObj["submissionCollaborators"] as List <object>)[0] as string; var bodyObj = (dataObj["submissionJson"] as List <object>)[0] as Dictionary <string, object>; var jsonContent = (bodyObj["Items"] as List <object>)[0] as string; submission.body = "{ \"Items\" : [\"" + jsonContent + "\"] }"; context.done(submission); } catch (Exception e) { Debug.Log("Could not read submission at:" + submissionAddress + " tournament: " + tournamentAddress); Debug.Log(e); context.done(null); } } }
private static IEnumerator CoroutineUploadSubmission(RoutineContext context) { // Get accounts var requestAccounts = new EthAccountsUnityRequest(mtxNode); yield return(requestAccounts.SendRequest()); var resultsAccounts = requestAccounts.Result; var usedAccount = resultsAccounts[0]; // Try to create a peer. var createPeerFunction = platformContract.GetFunction("createPeer"); object[] createPeerParams = { }; var createPeerInput = createPeerFunction.CreateTransactionInput(usedAccount, createPeerParams); createPeerInput.Gas = new HexBigInteger(3000000); var createPeerCall = new EthSendTransactionUnityRequest(mtxNode); yield return(createPeerCall.SendRequest(createPeerInput)); try { var resultsTransaction = createPeerCall.Result; } catch (Exception e) { // Error Debug.Log("Could not check peer status"); } // tournament.entryFee(); var submission = (Submission)((object[])context.param)[0]; tournamentContract = new Contract(null, tournamentAbi, submission.tournamentAddress); var entryFeeFunction = tournamentContract.GetFunction("entryFee"); var entryFeeInput = entryFeeFunction.CreateCallInput(new object[0]); entryFeeInput.Gas = new HexBigInteger(300000); var entryFeeCall = new EthCallUnityRequest(mtxNode); yield return(entryFeeCall.SendRequest(entryFeeInput, BlockParameter.CreateLatest())); EntryFeeDTO entryFee = new EntryFeeDTO(); try { entryFee = entryFeeFunction.DecodeDTOTypeOutput <EntryFeeDTO>(entryFeeCall.Result); } catch (Exception e) { Debug.Log("Could not get tournament entry fee."); } // token.approve(tournament.address, tournament.entryFee) if (entryFee.entryFee > 0) { var tokenApproveFunction = tokenContract.GetFunction("approve"); object[] tokenClearApproveParams = { submission.tournamentAddress, 0 }; object[] tokenApproveParams = { submission.tournamentAddress, entryFee.entryFee }; var tokenClearApproveInput = tokenApproveFunction.CreateTransactionInput(usedAccount, tokenClearApproveParams); var tokenApproveInput = tokenApproveFunction.CreateTransactionInput(usedAccount, tokenApproveParams); tokenClearApproveInput.Gas = new HexBigInteger(3000000); tokenApproveInput.Gas = new HexBigInteger(3000000); var tokenClearApproveTransaction = new EthSendTransactionUnityRequest(mtxNode); var tokenApproveTransaction = new EthSendTransactionUnityRequest(mtxNode); yield return(tokenClearApproveTransaction.SendRequest(tokenClearApproveInput)); try { var tokenClearApprovalResult = tokenClearApproveTransaction.Result; } catch (Exception e) { Debug.Log("Could not approve tournament to withdraw entry fee."); } yield return(tokenApproveTransaction.SendRequest(tokenApproveInput)); try { var tokenApprovalTransactionResult = tokenApproveTransaction.Result; } catch (Exception e) { Debug.Log("Could not approve tournament to withdraw entry fee."); } } //platform.enterTournament(tournament.address) var enterTournamentFunction = platformContract.GetFunction("enterTournament"); object[] enterTournamentParams = { submission.tournamentAddress }; var enterTournamentInput = enterTournamentFunction.CreateTransactionInput(usedAccount, enterTournamentParams); enterTournamentInput.Gas = new HexBigInteger(3300000); var enterTournamentTransaction = new EthSendTransactionUnityRequest(mtxNode); yield return(enterTournamentTransaction.SendRequest(enterTournamentInput)); try { var enterTournamentTransactionResult = enterTournamentTransaction.Result; } catch (Exception e) { Debug.Log("Could not enter tournament."); } // Fix the below code // Prepare create submission var createSubmissionFunction = tournamentContract.GetFunction("createSubmission"); // Parse routine params var tournamentAddress = (submission.tournamentAddress); var title = submission.title; WWWForm form = new WWWForm(); form.AddBinaryData("description", Encoding.ASCII.GetBytes(((Submission)((object[])(context.param))[0]).title), "description.txt", "text/plain"); form.AddBinaryData("jsonContent", Encoding.ASCII.GetBytes(((Submission)((object[])(context.param))[0]).body), "jsonContent.json", "application/json"); UnityWebRequest ipfsRequest = UnityWebRequest.Post(submissionUploadEndpt, form); yield return(ipfsRequest.Send()); print("request completed with code: " + ipfsRequest.responseCode); if (ipfsRequest.isError) { print("Error: " + ipfsRequest.error); } else { print("Request Response: " + ipfsRequest.downloadHandler.text); } var response = serializer.Deserialize <object>(ipfsRequest.downloadHandler.data) as Dictionary <string, object>; var folderHash = Encoding.UTF8.GetBytes((string)response["folderHash"]); string[] contributors = { }; int[] contributorDistribution = { }; string[] references = { }; if (submission.references != string.Empty) { references = submission.references.Split(','); } if (submission.contributors != string.Empty) { contributors = submission.contributors.Split(','); contributorDistribution = Enumerable.Range(0, contributors.Length).Select(x => 1).ToArray(); } // Make input object[] inputParams = { title, usedAccount, folderHash, contributors, contributorDistribution, references }; var transactionInput = createSubmissionFunction.CreateTransactionInput(usedAccount, inputParams); transactionInput.Gas = new HexBigInteger(3000000); transactionInput.GasPrice = new HexBigInteger(20); // Do request var requestTransaction = new EthSendTransactionUnityRequest(mtxNode); yield return(requestTransaction.SendRequest(transactionInput)); // Results try { var resultsTransaction = requestTransaction.Result; // Success context.done(resultsTransaction); } catch (Exception e) { // Error Debug.Log("Could not submit submission"); //Debug.Log(e); context.done(null); } }