Example #1
0
        public void ControlMonster(Client gc, int j)
        {
            if (this.IsControling == true)
            {
                return;
            }

            var chr = gc.Character;

            this.IsControling = true;

            Delay tmr = null;

            tmr = new Delay(1000, true, () =>
            {
                if (this.GetMapCharactersTotal() < 1)
                {
                    tmr.Cancel();
                    this.IsControling = false;
                    return;
                }

                for (int i = 0; i < j; i++)
                {
                    if (this.Monster[i].State == 3 || this.Monster[i].State == 7 || this.Monster[i].State == 9 ||
                        this.Monster[i].MoveType == 3)
                    {
                        continue;
                    }

                    int Direction = this.Monster[i].Direction;

                    Monster Monster = UpdatePosition(this.Monster[i], (int)(40 * this.Monster[i].Speed));

                    foreach (Character All in this.Characters)
                    {
                        if (this.Monster[i].State != 9 && Direction != Monster.Direction && All.MapX == this.MapX &&
                            All.MapY == this.MapY)
                        {
                            MonsterPacket.spawnMonster(All.Client, this.Monster[i], 0, 0, 0, 0);
                        }
                    }
                }
            });
            tmr.Execute();

            Delay tmr2 = null;

            tmr2 = new Delay(20000, true, () =>
            {
                if (this.GetMapCharactersTotal() < 1)
                {
                    tmr2.Cancel();
                    this.IsControling = false;
                    return;
                }

                for (int i = 0; i < j; i++)
                {
                    if (this.Monster[i].IsAlive == false)
                    {
                        this.Monster[i].HP      = MobFactory.MonsterMaxHP(this.Monster[i].Level);
                        this.Monster[i].IsAlive = true;
                        this.Monster[i].State   = (this.Monster[i].MoveType == 0 ? (byte)0 : (byte)1);
                        foreach (Character All in this.Characters)
                        {
                            if (All.MapX == this.MapX && All.MapY == this.MapY)
                            {
                                MonsterPacket.regenrMonster(All.Client, this.Monster[i]);
                                MonsterPacket.spawnMonster(All.Client, this.Monster[i], 0, 0, 0, 0);
                            }
                        }
                    }
                }
            });
            tmr2.Execute();
        }
