public void AddBuff(Buff.Buff indicator)
        {
            if (indicator?.Card == null || indicator.Card.BuffType == BuffType.Bad && Buffs.Any(b => b.Card.CardId == indicator.Card.CardId))
            {
                return;
            }
            Buffs.RemoveWhere(s => !s.Card.CardId.Equals(indicator.Card.CardId), out ConcurrentBag <Buff.Buff> buffs);
            Buffs = buffs;
            //TODO: Find a better way to do this
            int randomTime = 0;

            if (Session is Character character)
            {
                if (indicator.Card.CardId == 85)
                {
                    randomTime = character.BuffRandomTime = ServerManager.Instance.RandomNumber(50, 350);
                }
                else if (indicator.Card.CardId == 336)
                {
                    randomTime = character.BuffRandomTime = ServerManager.Instance.RandomNumber(30, 70);
                }
                else if (indicator.Card.CardId == 0)
                {
                    character.BuffRandomTime = character.ChargeValue > 7000 ? 7000 : character.ChargeValue;
                }
                if (!indicator.StaticBuff)
                {
                    character.Session.SendPacket($"bf 1 {character.CharacterId} {(character.ChargeValue > 7000 ? 7000 : character.ChargeValue)}.{indicator.Card.CardId}.{indicator.Card.Duration} {Level}");
                    character.Session.SendPacket(character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("UNDER_EFFECT"), indicator.Card.Name), 20));
                }
            }
            if (!indicator.StaticBuff)
            {
                indicator.RemainingTime = indicator.Card.Duration == 0 ? randomTime : indicator.Card.Duration;
                indicator.Start         = DateTime.Now;
            }
            Buffs.Add(indicator);
            indicator.Card.BCards.ForEach(c => c.ApplyBCards(Entity));

            if (indicator.Card.EffectId > 0)
            {
                //Entity.MapInstance?.Broadcast(Entity.GenerateEff(indicator.Card.EffectId));
            }
            if (ObservableBag.TryGetValue(indicator.Card.CardId, out IDisposable value))
            {
                value?.Dispose();
            }

            ObservableBag[indicator.Card.CardId] = Observable.Timer(TimeSpan.FromMilliseconds(indicator.RemainingTime * (indicator.StaticBuff ? 1000 : 100))).Subscribe(o =>
            {
                RemoveBuff(indicator.Card.CardId);
                if (indicator.Card.TimeoutBuff != 0 && ServerManager.Instance.RandomNumber() < indicator.Card.TimeoutBuffChance)
                {
                    AddBuff(new Buff.Buff(indicator.Card.TimeoutBuff, Level));
                }
            });
        }
        public void RemoveBuff(int id, bool removePermaBuff = false)
        {
            Buff.Buff indicator = Buffs.FirstOrDefault(s => s.Card.CardId == id);
            if (indicator == null || !removePermaBuff && indicator.IsPermaBuff && indicator.RemainingTime <= 0)
            {
                return;
            }

            if (indicator.IsPermaBuff && !removePermaBuff)
            {
                AddBuff(indicator);
                return;
            }

            Buffs.RemoveWhere(s => s.Card.CardId != id, out ConcurrentBag <Buff.Buff> buffs);
            Buffs = buffs;
            if (!(Session is Character character))
            {
                return;
            }

            if (indicator.StaticBuff)
            {
                character.Session.SendPacket($"vb {indicator.Card.CardId} 0 {indicator.Card.Duration}");
                character.Session.SendPacket(character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("EFFECT_TERMINATED"), indicator.Card.Name), 11));
            }
            else
            {
                character.Session.SendPacket($"bf 1 {character.CharacterId} 0.{indicator.Card.CardId}.0 {Level}");
                character.Session.SendPacket(character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("EFFECT_TERMINATED"), indicator.Card.Name), 20));
            }

            if (indicator.Card.BCards.Any(s => s.Type == (byte)CardType.Move))
            {
                character.LoadSpeed();
                character.LastSpeedChange = DateTime.Now;
                character.Session.SendPacket(character.GenerateCond());
            }

            if (!indicator.Card.BCards.Any(s => s.Type == (byte)CardType.SpecialActions && s.SubType.Equals((byte)AdditionalTypes.SpecialActions.Hide)))
            {
                return;
            }

            character.Invisible = false;
            character.Mates.Where(m => m.IsTeamMember).ToList().ForEach(m => character.MapInstance?.Broadcast(m.GenerateIn()));
            character.MapInstance?.Broadcast(character.GenerateInvisible());
        }
