public virtual void OnEnable()
    {
        if (!enemyObject)
        {
            enemyObject = this.gameObject;
        }
        if (this.IsDead)
        {
            this.IsDead = false;
        }

        if (enemyObject)
        {
            this.Sight      = this.GetComponentInChildren <CEnemySight>();
            enemyController = enemyObject.GetComponent <IController>();
            enemyAI         = enemyObject.GetComponent <IBasicAI>();
            if (this.GetComponent <SpriteRenderer>())
            {
                this.SetSpriteOrigin();
            }
            enemyAI.LivingEntity             = this;
            enemyAI.Speed                    = this.fSpeed;
            enemyController.AtkEvent        += this.AttackObject;
            enemyController.MoveEvent       += this.MoveForwardObject;
            enemyController.TurnEvent       += this.TurnObject;
            enemyController.RandomMoveEvent += this.MoveForwardObject;
            enemyAI.FacingRight              = false;
            enemyAI.EnemySight               = this.Sight;
            animator = this.GetComponent <Animator>();
        }

        this.fCurrentHealth = fMaxHealth;
        this.IsDamaged      = false;
    }
Beispiel #2
0
        /// <summary>
        /// Main Constructor
        /// </summary>
        /// <param name="_self">Reference to the host</param>
        public MatronMind(IBasicAI _self) : base(_self)
        {
            mStates.Add("idle", new Idle(this));
            mStates.Add("persue", new Persue(this));

            mCurrentState = mStates["idle"];
        }
 //ADD : float AttackRange
 public AttackTargetTask(IBasicAI AI, ControllEventInt eventAttack, int nRange, float fRange)
 {
     myAI         = AI;
     attackEvent  = eventAttack;
     nDiceRange   = nRange;
     fAttackRange = fRange;
 }
Beispiel #4
0
        /// <summary>
        /// 数据到达事件处理函数
        /// 1.将数据传到dataWriter中为写文件做准备
        /// 2.更新最新数据latestData
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataArrivalHandler(object sender, DataArrivalEventArgs e)
        {
            //sender其实就是ai
            IBasicAI thisAI = (IBasicAI)sender;

            double[,] newData = e.NewData;
            //只有AutoWriteDataToFile == true,才存文件
            if (thisAI.StaticConfig.AutoWriteDataToFile)
            {
                //传数据到dataWriter
                dataWriter.AcceptNewData(newData);
            }

            //更新最新数据latestData
            int latestdataIndex;

            //如果数据格式为“data[通道个数][每通道数据个数]”则不需要转置;
            //如果数据格式为“data[每通道数据个数][通道个数]”则需要转置
            if (basicAI.DataNeedTransposeWhenSaving)
            {
                latestdataIndex = newData.GetUpperBound(0);
                for (int i = 0; i < ChannelCount(-1); i++)
                {
                    latestData[i] = newData[latestdataIndex, i];
                }
            }
            else
            {
                latestdataIndex = newData.GetUpperBound(1);
                for (int i = 0; i < ChannelCount(-1); i++)
                {
                    latestData[i] = newData[i, latestdataIndex];
                }
            }
        }
Beispiel #5
0
                                   { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } };                     // 5
        /// <summary>
        /// Main Constructor
        /// Creates Behaviour States
        /// </summary>
        /// <param name="_self">Reference to the Host Body</param>
        public DoctorMind(IBasicAI _self) : base(_self)
        {
            mStates.Add("idle", new Idle(this));
            mStates.Add("walk", new Walk(this));

            mCurrentState = mStates["idle"];
            SetMap(_Map);
        }
