Пример #1
0
 public override void Init(AIMemory aiMemory, BaseAIRoutine aiRoutine)
 {
     this.aiMemory              = aiMemory ?? new AIMemory();
     this.aiRoutine             = aiRoutine ?? new SimpleAIRoutine();
     this.lastTick              = DateTime.Now;
     this.guideCommandByVobInst = new Dictionary <VobInst, GuideCommandInfo>();
 }
Пример #2
0
    public override void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
    {
        base.Result = base.Inverted;
        IAIAttack iAIAttack = base.Owner as IAIAttack;

        if (iAIAttack == null)
        {
            return;
        }
        BaseEntity bestTarget = iAIAttack.GetBestTarget();

        if (base.Inverted)
        {
            if (bestTarget == null && base.ShouldSetOutputEntityMemory)
            {
                memory.Entity.Remove(base.OutputEntityMemorySlot);
            }
            base.Result = bestTarget == null;
        }
        else
        {
            if (bestTarget != null && base.ShouldSetOutputEntityMemory)
            {
                memory.Entity.Set(bestTarget, base.OutputEntityMemorySlot);
            }
            base.Result = bestTarget != null;
        }
    }
Пример #3
0
    public AIBrain(
        List <AISensor> _sensors,
        List <AISystem> _systems,
        List <AIAction> _actions,
        List <AIGoal> _goals,
        List <State> _states,
        List <AIStateSystem> _allStateSystems,
        AIBrainProps _brainProps,
        Transform _transform,
        AIMemory _memory,
        ref GlobalEvents.OnDeadHandler _onDead
        )
    {
        allSensors      = _sensors;
        allSystems      = _systems;
        allActions      = _actions;
        AllGoals        = _goals;
        allStates       = _states;
        allStateSystems = _allStateSystems;

        brain     = _brainProps;
        Memory    = _memory;
        Transform = _transform;
        Animator  = _transform.GetComponent <Animator>();
        Agent     = _transform.GetComponent <NavMeshAgent>();

        onDead         = _onDead;
        _onDead       += OnDead;
        pollingSensors = allSensors.OfType <AISensorPolling>().ToList();
    }
 public TransitionClaculator(AIMemory aiMem, IJumpRequest aiLocalSolver)
 {
     this.aiMem         = aiMem;
     this.aiLocalSolver = aiLocalSolver;
     leftToRight        = TransitionType.NONE;
     rightToLeft        = TransitionType.NONE;
     InitialisePatterns();
 }
Пример #5
0
 void Start()
 {
     aiMem = new AIMemory(WindowX, WindowY, transform.position, new EnvironmentAnalyser(), this, 3.1f);
     Camera.main.GetComponent <DebugGraph>().AiMapGraph = aiMem;
     aiMem.UpdateMemory(transform.position);
     lastWinX = WindowX;
     lastWinY = WindowY;
 }
    private void OnMessageReceived(object sender, InformationEventArgs eArgs)
    {
        AIMemory memSender = (AIMemory)sender;

        foreach (var message in eArgs.Messages)
        {
            message.DispatchTo(messageHandlers, memSender);
        }
    }
        protected void DynamicDispatch(IHandlerP handler, MessageType mS, AIMemory memSender)
        {
            IMessageHandler <MessageType> matchingHandler = handler as IMessageHandler <MessageType>;

            if (matchingHandler != null)
            {
                matchingHandler.ProcessMessage(mS, memSender);
            }
        }
        public void DispatchTo(IHandlerP handler, AIMemory memSender)
        {
            MessageType messageAsType = this as MessageType;

            if (messageAsType != null)
            {
                DynamicDispatch(handler, messageAsType, memSender);
            }
        }
Пример #9
0
        public void ProcessMessage(AIMessageSuspicionLost message, AIMemory memSender)
        {
            var susps = memory.Items.OfType <InformationSuspicion>().Where(x => x.BaseTransform != null && x.BaseTransform == message.lostTarget).ToList().OrderByDescending(x => x.UpdateTime).ToList();

            if (susps.Count > 0)
            {
                memory.BroadcastToListeners(new AIMessageSuspicionPosition(message.lostTarget, susps[0].lastKnownPosition.Value, susps[0].UpdateTime));
            }
        }
Пример #10
0
    public override void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
    {
        BaseEntity baseEntity = memory.Entity.Get(base.InputEntityMemorySlot);

        base.Result = false;
        if (!(baseEntity == null))
        {
            bool flag = Vector3Ex.Distance2D(base.Owner.transform.position, baseEntity.transform.position) <= Range;
            base.Result = (base.Inverted ? (!flag) : flag);
        }
    }
