Пример #1
0
        public AdventureCommandRegistry(IReadonlyAdventureGame game)
        {
            var lookCommand      = new Look(game, "look", "l");
            var helpCommand      = new Help(game, "help");
            var moveCommand      = new Move(game, "move", "go", "walk", "run", "climb", "crawl");
            var takeCommand      = new Take(game, "take", "get", "grab");
            var dropCommand      = new Drop(game, "drop");
            var magicWord1       = new Xyzzy(game, "xyzzy");
            var magicWord2       = new Plugh(game, "plugh");
            var inventoryCommand = new Carrying(game, "inventory", "inv");
            var interactCommand  = new Interact(game, "use"); // Do not add aliases for this command
            var yes = new Yes(game, "yes", "y");
            var no  = new No(game, "no", "n");
            var say = new Say(game, "say");

            RegisteredCommands = new List <IAdventureCommand> {
                lookCommand,
                helpCommand,
                moveCommand,
                takeCommand,
                dropCommand,
                magicWord1,
                magicWord2,
                inventoryCommand,
                interactCommand,
                yes,
                no,
                say,
            };
        }
Пример #2
0
 public void Disposing(Actor self)
 {
     if (Carrying != null && IsCarrying)
     {
         Carrying.Dispose();
         Carrying = null;
     }
 }
Пример #3
0
 internal void ReloadContent(ref Director director, ContentManager content)
 {
     base.ReloadContent(ref director);
     if (Carrying.IsPresent())
     {
         Carrying.Get().ReloadContent(ref director);
     }
     mDirector       = director;
     mGenUnitTexture = content.Load <Texture2D>("GenUnit");
 }
Пример #4
0
        // INotifyKilled
        public void Killed(Actor self, AttackInfo e)
        {
            if (Carrying != null)
            {
                if (IsCarrying && Carrying.IsInWorld && !Carrying.IsDead)
                {
                    Carrying.Kill(e.Attacker);
                }

                Carrying = null;
            }

            UnreserveCarryable();
        }
Пример #5
0
        // Unreserve the carryable
        public void UnreserveCarryable()
        {
            if (Carrying != null)
            {
                if (Carrying.IsInWorld && !Carrying.IsDead)
                {
                    Carrying.Trait <Carryable>().UnReserve(self);
                }

                Carrying = null;
            }

            CarryableReleased();
        }
Пример #6
0
        public bool PickApple()
        {
            if (IsCarrying)
            {
                return(false);
            }
            var apple = _nearApples.FirstOrDefault();

            if (apple == null)
            {
                return(false);
            }
            apple.AddCarryingAnt(this);
            _carrying = Carrying.Apple;
            return(true);
        }
Пример #7
0
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(mGenUnitTexture,
                             AbsolutePosition,
                             null,
                             Color.White,
                             0f,
                             new Vector2(10),
                             Vector2.One,
                             SpriteEffects.None,
                             LayerConstants.GeneralUnitLayer);

            if (Carrying.IsPresent())
            {
                Carrying.Get().Draw(spriteBatch);
            }
        }
Пример #8
0
        public override bool Die()
        {
            // stats tracking for the death of a general unit
            mDirector.GetStoryManager.UpdateUnits("lost");

            mTask = new Task(Job, Optional <PlatformBlank> .Of(null), null, Optional <IPlatformAction> .Of(null));
            if (Carrying.IsPresent())
            {
                Carrying.Get().Die();
                Carrying = Optional <Resource> .Of(null);
            }

            mDirector.GetDistributionDirector.GetManager(Graphid).Kill(this);
            mAssignedAction?.Kill(this);
            mDirector.GetStoryManager.Level.GameScreen.RemoveObject(this);

            return(true);
        }
Пример #9
0
        public bool PickSugar()
        {
            if (IsCarrying)
            {
                return(false);
            }
            var sugar = _nearSugar.FirstOrDefault();

            if (sugar == null)
            {
                return(false);
            }
            if (!sugar.PickSugar())
            {
                return(false);
            }
            _carrying = Carrying.Sugar;
            return(true);
        }