Beispiel #6
0
        /// <summary>
        /// Main Constructor
        /// </summary>
        /// <param name="_self">Reference to himself</param>
        public OldManMind(IBasicAI _self) : base(_self)
        {
            mStates.Add("idle", new Idle(this));
            mStates.Add("talk", new Talk(this));
            mStates.Add("yeet", new Yeet(this));
            mStates.Add("run", new Run(this));

            mCurrentState = mStates["idle"];
        }
 public virtual void OnDisable()
 {
     this.ReturnToOriginAtk();
     this.ReturnToOriginSpeed();
     enemyController          = null;
     enemyAI                  = null;
     this.Sight.IsAttackRange = false;
     this.Sight               = null;
     this.bIsBuff             = false;
 }
Beispiel #8
0
        /// <summary>
        /// AI任务状态变化事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StatusChangedHandler(object sender, EventArgs e)
        {
            //sender其实就是ai
            IBasicAI thisAI = (IBasicAI)sender;

            switch (thisAI.AIState)
            {
            case Status.Idle:
                //自动删除多余数据
                try
                {
                    ShotDirOperator.DeleteRedundantDataDirectories(
                        DataFileParentDirectory, basicAI.StaticConfig.RemainShotsMax - basicAI.StaticConfig.RemainShotsMin, basicAI.StaticConfig.RemainShotsMin);
                }
                catch (Exception)
                {
                    //删不掉就不删
                }
                AIState = Status.Idle;
                break;

            case Status.Ready:
                //只有AutoWriteDataToFile == true,才创建下一个文件夹
                if (thisAI.StaticConfig.AutoWriteDataToFile)
                {
                    //创建下一个文件夹
                    CurrentFileDirectiory = ShotDirOperator.CreateNextDirectory(DataFileParentDirectory);
                    //new DataWriter,缓存当前炮数据及将数据写入文件
                    string dataDirectory = CurrentFileDirectiory + @"\";
                    dataWriter        = DataFileFactory.GetWriter(dataDirectory, dataFileName, ChannelCount(-1), SampleRate(-1), basicAI.DataNeedTransposeWhenSaving, basicAI.StaticConfig.StartTime);
                    FullDataFilePaths = dataWriter.FullPathOfAllDataFiles();
                }
                AIState = Status.Ready;
                break;

            case Status.Running:
                AIState = Status.Running;
                break;

            case Status.Error:
                thisAI.TryStopTask();
                AIState = Status.Error;
                break;

            default:
                break;
            }
        }
Beispiel #9
0
    public IEnumerator PunchMove(IBasicAI enemyAI, int patternIndex)
    {
        float fTime = 0f;

        bIsRocketPunch = true;
        while (fTime < 1f)
        {
            fTime += Time.deltaTime * 0.3f;
            this.transform.position = Vector3.Lerp(this.transform.position, new Vector3(punchMaxX, myArm.transform.position.y, this.transform.position.z), fTime);
            yield return(new WaitForEndOfFrame());
        }

        bIsRocketPunch = false;
        this.RockectReturn(enemyAI, patternIndex);
        yield break;
    }
Beispiel #10
0
        /// <summary>
        /// AI任务结束
        /// 保存时间文件及配置文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AIStopHandler(object sender, EventArgs e)
        {
            //sender其实就是ai
            IBasicAI thisAI = (IBasicAI)sender;

            System.Diagnostics.Debug.WriteLine("AIThing stop! Thread no: " + Thread.CurrentThread.ManagedThreadId.ToString() + " " + Path);

            //只有AutoWriteDataToFile == true,才写文件
            if (thisAI.StaticConfig.AutoWriteDataToFile)
            {
                //不再读数据,把数据文件写完
                dataWriter.FinishWrite();
            }

            //停止任务
            TryStop();

            //产生AITaskFinished事件
            MyHub.EventHub.Publish(Path, "AITaskFinished", "AITaskFinished");
        }
