Exemple #1
0
        private void UpdateTile(Tile newTile)
        {
            if (newTile == _tile) return;

            if (_tile != null) {
                _tile.RemoveStaticEntity(Entity);
            }

            _tile = newTile;

            if (_tile != null) {
                _tile.AddStaticEntity(Entity);
            }
        }
Exemple #2
0
 public StaticTile(Entity ent)
     : base(ent)
 {
     _tile = null;
 }
Exemple #3
0
        public override IEnumerable<Action> GetActions()
        {
            _pendingTiles = _destTiles.Where(x => x.StaticEntities.Count() == 0).ToArray();

            if (ShouldAbandon()) {
                if (Human.IsHoldingItem) {
                    yield return new DropItemAction(1f);
                }

                yield break;
            }

            if (!Human.IsHoldingItem) {
                _destTile = null;

                if (_destResource != null && (_destResource.Entity.Position2D != _destResource.LastPos || !_destResource.Entity.IsValid)) {
                    _destResource = null;
                }

                if (_destResource == null) {
                    _destResource = _blockBeliefs.Entities
                        .Union(Beliefs.Entities)
                        .Where(x => x.Type == EntityType.PlankSource || x.Type == EntityType.PlankPile)
                        .Where(x => World.GetTile(x.LastPos).IsInterior)
                        .OrderBy(x => World.Difference(x.LastPos, Entity.Position2D).LengthSquared)
                        .FirstOrDefault();

                    if (_destResource == null) {
                        _noResources = true;
                        yield break;
                    } else {
                        if (_nav != null) {
                            _nav.Dispose();
                        }

                        _nav = new RouteNavigator(Entity, _destResource.LastPos +
                            World.Difference(_destResource.LastPos, Entity.Position2D).Normalized() * 1.4f);
                    }
                }

                var diff = World.Difference(Entity.Position2D, _destResource.LastPos);

                if (_nav.HasEnded) {
                    yield return new MovementAction(diff.Normalized() * 2f);
                } else if (_nav.HasDirection) {
                    yield return new MovementAction(_nav.GetDirection() * 2f);
                }

                if (diff.LengthSquared < 2f) {
                    if (_destResource.Type == EntityType.PlankSource) {
                        yield return new AttackAction(_destResource.Entity);
                    } else if (_destResource.Entity.GetComponent<Item>().CanPickup(Entity)) {
                        yield return new PickupItemAction(_destResource.Entity, 2f);
                    }
                }
            } else {
                _destResource = null;

                if (_destTile != null && !_pendingTiles.Contains(_destTile)) {
                    _destTile = null;
                }

                if (_destTile == null) {
                    _destTile = _pendingTiles
                        .OrderBy(x => World.Difference(Entity.Position2D, x.Position).LengthSquared)
                        .FirstOrDefault();

                    if (_nav != null) {
                        _nav.Dispose();
                    }

                    _nav = new RouteNavigator(Entity, _destTile.Position);
                }

                if (_destTile != null) {
                    var diff = World.Difference(Entity.Position2D, _destTile.Position);

                    if (_nav.HasDirection) {
                        yield return new MovementAction(_nav.GetDirection() * 2f);
                    }

                    if (diff.LengthSquared < 0.25f) {
                        yield return new DropItemAction(2f);
                    }
                }
            }
        }