public static bool TryWhileCILNoDebug(CommandQueue queue, int entry_ind, IntegerTag integer) { WhileCommandData dat = queue.CurrentRunnable.EntryData[entry_ind] as WhileCommandData; integer.Internal = ++dat.Index; return(IfCommand.TryIf(queue, null, new List <Argument>(dat.ComparisonArgs))); }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { try { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1)); if (num == null) { queue.HandleError(entry, "Invalid amount number!"); return; } PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); if (player == null) { queue.HandleError(entry, "Invalid player!"); return; } player.Internal.player.life.askWarm((uint)num.Internal); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully adjusted the warmth level of a player!"); } } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, "Failed to adjust player's warmth level: " + ex.ToString()); } }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.AggregatorConfigResponsePayload.MaxLevelTagType: return(_maxLevel = GetIntegerTag(childTag)); case Constants.AggregatorConfigResponsePayload.AggregationAlgorithmTagType: return(_aggregationAlgorithm = GetIntegerTag(childTag)); case Constants.AggregatorConfigResponsePayload.AggregationPeriodTagType: return(_aggregationPeriod = GetIntegerTag(childTag)); case Constants.AggregatorConfigResponsePayload.MaxRequestsTagType: return(_maxRequests = GetIntegerTag(childTag)); case Constants.AggregatorConfigResponsePayload.ParentUriTagType: StringTag uriTag = GetStringTag(childTag); ParentsUris.Add(uriTag.Value); return(uriTag); default: return(base.ParseChild(childTag)); } }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.AggregationHashChain.AggregationTimeTagType: return(_aggregationTime = GetIntegerTag(childTag)); case Constants.AggregationHashChain.ChainIndexTagType: IntegerTag chainIndexTag = GetIntegerTag(childTag); _chainIndex.Add(chainIndexTag); return(chainIndexTag); case Constants.AggregationHashChain.InputDataTagType: return(_inputData = GetRawTag(childTag)); case Constants.AggregationHashChain.InputHashTagType: return(_inputHash = GetImprintTag(childTag)); case Constants.AggregationHashChain.AggregationAlgorithmIdTagType: IntegerTag aggrAlgorithmTag = GetIntegerTag(childTag); _aggrAlgorithm = HashAlgorithm.GetById((byte)aggrAlgorithmTag.Value); return(aggrAlgorithmTag); case (uint)LinkDirection.Left: case (uint)LinkDirection.Right: Link linkTag = childTag as Link ?? new Link(childTag); _links.Add(linkTag); return(linkTag); default: return(base.ParseChild(childTag)); } }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1)); if (num.Internal <= 0) { queue.HandleError(entry, "Must provide a number that is greater than 0!"); return; } EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0)); if (entity == null) { queue.HandleError(entry, "Invalid entity!"); return; } ZombieTag zombie; if (entity.TryGetZombie(out zombie)) { Zombie inZomb = zombie.Internal; inZomb.maxHealth = (ushort)num.Internal; if (inZomb.health > inZomb.maxHealth) { inZomb.health = inZomb.maxHealth; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully set health of a zombie to " + inZomb.maxHealth + "!"); } return; } PlayerTag player; if (entity.TryGetPlayer(out player)) { GameObject playerObj = player.Internal.player.gameObject; UFMHealthController controller = playerObj.GetComponent <UFMHealthController>(); if (controller == null) { controller = playerObj.AddComponent <UFMHealthController>(); } controller.maxHealth = (uint)num.Internal; PlayerLife life = player.Internal.player.life; byte curr = life.health; controller.health = curr >= controller.maxHealth ? controller.maxHealth : curr; life._health = controller.Translate(); life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { life.health }); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully set max health of a player to " + controller.maxHealth + "!"); } return; } queue.HandleError(entry, "That entity can't be healed!"); }
public int GetAttributeI(string attr, int def) { if (Attributes.TryGetValue(attr, out TemplateObject outp)) { return((int)IntegerTag.TryFor(outp).Internal); } return(def); }
public void TestIntegerTagToString() { IntegerTag tag = new IntegerTag(0x1, false, false, 10); Assert.AreEqual("TLV[0x1]:i10", tag.ToString(), "Tag unsigned long representation should be correct"); tag = new IntegerTag(0x1, true, true, 11); Assert.AreEqual("TLV[0x1,N,F]:i11", tag.ToString(), "Tag unsigned long representation should be correct"); }
/// <summary>Converts a script object type to a specific raw type (if possible) for the ConfigSet command.</summary> public static object ConvertForType(Type fieldType, TemplateObject input, CommandQueue queue) { if (fieldType == typeof(string)) { return(input.ToString()); } else if (fieldType == typeof(bool)) { return(BooleanTag.TryFor(input)?.Internal); } else if (fieldType == typeof(long)) { return(IntegerTag.TryFor(input)?.Internal); } else if (fieldType == typeof(int)) { IntegerTag integer = IntegerTag.TryFor(input); if (integer is not null) { return((int)integer.Internal); } } else if (fieldType == typeof(short)) { IntegerTag integer = IntegerTag.TryFor(input); if (integer is not null) { return((short)integer.Internal); } } else if (fieldType == typeof(byte)) { IntegerTag integer = IntegerTag.TryFor(input); if (integer is not null) { return((byte)integer.Internal); } } else if (fieldType == typeof(double)) { return(NumberTag.TryFor(input)?.Internal); } else if (fieldType == typeof(float)) { NumberTag number = NumberTag.TryFor(input); if (number is not null) { return((float)number.Internal); } } else { queue.HandleError($"Cannot convert script objects to config type {TextStyle.SeparateVal(fieldType.Name)}"); } return(null); }
public void TestIntegerTagEquals() { IntegerTag tag = new IntegerTag(0x1, false, false, 10); Assert.AreEqual(new IntegerTag(0x1, false, false, 10), tag, "Tag Equals function should compare correctly"); Assert.IsTrue(tag.Equals(tag), "Tags should be equal"); Assert.IsTrue(tag == new IntegerTag(0x1, false, false, 10), "Tag should compare correctly with other objects"); Assert.IsTrue(tag != new ChildIntegerTag(0x1, false, false, 10), "Tag should compare correctly with other objects"); Assert.IsFalse(tag.Equals(new StringTag(0x1, false, false, "test")), "Tag Equals function should compare correctly with other objects"); Assert.IsFalse(tag.Equals(new object()), "Tag Equals function should compare correctly with other objects"); }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { IntegerTag itag = IntegerTag.TryFor(entry.GetArgumentObject(queue, 0)); uint ti = (uint)itag.Internal; SDG.Unturned.LightingManager.time = ti; if (entry.ShouldShowGood(queue)) { entry.Good(queue, "World time set to " + ti + "!"); } }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.PduPayload.RequestIdTagType: return(_requestId = GetIntegerTag(childTag)); default: return(base.ParseChild(childTag)); } }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.PublicationData.PublicationTimeTagType: return(_publicationTime = GetIntegerTag(childTag)); case Constants.PublicationData.PublicationHashTagType: return(_publicationHash = GetImprintTag(childTag)); default: return(base.ParseChild(childTag)); } }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.ExtendResponsePayload.LastTimeTagType: return(_calendarLastTime = GetIntegerTag(childTag)); case Constants.CalendarHashChain.TagType: return(CalendarHashChain = childTag as CalendarHashChain ?? new CalendarHashChain(childTag)); default: return(base.ParseChild(childTag)); } }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.PduPayload.StatusTagType: return(_status = GetIntegerTag(childTag)); case Constants.PduPayload.ErrorMessageTagType: return(_errorMessage = GetStringTag(childTag)); default: return(base.ParseChild(childTag)); } }
/// <summary>Executes the numbered input part of the repeat command, without debug.</summary> /// <param name="queue">The command queue involved.</param> /// <param name="entry">Entry to be executed.</param> public static bool TryRepeatNumberedCIL_NoDebug(CommandQueue queue, CommandEntry entry) { int target = (int)IntegerTag.TryFor(entry.GetArgumentObject(queue, 0)).Internal; if (target <= 0) { return(false); } entry.SetData(queue, new RepeatCommandData() { Index = 1, Total = target }); return(true); }
public void TestIntegerTagCreateFromTag() { RawTag rawTag = new RawTag(0x1, false, false, new byte[] { 0x1 }); IntegerTag tag = new IntegerTag(rawTag); Assert.AreEqual(0x1, tag.Type, "Tag type should be correct"); Assert.IsFalse(tag.NonCritical, "Tag non critical flag should be correct"); Assert.IsFalse(tag.Forward, "Tag forward flag should be correct"); Assert.AreEqual(1, tag.Value, "Tag value should be decoded correctly"); Assert.AreEqual("TLV[0x1]:i1", tag.ToString(), "Tag string representation should be correct"); IntegerTag newTag = new IntegerTag(rawTag); Assert.AreEqual(newTag, tag, "Value should be equal"); }
public static RecipeTag For(Server tserver, TagData data, TemplateObject input) { if (input is RecipeTag) { return((RecipeTag)input); } int ind = (int)IntegerTag.For(data, input).Internal; if (ind < 0 || ind >= tserver.Recipes.Recipes.Count) { data.Error("Invalid recipe input!"); return(null); } return(new RecipeTag(tserver.Recipes.Recipes[ind])); }
public override TemplateObject Handle(TagData data) { if (data.Remaining == 0) { return(this); } switch (data[0]) { case "items": { List <TemplateObject> list = new List <TemplateObject>(); foreach (Items items in Internal) { for (byte i = 0; i < items.getItemCount(); i++) { ItemJar item = items.getItem(i); list.Add(new ItemTag(item)); } } return(new ListTag(list).Handle(data)); } case "item": { long index = IntegerTag.For(data, data.GetModifierObject(0)).Internal; int curr = 0; byte size; while (index >= (size = Internal[curr].getItemCount())) { curr++; if (curr == Internal.Length) { curr--; index = Internal[curr].getItemCount() - 1; break; } else { index -= size; } } return(new ItemTag(Internal[curr].getItem((byte)index))); } default: return(new TextTag(ToString()).Handle(data)); } }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.PduHeader.LoginIdTagType: return(_loginId = GetStringTag(childTag)); case Constants.PduHeader.InstanceIdTagType: return(_instanceId = GetIntegerTag(childTag)); case Constants.PduHeader.MessageIdTagType: return(_messageId = GetIntegerTag(childTag)); default: return(base.ParseChild(childTag)); } }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.PduPayload.RequestIdTagType: return(_requestId = GetIntegerTag(childTag)); case Constants.AggregationRequestPayload.RequestHashTagType: return(_requestHash = GetImprintTag(childTag)); case Constants.AggregationRequestPayload.RequestLevelTagType: return(_requestLevel = GetIntegerTag(childTag)); default: return(base.ParseChild(childTag)); } }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.PduPayload.RequestIdTagType: return(_requestId = GetIntegerTag(childTag)); case Constants.ExtendRequestPayload.AggregationTimeTagType: return(_aggregationTime = GetIntegerTag(childTag)); case Constants.ExtendRequestPayload.PublicationTimeTagType: return(_publicationTime = GetIntegerTag(childTag)); default: return(base.ParseChild(childTag)); } }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.PublicationsFileHeader.VersionTagType: return(_version = GetIntegerTag(childTag)); case Constants.PublicationsFileHeader.CreationTimeTagType: return(_creationTime = GetIntegerTag(childTag)); case Constants.PublicationsFileHeader.RepositoryUriTagType: return(_repositoryUri = GetStringTag(childTag)); default: return(base.ParseChild(childTag)); } }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 2)); if (num == null) { queue.HandleError(entry, "Invalid amount number!"); return; } PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); if (player == null) { queue.HandleError(entry, "Invalid player!"); return; } bool award = entry.GetArgument(queue, 1) == "award"; if (num.Internal > 0) { PlayerSkills skills = player.Internal.player.skills; if (award) { skills._experience += (uint)num.Internal; } else { skills._experience -= (uint)num.Internal; } skills.channel.send("tellExperience", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { skills.experience }); } else { queue.HandleError(entry, "Amount must be positive!"); return; } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully " + (award ? "awarded experience to" : "took experience from") + " a player!"); } }
/// <summary>Executes the command.</summary> /// <param name="queue">The command queue involved.</param> /// <param name="entry">Entry to be executed.</param> public static void Execute(CommandQueue queue, CommandEntry entry) { int count = 1; if (entry.Arguments.Length > 0) { IntegerTag inter = IntegerTag.TryFor(entry.GetArgumentObject(queue, 0)); if (inter != null) { count = (int)inter.Internal; } } if (count <= 0) { ShowUsage(queue, entry); return; } for (int i = 0; i < count; i++) { CompiledCommandRunnable runnable = queue.CurrentRunnable; for (int ind = runnable.Index; ind < runnable.Entry.Entries.Length; ind++) { CommandEntry tentry = runnable.Entry.Entries[ind]; if (tentry.Command.Meta.IsBreakable && tentry.IsCallback) { runnable.Index = ind + 1; goto completed; } } if (queue.RunningStack.Count > 1) { queue.RunningStack.Pop(); } else { queue.HandleError(entry, "Not in that many blocks!"); return; } completed: continue; } entry.GoodOutput(queue, "Broke free successfully."); }
/// <summary>Executes the callback part of the while command.</summary> /// <param name="queue">The command queue involved.</param> /// <param name="entry">Entry to be executed.</param> /// <param name="integer">While Index holder.</param> public static bool TryWhileCIL(CommandQueue queue, CommandEntry entry, IntegerTag integer) { WhileCommandData dat = queue.CurrentRunnable.EntryData[entry.BlockStart - 1] as WhileCommandData; integer.Internal = ++dat.Index; if (IfCommand.TryIf(queue, entry, new List <Argument>(dat.ComparisonArgs))) { if (entry.ShouldShowGood(queue)) { entry.GoodOutput(queue, "While looping: " + TextStyle.Separate + dat.Index + TextStyle.Base + "..."); } return(true); } if (entry.ShouldShowGood(queue)) { entry.GoodOutput(queue, "While stopping."); } return(false); }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.Rfc3161Record.AggregationTimeTagType: return(_aggregationTime = GetIntegerTag(childTag)); case Constants.Rfc3161Record.ChainIndexTagType: IntegerTag chainTag = GetIntegerTag(childTag); _chainIndex.Add(chainTag); return(chainTag); case Constants.Rfc3161Record.InputHashTagType: return(_inputHash = GetImprintTag(childTag)); case Constants.Rfc3161Record.TstInfoPrefixTagType: return(_tstInfoPrefix = GetRawTag(childTag)); case Constants.Rfc3161Record.TstInfoSuffixTagType: return(_tstInfoSuffix = GetRawTag(childTag)); case Constants.Rfc3161Record.TstInfoAlgorithmTagType: IntegerTag tstInfoAlgorithmTag = GetIntegerTag(childTag); _tstInfoAlgorithm = HashAlgorithm.GetById((byte)tstInfoAlgorithmTag.Value); return(tstInfoAlgorithmTag); case Constants.Rfc3161Record.SignedAttributesPrefixTagType: return(_signedAttributesPrefix = GetRawTag(childTag)); case Constants.Rfc3161Record.SignedAttributesSuffixTagType: return(_signedAttributesSuffix = GetRawTag(childTag)); case Constants.Rfc3161Record.SignedAttributesAlgorithmTagType: IntegerTag signedAttributesAlgorithmTag = GetIntegerTag(childTag); _signedAttributesAlgorithm = HashAlgorithm.GetById((byte)signedAttributesAlgorithmTag.Value); return(signedAttributesAlgorithmTag); default: return(base.ParseChild(childTag)); } }
/// <summary> /// Parse child element /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.AggregationHashChain.Link.LevelCorrectionTagType: return(_levelCorrection = GetIntegerTag(childTag)); case Constants.AggregationHashChain.Link.SiblingHashTagType: return(_siblingHash = GetImprintTag(childTag)); case Constants.AggregationHashChain.Link.LegacyId: _legacyId = GetRawTag(childTag); _legacyIdString = GetLegacyIdString(_legacyId.Value); return(_legacyId); case Constants.AggregationHashChain.Metadata.TagType: return(_metadata = childTag as Metadata ?? new Metadata(childTag)); default: return(base.ParseChild(childTag)); } }
public static TemplateObject TOFor(Server tserver, string type, string content) { switch (type) { case "text": return(new TextTag(content)); //case "item": // return ItemTag.For(tserver, content); case "numb": return(NumberTag.TryFor(content)); case "inte": return(IntegerTag.TryFor(content)); case "bool": return(BooleanTag.TryFor(content)); default: return(new TextTag(content)); // Disregard errors and just make it text anyway. Probably just bad user input. } }
/// <summary> /// Parse child tag /// </summary> protected override ITlvTag ParseChild(ITlvTag childTag) { switch (childTag.Type) { case Constants.ExtenderConfigResponsePayload.MaxRequestsTagType: return(_maxRequests = GetIntegerTag(childTag)); case Constants.ExtenderConfigResponsePayload.ParentUriTagType: StringTag uriTag = GetStringTag(childTag); ParentsUris.Add(uriTag.Value); return(uriTag); case Constants.ExtenderConfigResponsePayload.CalendarFirstTimeTagType: return(_calendarFirstTime = GetIntegerTag(childTag)); case Constants.ExtenderConfigResponsePayload.CalendarLastTimeTagType: return(_calendarLastTime = GetIntegerTag(childTag)); default: return(base.ParseChild(childTag)); } }
private static AggregationHashChain.Link CreateLinkWithLevelCorrection(AggregationHashChain.Link link, ulong levelCorrection) { TlvTagBuilder builder = new TlvTagBuilder(link); IntegerTag levelCorrectionTag = builder.GetChildByType(Constants.AggregationHashChain.Link.LevelCorrectionTagType) as IntegerTag; if (levelCorrectionTag != null) { IntegerTag newLevelCorrectionTag = new IntegerTag( levelCorrectionTag.Type, levelCorrectionTag.NonCritical, levelCorrectionTag.Forward, levelCorrection); builder.ReplaceChildTag(levelCorrectionTag, newLevelCorrectionTag); } else { builder.AddChildTag(new IntegerTag(Constants.AggregationHashChain.Link.LevelCorrectionTagType, false, false, levelCorrection)); } return(new AggregationHashChain.Link(builder.BuildTag())); }