Esempio n. 1
0
        public void ChangeOpponent()
        {
            Mobile agro, best = null;
            double distance, random = Utility.RandomDouble();

            if (random < 0.75)
            {
                // find random target relatively close
                for (int i = 0; i < Aggressors.Count && best == null; i++)
                {
                    agro = Validate(Aggressors[i].Attacker);

                    if (agro == null)
                    {
                        continue;
                    }

                    distance = StrikingRange - GetDistanceToSqrt(agro);

                    if (distance > 0 && distance < StrikingRange - 2 && InLOS(agro.Location))
                    {
                        distance /= StrikingRange;

                        if (random < distance)
                        {
                            best = agro;
                        }
                    }
                }
            }
            else
            {
                int damage = 0;

                // find a player who dealt most damage
                for (int i = 0; i < DamageEntries.Count; i++)
                {
                    agro = Validate(DamageEntries[i].Damager);

                    if (agro == null)
                    {
                        continue;
                    }

                    distance = GetDistanceToSqrt(agro);

                    if (distance < StrikingRange && DamageEntries[i].DamageGiven > damage && InLOS(agro.Location))
                    {
                        best   = agro;
                        damage = DamageEntries[i].DamageGiven;
                    }
                }
            }

            if (best != null)
            {
                // teleport
                best.Location = BasePeerless.GetSpawnPosition(Location, Map, 1);
                best.FixedParticles(0x376A, 9, 32, 0x13AF, EffectLayer.Waist);
                best.PlaySound(0x1FE);

                Timer.DelayCall(TimeSpan.FromSeconds(1), new TimerCallback(delegate()
                {
                    // poison
                    best.ApplyPoison(this, HitPoison);
                    best.FixedParticles(0x374A, 10, 15, 5021, EffectLayer.Waist);
                    best.PlaySound(0x474);
                }));

                m_Change = DateTime.UtcNow + TimeSpan.FromSeconds(Utility.RandomMinMax(5, 10));
            }
        }