public override AIState Update(Duck duck, DuckAI ai)
 {
     if (duck.holdObject != null && duck.holdObject is Gun)
     {
         return((AIState)null);
     }
     duck.ThrowItem();
     if (this._target == null)
     {
         List <Thing> list1 = Level.current.things[typeof(Gun)].Where <Thing>((Func <Thing, bool>)(x => (x as Gun).ammo > 0 && (x as Gun).owner == null)).ToList <Thing>();
         if (AI.Nearest(duck.position, list1) is Gun gun)
         {
             this._target = (Thing)gun;
             ai.SetTarget(gun.position);
         }
         else
         {
             List <Thing> list2 = Level.current.things[typeof(ItemBox)].Where <Thing>((Func <Thing, bool>)(x => !(x as ItemBox)._hit)).ToList <Thing>();
             if (!(AI.Nearest(duck.position, list2) is ItemBox itemBox))
             {
                 return((AIState) new AIStateWait(Rando.Float(0.8f, 1f)));
             }
             this._target = (Thing)itemBox;
             ai.SetTarget(itemBox.position + new Vec2(0.0f, 32f));
         }
     }
     else if (this._target is ItemBox)
     {
         if ((double)Math.Abs(this._target.x - duck.x) < 8.0)
         {
             ai.locomotion.Jump(15);
             return((AIState) new AIStateWait(Rando.Float(0.8f, 1f)));
         }
     }
     else if (this._target.owner != null && this._target.owner != duck)
     {
         this._target = (Thing)null;
     }
     else if ((double)(this._target.position - duck.position).length < 18.0)
     {
         ai.Press("GRAB");
     }
     else
     {
         ++this._refresh;
         if (this._refresh > 10 && ai.canRefresh)
         {
             this._target  = (Thing)null;
             ai.canRefresh = false;
         }
     }
     return((AIState)this);
 }
Exemple #2
0
 public override AIState Update(Duck duck, DuckAI ai)
 {
     if (this._target == null)
     {
         List <Thing> list = Level.current.things[typeof(HatConsole)].ToList <Thing>();
         if (!(AI.Nearest(duck.position, list) is HatConsole hatConsole))
         {
             return((AIState) new AIStateWait(Rando.Float(0.8f, 1f)));
         }
         this._target = (Thing)hatConsole;
         ai.SetTarget(hatConsole.position);
         return((AIState)this);
     }
     if ((double)(this._target.position - duck.position).length < 10.0 && duck.grounded)
     {
         this._wait -= 0.016f;
         if ((double)this._wait <= 0.0)
         {
             if (!this._did1 || !(this._target as HatConsole).box._hatSelector.open)
             {
                 ai.Press("SHOOT");
                 this._did1 = true;
             }
             this._wait2 -= 0.016f;
             if ((double)this._wait2 <= 0.0 && (this._target as HatConsole).box._hatSelector.open)
             {
                 if (!this._did2)
                 {
                     ai.Press("JUMP");
                     this._did2 = true;
                 }
                 this._wait3 -= 0.016f;
                 if ((double)this._wait3 <= 0.0)
                 {
                     this._wait3 = Rando.Float(0.2f);
                     if ((double)Rando.Float(1f) > 0.5)
                     {
                         if (this._moveLeft > 0)
                         {
                             ai.Press("LEFT");
                             --this._moveLeft;
                         }
                         else if (this._moveUp > 0)
                         {
                             ai.Press("UP");
                             --this._moveUp;
                         }
                     }
                     else if (this._moveUp > 0)
                     {
                         ai.Press("UP");
                         --this._moveUp;
                     }
                     else if (this._moveLeft > 0)
                     {
                         ai.Press("LEFT");
                         --this._moveLeft;
                     }
                     if (this._moveLeft == 0 && this._moveUp == 0)
                     {
                         if (!this._did3)
                         {
                             ai.Press("JUMP");
                             this._did3 = true;
                         }
                         this._wait4 -= 0.016f;
                         if ((double)this._wait4 <= 0.0)
                         {
                             ai.Press("QUACK");
                             return((AIState) new AIStateWait(Rando.Float(0.8f, 1f)));
                         }
                     }
                 }
             }
         }
     }
     return((AIState)this);
 }
Exemple #3
0
 public override AIState Update(Duck duck, DuckAI ai)
 {
     if (!(duck.holdObject is Gun holdObject))
     {
         return((AIState)null);
     }
     if (holdObject.ammo <= 0)
     {
         duck.ThrowItem();
         return((AIState) new AIStateWait(1f));
     }
     ++this._refresh;
     if (this._refresh > 10 && ai.canRefresh)
     {
         this._refresh = 0;
         this._target  = (Duck)null;
         ai.canRefresh = false;
     }
     if (this._target == null)
     {
         List <Thing> list = Level.current.things[typeof(Duck)].Where <Thing>((Func <Thing, bool>)(x => x != duck && !(x as Duck).dead)).ToList <Thing>();
         if (!(AI.Nearest(duck.position, list) is Duck duck1))
         {
             return((AIState) new AIStateWait(Rando.Float(0.8f, 1f)));
         }
         this._target = duck1;
         ai.SetTarget(duck1.position);
     }
     else
     {
         if ((double)(duck.position - this._target.position).length < 10.0)
         {
             this._scatterWait -= 0.01f;
             if ((double)this._scatterWait < 0.0)
             {
                 List <Thing> list = Level.current.things[typeof(PathNode)].ToList <Thing>();
                 ai.SetTarget(list[Rando.Int(list.Count - 1)].position);
                 this._state.Push((AIState) new AIStateWait(1f + Rando.Float(1f)));
                 this._scatterWait = 1f;
             }
         }
         if ((double)Math.Abs(duck.y - this._target.y) < 16.0 && (double)Math.Abs(duck.x - this._target.x) < 150.0 && Level.CheckRay <Duck>(duck.position + new Vec2((float)((int)duck.offDir * 10), 0.0f), this._target.position) == this._target)
         {
             if (Level.CheckLine <Block>(duck.position, this._target.position) == null)
             {
                 this._targetWait -= 0.2f;
                 if ((double)this._targetWait <= 0.0 && (double)Rando.Float(1f) > 0.600000023841858)
                 {
                     ai.Press("SHOOT");
                     this._state.Push((AIState) new AIStateWait(Rando.Float(0.2f, 0.3f)));
                     return((AIState)this);
                 }
             }
         }
         else
         {
             this._targetWait = 1f;
         }
     }
     return((AIState)this);
 }