Esempio n. 3
0
        public void RemoveBuff(int id, bool removePermaBuff = false)
        {
            Buff.Buff indicator = Buffs.FirstOrDefault(s => s.Card.CardId == id);
            if (indicator == null || !removePermaBuff && indicator.IsPermaBuff && indicator.RemainingTime <= 0)
            {
                return;
            }

            if (indicator.IsPermaBuff && !removePermaBuff)
            {
                AddBuff(indicator);
                return;
            }

            if (ObservableBag.ContainsKey((short)id))
            {
                ObservableBag[(short)id]?.Dispose();
            }
            Buffs.RemoveWhere(s => s.Card.CardId != id, out ConcurrentBag <Buff.Buff> buffs);
            Buffs = buffs;

            if (Session is MapMonster monster)
            {
                monster.ReflectiveBuffs.TryRemove((short)id, out _);
            }

            if (!(Session is Character character))
            {
                return;
            }

            character.ReflectiveBuffs.TryRemove((short)id, out _);

            // Fairy booster
            if (indicator.Card.CardId == 131)
            {
                character.GeneratePairy();
            }

            if (!character.ReflectiveBuffs.Any())
            {
                IsReflecting = false;
            }

            if (indicator.StaticBuff)
            {
                character.Session.SendPacket($"vb {indicator.Card.CardId} 0 {indicator.Card.Duration}");
                character.Session.SendPacket(character.GenerateSay(
                                                 string.Format(Language.Instance.GetMessageFromKey("EFFECT_TERMINATED"), indicator.Card.Name), 11));
            }
            else
            {
                character.Session.SendPacket($"bf 1 {character.CharacterId} 0.{indicator.Card.CardId}.0 {Level}");
                character.Session.SendPacket(character.GenerateSay(
                                                 string.Format(Language.Instance.GetMessageFromKey("EFFECT_TERMINATED"), indicator.Card.Name), 20));
            }

            // Fairy Booster
            if (indicator.Card.CardId == 131)
            {
                character.Session.SendPacket(character.GeneratePairy());
            }

            if (indicator.Card.BCards.Any(s => s.Type == (byte)CardType.Move))
            {
                character.LoadSpeed();
                character.LastSpeedChange = DateTime.Now;
                character.Session.SendPacket(character.GenerateCond());
            }

            if (!indicator.Card.BCards.Any(s =>
                                           s.Type == (byte)CardType.SpecialActions &&
                                           s.SubType.Equals((byte)AdditionalTypes.SpecialActions.Hide)) &&
                indicator.Card.CardId != 559 && indicator.Card.CardId != 560)
            {
                return;
            }

            if (indicator.Card.CardId == 559 && character.TriggerAmbush)
            {
                character.AddBuff(new Buff.Buff(560));
                character.TriggerAmbush = false;
                return;
            }

            if (indicator.Card.BCards.Any(s => s.Type == (byte)CardType.HideBarrelSkill && s.SubType.Equals((byte)AdditionalTypes.HideBarrelSkill.NoHPConsumption)))
            {
                character.HasGodMode = false;
            }

            if (indicator.Card.BCards.Any(s => s.Type == (byte)CardType.NoDefeatAndNoDamage && s.SubType.Equals((byte)AdditionalTypes.NoDefeatAndNoDamage.NeverReceiveDamage)))
            {
                character.HasGodMode = false;
            }

            character.Invisible = false;
            character.Mates.Where(m => m.IsTeamMember).ToList()
            .ForEach(m => character.MapInstance?.Broadcast(m.GenerateIn()));
            character.MapInstance?.Broadcast(character.GenerateInvisible());
        }
Esempio n. 4
0
        public void AddBuff(Buff.Buff indicator, IBattleEntity caster = null)
        {
            if (indicator?.Card == null || indicator.Card.BuffType == BuffType.Bad &&
                Buffs.Any(b => b.Card.CardId == indicator.Card.CardId))
            {
                return;
            }

            //TODO: add a scripted way to remove debuffs from boss when a monster is killed (475 is laurena's buff)
            if (indicator.Card.CardId == 475)
            {
                return;
            }

            Buffs.RemoveWhere(s => !s.Card.CardId.Equals(indicator.Card.CardId), out ConcurrentBag <Buff.Buff> buffs);
            Buffs = buffs;
            int randomTime = 0;

            if (Session is Character character)
            {
                randomTime = RandomTimeBuffs(indicator);

                if (!indicator.StaticBuff)
                {
                    character.Session.SendPacket(
                        $"bf 1 {character.CharacterId} {(character.ChargeValue > 7000 ? 7000 : character.ChargeValue)}.{indicator.Card.CardId}.{(indicator.Card.Duration == 0 ? randomTime : indicator.Card.Duration)} {Level}");
                    character.Session.SendPacket(character.GenerateSay(
                                                     string.Format(Language.Instance.GetMessageFromKey("UNDER_EFFECT"), indicator.Card.Name), 20));
                }
            }

            if (Session is Mate mate)
            {
                randomTime = RandomTimeBuffs(indicator);
                mate.Owner?.Session.SendPacket($"bf 1 {mate.Owner?.CharacterId} 0.{indicator.Card.CardId}.{(indicator.Card.Duration == 0 ? randomTime : indicator.Card.Duration)} {Level}");
            }

            if (!indicator.StaticBuff)
            {
                indicator.RemainingTime = indicator.Card.Duration == 0 ? randomTime : indicator.Card.Duration;
                indicator.Start         = DateTime.Now;
            }

            Buffs.Add(indicator);
            if (indicator.Entity != null)
            {
                indicator.Card.BCards.ForEach(c => c.ApplyBCards(Entity, indicator.Entity));
            }
            else
            {
                indicator.Card.BCards.ForEach(c => c.ApplyBCards(Entity));
            }

            if (indicator.Card.EffectId > 0 && indicator.Card.EffectId != 7451)
            {
                Entity.MapInstance?.Broadcast(Entity.GenerateEff(indicator.Card.EffectId));
            }

            if (ObservableBag.TryGetValue(indicator.Card.CardId, out IDisposable value))
            {
                value?.Dispose();
            }

            ObservableBag[indicator.Card.CardId] = Observable
                                                   .Timer(TimeSpan.FromMilliseconds(indicator.RemainingTime * (indicator.StaticBuff ? 1000 : 100)))
                                                   .Subscribe(o =>
            {
                RemoveBuff(indicator.Card.CardId);

                if (indicator.Card.TimeoutBuff != 0 &&
                    ServerManager.Instance.RandomNumber() < indicator.Card.TimeoutBuffChance)
                {
                    AddBuff(new Buff.Buff(indicator.Card.TimeoutBuff, Level));
                }
            });
        }