Beispiel #1
0
        void CleanupLinkdead()
        {
            var remove = _listener.Clients
                         .Where(client => client.Status != ConnectionStatus.Connected &&
                                (Global.Now - client.LastMessageTimestamp) > TimeSpan.FromSeconds(60))
                         .ToList();

            foreach (ClientConnection client in remove)
            {
                if (client.Avatar != null)
                {
                    ((MobileAvatar)client.Avatar).Client = null;
                    _world.Remove(client.Avatar);
                }
                else
                {
                    client.Avatar = null;
                }
                _listener.Clients.Remove(client);
            }
        }
Beispiel #2
0
        // TODO: use dynamic instead
        public void PhysicalAttack(PhysicalObject po)
        {
            // TODO use the real range of kill
            if ((Position - po.Position).Length > 100)
            {
                // target is out of range
                SendLog(Target.TemplateObjectName + " is out of range.");
                return;
            }
            if (po is MobileAvatar)
            {
                var opponent = (MobileAvatar)po;

                // if not already in a fight, your opponent automatically
                // fights back
                if (opponent.Target == null)
                {
                    opponent.Target = this;
                }

                // avoidance phase: ratio of Dexterity
                if (Dexterity == 0 || Global.Rand.Next(100) <= opponent.Dexterity / Dexterity * 20)
                {
                    // 20% chance for equal dexterity player to avoid
                    World.InformNearby(
                        this,
                        new ToClient.CombatReport(this, Target, EnumCombatEvent.Avoids, 0));
                    return;
                }

                // hit phase: hit-roll determines if you miss, hit armor, or bypass armor
                int hitroll    = 80;
                int attackroll = Global.Rand.Next(hitroll);

                if (attackroll < 20)
                {
                    // %20 chance to miss for weapon with 100 hit-roll
                    World.InformNearby(
                        this,
                        new ToClient.CombatReport(this, Target, EnumCombatEvent.Misses, 0));
                }

                // damage phase: weapon damage + bonuses
                int damage = 10;
                // TODO: use armor rating
                if (attackroll < 50)
                {
                    damage -= 8; // opponent.ArmorRating
                }
                if (damage < 0)
                {
                    damage = 0;
                }

                damage              *= Strength / opponent.Constitution;
                opponent.HitPoints  -= damage;
                opponent.MobileState = EnumMobileState.Fighting;
                opponent.UpdateState();
                World.InformNearby(
                    this,
                    new ToClient.CombatReport(this, Target, EnumCombatEvent.Hits, damage));
            }
            else if (po is Item)
            {
                // attacking object
                var item   = Target as Item;
                int damage = 10;
                item.HitPoints -= damage;
                World.InformNearby(
                    this,
                    new ToClient.CombatReport(this, Target, EnumCombatEvent.Hits, damage));

                // You destroyed the item
                if (item.HitPoints <= 0)
                {
                    World.Remove(item);
                }
            }
            else
            {
                throw new Exception("ERROR: attacking a " + po.GetType() + " " + po);
            }
        }