Example #1
0
        public bool IsCorrectTarget(RPGObject source, RPGObject target, Point targetLocation)
        {
            if (source == null || target == null)
            {
                return(false);
            }

            bool    result = false;
            RPGCalc calc   = new RPGCalc();

            switch (range)
            {
            case (EffectRange.Self):
            {
                result = (source == target);
                break;
            }

            case (EffectRange.Target):
            {
                // target is roughly at location
                result = calc.ObjectOnPoint(target, targetLocation);
                break;
            }

            case (EffectRange.Touch):
            {
                // target within touch distance
                int d = calc.DistanceBetween(source, target);
                result = (d <= RPGCalc.DEFAULT_TOUCH_RANGE);
                break;
            }

            case (EffectRange.Area):
            {
                // target within item distance
                int d = calc.DistanceBetween(source, target);
                result = (d <= this.distance);
                break;
            }

            case (EffectRange.TargetArea):
            {
                // target within item distance and radius
                int d = calc.DistanceBetween(target, targetLocation);
                result = (d <= this.radius);
                break;
            }

            default:
            {
                break;
            }
            } // end switch
            return(result);
        }
Example #2
0
        public ArrayList GetItemsNear(Point point)
        {
            RPGCalc   calc    = new RPGCalc();
            ArrayList results = new ArrayList();

            foreach (RPGObject obj in RPGObjects)
            {
                if (obj == null)
                {
                    continue;
                }
                // if object is not actor
                if (obj.GetType() != typeof(Actor) &&
                    obj.GetType() != typeof(PlayerCharacter))
                {
                    // and if object is near point
                    if (calc.DistanceBetween(obj, point) < GRAB_MAX_DISTANCE)
                    {
                        results.Add(obj);
                    }
                }
            }

            // if nothing found...
            return(results);
        }
        public void DecideWhatToDo()
        {
            // this is if nothing is happening and the actor is just standing there...

            // assess the state of 'self' and add new actions.
            LastUpdate = System.DateTime.Now;

            #region if Is Being Attacked
            if (self.States.IsBeingAttacked)
            {
                // make sure our attacker is still alive
                if (lastAttacker == null ||
                    lastAttacker.DeleteMe == true ||
                    lastAttacker.States.IsDying)
                {
                    // or we're not being attacked anymore
                    self.States.IsBeingAttacked = false;
                }
                else
                {
                    // if not already attacking target
                    if (self.Actions.Contains(RPGAction.ActionType.Attack, self, lastAttacker) == false)
                    {
                        // make sure our AI wants us to retaliate
                        if (this.RetaliateOnAttacker)
                        {
                            self.Act(RPGObject.Action.Attack, lastAttacker.Location, lastAttacker);
                        }
                    }
                }
            }
            #endregion

            else
            {
                // go through surroundings and stimulous

                RPGObject[] objs = Session.thisSession.thisArea.GetObjects();
                foreach (RPGObject obj in objs)
                {
                    // maybe attack other actors
                    if (obj == null ||
                        !obj.isOfType(typeof(Actor)))
                    {
                        continue;
                    }

                    Actor objActor = obj as Actor;

                    // maybe attack certain alignments
                    Actor.Alignment a = objActor.GetAlignment();
                    if (!ShouldAttackAlignment(objActor))
                    {
                        continue;
                    }

                    // maybe attack if within LOS
                    RPGCalc calc = new RPGCalc();
                    int     dist = calc.DistanceBetween(self, objActor);
                    if (dist > self.LOSRange)
                    {
                        continue;
                    }

                    // we've passed all other checks, so attack
                    self.Act(RPGObject.Action.Attack, objActor.Location, obj);
                }
            }
        } // end DecideWhatToDo
        } // end DecideWhatToDo

        private bool ShouldAttackAlignment(Actor actor)
        {
            Actor.Alignment a = actor.GetAlignment();

            switch (self.GetAlignment())
            {
            // Good
            case (Actor.Alignment.Lawful_Good):
            case (Actor.Alignment.Neutral_Good):
            case (Actor.Alignment.Chaotic_Good):
            {
                // good only attacks evil
                if (a == Actor.Alignment.Lawful_Evil ||
                    a == Actor.Alignment.Neutral_Evil ||
                    a == Actor.Alignment.Chaotic_Evil)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            // Evil
            case (Actor.Alignment.Lawful_Evil):
            case (Actor.Alignment.Neutral_Evil):
            case (Actor.Alignment.Chaotic_Evil):
            {
                // evil attacks all but evil
                if (a == Actor.Alignment.Lawful_Evil ||
                    a == Actor.Alignment.Neutral_Evil ||
                    a == Actor.Alignment.Chaotic_Evil)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            // Neutral
            case (Actor.Alignment.Chaotic_Neutral):
            case (Actor.Alignment.Lawful_Neutral):
            case (Actor.Alignment.True_Neutral):
            {
                // Neutral attacks based on other things...

                // first, for now, space.

                RPGCalc calc = new RPGCalc();
                int     dist = calc.DistanceBetween(self, actor);
                if (dist <= (actor.Width * 4))         // personal space
                {
                    return(true);
                }
                // Relation to PC?
                else        //if(other issues){}else
                {
                    return(false);
                }
            }

            default:
            {
                return(false);
            }
            }
        }