Exemplo n.º 1
0
 void OnEnable()
 {
     base.OnEnable();
     botController = GetComponentInParent <BotController>();
     animator      = GetComponentInParent <Animator>();
     moveTransform = botController.transform;
 }
Exemplo n.º 2
0
        private void Awake()
        {
            Instance = this;

            Player = GameObject.FindGameObjectWithTag("Player").transform;

            SaveDataRepository = new SaveDataRepository();

            ObjectManager = new ObjectManager();

            PlayerController = new PlayerController(new UnitMotor(Player));
            _updates.Add(PlayerController);

            FlashLightController = new FlashLightController();
            _updates.Add(FlashLightController);

            InputController = new InputController();
            _updates.Add(InputController);

            ObjectDetectorController = new ObjectDetectorController(Camera.main);
            _updates.Add(ObjectDetectorController);

            WeaponController = new WeaponController();
            _updates.Add(WeaponController);

            BotController = new BotController();
            _updates.Add(BotController);
        }
Exemplo n.º 3
0
 public BehaviorData(bool logical)
 {
     this.type    = ReturnType.LOGICAL;
     this.logical = logical;
     this.number  = this.logical ? 1 : 0;
     this.bot     = null;
 }
Exemplo n.º 4
0
 public BehaviorData(float number)
 {
     this.type    = ReturnType.NUMBER;
     this.number  = number;
     this.logical = this.number != 0;
     this.bot     = null;
 }
Exemplo n.º 5
0
    void GetNextBot()
    {
        int tmpIndex = arrayBotController.Count;

        while (tmpIndex > 0)
        {
            tmpIndex--;

            if (indexBot > arrayBotController.Count - 1)
            {
                indexBot = 0;
            }

            if (playerState == PlayerState.FollowBot)
            {
                botController = arrayBotController[indexBot];
                botController.ChangeState(5);//"PlayerFollow"
                return;
            }

            indexBot++;
        }

        {
            ChangePlayerState(1);//Spectator
        }
    }
Exemplo n.º 6
0
 private BehaviorData()
 {
     this.type    = ReturnType.EMPTY;
     this.logical = false;
     this.number  = 0;
     this.bot     = null;
 }
Exemplo n.º 7
0
        public async Task PatchBot()
        {
            var controller = new BotController(Manager, new AdminManager(Context, LogUtils.FakeLogger <AdminManager>()), User);
            var bot        = await PostTestBot(controller);

            var res = await controller.PatchAsync(bot.Id, new Models.Input.Admin.BotUpdate()
            {
                ProfileMsg = "Updated message"
            }) as JsonResult;

            var obj = res.Value as Models.Output.Bot;

            Assert.AreEqual("MyBot", obj.FirstName);
            Assert.AreEqual("mybot@wikilibs", obj.Email);
            Assert.AreEqual("mybot", obj.Pseudo);
            Assert.IsFalse(obj.Private);
            Assert.AreEqual("Updated message", obj.ProfileMsg);
            Assert.IsTrue(obj.LastName == null || obj.LastName.Length <= 0);
            Assert.AreEqual(0, obj.Points);
            Assert.IsNotNull(obj.Secret);
            Assert.IsNotEmpty(obj.Secret);
            Assert.AreEqual(24, obj.Secret.Length);
            Assert.AreNotEqual(obj.Secret, bot.Secret);
            User.SetPermissions(new string[] { });
            Assert.ThrowsAsync <Shared.Exceptions.InsuficientPermission>(() => controller.PatchAsync(null, null));
        }
Exemplo n.º 8
0
    public void ShootPlayer()
    {
        if (GameManager.self.scoreManager.TotalShotsAmount > 0)
        {
            GameObject    obj           = Instantiate(Stickman, transform.position, Quaternion.identity);
            BotController botController = obj.GetComponent <BotController>();
            botControllers.Add(botController);

            GameManager.self.scoreManager.PlayerShooted();

            if (GameManager.self.scoreManager.TotalShotsAmount == 0)
            {
                botController.LastStickman();
            }

#if UNITY_IOS
            if (GameManager.TapticEnabled)
            {
                TapticEngine.TriggerLight();
            }
#endif
        }


        anim.Play(GameManager.self.StringToHashes[49], -1, 0);
    }
