Пример #1
0
        public EffectBase DeserializeEffect(byte[] buffer, ref int index)
        {
            if (buffer.Length < index)
            {
                throw new System.Exception("buffer too small to contain an Effect");
            }
            byte       b = buffer[index];
            EffectBase effectBase;

            switch (b)
            {
            case 1:
                effectBase = new EffectBase();
                break;

            case 2:
                effectBase = new EffectCreature();
                break;

            case 3:
                effectBase = new EffectDate();
                break;

            case 4:
                effectBase = new EffectDice();
                break;

            case 5:
                effectBase = new EffectDuration();
                break;

            case 6:
                effectBase = new EffectInteger();
                break;

            case 7:
                effectBase = new EffectLadder();
                break;

            case 8:
                effectBase = new EffectMinMax();
                break;

            case 9:
                effectBase = new EffectMount();
                break;

            case 10:
                effectBase = new EffectString();
                break;

            default:
                throw new System.Exception(string.Format("Incorrect identifier : {0}", b));
            }
            index++;
            effectBase.DeSerialize(buffer, ref index);
            return(effectBase);
        }
Пример #2
0
        public void InitializeEffects(Mount mount)
        {
            if (Effects.Count > 0)
            {
                Effects.Clear();
            }

            Effects.Add(m_mountEffect = new EffectMount(EffectsEnum.Effect_ViewMountCharacteristics, mount.Id, DateTime.Now, mount.Template.Id));
            if (mount.Owner != null)
            {
                Effects.Add(m_belongsToEffect = new EffectString(EffectsEnum.Effect_BelongsTo, mount.Owner.Name));
            }
            Effects.Add(m_nameEffect     = new EffectString(EffectsEnum.Effect_Name, mount.Name));
            Effects.Add(m_validityEffect = new EffectDuration(EffectsEnum.Effect_Validity, MountManager.MountStorageValidity));

            Mount             = mount;
            mount.StoredSince = DateTime.Now;
            Owner.SetOwnedMount(mount);
        }
Пример #3
0
        private void Initialize()
        {
            if (Effects.Count > 0)
            {
                // hack to bypass initialization (see MountManager.StoreMount)
                if (Effects.Any(x => x.Id == -1))
                {
                    return;
                }

                m_mountEffect     = Effects.OfType <EffectMount>().FirstOrDefault();
                m_nameEffect      = Effects.OfType <EffectString>().FirstOrDefault(x => x.EffectId == EffectsEnum.Effect_Name);
                m_belongsToEffect = Effects.OfType <EffectString>().FirstOrDefault(x => x.EffectId == EffectsEnum.Effect_BelongsTo);
                m_validityEffect  = Effects.OfType <EffectDuration>().FirstOrDefault(x => x.EffectId == EffectsEnum.Effect_Validity);

                if (m_mountEffect == null)
                {
                    logger.Error($"Invalid certificate mount effect absent");
                    CreateMount();
                    return;
                }

                // invalid certificate
                if (m_mountEffect.Date < DateTime.Now - MountManager.MountStorageValidity)
                {
                    return;
                }

                var record = MountManager.Instance.GetMount(m_mountEffect.MountId);

                if (record == null) // mount has been deleted, the certificate isn't valid anymore
                {
                    return;
                }

                Mount = new Mount(Owner, record);
            }
            else
            {
                CreateMount();
            }
        }
Пример #4
0
        public EffectBase ConvertExportedEffect(EffectInstance effect)
        {
            EffectBase result;

            if (effect is EffectInstanceLadder)
            {
                result = new EffectLadder(effect as EffectInstanceLadder);
            }
            else
            {
                if (effect is EffectInstanceCreature)
                {
                    result = new EffectCreature(effect as EffectInstanceCreature);
                }
                else
                {
                    if (effect is EffectInstanceDate)
                    {
                        result = new EffectDate(effect as EffectInstanceDate);
                    }
                    else
                    {
                        if (effect is EffectInstanceDice)
                        {
                            result = new EffectDice(effect as EffectInstanceDice);
                        }
                        else
                        {
                            if (effect is EffectInstanceDuration)
                            {
                                result = new EffectDuration(effect as EffectInstanceDuration);
                            }
                            else
                            {
                                if (effect is EffectInstanceMinMax)
                                {
                                    result = new EffectMinMax(effect as EffectInstanceMinMax);
                                }
                                else
                                {
                                    if (effect is EffectInstanceMount)
                                    {
                                        result = new EffectMount(effect as EffectInstanceMount);
                                    }
                                    else
                                    {
                                        if (effect is EffectInstanceString)
                                        {
                                            result = new EffectString(effect as EffectInstanceString);
                                        }
                                        else
                                        {
                                            if (effect is EffectInstanceInteger)
                                            {
                                                result = new EffectInteger(effect as EffectInstanceInteger);
                                            }
                                            else
                                            {
                                                result = new EffectBase(effect);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }