Inheritance: MonoBehaviour
Example #1
0
    public override ActionResult Execute(AI ai)
    {
		Vector3 loc = Vector3.zero;//Default
		//Create a navigation graph collection
		List<RAINNavigationGraph> found = new List<RAINNavigationGraph>();
		
		//Create a vector location based on our AI current location 
		//plus random range values for x and z coordinates
		do
		{
			loc = new Vector3(ai.Kinematic.Position.x + Random.Range(-8f, 8f),
			                  ai.Kinematic.Position.y,
			                  ai.Kinematic.Position.z + Random.Range(-8f, 8f));
			
			//We will create navigation points using the above calculated value, the AI current positon and ensure it is within the bounds of our navigation graph
			found = NavigationManager.instance.GraphsForPoints(ai.Kinematic.Position, loc, ai.Motor.StepUpHeight, NavigationManager.GraphType.Navmesh, ((BasicNavigator)ai.Navigator).GraphTags);
			
		} while ((Vector3.Distance(ai.Kinematic.Position, loc) < 2f) || (found.Count == 0)); //We want to be sure the location found is far enough away from each one we move to so we don't pick anything to close or the same one
		
		//We will define a runtime variable in the AIRigs Memory element panel. You can select this in your inspector to see the output at runtime.
		ai.WorkingMemory.SetItem<Vector3>("varMoveTo", loc);

		if(_startTime > 500f)
		{
			ai.WorkingMemory.SetItem("isSearching", false);
			_startTime = 0;
		}

        return ActionResult.SUCCESS;
    }
Example #2
0
 // Use this for initialization
 void Start()
 {
     aiMoveCamera = new AIMoveCamera ();
     aiMoveCamera.Start (this);
     lastAI = new AITurn ();
     lastAI.Start (this);
 }
    public override RAINDecision.ActionResult Execute( AI ai )
    {
        base.Start( ai );

        ActionResult result = ActionResult.FAILURE;
        ActionResult tResult = ActionResult.FAILURE;

        if (target.IsValid && target.IsVariable) {
            Vector3 tTarget = target.Evaluate<Vector3>( ai.DeltaTime, ai.WorkingMemory );
            float tDistance = (tTarget - ai.Kinematic.Position).magnitude;

            if (tDistance > 1.5f) {
                for (; _lastRunning < _children.Count; _lastRunning++) {
                    tResult = _children[ _lastRunning ].Run( ai );
                    if (tResult != ActionResult.SUCCESS) {
                        break;
                    }
                }

                result = tResult;
            } else {
                if (targetLanded.IsValid && targetLanded.IsVariable) {
                    ai.WorkingMemory.SetItem<bool>( targetLanded.VariableName, false );
                }
            }
        }

        return result;
    }
Example #4
0
 public override void ActivatePusher(AI ai, int turn)
 {
     if (ActiveTurns[turn])
     {
         Board.MoveAIOnce(ai, Direction);
     }
 }
 public override ActionResult Execute(AI ai)
 {
     var targetPosition = unit.transform.position;
     ai.WorkingMemory.SetItem("targetPosition", targetPosition);
     Debug.DrawLine(ai.Body.transform.position, targetPosition, Color.red, 3f);
     return ActionResult.SUCCESS;
 }
Example #6
0
    void ChangeAI()
    {
        AIState state = lastAI.GetNextState ();
        lastAI.Finish ();

        if (state == AIState.None)
        {
            Instantiate(Resources.Load("Prefabs/Interact"));
            Destroy(gameObject);
            return;
        }

        AI ai;
        switch (state) {
        case AIState.Stay:
            ai = new AIStay();
            break;
        case AIState.Run:
            ai = new AIRun();
        break;
        case AIState.Sit:
            ai = new AISit();
            break;
        default:
            ai = new AISit();
            break;
        }

        ai.Start(this);
        lastAI = ai;
    }
 void Awake()
 {
     character = motor.transform;
     player = GameObject.FindWithTag ("Player").transform;
     ai = transform.parent.GetComponentInChildren<AI> ();
     inRange = firing = false; nextRaycastTime = lastRaycastSuccessfulTime = noticeTime = nextWeaponToFire = 0; lastFireTime = -1;
 }
Example #8
0
	// Use this for initialization
	public override void Initialize (AI parent)
	{
		base.Initialize(parent);
		transparent = false;
		ActionName = "AIMove";
		started = Time.time;
	}
Example #9
0
 public CentralDefenderAI(AI gameAI)
     : base(gameAI)
 {
     LeftSideRunRoom = new Rectangle(new Point(0, 10), new Size(GameAI.FieldCell.GetLength(0) / 2, GameAI.FieldCell.GetLength(1) - 20));
     RightSideRunRoom = new Rectangle(new Point(GameAI.FieldCell.GetLength(0) / 2, 10), new Size(GameAI.FieldCell.GetLength(0) / 2, GameAI.FieldCell.GetLength(1) - 20));
     DefenceBallDistance = 15;
 }
Example #10
0
        public Player(Texture2D texture, Vector2 position, Character character, LinkedListNode<Vector2> checkpoint)
            : base(texture, position, new Vector2(GameData.PLAYER_WIDTH, GameData.PLAYER_HEIGHT))
        {
            Color = character.Color;
            CurrentCharacter = character;
            SpawnedPlatform = null;
            ClonedPlayer = null;
            Score = 0;
            Checkpoints = 0;
            Progress = 0;
            Place = 0;
            Node = checkpoint;
            MaxVelocity = GameData.MAX_VELOCITY;

            ResetValues();

            int[] animationFrames = { 4, 4, 2, 4, 2, 1, 1 };
            Origin = new Vector2(Origin.X / animationFrames.Max(), Origin.Y / animationFrames.Length);
            float textureScale = GameData.PLAYER_HEIGHT / Origin.Y / 2f * (20f / 18f);
            Sprite = new AnimatedSprite(texture, this, animationFrames, textureScale);

            SlideEmitter = new ParticleEmitter(GameData.SLIDE_TEXTURES, Position, 75f);
            SlideEmitter.Red = SlideEmitter.Blue = SlideEmitter.Green = 1f;
            SlideEmitter.RedVar = SlideEmitter.BlueVar = SlideEmitter.GreenVar = 0f;
            SlideEmitter.AngVelVar = 0.001f;
            SlideEmitter.LiveTime = 5f;
            SlideEmitter.VelVarX = SlideEmitter.VelVarY = 0.5f;

            JetpackEmitter = new ParticleEmitter(GameData.JETPACK_TEXTURES, Position, 140f);
            JetpackEmitter.Size = 1.5f;
            JetpackEmitter.Red = 0.62f;
            JetpackEmitter.Blue = 0.16f;
            JetpackEmitter.Green = 0.1f;
            JetpackEmitter.RedVar = JetpackEmitter.BlueVar = JetpackEmitter.GreenVar = 0f;
        }
Example #11
0
    /// <summary>
    /// Release the cover point on Stop
    /// </summary>
    /// <param name="ai">The AI executing the action</param>
    public override void Stop(AI ai)
    {
        //Vacate will release the cover point
        Vacate(ai);

        base.Stop(ai);
    }
Example #12
0
    /// <summary>
    /// Reset the fade delay and grab the fader
    /// </summary>
    /// <param name="ai">The AI executing this action</param>
    public override void Start(AI ai)
    {
        base.Start(ai);

        fader = ai.Body.GetComponentInChildren<FadeToBlack>();
        fadeDelay = 5f;
    }