Exemplo n.º 9
0
    public void MissileAudio(string botName)
    {
        GameObject    bot    = GameObject.Find(botName);
        BotController target = bot.GetComponent <BotController>();

        target.audioSource.PlayOneShot(target.specialAbilitySound);
    }
    public void Initialize(Player player)
    {
        //transform.SetParent(GameManager.instance.imageTarget.transform);
        transform.SetParent(GameManager.instance.grid.transform, false);

        photonPlayer = player;
        id           = player.ActorNumber;
        GameManager.instance.players[id - 1] = this;


        if (player.IsMasterClient)
        {
            setTurn(true); //if the player is the first in the list, then the game starts with them being the active player
        }
        else
        {
            setTurn(false);
        }

        foreach (Transform child in transform)
        {
            BotController botScript = child.GetComponent <BotController>();
            botScript.InitializeBot();
        }
        EndTurnButton = GetComponent <Button>();
        grid          = GameManager.instance.grid;


        //GameOver
        AssignClock(player);
    }
Exemplo n.º 11
0
    public IEnumerator Damage(string botName, float bonusDamage, float normalDamage)
    {
        yield return(new WaitForSeconds(0.5f));

        GameObject    bot    = GameObject.Find(botName);
        BotController target = bot.GetComponent <BotController>();

        target.updatingHealth = true;

        //print(target.health);

        //Half damage taken if player has entered guard

        if (target.guardMode && normalDamage > 0)
        {
            target.health   -= (bonusDamage + normalDamage) / 2;
            target.guardMode = false;
        }
        else
        {
            target.health -= bonusDamage + normalDamage;
            if (target.health > target.maxHealth)
            {
                target.health = target.maxHealth;
            }
        }
    }
Exemplo n.º 12
0
    public void DeathAudio(string botName)
    {
        GameObject    bot    = GameObject.Find(botName);
        BotController target = bot.GetComponent <BotController>();

        target.audioSource.PlayOneShot(target.deathSound);
    }
    public override void UpdateState(BotController bot)
    {
        var player = GameManager.Instance.Player;

        if (player == null || player.IsDead)
        {
            return;
        }


        if (Vector3.Distance(player.transform.position, m_LastPlayerPos) > 5f)
        {
            bot.SetPathDestination(player.transform.position);
        }

        m_LastPlayerPos = player.transform.position;

        bot.ShootDirection = player.transform.position - bot.transform.position;

        // Square distance calculation is faster and efficient
        if (bot.ShootDirection.sqrMagnitude < bot.maxShootDist * bot.maxShootDist)
        {
            bot.Shoot();
        }
    }
    public override void OnStateChanged(BotController bot, BotState previousState)
    {
        Vector3 wp = bot.GetRandomWaypoint();

        bot.SetPathDestination(wp); // Set a random waypoint as destination
        bot.StoppingDistance = bot.waypointSkipDist;
    }
    public override void UpdateState(BotController bot)
    {
        var player = GameManager.Instance.Player;

        if (player == null || player.IsDead)
        {
            return;
        }

        bot.ResetWaypoints(); // We'll be using all the waypoints
        float   minDotValue = float.MaxValue;
        Vector3 targetWP    = bot.transform.position;

        bot.ForEachWaypoint(wp => // Get a waypoint that is in opposite direction to that of player
        {
            float dot = Vector3.Dot(wp - bot.transform.position, player.transform.position - bot.transform.position);
            if (dot < minDotValue)
            {
                minDotValue = dot;
                targetWP    = wp;
            }
        });

        bot.SetPathDestination(targetWP);

        bot.ShootDirection = player.transform.position - bot.transform.position;

        // Square distance calculation is faster and efficient
        if (bot.ShootDirection.sqrMagnitude < bot.maxShootDist * bot.maxShootDist)
        {
            bot.Shoot();
        }
    }
Exemplo n.º 16
0
 public BehaviorData(BotController bot)
 {
     this.type    = ReturnType.BOT;
     this.bot     = bot;
     this.logical = this.bot != null;
     this.number  = 0;
 }
Exemplo n.º 17
0
        public static void Run()
        {
            var players = new[]
            {
                Player.CreateCustom("TrickBoy1", new MaxTrickBoy()),
                Player.CreateCustom("O1", new Opportunist()),
                Player.CreateCustom("TrickBoy2", new MaxTrickBoy()),
                Player.CreateCustom("O1", new Opportunist()),
                Player.CreateCustom("O1", new Opportunist()),
                Player.CreateCustom("O1", new Opportunist()),
            };

            for (int repeat = 0; repeat <= 10; repeat++)
            {
                var scoreTracker = new ScoreTracker();
                // scoreTracker.PrintHeader(players);
                for (int games = 0; games < 1000; games++)
                {
                    var gameDef = new EumelGameRoomDefinition(
                        "the game",
                        players.Select(p => p.Info).ToImmutableList().WithValueSemantics(),
                        EumelGamePlan.For(players.Length),
                        new GameRoomSettings(0)
                        );
                    var botController = new BotController(players.Select(p => p.Invocable), gameDef);
                    var room          = new ActiveLobby(botController, gameDef, GameProgress.NotStarted);
                    room.SubscribeWithPreviousEvents(scoreTracker);
                    while (room.HasMoreRounds)
                    {
                        room.StartNextRound();
                    }
                }
                Console.WriteLine("Total scores: " + string.Join(", ", Enumerable.Zip(players.Select(p => p.Info.Name), scoreTracker.Scores)));
            }
        }
        public static async Task Handler(ControllerActionContext controllerActionContext)
        {
            var           serv       = controllerActionContext.UpdateContext.Services;
            var           factory    = serv.GetRequiredService <IControllersFactory>();
            BotController controller = factory.Create(controllerActionContext);
            //Invoke initializer.
            await BotController.InvokeInitialize(controller, controllerActionContext);

            var methodInfo = controllerActionContext.ActionDescriptor.MethodInfo;

            //Model binding.
            var modelBindingContext = new ModelBindingContext(controllerActionContext);
            var mainModelBinder     = serv
                                      .GetRequiredService <IMainModelBinderProvider>().MainModelBinder;
            await mainModelBinder.Bind(modelBindingContext);

            controllerActionContext.IsModelStateValid = modelBindingContext.IsAllBinded();
            var invokationParams = modelBindingContext.ToMethodParameters();

            //Invoke.
            var methodResult = methodInfo.Invoke(controller, invokationParams);

            if (methodResult is Task task)
            {
                await task;
            }

            //Invoke finished.
            await BotController.InvokeProcessed(controller);
        }
Exemplo n.º 19
0
 // Start is called before the first frame update
 void Start()
 {
     sensor     = GetComponentInParent <BotSensor>();
     controller = GetComponentInParent <BotController>();
     enemyLayer = sensor.GetEnemyLayer();
     timer      = GetCoolDown();
 }
Exemplo n.º 20
0
    // Returns nth target or last target if less than n total or first target if n is less than 1 or null if there were no targets
    public static BotController NthTarget(int n, string targetingPriority, BotController myself)
    {
        List <BotController> targets = Targets(targetingPriority, myself);
        int working_n = Mathf.Clamp(n, 1, targets.Count); // Clamp n between "1st" and "last"

        return(targets.Count > 0 ? targets[working_n - 1] : null);
    }
Exemplo n.º 21
0
    public override void ProcessAction(BotController botController)
    {
        if (botController.botAction == action)
        {
            targetPosition = botController.thisTransform.position;

            if (readyAction == true)
            {
                base.ProcessAction();

                processAction = 10;

                botController.health += repearPower * Time.deltaTime;

                foreach (ModulBasys modul in botController.modulController)
                {
                    RepearModul(modul, repearPower);
                    modul.ReloadWeapon();
                }

                if (botController.health >= 100)
                {
                    botController.health    = 100;
                    botController.botAction = SM_BotAction.None;
                }
            }
        }
    }
Exemplo n.º 22
0
 private bool canAccessMemory(BotController bc, int memoryLocation, Type type)
 {
     return(option == Option.LOAD &&
            bc.memory.ContainsKey(memoryLocation) &&
            bc.memory[memoryLocation].GetType() == type
            );
 }