Пример #10
0
        public AdventureCommandRegistry(IReadonlyAdventureGame game)
        {
            var lookCommand      = new Look(game, "look", "l");
            var helpCommand      = new Help(game, "help");
            var moveCommand      = new Move(game, "move", "go", "walk", "run", "climb", "crawl", "head");
            var takeCommand      = new Take(game, "take", "get", "grab");
            var dropCommand      = new Drop(game, "drop", "discard");
            var magicWord1       = new Xyzzy(game, "xyzzy");
            var magicWord2       = new Plugh(game, "plugh");
            var inventoryCommand = new Carrying(game, "inventory", "inv");
            var interactCommand  = new Interact(game, "use"); // Do not add aliases for this command
            var yes    = new Yes(game, "yes", "y");
            var no     = new No(game, "no", "n");
            var say    = new Say(game, "say");
            var back   = new Back(game, "back", "retreat");
            var give   = new Give(game, "give");
            var attack = new Attack(game, "attack", "assault", "kill", "murder", "slay");

            // ToDo: Remove this as its for TESTING ONLY
            var teleport = new Teleport(game, "teleport");

            RegisteredCommands = new List <IAdventureCommand> {
                lookCommand,
                helpCommand,
                moveCommand,
                takeCommand,
                dropCommand,
                magicWord1,
                magicWord2,
                inventoryCommand,
                interactCommand,
                yes,
                no,
                say,
                back,
                teleport,
                give,
                attack,
            };
        }
Пример #11
0
        /// <summary>
        /// Used to change the job. Is usually only called if the player wants more/less Units working in a certain job.
        /// </summary>
        /// <param name="job">The job the unit should do.</param>
        public void ChangeJob(JobType job)
        {
            //If its moving it cannot be assigned, since the unit only assigns itself when it reached the target (and stopped moving)
            //That also means, that the CurrentNode is the Producing platform, so we call that UnAssign method.
            if ((Job == JobType.Production || Job == JobType.Defense) && mTask.End.IsPresent())
            {
                mTask.End.Get().UnAssignUnits(this, Job);
                mAssigned = false;
            }

            //Finish what you started.
            if (Job == JobType.Logistics || Job == JobType.Construction)
            {
                if (Carrying.IsPresent())
                {
                    mFinishTask = true;
                }
                else
                {
                    //Put the task back in the Queue.
                    var isbuilding = Job == JobType.Construction;
                    if (mTask.Action.IsPresent())
                    {
                        if (mTask.GetResource != null)
                        {
                            mDirector.GetDistributionDirector.GetManager(Graphid).RequestResource(mTask.End.Get(), (EResourceType)mTask.GetResource, mTask.Action.Get(), isbuilding);
                        }
                    }
                    else
                    {
                        if (mTask.GetResource != null)
                        {
                            mDirector.GetDistributionDirector.GetManager(Graphid).RequestResource(mTask.End.Get(), (EResourceType)mTask.GetResource, null, isbuilding);
                        }
                    }
                }
            }
            Job = job;
        }
Пример #12
0
        private void PickupOrDrop()
        {
            if (Carrying != null)
            {
                Carrying.OnDropped(this);
                if (Carrying is PuzzlePiece pl && !pl.IsPlacedOnGrid)
                {
                    Carrying.AnimateMove(Position + new Vector2(0, -10));
                    _dropItem.Play();
                }
                Carrying.Color = Color.White;
                Carrying       = null;
                return;
            }

            if (TargetEntity != null)
            {
                Carrying       = TargetEntity;
                Carrying.Depth = Depths.PlayerCarry;
                Carrying.OnPickedUp(this);
                _pickupItem.Play();
            }
        }