Пример #11
0
        public void ProcessMessage(AIMessageTargetDead message, AIMemory memSender)
        {
            var memInfo      = memory.GetSuspicionWithBaseTransform <InformationAlive>(message.deadTarget);
            var relatedInfos = memory.Items.OfType <InformationSuspicion>().Where(x => x != memInfo).ToList();

            memory.Remove(relatedInfos);
            if (memInfo != null)
            {
                memInfo.IsDead = true;
            }
        }
Пример #12
0
    public override void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
    {
        base.Result = false;
        BaseEntity baseEntity = memory.Entity.Get(base.InputEntityMemorySlot);

        if (!(baseEntity == null) && base.Owner is IAIAttack)
        {
            bool flag = senses.Memory.IsLOS(baseEntity);
            base.Result = (base.Inverted ? (!flag) : flag);
        }
    }
Пример #13
0
 public override void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
 {
     base.Result = base.Inverted;
     if (base.Inverted)
     {
         base.Result = senses.TimeInAgressiveState < Value;
     }
     else
     {
         base.Result = senses.TimeInAgressiveState >= Value;
     }
 }
Пример #14
0
        public void ProcessMessage(AIMessageSuspicionPosition message, AIMemory memSender)
        {
            var susps = memory.Items.OfType <InformationSuspicion>().Where(x => x.BaseTransform != null && x.BaseTransform == message.FoundTransform).ToList();

            foreach (var susp in susps)
            {
                if (message.FoundTime > susp.UpdateTime)
                {
                    susp.Update(message.FoundPos, susp.lastKnownPosition.Confidence);
                }
            }
        }
Пример #15
0
    public override void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
    {
        base.Result = base.Inverted;
        IAIAttack iAIAttack = base.Owner as IAIAttack;

        if (iAIAttack != null)
        {
            BaseEntity baseEntity = memory.Entity.Get(base.InputEntityMemorySlot);
            iAIAttack.AttackTick(deltaTime, baseEntity, senses.Memory.IsLOS(baseEntity));
            base.Result = !base.Inverted;
        }
    }
Пример #16
0
    public override void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
    {
        base.Result = base.Inverted;
        bool flag = Random.Range(0f, 1f) <= Chance;

        if (base.Inverted)
        {
            base.Result = !flag;
        }
        else
        {
            base.Result = flag;
        }
    }
Пример #17
0
    public override void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
    {
        base.Result  = base.Inverted;
        combatEntity = memory.Entity.Get(base.InputEntityMemorySlot) as BaseCombatEntity;
        float num = lastExecuteTime;

        lastExecuteTime = Time.time;
        if (!(combatEntity == null) && combatEntity.lastAttackedTime >= num && !(combatEntity.lastAttacker == null) && !(combatEntity.lastAttacker == combatEntity))
        {
            if (base.ShouldSetOutputEntityMemory)
            {
                memory.Entity.Set(combatEntity.lastAttacker, base.OutputEntityMemorySlot);
            }
            base.Result = !base.Inverted;
        }
    }
Пример #18
0
    // Use this for initialization
    void Start()
    {
        SetPlayer2StartPosition();
        x          = player2.transform.position.x - 0.1f;
        y          = 2f;
        projectile = Instantiate(projectilePrefab);
        projectile.gameObject.SetActive(false);
        compAttack = player2.GetComponent <CalculationPlayerAttack>();
        compAttack.TakeTurn(projectile);
        compAttack.AnimalPosition = new Vector3(x, y, 0);
        compAttack.CreateCow();
        compAttack.CanShoot = true;

        memory         = new AIMemory();
        Time.timeScale = 100f;
    }
Пример #19
0
    public void SetupAI(AISettings settings)
    {
        aiEnabled            = false;
        this.maxLP           = settings.MaxLP;
        this.minimumDistance = settings.MinDistance;
        GetComponent <AIWeaponController>().accuracy         = settings.Accuracy;
        GetComponent <AIWeaponController>().cooldown         = settings.CoolDown;
        GetComponent <AIWeaponController>().maxExtraCooldown = settings.MaxExtraCooldown;
        GetComponent <AIWeaponController>().shootDistance    = settings.ShootDistance;
        GetComponent <AIWeaponController>().Setup();
        if (target == null)
        {
            GameObject go = GameObject.FindGameObjectWithTag(enemyTag);
            if (go != null)
            {
                target = go.transform;
            }
        }

        lp = maxLP;
        this.transform.position = new Vector3(RoundedMath.Mult(Mathf.RoundToInt(this.transform.position.x / boxFactor), boxFactor), this.transform.position.y);

        aiMovement         = GetComponent <AIMovement>();
        aiWeaponController = GetComponent <AIWeaponController>();

        ea                    = new EnvironmentAnalyser();
        aiMemory              = new AIMemory(windowSizeX, windowSizeY, this.transform.position, ea, this, boxFactor);
        generalSolver         = new GeneralSolver(aiMemory);
        aiMemory.MaxAreaWidth = settings.MaxAreaWidth;

        aiToTarget      = new AIGetToTargetActions(aiMemory, generalSolver, aiMovement, this.transform, target, this, minimumDistance, this);
        aiWeaponActions = new AIWeaponActions(aiWeaponController);


        projectileDetector = new ProjectileDetector(this.transform, 10, projectileLayer);
        aiBehaviorTree     = new AIBehaviorTree(aiToTarget, aiWeaponActions, this, projectileDetector);
        if (aiType == AIType.AGGRESSIVE)
        {
            aiBehaviorTree.CreateAndStartAggrassiveAI();
        }
        if (aiType == AIType.DEFENSIVE)
        {
            aiBehaviorTree.CreateAndStartDefensiveAI();
        }

        aiEnabled = true;
    }