Exemplo n.º 23
0
    public override void doAction(ProcessContext context)
    {
        int[] paramIndices   = getParameterIndices(context);
        int   param1         = paramIndices[0];
        int   memoryLocation = (int)context.instruction(param1)
                               .instructionToNumber(context.context(param1));
        BotController bc = context.botController;

        switch (option)
        {
        case Option.STORE:
            int    param2      = paramIndices[1];
            object storeObject = context.instruction(param2)
                                 .getReturnObject(context.context(param2));
            if (!bc.memory.ContainsKey(memoryLocation))
            {
                bc.memory.Add(memoryLocation, storeObject);
            }
            else
            {
                bc.memory[memoryLocation] = storeObject;
            }
            Debug.Log("Stored[" + memoryLocation + "]: " + bc.memory[memoryLocation]);
            break;

        case Option.ERASE:
            bc.memory.Remove(memoryLocation);
            break;
        }
    }
    public override int fire(BotController bc)
    {
        int x = getInput();
        int y = getInput();

        return(x - y);
    }
Exemplo n.º 25
0
 public PursueStrategy(BotController controller, Vector3 destination)
     : base(controller)
 {
     Path path = BotController.Character.World.FindPath(BotController.Character.Position, destination);
     if (path != null && path.NodeCount > 0)
         Target = path.PathNodes[0];
 }
Exemplo n.º 26
0
    public void PlayHealEffect(string botName)
    {
        GameObject    bot    = GameObject.Find(botName);
        BotController target = bot.GetComponent <BotController>();

        target.healEffect.Play();
    }
Exemplo n.º 27
0
 public void doAttack(BotController bot, AnimationClip attackAnimation)
 {
     this.attackAnimation = attackAnimation;
     if (bot != null) {
         impactBot(bot, attackAnimation);
     }
 }
Exemplo n.º 28
0
        public async Task StooqSourceAsyncTest()
        {
            // Change         : Jobcity request to read data directly from api.
            // Change Date    : 2020/01/21
            // Arrange
            var services = new ServiceCollection();

            services.AddMemoryCache();
            var serviceProvider = services.BuildServiceProvider();
            var memoryCache     = serviceProvider.GetService <IMemoryCache>();
            var controller      = new BotController(_mockLogger.Object, memoryCache, _mockWebHosting.Object);

            // Act
            var actionResult = await controller.ResponseMsgAsync(_mockEntity);


            // Assert
            Xunit.Assert.NotNull(actionResult);
            var response = Xunit.Assert.IsAssignableFrom <OkObjectResult>(actionResult);

            Xunit.Assert.NotNull(response);
            Xunit.Assert.Equal((int)HttpStatusCode.OK, response.StatusCode.Value);
            Xunit.Assert.NotNull(response.Value);
            var     json = JsonConvert.SerializeObject(response.Value, Formatting.Indented);
            JObject jo   = JObject.Parse(json);

            Xunit.Assert.StartsWith("AAPL.US quote is $265.8 per share.", jo["Data"].ToString());
        }
Exemplo n.º 29
0
    // Side Detonator Attack
    public void BlackHoleAttack()
    {
        // Detect enemy in range of attack.
        Collider2D enemyCollider2D = Physics2D.OverlapCircle(attackPoint.position,
                                                             attackRange,
                                                             enemyLayers);

        if (enemyCollider2D && isRunning)
        {
            if (!IsPartCoolingDown())
            {
                ResetCooldownTimer();

                Debug.Log(enemyCollider2D.name + " was attacked by Black Hole part.");
                // TODO: Play the Black Hole attack animation.

                // Pull opponent rapidly toward player
                BotController controller = enemyCollider2D.GetComponentInParent <BotController>();
                BotSensor     sensor     = enemyCollider2D.GetComponentInParent <BotSensor>();
                if (controller != null)
                {
                    Vector2 direction = sensor.GetPosition() - transform.position;
                    controller.ApplyForce(-1 * (direction.normalized * pullStrength));
                }
            }
        }
    }
