Пример #1
0
        public static Vital Convert(Shared.Ability ability)
        {
            Vital v = new Vital();

            v.Ranks       = ability.Ranks;
            v.Current     = ability.Base + ability.Ranks;
            v.XpSpent     = ability.ExperienceSpent;
            v.LevelFromCp = 0;
            return(v);
        }
Пример #2
0
        public static CachePwnWeenie ConvertFromWeenie(Models.Weenie.Weenie w)
        {
            CachePwnWeenie pwn = new CachePwnWeenie
            {
                WeenieId     = w.WeenieClassId,
                WeenieTypeId = w.IntProperties.First(i => i.IntPropertyId == (int)IntPropertyId.WeenieType).Value
                               .Value
            };

            if (w.IntProperties?.Count > 0)
            {
                pwn.IntStats = new List <IntStat>();
            }

            w.IntProperties?.ForEach(ip =>
            {
                pwn.IntStats.Add(new IntStat()
                {
                    Key   = ip.IntPropertyId,
                    Value = ip.Value.Value
                });
            });

            if (w.Int64Properties?.Count > 0)
            {
                pwn.Int64Stats = new List <Int64Stat>();
            }

            w.Int64Properties?.ForEach(ip =>
            {
                pwn.Int64Stats.Add(new Int64Stat()
                {
                    Key   = ip.Int64PropertyId,
                    Value = ip.Value.Value
                });
            });

            if (w.DoubleProperties?.Count > 0)
            {
                pwn.FloatStats = new List <FloatStat>();
            }

            w.DoubleProperties?.ForEach(dp =>
            {
                pwn.FloatStats.Add(new FloatStat()
                {
                    Key   = dp.DoublePropertyId,
                    Value = (float)dp.Value.Value
                });
            });

            if (w.BoolProperties?.Count > 0)
            {
                pwn.BoolStats = new List <BoolStat>();
            }

            w.BoolProperties?.ForEach(bp =>
            {
                pwn.BoolStats.Add(new BoolStat()
                {
                    Key       = bp.BoolPropertyId,
                    BoolValue = bp.Value
                });
            });

            if (w.DidProperties?.Count > 0)
            {
                pwn.DidStats = new List <DidStat>();
            }

            w.DidProperties?.ForEach(dp =>
            {
                pwn.DidStats.Add(new DidStat()
                {
                    Key   = dp.DataIdPropertyId,
                    Value = dp.Value.Value
                });
            });

            if (w.StringProperties?.Count > 0)
            {
                pwn.StringStats = new List <StringStat>();
            }

            w.StringProperties?.ForEach(sp =>
            {
                pwn.StringStats.Add(new StringStat()
                {
                    Key   = sp.StringPropertyId,
                    Value = sp.Value
                });
            });

            if (w.BookProperties.Count > 0)
            {
                pwn.Book = new Book
                {
                    Pages = new List <Page>(),

                    MaxCharactersPerPage = 1000
                };

                w.BookProperties.ForEach(bp =>
                {
                    pwn.Book.Pages.Add(new Page()
                    {
                        AuthorAccount = bp.AuthorAccount,
                        AuthorId      = bp.AuthorId,
                        AuthorName    = bp.AuthorName,
                        IgnoreAuthor  = bp.IgnoreAuthor,
                        PageText      = bp.PageText
                    });
                });
                pwn.Book.MaxNumberPages = pwn.Book.Pages.Count; // Thwargle fixed the maxNumPages to count pages woo woo
            }

            if (w.HasAbilities)
            {
                pwn.Attributes = new AttributeSet
                {
                    Strength     = Attribute.Convert(w.Abilities.Strength),
                    Endurance    = Attribute.Convert(w.Abilities.Endurance),
                    Coordination = Attribute.Convert(w.Abilities.Coordination),
                    Quickness    = Attribute.Convert(w.Abilities.Quickness),
                    Focus        = Attribute.Convert(w.Abilities.Focus),
                    Self         = Attribute.Convert(w.Abilities.Self),

                    Health  = Vital.Convert(w.Vitals.Health),
                    Stamina = Vital.Convert(w.Vitals.Stamina),
                    Mana    = Vital.Convert(w.Vitals.Mana)
                };

                if (w.Skills?.Count > 0)
                {
                    pwn.Skills = new List <SkillListing>();
                }

                // also applies to skills
                w.Skills.ForEach(s =>
                {
                    pwn.Skills.Add(new SkillListing()
                    {
                        SkillId = s.SkillId,
                        Skill   = new Skill()
                        {
                            Ranks                 = s.Ranks,
                            TrainedLevel          = s.Status,
                            XpInvested            = s.ExperienceSpent != null ? s.ExperienceSpent : 0,
                            ResistanceOfLastCheck = 0,
                            LevelFromPp           = 0,
                            LastUsed              = 0.0f
                        }
                    });
                });
            }

            if (w.Positions?.Count > 0)
            {
                pwn.Positions = new List <PositionListing>();
            }

            w.Positions?.ForEach(p =>
            {
                pwn.Positions.Add(new PositionListing()
                {
                    PositionType = p.PositionType,
                    Position     = new Position()
                    {
                        Frame = new Frame()
                        {
                            Position = new XYZ()
                            {
                                X = p.X,
                                Y = p.Y,
                                Z = p.Z
                            },
                            Rotations = new Quaternion()
                            {
                                W = p.QW,
                                X = p.QX,
                                Y = p.QY,
                                Z = p.QZ
                            }
                        },
                        LandCellId = p.Landblock
                    }
                });
            });

            if (w.Spells?.Count > 0)
            {
                pwn.Spells = new List <SpellbookEntry>();
            }

            w.Spells?.ForEach(s =>
            {
                pwn.Spells.Add(new SpellbookEntry()
                {
                    SpellId = s.SpellId,
                    Stats   = new SpellCastingStats()
                    {
                        CastingChance = s.Probability
                    }
                });
            });

            if (w.CreateList?.Count > 0)
            {
                pwn.CreateList = new List <CreateItem>();
            }

            w.CreateList?.ForEach(cl =>
            {
                pwn.CreateList.Add(new CreateItem()
                {
                    Destination   = cl.Destination,
                    Palette       = cl.Palette,
                    Shade         = cl.Shade,
                    StackSize     = cl.StackSize,
                    TryToBond     = cl.TryToBond != null && (bool)cl.TryToBond ? (byte)1 : (byte)0,
                    WeenieClassId = cl.WeenieClassId
                });
            });

            if (w.GeneratorTable?.Count > 0)
            {
                pwn.GeneratorTable = new List <GeneratorTable>();
            }

            w.GeneratorTable?.ForEach(gt =>
            {
                GeneratorTable ngt = new GeneratorTable()
                {
                    Delay         = gt.Delay,
                    InitCreate    = gt.InitCreate,
                    MaxNumber     = gt.MaxNumber,
                    ObjectCell    = gt.ObjectCell,
                    PaletteId     = gt.PaletteId,
                    Probability   = gt.Probability,
                    Shade         = gt.Shade,
                    Slot          = gt.Slot,
                    StackSize     = gt.StackSize,
                    WeenieClassId = gt.WeenieClassId,
                    WhenCreate    = gt.WhenCreate,
                    WhereCreate   = gt.WhereCreate
                };
                ngt.Frame = new Frame
                {
                    Position  = new XYZ(),
                    Rotations = new Quaternion
                    {
                        W = gt.Frame.Angles.W,
                        X = gt.Frame.Angles.X,
                        Y = gt.Frame.Angles.Y,
                        Z = gt.Frame.Angles.Z
                    }
                };
                ngt.Frame.Position.X = gt.Frame.Origin.X;
                ngt.Frame.Position.Y = gt.Frame.Origin.Y;
                ngt.Frame.Position.X = gt.Frame.Origin.X;

                pwn.GeneratorTable.Add(ngt);
            });

            if (w.EmoteTable?.Count > 0)
            {
                pwn.EmoteTable = new List <EmoteCategoryListing>();

                foreach (var es in w.EmoteTable)
                {
                    if (!pwn.EmoteTable.Any(et => et.EmoteCategoryId == (int)es.EmoteCategoryId))
                    {
                        pwn.EmoteTable.Add(new EmoteCategoryListing()
                        {
                            EmoteCategoryId = (int)es.EmoteCategoryId,
                            Emotes          = new List <Emote>()
                        });
                    }

                    EmoteCategoryListing ecl =
                        pwn.EmoteTable.First(et => et.EmoteCategoryId == (int)es.EmoteCategoryId);

                    var pwnEmote = new Emote()
                    {
                        ClassId     = es.ClassId,
                        Category    = es.EmoteCategoryId,
                        MaxHealth   = es.MaxHealth,
                        MinHealth   = es.MinHealth,
                        Probability = es.Probability,
                        Quest       = es.Quest,
                        Style       = es.Style,
                        SubStyle    = es.SubStyle,
                        VendorType  = es.VendorType,
                        Emotes      = new List <EmoteAction>()
                    };

                    es.Emotes.ForEach(dfEmote =>
                    {
                        var ea = new EmoteAction()
                        {
                            Amount          = dfEmote.Amount,
                            Amount64        = dfEmote.Amount64,
                            Delay           = dfEmote.Delay,
                            Display         = dfEmote.Display,
                            EmoteActionType = dfEmote.EmoteTypeId,
                            Extent          = dfEmote.Extent,
                            FMax            = dfEmote.MaximumFloat,
                            FMin            = dfEmote.MinimumFloat,
                            HeroXp64        = dfEmote.HeroXp64,
                            Max             = dfEmote.Maximum,
                            Maximum64       = dfEmote.Maximum64,
                            Message         = dfEmote.Message,
                            Min             = dfEmote.Minimum,
                            Minimum64       = dfEmote.Minimum64,
                            Motion          = dfEmote.MotionId,
                            Percent         = (float?)dfEmote.Percent,
                            PScript         = dfEmote.PhysicsScriptId,
                            Sound           = dfEmote.Sound,
                            SpellId         = dfEmote.SpellId,
                            Stat            = dfEmote.Stat,
                            TestString      = dfEmote.TestString,
                            TreasureClass   = dfEmote.TreasureClassId,
                            TreasureType    = (int?)dfEmote.TreasureType,
                            WealthRating    = dfEmote.WealthRatingId
                        };

                        if (dfEmote.PositionX != null)
                        {
                            ea.Frame = new Frame()
                            {
                                Position = new XYZ()
                                {
                                    X = dfEmote.PositionX.Value,
                                    Y = dfEmote.PositionY.Value,
                                    Z = dfEmote.PositionZ.Value
                                }
                            };
                        }

                        if (dfEmote.RotationW != null)
                        {
                            ea.Frame           = ea.Frame ?? new Frame();
                            ea.Frame.Rotations = new Quaternion()
                            {
                                W = dfEmote.RotationW.Value,
                                X = dfEmote.RotationX.Value,
                                Y = dfEmote.RotationY.Value,
                                Z = dfEmote.RotationZ.Value
                            };
                        }

                        if (dfEmote.CreationProfile != null &&
                            Shared.Emote.IsPropertyVisible("CreationProfile", dfEmote.EmoteType))
                        {
                            ea.Item = new CreateItem()
                            {
                                Destination   = dfEmote.CreationProfile.Destination,
                                Palette       = dfEmote.CreationProfile.Palette,
                                Shade         = dfEmote.CreationProfile.Shade,
                                StackSize     = dfEmote.CreationProfile.StackSize,
                                TryToBond     = dfEmote.CreationProfile.TryToBond != null && (bool)dfEmote.CreationProfile.TryToBond ? (byte)1 : (byte?)0,
                                WeenieClassId = dfEmote.CreationProfile.WeenieClassId
                            };
                        }

                        pwnEmote.Emotes.Add(ea);
                    });

                    ecl.Emotes.Add(pwnEmote);

                    // previous code ensures the "ecl" is already added to pwn.EmoteTable
                }
            }

            if (w.BodyParts?.Count > 0)
            {
                pwn.Body = new Body
                {
                    BodyParts = new List <BodyPartListing>()
                };
            }

            w.BodyParts?.ForEach(bp =>
            {
                pwn.Body.BodyParts.Add(new BodyPartListing()
                {
                    Key      = (int)bp.BodyPartType,
                    BodyPart = new BodyPart()
                    {
                        BH          = bp.BodyHeight,
                        DType       = (int)bp.DamageType,
                        DVal        = bp.Damage,
                        DVar        = bp.DamageVariance,
                        ArmorValues = new ArmorValues()
                        {
                            ArmorVsAcid     = bp.ArmorValues.Acid,
                            ArmorVsBludgeon = bp.ArmorValues.Bludgeon,
                            ArmorVsCold     = bp.ArmorValues.Cold,
                            ArmorVsElectric = bp.ArmorValues.Electric,
                            ArmorVsFire     = bp.ArmorValues.Fire,
                            ArmorVsNether   = bp.ArmorValues.Nether,
                            ArmorVsPierce   = bp.ArmorValues.Pierce,
                            ArmorVsSlash    = bp.ArmorValues.Slash,
                            BaseArmor       = bp.ArmorValues.Base
                        },
                        SD = new Zones()
                        {
                            HLB = bp.TargetingData.HighLeftBack,
                            HLF = bp.TargetingData.HighLeftFront,
                            HRB = bp.TargetingData.HighRightBack,
                            HRF = bp.TargetingData.HighRightFront,
                            LLB = bp.TargetingData.LowLeftBack,
                            LLF = bp.TargetingData.LowLeftFront,
                            LRB = bp.TargetingData.LowRightBack,
                            LRF = bp.TargetingData.LowRightFront,
                            MLB = bp.TargetingData.MidLeftBack,
                            MLF = bp.TargetingData.MidLeftFront,
                            MRB = bp.TargetingData.MidRightBack,
                            MRF = bp.TargetingData.MidRightFront
                        }
                    }
                });
            });
            return(pwn);
        }