Пример #13
0
        public override void Update(GameTime gameTime)
        {
            if (!IsActive)
            {
                return;
            }

            var gamePad = GamePad.GetState(Index);
            var kb      = Keyboard.GetState();

            if (JustPressed(gamePad, Buttons.A) || JustTriggered(gamePad, x => x.Right) || JustPressed(kb, Keys.L, Keys.C) || (Index == PlayerIndex.One && Input.KeyPressed(Keys.Space)))
            {
                PickupOrDrop();
            }

            var pressedRotateLeft  = JustPressed(gamePad, Buttons.LeftShoulder) || JustPressed(gamePad, Buttons.X) || JustPressed(kb, Keys.J, Keys.V) || (Index == PlayerIndex.One && Input.KeyPressed(Keys.Z));
            var pressedRotateRight = JustPressed(gamePad, Buttons.RightShoulder) || JustPressed(gamePad, Buttons.B) || JustPressed(kb, Keys.K, Keys.B) || (Index == PlayerIndex.One && Input.KeyPressed(Keys.X));

            if (Carrying != null)
            {
                Carrying?.AnimateMove(Position + new Vector2(0, -20), 1);

                if (pressedRotateLeft)
                {
                    RotateCarried(-1);
                }
                if (pressedRotateRight)
                {
                    RotateCarried(1);
                }
            }

            if (pressedRotateLeft || pressedRotateRight)
            {
                var change = (pressedRotateLeft ? -1 : 0) + (pressedRotateRight ? 1 : 0);
                Q19Game.Instance.Scene.Visit(e =>
                {
                    if (e is PuzzlesPreview pp)
                    {
                        pp.GoTo(change);
                    }
                });
            }

            var moveInput = GetGamePadMovement(gamePad);

            if (Q19Game.DebugIsActivePlayer(Index))
            {
                moveInput += GetKeyboardMovement(kb, PlayerIndex.One);
            }
            else if (Index < PlayerIndex.Three)
            {
                moveInput += GetKeyboardMovement(kb, Index);
            }

            if (_disableInput)
            {
                var currentTarget    = _autoMoveTargets[0];
                var toTarget         = currentTarget - Position;
                var distanceToTarget = toTarget.Length();
                moveInput = toTarget;
                if (distanceToTarget < Speed * (float)gameTime.ElapsedGameTime.TotalSeconds)
                {
                    _autoMoveTargets.RemoveAt(0);
                    if (!_autoMoveTargets.Any())
                    {
                        _disableInput = false;
                    }
                }
            }

            var isMoving = moveInput != Vector2.Zero;

            if (isMoving)
            {
                var movement = Vector2.Normalize(moveInput) * Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;

                #region level bound collision

                var result = Q19Game.Instance.Scene.Level.IsWithinBounds(this, movement);
                if (result.CollidingX)
                {
                    movement.X = 0;
                }
                if (result.CollidingY)
                {
                    movement.Y = 0;
                }

                #endregion


                Position += movement;
            }

            _movementSounds.UpdateMovementSound(isMoving, gameTime);

            var pickupEntities  = Q19Game.Instance.GetAllPickupEntities();
            var closestDistance = float.MaxValue;
            TargetEntity = null;
            foreach (var pickupEntity in pickupEntities)
            {
                var distance = Vector2.DistanceSquared(pickupEntity.Position, Position);
                if (distance < closestDistance)
                {
                    closestDistance = distance;
                    TargetEntity    = pickupEntity;
                }
            }
            if (closestDistance > PickupDistance * PickupDistance)
            {
                TargetEntity = null;
            }
            else
            {
                TargetEntity.TouchFocus(PlayerColor);
            }

            // Highlight fire and piece when close enough to burn a piece
            if (Carrying != null)
            {
                Carrying.Color = Color.White;
                Q19Game.Instance.Scene.Visit(e =>
                {
                    if (e is Fire f && f.CarriedBy == null &&
                        Vector2.DistanceSquared(Carrying.Position, f.Position) < Fire.FireTossDistance * Fire.FireTossDistance)
                    {
                        f.TouchFocus(PlayerColor);
                        Carrying.Color = Color.Red;
                    }
                });
            }

            _previousGamePadState  = gamePad;
            _previousKeyboardState = kb;
            base.Update(gameTime);
        }
Пример #14
0
 private void RotateCarried(int direction)
 {
     _spinCarriedSound.Play();
     Carrying.Rotate(direction);
 }