Example #13
0
    /// <summary>
    /// Remove colliders, entity rigs, rigid bodies, and character controllers
    /// </summary>
    /// <param name="ai">The AI executing the action</param>
    /// <returns>ActionResult.SUCCESS</returns>
    public override ActionResult Execute(AI ai)
    {
        //COLLIDERS
        Collider[] activeColliders = ai.Body.GetComponents<Collider>();
        foreach (Collider tCollider in activeColliders)
            if (tCollider != null)
                GameObject.DestroyImmediate(tCollider);

        //ENTITY RIGS ARE DEACTIVATED, NOT DESTROYED
        EntityRig tEntityRig = ai.Body.GetComponentInChildren<EntityRig>();
        if (tEntityRig != null)
            tEntityRig.Entity.DeactivateEntity();

        //RIGID BODIES (only 1 expected)
        Rigidbody tRigidBody = ai.Body.GetComponent<Rigidbody>();
        if (tRigidBody != null)
            tRigidBody.isKinematic = true;

        //CHARACTER CONTROLLERS (only 1 expected)
        CharacterController tCController = ai.Body.GetComponent<CharacterController>();
        if (tCController != null)
            GameObject.DestroyImmediate(tCController);

        return ActionResult.SUCCESS;
    }
Example #14
0
    /// <summary>
    /// Executing this action just checks to make sure we have a valid cover point that we still own.
    /// </summary>
    /// <param name="ai">The AI executing the action</param>
    /// <returns>FAILURE if we don't have a valid cover point.  Otherwise this action will continue to
    /// return RUNNING.  This means you should use it in a Parallel only.</returns>
    public override ActionResult Execute(AI ai)
    {
        if ((_currentCoverPoint == null) || (_currentCoverPoint.Occupant != ai.Body))
            return ActionResult.FAILURE;

        return ActionResult.RUNNING;
    }
Example #15
0
    public override ActionResult Execute(AI ai)
    {
        Vector3 loc = Vector3.zero;

        List<RAINNavigationGraph> found = new List<RAINNavigationGraph>();
        do
        {
            loc = new Vector3(ai.Kinematic.Position.x + Random.Range(-5f, 5f),
                              ai.Kinematic.Position.y,
                              ai.Kinematic.Position.z + Random.Range(-5f, 5f));

            setFlushToSurface(loc);

            found = NavigationManager.Instance.GraphsForPoints(
                ai.Kinematic.Position,
                _target.Position,
                ai.Motor.StepUpHeight,
                NavigationManager.GraphType.Navmesh,
                ((BasicNavigator)ai.Navigator).GraphTags);

        } while ((Vector3.Distance(ai.Kinematic.Position, _target.Position) < 2f) || (found.Count == 0));

        ai.WorkingMemory.SetItem<Vector3>("wanderTarget", _target.Position);
        Debug.Log ("wander Target is " + _target.Position);

        return ActionResult.SUCCESS;
    }
    public override ActionResult Execute(AI ai)
    {
        //enemyObject = enemy.Evaluate(ai.DeltaTime, ai.WorkingMemory).GetValue<GameObject>();
        if( ai.WorkingMemory.GetItem("Wizard").GetValue<RAIN.Entities.Aspects.VisualAspect>() == null )
        {
            enemyObject = null;
            ai.WorkingMemory.SetItem("ShouldAttack", false );
            return ActionResult.SUCCESS;
        }
        else
            enemyObject = ai.WorkingMemory.GetItem("Wizard").GetValue<RAIN.Entities.Aspects.VisualAspect>().Entity.Form;
        if( enemyObject != null )
        {
            //if( enemyObject.GetPhotonView().isMine )
            {
                if ((int)enemyObject.GetPhotonView().owner.customProperties["Health"] <= 0 )
                {
                    ai.WorkingMemory.SetItem("ShouldAttack", false );
                }
                else
                {
                    ai.WorkingMemory.SetItem("ShouldAttack", true );
                }
            }

        }

        return ActionResult.SUCCESS;
    }
Example #17
0
    /// <summary>
    /// Start finds and stores the AimAndFireElement
    /// </summary>
    /// <param name="ai">The AI executing the action</param>
    public override void Start(AI ai)
    {
        base.Start(ai);

        if (_aimAndFire == null)
            _aimAndFire = ai.GetCustomElement<AimAndFireElement>();
    }
Example #18
0
    private void DoAvoidance(AI ai, RAINAspect aspect)
    {
        between = ai.Kinematic.Position - aspect.Position;
        avoidVector = Vector3.Cross(Vector3.up, between);

        Vector3 avoidPoint;

        int direction = Random.Range(0, 100);

        avoidVector.Normalize();

        if(direction < 50)
            avoidVector *= -1;

        avoidPoint = GetPositionOnNavMesh(avoidVector, ai);

        if(avoidPoint == Vector3.zero)
        {
            avoidVector *= -1;
            avoidPoint = GetPositionOnNavMesh(avoidVector, ai);
        }

        if(avoidPoint == Vector3.zero)
        {
            Debug.Log("Avoid not possible!");

            // Change destination
            ai.WorkingMemory.SetItem("hasArrived", true);

            return;
        }

        ai.Motor.MoveTo(ai.Kinematic.Position + avoidPoint);
        Debug.Log (ai.Body.name + " is avoiding " + aspect.Entity.Form.name);
    }
        /// <summary>
        /// Add an AI to the appropriate TeamPlanner, or move it to the
        /// appropriate TeamPlanner if it is already in one.
        /// </summary>
        /// <param name="ai">Agent's AI to be registered.</param>
        internal static void register(AI ai)
        {
            if (ai == null)
            {
                return;
            }

            int allegiance = ai.Character_.Allegiance_;
            if (registry_.ContainsKey(ai))
            {
                int previousAllegiance =
                    registry_[ai];
                map_[previousAllegiance].removeMember(ai);
                registry_[ai] = ai.Character_.Allegiance_;
            }
            else
            {
                registry_.Add(ai, allegiance);
            }

            if (map_.ContainsKey(allegiance))
            {
                map_[allegiance].addMember(ai);
            }
            else
            {
                TeamPlanner tp = new TeamPlanner(allegiance);
                tp.addMember(ai);
                tp.addGoal(new TeamGoalEliminate());
                map_.Add(allegiance, tp);
            }
        }
Example #20
0
    /// <summary>
    /// When executing, this action checks to see if the AI "enemy" variable has a value.  If so,
    /// and if the enemy has an aimpoint aspect, that is used as the aim target.  If the aimpoint doesn't
    /// exist, then the enemy is used directly.  If neither exists, firing still occurs but aiming does not.
    /// </summary>
    /// <param name="ai">The AI executing the action</param>
    /// <returns>FAILURE if the AimAndFireElement is missing, SUCCESS otherwise</returns>
    public override ActionResult Execute(AI ai)
    {
        if (_aimAndFire == null)
            return ActionResult.FAILURE;

        //Use the AI enemy variable as the aim target
        GameObject tAimObject = ai.WorkingMemory.GetItem<GameObject>("enemy");

        //If the target exists, set the aim target
        if (tAimObject != null)
        {
            RAINAspect tAimPoint = null;

            //Look for an aimpoint aspect and use that if possible
            EntityRig tEntity = tAimObject.GetComponentInChildren<EntityRig>();
            if (tEntity != null)
                tAimPoint = tEntity.Entity.GetAspect("aimpoint");

            //Otherwise just use the enemy object plus a default height
            if (tAimPoint == null)
                _aimAndFire.SetAimTarget(tAimObject.transform.position + new Vector3(0, 1.5f, 0));
            else
                _aimAndFire.SetAimTarget(tAimPoint.Position);
        }

        //Fire away
        _aimAndFire.FireWeapon();

        return ActionResult.SUCCESS;
    }
