Exemple #1
0
        private bool ChangeAllowed(DurabilityLevel now, DurabilityLevel next, string currentSkuName)
        {
            if (now == DurabilityLevel.Gold)
            {
                if (next != DurabilityLevel.Gold)
                {
                    return(false);
                }
            }

            if (now == DurabilityLevel.Silver)
            {
                if (next != DurabilityLevel.Gold && next != DurabilityLevel.Silver)
                {
                    return(false);
                }
            }

            if (next == DurabilityLevel.Gold)
            {
                var targetSkuName = string.IsNullOrEmpty(this.Sku) ? currentSkuName : this.Sku;

                if (!skusSupportGoldDurability.Contains(targetSkuName))
                {
                    WriteWarning("Only Standard_D15_v2 and Standard_G5 supports Gold durability");
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
        protected void GetDurabilityLevel(string nodeTypeName, out DurabilityLevel durabilityLevel, out bool isMismatched)
        {
            var cluster  = GetCurrentCluster();
            var nodeType = cluster.NodeTypes.SingleOrDefault(n => n.Name.Equals(nodeTypeName, StringComparison.OrdinalIgnoreCase));

            if (nodeType == null)
            {
                throw new PSInvalidOperationException(string.Format(ServiceFabricProperties.Resources.CannotFindTheNodeType, nodeTypeName));
            }

            var durabilityLevelFromNodeType = (DurabilityLevel)Enum.Parse(typeof(DurabilityLevel), nodeType.DurabilityLevel);

            var vmss = GetVmss(nodeTypeName);
            var ext  = FindFabricVmExt(vmss.VirtualMachineProfile.ExtensionProfile.Extensions);

            var durabilityLevelStr = (string)((JObject)ext.Settings)["durabilityLevel"];

            if (string.IsNullOrWhiteSpace(durabilityLevelStr))
            {
                throw new PSInvalidOperationException(ServiceFabricProperties.Resources.CannotFindDurabilityLevelSetting);
            }

            var durabilityLevelFromVmss = (DurabilityLevel)Enum.Parse(typeof(DurabilityLevel), durabilityLevelStr);

            if (durabilityLevelFromVmss != durabilityLevelFromNodeType)
            {
                WriteWarning(ServiceFabricProperties.Resources.DurabilityLevelMismatches);
                durabilityLevel = durabilityLevelFromNodeType;
                isMismatched    = true;
                return;
            }

            durabilityLevel = durabilityLevelFromNodeType;
            isMismatched    = false;
        }
Exemple #3
0
        public Task <IMutationResult> MutateIn(string id, IEnumerable <OperationSpec> specs, TimeSpan?timeout = null, TimeSpan?expiration = null, ulong cas = 0, bool createDocument = false,
                                               DurabilityLevel durabilityLevel = DurabilityLevel.None, CancellationToken token            = default(CancellationToken))
        {
            var options = new MutateInOptions();

            ConfigureMutateInOptions(options, timeout, expiration, cas, createDocument, durabilityLevel, token);

            return(MutateIn(id, specs, options));
        }
Exemple #4
0
        public async Task RemoveClient(string clientUuid, DurabilityLevel durability = DurabilityLevel.None)
        {
            var opts  = new MutateInOptions().Timeout(RemoveClientTimeout).Durability(DurabilityLevel.None);
            var specs = new MutateInSpec[]
            {
                MutateInSpec.Remove(ClientRecordEntry.PathForEntry(clientUuid), isXattr: true),
            };

            _ = await Collection.MutateInAsync(ClientRecordsIndex.CLIENT_RECORD_DOC_ID, specs, opts).CAF();
        }
        public override void DisplayLabelName(Mobile from)
        {
            if (from == null)
            {
                return;
            }

            string displayName = "";

            if (IsMagical && !Identified && from.AccessLevel == AccessLevel.Player)
            {
                LabelTo(from, "unidentified " + Name);
            }

            else
            {
                switch (Quality)
                {
                case Server.Quality.Low: displayName = "low quality "; break;

                case Server.Quality.Regular: displayName = ""; break;

                case Server.Quality.Exceptional: displayName += "exceptional "; break;
                }

                if (DurabilityLevel != InstrumentDurabilityLevel.Regular)
                {
                    displayName += DurabilityLevel.ToString().ToLower() + " ";
                }

                switch (ArtistryLevel)
                {
                case InstrumentArtistryLevel.Melodist: displayName += "melodist "; break;

                case InstrumentArtistryLevel.Jongleur: displayName += "jongleur "; break;

                case InstrumentArtistryLevel.Minstrel: displayName += "minstrel "; break;

                case InstrumentArtistryLevel.Troubadour: displayName += "troubadour "; break;

                case InstrumentArtistryLevel.Balladeer: displayName += "balladeer "; break;
                }

                displayName += Name;

                if (SlayerGroup != SlayerGroupType.None)
                {
                    displayName += " of " + SlayerGroup.ToString().ToLower() + " enticement";
                }

                LabelTo(from, displayName);
            }

            LabelTo(from, UsesRemaining.ToString() + " uses remaining");
        }
Exemple #6
0
        public async Task Upsert_with_durability(DurabilityLevel durabilityLevel)
        {
            var collection = await _fixture.GetDefaultCollection();

            // Upsert will throw exception if durability is not met
            await collection.Upsert(
                "id",
                new { name = "mike" },
                durabilityLevel : durabilityLevel
                );
        }
Exemple #7
0
        public Task MutateAtrPending(ulong exp, DurabilityLevel durabilityLevel)
        {
            var atrEntry = new AtrEntry()
            {
                State           = Support.AttemptStates.PENDING,
                DurabilityLevel = new ShortStringDurabilityLevel(durabilityLevel).ToString()
            };

            Atrs[FullId] = atrEntry;
            return(Task.CompletedTask);
        }
        public async Task Upsert_with_durability(DurabilityLevel durabilityLevel)
        {
            var collection = await _fixture.GetDefaultCollection().ConfigureAwait(false);

            // Upsert will throw exception if durability is not met
            await collection.UpsertAsync(
                "id",
                new { name = "mike" },
                options => options.DurabilityLevel = durabilityLevel
                ).ConfigureAwait(false);
        }
Exemple #9
0
        public Task Touch(string id, TimeSpan expiration, TimeSpan?timeout = null,
                          DurabilityLevel durabilityLevel = DurabilityLevel.None, CancellationToken token = default(CancellationToken))
        {
            var options = new TouchOptions
            {
                Timeout         = timeout,
                DurabilityLevel = durabilityLevel,
                Token           = token
            };

            return(Touch(id, expiration, options));
        }
Exemple #10
0
        public Task <IGetResult> GetAndTouch(string id, TimeSpan expiration, IEnumerable <string> projections = null,
                                             TimeSpan?timeout        = null, DurabilityLevel durabilityLevel = DurabilityLevel.None,
                                             CancellationToken token = default(CancellationToken))
        {
            var options = new GetAndTouchOptions
            {
                Timeout         = timeout,
                DurabilityLevel = durabilityLevel,
                Token           = token
            };

            return(GetAndTouch(id, expiration, options));
        }
Exemple #11
0
        public Task <IMutationResult> MutateIn(string id, Action <MutateInSpecBuilder> configureBuilder, TimeSpan?timeout = null, TimeSpan?expiration = null, ulong cas = 0, bool createDocument = false,
                                               DurabilityLevel durabilityLevel = DurabilityLevel.None, CancellationToken token = default(CancellationToken))
        {
            var builder = new MutateInSpecBuilder();

            configureBuilder(builder);

            var options = new MutateInOptions();

            ConfigureMutateInOptions(options, timeout, expiration, cas, createDocument, durabilityLevel, token);

            return(MutateIn(id, builder.Specs, options));
        }
Exemple #12
0
        public BaseArmor(int itemID) :  base(itemID)
        {
            m_Quality    = CraftQuality.Regular;
            m_Durability = DurabilityLevel.Regular;
            m_Crafter    = null;

            m_HitPoints = m_MaxHitPoints = Utility.RandomMinMax(InitMinHits, InitMaxHits);

            this.Layer = (Layer)ItemData.Quality;

            m_AosAttributes      = new AosAttributes(this);
            m_AosArmorAttributes = new AosArmorAttributes(this);
            m_AosSkillBonuses    = new AosSkillBonuses(this);
        }
Exemple #13
0
        public BaseArmor( int itemID )
            : base(itemID)
        {
            m_Quality = CraftQuality.Regular;
            m_Durability = DurabilityLevel.Regular;
            m_Crafter = null;

            m_HitPoints = m_MaxHitPoints = Utility.RandomMinMax( InitMinHits, InitMaxHits );

            this.Layer = (Layer)ItemData.Quality;

            m_AosAttributes = new AosAttributes( this );
            m_AosArmorAttributes = new AosArmorAttributes( this );
            m_AosSkillBonuses = new AosSkillBonuses( this );
        }
        public DocumentRepository(TransactionContext overallContext, TimeSpan?keyValueTimeout, DurabilityLevel durability, string attemptId)
        {
            _overallContext  = overallContext;
            _keyValueTimeout = keyValueTimeout;
            _durability      = durability;
            _attemptId       = attemptId;


            _metadataSerializerSettings = new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore
            };

            _metadataSerializer = JsonSerializer.Create(_metadataSerializerSettings);
        }
Exemple #15
0
        public static Transactions CreateTransaction(ICluster cluster, DurabilityLevel durability, ITestOutputHelper outputHelper)
        {
            var configBuilder = TransactionConfigBuilder.Create()
                                .DurabilityLevel(durability)
                                .LoggerFactory(new ClusterFixture.TestOutputLoggerFactory(outputHelper));

            if (Debugger.IsAttached)
            {
                // don't expire when watching the debugger.
                configBuilder.ExpirationTime(TimeSpan.FromMinutes(1000));
            }

            var txn = Transactions.Create(cluster, configBuilder.Build());

            return(txn);
        }
Exemple #16
0
 internal TransactionConfig(
     DurabilityLevel durabilityLevel = DefaultDurabilityLevel,
     TimeSpan?expirationTime         = null,
     TimeSpan?cleanupWindow          = null,
     TimeSpan?keyValueTimeout        = null,
     bool cleanupClientAttempts      = DefaultCleanupClientAttempts,
     bool cleanupLostAttempts        = DefaultCleanupLostAttempts
     )
 {
     ExpirationTime        = expirationTime ?? TimeSpan.FromMilliseconds(DefaultExpirationMilliseconds);
     CleanupLostAttempts   = cleanupLostAttempts;
     CleanupClientAttempts = cleanupClientAttempts;
     CleanupWindow         = cleanupWindow ?? TimeSpan.FromMilliseconds(DefaultCleanupWindowMilliseconds);
     KeyValueTimeout       = keyValueTimeout;
     DurabilityLevel       = durabilityLevel;
 }
Exemple #17
0
        public Task <IMutationResult> Insert <T>(string id, T content, TimeSpan?timeout = null, TimeSpan expiration = default(TimeSpan),
                                                 ulong cas = 0, PersistTo persistTo = PersistTo.None, ReplicateTo replicateTo = ReplicateTo.None,
                                                 DurabilityLevel durabilityLevel = DurabilityLevel.None, CancellationToken token = default(CancellationToken))
        {
            var options = new InsertOptions
            {
                Timeout         = timeout,
                Expiration      = expiration,
                Cas             = cas, PersistTo = persistTo,
                ReplicateTo     = replicateTo,
                DurabilityLevel = durabilityLevel,
                Token           = token
            };

            return(Insert(id, content, options));
        }
Exemple #18
0
        public Task Remove(string id, TimeSpan?timeout     = null, ulong cas = 0,
                           PersistTo persistTo             = PersistTo.None, ReplicateTo replicateTo = ReplicateTo.None,
                           DurabilityLevel durabilityLevel = DurabilityLevel.None, CancellationToken token = default(CancellationToken))
        {
            var options = new RemoveOptions
            {
                Timeout         = timeout,
                Cas             = cas,
                PersistTo       = persistTo,
                ReplicateTo     = replicateTo,
                DurabilityLevel = durabilityLevel,
                Token           = token
            };

            return(Remove(id, options));
        }
        public async Task MutateAtrPending(ulong exp, DurabilityLevel documentDurability)
        {
            using var logScope = _logger.BeginMethodScope();
            var shortDurability = new ShortStringDurabilityLevel(documentDurability).ToString();
            var specs           = new[]
            {
                MutateInSpec.Insert(_prefixedAtrFieldTransactionId,
                                    _overallContext.TransactionId, createPath: true, isXattr: true),
                MutateInSpec.Insert(_prefixedAtrFieldStatus,
                                    AttemptStates.PENDING.ToString(), isXattr: true),
                MutateInSpec.Insert(_prefixedAtrFieldStartTimestamp, MutationMacro.Cas),
                MutateInSpec.Insert(_prefixedAtrFieldExpiresAfterMsecs, exp,
                                    createPath: false, isXattr: true),
                MutateInSpec.Insert(_prefixedAtrFieldDurability, shortDurability, isXattr: true),
                MutateInSpec.SetDoc(new byte?[] { null }), // ExtBinaryMetadata
            };

            var mutateResult = await Collection.MutateInAsync(AtrId, specs, GetMutateOpts(StoreSemantics.Upsert)).CAF();

            _logger.LogInformation("Upserted ATR to PENDING {atr}/{atrRoot} (cas = {cas})", AtrId, _atrRoot, mutateResult.Cas);
        }
Exemple #20
0
        private static void ConfigureMutateInOptions(MutateInOptions options, TimeSpan?timeout, TimeSpan?expiration,
                                                     ulong cas, bool createDocument, DurabilityLevel durabilityLevel, CancellationToken token)
        {
            if (timeout.HasValue)
            {
                options.Timeout(timeout.Value);
            }

            if (expiration.HasValue)
            {
                options.Expiration(expiration.Value);
            }

            if (cas > 0)
            {
                options.Cas(cas);
            }

            var flags = SubdocDocFlags.None;

            if (createDocument)
            {
                flags ^= SubdocDocFlags.UpsertDocument;
            }

            if (durabilityLevel != DurabilityLevel.None)
            {
                options._DurabilityLevel = durabilityLevel;
            }

            if (token != CancellationToken.None)
            {
                options._Token = token;
            }

            options.Flags(flags);
        }
 /// <summary>
 /// Set the minimum desired <see cref="DurabilityLevel(KeyValue.DurabilityLevel)"/>.
 /// </summary>
 /// <param name="durabilityLevel">The <see cref="DurabilityLevel(KeyValue.DurabilityLevel)"/> desired.</param>
 /// <returns>The continued instance of this builder.</returns>
 public PerTransactionConfigBuilder DurabilityLevel(DurabilityLevel durabilityLevel)
 {
     _config.DurabilityLevel = durabilityLevel;
     return this;
 }
Exemple #22
0
 public UpsertOptions WithDurability(DurabilityLevel durabilityLevel)
 {
     DurabilityLevel = durabilityLevel;
     return(this);
 }
Exemple #23
0
 public GetAndTouchOptions WithDurability(DurabilityLevel durabilityLevel)
 {
     DurabilityLevel = durabilityLevel;
     return(this);
 }
Exemple #24
0
 public DecrementOptions Durability(DurabilityLevel durabilityLevel)
 {
     DurabilityLevel = durabilityLevel;
     return(this);
 }
Exemple #25
0
 public InsertOptions Durability(DurabilityLevel durabilityLevel)
 {
     DurabilityLevel = durabilityLevel;
     return(this);
 }
Exemple #26
0
 public MutateInOptions Durability(DurabilityLevel durabilityLevel)
 {
     DurabilityLevel = durabilityLevel;
     return(this);
 }
Exemple #27
0
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadInt();

            switch ( version )
            {
                case 8:
                {
                    m_Identified = reader.ReadMobileList();

                    goto case 7;
                }
                case 7:
                case 6:
                case 5:
                {
                    SaveFlag flags = (SaveFlag)reader.ReadEncodedInt();

                    if ( GetSaveFlag( flags, SaveFlag.Attributes ) )
                        m_AosAttributes = new AosAttributes( this, reader );
                    else
                        m_AosAttributes = new AosAttributes( this );

                    if ( GetSaveFlag( flags, SaveFlag.ArmorAttributes ) )
                        m_AosArmorAttributes = new AosArmorAttributes( this, reader );
                    else
                        m_AosArmorAttributes = new AosArmorAttributes( this );

                    if ( GetSaveFlag( flags, SaveFlag.PhysicalBonus ) )
                        m_PhysicalBonus = reader.ReadEncodedInt();

                    if ( GetSaveFlag( flags, SaveFlag.FireBonus ) )
                        m_FireBonus = reader.ReadEncodedInt();

                    if ( GetSaveFlag( flags, SaveFlag.ColdBonus ) )
                        m_ColdBonus = reader.ReadEncodedInt();

                    if ( GetSaveFlag( flags, SaveFlag.PoisonBonus ) )
                        m_PoisonBonus = reader.ReadEncodedInt();

                    if ( GetSaveFlag( flags, SaveFlag.EnergyBonus ) )
                        m_EnergyBonus = reader.ReadEncodedInt();

                    if ( GetSaveFlag( flags, SaveFlag.Identified ) && version < 7 )
                        reader.ReadBool();
                        //m_Identified = ( version >= 7 || reader.ReadBool() );

                    if ( GetSaveFlag( flags, SaveFlag.MaxHitPoints ) )
                        m_MaxHitPoints = reader.ReadEncodedInt();

                    if ( GetSaveFlag( flags, SaveFlag.HitPoints ) )
                        m_HitPoints = reader.ReadEncodedInt();

                    if ( GetSaveFlag( flags, SaveFlag.Crafter ) )
                        m_Crafter = reader.ReadMobile();

                    if ( GetSaveFlag( flags, SaveFlag.Quality ) )
                        m_Quality = (CraftQuality)reader.ReadEncodedInt();
                    else
                        m_Quality = CraftQuality.Regular;

                    if ( version == 5 && m_Quality == CraftQuality.Low )
                        m_Quality = CraftQuality.Regular;

                    if ( GetSaveFlag( flags, SaveFlag.Durability ) )
                        m_Durability = (DurabilityLevel)reader.ReadEncodedInt();

                    if ( GetSaveFlag( flags, SaveFlag.Protection ) )
                        m_Protection = (ArmorProtectionLevel)reader.ReadEncodedInt();

                    if ( GetSaveFlag( flags, SaveFlag.BaseArmor ) )
                        m_ArmorBase = reader.ReadEncodedInt();
                    else
                        m_ArmorBase = -1;

                    if ( GetSaveFlag( flags, SaveFlag.StrBonus ) )
                        m_StrBonus = reader.ReadEncodedInt();
                    else
                        m_StrBonus = -1;

                    if ( GetSaveFlag( flags, SaveFlag.DexBonus ) )
                        m_DexBonus = reader.ReadEncodedInt();
                    else
                        m_DexBonus = -1;

                    if ( GetSaveFlag( flags, SaveFlag.IntBonus ) )
                        m_IntBonus = reader.ReadEncodedInt();
                    else
                        m_IntBonus = -1;

                    if ( GetSaveFlag( flags, SaveFlag.StrReq ) )
                        m_StrReq = reader.ReadEncodedInt();
                    else
                        m_StrReq = -1;

                    if ( GetSaveFlag( flags, SaveFlag.DexReq ) )
                        m_DexReq = reader.ReadEncodedInt();
                    else
                        m_DexReq = -1;

                    if ( GetSaveFlag( flags, SaveFlag.IntReq ) )
                        m_IntReq = reader.ReadEncodedInt();
                    else
                        m_IntReq = -1;

                    if ( GetSaveFlag( flags, SaveFlag.MedAllowance ) )
                        m_Meditate = (AMA)reader.ReadEncodedInt();
                    else
                        m_Meditate = (AMA)(-1);

                    if ( GetSaveFlag( flags, SaveFlag.SkillBonuses ) )
                        m_AosSkillBonuses = new AosSkillBonuses( this, reader );

                    if ( GetSaveFlag( flags, SaveFlag.PlayerConstructed ) )
                        m_PlayerConstructed = true;

                    break;
                }
                case 4:
                {
                    m_AosAttributes = new AosAttributes( this, reader );
                    m_AosArmorAttributes = new AosArmorAttributes( this, reader );
                    goto case 3;
                }
                case 3:
                {
                    m_PhysicalBonus = reader.ReadInt();
                    m_FireBonus = reader.ReadInt();
                    m_ColdBonus = reader.ReadInt();
                    m_PoisonBonus = reader.ReadInt();
                    m_EnergyBonus = reader.ReadInt();
                    goto case 2;
                }
                case 2:
                case 1:
                {
                    /*m_Identified = */reader.ReadBool();
                    goto case 0;
                }
                case 0:
                {
                    m_ArmorBase = reader.ReadInt();
                    m_MaxHitPoints = reader.ReadInt();
                    m_HitPoints = reader.ReadInt();
                    m_Crafter = reader.ReadMobile();
                    m_Quality = (CraftQuality)reader.ReadInt();
                    m_Durability = (DurabilityLevel)reader.ReadInt();
                    m_Protection = (ArmorProtectionLevel)reader.ReadInt();

                    AMT mat = (AMT)reader.ReadInt();

                    if ( m_ArmorBase == RevertArmorBase )
                        m_ArmorBase = -1;

                    /*m_BodyPos = (ArmorBodyType)*/reader.ReadInt();

                    if ( version < 4 )
                    {
                        m_AosAttributes = new AosAttributes( this );
                        m_AosArmorAttributes = new AosArmorAttributes( this );
                    }

                    if ( version < 3 && m_Quality == CraftQuality.Exceptional )
                        DistributeBonuses( 6 );

                    m_StrBonus = reader.ReadInt();
                    m_DexBonus = reader.ReadInt();
                    m_IntBonus = reader.ReadInt();
                    m_StrReq = reader.ReadInt();
                    m_DexReq = reader.ReadInt();
                    m_IntReq = reader.ReadInt();

                    if ( m_StrBonus == OldStrBonus )
                        m_StrBonus = -1;

                    if ( m_DexBonus == OldDexBonus )
                        m_DexBonus = -1;

                    if ( m_IntBonus == OldIntBonus )
                        m_IntBonus = -1;

                    if ( m_StrReq == OldStrReq )
                        m_StrReq = -1;

                    if ( m_DexReq == OldDexReq )
                        m_DexReq = -1;

                    if ( m_IntReq == OldIntReq )
                        m_IntReq = -1;

                    m_Meditate = (AMA)reader.ReadInt();

                    if ( m_Meditate == OldMedAllowance )
                        m_Meditate = (AMA)(-1);

                    if ( m_MaxHitPoints == 0 && m_HitPoints == 0 )
                        m_HitPoints = m_MaxHitPoints = Utility.RandomMinMax( InitMinHits, InitMaxHits );

                    break;
                }
            }

            if ( m_AosSkillBonuses == null )
                m_AosSkillBonuses = new AosSkillBonuses( this );

            if ( Core.AOS && Parent is Mobile )
                m_AosSkillBonuses.AddTo( (Mobile)Parent );

            int strBonus = ComputeStatBonus( StatType.Str );
            int dexBonus = ComputeStatBonus( StatType.Dex );
            int intBonus = ComputeStatBonus( StatType.Int );

            if ( Parent is Mobile && (strBonus != 0 || dexBonus != 0 || intBonus != 0) )
            {
                Mobile m = (Mobile)Parent;

                string modName = Serial.ToString();

                if ( strBonus != 0 )
                    m.AddStatMod( new StatMod( StatType.Str, modName + "Str", strBonus, TimeSpan.Zero ) );

                if ( dexBonus != 0 )
                    m.AddStatMod( new StatMod( StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero ) );

                if ( intBonus != 0 )
                    m.AddStatMod( new StatMod( StatType.Int, modName + "Int", intBonus, TimeSpan.Zero ) );
            }

            if ( Parent is Mobile )
                ((Mobile)Parent).CheckStatTimers();

            if ( version < 7 )
                m_PlayerConstructed = true; // we don't know, so, assume it's crafted
        }
Exemple #28
0
 public RemoveOptions Durability(DurabilityLevel durabilityLevel)
 {
     DurabilityLevel = durabilityLevel;
     return(this);
 }
Exemple #29
0
 public IncrementOptions WithDurability(DurabilityLevel durabilityLevel)
 {
     DurabilityLevel = durabilityLevel;
     return(this);
 }
Exemple #30
0
 public PrependOptions Durability(DurabilityLevel durabilityLevel)
 {
     DurabilityLevel = durabilityLevel;
     return(this);
 }
Exemple #31
0
 public ReplaceOptions WithDurability(DurabilityLevel durabilityLevel)
 {
     DurabilityLevel = durabilityLevel;
     return(this);
 }
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadInt();

            switch ( version )
            {
                case 8:
                {
                    m_Identified = reader.ReadMobileList();

                    goto case 7;
                }
                case 7:
                case 6:
                case 5:
                {
                    SaveFlag flags = (SaveFlag)reader.ReadInt();

                    if ( GetSaveFlag( flags, SaveFlag.DamageLevel ) )
                        m_DamageLevel = (WeaponDamageLevel)reader.ReadInt();

                    if ( GetSaveFlag( flags, SaveFlag.AccuracyLevel ) )
                        m_AccuracyLevel = (WeaponAccuracyLevel)reader.ReadInt();

                    if ( GetSaveFlag( flags, SaveFlag.DurabilityLevel ) )
                        m_DurabilityLevel = (DurabilityLevel)reader.ReadInt();

                    if ( GetSaveFlag( flags, SaveFlag.Quality ) )
                        m_Quality = (CraftQuality)reader.ReadInt();
                    else
                        m_Quality = CraftQuality.Regular;

                    if ( GetSaveFlag( flags, SaveFlag.Hits ) )
                        m_Hits = reader.ReadInt();

                    if ( GetSaveFlag( flags, SaveFlag.MaxHits ) )
                        m_MaxHits = reader.ReadInt();

                    if ( GetSaveFlag( flags, SaveFlag.Slayer ) )
                        m_Slayer = (SlayerName)reader.ReadInt();

                    if ( GetSaveFlag( flags, SaveFlag.Poison ) )
                        m_Poison = Poison.Deserialize( reader );

                    if ( GetSaveFlag( flags, SaveFlag.PoisonCharges ) )
                    {
                        m_PoisonCharges = reader.ReadInt();
                        if ( version >= 7 )
                            m_PoisonChance = reader.ReadDouble();
                        else
                            m_PoisonChance = Utility.RandomDouble() * 0.25;
                    }

                    if ( GetSaveFlag( flags, SaveFlag.Crafter ) )
                        m_Crafter = reader.ReadMobile();

                    if ( GetSaveFlag( flags, SaveFlag.Identified ) && version < 6 )
                        reader.ReadBool();
                        //m_Identified = ( version >= 6 || reader.ReadBool() );

                    if ( GetSaveFlag( flags, SaveFlag.StrReq ) )
                        m_StrReq = reader.ReadInt();
                    else
                        m_StrReq = -1;

                    if ( GetSaveFlag( flags, SaveFlag.DexReq ) )
                        m_DexReq = reader.ReadInt();
                    else
                        m_DexReq = -1;

                    if ( GetSaveFlag( flags, SaveFlag.IntReq ) )
                        m_IntReq = reader.ReadInt();
                    else
                        m_IntReq = -1;

                    if ( GetSaveFlag( flags, SaveFlag.MinDamage ) )
                        m_MinDamage = reader.ReadInt();
                    else
                        m_MinDamage = -1;

                    if ( GetSaveFlag( flags, SaveFlag.MaxDamage ) )
                        m_MaxDamage = reader.ReadInt();
                    else
                        m_MaxDamage = -1;

                    if ( GetSaveFlag( flags, SaveFlag.HitSound ) )
                        m_HitSound = reader.ReadInt();
                    else
                        m_HitSound = -1;

                    if ( GetSaveFlag( flags, SaveFlag.MissSound ) )
                        m_MissSound = reader.ReadInt();
                    else
                        m_MissSound = -1;

                    if ( GetSaveFlag( flags, SaveFlag.Speed ) )
                        m_Speed = reader.ReadInt();
                    else
                        m_Speed = -1;

                    if ( GetSaveFlag( flags, SaveFlag.MaxRange ) )
                        m_MaxRange = reader.ReadInt();
                    else
                        m_MaxRange = -1;

                    if ( GetSaveFlag( flags, SaveFlag.Skill ) )
                        m_Skill = (SkillName)reader.ReadInt();
                    else
                        m_Skill = (SkillName)(-1);

                    if ( GetSaveFlag( flags, SaveFlag.Type ) )
                        m_Type = (WeaponType)reader.ReadInt();
                    else
                        m_Type = (WeaponType)(-1);

                    if ( GetSaveFlag( flags, SaveFlag.Animation ) )
                        m_Animation = (WeaponAnimation)reader.ReadInt();
                    else
                        m_Animation = (WeaponAnimation)(-1);

                    if ( GetSaveFlag( flags, SaveFlag.Resource ) )
                        m_Resource = (CraftResource)reader.ReadInt();
                    else
                        m_Resource = CraftResource.Iron;

                    if ( GetSaveFlag( flags, SaveFlag.xAttributes ) )
                        m_AosAttributes = new AosAttributes( this, reader );
                    else
                        m_AosAttributes = new AosAttributes( this );

                    if ( GetSaveFlag( flags, SaveFlag.xWeaponAttributes ) )
                        m_AosWeaponAttributes = new AosWeaponAttributes( this, reader );
                    else
                        m_AosWeaponAttributes = new AosWeaponAttributes( this );

                    if ( UseSkillMod && m_AccuracyLevel != WeaponAccuracyLevel.Regular && Parent is Mobile )
                    {
                        m_SkillMod = new DefaultSkillMod( AccuracyMod, true, (int)m_AccuracyLevel * 5 );
                        ((Mobile)Parent).AddSkillMod( m_SkillMod );
                    }

                    if ( Core.AOS && m_AosWeaponAttributes.MageWeapon != 0 && Parent is Mobile )
                    {
                        m_MageMod = new DefaultSkillMod( SkillName.Magery, true, -m_AosWeaponAttributes.MageWeapon );
                        ((Mobile)Parent).AddSkillMod( m_MageMod );
                    }

                    if ( GetSaveFlag( flags, SaveFlag.PlayerConstructed ) )
                        m_PlayerConstructed = true;

                    if ( GetSaveFlag( flags, SaveFlag.SpellEffect ) )
                    {
                        m_Effect = (SpellEffect)reader.ReadInt();
                        m_EffectCharges = reader.ReadInt();
                    }

                    break;
                }
                case 4:
                {
                    m_Slayer = (SlayerName)reader.ReadInt();

                    goto case 3;
                }
                case 3:
                {
                    m_StrReq = reader.ReadInt();
                    m_DexReq = reader.ReadInt();
                    m_IntReq = reader.ReadInt();

                    goto case 2;
                }
                case 2:
                {
                    /*m_Identified = */reader.ReadBool();

                    goto case 1;
                }
                case 1:
                {
                    m_MaxRange = reader.ReadInt();

                    goto case 0;
                }
                case 0:
                {
                    if ( version == 0 )
                        m_MaxRange = 1; // default

                    if ( version < 5 )
                    {
                        m_Resource = CraftResource.Iron;
                        m_AosAttributes = new AosAttributes( this );
                        m_AosWeaponAttributes = new AosWeaponAttributes( this );
                    }

                    m_MinDamage = reader.ReadInt();
                    m_MaxDamage = reader.ReadInt();

                    m_Speed = reader.ReadInt();

                    m_HitSound = reader.ReadInt();
                    m_MissSound = reader.ReadInt();

                    m_Skill = (SkillName)reader.ReadInt();
                    m_Type = (WeaponType)reader.ReadInt();
                    m_Animation = (WeaponAnimation)reader.ReadInt();
                    m_DamageLevel = (WeaponDamageLevel)reader.ReadInt();
                    m_AccuracyLevel = (WeaponAccuracyLevel)reader.ReadInt();
                    m_DurabilityLevel = (DurabilityLevel)reader.ReadInt();
                    m_Quality = (CraftQuality)reader.ReadInt();

                    m_Crafter = reader.ReadMobile();

                    m_Poison = Poison.Deserialize( reader );
                    m_PoisonCharges = reader.ReadInt();

                    if ( m_StrReq == OldStrengthReq )
                        m_StrReq = -1;

                    if ( m_DexReq == OldDexterityReq )
                        m_DexReq = -1;

                    if ( m_IntReq == OldIntelligenceReq )
                        m_IntReq = -1;

                    if ( m_MinDamage == OldMinDamage )
                        m_MinDamage = -1;

                    if ( m_MaxDamage == OldMaxDamage )
                        m_MaxDamage = -1;

                    if ( m_HitSound == OldHitSound )
                        m_HitSound = -1;

                    if ( m_MissSound == OldMissSound )
                        m_MissSound = -1;

                    if ( m_Speed == OldSpeed )
                        m_Speed = -1;

                    if ( m_MaxRange == OldMaxRange )
                        m_MaxRange = -1;

                    if ( m_Skill == OldSkill )
                        m_Skill = (SkillName)(-1);

                    if ( m_Type == OldType )
                        m_Type = (WeaponType)(-1);

                    if ( m_Animation == OldAnimation )
                        m_Animation = (WeaponAnimation)(-1);

                    if ( UseSkillMod && m_AccuracyLevel != WeaponAccuracyLevel.Regular && Parent is Mobile )
                    {
                        m_SkillMod = new DefaultSkillMod( AccuracyMod, true, (int)m_AccuracyLevel * 5);
                        ((Mobile)Parent).AddSkillMod( m_SkillMod );
                    }

                    break;
                }
            }

            int strBonus = m_AosAttributes.BonusStr;
            int dexBonus = m_AosAttributes.BonusDex;
            int intBonus = m_AosAttributes.BonusInt;

            if ( this.Parent is Mobile && (strBonus != 0 || dexBonus != 0 || intBonus != 0) )
            {
                Mobile m = (Mobile)this.Parent;

                string modName = this.Serial.ToString();

                if ( strBonus != 0 )
                    m.AddStatMod( new StatMod( StatType.Str, modName + "Str", strBonus, TimeSpan.Zero ) );

                if ( dexBonus != 0 )
                    m.AddStatMod( new StatMod( StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero ) );

                if ( intBonus != 0 )
                    m.AddStatMod( new StatMod( StatType.Int, modName + "Int", intBonus, TimeSpan.Zero ) );
            }

            if ( Parent is Mobile )
                ((Mobile)Parent).CheckStatTimers();

            if ( m_Hits <= 0 && m_MaxHits <= 0 )
            {
                m_Hits = m_MaxHits = Utility.RandomMinMax( InitMinHits, InitMaxHits );
            }

            if ( version < 6 )
                m_PlayerConstructed = true; // we don't know, so, assume it's crafted
        }
Exemple #33
0
 public AppendOptions WithDurability(DurabilityLevel durabilityLevel)
 {
     DurabilityLevel = durabilityLevel;
     return(this);
 }