Example #1
0
    // ================================================================ //
    //
    //  하급 몬스터 관계 조작 명령 패킷 수신.
    //

    public void OnReceiveMonsterDataPacket(int node, PacketId id, byte[] data)
    {
        if (m_isHost)
        {
            // 호스트의 몬스터는 발생 완료.
            return;
        }

        MonsterPacket packet  = new MonsterPacket(data);
        MonsterData   monster = packet.GetPacket();

        //Debug.Log("[CLIENT] Receive monster data packet:" + monster.lairId + " - " + monster.monsterId);

        var lairs = enemies.FindAll(x => (x.behavior as chrBehaviorEnemy_Lair) != null);

        foreach (var lair in lairs)
        {
            if (lair.name == monster.lairId)
            {
                QuerySpawn query = new QuerySpawn(lair.name, monster.monsterId);

                query.set_done(true);
                query.set_success(true);

                QueryManager.get().registerQuery(query);
            }
        }
    }
Example #2
0
        /// <summary>
        /// [CMD_SYNC / SCMD_SYNC_MONSTER] Synchronizes a specific monster to a specific client.
        /// </summary>
        /// <param name="message">A <see cref="Msg"/> value.</param>
        private void Message_ResyncClient(Msg message)
        {
            ConnectedClient client  = this.clients[message.client_id];
            Monster         monster = this.monsters[message.data];

            if (client != null && monster != null)
            {
                MonsterPacket packet = new MonsterPacket();
                packet.MonsterInstance = monster;
                client.QueuePacket(packet);
            }
        }
Example #3
0
 public void FromPacket(MonsterPacket packet)
 {
     UID      = packet.MonsterUid;
     Name     = packet.MonsterName;
     Position = packet.Position;
     GetSpriteAsset().SpriteRowIndex = packet.SpriteIndex;
     MoveSpeed = packet.MoveSpeed;
     Atk       = packet.Atk;
     Def       = packet.Def;
     AtkSpeed  = packet.AtkSpeed;
     HP        = packet.HP;
     MAXHP     = packet.MAXHP;
 }
Example #4
0
    public void RequestSpawnEnemy(string lairName, string monsterName)
    {
        if (m_network != null)
        {
            MonsterData monster = new MonsterData();

            monster.lairId    = lairName;
            monster.monsterId = monsterName;

            MonsterPacket packet     = new MonsterPacket(monster);
            int           serverNode = m_network.GetServerNode();

            m_network.SendReliable <MonsterData>(serverNode, packet);
        }
    }
 /// <summary>
 /// Poll the socket for waiting data and parse.
 /// </summary>
 private void ReceiveMessages()
 {
     if (this.socket.Poll(POLL_TIMEOUT, SelectMode.SelectRead))
     {
         // Read waiting raw bytes.
         int received = this.socket.Receive(this.packetBuffer, BUFFER_SIZE, SocketFlags.None);
         if (received > 0)
         {
             int offset = 0;
             while (offset < received)
             {
                 // While we have data to read, attempt to parse the bytes into a packet.
                 IPacket packet;
                 int processed = Framing.ReadPacket(this.packetBuffer, received - offset, offset, out packet);
                 if (packet != null)
                 {
                     // Generic message packet (enqueue in our local message broker
                     if (packet.PacketHeader == Framing.HDR_PACKET)
                     {
                         Packet msgPacket = (Packet)packet;
                         Debug.Log(String.Format("[ServerConnection.ReceiveMessages] Got message packet containing {0} messages at timestamp {1:g}",
                             msgPacket.Count, DateTime.FromBinary(msgPacket.Timestamp)));
                         foreach (Msg msg in msgPacket)
                         {
                             // Sanity check in case server messages somehow get sent to client
                             if (msg.IsClient())
                             {
                                 MessageBroker.Instance.Enqueue(msg);
                             }
                         }
                     }
                     // Monster packet (tell the spawn manager to create/update new monster instance)
                     else if (packet.PacketHeader == Framing.HDR_MONSTER)
                     {
                         MonsterPacket monPacket = (MonsterPacket)packet;
                         Debug.Log(String.Format("[ServerConnection.ReceiveMessages] Got monster packet containing monster instance {0}", monPacket.MonsterInstance.ObjectID));
                         SpawnManager.Instance.QueueMonsterUpdate(monPacket.MonsterInstance);
                     }
                 }
                 offset += processed;
             }
         }
         else
         {
             Debug.LogWarning("[ServerConnection.ReceiveMessages] No data received. Connection lost?");
         }
     }
 }
Example #6
0
        public void OnMonsterSpawn(MonsterPacket packet)
        {
            MonsterFactory.BuildAndInstantiate(new MonsterFactoryOpts()
            {
                Position = packet.Position,
                Packet   = packet
            });

            if (packet.SpawnAnimation)
            {
                AnimationFactory.BuildAndInstantiate(new AnimationOpts()
                {
                    AnimationImageName = DefaultAssets.ANM_SMOKE,
                    MapPosition        = packet.Position
                });
            }
        }