Example #21
0
 public CentralMidfielderAI(AI gameAI)
     : base(gameAI)
 {
     LeftSideRunRoom = new Rectangle(new Point(15, 7), new Size(GameAI.FieldCell.GetLength(0) - 15, GameAI.FieldCell.GetLength(1) - 14));
     RightSideRunRoom = new Rectangle(new Point(0, 7), new Size(GameAI.FieldCell.GetLength(0) - 15, GameAI.FieldCell.GetLength(1) - 14));
     DefenceBallDistance = 5;
 }
Example #22
0
 void Start()
 {
     initialize ();
     print ();
     ai = new AI(this);
     print("Starting time: " + Time.time);
 }
Example #23
0
    public string RadioDispatcher(AI cop, Transform player, float currentTime)
    {
        float firstObservedTime = cop.WorkingMemory.GetItem <float> ("FirstObservedTime");

        //Debug.Log (cop.Body.name + ": firstObservedTime = " + firstObservedTime);
        //Debug.Log (cop.Body.name + ": currentTime - firstObservedTime = " + (currentTime - firstObservedTime));
        if ((firstObservedTime != 0) && ((currentTime - firstObservedTime) > 1.0f)) {
            if (HasPlayerNotMovedFromLastObjectDetection (cop, player)) {
                //		Debug.Log (cop.Body.name + "Player is linger enough to cause suspicion. Calling dispatcher");
                RadioManager.Singleton.RadioDispatcher (cop, player, currentTime);

                //		Debug.Log ("Suspicion Level = " + StateManager.GetSuspicion());
                if (StateManager.instance.GetSuspicion () >= StateManager.MAXIMUM_SUSPICION_LEVEL) {
                    return "arrest";
                } else {
                    return "observe";
                }

            }
        }

        //Debug.Log (cop.Body.name + "did not radio dispatcher");

        return "observe";
    }
Example #24
0
    public IEnumerator StartStatus(AI a)
    {
        ai = a;
        bool in_state = !ai.status_manager.is_dead;
        while(in_state)
        {
            yield return StartCoroutine(Execute());

            if(CheckPreviousState())
            {
                in_state = false;
                ToPreviousState();
            }
            else if(CheckNextState())
            {
                in_state = false;
                ToNextState();
            }

            //start allover again if the current target does not exists or is dead
            if(ai.status_manager.target == null || ((ai.status_manager.target.GetComponent("StatusManager") as StatusManager).is_dead))
            {
                in_state = false;
                StartCoroutine(ai.detection.StartStatus(ai));
            }

            in_state = in_state && !ai.status_manager.is_dead;
            yield return new WaitForSeconds(Time.deltaTime);
        }
    }
Example #25
0
    public override ActionResult Execute(AI ai)
    {
        if (_children.Count == 0)
        {
            return ActionResult.FAILURE;
        }

        int successes = 0;
        for (int i = 0; i < _children.Count; i++)
        {
            var result = _children[i].Run(ai);

            if (result == ActionResult.SUCCESS)
            {
                _children[i].Reset();
                successes++;
            }
            else if (result == ActionResult.FAILURE)
            {
                return ActionResult.FAILURE;
            }
        }      

        if (ai.Body.transform.position == ai.Motor.MoveTarget.Position && successes == _children.Count)
        {
            return ActionResult.SUCCESS;
        }
        return ActionResult.RUNNING;
    }
    private void DoAvoidance(AI ai, RAINAspect aspect)
    {
        between = ai.Kinematic.Position - aspect.Position;
        avoidVector = Vector3.Cross(Vector3.up, between);

        int direction = Random.Range(0, 100);

        avoidVector.Normalize();

        if (direction < 50)
            avoidVector *= -1;

        if (!CheckPositionOnNavMesh(avoidVector, ai))
            avoidVector *= -1;

        if (!CheckPositionOnNavMesh(avoidVector, ai))
        {
            //Debug.Log("Avoid not possible!");
            return;
        }

        Vector3 destination = ai.Kinematic.Position + avoidVector;
        //ai.Motor.MoveTo(destination);
        //ai.Kinematic.Position += avoidVector;
        ai.Kinematic.Position = Vector3.Lerp(ai.Kinematic.Position, destination, 0.3f);
        ai.Motor.FaceAt(avoidVector);
    }
Example #27
0
    // Use this for initialization
    void Start()
    {
        if(thoughtMan==null) thoughtMan = GameObject.Find("ThoughtManager").GetComponent<ThoughtManager>();
        myAI = GetComponent<AI> ();

        InitIdeas();
    }
Example #28
0
 public void Register(AI.AI ai)
 {
     if (!_AIs.ContainsKey(ai.ID))
     {
         _AIs.Add(ai.ID, ai);
     }
 }
 public override ActionResult Execute(AI ai)
 {
     Environment.FACTIONS f=control.faction;
     Debug.Log("Execute Movement Action: "+f);
     ai.WorkingMemory.SetItem<Transform>("movementTarget",SelectKeyLoc());
     return ActionResult.SUCCESS;
 }
Example #30
0
 public override ActionResult Execute(AI ai)
 {
     Debug.Log ("execute");
     //	Dialoguer.
     //return ActionResult.SUCCESS;
     return ActionResult.FAILURE;
 }
Example #31
0
 public virtual void InitilizeState(AI ai)
 {
 }
Example #32
0
 private bool 娱乐法师戏法小丑效果()
 {
     已发动小丑 = true;
     AI.SelectPosition(CardPosition.FaceUpDefence);
     return(true);
 }
Example #33
0
 private void Start()
 {
     ai = new AI(pm);
     generateEmptyBoard();
     PlacePieces();
 }
Example #34
0
 void Start()
 {
     ai       = GetComponent <AI>();
     states   = GetComponent <States>();
     movement = GetComponent <Movement>();
 }
 private bool GoblindberghEffect()
 {
     AI.SelectCard(L4Tuners);
     return(true);
 }
Example #36
0
 public virtual void ExitState(AI ai)
 {
 }
Example #37
0
 private bool SeaStealthAttackeff()
 {
     if (DefaultOnBecomeTarget())
     {
         AI.SelectCard(CardId.MegalosmasherX);
         SeaStealthAttackeff_used = true;
         return(true);
     }
     if ((Card.IsFacedown() && Bot.HasInHandOrInSpellZoneOrInGraveyard(CardId.PacifisThePhantasmCity)))
     {
         if (!Bot.HasInSpellZone(CardId.PacifisThePhantasmCity))
         {
             if (Bot.HasInGraveyard(CardId.PacifisThePhantasmCity))
             {
                 foreach (ClientCard s in Bot.GetGraveyardSpells())
                 {
                     if (s.Id == CardId.PacifisThePhantasmCity)
                     {
                         AI.SelectYesNo(true);
                         AI.SelectCard(s);
                         break;
                     }
                 }
             }
             else
             {
                 foreach (ClientCard s in Bot.Hand)
                 {
                     if (s.Id == CardId.PacifisThePhantasmCity)
                     {
                         AI.SelectYesNo(true);
                         AI.SelectCard(s);
                         break;
                     }
                 }
             }
         }
         else
         {
             AI.SelectYesNo(false);
         }
         return(UniqueFaceupSpell());
     }
     else if (Card.IsFaceup())
     {
         ClientCard target = null;
         foreach (ClientCard s in Bot.GetSpells())
         {
             if (s.Id == CardId.PacifisThePhantasmCity)
             {
                 target = s;
             }
         }
         if (target != null && AI.Utils.IsChainTarget(target))
         {
             SeaStealthAttackeff_used = true;
             return(true);
         }
         target = AI.Utils.GetLastChainCard();
         if (target != null)
         {
             if (target.Id == CardId.BrandishSkillAfterburner)
             {
                 AI.SelectCard(CardId.MegalosmasherX);
                 SeaStealthAttackeff_used = true;
                 return(true);
             }
             if (Enemy.GetGraveyardSpells().Count >= 3 && target.Id == CardId.BrandishSkillJammingWave)
             {
                 AI.SelectCard(CardId.MegalosmasherX);
                 SeaStealthAttackeff_used = true;
                 return(true);
             }
         }
     }
     return(false);
 }
