Esempio n. 1
0
        public RPGAction GetNextAction()
        {
            RPGAction firstAction = PeekNextAction();

            Actions.Remove(firstAction);
            return(firstAction);
        }
Esempio n. 2
0
        public bool Contains(RPGAction.ActionType t, Actor source, Actor target)
        {
            RPGAction a = new RPGAction(t, target);

            a.Source = source;
            a.target = target;
            return(Contains(a));
        }
Esempio n. 3
0
        public void AddLast(RPGAction ActionToDoLast)
        {
            // look through list of actions and add new with index max + 1;
            int max = 1;

            if (Actions.Count > 0)
            {
                max = (Actions[0] as RPGAction).Index;

                foreach (RPGAction a in Actions)
                {
                    max = Math.Max(max, a.Index);
                }
            }

            ActionToDoLast.Index = max;
            Actions.Add(ActionToDoLast);
        }
Esempio n. 4
0
        public void AddFirst(RPGAction ActionToDoFirst)
        {
            // look through list of actions and add new with index min - 1;
            int min = 1;

            if (Actions.Count > 0)
            {
                min = (Actions[0] as RPGAction).Index;

                foreach (RPGAction a in Actions)
                {
                    min = Math.Min(min, a.Index);
                }
            }
            ActionToDoFirst.Index = min - 1;
            Actions.Add(ActionToDoFirst);

            switch (ActionToDoFirst.type)
            {
            case (RPGAction.ActionType.Attack):
            {
                ((Actor)ActionToDoFirst.Source).States.IsAttacking = true;
                break;
            }

            case (RPGAction.ActionType.Walk):
            case (RPGAction.ActionType.Get):
            {
                if (ActionToDoFirst.Source != null)
                {
                    if (ActionToDoFirst.Source.isOfType(typeof(Actor)))
                    {
                        ((Actor)ActionToDoFirst.Source).States.IsAttacking = false;
                    }
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }
Esempio n. 5
0
        public bool Contains(RPGAction action)
        {
            if (self.currentAction != null)
            {
                if (self.currentAction.Source == action.Source &&
                    self.currentAction.target == action.target &&
                    self.currentAction.type == action.type)
                {
                    return(true);
                }
            }

            foreach (RPGAction a in Actions)
            {
                if (action.target == a.target &&
                    action.type == a.type &&
                    action.Source == a.Source)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 6
0
        public void Act(Action a, Point loc, RPGObject obj)
        {
            switch (a)
            {
            case (Action.Move):
            {
                RPGAction action = new RPGAction(RPGAction.ActionType.Walk, loc);

                // because we want our feet to go to the location,
                // adjust the location to be relative to the feet.
                // Center on object for now.

                loc.X -= this.Width / 2;
                loc.Y -= this.Height / 2;

                action.Source      = this;
                action.destination = loc;

                this.currentAction = null;
                Actions.ClearAndAddNew(action);
                break;
            }

            case (Action.Attack):
            {
                RPGAction action = new RPGAction(RPGAction.ActionType.Attack, obj);
                action.target = obj;
                action.Source = this;

                this.currentAction = null;
                Actions.ClearAndAddNew(action);
                break;
            }

            case (Action.Get):
            {
                RPGAction action = new RPGAction(RPGAction.ActionType.Get, obj);

                action.target = obj;
                action.Source = this;
                // adjust the height slightly
                action.destination = new Point(obj.X, obj.Y - (this.Height / 2));

                this.currentAction = null;
                Actions.ClearAndAddNew(action);
                break;
            }

            case (Action.Talk):
            {
                break;
            }

            case (Action.Use):
            {
                break;
            }

            default:
            {
                break;
            }
            }
        }
Esempio n. 7
0
 public void ClearAndAddNew(RPGAction newAction)
 {
     Clear();
     AddFirst(newAction);
 }
Esempio n. 8
0
        public override void UpdateSelf()
        {
            if (this.currentState == ActionState.Dying)
            {
                this.Actions.Clear();
                this.currentAction = null;

                // do any effects that triger 'on death'...

                // check if we've been dying long enough
                if (System.DateTime.Now.CompareTo(lastDamage.AddMilliseconds(new RPGDraw().DAMAGE_DURATION)) > 0)
                {
                    this.DeleteMe = true;
                }
            }
            else
            {
                // before the actor can do anything, do any effects
                CheckEffects();

                // double check our priorities periodically
                if (System.DateTime.Now.CompareTo(this.AI.LastUpdate.AddMilliseconds(this.AI.AIUpdateDelay)) > 0)
                {
                    if (this.AIActive)
                    {
                        this.AI.DecideWhatToDo();
                    }
                }

                #region Do Current Action
                if (currentAction != null && currentAction.Accomplished == false)
                {
                    // then do action.
                    switch (currentAction.type)
                    {
                        #region Case: Walk
                    case (RPGAction.ActionType.Walk):
                    {
                        // see if action has been accomplished
                        bool Near;
                        if (currentAction.target != null)
                        {
                            Near = new RPGCalc().ActorStandingNearPoint(this, currentAction.target.Location);
                        }
                        else
                        {
                            Near = new RPGCalc().ActorStandingNearPoint(this, currentAction.destination);
                        }
                        if (Near)
                        {
                            currentAction.Accomplished = true;
                            this.currentState          = ActionState.Standing;
                            StopMoving();
                        }
                        else
                        {
                            // try to walk towards target.

                            // Pathing -check for obstacles and plan to go around

                            if (currentAction.NeedsUpdating == true)
                            {
                                if (currentAction.target != null)
                                {
                                    CalculateMovement(currentAction.target.Location);
                                }
                                else
                                {
                                    CalculateMovement(currentAction.destination);
                                }
                                currentAction.NeedsUpdating = false;
                            }
                            else
                            {
                                currentAction.Check();         // maybe needs updating next time...
                            }

                            if (Move() == false)
                            {
                                // stopped moving because we hit something,
                                currentAction.Accomplished = true;
                                this.currentState          = ActionState.Standing;
                                StopMoving();
                                currentAction = null;
                            }
                            else
                            {
                                // we took a step, so turn toward direction walking
                                Turn(currentAction.destination);
                            }
                        }
                        break;
                    }
                        #endregion

                        #region Case: Attack
                    case (RPGAction.ActionType.Attack):
                    {
                        // if target it dead or dying
                        if (currentAction.target == null ||
                            currentAction.target.currentState == ActionState.Dying)
                        {
                            currentAction.Accomplished = true;

                            // stop attacking
                            this.currentState = ActionState.Standing;
                        }
                        else
                        {
                            // turn toward target
                            Turn(currentAction.target.Location);

                            // try to attack - check if in range
                            int dist = new RPGCalc().DistanceBetween(this, currentAction.target);

                            if (this.inventory.GetWpn() == null && dist <= 30)
                            {
                                AttemptToEngageTarget();
                            }
                            else if (this.inventory.GetWpn() != null &&
                                     dist <= this.inventory.GetWpn().Range)
                            {
                                AttemptToEngageTarget();
                            }         // if dist ok
                            else
                            {
                                // add action to attack to front of list
                                Actions.AddFirst(currentAction);

                                // add action to walk to target to front of list. (before attack);
                                RPGAction walk = new RPGAction(RPGAction.ActionType.Walk, currentAction.target);

                                if (this.inventory.GetWpn() == null ||
                                    this.inventory.GetWpn().weaponType == RPGWeapon.WeaponType.Melee)
                                {
                                    walk.target = currentAction.target;
                                }
                                else
                                {
                                    walk.destination = new RPGCalc().PointToBeInRange(this, currentAction.target);
                                }
                                walk.UpdateFrequency = 100;         // update really often

                                Actions.AddFirst(walk);

                                // CRUCIAL: switch to walking, since target out of range.
                                currentAction = walk;
                            }
                        }
                        break;
                    }
                        #endregion

                        #region Case: Get
                    case (RPGAction.ActionType.Get):
                    {
                        // if target is gone
                        if (currentAction.target == null)
                        {
                            currentAction.Accomplished = true;

                            // stop getting
                            this.currentState = ActionState.Standing;
                        }
                        else
                        {
                            // turn toward target
                            Turn(currentAction.target.Location);

                            // try to get - check if in range
                            int dist = new RPGCalc().DistanceBetween(this, currentAction.target);

                            if (dist <= 40)         // arbitrary reach of actor
                            {
                                this.inventory.AddItem(currentAction.target);
                                Session.thisSession.thisArea.RemoveObject(currentAction.target);
                                currentAction.Accomplished = true;
                                Session.Print(this.Name + " picked up something.");
                            }         // if dist ok
                            else
                            {
                                // add get action to front of list
                                Actions.AddFirst(currentAction);

                                // add action to walk to target to front of list. (before the get);
                                RPGAction walk = new RPGAction(RPGAction.ActionType.Walk, currentAction.target);

                                walk.UpdateFrequency = 500;         // update not too often because it is a get action

                                Actions.AddFirst(walk);

                                // CRUCIAL: switch to walking, since target out of range.
                                currentAction = walk;
                            }
                        } break;
                    }

                        #endregion
                    default:
                    {
                        break;
                    }
                    } // end switch
                }     // end if currentAction
                #endregion

                #region or GetNextAction
                else
                {
                    currentAction = Actions.GetNextAction();

                    // if nothing in queue
                    if (currentAction == null)
                    {
                        // check object's AI to determine what to do next.
                    }
                }
                #endregion
            } // end if still alive
        }