public List <PlayerMgr> GetRangePlayers(int dist)
 {
     try
     {
         List <PlayerMgr> Players = new List <PlayerMgr>();
         lock (Helpers.Manager.clients)
         {
             for (int i = 0; i < Helpers.Manager.clients.Count; i++)
             {
                 PlayerMgr s = Helpers.Manager.clients[i];
                 //double distance = Formule.gamedistance((float)x, (float)y, s.Character.Position.x, s.Character.Position.y);
                 double distance = Formule.gamedistance(this, s.Character.Position);
                 if (distance <= dist)
                 {
                     Players.Add(s);
                 }
             }
             return(Players);
         }
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
     return(null);
 }
Exemplo n.º 2
0
        private void HarmonyBuff_callback(object e)
        {
            try
            {
                foreach (int p in Spawn)
                {
                    PlayerMgr s = Helpers.GetInformation.GetPlayer(p);

                    //double distance = Formule.gamedistance((float)x, (float)y, s.Character.Position.x, s.Character.Position.y);
                    double distance = Formule.gamedistance(this, s.Character.Position);
                    if (distance <= Radius && !s.Character.Action.Buff.InfiniteBuffs.ContainsKey(Name))
                    {
                        byte slot = s.SkillBuffGetFreeSlot();
                        if (slot == 255)
                        {
                            return;
                        }

                        //add properties
                        foreach (KeyValuePair <string, int> a in ObjData.Manager.SkillBase[ID].Properties1)
                        {
                            if (s.SkillAdd_Properties(s, a.Key, true, slot))
                            {
                                return;
                            }
                            ;
                        }

                        s.Character.Action.Buff.SkillID[slot] = ID;
                        s.Character.Action.Buff.OverID[slot]  = s.Character.Ids.GetBuffID();
                        s.Character.Action.Buff.slot          = slot;
                        s.Character.Action.Buff.count++;

                        s.Send(s.Character.Spawn, Client.Packet.SkillIconPacket(s.Character.Information.UniqueID, ID, s.Character.Action.Buff.OverID[s.Character.Action.Buff.slot], false));
                        s.Character.Action.Buff.InfiniteBuffs.Add(Name, s.Character.Action.Buff.slot);

                        Inside.Add(s.Character.Information.UniqueID);
                    }
                    else if (distance >= Radius && s.Character.Action.Buff.InfiniteBuffs.ContainsKey(Name))
                    {
                        if (Inside.Contains(s.Character.Information.UniqueID))
                        {
                            s.SkillBuffEnd(s.Character.Action.Buff.InfiniteBuffs[Name]);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
        void walkcallback(object e)
        {
            try
            {
                if (this != null)
                {
                    if (RecordedTime <= 0)
                    {
                        Runing = false;
                        //if (Attacking) AttackHim();
                        StopMovement();
                        if (!Attacking)
                        {
                            StartRunTimer(Rnd.Next(1, 5) * 1000);
                        }
                    }
                    else
                    {
                        // only 40% left from the movement and attacking
                        if (RecordedTime <= WalkingTime * 0.50 && Attacking && AgressiveDMG != null)
                        {
                            PlayerMgr sys      = (PlayerMgr)GetTarget();
                            double    distance = Formule.gamedistance((float)x, (float)y, sys.Character.Position.x, sys.Character.Position.y);
                            if (distance > 3 && distance < 19)
                            {
                                StopMovement();
                                GotoPlayer(sys.Character, distance);
                            }
                        }

                        x            += wx * 0.1f;
                        y            += wy * 0.1f;
                        RecordedTime -= (WalkingTime * 0.1);
                    }
                    //CheckEveryOne();
                    if (SpawnWatch.ElapsedMilliseconds >= 1000)
                    {
                        //Console.Write("StopWatch şuan {0} ms", SpawnWatch.ElapsedMilliseconds);
                        CheckEveryOne();
                        SpawnWatch.Restart();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
        public void CalculateNewPosition()
        {
            //int FoundCount = FoundPosition();
            int CAngle = 0;

            /* if (FoundCount >= 0)
             * {*/
            int   AngleIndex = Rnd.Next(0, 360);
            float INC        = Rnd.Next(0, 3) * (float)Rnd.NextDouble(),
                  MinRadius  = 0.85f,
                  MaxRadius  = 8.85f;
            float  AddX      = (INC * ObjData.Manager.AngleCos[AngleIndex]);
            float  AddY      = (INC * ObjData.Manager.AngleSin[AngleIndex]);
            double distance  = Formule.gamedistance(x + AddX, y + AddY, x, y);

            if (distance >= MinRadius && distance <= MaxRadius)
            {
                x     += AddX;
                y     += AddY;
                CAngle = Convert.ToInt32(Math.Atan2(x, y) * 10430.38208);
                if (CAngle >= 32000)
                {
                    Log.Exception("Angle Hatası:" + CAngle);
                }
                else
                {
                    Angle = (short)CAngle;
                }
            }
            else
            {
                // Recalc
                CalculateNewPosition();
            }

            // CalculateNewPosition();

            /* }
             * else
             * {
             *   // İtem'in şimdiki pozisyonu iyi.
             *   // TODO:Bu algoritmanın geliştirilmesi gerekiyor.
             * }*/
        }
        public void CalcSharedPartyExpSp(int paramexp, party pt, PlayerMgr targetplayer, ref long outexp)
        {
            try
            {
                byte mlv = ObjData.Manager.ObjectBase[ID].Level;
                // party average
                int        k             = 0;
                List <int> NearbyMembers = new List <int>(9);
                if (pt.Members.Count != 0)
                {
                    double playerDist;
                    foreach (int memb in pt.Members)
                    {
                        PlayerMgr i = Helpers.GetInformation.GetPlayer(memb);
                        //playerDist = Formule.gamedistance(targetplayer.Character.Position.x, targetplayer.Character.Position.y, i.Character.Position.x, i.Character.Position.y);
                        playerDist = Formule.gamedistance(targetplayer.Character.Position, i.Character.Position);
                        if (playerDist >= 50)
                        {
                            NearbyMembers.Add(i.Character.Information.UniqueID);
                        }
                    }
                    foreach (int l in NearbyMembers)
                    {
                        k += Helpers.GetInformation.GetPlayer(l).Character.Information.Level;
                    }
                    k = (int)(k / pt.Members.Count);
                    //k = átlag.
                    foreach (int mem in NearbyMembers)
                    {
                        PlayerMgr ch   = Helpers.GetInformation.GetPlayer(mem);
                        int       ptsp = 97;
                        //This isn't the right formula. TODO: We must find the right one!
                        int ptexp = (int)((((paramexp / mlv) + (mlv - k)) * mlv) / k) * ch.Character.Information.Level;
                        ptexp *= Helpers.Settings.Rate.Experience;
                        byte kat = Kat;
                        if (kat == 20)
                        {
                            kat = 25;
                        }
                        ptexp *= kat; //we multiply the exp according to type of the mob.
                        //TODO: premium ticket
                        //gap:
                        ptexp -= (ptexp * (ch.Character.Information.Level) - Math.Abs(ch.Character.Information.Level - ch.MasteryGetBigLevel)) * 10 / 100;
                        if (ch.Character.Information.Level == 110 && ch.Character.Information.XP >= 4000000000)
                        {
                            ptexp = 0;
                        }
                        //we calculate the amount of sp:
                        if (Math.Abs(ObjData.Manager.ObjectBase[ID].Level - k) < 10)
                        {
                            int gap = Math.Abs(ch.Character.Information.Level - ch.MasteryGetBigLevel) * 10;
                            if (gap >= 90)
                            {
                                gap = 90;
                            }
                            ptsp  = (ptsp * (100 + gap)) / k; //Instead of 100 I share with the avareage of the party, so we get a proportionate number.
                            ptsp *= kat;
                            ptsp *= Helpers.Settings.Rate.SkillPoint;
                        }
                        //Send total to all in party (Set exp from formula)
                        SetPartyMemberExp(ch, (long)ptexp, ch.Character.Information.Attributes, (long)ptsp);
                        SetSp(ch, ptsp);
                        if (ch.Character.Network.Guild.Guildid != 0)
                        {
                            if (Math.Abs(ch.Character.Network.Guild.LastDonate - ch.Character.Network.Guild.DonateGP) >= 10)
                            {
                                DB.query("UPDATE guild_members SET guild_points='" + ch.Character.Network.Guild.DonateGP + "' WHERE guild_member_id='" + ch.Character.Information.CharacterID + "'");
                                ch.Character.Network.Guild.LastDonate = ch.Character.Network.Guild.DonateGP;

                                // set new amount to every guild members guild class
                                foreach (int m in ch.Character.Network.Guild.Members)
                                {
                                    int targetindex = ch.Character.Network.Guild.MembersInfo.FindIndex(i => i.MemberID == m);
                                    if (ch.Character.Network.Guild.MembersInfo[targetindex].Online)
                                    {
                                        PlayerMgr sys = Helpers.GetInformation.GetPlayer(m);

                                        // here comes the messy way
                                        ObjData.guild_player mygp = new ObjData.guild_player();
                                        int myindex = 0;
                                        foreach (ObjData.guild_player gp in sys.Character.Network.Guild.MembersInfo)
                                        {
                                            if (gp.MemberID == ch.Character.Information.CharacterID)
                                            {
                                                mygp          = gp;
                                                mygp.DonateGP = ch.Character.Network.Guild.DonateGP;
                                                break;
                                            }
                                            myindex++;
                                        }
                                        sys.Character.Network.Guild.MembersInfo[myindex] = mygp;
                                    }
                                }

                                ch.Character.Network.Guild.Send(Client.Packet.GuildUpdate(ch.Character, 9, 0, 0, 0));
                            }
                        }
                        outexp = ptexp;
                    }
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
        public void AutoRunCallBack(object e)
        {
            float  NewX = x, NewY = y;
            double Distance = 0.0;

            try
            {
                if (RecordedTime <= 0 && AutoMovement && !Die)
                {
                    double MaxDistance = 0.0;
                    if (RunningSpeed <= 0 && BerserkerSpeed <= 0)
                    {
                        StopMovement();
                        StopAutoRunTimer();
                        return;
                    }
                    if (UniqueGuardMode)
                    {
                        MaxDistance = 15;
                    }
                    else
                    {
                        MaxDistance = 100;
                    }
                    double OrjDistance = Formule.gamedistance((float)x, (float)y, (float)OriginalX, (float)OriginalY);

                    if (OrjDistance > MaxDistance)
                    {
                        wx   = OriginalX - x;
                        wy   = OriginalY - y;
                        xSec = (byte)((OriginalX / 192) + 135);
                        ySec = (byte)((OriginalY / 192) + 92);
                        if (LastState == 1 && LastState2 == 2)
                        {
                            ChangeState(1, 3);
                            Send(Packet.SetSpeed(UniqueID, WalkingSpeed, RunningSpeed));
                        }
                        Runing       = true;
                        WalkingTime  = (OrjDistance / (WalkingSpeed * 0.0768)) * 1000.0;
                        RecordedTime = WalkingTime;
                        StartMovement((int)(WalkingTime * 0.0768));
                        Send(Packet.Movement(new ObjData.vektor(UniqueID,
                                                                Formule.packetx((float)OriginalX, xSec),
                                                                (float)z,
                                                                Formule.packety((float)OriginalY, ySec),
                                                                xSec,
                                                                ySec)));
                    }
                    else
                    {
                        Helpers.Functions.aRound(ref NewX, ref NewY, 2);
                        wx       = NewX - x;
                        wy       = NewY - y;
                        xSec     = (byte)((NewX / 192) + 135);
                        ySec     = (byte)((NewY / 192) + 92);
                        Runing   = true;
                        Distance = Formule.gamedistance((float)x, (float)y, (float)NewX, (float)NewY);
                        if (Runing == true || WalkingSpeed != 0)
                        {
                            if (LastState == 1 && LastState2 == 3)
                            {
                                ChangeState(1, 2);
                                Send(Packet.SetSpeed(UniqueID, WalkingSpeed, RunningSpeed));
                            }
                            Runing       = false;
                            WalkingTime  = (Distance / (WalkingSpeed * 0.0768)) * 1000.0;
                            RecordedTime = WalkingTime;
                        }
                        else if (RunningSpeed != 0 && WalkingSpeed == 0)
                        {
                            if (LastState == 1 && LastState2 == 2)
                            {
                                ChangeState(1, 3);
                                Send(Packet.SetSpeed(UniqueID, WalkingSpeed, RunningSpeed));
                            }
                            Runing       = true;
                            WalkingTime  = (Distance / (RunningSpeed * 0.0768)) * 1000.0;
                            RecordedTime = WalkingTime;
                        }
                        if (!FileDB.CheckCave(xSec, ySec))
                        {
                            Send(Packet.Movement(new ObjData.vektor(UniqueID,
                                                                    Formule.packetx((float)NewX, xSec),
                                                                    (float)z,
                                                                    Formule.packety((float)NewY, ySec),
                                                                    xSec,
                                                                    ySec)));
                        }
                        else
                        {
                            Send(Packet.Movement(new ObjData.vektor(UniqueID,
                                                                    Formule.cavepacketx((float)NewX),
                                                                    (float)z,
                                                                    Formule.cavepackety((float)NewY),
                                                                    xSec,
                                                                    ySec)));
                        }
                        CheckEveryOne();
                        StartMovement((int)(WalkingTime * 0.0768));
                    }
                }
                else
                {
                    return;
                }
            }
            catch
            {
                StopMovement();
                StopAgressiveTimer();
            }
        }
Exemplo n.º 7
0
        public void AttackMain() // have to add this to thread pool
        {
            try
            {
                PlayerMgr sys;
                double    distance;

                if (AgressiveDMG != null)
                {
                    sys = (PlayerMgr)GetTarget();
                }
                else
                {
                    return;
                }
                //Print.Format("AttackMain()");
                if (bSleep)
                {
                    return;
                }

                if (sys == null || Die || GetDie)
                {
                    Attacking = false; return;
                }
                if (sys != null && !Spawned(sys.Character.Information.UniqueID))
                {
                    Attacking = false; return;
                }
                if (!sys.MonsterCheck(UniqueID))
                {
                    sys.Character.Action.MonsterID.Add(UniqueID);
                }
                if (!sys.Character.InGame)
                {
                    Attacking = false; return;
                }

                if (AutoMovement)
                {
                    StopAutoRunTimer();
                }
                else
                {
                    StopAgressiveTimer();
                }

                Busy      = true;
                Attacking = true;
                bool Hit = false;

                int AttackType     = 0;
                int AttackDistance = 0;
                int AttackTime     = 1000;

                int acount = UniqueID;

                //mob starts running
                ChangeState(1, 3);

                Stopwatch PursuitWatch = new Stopwatch();
                PursuitWatch.Start();

                // mob brain loop
                while (Attacking)
                {
                    if (sys == null || Die || GetDie)
                    {
                        AttackStop(); break;
                    }
                    if (sys != null && !Spawned(sys.Character.Information.UniqueID))
                    {
                        AttackStop(); break;
                    }
                    if (!sys.Character.InGame)
                    {
                        AttackStop(); break;
                    }

                    // make every new skill random
                    AttackType     = ObjData.Manager.ObjectBase[ID].Skill[Rnd.Next(0, ObjData.Manager.ObjectBase[ID].amountSkill)];
                    AttackDistance = ObjData.Manager.SkillBase[AttackType].Distance;
                    AttackTime     = ObjData.Manager.SkillBase[AttackType].Action_CastingTime;

                    distance = Formule.gamedistance((float)x, (float)y, sys.Character.Position.x, sys.Character.Position.y);

                    // mob's attack ranged
                    if (AttackDistance != 0)
                    {
                        distance -= AttackDistance;
                        if (distance < 0)
                        {
                            distance = 0;
                        }
                    }

                    #region Monster action switch
                    // stop pursuit coz player too far
                    if (distance > 19 /*&& Attack != null*/)
                    {
                        ChangeState(8, 1);
                        AttackStop();
                        break;
                    }
                    // player try to escape from mob's agro => go and pursuit the player
                    else if ((distance > 3 && distance < 19) && Runing == false /*&& PursuitWatch.ElapsedMilliseconds >= 500*/)
                    {
                        //restrict the loop to call this branch so frequent
                        //PursuitWatch.Restart();

                        Runing = true;
                        GotoPlayer(sys.Character, distance);
                    }
                    else if (distance <= 3 && Runing == false)
                    {
                        Hit = true;
                        AttackHim(AttackType);
                    }
                    #endregion

                    if (Hit) // wait for the attack animation
                    {
                        Thread.Sleep(AttackTime);
                        Hit = false;
                    }
                    else
                    {
                        int SleepTime = 300;
                        //magic

                        /*if (Walking)
                         * {
                         *  if (RecordedTime < SleepTime)
                         *  {
                         *      SleepTime = (int)RecordedTime-50;
                         *      if (RecordedTime < 50) SleepTime = 50;
                         *  }
                         * }*/
                        Thread.Sleep(SleepTime);
                    }
                }

                GC.Collect();
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }