home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / kung_fu.swf / scripts / __Packages / com / KidFighting / AiController.as next >
Encoding:
Text File  |  2006-06-13  |  5.4 KB  |  201 lines

  1. class com.KidFighting.AiController
  2. {
  3.    var _timer;
  4.    var _owner;
  5.    var skillKeyList;
  6.    var dispatchEvent;
  7.    static var _evt = mx.events.EventDispatcher.initialize(com.KidFighting.AiController.prototype);
  8.    static var motionList = ["jump","down","move","nothing"];
  9.    static var directionList = ["right","left"];
  10.    function AiController()
  11.    {
  12.       this._timer = new ds.controls.Timer();
  13.       this._timer.interval = 33;
  14.       this._timer.func = mx.utils.Delegate.create(this,this.update);
  15.    }
  16.    function get owner()
  17.    {
  18.       return this._owner;
  19.    }
  20.    function set owner(ow)
  21.    {
  22.       this._owner = ow;
  23.       this.skillKeyList = [];
  24.       for(var _loc2_ in this._owner.m_skillList)
  25.       {
  26.          if(this._owner.m_skillList[_loc2_].name != "Throw")
  27.          {
  28.             this.skillKeyList.push(_loc2_);
  29.          }
  30.       }
  31.       this.skillKeyList.push("");
  32.       this.skillKeyList.push("");
  33.    }
  34.    function getDistance()
  35.    {
  36.       return Math.abs(this.owner.ani._x - this.owner.opponent.ani._x);
  37.    }
  38.    function getFlyItemSkill()
  39.    {
  40.       for(var _loc2_ in this.owner.skillList)
  41.       {
  42.          if(this.owner.skillList[_loc2_].type == "flyItem")
  43.          {
  44.             return this.owner.skillList[_loc2_];
  45.          }
  46.       }
  47.       return null;
  48.    }
  49.    function update()
  50.    {
  51.       var _loc8_ = com.KidFighting.AiController;
  52.       var _loc10_ = "nothing";
  53.       var _loc13_ = undefined;
  54.       var _loc3_ = false;
  55.       if(random(3) == 1 && this.getDistance() > 80)
  56.       {
  57.          var _loc2_ = this.getFlyItemSkill();
  58.          if(_loc2_ != null)
  59.          {
  60.             _loc10_ = "skill";
  61.             var _loc7_ = _loc2_.keys;
  62.             _loc3_ = true;
  63.          }
  64.       }
  65.       else if(this.getDistance() > 80)
  66.       {
  67.          _loc10_ = "move";
  68.          if(random(2) == 1)
  69.          {
  70.             _loc13_ = this.owner.side != 1 ? "left" : "right";
  71.          }
  72.          else if(random(4) == 1)
  73.          {
  74.             _loc10_ = "jump";
  75.             _loc13_ = this.owner.side != 1 ? "left" : "right";
  76.          }
  77.          else if(random(5) == 1)
  78.          {
  79.             _loc10_ = "skill";
  80.          }
  81.       }
  82.       else if(random(2) == 1)
  83.       {
  84.          _loc10_ = "skill";
  85.       }
  86.       else if(random(7) == 1)
  87.       {
  88.          _loc10_ = "down";
  89.       }
  90.       else if(random(5) == 1)
  91.       {
  92.          _loc10_ = "jump";
  93.          _loc13_ = com.KidFighting.AiController.directionList[random(com.KidFighting.AiController.directionList.length)];
  94.       }
  95.       else
  96.       {
  97.          _loc10_ = "move";
  98.          _loc13_ = com.KidFighting.AiController.directionList[random(com.KidFighting.AiController.directionList.length)];
  99.       }
  100.       if(this.owner.uniqueId > 7 && !_loc3_)
  101.       {
  102.          var _loc4_ = this.owner.opponent.status;
  103.          var _loc6_ = undefined;
  104.          var _loc5_ = undefined;
  105.          switch(_loc4_)
  106.          {
  107.             case "block":
  108.                if(this.getDistance() < 45)
  109.                {
  110.                   _loc6_ = true;
  111.                   _loc5_ = true;
  112.                }
  113.                break;
  114.             case "skill":
  115.                if(random(2) == 1)
  116.                {
  117.                   _loc10_ = "jump";
  118.                   _loc13_ = this.owner.side != 1 ? "left" : "right";
  119.                }
  120.                else
  121.                {
  122.                   _loc10_ = "skill";
  123.                }
  124.                if(this.getDistance() < 60)
  125.                {
  126.                   _loc10_ = "move";
  127.                   _loc13_ = this.owner.side != 1 ? "right" : "left";
  128.                }
  129.                break;
  130.             case "normal":
  131.             case "left":
  132.             case "right":
  133.                if(this.getDistance() > 50)
  134.                {
  135.                   _loc10_ = "move";
  136.                   _loc13_ = this.owner.side != 1 ? "left" : "right";
  137.                }
  138.                else if(random(2) == 1)
  139.                {
  140.                   _loc10_ = "skill";
  141.                }
  142.          }
  143.       }
  144.       if(this.owner.isInvincible || this.owner.direction == "up" || this.owner.status == "hurt" || this.owner.status == "cought")
  145.       {
  146.          return undefined;
  147.       }
  148.       if(_loc10_ == "skill")
  149.       {
  150.          if(_loc7_ == undefined)
  151.          {
  152.             _loc7_ = this.skillKeyList[random(this.skillKeyList.length)];
  153.          }
  154.          if(_loc6_ == undefined)
  155.          {
  156.             _loc6_ = Boolean(random(2));
  157.          }
  158.          if(_loc5_ == undefined)
  159.          {
  160.             _loc5_ = Boolean(random(2));
  161.          }
  162.          this.dispatchEvent({activer:this.owner,type:"updateInput",motion:"skill",skillKeys:_loc7_,isPunch:_loc6_,isKick:_loc5_});
  163.       }
  164.       else
  165.       {
  166.          this.dispatchEvent({activer:this.owner,type:"updateInput",motion:_loc10_,direction:_loc13_});
  167.       }
  168.       if(this.owner.uniqueId > 7)
  169.       {
  170.          if(this.owner.status != "skill" && this.owner.status != "kick" && this.owner.status != "punch" && this.owner.direction != "up")
  171.          {
  172.             this.owner.direction = this.owner.side != -1 ? "left" : "right";
  173.          }
  174.       }
  175.    }
  176.    function start()
  177.    {
  178.       this._timer.start();
  179.    }
  180.    function stop()
  181.    {
  182.       this._timer.stop();
  183.    }
  184.    function onPauseGame()
  185.    {
  186.       this.stop();
  187.    }
  188.    function onResumeGame()
  189.    {
  190.       this.start();
  191.    }
  192.    function onFightStart()
  193.    {
  194.       this.start();
  195.    }
  196.    function onFightEnd()
  197.    {
  198.       this.stop();
  199.    }
  200. }
  201.