Example #38
0
 private bool MegalosmasherXsummon()
 {
     AI.SelectPlace(Zones.z1 | Zones.z3);
     summon_used = true;
     return(true);
 }
 public void MoveToTarget(AI character)
 {
     character.transform.position = taskTarget.position;
 }
Example #40
0
    public Player()
    {
        string[] inputs;
        inputs = Console.ReadLine().Split(' ');
        int width  = int.Parse(inputs[0]);
        int height = int.Parse(inputs[1]); // size of the map

        game = new Game(width, height);

        // game loop
        while (true)
        {
            inputs             = Console.ReadLine().Split(' ');
            game.MyScore       = int.Parse(inputs[0]); // Amount of ore delivered
            game.OpponentScore = int.Parse(inputs[1]);
            for (int i = 0; i < height; i++)
            {
                var row = Console.ReadLine();

                inputs = row.Split(' ');
                for (int j = 0; j < width; j++)
                {
                    string ore  = inputs[2 * j];                // amount of ore or "?" if unknown
                    int    hole = int.Parse(inputs[2 * j + 1]); // 1 if cell has a hole
                    game.Cells[j, i].Update(ore, hole);
                }
            }
            inputs = Console.ReadLine().Split(' ');
            int entityCount   = int.Parse(inputs[0]); // number of entities visible to you
            int radarCooldown = int.Parse(inputs[1]); // turns left until a new radar can be requested
            int trapCooldown  = int.Parse(inputs[2]); // turns left until a new trap can be requested

            game.Radars.Clear();
            game.Traps.Clear();
            game.MyRobots.Clear();
            game.OpponentRobots.Clear();

            game.RadarCooldown = radarCooldown;
            game.TrapCooldown  = trapCooldown;

            for (int i = 0; i < entityCount; i++)
            {
                var entityState = Console.ReadLine();

                inputs = entityState.Split(' ');
                int        id    = int.Parse(inputs[0]);             // unique id of the entity
                EntityType type  = (EntityType)int.Parse(inputs[1]); // 0 for your robot, 1 for other robot, 2 for radar, 3 for trap
                int        x     = int.Parse(inputs[2]);
                int        y     = int.Parse(inputs[3]);             // position of the entity
                EntityType item  = (EntityType)int.Parse(inputs[4]); // if this entity is a robot, the item it is carrying (-1 for NONE, 2 for RADAR, 3 for TRAP, 4 for ORE)
                Coord      coord = new Coord(x, y);

                switch (type)
                {
                case EntityType.MY_ROBOT:
                    game.MyRobots.Add(new Robot(id, coord, item));
                    break;

                case EntityType.OPPONENT_ROBOT:
                    game.OpponentRobots.Add(new Robot(id, coord, item));
                    break;

                case EntityType.RADAR:
                    game.Radars.Add(new Entity(id, coord, item));
                    break;

                case EntityType.TRAP:
                    game.Traps.Add(new Entity(id, coord, item));
                    break;
                }
            }

            var ai      = new AI(game, onGoingMissions);
            var actions = ai.GetActions();

            foreach (var action in actions)
            {
                Console.WriteLine(action);
            }
        }
    }
 private bool MissusRadianteff()
 {
     AI.SelectCard(CardId.MaxxC, CardId.MissusRadiant);
     return(true);
 }
Example #42
0
 public virtual void Exicute(AI ai)
 {
 }
        private bool EaterOfMillionssp()
        {
            if (Bot.MonsterZone[0] == null)
            {
                AI.SelectPlace(Zones.z0);
            }
            else
            {
                AI.SelectPlace(Zones.z4);
            }
            if (Enemy.HasInMonstersZone(CardId.KnightmareGryphon, true))
            {
                return(false);
            }
            if (Bot.HasInMonstersZone(CardId.InspectBoarder) && !eater_eff)
            {
                return(false);
            }
            if (Util.GetProblematicEnemyMonster() == null && Bot.ExtraDeck.Count < 5)
            {
                return(false);
            }
            if (Bot.GetMonstersInMainZone().Count >= 5)
            {
                return(false);
            }
            if (Util.IsTurn1OrMain2())
            {
                return(false);
            }
            AI.SelectPosition(CardPosition.FaceUpAttack);
            IList <ClientCard> targets = new List <ClientCard>();

            foreach (ClientCard e_c in Bot.ExtraDeck)
            {
                targets.Add(e_c);
                if (targets.Count >= 5)
                {
                    AI.SelectCard(targets);

                    /*AI.SelectCard(new[] {
                     *  CardId.BingirsuTheWorldChaliceWarrior,
                     *  CardId.TopologicTrisbaena,
                     *  CardId.KnightmareCerberus,
                     *  CardId.KnightmarePhoenix,
                     *  CardId.KnightmareUnicorn,
                     *  CardId.BrandishMaidenKagari,
                     *  CardId.HeavymetalfoesElectrumite,
                     *  CardId.CrystronNeedlefiber,
                     *  CardId.FirewallDragon,
                     *  CardId.BirrelswordDragon,
                     *  CardId.RaidraptorUltimateFalcon,
                     * });*/

                    AI.SelectPlace(Zones.z4 | Zones.z0);
                    return(true);
                }
            }
            Logger.DebugWriteLine("*** Eater use up the extra deck.");
            foreach (ClientCard s_c in Bot.GetSpells())
            {
                targets.Add(s_c);
                if (targets.Count >= 5)
                {
                    AI.SelectCard(targets);
                    return(true);
                }
            }
            return(false);
        }
