private static SkillModifiedValue CreateSmv(float startValue, ModificationStrategy strategy, Type skillType, LocString benefitsDescription) { SkillModifiedValue smv = new SkillModifiedValue(startValue, strategy, skillType, benefitsDescription); SkillModifiedValueManager.AddSkillBenefit(Localizer.Do("You"), smv); return(smv); }
public static void Cut(User user) { try { UserSession userSession = WorldEditManager.GetUserSession(user); WorldRange region = userSession.Selection; WorldEditCommand command = new CopyCommand(user); if (command.Invoke(region)) { user.Player.MsgLoc($"Copy done in {command.ElapsedMilliseconds}ms."); command = new SetCommand(user, "Empty"); if (command.Invoke(region)) { user.Player.MsgLoc($"{command.BlocksChanged} blocks cleared in {command.ElapsedMilliseconds}ms."); } } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
private void Add(Dictionary <Vector3i, WorldEditBlock> list, WorldEditBlock worldEditBlock) { if (!list.TryAdd(worldEditBlock.Position, worldEditBlock)) { Log.WriteLine(Localizer.Do($"Unable add {worldEditBlock.Position} to {list}")); } }
public TooltipSection MinablesTooltip(TooltipContext context) { var myHardness = this.Tier.GetCurrentValue(context.Player.User); var minableBlockTypes = Block.BlockTypesWithAttribute(typeof(Minable)).Select(x => new KeyValuePair <Type, float>(x, Block.Get <Minable>(x).Hardness)).ToList(); if (!minableBlockTypes.Any()) { return(null); } var allBlocks = AllItems.OfType <BlockItem>(); var resList = new List <LocString>(); minableBlockTypes.OrderBy(item => item.Value).ForEach(x => { var targetItem = allBlocks.FirstOrDefault(item => item.OriginType == x.Key); var hitCount = (int)Math.Ceiling(x.Value / myHardness); if (targetItem != null) { resList.Add(Localizer.Do($"{Localizer.Do($"{targetItem.UILink()}: {hitCount}")} {Localizer.Plural("hit", hitCount)}")); } }); return(new TooltipSection(Localizer.DoStr("Can mine"), resList.FoldoutListLoc("item", context.Origin))); }
public static void Replace(User user, string pTypeNames) { try { string[] splitted = pTypeNames.Trim().Split(','); string toFind = splitted[0].ToLower().Replace(" ", ""); string toReplace = string.Empty; if (splitted.Length >= 2) { toReplace = splitted[1].Trim().ToLower().Replace(" ", ""); } ReplaceCommand command = new ReplaceCommand(user, toFind, toReplace); if (command.Invoke()) { user.Player.MsgLoc($"{command.BlocksChanged} blocks changed."); } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
private static void FetchWhitelist(string url, Action <List <string>, Exception> callback) { List <string> result = null; ThreadPool.QueueUserWorkItem(ar => { Exception exception = null; try { var webRequest = WebRequest.Create(url); webRequest.Timeout = 10000; using (var response = webRequest.GetResponse()) { using (var responseStream = response.GetResponseStream()) { using (var streamReader = new StreamReader(responseStream)) result = new List <string>(streamReader .ReadToEnd() .Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)); } } } catch (Exception ex) { Log.WriteErrorLine(Localizer.Do(FormattableStringFactory.Create("{0} Error when fetching whitelist: {1} {2}", LogTag, url, (object)ex.Message))); exception = ex; } callback(result, exception); }); }
public override InteractResult OnActRight(InteractionContext context) { try { if (context.BlockPosition == null || !context.BlockPosition.HasValue) { return(InteractResult.Success); } Vector3i pos = context.BlockPosition.Value; pos.X = pos.X < 0 ? pos.X + Shared.Voxel.World.VoxelSize.X : pos.X; pos.Z = pos.Z < 0 ? pos.Z + Shared.Voxel.World.VoxelSize.Z : pos.Z; pos.X = pos.X % Shared.Voxel.World.VoxelSize.X; pos.Z = pos.Z % Shared.Voxel.World.VoxelSize.Z; UserSession userSession = WorldEditManager.GetUserSession(context.Player.User); userSession.SetSecondPosition(pos); context.Player.MsgLoc($"Second Position set to ({pos.x}, {pos.y}, {pos.z})"); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } return(InteractResult.NoOp); }
/// <summary>Return a warning text if there's any sleeping user on this bed</summary> public LocString BedPickupConfirmation() { // Try to get a sleeping player on this bes var sleepingPlayer = this.Parent.UsingPlayers.Select(p => p.Target as Player).Where(p => SleepManager.Obj.IsPlayerAsleep(p.User)).FirstOrDefault(); // return a confirmation text if there's a sleeping user return(sleepingPlayer != null?Localizer.Do($"Are you sure you want to remove {sleepingPlayer.User.UILink()}'s bed while they are sleeping in it? This is generally considered quite rude and uncouth.") : LocString.Empty); }
public TooltipSection OilTooltip(Player player) { var layer = WorldLayerManager.GetLayer(LayerNames.Oil); var pos = player.User.Position.XZi; float value = 0.0f; layer.ForRadius(layer.WorldPosToLayerPos(pos), PumpJackObject.Radius, (x, val) => value += val); return(new TooltipSection(Localizer.Do("Oil Amount"), new LocString(Text.Num(value)))); }
public void ActionPerformed(GameAction action) { try { ActionAsync(action).Wait(); } catch (Exception e) { Log.WriteLine(Localizer.Do($"[CHAT-RELAY] Error capturing GameAction {e.ToString()}")); } }
// Hit to unclaim public override InteractResult OnActLeft(InteractionContext context) { Vector2i?position = ClaimingUtils.GetClaimingPosition(context); Player player = context.Player; if (!position.HasValue) { return(InteractResult.NoOp); } var plot = PropertyManager.GetPlot(position.Value); var deed = plot?.Deed; if (deed == null) { return(ErrorAlreadyPublic); } // shift + click if (context.Modifier == InteractionModifier.Shift) { var nearbyDeeds = PropertyManager.ConnectedDeeds(player.User, position.Value)?.Distinct(); if (nearbyDeeds != null && nearbyDeeds.Count() > 0) { ClaimingUtils.ChangeWithDialog(player, nearbyDeeds, position.Value); } else { return(ErrorNoNearby); } return(InteractResult.NoOp); } // ctrl + click else if (context.Modifier == InteractionModifier.Ctrl) { DeleteWithDialog(player, deed); return(InteractResult.NoOp); // } // regular click else { var deedsAfterUnclaim = deed.GetContiguousPartsWithAlterations(null, new List <Vector2i> { position.Value }); if (deedsAfterUnclaim.Count > 1) { this.ConfirmUnclaim(player, Localizer.Do($"Unclaiming this plot will split {deed.Name} into {deedsAfterUnclaim.Count()} because property must be contiguous on a deed. Do you want to continue?"), position.Value); return(InteractResult.NoOp); } var result = (InteractResult)PropertyManager.TryUnclaim(new GameActionPack(), player.User, player.User.Inventory, position.Value, autoPerform: true); return(result); } }
public static void RmWand(User user) { try { user.Inventory.TryRemoveItems(WorldEditManager.GetWandItemStack()); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public void Initialize() { string steam2discord = File.ReadAllText("/app/Mods/Crossing/steam2discord.json"); SteamToDiscord = JsonConvert.DeserializeObject <Dictionary <string, string> >(steam2discord); Log.WriteLine(Localizer.Do($"Found {SteamToDiscord.Count} in SteamToDiscord")); string discord2steam = File.ReadAllText("/app/Mods/Crossing/discord2steam.json"); DiscordToSteam = JsonConvert.DeserializeObject <Dictionary <string, string> >(discord2steam); Log.WriteLine(Localizer.Do($"Found {DiscordToSteam.Count} in DiscordToSteam")); }
public static void Undo(User user, int count = 1) { try { UserSession userSession = WorldEditManager.GetUserSession(user); if (userSession.ExecutingCommand != null && userSession.ExecutingCommand.IsRunning) { throw new WorldEditCommandException("You can't use undo right now!"); //TODO: Probably need to rework that and impliment aborting } if (count > userSession.ExecutedCommands.Count) { count = userSession.ExecutedCommands.Count; } if (count.Equals(0)) { throw new WorldEditCommandException("Nothing to undo"); } for (int i = 1; i <= count; i++) { if (userSession.ExecutedCommands.TryPop(out WorldEditCommand command)) { userSession.ExecutingCommand = command; if (command.Undo()) { if (count.Equals(1)) { user.Player.MsgLoc($"Undo done."); break; } else { user.Player.MsgLoc($"Undo {i}/{count} done."); } } userSession.ExecutingCommand = null; } else { throw new WorldEditCommandException("Nothing to undo"); } } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public static void Reset(User user) { try { UserSession session = WorldEditManager.GetUserSession(user); session.ResetSelection(); user.Player.MsgLoc($"WorldEdit: Positions reset"); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public static async void DeleteWithDialog(Player player, Deed deed) { try { if (await player?.ConfirmBox(Localizer.Do($"Do you wish to completely unclaim {deed?.MarkedUpName}?"))) { deed?.DeleteDeed(player); } } catch (Exception e) { Log.WriteException(e); } }
public static void Distr(User user, string type = "brief", string fileName = null) { type = type.Replace(" ", "").Trim(); if (type.Contains("brief")) { type = "brief"; } if (type.Contains("detail")) { type = "detail"; } switch (type) { case "brief": case "b": type = "brief"; break; case "detail": case "d": type = "detail"; break; default: type = "brief"; break; } if (!string.IsNullOrEmpty(fileName)) { fileName = fileName.Replace(" ", string.Empty).Trim(); } try { WorldEditCommand command = new DistrCommand(user, type, fileName); if (command.Invoke()) { //Output done in he command } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public string GetEcopediaData(Player player, EcopediaPage page) { var i = 0; var penalties = HousingCalculation.OccupancyPenalties; if (penalties == null) { return(string.Empty); } var list = penalties.Skip(1).Take(penalties.Count() - 2) .Select(x => $"{Text.PluralLocStr(Localizer.DoStr("Occupant"), "Occupants", i++)}: {Text.StyledPercent(x)}") .Append(Localizer.Do($"{penalties.Count() - 1} or more Occupants: {Text.StyledPercent(penalties.Last())}")); return(list.MakeListLoc($"Occupancy Penalties:", false)); }
/// <summary> /// This Method should override the CreateLevelUpAction() Method of Skills that can be superskilled. /// Just place the Example code in the code of superskillable Skills. /// </summary> /// <example> /// <code> ///public override IAtomicAction CreateLevelUpAction(Player player) ///{ /// return SkillUtils.SuperSkillLevelUp(this, player); ///} /// </code> /// </example> /// <seealso cref="Skill.CreateLevelUpAction(Player)"/> /// <param name="skill"></param> /// <param name="player"></param> /// <returns></returns> public static IAtomicAction SuperSkillLevelUp(Skill skill, Player player) { if (skill.Level != 5) { return(SimpleAtomicAction.NoOp); } if (SkillUtils.SuperSkillCount(player.User) >= REYmodSettings.Obj.Config.Maxsuperskills) { return(new FailedAtomicAction(Localizer.Do("You already have enough SuperSkills " + SkillUtils.SuperSkillCount(player.User) + "/" + REYmodSettings.Obj.Config.Maxsuperskills))); } if (CheckSuperskillConfirmation(player.User)) { superskillconfirmed.Remove(player.User.ID); return(SimpleAtomicAction.NoOp); } SkillUtils.ShowSuperSkillInfo(player); return(new FailedAtomicAction(Localizer.Do("You need to confirm first"))); }
public static void Selclaim(User user) { try { Vector3i pos = user.Position.Round; Vector2i claimPos = PlotUtil.NearestPlotPosInWorld(pos.XZ); UserSession session = WorldEditManager.GetUserSession(user); session.SetFirstPosition(claimPos.X_Z(pos.Y - 1)); session.SetSecondPosition(WorldEditUtils.SecondPlotPos(claimPos).X_Z(pos.Y - 1)); user.Player.MsgLoc($"First Position set to {session.Selection.min}"); user.Player.MsgLoc($"Second Position set to {session.Selection.max}"); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public static void Grow(User user) { try { WorldEditCommand command = new GrowCommand(user); if (command.Invoke()) { user.Player.MsgLoc($"Grow done."); } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public static void Shift(User user, string directionAndAmount = "1") { try { SelectionCommand command = SelectionCommand.ShiftCommand(user, directionAndAmount); if (command.Invoke()) { user.Player.MsgLoc($"Shifted selection {command.amount} {command.direction}"); } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public static void Rotate(User user, int degrees = 90) { try { WorldEditCommand command = new RotateCommand(user, degrees); if (command.Invoke()) { user.Player.MsgLoc($"Rotation in clipboard done."); } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public static void Paste(User user) { try { WorldEditCommand command = new PasteCommand(user); if (command.Invoke()) { user.Player.MsgLoc($"Paste done in {command.ElapsedMilliseconds}ms."); } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public async Task InitializeAsync(DiscordSocketClient discord) { _client = discord; _client.Log += LogAsync; _client.Ready += ReadyAsync; _client.MessageReceived += MessageReceivedAsync; try { await _client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("ISABELLE_TOKEN")); await _client.StartAsync(); Log.WriteLine(Localizer.Do($"[ISABELLE] Succesfully logged in to Discord")); } catch (Exception e) { Log.WriteLine(Localizer.Do($"[ISABELLE] Error logging in to Discord {e.ToString()}")); } }
public static void Delete(User user) { try { SetCommand command = new SetCommand(user, "Empty"); if (command.Invoke()) { user.Player.MsgLoc($"{command.BlocksChanged} blocks cleared in {command.ElapsedMilliseconds}ms."); } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public static void Export(User user, string fileName) { try { WorldEditCommand command = new ExportCommand(user, fileName); if (command.Invoke()) { user.Player.MsgLoc($"Export done in {command.ElapsedMilliseconds}ms."); } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public static void Up(User user, int count = 1) { try { WorldEditCommand command = new UpCommand(user, count); if (command.Invoke()) { //Silence? } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public static void Move(User user, string directionAndAmount = "1") { try { MoveCommand command = new MoveCommand(user, directionAndAmount); if (command.Invoke()) { user.Player.MsgLoc($"{command.BlocksChanged} blocks moved."); } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }
public static void SetPos2(User user) { try { Vector3 pos = user.Position; pos.X = pos.X < 0 ? pos.X + Shared.Voxel.World.VoxelSize.X : pos.X; pos.Z = pos.Z < 0 ? pos.Z + Shared.Voxel.World.VoxelSize.Z : pos.Z; pos.X = pos.X % Shared.Voxel.World.VoxelSize.X; pos.Z = pos.Z % Shared.Voxel.World.VoxelSize.Z; UserSession session = WorldEditManager.GetUserSession(user); session.SetSecondPosition(pos.Round); user.Player.MsgLoc($"Second Position set to {pos}"); } catch (Exception e) { Log.WriteError(Localizer.Do($"{e}")); } }