Пример #15
0
        protected virtual void OnCollisionEnter(Collision collision)
        {
            if (!Alive)
            {
                return;
            }

            var sugar = collision.gameObject.GetComponent <Sugar>();

            if (sugar != null)
            {
                _nearSugar.Add(sugar);
                _antScript.Reach(sugar);
            }
            var apple = collision.gameObject.GetComponent <Apple>();

            if (apple != null)
            {
                _nearApples.Add(apple);
                _antScript.Reach(apple);
            }
            var anthill = collision.gameObject.GetComponent <Anthill>();

            if (anthill != null)
            {
                switch (_carrying)
                {
                case Carrying.Noting:
                    _antScript.Reach(anthill);
                    break;

                case Carrying.Sugar:
                    anthill.CollectSugar();
                    _carrying = Carrying.Noting;
                    _antScript.Reach(anthill);
                    break;

                case Carrying.Apple:
                    break;

                default:
                    throw new NotSupportedException(string.Format(
                                                        "The carring state '{0}' is not supported.",
                                                        _carrying));
                }
            }
            var mark = collision.gameObject.GetComponent <Mark>();

            if (mark != null)
            {
                if (mark.Creator != this)
                {
                    _antScript.Reach(mark);
                }
            }
            var levelBoundary = collision.gameObject.GetComponentInParent <LevelBoundary>();

            if (levelBoundary != null)
            {
                _state      = State.Idle;
                Destination = transform.position;
                _antScript.ReachBoundaries();
            }
        }
Пример #16
0
 public void RemoveCarriedApple()
 {
     _carrying = Carrying.Noting;
     InitDestination(Destination);
 }