Example #7
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 #8
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 #9
0
        public static void WarpToMap_Req(InPacket lea, Client gc)
        {
            int   CharacterID = lea.ReadInt();
            short MapX        = lea.ReadShort();
            short MapY        = lea.ReadShort();
            short PositionX   = lea.ReadShort();
            short PositionY   = lea.ReadShort();
            var   chr         = gc.Character;

            chr.MapX    = MapX;
            chr.MapY    = MapY;
            chr.PlayerX = PositionX;
            chr.PlayerY = PositionY;

            if (MapX == 77 && MapY == 1)
            {
                CashShopPacket.CashShopList1(gc); // 人物
                CashShopPacket.CashShopList2(gc); // 裝備
                CashShopPacket.CashShopList3(gc); // 能力
                CashShopPacket.CashShopList4(gc); // 靈物
                CashShopPacket.CashShopList5(gc); // 寶牌
                CashShopPacket.CashShopList6(gc);
                CashShopPacket.CashShopList7(gc); // 紅利積點
                CashShopPacket.CashShopList8(gc);
                CashShopPacket.CashShopList9(gc);
                CashShopPacket.MgameCash(gc);
                CashShopPacket.GuiHonCash(gc);

                // 接收禮物
                List <int> Gifts = new List <int>();

                foreach (dynamic datum in new Datums("Gifts").Populate())
                {
                    if (chr.Name.Equals(datum.name) && datum.receive == 0)
                    {
                        Gifts.Add(datum.itemID);
                        datum.receive = 1;
                        datum.Update("id = '{0}'", datum.id);
                    }
                }
                foreach (int ItemID in Gifts)
                {
                    chr.Items.Add(new Item(ItemID, true, 0, -1, (byte)InventoryType.ItemType.Cash, chr.Items.GetNextFreeSlot(InventoryType.ItemType.Cash)));
                    chr.Items.Save();
                }
                InventoryPacket.getInvenCash(gc);
                MapPacket.warpToMap(gc, chr, CharacterID, MapX, MapY, PositionX, PositionY);
                return;
            }

            Map Map = MapFactory.GetMap(MapX, MapY);

            MapPacket.warpToMap(gc, chr, CharacterID, MapX, MapY, PositionX, PositionY);

            if (Map.GetMapCharactersTotal() > 0)
            {
                foreach (Character All in Map.Characters)
                {
                    MapPacket.warpToMap(All.Client, chr, CharacterID, MapX, MapY, PositionX, PositionY);
                }

                MapPacket.createUser(gc, Map);
            }

            Map.Characters.Add(chr);

            //if ((MapX == 1 && MapY == 53) || (MapX == 1 && MapY == 54) || (MapX == 1 && MapY == 55))
            //    return;

            //if ((MapX == 10 && MapY == 63) || (MapX == 10 && MapY == 64))
            //{
            //    Monster Monster = new Monster(0, 1020001, 200, 10000, 10000, 0, 0, 1, 0xFF, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1408, 659, true);
            //    Map.Monster.Add(Monster);
            //}

            MonsterPacket.createAllMonster(gc, Map, Map.Monster);

            int j = 0;

            for (int i = 0; i < 50; i++)
            {
                if (Map.Monster[i] != null)
                {
                    j++;
                }
            }

            //for (int i = 0; i < j; i++)
            //{
            //    foreach (Character All in map.Characters)
            //    {
            //        if (map.Monster[i].IsAlive == true)
            //            MonsterPacket.spawnMonster(All.Client, map.Monster[i], 0, 0, 0, 0);
            //    }
            //}

            //if (map.GetMapCharactersTotal() < 1)
            //{
            Map.ControlMonster(gc, j);
            //}

            //if (chr.IsFuring == true)
            //{
            //    foreach (Character All in Map.Characters)
            //    {
            //        StatusPacket.Fury(All.Client, chr, chr.FuringType);
            //    }
            //}
        }
Example #10
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();
            }
        }
Example #11
0
	// ================================================================ //
	//
	//  하급 몬스터 관계 조작 명령 패킷 수신.
	//

	public void OnReceiveMonsterDataPacket(int node, PacketId id, byte[] data)
	{
		if (m_isHost) {
			// 호스트의 몬스터는 발생 완료.
			return;
		}

		MonsterPacket packet = new MonsterPacket(data);
		MonsterData monster = packet.GetPacket();

		//Debug.Log("[CLIENT] Receive monster data packet:" + monster.lairId + " - " + monster.monsterId);

		var	lairs = enemies.FindAll(x => (x.behavior as chrBehaviorEnemy_Lair) != null);
		
		foreach(var lair in lairs) {

			if (lair.name == monster.lairId) {

				QuerySpawn query = new QuerySpawn(lair.name, monster.monsterId);

				query.set_done(true);
				query.set_success(true);

				QueryManager.get().registerQuery(query);
			
			}
		}

	}
Example #12
0
	public void RequestSpawnEnemy(string lairName, string monsterName)
	{
		if(m_network != null) {

			MonsterData monster = new MonsterData ();
	
			monster.lairId = lairName;
			monster.monsterId = monsterName;
	
			MonsterPacket packet = new MonsterPacket(monster);
			int serverNode = m_network.GetServerNode();
	
			m_network.SendReliable<MonsterData>(serverNode, packet);
		}
	}