Example #44
0
 public ITicTacToeBoxClass.ITicTacToeBox Move(
     ITicTacToeBoxClass.ITicTacToeBox ticTacToeBox,
     GameSettings.gameSetting settings)
 {
     return(AI.aIMove(settings, ticTacToeBox));
 }
 private bool DragunityArmaMysletainnEffect()
 {
     AI.SelectCard(CardId.DragunityPhalanx);
     return(true);
 }
 private bool WakingTheDragoneff()
 {
     AI.SelectCard(new[] { CardId.RaidraptorUltimateFalcon });
     return(true);
 }
        private bool DragonRavineEffect()
        {
            if (Card.Location != CardLocation.SpellZone)
            {
                return(false);
            }

            int tributeId = -1;

            if (Bot.HasInHand(CardId.DragunityPhalanx))
            {
                tributeId = CardId.DragunityPhalanx;
            }
            else if (Bot.HasInHand(CardId.FireFormationTenki))
            {
                tributeId = CardId.FireFormationTenki;
            }
            else if (Bot.HasInHand(CardId.Terraforming))
            {
                tributeId = CardId.Terraforming;
            }
            else if (Bot.HasInHand(CardId.DragonRavine))
            {
                tributeId = CardId.DragonRavine;
            }
            else if (Bot.HasInHand(CardId.AssaultTeleport))
            {
                tributeId = CardId.AssaultTeleport;
            }
            else if (Bot.HasInHand(CardId.AssaultBeast))
            {
                tributeId = CardId.AssaultBeast;
            }
            else if (Bot.HasInHand((int)CardId.DragunityArmaMysletainn))
            {
                tributeId = CardId.DragunityArmaMysletainn;
            }
            else
            {
                int count = 0;
                foreach (ClientCard card in Bot.Hand)
                {
                    if (card.IsCode(CardId.DragunityDux))
                    {
                        ++count;
                    }
                }
                if (count >= 2)
                {
                    tributeId = CardId.DragunityDux;
                }
            }
            if (tributeId == -1 && Bot.HasInHand(CardId.StardustDragonAssaultMode))
            {
                tributeId = CardId.StardustDragonAssaultMode;
            }
            if (tributeId == -1 && Bot.HasInHand(CardId.DragunitySpearOfDestiny))
            {
                tributeId = CardId.StardustDragonAssaultMode;
            }
            if (tributeId == -1 && Bot.HasInHand(CardId.DragonsMirror) &&
                Bot.GetMonsterCount() == 0)
            {
                tributeId = CardId.StardustDragonAssaultMode;
            }

            if (tributeId == -1)
            {
                return(false);
            }

            int needId = -1;

            if (!Bot.HasInMonstersZone(CardId.DragunityPhalanx) &&
                !Bot.HasInGraveyard(CardId.DragunityPhalanx))
            {
                needId = CardId.DragunityPhalanx;
            }
            else if (Bot.GetMonsterCount() == 0)
            {
                needId = CardId.DragunityDux;
            }
            else
            {
                /*bool hasRealMonster = false;
                 * foreach (ClientCard card in Bot.GetMonsters())
                 * {
                 *  if (!card.IsCode(CardId.AssaultBeast))
                 *  {
                 *      hasRealMonster = true;
                 *      break;
                 *  }
                 * }
                 * if (!hasRealMonster || Util.GetProblematicCard() != null)*/
                needId = CardId.DragunityDux;
            }

            if (needId == -1)
            {
                return(false);
            }

            int option;

            if (tributeId == CardId.DragunityPhalanx)
            {
                needId = CardId.DragunityDux;
            }

            int remaining = 3;

            foreach (ClientCard card in Bot.Hand)
            {
                if (card.IsCode(needId))
                {
                    remaining--;
                }
            }
            foreach (ClientCard card in Bot.Graveyard)
            {
                if (card.IsCode(needId))
                {
                    remaining--;
                }
            }
            foreach (ClientCard card in Bot.Banished)
            {
                if (card.IsCode(needId))
                {
                    remaining--;
                }
            }
            if (remaining <= 0)
            {
                return(false);
            }

            if (needId == CardId.DragunityPhalanx)
            {
                option = 2;
            }
            else
            {
                option = 1;
            }

            if (ActivateDescription != Util.GetStringId(CardId.DragonRavine, option))
            {
                return(false);
            }

            AI.SelectCard(tributeId);
            AI.SelectNextCard(needId);

            return(true);
        }
        private MovementFormNode m_CurrentRandomChild = null;               //The current randomly chosen child that will be operated on

        public MovementOptionRandomNode(AI reference, params MovementFormNode[] childNodes) : base(reference, childNodes)
        {
        }
Example #49
0
 // Use this for initialization
 void Start()
 {
     ai = this.transform.parent.gameObject.GetComponent <AI> ();
 }
        private bool ScrapDragonEffect()
        {
            ClientCard invincible = Util.GetProblematicEnemyCard(3000);

            if (invincible == null && !Util.IsOneEnemyBetterThanValue(2800 - 1, false))
            {
                return(false);
            }

            int tributeId = -1;

            if (Bot.HasInSpellZone(CardId.FireFormationTenki))
            {
                tributeId = CardId.FireFormationTenki;
            }
            else if (Bot.HasInSpellZone(CardId.Terraforming))
            {
                tributeId = CardId.Terraforming;
            }
            else if (Bot.HasInSpellZone(CardId.DragonsMirror))
            {
                tributeId = CardId.DragonsMirror;
            }
            else if (Bot.HasInSpellZone(CardId.CardsOfConsonance))
            {
                tributeId = CardId.CardsOfConsonance;
            }
            else if (Bot.HasInSpellZone(CardId.AssaultTeleport))
            {
                tributeId = CardId.AssaultTeleport;
            }
            else if (Bot.HasInSpellZone(CardId.AssaultModeActivate))
            {
                tributeId = CardId.AssaultModeActivate;
            }
            else if (Bot.HasInSpellZone(CardId.DragonRavine))
            {
                tributeId = CardId.DragonRavine;
            }

            List <ClientCard> monsters = Enemy.GetMonsters();

            monsters.Sort(CardContainer.CompareCardAttack);

            ClientCard destroyCard = invincible;

            if (destroyCard == null)
            {
                for (int i = monsters.Count - 1; i >= 0; --i)
                {
                    if (monsters[i].IsAttack())
                    {
                        destroyCard = monsters[i];
                        break;
                    }
                }
            }

            if (destroyCard == null)
            {
                return(false);
            }

            AI.SelectCard(tributeId);
            AI.SelectNextCard(destroyCard);

            return(true);
        }
Example #51
0
    public override void Exicute(AI ai)
    {
        if (!caughtPlayer)
        {
            Vector3 mag = (GameManager.instance.playerScript.transform.position - ai.transform.position);
            distance = (GameManager.instance.playerScript.transform.position - ai.transform.position).sqrMagnitude;
            if (distance <= catchDistance * catchDistance)
            {
                if (!GameManager.instance.inHiding)
                {
                    GameManager.instance.playerScript.LockMovement();
                    GameManager.instance.playerScript.Zap();
                    if (mag.z < 0)
                    {
                        ai.agent.enabled = false;
                        Vector3 pos = new Vector3(GameManager.instance.playerScript.gameObject.transform.position.x,
                                                  ai.gameObject.transform.position.y, GameManager.instance.playerScript.gameObject.transform.position.z + 0.5f);
                        ai.transform.LookAt(new Vector3(GameManager.instance.playerScript.gameObject.transform.position.x, ai.gameObject.transform.rotation.y, GameManager.instance.playerScript.gameObject.transform.position.z));
                        ai.gameObject.transform.rotation = Quaternion.Euler(0, 180, 0);
                        ai.gameObject.transform.position = pos;
                        GameManager.instance.playerScript.PositionMeAlt(ai, 0);
                    }
                    else if (mag.z > 0)
                    {
                        ai.agent.enabled = false;
                        Vector3 pos = new Vector3(GameManager.instance.playerScript.gameObject.transform.position.x,
                                                  ai.gameObject.transform.position.y, GameManager.instance.playerScript.gameObject.transform.position.z - 0.5f);
                        ai.transform.LookAt(new Vector3(GameManager.instance.playerScript.gameObject.transform.position.x, ai.gameObject.transform.rotation.y, GameManager.instance.playerScript.gameObject.transform.position.z));
                        ai.gameObject.transform.rotation = Quaternion.Euler(0, 0, 0);
                        ai.gameObject.transform.position = pos;
                        GameManager.instance.playerScript.PositionMeAlt(ai, 180);
                    }
                    ai.myAnimator.SetTrigger("attack");
                    caughtPlayer = true;
                    return;
                }
                else
                {
                    ai.SwitchState(connections[0]);
                }
            }

            chasePos   = GameManager.instance.playerScript.transform.position;
            chasePos.y = ai.transform.position.y;
            ai.agent.SetDestination(chasePos);

            if (!ai.chasing)
            {
                if (!GameManager.instance.paused)
                {
                    searchingFor += GameManager.instance.delta;
                }
                if (searchingFor >= ai.searchTime)
                {
                    searchingFor = 0;
                    ai.SwitchState(connections[0]);
                }
            }
            else if (searchingFor != 0)
            {
                searchingFor = 0;
            }
        }
    }
Example #52
0
        public override void Bind(Entity entity, Main main, bool creating = false)
        {
            if (ParticleSystem.Get(main, "SnakeSparks") == null)
            {
                ParticleSystem.Add(main, "SnakeSparks",
                                   new ParticleSystem.ParticleSettings
                {
                    TextureName           = "Particles\\splash",
                    MaxParticles          = 1000,
                    Duration              = TimeSpan.FromSeconds(1.0f),
                    MinHorizontalVelocity = -7.0f,
                    MaxHorizontalVelocity = 7.0f,
                    MinVerticalVelocity   = 0.0f,
                    MaxVerticalVelocity   = 7.0f,
                    Gravity        = new Vector3(0.0f, -10.0f, 0.0f),
                    MinRotateSpeed = -2.0f,
                    MaxRotateSpeed = 2.0f,
                    MinStartSize   = 0.3f,
                    MaxStartSize   = 0.7f,
                    MinEndSize     = 0.0f,
                    MaxEndSize     = 0.0f,
                    BlendState     = Microsoft.Xna.Framework.Graphics.BlendState.AlphaBlend,
                    MinColor       = new Vector4(2.0f, 2.0f, 2.0f, 1.0f),
                    MaxColor       = new Vector4(2.0f, 2.0f, 2.0f, 1.0f),
                });
                ParticleSystem.Add(main, "SnakeSparksRed",
                                   new ParticleSystem.ParticleSettings
                {
                    TextureName           = "Particles\\splash",
                    MaxParticles          = 1000,
                    Duration              = TimeSpan.FromSeconds(1.0f),
                    MinHorizontalVelocity = -7.0f,
                    MaxHorizontalVelocity = 7.0f,
                    MinVerticalVelocity   = 0.0f,
                    MaxVerticalVelocity   = 7.0f,
                    Gravity        = new Vector3(0.0f, -10.0f, 0.0f),
                    MinRotateSpeed = -2.0f,
                    MaxRotateSpeed = 2.0f,
                    MinStartSize   = 0.3f,
                    MaxStartSize   = 0.7f,
                    MinEndSize     = 0.0f,
                    MaxEndSize     = 0.0f,
                    BlendState     = Microsoft.Xna.Framework.Graphics.BlendState.AlphaBlend,
                    MinColor       = new Vector4(1.4f, 0.8f, 0.7f, 1.0f),
                    MaxColor       = new Vector4(1.4f, 0.8f, 0.7f, 1.0f),
                });
                ParticleSystem.Add(main, "SnakeSparksYellow",
                                   new ParticleSystem.ParticleSettings
                {
                    TextureName           = "Particles\\splash",
                    MaxParticles          = 1000,
                    Duration              = TimeSpan.FromSeconds(1.0f),
                    MinHorizontalVelocity = -7.0f,
                    MaxHorizontalVelocity = 7.0f,
                    MinVerticalVelocity   = 0.0f,
                    MaxVerticalVelocity   = 7.0f,
                    Gravity        = new Vector3(0.0f, -10.0f, 0.0f),
                    MinRotateSpeed = -2.0f,
                    MaxRotateSpeed = 2.0f,
                    MinStartSize   = 0.3f,
                    MaxStartSize   = 0.7f,
                    MinEndSize     = 0.0f,
                    MaxEndSize     = 0.0f,
                    BlendState     = Microsoft.Xna.Framework.Graphics.BlendState.AlphaBlend,
                    MinColor       = new Vector4(1.4f, 1.4f, 0.7f, 1.0f),
                    MaxColor       = new Vector4(1.4f, 1.4f, 0.7f, 1.0f),
                });
            }

            Snake snake = entity.GetOrCreate <Snake>("Snake");

            entity.CannotSuspendByDistance = true;
            Transform transform = entity.GetOrCreate <Transform>("Transform");

            AI ai = entity.GetOrCreate <AI>("AI");

            Agent agent = entity.GetOrCreate <Agent>("Agent");

            const float defaultSpeed    = 5.0f;
            const float chaseSpeed      = 18.0f;
            const float closeChaseSpeed = 12.0f;
            const float crushSpeed      = 125.0f;

            VoxelChaseAI chase = entity.GetOrCreate <VoxelChaseAI>("VoxelChaseAI");

            chase.Add(new TwoWayBinding <Vector3>(transform.Position, chase.Position));
            chase.Speed.Value             = defaultSpeed;
            chase.EnablePathfinding.Value = ai.CurrentState.Value == "Chase";
            chase.Filter = delegate(Voxel.State state)
            {
                if (state == Voxel.States.Infected || state == Voxel.States.Neutral || state == Voxel.States.Hard || state == Voxel.States.HardInfected)
                {
                    return(true);
                }
                return(false);
            };
            entity.Add(new CommandBinding(chase.Delete, entity.Delete));

            PointLight positionLight = null;

            if (!main.EditorEnabled)
            {
                positionLight                   = new PointLight();
                positionLight.Serialize         = false;
                positionLight.Color.Value       = new Vector3(1.5f, 0.5f, 0.5f);
                positionLight.Attenuation.Value = 20.0f;
                positionLight.Add(new Binding <bool, string>(positionLight.Enabled, x => x != "Suspended", ai.CurrentState));
                positionLight.Add(new Binding <Vector3, string>(positionLight.Color, delegate(string state)
                {
                    switch (state)
                    {
                    case "Chase":
                    case "Crush":
                        return(new Vector3(1.5f, 0.5f, 0.5f));

                    case "Alert":
                        return(new Vector3(1.5f, 1.5f, 0.5f));

                    default:
                        return(new Vector3(1.0f, 1.0f, 1.0f));
                    }
                }, ai.CurrentState));
                entity.Add("PositionLight", positionLight);
                ParticleEmitter emitter = entity.GetOrCreate <ParticleEmitter>("Particles");
                emitter.Serialize = false;
                emitter.ParticlesPerSecond.Value = 100;
                emitter.Add(new Binding <string>(emitter.ParticleType, delegate(string state)
                {
                    switch (state)
                    {
                    case "Chase":
                    case "Crush":
                        return("SnakeSparksRed");

                    case "Alert":
                        return("SnakeSparksYellow");

                    default:
                        return("SnakeSparks");
                    }
                }, ai.CurrentState));
                emitter.Add(new Binding <Vector3>(emitter.Position, transform.Position));
                emitter.Add(new Binding <bool, string>(emitter.Enabled, x => x != "Suspended", ai.CurrentState));

                positionLight.Add(new Binding <Vector3>(positionLight.Position, transform.Position));
                emitter.Add(new Binding <Vector3>(emitter.Position, transform.Position));
                agent.Add(new Binding <Vector3>(agent.Position, transform.Position));
                Sound.AttachTracker(entity);
            }

            AI.Task checkMap = new AI.Task
            {
                Action = delegate()
                {
                    if (chase.Voxel.Value.Target == null || !chase.Voxel.Value.Target.Active)
                    {
                        entity.Delete.Execute();
                    }
                },
            };

            AI.Task checkOperationalRadius = new AI.Task
            {
                Interval = 2.0f,
                Action   = delegate()
                {
                    bool shouldBeActive = (transform.Position.Value - main.Camera.Position).Length() < snake.OperationalRadius;
                    if (shouldBeActive && ai.CurrentState == "Suspended")
                    {
                        ai.CurrentState.Value = "Idle";
                    }
                    else if (!shouldBeActive && ai.CurrentState != "Suspended")
                    {
                        ai.CurrentState.Value = "Suspended";
                    }
                },
            };

            AI.Task checkTargetAgent = new AI.Task
            {
                Action = delegate()
                {
                    Entity target = ai.TargetAgent.Value.Target;
                    if (target == null || !target.Active)
                    {
                        ai.TargetAgent.Value  = null;
                        ai.CurrentState.Value = "Idle";
                    }
                },
            };

            Func <Voxel, Direction> randomValidDirection = delegate(Voxel m)
            {
                Voxel.Coord c    = chase.Coord;
                Direction[] dirs = new Direction[6];
                Array.Copy(DirectionExtensions.Directions, dirs, 6);

                // Shuffle directions
                int i = 5;
                while (i > 0)
                {
                    int       k    = this.random.Next(i);
                    Direction temp = dirs[i];
                    dirs[i] = dirs[k];
                    dirs[k] = temp;
                    i--;
                }

                foreach (Direction dir in dirs)
                {
                    if (chase.Filter(m[c.Move(dir)]))
                    {
                        return(dir);
                    }
                }
                return(Direction.None);
            };

            Direction currentDir = Direction.None;

            chase.Add(new CommandBinding <Voxel, Voxel.Coord>(chase.Moved, delegate(Voxel m, Voxel.Coord c)
            {
                if (chase.Active)
                {
                    string currentState = ai.CurrentState.Value;
                    Voxel.t id          = m[c].ID;
                    if (id == Voxel.t.Hard)
                    {
                        m.Empty(c);
                        m.Fill(c, Voxel.States.HardInfected);
                        m.Regenerate();
                    }
                    else if (id == Voxel.t.Neutral)
                    {
                        m.Empty(c);
                        m.Fill(c, Voxel.States.Infected);
                        m.Regenerate();
                    }
                    else if (id == Voxel.t.Empty)
                    {
                        m.Fill(c, Voxel.States.Infected);
                        m.Regenerate();
                    }
                    AkSoundEngine.PostEvent(AK.EVENTS.PLAY_SNAKE_MOVE, entity);

                    if (currentState == "Idle")
                    {
                        if (currentDir == Direction.None || !chase.Filter(m[chase.Coord.Value.Move(currentDir)]) || this.random.Next(8) == 0)
                        {
                            currentDir = randomValidDirection(m);
                        }
                        chase.Coord.Value = chase.Coord.Value.Move(currentDir);
                    }
                    else if (snake.Path.Length > 0)
                    {
                        chase.Coord.Value = snake.Path[0];
                        snake.Path.RemoveAt(0);
                    }
                }
            }));

            const float sightDistance   = 50.0f;
            const float hearingDistance = 0.0f;

            ai.Setup
            (
                new AI.AIState
            {
                Name  = "Suspended",
                Tasks = new[] { checkOperationalRadius },
            },
                new AI.AIState
            {
                Name  = "Idle",
                Enter = delegate(AI.AIState previous)
                {
                    Entity voxelEntity = chase.Voxel.Value.Target;
                    if (voxelEntity != null)
                    {
                        Voxel m = voxelEntity.Get <Voxel>();
                        if (currentDir == Direction.None || !chase.Filter(m[chase.Coord.Value.Move(currentDir)]))
                        {
                            currentDir = randomValidDirection(m);
                        }
                        chase.Coord.Value = chase.Coord.Value.Move(currentDir);
                    }
                },
                Tasks = new[]
                {
                    checkMap,
                    checkOperationalRadius,
                    new AI.Task
                    {
                        Interval = 1.0f,
                        Action   = delegate()
                        {
                            Agent a = Agent.Query(transform.Position, sightDistance, hearingDistance, x => x.Entity.Type == "Player");
                            if (a != null)
                            {
                                ai.CurrentState.Value = "Alert";
                            }
                        },
                    },
                },
            },
                new AI.AIState
            {
                Name  = "Alert",
                Enter = delegate(AI.AIState previous)
                {
                    chase.EnableMovement.Value = false;
                },
                Exit = delegate(AI.AIState next)
                {
                    chase.EnableMovement.Value = true;
                },
                Tasks = new[]
                {
                    checkMap,
                    checkOperationalRadius,
                    new AI.Task
                    {
                        Interval = 0.4f,
                        Action   = delegate()
                        {
                            if (ai.TimeInCurrentState > 3.0f)
                            {
                                ai.CurrentState.Value = "Idle";
                            }
                            else
                            {
                                Agent a = Agent.Query(transform.Position, sightDistance, hearingDistance, x => x.Entity.Type == "Player");
                                if (a != null)
                                {
                                    ai.TargetAgent.Value  = a.Entity;
                                    ai.CurrentState.Value = "Chase";
                                }
                            }
                        },
                    },
                },
            },
                new AI.AIState
            {
                Name  = "Chase",
                Enter = delegate(AI.AIState previousState)
                {
                    chase.EnablePathfinding.Value = true;
                    chase.Speed.Value             = chaseSpeed;
                },
                Exit = delegate(AI.AIState nextState)
                {
                    chase.EnablePathfinding.Value = false;
                    chase.Speed.Value             = defaultSpeed;
                },
                Tasks = new[]
                {
                    checkMap,
                    checkOperationalRadius,
                    checkTargetAgent,
                    new AI.Task
                    {
                        Interval = 0.07f,
                        Action   = delegate()
                        {
                            Vector3 targetPosition = ai.TargetAgent.Value.Target.Get <Agent>().Position;

                            float targetDistance = (targetPosition - transform.Position).Length();

                            chase.Speed.Value = targetDistance < 15.0f ? closeChaseSpeed : chaseSpeed;

                            if (targetDistance > 50.0f || ai.TimeInCurrentState > 30.0f)                                     // He got away
                            {
                                ai.CurrentState.Value = "Alert";
                            }
                            else if (targetDistance < 4.0f)                                     // We got 'im
                            {
                                // First, make sure we're not near a reset block
                                Voxel v = chase.Voxel.Value.Target.Get <Voxel>();
                                if (VoxelAStar.BroadphaseSearch(v, chase.Coord, 6, x => x.Type == Lemma.Components.Voxel.States.Reset) == null)
                                {
                                    ai.CurrentState.Value = "Crush";
                                }
                            }
                            else
                            {
                                chase.Target.Value = targetPosition;
                            }
                        },
                    },
                },
            },
                new AI.AIState
            {
                Name  = "Crush",
                Enter = delegate(AI.AIState lastState)
                {
                    // Set up cage
                    Voxel.Coord center = chase.Voxel.Value.Target.Get <Voxel>().GetCoordinate(ai.TargetAgent.Value.Target.Get <Agent>().Position);

                    int radius = 1;

                    // Bottom
                    for (int x = center.X - radius; x <= center.X + radius; x++)
                    {
                        for (int z = center.Z - radius; z <= center.Z + radius; z++)
                        {
                            snake.Path.Add(new Voxel.Coord {
                                X = x, Y = center.Y - 4, Z = z
                            });
                        }
                    }

                    // Outer shell
                    radius = 2;
                    for (int y = center.Y - 3; y <= center.Y + 3; y++)
                    {
                        // Left
                        for (int z = center.Z - radius; z <= center.Z + radius; z++)
                        {
                            snake.Path.Add(new Voxel.Coord {
                                X = center.X - radius, Y = y, Z = z
                            });
                        }

                        // Right
                        for (int z = center.Z - radius; z <= center.Z + radius; z++)
                        {
                            snake.Path.Add(new Voxel.Coord {
                                X = center.X + radius, Y = y, Z = z
                            });
                        }

                        // Backward
                        for (int x = center.X - radius; x <= center.X + radius; x++)
                        {
                            snake.Path.Add(new Voxel.Coord {
                                X = x, Y = y, Z = center.Z - radius
                            });
                        }

                        // Forward
                        for (int x = center.X - radius; x <= center.X + radius; x++)
                        {
                            snake.Path.Add(new Voxel.Coord {
                                X = x, Y = y, Z = center.Z + radius
                            });
                        }
                    }

                    // Top
                    for (int x = center.X - radius; x <= center.X + radius; x++)
                    {
                        for (int z = center.Z - radius; z <= center.Z + radius; z++)
                        {
                            snake.Path.Add(new Voxel.Coord {
                                X = x, Y = center.Y + 3, Z = z
                            });
                        }
                    }

                    chase.EnablePathfinding.Value = false;
                    chase.Speed.Value             = crushSpeed;

                    snake.CrushCoordinate.Value = chase.Coord;
                },
                Exit = delegate(AI.AIState nextState)
                {
                    chase.Speed.Value = defaultSpeed;
                    chase.Coord.Value = chase.LastCoord.Value = snake.CrushCoordinate;
                    snake.Path.Clear();
                },
                Tasks = new[]
                {
                    checkMap,
                    checkOperationalRadius,
                    checkTargetAgent,
                    new AI.Task
                    {
                        Interval = 0.01f,
                        Action   = delegate()
                        {
                            Agent a = ai.TargetAgent.Value.Target.Get <Agent>();
                            a.Damage.Execute(0.01f / 1.5f);                                     // seconds to kill
                            if (!a.Active)
                            {
                                ai.CurrentState.Value = "Alert";
                            }
                            else
                            {
                                if ((a.Position - transform.Position.Value).Length() > 5.0f)                                         // They're getting away
                                {
                                    ai.CurrentState.Value = "Chase";
                                }
                            }
                        }
                    }
                },
            }
            );

            this.SetMain(entity, main);

            entity.Add("OperationalRadius", snake.OperationalRadius);
        }
