예제 #1
0
        private void doPunch()
        {
            FightObject f = punchTarget;

            if (punchTarget == null)
            {
                List <FightObject> fs = getObjectInRange();
                if (fs == null)
                {
                    swinging = false;
                    return;
                }
                f = fs[0];
            }
            f.punch(maxPunchDamage);
            swinging    = false;
            punchTarget = null;
            //Next, there are cases where there is quick punch and grab in succession.
            //So we block grabs for x amount of seconds after a punch.
            if (isAI)
            {
                lastGrabTime = DateTime.Now;
                stopGrabTime = 2;
            }
        }
예제 #2
0
 private void seek()
 {
     if (!seeking)
     {
         return;
     }
     if ((DateTime.Now - startSeekTime).TotalMilliseconds < 600)
     {
         return;
     }
     if (pathIndex == path.Count)
     {
         if (target != null && !(target is Furniture))
         {
             move(seek(target), false);
         }
     }
     else
     {
         MovementDirection m = seek(path[pathIndex]);
         if (m != MovementDirection.none)
         {
             move(m, false);
         }
         else
         {
             pathIndex++;
         }
     }
     if ((target != null && !(target is Furniture) && isInRange(target)) || pathIndex == path.Count)
     {
         seeking = false;
         target  = null;
     }
 }
예제 #3
0
        private void seekRandomFurniture()
        {
            FightObject f = null;

            do
            {
                f = things[Common.getRandom(0, things.Count - 1)];
            } while (!(f is Furniture));
            startSeeking(f);
        }
예제 #4
0
 /// <summary>
 /// Starts seeking the specified coordinates. The AI will travel to the node nearest these coordinates but may not end up on these coordinates exactly.
 /// </summary>
 /// <param name="x">The x coordinate to seek.</param>
 /// <param name="y">The y coordinate to seek.</param>
 public void startSeeking(int x, int y)
 {
     if (!seeking)
     {
         seeking       = true;
         target        = null;
         seekX         = x;
         seekY         = y;
         path          = MapNode.getCachedPathTo(new Vector2(this.x, this.y), new Vector2(x, y));
         startSeekTime = DateTime.Now;
         pathIndex     = 0;
     }
 }
예제 #5
0
 /// <summary>
 /// Starts seeking the FightObject.
 /// </summary>
 /// <param name="target">The target to seek.</param>
 public void startSeeking(FightObject target)
 {
     if (!seeking)
     {
         seeking       = true;
         startSeekTime = DateTime.Now;
         path          = MapNode.getCachedPathTo(new Vector2(x, y), (target is Furniture) ? ((Furniture)target).getClosestCorner(x, y) : new Vector2(target.x, target.y));
         pathIndex     = 0;
         this.target   = target;
         seekX         = target.x;
         seekY         = target.y;
     }
 }
예제 #6
0
 /// <summary>
 /// Makes this person punch someone.
 /// </summary>
 /// <param name="f">The object to punch or null to select one.</param>
 /// <param name="max">The max damage.</param>
 public void punchSomeone(FightObject f, int max)
 {
     if (swinging || grabTarget != null)
     {
         return;
     }
     if (isAI && (DateTime.Now - lastPunchTime).TotalSeconds < stopPunchTime)
     {
         return;
     }
     lastPunchTime = DateTime.Now;
     stopPunchTime = Common.getRandom(1, 3);
     playSound(swingSound[Common.getRandom(0, 1)], true, false);
     playSound(swingVoice[Common.getRandom(0, swingVoice.Length - 1)], true, false);
     startSwingTime = DateTime.Now;
     maxPunchDamage = max;
     swinging       = true;
     punchTarget    = f;
 }
예제 #7
0
 /// <summary>
 /// Seeks the FightObject
 /// </summary>
 /// <param name="f">The object to seek.</param>
 protected Person.MovementDirection seek(FightObject f)
 {
     if (distanceBetween(f) <= 1)
     {
         return(Person.MovementDirection.none);
     }
     if (f.x > x && !isBlockedByObject(x + 1, y))
     {
         return(Person.MovementDirection.east);
     }
     else if (f.x < x && !isBlockedByObject(x - 1, y))
     {
         return(Person.MovementDirection.west);
     }
     else if (f.y > y && !isBlockedByObject(x, y + 1))
     {
         return(Person.MovementDirection.north);
     }
     else if (f.y < y && !isBlockedByObject(x, y - 1))
     {
         return(Person.MovementDirection.south);
     }
     return(Person.MovementDirection.none);
 }
예제 #8
0
 /// <summary>
 /// Gets the distance between this object and another object.
 /// </summary>
 /// <param name="f">The other object</param>
 /// <returns>The distance</returns>
 public double distanceBetween(FightObject f)
 {
     return(Degrees.getDistanceBetween(x, y, f.x, f.y));
 }
예제 #9
0
 /// <summary>
 /// True if o is within range of this object, false otherwise.
 /// </summary>
 /// <param name="o">The object to measure by</param>
 /// <returns>True if in range, false otherwise</returns>
 public bool isInRange(FightObject o)
 {
     return(distanceBetween(o) <= 1);
 }