Beispiel #1
0
        public void OnEntityTarget(EntityTargetPacket packet)
        {
            var player = Server.GetPlayer(packet.WhoUuid);

            if (packet.TargetUuid == null)
            {
                player.Target.BeingTargetedBy.Remove(player);
                player.Target = null;
                Log.Info("CANCEL TARGET");
                GameScheduler.CancelTask(player.AttackTaskId);
                return;
            }

            var targetEntityType = packet.TargetUuid.GetEntityTypeFromUid();

            if (targetEntityType == EntityType.MONSTER)
            {
                var monster = Server.Map.Monsters[packet.TargetUuid];
                Server.Events.Call(new EntityTargetEvent()
                {
                    Entity         = player,
                    TargetedEntity = monster
                });
            }
        }
        public static void RescheduleAttack(LivingEntity attacker, LivingEntity defender, long attackDelay)
        {
            if (attacker.AttackTaskId != null)
            {
                GameScheduler.CancelTask(attacker.AttackTaskId);
            }

            var attackTask = new SchedulerTask(attackDelay + 1, GameThread.TIME_MS_NOW)
            {
                Task = () =>
                {
                    if (attacker.EntityType == EntityType.PLAYER)
                    {
                        if (Server.GetPlayer(attacker.UID) == null)
                        {
                            return;
                        }
                    }
                    TryAttacking(attacker, defender);
                }
            };

            GameScheduler.Schedule(attackTask);
            attacker.AttackTaskId = attackTask.UID;
        }
Beispiel #3
0
 public override void Die()
 {
     Log.Debug(this.Name + " Died");
     Server.Map.UpdateEntityPosition(this, from: this.Position, to: null);
     Server.Map.Monsters.Remove(this.UID);
     this.OriginSpawner?.CreateSpawnTask();
     GameScheduler.CancelTask(MovementTaskId);
     GameScheduler.CancelTask(AttackTaskId);
 }
Beispiel #4
0
        public static void TryAttacking(this LivingEntity attacker, LivingEntity defender, bool singleHit = false)
        {
            if (attacker.Position.GetDistance(defender.Position) > 1)
            {
                Log.Info("Entity tryed to attack other entity being too far away");
                return;
            }
            if (defender.HP <= 0 || attacker.HP < 0)
            {
                return;
            }
            var now = GameThread.TIME_MS_NOW;

            if (now < attacker.NextAttackAt)
            {
                var timeToFinishCd = attacker.NextAttackAt - now;
                if (!singleHit)
                {
                    RescheduleAttack(attacker, defender, timeToFinishCd);
                }
                return;
            }
            if (attacker.AttackTaskId != null)
            {
                GameScheduler.CancelTask(attacker.AttackTaskId);
            }
            var attackDelay = Formulas.GetTimeBetweenAttacks(attacker.AtkSpeed);

            attacker.NextAttackAt = now + attackDelay;

            Log.Debug(attacker.Name + " Attacking " + defender.Name);
            Server.Events.Call(new EntityAttackEvent()
            {
                Attacker = attacker,
                Defender = defender
            });

            if (!singleHit)
            {
                RescheduleAttack(attacker, defender, attackDelay);
            }
        }
Beispiel #5
0
        public void MovementTick()
        {
            if (MovementTaskId == Guid.Empty)
            {
                GameScheduler.CancelTask(MovementTaskId);
            }

            MovementBehaviour?.PerformMovement(this);
            LastMovement        = GameThread.TIME_MS_NOW;
            this.MovementTaskId = GameScheduler.Schedule(new SchedulerTask(MovementDelay, LastMovement)
            {
                Task = () =>
                {
                    MovementTaskId = Guid.Empty;
                    if (HP > 0)
                    {
                        MovementTick();
                    }
                }
            });
        }