Example #53
0
 //苦涩
 private bool KuseEffect()
 {
     AI.SelectCard(CardId.Jianpanlong, CardId.Jianpanlong, CardId.Xielingwushi, CardId.Xielingwushi, CardId.Xielingwushi);
     return(true);
 }
Example #54
0
 public override void ExitState(AI ai)
 {
     ai.inChaseState = false;
     //ai.chasing = false;
 }
Example #55
0
 //魔王树
 private bool MowangshuEffect()
 {
     AI.SelectCard(CardId.Shiyuan, CardId.Zhicai, CardId.Dizhen, CardId.Huanglei, CardId.Daxian, CardId.Qihuanwang, CardId.Moshujia, CardId.Xielingwushi,
                   CardId.Mohuanghou, CardId.Jingling, CardId.Rongheshu, CardId.Yongchang, CardId.Guichen, CardId.Zhongya, CardId.Huhuan, CardId.Zaidan, CardId.Shiyuan);
     return(true);
 }
Example #56
0
 //遗言
 private bool YiyanEffect()
 {
     AI.SelectCard(CardId.Jianpanlong, CardId.Xielingwushi, CardId.Moshujia, CardId.Bailongqishi);
     AI.SelectPosition(CardPosition.FaceUpDefence);
     return(true);
 }
