Ejemplo n.º 1
0
 public Buff(int id, byte level = 0, bool isPermaBuff = false, IBattleEntity entity = null)
 {
     Card        = ServerManager.Instance.Cards.FirstOrDefault(s => s.CardId == id);
     Level       = level;
     IsPermaBuff = isPermaBuff;
     Entity      = entity;
 }
Ejemplo n.º 2
0
        public void GenerateDeath(IBattleEntity killer = null)
        {
            if (!IsAlive || IsInvicible) // Act4 Guardians
            {
                CurrentHp = IsInvicible ? 1 : CurrentHp;
                return;
            }

            IsAlive   = false;
            CurrentHp = 0;
            CurrentMp = 0;
            Death     = DateTime.Now;
            LastMove  = DateTime.Now.AddMilliseconds(500);
            BattleEntity.Buffs.Clear();
            Target = null;
            if (MapInstance?.InstanceBag != null)
            {
                MapInstance.InstanceBag.Combo += IsBonus ? 1 : 0;
                MapInstance.InstanceBag.Point +=
                    EventHelper.Instance.CalculateComboPoint(MapInstance.InstanceBag.Combo + (IsBonus ? 1 : 0));
                MapInstance.InstanceBag.MonstersKilled++;
            }
            BattleEntity.OnDeathEvents.ToList().ForEach(e => { EventHelper.Instance.RunEvent(e, monster: this); });
            killer?.GenerateRewards(this);
        }
Ejemplo n.º 3
0
        public BattleReward Reward(IBattleEntity victim)
        {
            MonsterBattleEntity monster = victim as MonsterBattleEntity;

            if (monster == null)
            {
                return(null);
            }

            context.GetModule <PlayerModule>().AddExperience(user.Service, user.Name, monster.Monster.Experience);
            context.GetModule <PlayerModule>().UpdateGold(PlayerID, monster.Monster.Gold);

            Item     item     = null;
            DropItem dropitem = monster.Monster.DroppedItems.FirstOrDefault(i => RNG.XORShift64.NextDouble() < i.Rate);

            if (dropitem != null)
            {
                item = context.GetModule <ItemModule>().GetItem(dropitem.ItemID);
                if (item != null)
                {
                    if (context.GetModule <InventoryModule>().AddItem(PlayerID, item.ID, 1) == AddInventoryItemResult.InventoryFull)
                    {
                        item = null;
                    }
                }
            }

            return(new BattleReward {
                XP = monster.Monster.Experience,
                Gold = monster.Monster.Gold,
                Item = item
            });
        }
