Esempio n. 1
0
 public static void AddToGame(Hero hero, FixedObject gameObject)
 {
     if (!hero.AddToBag(gameObject))
     {
         Map.SetHObjectFromDestination(hero.Position, gameObject);
     }
 }
Esempio n. 2
0
        internal void SetObjectFromCell(Point cell, FixedObject gameObject)
        {
            if (cell == null)
            {
                return;
            }

            if (gameObject == null)
            {
                _map[cell.X, cell.Y] = null;
                return;
            }

            var largeObjectInner = gameObject as LargeObjectInner;

            if (largeObjectInner != null)
            {
                largeObjectInner.OuterObjects.ForEach(outerObject =>
                {
                    var outerO = outerObject;
                    SetObjectFromCell(new Point(cell.X + outerO.PlaceInObject.X, cell.Y + outerO.PlaceInObject.Y), outerO);
                });

                return;
            }

            if (gameObject.RemoveFromContainer != null)
            {
                gameObject.RemoveFromContainer();
            }

            gameObject.RemoveFromContainer = (() =>
            {
                gameObject.RemoveFromContainer = null;

                if (gameObject == _map[cell.X, cell.Y])
                {
                    this.SetObjectFromCell(cell, null);
                }

                if (gameObject.Properties.Contains(Property.Regrowable) && gameObject is ICloneable)
                {
                    this.SetObjectFromCell(this.GetRandomNearEmptyPoint(cell, 3), (FixedObject)(gameObject as ICloneable).Clone());
                }
            });

            if (gameObject.Properties.Contains(Property.Dropable))
            {
                gameObject.Properties.Remove(Property.Dropable);

                if (!gameObject.Properties.Contains(Property.Pickable))
                    gameObject.Properties.Add(Property.Pickable);
            }

            _map[cell.X, cell.Y] = gameObject;
        }
Esempio n. 3
0
        private void SetHObjectFromCell(Point cell, FixedObject gameObject)
        {
            if (CellInInnerMap(cell))
            {
                _innerMap.SetObjectFromCell(new Point(cell.X - _innerMapPoint.X, cell.Y - _innerMapPoint.Y), gameObject);
                return;
            }

            SetObjectFromCell(cell, gameObject);
        }
Esempio n. 4
0
        internal void SetHObjectFromDestination(Point destination, FixedObject gameObject)
        {
            var cell = PointToCell(destination);

            SetHObjectFromCell(cell, gameObject);
        }
Esempio n. 5
0
 public Point GetDestination(Point destination, FixedObject destObject, Hero hero)
 {
     return destination;
 }
Esempio n. 6
0
        internal void SetObjectFromCell(Point cell, FixedObject gameObject)
        {
            if (cell == null)
            {
                return;
            }

            if (gameObject == null)
            {
                _map[cell.X, cell.Y] = null;
                return;
            }

            var largeObjectInner = gameObject as LargeObjectInner;

            if (largeObjectInner != null)
            {
                foreach (var outerObject in largeObjectInner.OuterObjects)
                {
                    var outerO = outerObject;
                    SetObjectFromCell(new Point(cell.X + outerO.PlaceInObject.X, cell.Y + outerO.PlaceInObject.Y), outerO);
                }

                return;
            }

            if (gameObject.RemoveFromContainer != null)
            {
                gameObject.RemoveFromContainer();
            }

            gameObject.RemoveFromContainer = (() =>
            {
                gameObject.RemoveFromContainer = null;

                if (gameObject == _map[cell.X, cell.Y])
                {
                    SetObjectFromCell(cell, null);
                }

                ApplySpoileringBehavior(gameObject);

                if (gameObject.Properties.Contains(Property.Regrowable))
                {
                    var gameObjName = gameObject.Name;
                    Game.PlannedQueueManager.AddObjectToQueue(new PlannedEvent(() =>
                    {
                        var nearCell = GetRandomNearEmptyPoint(cell, 3);
                        if (nearCell == null)
                        {
                            return(false);
                        }

                        SetObjectFromCell(nearCell, (FixedObject)Game.Factory.Produce(gameObjName));
                        return(true);
                    }));
                }
            });

            if (gameObject.Properties.Contains(Property.Dropable))
            {
                gameObject.Properties.Remove(Property.Dropable);

                if (!gameObject.Properties.Contains(Property.Pickable))
                {
                    gameObject.Properties.Add(Property.Pickable);
                }
            }

            _map[cell.X, cell.Y] = gameObject;
        }