Example #2
0
        public static void AttackMonster_Req(InPacket lea, Client gc)
        {
            short CharacterID = lea.ReadShort();
            short OriginalID  = lea.ReadShort();

            lea.ReadShort();
            short   Damage  = lea.ReadShort();
            short   HitX    = lea.ReadShort();
            short   HitY    = lea.ReadShort();
            short   SkillID = lea.ReadShort();
            var     chr     = gc.Character;
            Map     Map     = MapFactory.GetMap(chr.MapX, chr.MapY);
            Monster Monster = Map.getMonsterByOriginalID(OriginalID);

            if (Monster == null)
            {
                return;
            }
            Monster.HP -= Damage;
            switch (SkillID)
            {
            case 10108:     // 點穴定身
                if (Randomizer.Next(0, 2) == 0)
                {
                    Monster.Effect = 1;
                }
                break;

            case 10204:     // 餵毒術
                if (Randomizer.Next(0, 2) == 0)
                {
                    Monster.Effect = 2;
                }
                break;

            case 10304:     // 玄冰擊
            case 10305:     // 冰凍大地
                if (Randomizer.Next(0, 2) == 0)
                {
                    Monster.Effect = 5;
                }
                break;

            case 10306:     // 矇蔽蝕眼
                if (Randomizer.Next(0, 2) == 0)
                {
                    Monster.Effect = 3;
                }
                break;

            default:
                //Log.Inform("[Attack Monster] SkillID = {0}", SkillID);
                break;
            }
            if (Monster.HP <= 0)
            {
                //if (Monster.IsAlive == false)
                //    return;
                Monster.State  = 9;
                Monster.Effect = 0;
                //map.Monster.Remove(Monster);
                Monster.IsAlive = false;
                chr.Exp        += Monster.Exp;
                if (chr.Exp >= GameConstants.getExpNeededForLevel(chr.Level))
                {
                    chr.LevelUp();
                }
                StatusPacket.UpdateExp(gc);

                // 加入要掉落物品
                int Max_Count     = 2; // 設定最大物品掉落數
                int Current_Count = 0;
                foreach (Loot loot in MobFactory.Drop_Data)
                {
                    if (Current_Count == Max_Count)
                    {
                        break;
                    }

                    if (loot.MobID == Monster.MonsterID)
                    {
                        if ((Randomizer.Next(999999) / GameServer.Rates.Loot) < loot.Chance)
                        {
                            Monster.Drops.Add(new Drop(0, loot.ItemID, (short)Randomizer.Next(loot.MinimumQuantity, loot.MaximumQuantity)));
                            Current_Count++;
                        }
                    }
                }

                // 加入要掉落靈魂
                //【藍色鬼魂】能恢復20%的鬼力值
                //【綠色鬼魂】能恢復40%的鬼力值
                //【紅色鬼魂】累積憤怒計量值用,當憤怒計滿之後能轉為憤怒狀態,攻防都會*1.2倍
                //【紫色鬼魂】能吸收到封印裝備,蒐集越多越能增加封印物合成的成功機率

                // 無 : 1%
                // 9900001 : 20%
                // 9900002 : 19%
                // 9900003 : 20%
                // 9900004 : 40%

                int[] Soul =
                {
                    0,
                    9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001,                                                                                                                                                                                    // 20%
                    9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002,                                                                                                                                                                                             // 19%
                    9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003,                                                                                                                                                                                    // 20%
                    9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004 // 40%
                };

                int rnd = Randomizer.Next(0, 100);
                if (rnd != 0)
                {
                    Monster.Drops.Add(new Drop(0, Soul[rnd], 20));
                }

                //int Max_Soul_Count = 1; // 設定最大物品掉落數
                //int Current_Soul_Count = 0;
                //int[] Soul = new int[] { 15000, 250000, 800000, 650000 };
                //for (int i = 1; i < 5; i++)
                //{
                //    if (Max_Soul_Count == Current_Soul_Count)
                //        break;

                //    if ((Randomizer.Next(999999) / GameServer.Rates.Loot) < Soul[i-1])
                //    {
                //        Monster.Drops.Add(new Drop(0, 9900001 + (i -1), 20));
                //        Current_Soul_Count++;
                //    }
                //}

                short rndMoney = (short)(Monster.Exp + Randomizer.Next(6));

                if (rndMoney != 0 && Monster.MonsterID != 1010002)                                   // rndMoney != 0 (少數怪物未寫入經驗值)
                {
                    Monster.Drops.Add(new Drop(0, InventoryType.getMoneyStyle(rndMoney), rndMoney)); // 錢
                }
                for (int i = 0; i < Monster.Drops.Count; i++)
                {
                    Monster.Drops[i].PositionX = Monster.PositionX;
                    Monster.Drops[i].PositionY = Monster.PositionY - 50;
                    //Item it = new Item(Monster.Drops[i].ItemID, 0x63, 0x63, Monster.Drops[i].Quantity);
                    Monster.Drops[i].ID = Map.ObjectID;
                    Map.Item.Add(Map.ObjectID, new Drop(Map.ObjectID, Monster.Drops[i].ItemID, Monster.Drops[i].Quantity));
                    Map.ObjectID++;
                }
                foreach (Character All in Map.Characters)
                {
                    MapPacket.MonsterDrop(All.Client, Monster);
                }
                Monster.Drops.Clear();
            }
            else
            {
                Monster.State = 7;
                if (chr.PlayerX < HitX && Monster.Direction == 1)
                {
                    Monster.Direction = 0xFF;
                }
                else if (chr.PlayerX > HitX && Monster.Direction == 0xFF)
                {
                    Monster.Direction = 1;
                }
            }

            foreach (Character All in Map.Characters)
            {
                MonsterPacket.spawnMonster(All.Client, Monster, CharacterID, Damage, HitX, HitY);
            }

            if (Monster.State == 9 && Monster.tmr1 != null)
            {
                Monster.tmr1.Cancel();
                Monster.tmr1 = null;
                return;
            }

            if (Monster.State == 9 && Monster.tmr2 != null)
            {
                Monster.tmr2.Cancel();
                Monster.tmr2 = null;
                return;
            }

            if (Monster.State == 9 && Monster.tmr3 != null)
            {
                Monster.tmr3.Cancel();
                Monster.tmr3 = null;
                return;
            }

            int r = Randomizer.Next(0, 2);

            if (r == 0 && Monster.Effect == 0 && Monster.State == 7 && Monster.AttackType != 0 && Monster.tmr1 == null)
            {
                Monster.tmr1 = new Delay(600, false, () =>
                {
                    if (Monster.State == 9)
                    {
                        Monster.tmr1.Cancel();
                        Monster.tmr2.Cancel();
                        Monster.tmr3.Cancel();
                        Monster.tmr1 = null;
                        Monster.tmr2 = null;
                        Monster.tmr3 = null;
                        return;
                    }
                    Monster.State = 3;
                    foreach (Character All in Map.Characters)
                    {
                        MonsterPacket.spawnMonster(All.Client, Monster, CharacterID, 0, HitX, HitY);
                    }
                    Monster.tmr1 = null;

                    if (Monster.State == 3 && Monster.tmr2 == null)
                    {
                        Monster.tmr2 = new Delay(500, false, () =>
                        {
                            if (Monster.State == 9)
                            {
                                Monster.tmr1.Cancel();
                                Monster.tmr2.Cancel();
                                Monster.tmr3.Cancel();
                                Monster.tmr1 = null;
                                Monster.tmr2 = null;
                                Monster.tmr3 = null;
                                return;
                            }
                            Monster.State = (Monster.MoveType == 0 ? (byte)0 : (byte)1);
                            foreach (Character All in Map.Characters)
                            {
                                MonsterPacket.spawnMonster(All.Client, Monster, 0, 0, 0, 0);
                            }
                            Monster.tmr2 = null;
                        });
                        Monster.tmr2.Execute();
                    }
                });
                Monster.tmr1.Execute();
            }

            if ((r == 1 && Monster.Effect == 0 && Monster.State != 9) || (Monster.State != 9 && Monster.Effect == 0 && Monster.AttackType == 0))
            {
                Monster.tmr2 = new Delay(500, false, () =>
                {
                    Monster.State = (Monster.MoveType == 0 ? (byte)0 : (byte)1);
                    foreach (Character All in Map.Characters)
                    {
                        MonsterPacket.spawnMonster(All.Client, Monster, 0, 0, 0, 0);
                    }
                    Monster.tmr2 = null;
                });
                Monster.tmr2.Execute();
            }

            if (Monster.Effect != 0)
            {
                Monster.tmr3 = new Delay(6000, false, () =>
                {
                    Monster.Effect = 0;
                    Monster.State  = (Monster.MoveType == 0 ? (byte)0 : (byte)1);
                    foreach (Character All in Map.Characters)
                    {
                        MonsterPacket.spawnMonster(All.Client, Monster, 0, 0, 0, 0);
                    }
                    Monster.tmr3 = null;
                });
                Monster.tmr3.Execute();
            }
        }
