public async Task GoToAsync(int x, int y) { if (!Engine.CanMove(Context.Husk, out string notification)) { await Context.Channel.SendMessageAsync("You are currently in transit and cannot perform any actions."); return; } if (!string.IsNullOrWhiteSpace(notification)) { Context.Account.Notifier.Append(notification); } TravelResult result = Engine.TryGoTo(Context.Husk, x, y, out Destination attempted); switch (result) { case TravelResult.Start: StringBuilder travel = new StringBuilder(); travel.AppendLine($"Now travelling to (**{attempted.X}**, **{attempted.Y}**) in **{attempted.GetInnerName()}**."); Destination info = Context.Husk.Destination; travel.Append($"Arrival In: {Format.Counter((info.Arrival - info.StartedAt).TotalSeconds)}"); await Context.Channel.SendMessageAsync(travel.ToString()); break; case TravelResult.Instant: var location = attempted.GetLocation(); if (location?.Exterior != null) { await Context.Channel.SendFileAsync(location.Exterior.Path, $"You have reached (**{attempted.X}**, **{attempted.Y}**)."); } else { await Context.Channel.SendMessageAsync($"You have reached (**{attempted.X}**, **{attempted.Y}**)."); } break; default: await Context.Channel.SendMessageAsync("I'm sorry, but I could not pinpoint the coordinates you were referring to. Did you by any chance mistype?"); break; } }
private InaraResponse ProcessResponse(Response response) { if (response?.Header == null) { return new InaraResponse { Status = ResponseStatus.Unprocessed } } ; var result = new InaraResponse { Status = response.Header.Status, StatusText = response.Header.StatusText, User = response.Header.Data }; if (response.Events == null || response.Events.Length == 0) { return(result); } foreach (var requestEvent in Request.Events) { // try match request and response var responseEvent = response.Events.FirstOrDefault(e => e.Id == requestEvent.Id); switch (requestEvent.Name) { case "getCommanderProfile": result.Events.Add(CommanderResult.Process(responseEvent, _inara)); break; case "addCommanderShip": case "setCommanderShip": case "setCommanderShipTransfer": result.Events.Add(ShipResult.Process(responseEvent, _inara)); break; case "addCommanderTravelDock": case "addCommanderTravelFSDJump": case "setCommanderTravelLocation": result.Events.Add(TravelResult.Process(responseEvent, _inara)); break; case "getCommunityGoalsRecent": break; default: result.Events.Add(new EventResult { Name = requestEvent.Name, Status = responseEvent?.Status ?? ResponseStatus.OK, StatusText = responseEvent?.StatusText }); break; } } return(result); } }
public async Task GoToAsync(string id) { if (!Engine.CanMove(Context.Husk, out string notification)) { await Context.Channel.SendMessageAsync("You are currently in transit and cannot perform any actions."); return; } if (!string.IsNullOrWhiteSpace(notification)) { Context.Account.Notifier.Append(notification); } if (Context.Husk.Location.GetInnerType() == LocationType.Sector) { TravelResult result = Engine.TryGoToInSector(Context.Husk, Context.Brain, id, out Region attempted); switch (result) { case TravelResult.Start: var travel = new StringBuilder(); travel.AppendLine($"Now travelling to **{attempted.Name}**."); Destination info = Context.Husk.Destination; travel.Append($"Arrival In: {Format.Counter((info.Arrival - info.StartedAt).TotalSeconds)}"); await Context.Channel.SendMessageAsync(travel.ToString()); break; case TravelResult.Instant: // if (attempted.Exterior != null) // await Context.Channel.SendFileAsync(attempted.Exterior.Path, $"Welcome to **{attempted.Name}**."); //else await Context.Channel.SendMessageAsync($"Welcome to **{attempted.Name}**."); break; case TravelResult.Invalid: default: await Context.Channel.SendMessageAsync("I'm sorry, but I could not find the location you were referring to. Did you by any chance misspell?"); break; } } else { TravelResult result = Engine.TryGoTo(Context.Husk, Context.Brain, id, out Region attempted); Construct construct = attempted as Construct; switch (result) { case TravelResult.Instant: if (construct.Exterior != null) { await Context.Channel.SendFileAsync(construct.Exterior.Path, $"Welcome to **{construct.Name}**."); } else { await Context.Channel.SendMessageAsync($"Welcome to **{construct.Name}**."); } break; case TravelResult.Closed: if (construct.Tag.HasFlag(ConstructType.Market)) { await Context.Channel.SendMessageAsync($"**{construct.Name}** is currently closed. Come back in **{(((Market)construct).GetNextBlock(DateTime.UtcNow).From - DateTime.UtcNow).ToString(@"hh\:mm\:ss")}**."); } else { await Context.Channel.SendMessageAsync($"**{construct.Name}** is currently closed."); } break; default: await Context.Channel.SendMessageAsync("I'm sorry, but I could not find the location you were referring to. Did you by any chance misspell?"); break; } } }
public async Task <IActionResult> PostTraveling([FromBody] PassedGameData <int> passedData) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DateTime now = DateTime.UtcNow; if (passedData.UserToken == null || passedData.ActionToken == null) { return(BadRequest(new DataError("securityErr", "No authorization controll."))); } UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken); if (dbtoken == null) { return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change."))); } else { if (!dbtoken.IsTimeValid(now)) { return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required."))); } else { dbtoken.UpdateToken(now); } } Heros hero = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName); ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId); if (gametoken == null) { return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change."))); } else { if (!gametoken.IsTimeValid(now)) { return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required."))); } else { gametoken.UpdateToken(now); } } // if can go there if (hero.Status == 0) { var location = _context.HerosLocations.FirstOrDefault(e => (e.HeroId == hero.HeroId) && (e.LocationIdentifier == hero.CurrentLocation)); if (location == null) { return(BadRequest(new DataError("LocationErr", "Location is not available."))); } var descr = _context.LocationsDb.FirstOrDefault(e => e.LocationIdentifier == location.LocationIdentifier); if (descr == null) { return(BadRequest(new DataError("LocationErr", "LocationData is not available."))); } try { // TODO check location type AstarResult astar = null; int TravelScale = 0; int Start = -1; string StartName = ""; int Target = -1; string TargetName = ""; int LocationType = descr.LocationGlobalType; if (LocationType != 2) { LocationDescription description = JsonConvert.DeserializeObject <LocationDescription>(descr.Sketch); LocationState state = JsonConvert.DeserializeObject <LocationState>(location.Description); description.LocationGlobalType = descr.LocationGlobalType; int GlobalNodeID = description.GlobalMainNodeID(passedData.Data, state); if (GlobalNodeID == state.CurrentLocation) { throw new Exception("Moving nowhere"); } astar = LocationHandler.DistanceToMove(description, state, passedData.Data); TravelScale = description.TravelScale; Start = state.CurrentLocation; StartName = description.MainNodes.First(e => e.NodeID == state.CurrentLocation).Name; Target = GlobalNodeID; TargetName = description.MainNodes.First(e => e.NodeID == GlobalNodeID).Name; } else { InstanceDescription description = JsonConvert.DeserializeObject <InstanceDescription>(descr.Sketch); InstanceState state = JsonConvert.DeserializeObject <InstanceState>(location.Description); description.LocationGlobalType = descr.LocationGlobalType; int GlobalNodeID = description.GlobalMainNodeID(passedData.Data, state); if (GlobalNodeID == state.CurrentLocation) { throw new Exception("Moving nowhere"); } astar = LocationHandler.DistanceToMove(description, state, passedData.Data); TravelScale = description.TravelScale; Start = state.CurrentLocation; Target = GlobalNodeID; TargetName = passedData.Data.ToString(); } double TravelTime = LocationHandler.TimeTravel(astar.Distance, TravelScale, 18 * hero.VelocityFactor); Traveling travel = new Traveling() { EndTime = now.AddSeconds(TravelTime), HeroId = hero.HeroId, IsReverse = false, ReverseTime = null, Start = Start, StartName = StartName, StartTime = now, Target = Target, TargetName = TargetName, }; hero.Status = 1; _context.Traveling.Add(travel); TravelResult travelResult = travel.GenTravelResult(now); try { await _context.SaveChangesAsync(); return(Ok(new { success = true, travel = travelResult })); } catch (DbUpdateException) { return(BadRequest(new DataError("databaseErr", "Failed to remember travel."))); } } catch { return(BadRequest(new DataError("LocationErr", "Location is not available."))); } } else { return(BadRequest(new DataError("LocationErr", "Hero is not able to travel."))); } }
public async Task <IActionResult> PostTraveling([FromBody] PassedGameData <int?> passedData) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DateTime now = DateTime.UtcNow; if (passedData.UserToken == null || passedData.ActionToken == null) { return(BadRequest(new DataError("securityErr", "No authorization controll."))); } UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken); if (dbtoken == null) { return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change."))); } else { if (!dbtoken.IsTimeValid(now)) { return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required."))); } else { dbtoken.UpdateToken(now); } } Heros hero = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName); ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId); if (gametoken == null) { return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change."))); } else { if (!gametoken.IsTimeValid(now)) { return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required."))); } else { gametoken.UpdateToken(now); } } // if can go there if (hero.Status == 1) { try { var Travel = _context.Traveling.FirstOrDefault(e => e.HeroId == hero.HeroId); if (Travel == null || Travel.HasEnded(now) || Travel.IsReverse) { throw new Exception(); } Travel.IsReverse = true; Travel.ReverseTime = now; TravelResult travelResult = Travel.GenTravelResult(now); try { await _context.SaveChangesAsync(); return(Ok(new { success = true, travel = travelResult })); } catch (DbUpdateException) { return(BadRequest(new DataError("databaseErr", "Failed to remember travel."))); } } catch { return(BadRequest(new DataError("TravelErr", "Travel reverse is not available."))); } } else { return(BadRequest(new DataError("LocationErr", "Hero is not in the travel."))); } }