Beispiel #11
0
    public IEnumerator PunchReturn(Vector3 endPos, IBasicAI enemyAI, int patternIndex)
    {
        float fTime = 0f;

        while (fTime < 1f)
        {
            fTime += Time.deltaTime * 1.5f;
            this.transform.localPosition = Vector3.Lerp(this.transform.localPosition, endPos, fTime);
            yield return(new WaitForEndOfFrame());
        }

        this.transform.localPosition = new Vector3(this.transform.localPosition.x, -0.2f, this.transform.localPosition.z);
        fTime = 0f;

        enemyAI.AttackEnd();
        enemyAI.IdleTimeChk(enemyAI.fIdleTime);
        enemyAI.LivingEntity.gameObject.SendMessage("PatternCoolDownSetting", patternIndex);
        myArm.ArmAttackEnd();

        bIsRocketPunch = false;
        yield break;
    }
Beispiel #12
0
 public IsDamagedCondition(IBasicAI AI)
 {
     myAI = AI;
 }
Beispiel #13
0
 public IsTargetCondition(IBasicAI AI)
 {
     myAI = AI;
 }
Beispiel #14
0
 public RandomMoveTask(ControllEventVector3 moveEvent, IBasicAI AI)
 {
     currentDir      = Vector3.zero;
     myAI            = AI;
     randomMoveEvent = moveEvent;
 }
 public CoolDownChkCondition(IBasicAI AI)
 {
     myAI = AI;
 }
Beispiel #16
0
 public HoldIsBuffEnemyCondition(CBuffEnemyController controller, IBasicAI AI)
 {
     buffEnemyController = controller;
     myAI = AI;
 }
 public FindTargetTask(IBasicAI AI, ControllEvent eventTurn)
 {
     myAI      = AI;
     turnEvent = eventTurn;
 }
Beispiel #18
0
 public EnemyAttackTask(IBasicAI AI, int nAtkDiceRange, ControllEventInt eventAttack)
 {
     myAI        = AI;
     nDiceRange  = nAtkDiceRange;
     attackEvent = eventAttack;
 }
Beispiel #19
0
 public DecideAttackTask(IBasicAI AI)
 {
     myAI = AI;
 }
 public HoldBuffChkCondition(IBasicAI AI, CBuffEnemyController controller)
 {
     myAI = AI;
     buffEnemyController = controller;
 }
 public BuffIdleChkCondition(IBasicAI AI)
 {
     myAI = AI;
 }
Beispiel #22
0
 public PatrolMoveTask(IBasicAI AI, ControllEvent eventMove)
 {
     myAI      = AI;
     moveEvent = eventMove;
 }
Beispiel #23
0
 public IsPatrolCondition(IBasicAI AI)
 {
     myAI = AI;
 }
 public ChangeDirectionTask(IBasicAI AI, ControllEvent eventTurn)
 {
     myAI      = AI;
     turnEvent = eventTurn;
 }
Beispiel #25
0
 /// <summary>
 /// Main Constructor
 /// </summary>
 /// <param name="_self">Reference to AI Body</param>
 public AIMind(IBasicAI _self)
 {
     mStates     = new Dictionary <string, IState>();
     mSelf       = _self;
     mPathfinder = new Pathfinder(Global.ScreenWidth, Global.ScreenHeight, mMap);
 }
 public MoveToTargetTask(IBasicAI AI, ControllEvent eventMove, float fRange)
 {
     myAI         = AI;
     moveEvent    = eventMove;
     fAttackRange = fRange;
 }
Beispiel #27
0
 public void RocketPunch(IBasicAI enemyAI, int patternIndex)
 {
     StartCoroutine(PunchMove(enemyAI, patternIndex));
 }
Beispiel #28
0
 public void RockectReturn(IBasicAI enemyAI, int patternIndex)
 {
     StartCoroutine(PunchReturn(new Vector3(basePosition.x, basePosition.y, basePosition.z), enemyAI, patternIndex));
 }
 public IsAttackCondition(IBasicAI AI)
 {
     myAI = AI;
 }
 public MoveChkTask(IBasicAI AI, float fMoveEndTime)
 {
     myAI     = AI;
     fEndTime = fMoveEndTime;
 }