Example #3
0
        public static void AttackMonster_Req(InPacket lea, Client gc)
        {
            short CharacterID = lea.ReadShort();
            short OriginalID  = lea.ReadShort();

            lea.ReadShort();
            short   Damage  = lea.ReadShort();
            short   HitX    = lea.ReadShort();
            short   HitY    = lea.ReadShort();
            short   SkillID = lea.ReadShort();
            var     chr     = gc.Character;
            Map     Map     = MapFactory.GetMap(chr.MapX, chr.MapY);
            Monster Monster = Map.getMonsterByOriginalID(OriginalID);

            if (Monster == null)
            {
                return;
            }
            Monster.HP -= Damage;
            switch (SkillID)
            {
            case 10108:                     // 點穴定身
                if (Randomizer.Next(0, 2) == 0)
                {
                    Monster.Effect = 1;
                }
                break;

            case 10204:                     // 餵毒術
                if (Randomizer.Next(0, 2) == 0)
                {
                    Monster.Effect = 2;
                }
                break;

            case 10304:                     // 玄冰擊
            case 10305:                     // 冰凍大地
                if (Randomizer.Next(0, 2) == 0)
                {
                    Monster.Effect = 5;
                }
                break;

            case 10306:                     // 矇蔽蝕眼
                if (Randomizer.Next(0, 2) == 0)
                {
                    Monster.Effect = 3;
                }
                break;

            default:
                //Log.Inform("[Attack Monster] SkillID = {0}", SkillID);
                break;
            }

            if (Monster.HP <= 0)
            {
                //if (Monster.IsAlive == false)
                //    return;
                Monster.State  = 9;
                Monster.Effect = 0;
                //map.Monster.Remove(Monster);
                Monster.IsAlive = false;
                chr.Exp        += Monster.Exp;
                if (chr.Exp >= GameConstants.getExpNeededForLevel(chr.Level))
                {
                    chr.LevelUp();
                }
                StatusPacket.UpdateExp(gc);

                // 加入要掉落物品
                int Max_Count     = 2;             // 設定最大物品掉落數
                int Current_Count = 0;
                foreach (Loot loot in MobFactory.Drop_Data)
                {
                    if (Current_Count == Max_Count)
                    {
                        break;
                    }

                    if (loot.MobID == Monster.MonsterID)
                    {
                        if ((Randomizer.Next(999999) / GameServer.Rates.Loot) < loot.Chance)
                        {
                            Monster.Drops.Add(new Drop(0, loot.ItemID,
                                                       (short)Randomizer.Next(loot.MinimumQuantity, loot.MaximumQuantity)));
                            Current_Count++;
                        }
                    }
                }

                // join to drop soul
                // [Blue Ghost] can restore 20% of ghost power
                // [Green Ghost] Can restore 40% of Ghost Power
                // [Red Ghost] It is used to accumulate the measurement value of anger. When the anger is full, it can be turned into an anger state. The offense and defense will be 1.2
                // [Purple Ghost] can absorb the seal equipment, the more you collect the more you can increase the success rate of the seal synthesis

                // None: 1%
                // 9900001: 20%
                // 9900002: 19%
                // 9900003: 20%
                // 9900004: 40%

                int[] Soul =
                {
                    0,
                    9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001,
                    9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, 9900001, // 20%
                    9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002,
                    9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002, 9900002,          // 19%
                    9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003,
                    9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, 9900003, // 20%
                    9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004,
                    9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004,
                    9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004,
                    9900004, 9900004, 9900004, 9900004, 9900004, 9900004, 9900004                     // 40%
                };

                int rnd = Randomizer.Next(0, 100);
                if (rnd != 0)
                {
                    Monster.Drops.Add(new Drop(0, Soul[rnd], 20));
                }

                //int Max_Soul_Count = 1; // 設定最大物品掉落數
                //int Current_Soul_Count = 0;
                //int[] Soul = new int[] { 15000, 250000, 800000, 650000 };
                //for (int i = 1; i < 5; i++)
                //{
                //    if (Max_Soul_Count == Current_Soul_Count)
                //        break;

                //    if ((Randomizer.Next(999999) / GameServer.Rates.Loot) < Soul[i-1])
                //    {
                //        Monster.Drops.Add(new Drop(0, 9900001 + (i -1), 20));
                //        Current_Soul_Count++;
                //    }
                //}

                short rndMoney = (short)(Monster.Exp + Randomizer.Next(6));

                if (rndMoney != 0 && Monster.MonsterID != 1010002)                                   // rndMoney != 0 (少數怪物未寫入經驗值)
                {
                    Monster.Drops.Add(new Drop(0, InventoryType.getMoneyStyle(rndMoney), rndMoney)); // 錢
                }
                for (int i = 0; i < Monster.Drops.Count; i++)
                {
                    Monster.Drops[i].PositionX = Monster.PositionX;
                    Monster.Drops[i].PositionY = Monster.PositionY - 50;
                    //Item it = new Item(Monster.Drops[i].ItemID, 0x63, 0x63, Monster.Drops[i].Quantity);
                    Monster.Drops[i].ID = Map.ObjectID;
                    Map.Item.Add(Map.ObjectID,
                                 new Drop(Map.ObjectID, Monster.Drops[i].ItemID, Monster.Drops[i].Quantity));
                    Map.ObjectID++;
                }

                foreach (Character All in Map.Characters)
                {
                    MapPacket.MonsterDrop(All.Client, Monster);
                }

                Monster.Drops.Clear();
            }
            else
            {
                Monster.State = 7;
                if (chr.PlayerX < HitX && Monster.Direction == 1)
                {
                    Monster.Direction = 0xFF;
                }
                else if (chr.PlayerX > HitX && Monster.Direction == 0xFF)
                {
                    Monster.Direction = 1;
                }
            }

            foreach (Character All in Map.Characters)
            {
                MonsterPacket.spawnMonster(All.Client, Monster, CharacterID, Damage, HitX, HitY);
            }

            if (Monster.State == 9 && Monster.tmr1 != null)
            {
                Monster.tmr1.Cancel();
                Monster.tmr1 = null;
                return;
            }

            if (Monster.State == 9 && Monster.tmr2 != null)
            {
                Monster.tmr2.Cancel();
                Monster.tmr2 = null;
                return;
            }

            if (Monster.State == 9 && Monster.tmr3 != null)
            {
                Monster.tmr3.Cancel();
                Monster.tmr3 = null;
                return;
            }

            int r = Randomizer.Next(0, 2);

            if (r == 0 && Monster.Effect == 0 && Monster.State == 7 && Monster.AttackType != 0 && Monster.tmr1 == null)
            {
                Monster.tmr1 = new Delay(600, false, () =>
                {
                    if (Monster.State == 9)
                    {
                        Monster.tmr1.Cancel();
                        Monster.tmr2.Cancel();
                        Monster.tmr3.Cancel();
                        Monster.tmr1 = null;
                        Monster.tmr2 = null;
                        Monster.tmr3 = null;
                        return;
                    }

                    Monster.State = 3;
                    foreach (Character All in Map.Characters)
                    {
                        MonsterPacket.spawnMonster(All.Client, Monster, CharacterID, 0, HitX, HitY);
                    }
                    Monster.tmr1 = null;

                    if (Monster.State == 3 && Monster.tmr2 == null)
                    {
                        Monster.tmr2 = new Delay(500, false, () =>
                        {
                            if (Monster.State == 9)
                            {
                                Monster.tmr1.Cancel();
                                Monster.tmr2.Cancel();
                                Monster.tmr3.Cancel();
                                Monster.tmr1 = null;
                                Monster.tmr2 = null;
                                Monster.tmr3 = null;
                                return;
                            }

                            Monster.State = (Monster.MoveType == 0 ? (byte)0 : (byte)1);
                            foreach (Character All in Map.Characters)
                            {
                                MonsterPacket.spawnMonster(All.Client, Monster, 0, 0, 0, 0);
                            }
                            Monster.tmr2 = null;
                        });
                        Monster.tmr2.Execute();
                    }
                });
                Monster.tmr1.Execute();
            }

            if ((r == 1 && Monster.Effect == 0 && Monster.State != 9) ||
                (Monster.State != 9 && Monster.Effect == 0 && Monster.AttackType == 0))
            {
                Monster.tmr2 = new Delay(500, false, () =>
                {
                    Monster.State = (Monster.MoveType == 0 ? (byte)0 : (byte)1);
                    foreach (Character All in Map.Characters)
                    {
                        MonsterPacket.spawnMonster(All.Client, Monster, 0, 0, 0, 0);
                    }
                    Monster.tmr2 = null;
                });
                Monster.tmr2.Execute();
            }

            if (Monster.Effect != 0)
            {
                Monster.tmr3 = new Delay(6000, false, () =>
                {
                    Monster.Effect = 0;
                    Monster.State  = (Monster.MoveType == 0 ? (byte)0 : (byte)1);
                    foreach (Character All in Map.Characters)
                    {
                        MonsterPacket.spawnMonster(All.Client, Monster, 0, 0, 0, 0);
                    }
                    Monster.tmr3 = null;
                });
                Monster.tmr3.Execute();
            }
        }