Ejemplo n.º 4
0
    public override List <IBattleEntity> FindAllReachableTargets(IBattleEntity source)
    {
        _mapController.GetNeighbourDeltas(source.Coords, out var offsets);

        List <IBattleEntity> targetsAtBestPos = new List <IBattleEntity>();

        foreach (var offset in offsets)
        {
            Vector2Int atCoords        = offset + source.Coords;
            var        targetsAtCoords = FindTargetsAtCoords(source, atCoords);
            var        numTargets      = targetsAtCoords.Count;
            if (numTargets == 0)
            {
                continue;
            }

            if (numTargets > targetsAtBestPos.Count)
            {
                targetsAtBestPos = targetsAtCoords;
            }
        }
        if (targetsAtBestPos.Count > 1 && ((SimpleMeleeAttackData)Data).SingleTarget)
        {
            targetsAtBestPos.RemoveRange(1, targetsAtBestPos.Count - 1);
        }
        return(targetsAtBestPos);
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Hostility on actual Target
        /// </summary>
        internal void HostilityTarget()
        {
            if (!IsHostile || Target != null)
            {
                return;
            }
            IBattleEntity target = MapInstance.BattleEntities.FirstOrDefault(e => e.IsTargetable(SessionType()) && IsFactionTargettable(e.Faction) && Map.GetDistance(GetPos(), e.GetPos()) < (NoticeRange == 0 ? Monster.NoticeRange : NoticeRange));

            if (target == null || MoveEvent != null)
            {
                return;
            }
            if (OnNoticeEvents.Any())
            {
                OnNoticeEvents.ToList().ForEach(e => { EventHelper.Instance.RunEvent(e, monster: this); });
                OnNoticeEvents.Clear();
                return;
            }

            Target = target;
            if (!Monster.NoAggresiveIcon && LastEffect.AddSeconds(5) < DateTime.Now && target.GetSession() is Character character)
            {
                character?.Session.SendPacket(GenerateEff(5000));
            }
        }
Ejemplo n.º 6
0
        public static void Handle(IBattleEntity target, IBattleEntity sender, BCardDto bcard)
        {
            var random = ChickenContainer.Instance.Resolve <IRandomGenerator>();

            if (random.Next() >= bcard.FirstData)
            {
                return;
            }

            CardDto card = ChickenContainer.Instance.Resolve <ICardService>().GetById(bcard.SecondData);

            if (card == null)
            {
                Log.Debug($"Couldn't find any buff with card Id : {bcard.SecondData}");
                return;
            }

            var buff = new BuffContainer(card, sender.Level);

            target.AddBuff(buff);
            if (target is IPlayerEntity player)
            {
                player.SendPacketAsync(player.GenerateBfPacket(buff));
            }
        }
Ejemplo n.º 7
0
    private void Attacked(IBattleEntity arg1, IBattleEntity arg2, BattleActionResult arg3)
    {
        var evt = CreateEvent <BattleEventLog>();

        evt.results = arg3;
        AddEvent(evt);
    }
Ejemplo n.º 8
0
        public override void Process(IBattleEntity attacker, IBattleEntity target)
        {
            float hitprobability = MathCore.Sigmoid(attacker.Dexterity - target.Dexterity, 1.1f, GetCenter());

            if (RNG.XORShift64.NextFloat() < hitprobability)
            {
                long playerid = (target as PlayerBattleEntity)?.PlayerID ?? 0;
                int  gold     = Level * 50 + RNG.XORShift64.NextInt(attacker.Level * 15);
                gold = Math.Min(gold, context.GetModule <PlayerModule>().GetPlayerGold(playerid));

                if (gold == 0)
                {
                    context.GetModule <RPGMessageModule>().Create().BattleActor(attacker).Text(" looks at ").BattleActor(target).Text(" unable to grasp how someone can enter a battle without any ").Gold(0).Text(".").Send();
                }
                else
                {
                    context.GetModule <PlayerModule>().UpdateGold(playerid, -gold);
                    context.GetModule <RPGMessageModule>().Create().BattleActor(attacker).Text(" steals ").Gold(gold).Text(" from ").BattleActor(target).Text(", throwing it into the next hole while laughing maniacally.").Send();
                }
            }
            else
            {
                context.GetModule <RPGMessageModule>().Create().BattleActor(attacker).Text(" fails to steal ").Gold(0).Text(" from ").BattleActor(target).Text(".").Send();
            }
        }
Ejemplo n.º 9
0
    private void AttackOnCooldown(IBattleEntity obj)
    {
        var evt = CreateEvent <SimpleMessage>();

        evt.Text = "Tried to attack while on cooldown!\n";
        AddEvent(evt);
    }
Ejemplo n.º 10
0
 public static void AddBuff(this IBattleEntity entity, BuffContainer buffContainer)
 {
     if (entity.GetBuffByCardId(buffContainer.Id) == null)
     {
         entity.Buffs.Add(buffContainer);
     }
 }
Ejemplo n.º 11
0
    public override bool CanTargetBeReached(IBattleEntity attacker, IBattleEntity target)
    {
        var srcCoords = attacker.Coords;
        var tgtCoords = target.Coords;

        return(CanCoordsBeReached(srcCoords, tgtCoords));
    }
Ejemplo n.º 12
0
 public void GenerateRewards(IBattleEntity target)
 {
     if (target is MapMonster monster)
     {
         Owner.GenerateKillBonus(monster);
     }
 }
Ejemplo n.º 13
0
 private static Task CheckEntity(IBattleEntity entity)
 {
     if (entity is IPlayerEntity session)
     {
         return(session.ActualizeUiHpBar());
     }
     return(Task.CompletedTask);
 }
Ejemplo n.º 14
0
        public static void RemoveBuffById(this IBattleEntity entity, long id)
        {
            BuffContainer buffContainer = entity.GetBuffByCardId(id);

            if (buffContainer != null)
            {
                entity.Buffs.Remove(buffContainer);
            }
        }
Ejemplo n.º 15
0
        void PlayerDefeated(IBattleEntity target, RPGMessageBuilder message)
        {
            IBattleEntity attacker = Actors.FirstOrDefault(a => a is MonsterBattleEntity);

            message?.BattleActor(target).Text(" dies miserably and ").BattleActor(attacker).Text(" is laughing.");

            lock (actors)
                actors.Remove(target);
        }
Ejemplo n.º 16
0
 public async Task <HitRequest> CreateHitRequest(IBattleEntity sender, IBattleEntity target, SkillDto dto) =>
 new HitRequest
 {
     Sender    = sender,
     Target    = target,
     UsedSkill = dto,
     Damages   = 0,
     Bcards    = new List <BCardDto>(await _bCardService.GetBySkillIdAsync(dto.Id))
 };
Ejemplo n.º 17
0
        protected override async Task Handle(UseSkillPacket packet, IPlayerEntity player)
        {
            if (packet.CastId != 0)
            {
                await player.SendPacketAsync(new MscPacket());
            }

            if (player.IsSitting)
            {
                player.IsSitting = false;
            }

            if (!player.SkillComponent.SkillsByCastId.TryGetValue(packet.CastId, out SkillDto skill))
            {
                // skill does not exist
                await player.SendPacketAsync(player.GenerateEmptyCancelPacket(CancelPacketType.NotInCombatMode));

                Log.Warn($"{player.Character.Name} Trying to cast unowned skill");
                return;
            }

            IBattleEntity target = null;

            switch (packet.TargetVisualType)
            {
            case VisualType.Character:
                target = player.CurrentMap.GetEntity <IPlayerEntity>(packet.TargetId, VisualType.Character);
                break;

            case VisualType.Monster:
                target = player.CurrentMap.GetEntity <IMonsterEntity>(packet.TargetId, VisualType.Monster);
                break;

            case VisualType.Npc:
                target = player.CurrentMap.GetEntity <INpcEntity>(packet.TargetId, VisualType.Npc);
                break;
            }

            switch (target)
            {
            case null:
                await player.SendPacketAsync(player.GenerateEmptyCancelPacket(CancelPacketType.InCombatMode));

                return;

            case IBattleEntity battleEntity:

                await player.EmitEventAsync(new UseSkillEvent
                {
                    Skill  = skill,
                    Target = battleEntity
                });

                break;
            }
        }
Ejemplo n.º 18
0
 public void Remove(IBattleEntity entity, RPGMessageBuilder message = null)
 {
     lock (actorlock) {
         actors.Remove(entity);
         if (entity is MonsterBattleEntity)
         {
             MonsterDefeated((MonsterBattleEntity)entity, message);
         }
     }
 }
Ejemplo n.º 19
0
    public override List <IBattleEntity> FindTargetsAtCoords(IBattleEntity source, Vector2Int refCoords)
    {
        var srcCoords = source.Coords;

        if (CanCoordsBeReached(srcCoords, refCoords))
        {
            return(_entityController.GetFilteredEntitiesAt <IBattleEntity>(refCoords).FindAll(x => x.IsHostileTo(source)));
        }
        return(new List <IBattleEntity>());
    }
Ejemplo n.º 20
0
        internal void HostilityTarget()
        {
            if (Target != null)
            {
                return;
            }
            IBattleEntity target = MapInstance.BattleEntities.FirstOrDefault(e => e.IsTargetable(SessionType()) && Map.GetDistance(GetPos(), e.GetPos()) < Npc.NoticeRange);

            Target = target ?? Target;
        }
Ejemplo n.º 21
0
 public static CtPacket GenerateCtPacket(this IBattleEntity entity, IEntity target, SkillDto skill) =>
 new CtPacket
 {
     CastAnimationId  = skill.CastAnimation,
     CastEffect       = skill.CastEffect,
     SkillId          = skill.Id,
     VisualType       = entity.Type,
     VisualId         = entity.Id,
     TargetVisualType = target.Type,
     TargetId         = target.Id
 };
Ejemplo n.º 22
0
        public void PlayerDefeated(long playerid)
        {
            IBattleEntity target = Actors.FirstOrDefault(a => a is PlayerBattleEntity && ((PlayerBattleEntity)a).PlayerID == playerid);

            if (target == null)
            {
                return;
            }

            PlayerDefeated(target, null);
        }
Ejemplo n.º 23
0
 public void Add(IBattleEntity entity)
 {
     lock (actorlock) {
         actors.Add(entity);
         if (actors.Count == 2)
         {
             messages?.Create().BattleActor(actors[0], true).Text(" encounters a ").BattleActor(actors[1], true).Text(".").Send();
             actor = RNG.XORShift64.NextInt(2);
         }
     }
 }
Ejemplo n.º 24
0
        public EffectResult ProcessEffect(IBattleEntity attacker, IBattleEntity target)
        {
            float deflectchance = Math.Min(0.15f, Level * 0.03f);

            if (RNG.XORShift64.NextFloat() <= deflectchance)
            {
                messages.Create().BattleActor(attacker).Text(" is disgusted by the urinal smell of ").BattleActor(target).Text(" and refrains from attacking.").Send();
                return(new EffectResult(EffectResultType.CancelAttack));
            }
            return(new EffectResult(EffectResultType.None));
        }
Ejemplo n.º 25
0
 public EffectResult ProcessEffect(IBattleEntity attacker, IBattleEntity target)
 {
     if (RNG.XORShift64.NextFloat() <= Math.Min(0.25f, Level * 0.04f))
     {
         return(new EffectResult(EffectResultType.NewEffectTarget, new InfectionEffect(target, context.GetModule <AdventureModule>(), context.GetModule <RPGMessageModule>())
         {
             Level = Level,
             Time = 10.0 * Level
         }));
     }
     return(new EffectResult(EffectResultType.None));
 }
Ejemplo n.º 26
0
        public BattleEntity(IBattleEntity entity)
        {
            Entity                = entity;
            Session               = entity.GetSession();
            Buffs                 = new ConcurrentBag <Buff.Buff>();
            StaticBcards          = new ConcurrentBag <BCard>();
            SkillBcards           = new ConcurrentBag <BCard>();
            OnDeathEvents         = new ConcurrentBag <EventContainer>();
            OnHitEvents           = new ConcurrentBag <EventContainer>();
            ObservableBag         = new ConcurrentDictionary <short, IDisposable>();
            ShellOptionArmor      = new ConcurrentBag <EquipmentOptionDTO>();
            ShellOptionsMain      = new ConcurrentBag <EquipmentOptionDTO>();
            ShellOptionsSecondary = new ConcurrentBag <EquipmentOptionDTO>();
            CostumeHatBcards      = new ConcurrentBag <BCard>();
            CostumeSuitBcards     = new ConcurrentBag <BCard>();
            CostumeBcards         = new ConcurrentBag <BCard>();
            CellonOptions         = new ThreadSafeGenericList <EquipmentOptionDTO>();

            if (Session is Character character)
            {
                Level = character.Level;
                return;
            }

            NpcMonster npcMonster = Session is MapMonster mon ? mon.Monster
                : Session is MapNpc npc ? npc.Npc
                : Session is Mate mate ? mate.Monster
                : null;

            if (npcMonster == null)
            {
                return;
            }

            Level               = npcMonster.Level;
            Element             = npcMonster.Element;
            ElementRate         = npcMonster.ElementRate;
            FireResistance      = npcMonster.FireResistance;
            WaterResistance     = npcMonster.WaterResistance;
            LightResistance     = npcMonster.LightResistance;
            DarkResistance      = npcMonster.DarkResistance;
            DefenceRate         = npcMonster.DefenceDodge;
            DistanceDefenceRate = npcMonster.DistanceDefenceDodge;
            CloseDefence        = npcMonster.CloseDefence;
            RangedDefence       = npcMonster.DistanceDefence;
            MagicDefence        = npcMonster.MagicDefence;
            AttackUpgrade       = npcMonster.AttackUpgrade;
            CriticalChance      = npcMonster.CriticalChance;
            CriticalRate        = npcMonster.CriticalRate - 30;
            MinDamage           = npcMonster.DamageMinimum;
            MaxDamage           = npcMonster.DamageMaximum;
            HitRate             = npcMonster.Concentrate;
        }
Ejemplo n.º 27
0
    public bool TryAttackEntity(IBattleEntity other)
    {
        bool canAttack = _owner.IsHostileTo(other) && CurrentAttack.CanTargetBeReached(_owner, other);

        if (canAttack)
        {
            PrepareAttack(CurrentAttack.FindAllReachableTargets(_owner));
        }
        var defeated = StartAttack();

        return(defeated.Contains(other));
    }
Ejemplo n.º 28
0
 private Task KillMonster(IBattleEntity monster)
 {
     monster.Hp = 0;
     return(Context.Player.BroadcastAsync(monster.GenerateSuPacket(new HitRequest
     {
         Sender = Context.Player,
         Target = monster,
         HitMode = SuPacketHitMode.CriticalAttack,
         Damages = (uint)(monster.HpMax > ushort.MaxValue ? ushort.MaxValue : monster.HpMax),
         UsedSkill = Skill
     })));
 }
Ejemplo n.º 29
0
    public static void SolveAttack(IBattleEntity attacker, IBattleEntity defender, out BattleActionResult results)
    {
        results = new BattleActionResult();
        results.AttackerName = attacker.Name;
        results.DefenderName = defender.Name;

        results.DefenderStartHP = defender.HPTrait.HP;

        // 1. Solve chance to hit
        float attackerHitChance = 1.0f;

        if (URandom.value > attackerHitChance)
        {
            results.AttackerFlopped = true;
            return;
        }

        // 2. Solve defender's deflection
        float defenderAvoidChance = 0.0f;

        if (URandom.value <= defenderAvoidChance)
        {
            results.DefenderAvoided = true;
            return;
        }

        // 3. Crit check?
        float attackCriticalBonus = 0.0f;

        float attackerCritChance = 0.0f;

        if (URandom.value <= attackerCritChance)
        {
            attackCriticalBonus = 0.0f;
            results.Critical    = true;
        }

        // 4. Attack
        float attack = attacker.BattleTrait.Damage;

        attack *= (1 + attackCriticalBonus);
        float defense = 0.0f;

        int damageInflicted = (int)((attack * attack) / (attack + defense));

        results.AttackerDmgInflicted = damageInflicted;
        results.DefenderDmgTaken     = Mathf.Min(damageInflicted, defender.HPTrait.HP);
        results.DefenderDefeated     = damageInflicted >= defender.HPTrait.HP;

        attacker.ApplyBattleResults(results, BattleRole.Attacker);
        defender.ApplyBattleResults(results, BattleRole.Defender);
    }
Ejemplo n.º 30
0
    public override List <IBattleEntity> FindAllReachableTargets(IBattleEntity source)
    {
        var allInMaxRange = _entityController.GetNearbyEntities(source.Coords, _rangeData.MaxRange);

        allInMaxRange.RemoveAll(x => !typeof(IBattleEntity).IsAssignableFrom(x.GetType()));

        var allBattlers = allInMaxRange.ConvertAll(x => (IBattleEntity)x);

        allBattlers.RemoveAll(x => !source.IsHostileTo(x));
        allBattlers.RemoveAll(x => _mapController.Distance(x.Coords, source.Coords) < _rangeData.MinRange);
        allBattlers.RemoveAll(x => !CanTargetBeReached(source, x));
        return(allBattlers);
    }