home *** CD-ROM | disk | FTP | other *** search
- class com.KidFighting.AiController
- {
- var _timer;
- var _owner;
- var skillKeyList;
- var dispatchEvent;
- static var _evt = mx.events.EventDispatcher.initialize(com.KidFighting.AiController.prototype);
- static var motionList = ["jump","down","move","nothing"];
- static var directionList = ["right","left"];
- function AiController()
- {
- this._timer = new ds.controls.Timer();
- this._timer.interval = 33;
- this._timer.func = mx.utils.Delegate.create(this,this.update);
- }
- function get owner()
- {
- return this._owner;
- }
- function set owner(ow)
- {
- this._owner = ow;
- this.skillKeyList = [];
- for(var _loc2_ in this._owner.m_skillList)
- {
- if(this._owner.m_skillList[_loc2_].name != "Throw")
- {
- this.skillKeyList.push(_loc2_);
- }
- }
- this.skillKeyList.push("");
- this.skillKeyList.push("");
- }
- function getDistance()
- {
- return Math.abs(this.owner.ani._x - this.owner.opponent.ani._x);
- }
- function getFlyItemSkill()
- {
- for(var _loc2_ in this.owner.skillList)
- {
- if(this.owner.skillList[_loc2_].type == "flyItem")
- {
- return this.owner.skillList[_loc2_];
- }
- }
- return null;
- }
- function update()
- {
- var _loc8_ = com.KidFighting.AiController;
- var _loc10_ = "nothing";
- var _loc13_ = undefined;
- var _loc3_ = false;
- if(random(3) == 1 && this.getDistance() > 80)
- {
- var _loc2_ = this.getFlyItemSkill();
- if(_loc2_ != null)
- {
- _loc10_ = "skill";
- var _loc7_ = _loc2_.keys;
- _loc3_ = true;
- }
- }
- else if(this.getDistance() > 80)
- {
- _loc10_ = "move";
- if(random(2) == 1)
- {
- _loc13_ = this.owner.side != 1 ? "left" : "right";
- }
- else if(random(4) == 1)
- {
- _loc10_ = "jump";
- _loc13_ = this.owner.side != 1 ? "left" : "right";
- }
- else if(random(5) == 1)
- {
- _loc10_ = "skill";
- }
- }
- else if(random(2) == 1)
- {
- _loc10_ = "skill";
- }
- else if(random(7) == 1)
- {
- _loc10_ = "down";
- }
- else if(random(5) == 1)
- {
- _loc10_ = "jump";
- _loc13_ = com.KidFighting.AiController.directionList[random(com.KidFighting.AiController.directionList.length)];
- }
- else
- {
- _loc10_ = "move";
- _loc13_ = com.KidFighting.AiController.directionList[random(com.KidFighting.AiController.directionList.length)];
- }
- if(this.owner.uniqueId > 7 && !_loc3_)
- {
- var _loc4_ = this.owner.opponent.status;
- var _loc6_ = undefined;
- var _loc5_ = undefined;
- switch(_loc4_)
- {
- case "block":
- if(this.getDistance() < 45)
- {
- _loc6_ = true;
- _loc5_ = true;
- }
- break;
- case "skill":
- if(random(2) == 1)
- {
- _loc10_ = "jump";
- _loc13_ = this.owner.side != 1 ? "left" : "right";
- }
- else
- {
- _loc10_ = "skill";
- }
- if(this.getDistance() < 60)
- {
- _loc10_ = "move";
- _loc13_ = this.owner.side != 1 ? "right" : "left";
- }
- break;
- case "normal":
- case "left":
- case "right":
- if(this.getDistance() > 50)
- {
- _loc10_ = "move";
- _loc13_ = this.owner.side != 1 ? "left" : "right";
- }
- else if(random(2) == 1)
- {
- _loc10_ = "skill";
- }
- }
- }
- if(this.owner.isInvincible || this.owner.direction == "up" || this.owner.status == "hurt" || this.owner.status == "cought")
- {
- return undefined;
- }
- if(_loc10_ == "skill")
- {
- if(_loc7_ == undefined)
- {
- _loc7_ = this.skillKeyList[random(this.skillKeyList.length)];
- }
- if(_loc6_ == undefined)
- {
- _loc6_ = Boolean(random(2));
- }
- if(_loc5_ == undefined)
- {
- _loc5_ = Boolean(random(2));
- }
- this.dispatchEvent({activer:this.owner,type:"updateInput",motion:"skill",skillKeys:_loc7_,isPunch:_loc6_,isKick:_loc5_});
- }
- else
- {
- this.dispatchEvent({activer:this.owner,type:"updateInput",motion:_loc10_,direction:_loc13_});
- }
- if(this.owner.uniqueId > 7)
- {
- if(this.owner.status != "skill" && this.owner.status != "kick" && this.owner.status != "punch" && this.owner.direction != "up")
- {
- this.owner.direction = this.owner.side != -1 ? "left" : "right";
- }
- }
- }
- function start()
- {
- this._timer.start();
- }
- function stop()
- {
- this._timer.stop();
- }
- function onPauseGame()
- {
- this.stop();
- }
- function onResumeGame()
- {
- this.start();
- }
- function onFightStart()
- {
- this.start();
- }
- function onFightEnd()
- {
- this.stop();
- }
- }
-