/// <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); }
/// <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(OpenTibiaUnity.Core.Sprites.ThingType thingType) { Appearance appearance = new Appearance() { Id = thingType.ID, }; if (thingType.Attributes.Count > 0) { appearance.Flags = new AppearanceFlags(); } // Flags if (thingType.HasAttribute(DatAttributes.Ground)) { appearance.Flags.Ground = (ushort)thingType.Attributes[DatAttributes.Ground]; } if (thingType.HasAttribute(DatAttributes.Writable)) { appearance.Flags.Writable = (ushort)thingType.Attributes[DatAttributes.Writable]; } if (thingType.HasAttribute(DatAttributes.WritableOnce)) { appearance.Flags.WritableOnce = (ushort)thingType.Attributes[DatAttributes.WritableOnce]; } if (thingType.HasAttribute(DatAttributes.MinimapColor)) { appearance.Flags.MinimapColor = (ushort)thingType.Attributes[DatAttributes.MinimapColor]; } if (thingType.HasAttribute(DatAttributes.Elevation)) { appearance.Flags.Elevation = (ushort)thingType.Attributes[DatAttributes.Elevation]; } if (thingType.HasAttribute(DatAttributes.LensHelp)) { appearance.Flags.LensHelp = (ushort)thingType.Attributes[DatAttributes.LensHelp]; } if (thingType.HasAttribute(DatAttributes.Cloth)) { appearance.Flags.Cloth = (ushort)thingType.Attributes[DatAttributes.Cloth]; } if (thingType.HasAttribute(DatAttributes.DefaultAction)) { appearance.Flags.DefaultAction = (ushort)thingType.Attributes[DatAttributes.DefaultAction]; } if (thingType.HasAttribute(DatAttributes.GroundBorder)) { appearance.Flags.GroundBorder = (bool)thingType.Attributes[DatAttributes.GroundBorder]; } if (thingType.HasAttribute(DatAttributes.OnBottom)) { appearance.Flags.OnBottom = (bool)thingType.Attributes[DatAttributes.OnBottom]; } if (thingType.HasAttribute(DatAttributes.OnTop)) { appearance.Flags.OnTop = (bool)thingType.Attributes[DatAttributes.OnTop]; } if (thingType.HasAttribute(DatAttributes.Container)) { appearance.Flags.Container = (bool)thingType.Attributes[DatAttributes.Container]; } if (thingType.HasAttribute(DatAttributes.Stackable)) { appearance.Flags.Stackable = (bool)thingType.Attributes[DatAttributes.Stackable]; } if (thingType.HasAttribute(DatAttributes.ForceUse)) { appearance.Flags.ForceUse = (bool)thingType.Attributes[DatAttributes.ForceUse]; } if (thingType.HasAttribute(DatAttributes.MultiUse)) { appearance.Flags.MultiUse = (bool)thingType.Attributes[DatAttributes.MultiUse]; } if (thingType.HasAttribute(DatAttributes.FluidContainer)) { appearance.Flags.FluidContainer = (bool)thingType.Attributes[DatAttributes.FluidContainer]; } if (thingType.HasAttribute(DatAttributes.Splash)) { appearance.Flags.Splash = (bool)thingType.Attributes[DatAttributes.Splash]; } if (thingType.HasAttribute(DatAttributes.NotWalkable)) { appearance.Flags.NotWalkable = (bool)thingType.Attributes[DatAttributes.NotWalkable]; } if (thingType.HasAttribute(DatAttributes.NotMoveable)) { appearance.Flags.NotMoveable = (bool)thingType.Attributes[DatAttributes.NotMoveable]; } if (thingType.HasAttribute(DatAttributes.BlockProjectile)) { appearance.Flags.BlockProjectile = (bool)thingType.Attributes[DatAttributes.BlockProjectile]; } if (thingType.HasAttribute(DatAttributes.NotPathable)) { appearance.Flags.NotPathable = (bool)thingType.Attributes[DatAttributes.NotPathable]; } if (thingType.HasAttribute(DatAttributes.NoMoveAnimation)) { appearance.Flags.NoMoveAnimation = (bool)thingType.Attributes[DatAttributes.NoMoveAnimation]; } if (thingType.HasAttribute(DatAttributes.Pickupable)) { appearance.Flags.Pickupable = (bool)thingType.Attributes[DatAttributes.Pickupable]; } if (thingType.HasAttribute(DatAttributes.Hangable)) { appearance.Flags.Hangable = (bool)thingType.Attributes[DatAttributes.Hangable]; } if (thingType.HasAttribute(DatAttributes.HookSouth)) { appearance.Flags.HookSouth = (bool)thingType.Attributes[DatAttributes.HookSouth]; } if (thingType.HasAttribute(DatAttributes.HookEast)) { appearance.Flags.HookEast = (bool)thingType.Attributes[DatAttributes.HookEast]; } if (thingType.HasAttribute(DatAttributes.Rotateable)) { appearance.Flags.Rotateable = (bool)thingType.Attributes[DatAttributes.Rotateable]; } if (thingType.HasAttribute(DatAttributes.DontHide)) { appearance.Flags.DontHide = (bool)thingType.Attributes[DatAttributes.DontHide]; } if (thingType.HasAttribute(DatAttributes.Translucent)) { appearance.Flags.Translucent = (bool)thingType.Attributes[DatAttributes.Translucent]; } if (thingType.HasAttribute(DatAttributes.LyingCorpse)) { appearance.Flags.LyingCorpse = (bool)thingType.Attributes[DatAttributes.LyingCorpse]; } if (thingType.HasAttribute(DatAttributes.AnimateAlways)) { appearance.Flags.AnimateAlways = (bool)thingType.Attributes[DatAttributes.AnimateAlways]; } if (thingType.HasAttribute(DatAttributes.FullGround)) { appearance.Flags.FullGround = (bool)thingType.Attributes[DatAttributes.FullGround]; } if (thingType.HasAttribute(DatAttributes.Look)) { appearance.Flags.Look = (bool)thingType.Attributes[DatAttributes.Look]; } if (thingType.HasAttribute(DatAttributes.Wrapable)) { appearance.Flags.Wrapable = (bool)thingType.Attributes[DatAttributes.Wrapable]; } if (thingType.HasAttribute(DatAttributes.Unwrapable)) { appearance.Flags.GroundBorder = (bool)thingType.Attributes[DatAttributes.Unwrapable]; } if (thingType.HasAttribute(DatAttributes.TopEffect)) { appearance.Flags.TopEffect = (bool)thingType.Attributes[DatAttributes.TopEffect]; } if (thingType.HasAttribute(DatAttributes.Usable)) { appearance.Flags.Usable = (bool)thingType.Attributes[DatAttributes.Usable]; } if (thingType.HasAttribute(DatAttributes.Light)) { var lightInfo = (OpenTibiaUnity.Core.Sprites.LightInfo)thingType.Attributes[DatAttributes.Light]; appearance.Flags.Light = new LightInfo() { Intensity = lightInfo.intensity, Color = lightInfo.color, }; } if (thingType.HasAttribute(DatAttributes.Displacement)) { var displacement = (OpenTibiaUnity.Core.Sprites.Vector2Int)thingType.Attributes[DatAttributes.Displacement]; appearance.Flags.Displacement = new Vector2() { X = (uint)displacement.x, Y = (uint)displacement.y, }; } if (thingType.HasAttribute(DatAttributes.Market)) { var Market = (OpenTibiaUnity.Core.Sprites.MarketData)thingType.Attributes[DatAttributes.Market]; appearance.Flags.Market = new MarketInfo() { Category = (uint)Market.category, TradeAs = Market.tradeAs, ShowAs = Market.showAs, Name = Market.name, RestrictVocation = Market.restrictVocation, RequiredLevel = Market.requiredLevel, }; } 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); }