GetObjectById() public static method

public static GetObjectById ( uint ItemId ) : Object_
ItemId uint
return System.Object_
Example #1
0
        public static void NormalAttack(int Index_)
        {
            uint SkillId      = 0;
            byte AttackAmount = GetAmountAndSkillIdByWeaponType(Index_, ref SkillId);

            bool AttackingPlayer = false;

            for (int i = 0; i <= Player.PlayersOnline; i++)
            {
                if (Player.Objects[Index_].AttackingObjectId == Player.General[i].UniqueID)
                {
                    AttackingPlayer = true;
                }
            }

            int ObjectIndex = Players.GetObjectIndexAndType(Index_, Player.Objects[Index_].AttackingObjectId);

            Silkroad.Skill_ tmpAttackSkill = Silkroad.GetSkillById(SkillId);

            uint BasicAttackPower = 0;

            if (tmpAttackSkill.Type == Silkroad.TypeTable.Phy)
            {
                BasicAttackPower = (uint)random.Next(Player.Stats[Index_].MinPhy, Player.Stats[Index_].MaxPhy);
            }
            else if (tmpAttackSkill.Type == Silkroad.TypeTable.Mag)
            {
                BasicAttackPower = (uint)random.Next(Player.Stats[Index_].MinMag, Player.Stats[Index_].MaxMag);
            }

            double SkillAttackPower  = 1; //cause its normal attack
            double SkillIncreaseRate = 0; // needs to be calculated from passive skills/active buffs

            double EnemyAbsorbation = 0;

            if (AttackingPlayer)
            {
                EnemyAbsorbation = Player.Stats[ObjectIndex].TotalAccessoriesAbsorption / (double)100;
            }

            double EnemyDefence = 0;

            if (AttackingPlayer)
            {
                if (tmpAttackSkill.Type == Silkroad.TypeTable.Phy)
                {
                    EnemyDefence = Player.Stats[ObjectIndex].PhyDef;
                }
                else if (tmpAttackSkill.Type == Silkroad.TypeTable.Mag)
                {
                    EnemyDefence = Player.Stats[ObjectIndex].MagDef;
                }
            }
            else
            {
                if (tmpAttackSkill.Type == Silkroad.TypeTable.Phy)
                {
                    EnemyDefence = Silkroad.GetObjectById(Monsters.General[ObjectIndex].ID).PhyDef;
                }
                else if (tmpAttackSkill.Type == Silkroad.TypeTable.Mag)
                {
                    EnemyDefence = Silkroad.GetObjectById(Monsters.General[ObjectIndex].ID).MagDef;
                }
            }

            double TotalDamageIncreaseRate = 0;//needs to be calculated from the players equipment

            double Damage = Formula.CalculateDmg(
                BasicAttackPower,
                SkillAttackPower,
                SkillIncreaseRate,
                EnemyAbsorbation,
                EnemyDefence,
                Player.Stats[Index_].Level,
                Player.Stats[Index_].Strength,
                Player.Stats[Index_].Intelligence,
                TotalDamageIncreaseRate,
                tmpAttackSkill.PwrPercent / (double)100);

            byte Critical = 0;

            Player.Objects[Index_].NormalAttack = true;

            if (Player.Objects[Index_].SelectedObjectType == 2)
            {
                Timers.MonsterMovement[ObjectIndex].Stop();
            }

            PacketWriter writer = new PacketWriter();

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ATTACK);
            writer.AppendByte(1);
            writer.AppendByte(2);
            writer.AppendDword(SkillId);
            writer.AppendDword(Player.General[Index_].UniqueID);
            writer.AppendDword((uint)(random.Next(1000, 10000) + Player.General[Index_].UniqueID));
            writer.AppendDword(Player.Objects[Index_].AttackingObjectId);
            writer.AppendByte(1);
            writer.AppendByte(AttackAmount);
            writer.AppendByte(1);
            writer.AppendDword(Player.Objects[Index_].AttackingObjectId);

            byte afterstate = 0;

            for (int i = 1; i <= AttackAmount; i++)
            {
                if (tmpAttackSkill.Type == Silkroad.TypeTable.Phy)
                {
                    if (random.Next(1, 10) >= 7)
                    {
                        Damage  *= 2;
                        Critical = 2;
                    }
                }
                if (Player.Objects[Index_].SelectedObjectType == 2)
                {
                    Monsters.General[ObjectIndex].HP -= (int)Damage;
                    if (Monsters.General[ObjectIndex].HP < 0)
                    {
                        afterstate = 0x80;
                        Monsters.General[ObjectIndex].HP = 0;
                    }
                }
                else if (Player.Objects[Index_].SelectedObjectType == 1)
                {
                    int tmpHp = (int)(Player.Stats[ObjectIndex].CHP - Damage);
                    if (tmpHp < 0)
                    {
                        afterstate = 0x80;
                        Player.Stats[ObjectIndex].CHP = 0;
                    }
                    else
                    {
                        Player.Stats[ObjectIndex].CHP -= (int)Damage;
                    }
                }

                writer.AppendByte(afterstate);
                writer.AppendByte(Critical);
                writer.AppendDword((uint)Damage);
                writer.AppendByte(0);
                writer.AppendWord(0);
            }

            ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

            Player.General[Index_].Busy          = true;
            Player.Objects[Index_].NormalAttack  = true;
            Timers.PlayerAttack[Index_].Interval = 1350.0;
            Timers.PlayerAttack[Index_].Start();


            if (afterstate == 0x80)
            {
                Player.Objects[Index_].AttackingObjectDeadID = Player.Objects[Index_].AttackingObjectId;

                Player.General[Index_].Busy = false;
                Timers.PlayerAttack[Index_].Stop();
                Player.Objects[Index_].NormalAttack = false;
                if (Player.Objects[Index_].SelectedObjectType == 1)
                {
                    Player.General[ObjectIndex].State        = 10;
                    Player.Objects[ObjectIndex].NormalAttack = false;
                    Player.General[ObjectIndex].Busy         = false;
                    Timers.PlayerAttack[ObjectIndex].Stop();

                    Character.Die(ObjectIndex);
                    Character.Die2(ObjectIndex);
                    Player.Flags[ObjectIndex].Dead = true;
                }
                if (Player.Objects[Index_].SelectedObjectType == 2)
                {
                    Stats.GetBerserk(Index_, ObjectIndex);
                    Stats.GetXP(Index_, ObjectIndex);

                    if (Monsters.General[ObjectIndex].Type == 3)
                    {
                        Unique.OnUnique((uint)Monsters.General[ObjectIndex].ID, true, Player.General[Index_].CharacterName);
                    }

                    Monsters.General[ObjectIndex].Dead = true;

                    Timers.MonsterAttack[ObjectIndex].Stop();
                    Timers.MonsterDeath[Index_].Interval = 3000.0;
                    Timers.MonsterDeath[Index_].Start();
                }
            }
            else
            {
                if (Player.Objects[Index_].SelectedObjectType == 2)
                {
                    if (!Timers.MonsterAttack[ObjectIndex].Enabled)
                    {
                        Monsters.General[ObjectIndex].AttackingObjectIndex = Index_;
                        Timers.MonsterAttack[ObjectIndex].Interval         = 2350;
                        Timers.MonsterAttack[ObjectIndex].Start();
                    }
                }
            }
        }
