public static void SerializeLegacy(ThingType thingType, Net.OutputMessage binaryWriter, int startPhase, int phasesLimit) { binaryWriter.AddU8(1); binaryWriter.AddS32(thingType.HasAttribute(AttributesUniform.AnimateAlways) || thingType.Category == ThingCategory.Item ? 0 : 1); binaryWriter.AddU8(0); int duration; if (thingType.Category == ThingCategory.Effect) { duration = 75; } else { duration = phasesLimit > 0 ? 1000 / phasesLimit : 40; } for (int i = 0; i < phasesLimit; i++) { binaryWriter.AddS32(duration); // force legacy animation binaryWriter.AddS32(duration); } }
/// <summary> /// Generates protobuf appearance from the legacy thingtype /// </summary> /// <param name="thingType">thing generated from tibia.dat (old revisions)</param> /// <returns></returns> static Appearance GenerateAppearance(Core.Sprites.ThingType thingType) { Appearance appearance = new Appearance() { Id = thingType.ID, }; if (thingType.Attributes.Count > 0) { appearance.Flags = new AppearanceFlags(); } // Flags if (thingType.HasAttribute(AttributesUniform.Ground)) { appearance.Flags.Ground = new Ground() { Speed = (ushort)thingType.Attributes[AttributesUniform.Ground] } } ; if (thingType.HasAttribute(AttributesUniform.Writable)) { appearance.Flags.Writable = new Writable() { Length = (ushort)thingType.Attributes[AttributesUniform.Writable] } } ; if (thingType.HasAttribute(AttributesUniform.WritableOnce)) { appearance.Flags.WritableOnce = new Writable() { Length = (ushort)thingType.Attributes[AttributesUniform.WritableOnce] } } ; if (thingType.HasAttribute(AttributesUniform.MinimapColor)) { appearance.Flags.Minimap = new MiniMap() { Color = (ushort)thingType.Attributes[AttributesUniform.MinimapColor] } } ; if (thingType.HasAttribute(AttributesUniform.Elevation)) { appearance.Flags.Elevation = new Elevation() { Elevation_ = (ushort)thingType.Attributes[AttributesUniform.Elevation] } } ; if (thingType.HasAttribute(AttributesUniform.LensHelp)) { appearance.Flags.LensHelp = new LensHelp() { Id = (ushort)thingType.Attributes[AttributesUniform.LensHelp] } } ; if (thingType.HasAttribute(AttributesUniform.Cloth)) { appearance.Flags.Cloth = new Clothes() { Slot = (ushort)thingType.Attributes[AttributesUniform.Cloth] } } ; // default action if (thingType.HasAttribute(AttributesUniform.DefaultAction)) { var defaultAction = new DefaultAction(); var oldDefaultActionValue = (ushort)thingType.Attributes[AttributesUniform.DefaultAction]; if (oldDefaultActionValue > 4) { Console.WriteLine("Invalid default action: " + oldDefaultActionValue + " for item id: " + thingType.ID); } appearance.Flags.DefaultAction = new DefaultAction() { Action = (PlayerAction)oldDefaultActionValue }; } if (thingType.HasAttribute(AttributesUniform.GroundBorder)) { appearance.Flags.GroundBorder = true; } if (thingType.HasAttribute(AttributesUniform.Bottom)) { appearance.Flags.Bottom = true; } if (thingType.HasAttribute(AttributesUniform.Top)) { appearance.Flags.Top = true; } if (thingType.HasAttribute(AttributesUniform.Container)) { appearance.Flags.Container = true; } if (thingType.HasAttribute(AttributesUniform.Stackable)) { appearance.Flags.Stackable = true; } if (thingType.HasAttribute(AttributesUniform.Use)) { appearance.Flags.Use = true; } if (thingType.HasAttribute(AttributesUniform.ForceUse)) { appearance.Flags.ForceUse = true; } if (thingType.HasAttribute(AttributesUniform.MultiUse)) { appearance.Flags.MultiUse = true; } if (thingType.HasAttribute(AttributesUniform.FluidContainer)) { appearance.Flags.FluidContainer = true; } if (thingType.HasAttribute(AttributesUniform.Splash)) { appearance.Flags.Splash = true; } if (thingType.HasAttribute(AttributesUniform.Unpassable)) { appearance.Flags.Unpassable = true; } if (thingType.HasAttribute(AttributesUniform.Unmoveable)) { appearance.Flags.Unmoveable = true; } if (thingType.HasAttribute(AttributesUniform.Unsight)) { appearance.Flags.Unsight = true; } if (thingType.HasAttribute(AttributesUniform.BlockPath)) { appearance.Flags.BlockPath = true; } if (thingType.HasAttribute(AttributesUniform.NoMoveAnimation)) { appearance.Flags.NoMoveAnimation = true; } if (thingType.HasAttribute(AttributesUniform.Pickupable)) { appearance.Flags.Pickupable = true; } if (thingType.HasAttribute(AttributesUniform.Hangable)) { appearance.Flags.Hangable = true; } // can have only one hook // if (thingType.HasAttribute(AttributesUniform.HookSouth)) { appearance.Flags.Hook = new Hook() { Type = HookType.South } } ; else if (thingType.HasAttribute(AttributesUniform.HookEast)) { appearance.Flags.Hook = new Hook() { Type = HookType.East } } ; if (thingType.HasAttribute(AttributesUniform.Rotateable)) { appearance.Flags.Rotateable = true; } if (thingType.HasAttribute(AttributesUniform.DontHide)) { appearance.Flags.DontHide = true; } if (thingType.HasAttribute(AttributesUniform.Translucent)) { appearance.Flags.Translucent = true; } if (thingType.HasAttribute(AttributesUniform.LyingCorpse)) { appearance.Flags.LyingCorpse = true; } if (thingType.HasAttribute(AttributesUniform.AnimateAlways)) { appearance.Flags.AnimateAlways = true; } if (thingType.HasAttribute(AttributesUniform.FullGround)) { appearance.Flags.FullGround = true; } if (thingType.HasAttribute(AttributesUniform.Look)) { appearance.Flags.Look = true; } if (thingType.HasAttribute(AttributesUniform.Wrapable)) { appearance.Flags.Wrapable = true; } if (thingType.HasAttribute(AttributesUniform.Unwrapable)) { appearance.Flags.GroundBorder = true; } if (thingType.HasAttribute(AttributesUniform.TopEffect)) { appearance.Flags.TopEffect = true; } if (thingType.HasAttribute(AttributesUniform.Light)) { var lightInfo = (Core.Sprites.LightInfo)thingType.Attributes[AttributesUniform.Light]; appearance.Flags.Light = new LightInfo() { Intensity = lightInfo.intensity, Color = lightInfo.color, }; } if (thingType.HasAttribute(AttributesUniform.Offset)) { var displacement = (Core.Sprites.Vector2Int)thingType.Attributes[AttributesUniform.Offset]; appearance.Flags.Displacement = new Displacement() { X = displacement.x, Y = displacement.y, }; } if (thingType.HasAttribute(AttributesUniform.Market)) { var Market = (Core.Sprites.MarketData)thingType.Attributes[AttributesUniform.Market]; appearance.Flags.Market = new MarketInfo() { Category = Market.category, TradeAs = Market.tradeAs, ShowAs = Market.showAs, Name = Market.name, RestrictVocation = Market.restrictProfession, RequiredLevel = Market.restrictLevel, }; } foreach (var f in thingType.FrameGroups) { FrameGroup frameGroup = new FrameGroup(); frameGroup.Type = f.Key == 0 ? FrameGroupType.Idle : FrameGroupType.Walking; frameGroup.Height = f.Value.Height; frameGroup.Width = f.Value.Width; frameGroup.ExactSize = f.Value.ExactSize; frameGroup.Layers = f.Value.Layers; frameGroup.PatternWidth = f.Value.PatternWidth; frameGroup.PatternHeight = f.Value.PatternHeight; frameGroup.PatternDepth = f.Value.PatternDepth; frameGroup.Phases = f.Value.Phases; if (f.Value.Animator != null) { frameGroup.FrameAnimation = new FrameAnimation(); frameGroup.FrameAnimation.Async = f.Value.Animator.Async; frameGroup.FrameAnimation.LoopCount = f.Value.Animator.LoopCount; frameGroup.FrameAnimation.StartPhase = f.Value.Animator.StartPhase; foreach (var m in f.Value.Animator.FrameGroupDurations) { FrameGroupDuration duration = new FrameGroupDuration(); duration.Min = (uint)m.Minimum; duration.Max = (uint)m.Maximum; frameGroup.FrameAnimation.FrameGroupDurations.Add(duration); } } foreach (var s in f.Value.Sprites) { frameGroup.Sprites.Add(s); } appearance.FrameGroups.Add(frameGroup); } return(appearance); }