コード例 #1
0
        public Cell GetMovement(MapObject ob)
        {
            if (Movements == null || Movements.Count == 0)
            {
                return(this);
            }

            for (int i = 0; i < 5; i++) //20 Attempts to get movement;
            {
                MovementInfo movement = Movements[SEnvir.Random.Next(Movements.Count)];

                Map map = SEnvir.GetMap(movement.DestinationRegion.Map);


                Cell cell = map.GetCell(movement.DestinationRegion.PointList[SEnvir.Random.Next(movement.DestinationRegion.PointList.Count)]);

                if (cell == null)
                {
                    continue;
                }

                if (ob.Race == ObjectType.Player)
                {
                    PlayerObject player = (PlayerObject)ob;

                    if (movement.DestinationRegion.Map.MinimumLevel > ob.Level && !player.Character.Account.TempAdmin)
                    {
                        player.Connection.ReceiveChat(string.Format(player.Connection.Language.NeedLevel, movement.DestinationRegion.Map.MinimumLevel), MessageType.System);

                        foreach (SConnection con in player.Connection.Observers)
                        {
                            con.ReceiveChat(string.Format(con.Language.NeedLevel, movement.DestinationRegion.Map.MinimumLevel), MessageType.System);
                        }

                        break;
                    }
                    if (movement.DestinationRegion.Map.MaximumLevel > 0 && movement.DestinationRegion.Map.MaximumLevel < ob.Level && !player.Character.Account.TempAdmin)
                    {
                        player.Connection.ReceiveChat(string.Format(player.Connection.Language.NeedMaxLevel, movement.DestinationRegion.Map.MaximumLevel), MessageType.System);

                        foreach (SConnection con in player.Connection.Observers)
                        {
                            con.ReceiveChat(string.Format(con.Language.NeedMaxLevel, movement.DestinationRegion.Map.MaximumLevel), MessageType.System);
                        }

                        break;
                    }

                    if (movement.NeedSpawn != null)
                    {
                        SpawnInfo spawn = SEnvir.Spawns.FirstOrDefault(x => x.Info == movement.NeedSpawn);

                        if (spawn == null)
                        {
                            break;
                        }

                        if (spawn.AliveCount == 0)
                        {
                            player.Connection.ReceiveChat(player.Connection.Language.NeedMonster, MessageType.System);

                            foreach (SConnection con in player.Connection.Observers)
                            {
                                con.ReceiveChat(con.Language.NeedMonster, MessageType.System);
                            }

                            break;
                        }
                    }

                    if (movement.NeedItem != null)
                    {
                        if (player.GetItemCount(movement.NeedItem) == 0)
                        {
                            player.Connection.ReceiveChat(string.Format(player.Connection.Language.NeedItem, movement.NeedItem.ItemName), MessageType.System);

                            foreach (SConnection con in player.Connection.Observers)
                            {
                                con.ReceiveChat(string.Format(con.Language.NeedItem, movement.NeedItem.ItemName), MessageType.System);
                            }
                            break;
                        }

                        player.TakeItem(movement.NeedItem, 1);
                    }

                    switch (movement.Effect)
                    {
                    case MovementEffect.SpecialRepair:
                        player.SpecialRepair(EquipmentSlot.Weapon);
                        player.SpecialRepair(EquipmentSlot.Shield);
                        player.SpecialRepair(EquipmentSlot.Helmet);
                        player.SpecialRepair(EquipmentSlot.Armour);
                        player.SpecialRepair(EquipmentSlot.Necklace);
                        player.SpecialRepair(EquipmentSlot.BraceletL);
                        player.SpecialRepair(EquipmentSlot.BraceletR);
                        player.SpecialRepair(EquipmentSlot.RingL);
                        player.SpecialRepair(EquipmentSlot.RingR);
                        player.SpecialRepair(EquipmentSlot.Shoes);
                        player.SpecialRepair(EquipmentSlot.Belt);

                        player.RefreshStats();
                        break;
                    }
                }

                return(cell.GetMovement(ob));
            }

            return(this);
        }