Example #2
0
        public static void OnSpawn(PacketReader reader_, int Index_)
        {
            int  MonsterIndex = Monsters.MonsterAmount;
            uint monsterid    = reader_.ReadDword();
            byte monstertype  = reader_.ReadByte();


            uint uniqueid = (uint)Monsters.MonsterAmount + 1000;

            if (monstertype == 1)
            {
                monstertype = 0;
            }

            Silkroad.Object_ tmpMonster = Silkroad.GetObjectById(monsterid);

            PacketWriter writer = new PacketWriter();

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);

            writer.AppendDword(monsterid);
            writer.AppendDword(uniqueid);

            writer.AppendByte(Player.Position[Index_].XSector);
            writer.AppendByte(Player.Position[Index_].YSector);
            writer.AppendFloat(Player.Position[Index_].X);
            writer.AppendFloat(Player.Position[Index_].Z);
            writer.AppendFloat(Player.Position[Index_].Y);

            writer.AppendWord(0);
            writer.AppendByte(0);
            writer.AppendByte(1);
            writer.AppendByte(0);
            writer.AppendWord(0);
            writer.AppendWord(1);
            writer.AppendByte(0);

            writer.AppendFloat(tmpMonster.Speed);
            writer.AppendFloat(tmpMonster.Speed);
            writer.AppendFloat(tmpMonster.Speed);

            writer.AppendByte(0);
            writer.AppendByte(0);

            writer.AppendByte(monstertype);
            writer.AppendByte(1);
            byte[] tmpBuffer = writer.getWorkspace();
            //   ServerSocket.SendPacketInRange(writer.getWorkspace(),Index_);


            int   monsterhp = (int)tmpMonster.Hp;
            ulong exp       = tmpMonster.Exp;

            switch (monstertype)
            {
            case 2:
                monsterhp *= 2;
                exp       *= 2;
                break;

            case 3:
                exp *= 7;
                break;

            case 4:
                monsterhp *= 20;
                exp       *= 3;
                break;

            case 6:
                monsterhp *= 4;
                exp       *= 4;
                break;

            case 16:
                monsterhp *= 10;
                exp       *= 5;
                break;

            case 17:
                monsterhp *= 20;
                exp       *= 6;

                break;

            case 20:
                monsterhp *= 200;
                exp       *= 8;
                break;
            }

            Monsters.General[MonsterIndex].ID       = monsterid;
            Monsters.General[MonsterIndex].UniqueID = uniqueid;
            Monsters.General[MonsterIndex].Type     = monstertype;
            Monsters.General[MonsterIndex].HP       = monsterhp;
            Monsters.Position[MonsterIndex].XSector = Player.Position[Index_].XSector;
            Monsters.Position[MonsterIndex].YSector = Player.Position[Index_].YSector;
            Monsters.Position[MonsterIndex].X       = Player.Position[Index_].X;
            Monsters.Position[MonsterIndex].Z       = Player.Position[Index_].Z;
            Monsters.Position[MonsterIndex].Y       = Player.Position[Index_].Y;
            Monsters.General[MonsterIndex].Exp      = exp;
            Monsters.General[MonsterIndex].Level    = tmpMonster.Level;
            Monsters.General[MonsterIndex].Skills   = new ArrayList();
            Monsters.General[MonsterIndex].Dead     = false;

            for (int i = 0; i < Player.PlayersOnline; i++)
            {
                if (Player.General[i].CharacterID != 0)
                {
                    if (Formula.CalculateDistance(Monsters.Position[MonsterIndex], Player.Position[i]) <= 800)
                    {
                        ServerSocket.Send(tmpBuffer, i);
                        Player.Objects[i].SpawnedMonsterIndex.Add(MonsterIndex);
                    }
                }
            }


            uint[] skill = new uint[9];
            skill[0] = tmpMonster.Skill1;
            skill[1] = tmpMonster.Skill2;
            skill[2] = tmpMonster.Skill3;
            skill[3] = tmpMonster.Skill4;
            skill[4] = tmpMonster.Skill5;
            skill[5] = tmpMonster.Skill6;
            skill[6] = tmpMonster.Skill7;
            skill[7] = tmpMonster.Skill8;
            skill[8] = tmpMonster.Skill9;

            for (int i = 0; i <= 8; i++)
            {
                if (skill[i] != 0 && skill[i] <= 3000)
                {
                    Monsters.General[MonsterIndex].Skills.Add(skill[i]);
                }
            }

            Monsters.MonsterAmount++;

            if (monstertype == 3)
            {
                Unique.OnUnique(monsterid, false, null);
            }


            Timers.MonsterMovement[MonsterIndex].Interval = 5000;
            Timers.MonsterMovement[MonsterIndex].Start();
        }