예제 #1
0
        internal Point GetRandomWalkableSquare()
        {
            var walkableSquares = new List <Point>();

            for (var y = 0; y < GameMap.GetUpperBound(1); y++)
            {
                for (var x = 0; x < GameMap.GetUpperBound(0); x++)
                {
                    if (StaticModel.DoorX != x && StaticModel.DoorY != y && GameMap[x, y] == 1)
                    {
                        walkableSquares.Add(new Point(x, y));
                    }
                }
            }

            var randomNumber = PlusEnvironment.GetRandomNumber(0, walkableSquares.Count);
            var i            = 0;

            foreach (var coord in walkableSquares.ToList())
            {
                if (i == randomNumber)
                {
                    return(coord);
                }

                i++;
            }

            return(new Point(0, 0));
        }
예제 #2
0
        public Point GetRandomWalkableSquare()
        {
            var walkableSquares = new List <Point>();

            for (int y = 0; y < _gameMap.GetUpperBound(1); y++)
            {
                for (int x = 0; x < _gameMap.GetUpperBound(0); x++)
                {
                    if (_model.DoorX != x && _model.DoorY != y && _gameMap[x, y] == 1)
                    {
                        walkableSquares.Add(new Point(x, y));
                    }
                }
            }

            int RandomNumber = PlusEnvironment.GetRandomNumber(0, walkableSquares.Count);
            int i            = 0;

            foreach (Point coord in walkableSquares.ToList())
            {
                if (i == RandomNumber)
                {
                    return(coord);
                }
                i++;
            }

            return(new Point(0, 0));
        }
예제 #3
0
        public void PetEnergy(bool Add)
        {
            int MaxE;

            if (Add)
            {
                if (Energy == 100) // If Energy is 100, no point.
                {
                    return;
                }

                if (Energy > 85)
                {
                    MaxE = MaxEnergy - Energy;
                }
                else
                {
                    MaxE = 10;
                }
            }
            else
            {
                MaxE = 15; // Remove Max Energy as 15
            }
            if (MaxE <= 4)
            {
                MaxE = 15;
            }

            int r = PlusEnvironment.GetRandomNumber(4, MaxE);

            if (!Add)
            {
                Energy = Energy - r;

                if (Energy < 0)
                {
                    Energy = 1;
                    r      = 1;
                }
            }
            else
            {
                Energy = Energy + r;
            }


            if (DBState != DatabaseUpdateState.NeedsInsert)
            {
                DBState = DatabaseUpdateState.NeedsUpdate;
            }
        }
예제 #4
0
 public Item GetRandomExitTile()
 {
     return(ExitTeleports.Values.ToList()[PlusEnvironment.GetRandomNumber(0, ExitTeleports.Count - 1)]);
 }
예제 #5
0
파일: PetBot.cs 프로젝트: res7702/PlusEMU
        public override void OnTimerTick()
        {
            RoomUser Pet = GetRoomUser();

            if (Pet == null)
            {
                return;
            }


            #region Speech

            if (SpeechTimer <= 0)
            {
                if (Pet.PetData.DBState != PetDatabaseUpdateState.NeedsInsert)
                {
                    Pet.PetData.DBState = PetDatabaseUpdateState.NeedsUpdate;
                }

                if (Pet != null)
                {
                    var RandomSpeech = new Random();
                    RemovePetStatus();

                    string[] Speech  = PlusEnvironment.GetGame().GetChatManager().GetPetLocale().GetValue("speech.pet" + Pet.PetData.Type);
                    string   rSpeech = Speech[RandomNumber.GenerateRandom(0, Speech.Length - 1)];

                    if (rSpeech.Length != 3)
                    {
                        Pet.Chat(rSpeech);
                    }
                    else
                    {
                        Pet.Statusses.Add(rSpeech, TextHandling.GetString(Pet.Z));
                    }
                }
                SpeechTimer = PlusEnvironment.GetRandomNumber(20, 120);
            }
            else
            {
                SpeechTimer--;
            }

            #endregion

            #region Actions

            if (ActionTimer <= 0)
            {
                try
                {
                    RemovePetStatus();
                    ActionTimer = RandomNumber.GenerateRandom(15, 40 + GetRoomUser().PetData.VirtualId);
                    if (!GetRoomUser().RidingHorse)
                    {
                        // Remove Status
                        RemovePetStatus();

                        Point nextCoord = GetRoom().GetGameMap().GetRandomWalkableSquare();
                        if (GetRoomUser().CanWalk)
                        {
                            GetRoomUser().MoveTo(nextCoord.X, nextCoord.Y);
                        }
                    }
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);
                }
            }
            else
            {
                ActionTimer--;
            }

            #endregion

            #region Energy

            if (EnergyTimer <= 0)
            {
                RemovePetStatus();                                  // Remove Status

                Pet.PetData.PetEnergy(true);                        // Add Energy

                EnergyTimer = RandomNumber.GenerateRandom(30, 120); // 2 Min Max
            }
            else
            {
                EnergyTimer--;
            }

            #endregion
        }