Esempio n. 1
0
        private List <AbstractArea> GetAreaWithPheromone(List <AbstractArea> list)
        {
            var          homePosition = list[0];
            AbstractArea bestPosition = null;
            var          bestDistance = 0;

            List <AbstractArea> listSelected = new List <AbstractArea>();

            for (var i = 0; i < list.Count; i++)
            {
                var item = list[i];
                foreach (AbstractObject o in item.ListObject)
                {
                    if (o.GetType() == typeof(Pheromone))
                    {
                        var tmp = AbstractArea.GetDistance(homePosition, item);
                        if (tmp > bestDistance)
                        {
                            bestPosition = item;
                            bestDistance = tmp;
                        }
                        break;
                    }
                }
            }

            if (bestPosition != null)
            {
                listSelected.Add(bestPosition);
            }

            return(listSelected);
        }
Esempio n. 2
0
        public void OnCommand(GameClient client, string[] args)
        {
            if (IsSpammingCommand(client.Player, "search"))
            {
                return;
            }

            GamePlayer player = client.Player;

            if (player == null)
            {
                return;
            }

            bool searched = false;

            AbstractArea currentArea = null;

            foreach (AbstractArea area in player.CurrentAreas)
            {
                if (area is QuestSearchArea || area is Area.Search)
                {
                    currentArea = area;
                    break;
                }
                else
                {
                    player.Out.SendMessage("You see nothing special about this area.", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
                    return;
                }
            }
            // checks dataquests and rewardquests for search areas
            foreach (AbstractQuest quest in player.QuestList)
            {
                if (quest.Command(player, AbstractQuest.eQuestCommand.Search))
                {
                    searched = true;
                }
            }

            // Also check for DataQuests started via searching
            if (searched == false)
            {
                foreach (AbstractArea area in player.CurrentAreas)
                {
                    if (area is QuestSearchArea && (area as QuestSearchArea).DataQuest != null && (area as QuestSearchArea).Step == 0)
                    {
                        if ((area as QuestSearchArea).DataQuest.Command(player, AbstractQuest.eQuestCommand.SearchStart, area))
                        {
                            searched = true;
                        }
                    }
                }
            }

            if (searched == false)
            {
                player.Out.SendMessage("You can't do that here!", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
            }
        }
Esempio n. 3
0
 private bool CheckBottomLeftIntersection(AbstractArea left, AbstractArea right)
 {
     return(right.StartPosition.Left > left.StartPosition.Left &&
            right.StartPosition.Left < left.StartPosition.Left + left.Size.Width &&
            right.StartPosition.Top + right.Size.Height > left.StartPosition.Top &&
            right.StartPosition.Top + right.Size.Height <= left.StartPosition.Top + left.Size.Height);
 }
Esempio n. 4
0
        override public AbstractArea ChoiceNextArea(List <AbstractArea> listArea)
        {
            var positionHome = listArea[0];

            if (Life == 0)
            {
                return(Position);
            }

            if (StayHome)
            {
                IsGoingHome  = true;
                _destination = positionHome;
            }

            if (IsStoping)
            {
                return(Position);
            }

            if (IsGoingHome && (_destination == null || _destination != positionHome))
            {
                IsWalking    = true;
                _destination = positionHome;
            }

            if (_destination != null)
            {
                if (this.Position.X == _destination.X && this.Position.Y == _destination.Y)
                {
                    _destination = null;
                    IsWalking    = false;
                }
            }

            if (IsWalking)
            {
                Walk();
                return(null);
            }


            var total = listArea.Count;

            if (total == 1)
            {
                return(listArea.First());
            }
            if (total > 0 && StayHome == false)
            {
                return(listArea[RandInt(1, total)]);
            }
            return(null);
        }
Esempio n. 5
0
        public virtual bool Command(GamePlayer player, eQuestCommand command, AbstractArea area = null)
        {
            if (m_searchAreas == null || m_searchAreas.Count == 0)
            {
                return(false);
            }

            if (player == null || command == eQuestCommand.None)
            {
                return(false);
            }

            if (command == eQuestCommand.Search)
            {
                foreach (AbstractArea playerArea in player.CurrentAreas)
                {
                    if (playerArea is QuestSearchArea)
                    {
                        QuestSearchArea questArea = playerArea as QuestSearchArea;

                        if (questArea != null && questArea.Step == Step)
                        {
                            foreach (QuestSearchArea searchArea in m_searchAreas)
                            {
                                if (searchArea == questArea)
                                {
                                    StartQuestActionTimer(player, command, questArea.SearchSeconds);
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 6
0
 override public void MoveCharacter(AbstractCharacter character, AbstractArea source, AbstractArea destination)
 {
     source.RemoveCharacter(character);
     destination.AddCharcater(character);
 }
Esempio n. 7
0
 public void NotifyIsNight()
 {
     _destination = null;
     StayHome     = true;
 }
Esempio n. 8
0
 public void NotifyIsDay()
 {
     StayHome     = false;
     IsStoping    = false;
     _destination = null;
 }
Esempio n. 9
0
        protected void Walk()
        {
            float step = 0.1f;

            var source = this.Position;

            if (_destination == null)
            {
                IsWalking = false;
                return;
            }

            if (_destination.X > source.X && _destination.Y == source.Y)
            {
                Direction     = Direction.Right;
                this.Position = new Field(source.X + step, source.Y);
            }

            if (_destination.X < source.X && _destination.Y == source.Y)
            {
                Direction     = Direction.Left;
                this.Position = new Field(source.X - step, source.Y);
            }

            if (_destination.Y > source.Y && _destination.X == source.X)
            {
                Direction     = Direction.Down;
                this.Position = new Field(source.X, source.Y + step);
            }

            if (_destination.Y < source.Y && _destination.X == source.X)
            {
                Direction     = Direction.Up;
                this.Position = new Field(source.X, source.Y - step);
            }

            if (_destination.Y < source.Y && _destination.X < source.X)
            {
                Direction     = Direction.UpLeft;
                this.Position = new Field(source.X - step, source.Y - step);
            }

            if (_destination.Y > source.Y && _destination.X > source.X)
            {
                Direction     = Direction.DownRight;
                this.Position = new Field(source.X + step, source.Y + step);
            }

            if (_destination.Y < source.Y && _destination.X > source.X)
            {
                Direction     = Direction.UpRight;
                this.Position = new Field(source.X + step, source.Y - step);
            }

            if (_destination.Y > source.Y && _destination.X < source.X)
            {
                Direction     = Direction.DownLeft;
                this.Position = new Field(source.X - step, source.Y + step);
            }


            Random r     = new Random();
            double magic = r.NextDouble();

            // to fix floating cf: 1.0000001 not eq 1.0
            this.Position = new Field((float)Math.Round((Decimal)Position.X, 1),
                                      (float)Math.Round((Decimal)Position.Y, 1));
        }
Esempio n. 10
0
 private bool CheckLeftIntersection(AbstractArea left, AbstractArea right)
 {
     return(CheckTopLeftIntersection(left, right) ||
            CheckBottomLeftIntersection(left, right));
 }
Esempio n. 11
0
 public Path(AbstractArea start, AbstractArea end) : base(start, end)
 {
 }
Esempio n. 12
0
        public override AbstractArea ChoiceNextArea(List <AbstractArea> listArea)
        {
            var home            = (Anthill)listArea[0].Environment;
            var CurrentPosition = listArea[1];

            IsFighting = false;

            if (CurrentPosition == home.Position)
            {
                while (Life <= 90)
                {
                    var foods = (from f in home.ListObject
                                 where f.GetType() == typeof(Food)
                                 select f);

                    if (foods.Count() <= 10)
                    {
                        break;
                    }
                    Life += ((Food)foods.First()).GetRemaningPiece();
                    home.ListObject.Remove(foods.First());
                }
            }


            if (CurrentPosition == home.Position &&
                CurrentPosition.ListCharacters.Where(c => c.GetType() == typeof(AntFighter)).ToList().Count < 1)
            {
                //IsGoingHome = true;
            }
            else
            {
                IsGoingHome = false;
            }

            if (Life < 20)
            {
                IsGoingHome = true;
            }

            if (!IsGoingHome)
            {
                AbstractArea foundEnemyPosition = null;
                foreach (AbstractArea area in listArea)
                {
                    var listCharacters = area.ListCharacters;
                    foreach (AbstractCharacter c in listCharacters)
                    {
                        if (!home.IsCharacterFromAnthill(c) && c.Life > 0 &&
                            AbstractArea.GetDistance(c.Position, Position) <= 1)
                        {
                            List <AbstractArea> l = new List <AbstractArea>
                            {
                                foundEnemyPosition
                            };

                            foundEnemyPosition = area;
                            if (CanBeat && Life > 0)
                            {
                                IsFighting = true;
                                UpdateDirection((Field)area);
                                c.Life -= 5;
                                c.Life  = Math.Round(c.Life, 2);
                            }
                            return(base.ChoiceNextArea(l));
                        }
                    }
                }
            }

            IsStoping = false;
            return(base.ChoiceNextArea(listArea));
        }
 public void Initialization()
 {
     _intersectionChecker = new IntersectionChecker();
     _areaBuilder         = new ConcreteAreaBuilder();
     _newArea             = GenerateArea(1, 2, 3, 2);
 }
Esempio n. 14
0
 internal abstract void AddArea(AbstractArea areaIn);
Esempio n. 15
0
        override public void Simulate()
        {
            Sun.Instance.UpdateTime(TotalTime);

            if ((TotalTime - _lastTimeAddFood) >= 1000 && ListObject.Where(f => f.GetType() == typeof(Food)).ToList().Count < 80)
            {
                _lastTimeAddFood = TotalTime;
                AddObject(new Food(100));
            }

            List <AbstractObject> objectsToRemove = new List <AbstractObject>();

            foreach (AbstractObject obj in ListObject)
            {
                if (obj.GetType() == typeof(Food))
                {
                    Food food = (Food)obj;
                    if (food.GetRemaningPiece() == 0)
                    {
                        food.Position.ListObject.Remove(food);
                        objectsToRemove.Add(obj);
                    }
                }
            }
            ListObject.RemoveAll(food => objectsToRemove.Contains(food));


            ListAnthill.RemoveAll(a => a.ListCharacter.Count == 0);

            var countAnthill = ListAnthill.Count;

            for (var i = 0; i < countAnthill; i++)
            {
                Anthill anthill = ListAnthill[i];
                if (anthill == null)
                {
                    break;
                }
                anthill.TotalTime = TotalTime;

                if (TotalTime - _lastTimeDecreasePheromone >= 20)
                {
                    _lastTimeDecreasePheromone = TotalTime;
                    for (var y = 0; y < HeightWorld; y++)
                    {
                        for (var x = 0; x < WidthWorld; x++)
                        {
                            var field = Fields[y, x];
                            foreach (AbstractObject o in field.ListObject)
                            {
                                if (o.GetType() == typeof(Pheromone))
                                {
                                    ((Pheromone)o).Duration--;
                                }
                            }
                            field.ListObject.RemoveAll(o => o.GetType() == typeof(Pheromone) && ((Pheromone)o).Duration <= 0);
                        }
                    }
                }
                var queens = anthill.ListCharacter.Where(c => c.GetType() == typeof(AntQueen)).ToList();
                if (queens.Count > 1)
                {
                    var          queen = (AntQueen)queens.Last();
                    AbstractArea originalPositionQueen = queen.Position;
                    queen.CreateAnthill(anthill, this);
                    queen.Position = originalPositionQueen;
                }
                anthill.Areas     = Fields;
                anthill.TotalTime = TotalTime;
                anthill.Simulate();
            }
        }
Esempio n. 16
0
		public virtual bool Command(GamePlayer player, eQuestCommand command, AbstractArea area = null)
		{
			if (m_searchAreas == null || m_searchAreas.Count == 0)
				return false;

			if (player == null || command == eQuestCommand.None)
				return false;

			if (command == eQuestCommand.Search)
			{
				foreach (AbstractArea playerArea in player.CurrentAreas)
				{
					if (playerArea is QuestSearchArea)
					{
						QuestSearchArea questArea = playerArea as QuestSearchArea;

						if (questArea != null && questArea.Step == Step)
						{
							foreach (QuestSearchArea searchArea in m_searchAreas)
							{
								if (searchArea == questArea)
								{
									StartQuestActionTimer(player, command, questArea.SearchSeconds);
									return true;
								}
							}
						}
					}
				}
			}

			return false;
		}
Esempio n. 17
0
        /// <summary>
        /// Triggered from quest commands like /search
        /// </summary>
        /// <param name="player"></param>
        /// <param name="command"></param>
        /// <param name="area"></param>
        /// <returns></returns>
        public override bool Command(GamePlayer player, AbstractQuest.eQuestCommand command, AbstractArea area)
        {
            if (player == null || command == eQuestCommand.None)
                return false;

            if (command == eQuestCommand.Search)
            {
                // every active quest in the players quest list is sent this command.  Respond if we have an active search

                if (m_numSearchAreas > 0 && player == QuestPlayer)
                {
                    // see if the player is in our search area

                    foreach (AbstractArea playerArea in player.CurrentAreas)
                    {
                        if (playerArea is QuestSearchArea && (playerArea as QuestSearchArea).DataQuest != null && (playerArea as QuestSearchArea).DataQuest.ID == ID)
                        {
                            if ((playerArea as QuestSearchArea).Step == Step)
                            {
                                StartQuestActionTimer(player, command, (playerArea as QuestSearchArea).SearchSeconds, "Searching ...");
                                return true; // only allow one active search at a time
                            }
                        }
                    }
                }
            }

            if (command == eQuestCommand.SearchStart && area != null)
            {
                // If player can start this quest then do search action

                if (CheckQuestQualification(player))
                {
                    StartQuestActionTimer(player, command, (area as QuestSearchArea).SearchSeconds, "Searching ...");
                    return true;
                }
            }

            return false;
        }
Esempio n. 18
0
        public void OnCommand(GameClient client, string[] args)
        {
            if (args.Length == 1)
            {
                DisplaySyntax(client);
                return;
            }

            switch (args[1].ToLower())
            {
                #region Create
            case "create":
            {
                if (args.Length != 7)
                {
                    DisplaySyntax(client);
                    return;
                }

                DBArea area = new DBArea();
                area.Description = args[2];

                switch (args[3].ToLower())
                {
                case "circle": area.ClassType = "DOL.GS.Area+Circle"; break;

                case "square": area.ClassType = "DOL.GS.Area+Square"; break;

                case "safe":
                case "safearea": area.ClassType = "DOL.GS.Area+SafeArea"; break;

                case "bind":
                case "bindarea": area.ClassType = "DOL.GS.Area+BindArea"; break;

                default:
                {
                    DisplaySyntax(client);
                    return;
                }
                }

                area.Radius = Convert.ToInt16(args[4]);
                switch (args[5].ToLower())
                {
                case "y": { area.CanBroadcast = true; break; }

                case "n": { area.CanBroadcast = false; break; }

                default: { DisplaySyntax(client); return; }
                }
                area.Sound  = byte.Parse(args[6]);
                area.Region = client.Player.CurrentRegionID;
                area.X      = client.Player.X;
                area.Y      = client.Player.Y;
                area.Z      = client.Player.Z;

                Assembly     gasm    = Assembly.GetAssembly(typeof(GameServer));
                AbstractArea newArea = (AbstractArea)gasm.CreateInstance(area.ClassType, false);
                newArea.LoadFromDatabase(area);

                newArea.Sound        = area.Sound;
                newArea.CanBroadcast = area.CanBroadcast;
                WorldMgr.GetRegion(client.Player.CurrentRegionID).AddArea(newArea);
                GameServer.Database.AddObject(area);
                DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.Area.AreaCreated", area.Description, area.X, area.Z, area.Radius, area.CanBroadcast.ToString(), area.Sound));
                break;
            }

                #endregion Create
                #region Default
            default:
            {
                DisplaySyntax(client);
                break;
            }
                #endregion Default
            }
        }
Esempio n. 19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="first"></param>
 /// <param name="second"></param>
 /// <returns></returns>
 public bool AreIntersect(AbstractArea first, AbstractArea second)
 {
     return(CheckLeftIntersection(first, second) ||
            CheckLeftIntersection(second, first));
 }