Exemplo n.º 30
0
        public async Task ResponseMsgAsyncTestAsync()
        {
            // Arrange
            var services = new ServiceCollection();

            services.AddMemoryCache();
            var serviceProvider = services.BuildServiceProvider();

            var memoryCache = serviceProvider.GetService <IMemoryCache>();

            var controller = new BotController(_mockLogger.Object, memoryCache, _mockWebHosting.Object);

            // Act

            var actionResult = await controller.ResponseMsgAsync(_mockEntity);


            // Assert
            Xunit.Assert.NotNull(actionResult);
            var response = Xunit.Assert.IsAssignableFrom <OkObjectResult>(actionResult);

            Xunit.Assert.NotNull(response);
            Xunit.Assert.Equal((int)HttpStatusCode.OK, response.StatusCode.Value);
            Xunit.Assert.NotNull(response.Value);
        }
    // Side Detonator Attack
    public void SelfDetonatorAttack()
    {
        // Detect enemy in range of attack.
        Collider2D enemyCollider2D = Physics2D.OverlapCircle(attackPoint.position,
                                                             attackRange,
                                                             enemyLayers);

        if (enemyCollider2D)
        {
            Debug.Log(enemyCollider2D.name + " was attacked by self detonator part.");
            // TODO: Play the side detonator attack animation.
            // TODO: Implement damage to enemy health. (Use separate class?)
            // TODO: Implement small damage to player health. (Use separate class?)

            // Knockback opponent
            BotController controller = enemyCollider2D.GetComponentInParent <BotController>();
            BotSensor     sensor     = enemyCollider2D.GetComponentInParent <BotSensor>();
            if (controller != null)
            {
                Vector2 direction = sensor.GetPosition() - transform.position;
                controller.ApplyForce((direction.normalized * knockBackStrength)
                                      + (new Vector2(0.0f, upwardForce)));
            }
        }
    }
Exemplo n.º 32
0
 void OnEnable()
 {
     base.OnEnable();
     botController             = GetComponentInParent <BotController>();
     botController.pointSniper = transform.FindChild("PointSniper");
     FindBodyTarget();
 }
Exemplo n.º 33
0
 public RoamStrategy(BotController botController)
     : base(botController)
 {
     Vector3? destination = BotController.Character.World.GetClosestVertex(BotController.Character.Position);
     if (!destination.HasValue)
         throw new InvalidOperationException("Unable to find direct vertex for roaming.");
     this.Destination = destination.Value;
     PreviousDestination = BotController.Character.Position;
 }
Exemplo n.º 34
0
 private void impactBot(BotController opponent, AnimationClip attackAnimation)
 {
     // Impact
     bool attackQualifies = GetComponent<Animation>()[attackAnimation.name].time > GetComponent<Animation>()[attackAnimation.name].length * impactTime
         && GetComponent<Animation>()[attackAnimation.name].time < GetComponent<Animation>()[attackAnimation.name].length * impactEndTime;
     if (attackQualifies && !impacted && this.inRangeWithPosition(opponent.transform.position)) {
         opponent.knockbackFrom(transform.forward);
         impacted = false;
         Debug.Log("hit bot!");
     }
 }
Exemplo n.º 35
0
 public AttackStrategy(BotController controller, Character enemy, BodyCollider visibleCollider)
     : base(controller, enemy, visibleCollider)
 {
 }
Exemplo n.º 36
0
 public WaitStrategy(BotController controller, Vector3 lastSeen)
     : base(controller)
 {
     this.LastSeen = lastSeen;
 }
 public EnemyInteractionStrategy(BotController controller, Character enemy, BodyCollider visibleCollider)
     : base(controller)
 {
     this.Enemy = enemy;
     this.VisibleCollider = visibleCollider;
 }
Exemplo n.º 38
0
 public Strategy(BotController botController)
 {
     this.BotController = botController;
 }
Exemplo n.º 39
0
 public ReactionDelayStrategy(BotController controller, Character enemy, BodyCollider visibleCollider)
     : base(controller, enemy, visibleCollider)
 {
 }
Exemplo n.º 40
0
 public EmptyStrategy(BotController botController)
     : base(botController)
 {
 }