Example #57
0
        private bool DragonsRebirth()
        {
            List <ClientCard> cards = new List <ClientCard>(Duel.Fields[0].GetMonsters());

            if (cards.Count == 0)
            {
                return(false);
            }
            cards.Sort(AIFunctions.CompareCardAttack);
            ClientCard tributeCard = null;

            foreach (ClientCard monster in cards)
            {
                if (monster.Attack > 2000)
                {
                    return(false);
                }
                if (!monster.IsFacedown() && monster.Race == (int)CardRace.Dragon)
                {
                    tributeCard = monster;
                    break;
                }
            }

            if (tributeCard == null)
            {
                return(false);
            }

            cards = new List <ClientCard>(Duel.Fields[0].Hand);
            cards.AddRange(Duel.Fields[0].Graveyard);
            if (cards.Count == 0)
            {
                return(false);
            }
            cards.Sort(AIFunctions.CompareCardAttack);
            ClientCard summonCard = null;

            for (int i = cards.Count - 1; i >= 0; --i)
            {
                ClientCard monster = cards[i];
                if (monster.Attack < 2300)
                {
                    return(false);
                }
                if (monster.Race == (int)CardRace.Dragon && monster.Id != (int)CardId.HorusTheBlackFlameDragonLv8)
                {
                    summonCard = monster;
                    break;
                }
            }

            if (summonCard == null)
            {
                return(false);
            }

            AI.SelectCard(tributeCard);
            AI.SelectNextCard(summonCard);

            return(true);
        }
Example #58
0
 //水母
 private bool ShuimuEffect()
 {
     AI.SelectCard(CardId.Moshujia);
     AI.SelectNextCard(CardId.Qihuanwang, CardId.Jianpanlong, CardId.Bailongqishi);
     return(true);
 }
Example #59
0
        /// <summary>
        /// Clever enough.
        /// </summary>
        protected bool DefaultDimensionalBarrier()
        {
            const int RITUAL   = 0;
            const int FUSION   = 1;
            const int SYNCHRO  = 2;
            const int XYZ      = 3;
            const int PENDULUM = 4;

            if (Duel.Player != 0)
            {
                List <ClientCard> monsters = Enemy.GetMonsters();
                int[]             levels   = new int[13];
                bool tuner    = false;
                bool nontuner = false;
                foreach (ClientCard monster in monsters)
                {
                    if (monster.HasType(CardType.Tuner))
                    {
                        tuner = true;
                    }
                    else if (!monster.HasType(CardType.Xyz))
                    {
                        nontuner = true;
                    }
                    if (monster.IsOneForXyz())
                    {
                        AI.SelectOption(XYZ);
                        return(true);
                    }
                    levels[monster.Level] = levels[monster.Level] + 1;
                }
                if (tuner && nontuner)
                {
                    AI.SelectOption(SYNCHRO);
                    return(true);
                }
                for (int i = 1; i <= 12; i++)
                {
                    if (levels[i] > 1)
                    {
                        AI.SelectOption(XYZ);
                        return(true);
                    }
                }
                ClientCard l = Enemy.SpellZone[6];
                ClientCard r = Enemy.SpellZone[7];
                if (l != null && r != null && l.LScale != r.RScale)
                {
                    AI.SelectOption(PENDULUM);
                    return(true);
                }
            }
            ClientCard lastchaincard = GetLastChainCard();

            if (LastChainPlayer == 1 && lastchaincard != null && !lastchaincard.IsDisabled())
            {
                if (lastchaincard.HasType(CardType.Ritual))
                {
                    AI.SelectOption(RITUAL);
                    return(true);
                }
                if (lastchaincard.HasType(CardType.Fusion))
                {
                    AI.SelectOption(FUSION);
                    return(true);
                }
                if (lastchaincard.HasType(CardType.Synchro))
                {
                    AI.SelectOption(SYNCHRO);
                    return(true);
                }
                if (lastchaincard.HasType(CardType.Xyz))
                {
                    AI.SelectOption(XYZ);
                    return(true);
                }
                if (lastchaincard.IsFusionSpell())
                {
                    AI.SelectOption(FUSION);
                    return(true);
                }
            }
            foreach (ClientCard card in Duel.ChainTargets)
            {
                if (Card.Equals(card))
                {
                    AI.SelectOption(XYZ);
                    return(true);
                }
            }
            return(false);
        }
Example #60
0
 //祖母
 private bool ZumuEffect()
 {
     AI.SelectCard(CardId.Jianpanlong, CardId.Daxian, CardId.Diannao);
     return(true);
 }