Пример #20
0
 public override void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
 {
     base.Result  = base.Inverted;
     combatEntity = memory.Entity.Get(base.InputEntityMemorySlot) as BaseCombatEntity;
     if (!(combatEntity == null))
     {
         bool flag = combatEntity.healthFraction < HealthFraction;
         if (base.Inverted)
         {
             base.Result = !flag;
         }
         else
         {
             base.Result = flag;
         }
     }
 }
Пример #21
0
    public override void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
    {
        base.Result = base.Inverted;
        IAIAttack iAIAttack = base.Owner as IAIAttack;

        if (iAIAttack != null)
        {
            bool flag = iAIAttack.GetAmmoFraction() < Value;
            if (base.Inverted)
            {
                base.Result = !flag;
            }
            else
            {
                base.Result = flag;
            }
        }
    }
Пример #22
0
        public void ProcessMessage(AIMessageSuspicionFound message, AIMemory memSender)
        {
            var memInfo = memory.GetSuspicionWithBaseTransform <InformationAlive>(message.Info.BaseTransform);

            if (memInfo != null)
            {
                if (memInfo.UpdateTime < message.Info.UpdateTime)
                {
                    memInfo.Update(message.Info.lastKnownPosition.Value, memInfo.lastKnownPosition.Confidence);
                }
            }
            else
            {
                var n = new InformationSuspicion(message.Info);
                //n.SuspicionFirm = 1;
                //n.IsSure = true;
                memory.Add(n);
            }
        }
Пример #23
0
    public override void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
    {
        IAIHungerAbove iAIHungerAbove = base.Owner as IAIHungerAbove;

        if (iAIHungerAbove == null)
        {
            base.Result = false;
            return;
        }
        bool flag = iAIHungerAbove.IsHungerAbove(Value);

        if (base.Inverted)
        {
            base.Result = !flag;
        }
        else
        {
            base.Result = flag;
        }
    }
Пример #24
0
    public override void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
    {
        IAIMounted iAIMounted = memory.Entity.Get(base.InputEntityMemorySlot) as IAIMounted;

        base.Result = false;
        if (iAIMounted != null)
        {
            if (base.Inverted && !iAIMounted.IsMounted())
            {
                base.Result = true;
            }
            if (!base.Inverted && iAIMounted.IsMounted())
            {
                base.Result = true;
            }
            if (base.Result && base.ShouldSetOutputEntityMemory)
            {
                memory.Entity.Set(memory.Entity.Get(base.InputEntityMemorySlot), base.OutputEntityMemorySlot);
            }
        }
    }
Пример #25
0
 public AIGetToTargetActions(AIMemory aiMemory, GeneralSolver generalSolver, AIMovement aiMovement, Transform aiTransform, Transform target, ITargetAroundRequest targetAroundCheck, float minDist, AIController aiController)
 {
     this.aiMemory          = aiMemory;
     this.generalSolver     = generalSolver;
     this.aiMovement        = aiMovement;
     this.aiTransform       = aiTransform;
     targetTransform        = target;
     this.targetAroundCheck = targetAroundCheck;
     this.aiController      = aiController;
     minimumDistance        = minDist;
     minDistTmp             = minDist;
     path = new LinkedList <AStarNode>();
     if (graphDebug)
     {
         if (Camera.main.GetComponent <DebugGraph>() != null)
         {
             Camera.main.GetComponent <DebugGraph>().AiMapGraph = aiMemory;
             debugCam = Camera.main;
         }
     }
 }
Пример #26
0
 private void Awake()
 {
     memory = new AIMemory();
     memory.LoadMemoryFromFile("emr");
 }
Пример #27
0
 private void Start()
 {
     memory = GetComponent <AIMemory>();
 }
Пример #28
0
 public virtual void Execute(AIMemory memory, AIBrainSenses senses, StateStatus stateStatus)
 {
 }
Пример #29
0
 public AIMessageHandlerShooter(AIMemory _aiMemory)
 {
     memory = _aiMemory;
 }
Пример #30
0
 abstract public void Init(AIMemory aiMemory, BaseAIRoutine aiRoutine);