Пример #17
0
        /// <summary>
        /// In the Idle case the unit will just get a Target to move to and do so.
        /// In the Production case the unit will go to the producing Platform and call its produce method.
        /// </summary>
        /// <param name="gametime"></param>
        public void Update(GameTime gametime)
        {
            if (!mInitialized)
            {
                return;
            }
            //If true, this unit has still a task to finish and shall not act like the job it has now until the task is finished.
            //This should only occur when Logistic or Constructing units have only just picked up a Resource and their job changed after that.
            if (mFinishTask)
            {
                RegulateMovement();
                if (Carrying.IsPresent())
                {
                    Carrying.Get().Follow(this);
                }
                //This means we arrived at the point we want to leave the Resource and consider our work done
                if (!mTask.End.IsPresent() || !CurrentNode.Equals(mTask.End.Get()) ||
                    !ReachedTarget(mTask.End.Get().Center))
                {
                    return;
                }

                if (Carrying.IsPresent())
                {
                    var res = Carrying.Get();
                    res.UnFollow();
                    ((PlatformBlank)CurrentNode).StoreResource(res);
                    Carrying = Optional <Resource> .Of(null);
                }
                mDone = true;
                //We can now do the job we were assigned to.
                mFinishTask = false;
            }
            else
            {
                switch (Job)
                {
                case JobType.Idle:
                    if (!mIsMoving && mDone)
                    {
                        mDone = false;

                        mTask = mDirector.GetDistributionDirector.GetManager(Graphid)
                                .RequestNewTask(unit: this, job: Job, assignedAction: Optional <IPlatformAction> .Of(null));
                        //Check if the given destination is null (it shouldnt)
                        if (mTask.End.IsPresent())
                        {
                            mDestination = Optional <INode> .Of(mTask.End.Get());

                            TargetGraphid = mTask.End.Get().GetGraphIndex();
                        }
                    }

                    RegulateMovement();

                    //We arrived at the target, so its now time to get another job
                    if (mNodeQueue.Count == 0 && Job == JobType.Idle)
                    {
                        mDone = true;
                    }
                    break;

                case JobType.Production:
                    //You arrived at your destination and you now want to work.
                    if (!mIsMoving && !mDone && CurrentNode.Equals(mTask.End.Get()) && !mAssigned)
                    {
                        mTask.End.Get().ShowedUp(this, Job);
                        mAssigned = true;
                    }
                    if (mAssigned)
                    {
                        mTask.End.Get().Produce();
                    }

                    RegulateMovement();
                    break;

                case JobType.Defense:
                    //You arrived at your destination and you now want to work.
                    if (!mIsMoving && !mDone && CurrentNode.Equals(mTask.End.Get()))
                    {
                        if (!mAssigned)
                        {
                            mTask.End.Get().ShowedUp(this, Job);
                            mAssigned = true;
                        }
                    }
                    RegulateMovement();
                    break;

                case JobType.Logistics:

                    HandleTransport(gametime);
                    RegulateMovement();

                    if (Carrying.IsPresent())
                    {
                        Carrying.Get().Follow(this);
                    }
                    break;

                case JobType.Construction:
                    HandleTransport(gametime);
                    RegulateMovement();

                    if (Carrying.IsPresent())
                    {
                        Carrying.Get().Follow(this);
                    }
                    break;
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Logistics and Construction resemble each other very much, so this is the method to handle both.
        /// </summary>
        private void HandleTransport(GameTime time)
        {
            if (!mIsMoving && mDone)
            {
                mDone = false;

                mTask = mDirector.GetDistributionDirector.GetManager(Graphid).RequestNewTask(unit: this, job: Job, assignedAction: Optional <IPlatformAction> .Of(null));
                //First go to the location where you want to get your Resource from
                //Check if the given destination is null (it shouldnt).
                if (mTask.Begin.IsPresent())
                {
                    mDestination = Optional <INode> .Of(mTask.Begin.Get());

                    TargetGraphid = mTask.Begin.Get().GetGraphIndex();
                }
                else
                {
                    //In this case the DistributionManager has given you no valid task. That means there is no work in this job to be done. Ask in the next cycle.
                    mDone = true;
                }
            }

            //This means we arrived at the point we want to pick up a Resource
            if (mTask.Begin.IsPresent() && CurrentNode.Equals(mTask.Begin.Get()) &&
                ReachedTarget(mTask.Begin.Get().Center))
            {
                if (!Carrying.IsPresent())
                {
                    if (mTask.GetResource != null)
                    {
                        PickUp((EResourceType)mTask.GetResource);
                    }

                    //Failed to get resource, because no Resources were present. Tell the DistributionManager and consider your work done.
                    if (!Carrying.IsPresent())
                    {
                        if (mTask.Job == JobType.Logistics)
                        {
                            if (mTask.Action.IsPresent())
                            {
                                if (mTask.GetResource != null)
                                {
                                    mDirector.GetDistributionDirector.GetManager(Graphid).RequestResource(mTask.End.Get(), (EResourceType)mTask.GetResource, mTask.Action.Get());
                                }
                            }
                            else
                            {
                                if (mTask.GetResource != null)
                                {
                                    mDirector.GetDistributionDirector.GetManager(Graphid).RequestResource(mTask.End.Get(), (EResourceType)mTask.GetResource, null);
                                }
                            }
                        }
                        if (mTask.Job == JobType.Construction)
                        {
                            if (mTask.Action.IsPresent())
                            {
                                if (mTask.GetResource != null)
                                {
                                    mDirector.GetDistributionDirector.GetManager(Graphid).RequestResource(mTask.End.Get(), (EResourceType)mTask.GetResource, mTask.Action.Get(), true);
                                }
                            }
                            else
                            {
                                if (mTask.GetResource != null)
                                {
                                    mDirector.GetDistributionDirector.GetManager(Graphid).RequestResource(mTask.End.Get(), (EResourceType)mTask.GetResource, null, true);
                                }
                            }
                        }
                        mDone = true;
                    }
                }

                //Everything went fine with picking up, so now move on to your final destination
                if (mTask.End.IsPresent() && !mDone)
                {
                    mDestination = Optional <INode> .Of(mTask.End.Get());

                    TargetGraphid = mTask.End.Get().GetGraphIndex();
                }
            }

            //This means we arrived at the point we want to leave the Resource and consider our work done
            if (mTask.End.IsPresent() && CurrentNode.Equals(mTask.End.Get()) &&
                ReachedTarget(mTask.End.Get().Center) && Carrying.IsPresent())
            {
                var res = Carrying.Get();
                res.UnFollow();
                ((PlatformBlank)CurrentNode).StoreResource(res);
                Carrying = Optional <Resource> .Of(null);

                mDone = true;
            }
        }