示例#1
0
    void setCharacter()
    {
        abilities = new Ability[numAbilities];
        for (int i = 0; i < numAbilities; i++)
        {
            abilities[i] = data.abilities[i].GetComponent <Ability>();
            abilities[i].InitAbility(this);
            abilities[i].EAwake();
        }
        reloadingTime    = data.reloadingTime;
        reloading        = false;
        actualBullets    = data.totalBullets;
        totalBullets     = data.totalBullets;
        shootingCooldown = data.shootingCooldown;
        shooting         = false;
        shootingTimer    = 0.0f;

        shootCommand  = gameObject.AddComponent <ShootCommand>();
        reloadCommand = gameObject.AddComponent <ReloadCommand>();

        shootCommand.SetShoot(Shoot());
        InputManager.SetInputs("shoot", shootCommand);
        reloadCommand.SetReload(Reload());
        InputManager.SetInputs("reload", reloadCommand);

        InputManager.SetInputs("useAbility_1", abilities[0]);
        InputManager.SetInputs("useAbility_2", abilities[1]);
        InputManager.SetInputs("useAbility_3", abilities[2]);
    }
示例#2
0
文件: Ship.cs 项目: dannyd89/yafbcore
        /// <summary>
        /// Shoots with the ship
        /// </summary>
        protected override void shoot()
        {
            try
            {
                lock (syncShootCommands)
                {
                    if (userShootCommands.Count > 0)
                    {
                        for (int i = 0; i < ship.WeaponProductionStatus && userShootCommands.Count > 0; i++)
                        {
                            ShootCommand shootCommand = userShootCommands.Dequeue();
                            shootCommand.TempSetup(ship, playerShipMapUnit);

                            ship.Shoot(shootCommand.Direction,
                                       shootCommand.Direction.Angle,
                                       shootCommand.Time,
                                       shootCommand.Load,
                                       shootCommand.DamageHull,
                                       shootCommand.DamageShield,
                                       shootCommand.DamageEnergy,
                                       shootCommand.SubDirections);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"{ship.Name}: Shoot Exception");
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                ShootWaiter.Set();
            }
        }
        private static void Main(string[] args)
        {
            ICommand moveCommand  = new MoveCommand();
            ICommand jumpCommand  = new JumpCommand();
            ICommand shootCommand = new ShootCommand();

            InputHandler inputHandler = new InputHandler(moveCommand, jumpCommand, shootCommand);
        }
示例#4
0
        protected override void HandleCommand(ShootCommand shootCmnd)
        {
            Weapon wpn = CurrWeapon();

            if (wpn != null && wpn is RangedWeapon)
            {
                shotThisFrame = (wpn as RangedWeapon).Shoot();
            }
        }
            public override bool IsTransferable(ACommand c)
            {
                ShootCommand command = c as ShootCommand;

                if (command != null)
                {
                    cache.Cached(command, new ShootCommandV10(command.RANGE, command.ANGLE));
                    return(true);
                }
                return(false);
            }
示例#6
0
        public void RangedAttackRangeTest()
        {
            Creature enemy = new Creature(10);

            map[1, 2].putCreature(enemy);

            ICreatureCommand command = new ShootCommand(attacker, deffender, map, new TestRandom(0.1));

            Assert.IsTrue(command.isExecutable());

            command = new ShootCommand(attacker, enemy, map, new TestRandom(0.1));
            Assert.IsFalse(command.isExecutable());
        }
    public UnitCommand Process(IController controller)
    {
        var state = controller.Get;

        if (state.NeedShoot)
        {
            var process = new ShootCommand(_context);
            process.ScreenPosition = new Vector3(state.X, state.Y);
            Debug.Log("PositioN: " + process.ScreenPosition);
            return(process);
        }
        return(null);
    }
示例#8
0
    /// <summary>
    /// Sets and Populates all the Commands with their Methods and KeyCode.
    /// </summary>
    private void SetAndPopulateInput()
    {
        inputManager = new InputManager();
        ShootCommand       shootCommand       = new ShootCommand();
        ThrustCommand      thrustCommand      = new ThrustCommand();
        RotateLeftCommand  rotateLeftCommand  = new RotateLeftCommand();
        RotateRightCommand rotateRightCommand = new RotateRightCommand();

        inputManager.BindInputToCommandWithOrigin(KeyCode.Space, shootCommand, Player.PlayerGO);
        inputManager.BindInputToCommandWithOriginDown(KeyCode.W, thrustCommand, Player.PlayerGO);
        inputManager.BindInputToCommandWithOriginDown(KeyCode.A, rotateLeftCommand, Player.PlayerGO);
        inputManager.BindInputToCommandWithOriginDown(KeyCode.D, rotateRightCommand, Player.PlayerGO);
    }
示例#9
0
        /// <summary>
        /// The method to call to start a shoot attack with the weapon.
        /// </summary>
        public override void Shoot()
        {
            lock (this)
            {
                if (!CurrentWeaponConditionState.CanBeUsed ||
                    LastShot.AddSeconds((double)ShotRate) >= DateTime.UtcNow)
                {
                    return;
                }

                LastShot = DateTime.UtcNow;

                var bulletsForAttack = Math.Min(IsBurstFireEngaged ? 3 : 1, AmmunitionContainer.AmmunitionCount);
                AmmunitionContainer.AmmunitionCount -= bulletsForAttack;
                switch (bulletsForAttack)
                {
                case 3:
                    // Command would create gun fire sound,
                    // bullets and sound, etc. These
                    // could be done asynchronously.
                    // Would prob be best to have M16 burst
                    // fire shoot commands vs. single fire, etc.
                    // for animation purposes instead of calling
                    // ShootCommand 3 times here.
                    ShootCommand.Execute();
                    CurrentWeaponConditionState.WeaponUsed();
                    ShootCommand.Execute();
                    CurrentWeaponConditionState.WeaponUsed();
                    ShootCommand.Execute();
                    CurrentWeaponConditionState.WeaponUsed();
                    break;

                case 2:
                    ShootCommand.Execute();
                    CurrentWeaponConditionState.WeaponUsed();
                    ShootCommand.Execute();
                    CurrentWeaponConditionState.WeaponUsed();
                    break;

                case 1:
                    ShootCommand.Execute();
                    CurrentWeaponConditionState.WeaponUsed();
                    break;

                default:
                    EmptyGunFireCommand.Execute();
                    break;
                }
            }
        }
        private ACommand shootProcess(ShootCommand command, Battlefield.RobotAndBattlefield robotAndBattlefield)
        {
            BattlefieldRobot robot       = robotAndBattlefield.ROBOT;
            Battlefield      battlefield = robotAndBattlefield.BATTLEFIELD;

            Tank tank = robot as Tank;

            if (tank == null)
            {
                return(new ErrorCommand(robot.ROBOT_TYPE + " cannot use shot command."));
            }

            if (tank.GunsToLoad < tank.Gun.BARREL_NUMBER && tank.HitPoints > 0)
            {
                double range = command.RANGE;
                if (range > tank.Gun.MAX_RANGE)
                {
                    range = tank.Gun.MAX_RANGE;
                }
                double toX = range * Math.Cos(AngleUtils.ToRads(command.ANGLE)) + tank.X;
                double toY = range * Math.Sin(AngleUtils.ToRads(command.ANGLE)) + tank.Y;
                battlefield.obstacleManager.ShotChange(battlefield.turn, tank.X, tank.Y, ref toX, ref toY);
                int toLap = (int)Math.Ceiling(range / tank.Gun.SHOT_SPEED) + battlefield.turn;
                lock (battlefield.heapBullet) {
                    if (!battlefield.heapBullet.TryGetValue(toLap, out List <Bullet> bulletList))
                    {
                        bulletList = new List <Bullet>();
                        battlefield.heapBullet.Add(toLap, bulletList);
                    }

                    bulletList.Add(new Bullet(battlefield.turn, toLap, toX, toY, tank));
                }
                int loadAtTurn = battlefield.turn + RELOAD_TIME;
                lock (battlefield.gunLoaded) {
                    if (!battlefield.gunLoaded.TryGetValue(loadAtTurn, out List <Tank> list))
                    {
                        list = new List <Tank>();
                        battlefield.gunLoaded.Add(loadAtTurn, list);
                    }
                    list.Add(tank);
                }

                tank.GunsToLoad++;
                return(new ShootAnswerCommand(true));
            }
            else
            {
                return(new ShootAnswerCommand(false));
            }
        }
 void Update()
 {
     if (shallMoveLeft)
     {
         ICommand moveCommand = new MoveCommand(Direction.left);
         moveCommand.Execute(toControl);
     }
     if (shallMoveRight)
     {
         ICommand moveCommand = new MoveCommand(Direction.right);
         moveCommand.Execute(toControl);
     }
     if (shallShoot)
     {
         ICommand shootCommant = new ShootCommand();
         shootCommant.Execute(toControl);
     }
 }
示例#12
0
        public void SnajperStrzelaGdyGraczWidocznyWZasiegu()
        {
            // arrange
            Creature snajper = TestObjects.GetSimpleCreature(map, player);

            snajper.RangedWeapon = new RangedWeapon()
            {
                Range = 5, Chance = 0.9, Damage = 3
            };
            snajper.AI.Sniper = true;
            map[0, 0].putCreature(player);
            map[0, 5].putCreature(snajper);

            // act
            ICreatureCommand command  = snajper.AI.GenerateNextCommand();
            ShootCommand     sCommand = command as ShootCommand;

            // assert
            Assert.IsInstanceOfType(command, typeof(ShootCommand));
        }
    void Update()
    {
        // Every tick the enemy shall fly downward and into the direction of
        // the player
        if (player != null) {
            float xDistance = player.transform.position.x - this.transform.position.x;

            Direction direction = Direction.left;

            ICommand moveCommand = new MoveCommand(direction);
            moveCommand.Execute(toControl);

            // if distance on the x-axis of this enemies and the players
            // position is smaller than a given range the enemy shall shoot
            if (Mathf.Abs(xDistance) < shootingRange) {
                ICommand shootCommand = new ShootCommand();
                shootCommand.Execute(toControl);
            }
        }
    }
示例#14
0
        public void SpanikowanySnajperStrzelaGdyNieMaGdzieUciec()
        {
            // arrange
            Creature snajperInPanic = TestObjects.GetSimpleCreature(map, player);

            snajperInPanic.RangedWeapon = new RangedWeapon()
            {
                Range = 4, Chance = 0.9, Damage = 3
            };
            snajperInPanic.AI.Sniper        = true;
            snajperInPanic.PanicModeCounter = 10;
            map[1, 3].putCreature(player);
            map[0, 0].putCreature(snajperInPanic);

            // act
            ICreatureCommand command  = snajperInPanic.AI.GenerateNextCommand();
            ShootCommand     mCommand = command as ShootCommand;

            // assert
            Assert.IsInstanceOfType(command, typeof(ShootCommand));
        }
    void Update()
    {
        // Every tick the enemy shall fly downward and into the direction of
        // the player
        if (player != null)
        {
            float xDistance = player.transform.position.x - this.transform.position.x;

            Direction direction = Direction.left;

            ICommand moveCommand = new MoveCommand(direction);
            moveCommand.Execute(toControl);

            // if distance on the x-axis of this enemies and the players
            // position is smaller than a given range the enemy shall shoot
            if (Mathf.Abs(xDistance) < shootingRange)
            {
                ICommand shootCommand = new ShootCommand();
                shootCommand.Execute(toControl);
            }
        }
    }
示例#16
0
        public string Run()
        {
            ICommand command;

            var currentActiveWorm = gameState.MyPlayer.Worms.FirstOrDefault(x => x.Id == gameState.CurrentWormId);

            if (currentActiveWorm == null)
            {
                throw new InvalidWormIdException(
                          $"Could not find Worm with id={gameState.CurrentWormId} the worm does not exist or an invalid id was used.");
            }

            var opponentWorms = gameState.Opponents.First().Worms.Where(worm => worm.Health > 0);

            var opponentWormsInRangeOfActiveWorm =
                GetOpponentWormsInRangeOfActiveWorm(opponentWorms, currentActiveWorm);

            var opponentWormsWithoutObstaclesInRange =
                GetOpponentWormsWithoutObstacles(opponentWormsInRangeOfActiveWorm, currentActiveWorm);

            if (opponentWormsWithoutObstaclesInRange.Any())
            {
                var targetWorm    = opponentWormsWithoutObstaclesInRange.First();
                var shotDirection = GetShootDirection(targetWorm, currentActiveWorm);

                command = new ShootCommand()
                {
                    Direction = shotDirection
                };
            }
            else
            {
                command = GetRandomCommand(currentActiveWorm);
            }


            return(command?.RenderCommand());
        }
示例#17
0
    List <Command> BuildCommandLists(GameObject player, Transform content)
    {
        Transform      _enemy = player == this.player ? enemy.transform : this.player.transform;
        List <Command> list   = new List <Command>();

        foreach (Transform headCmd in content)
        {
            List <Command> lst      = null;
            Transform      cmdObj   = headCmd;
            Command        cmdClass = null;
            while (true)
            {
                switch (cmdObj.name)
                {
                // Movement
                case "Move(Clone)": cmdClass = new MoveCommand(player, Convert.ToInt32(cmdObj.GetArgs()[0])); break;

                case "TurnR(Clone)": cmdClass = new TurnCommand(player, -Convert.ToSingle(cmdObj.GetArgs()[0])); break;

                case "TurnL(Clone)": cmdClass = new TurnCommand(player, Convert.ToSingle(cmdObj.GetArgs()[0])); break;

                // Actions
                case "Shoot(Clone)": cmdClass = new ShootCommand(player, bulletPrefab); break;

                case "Look at enemy(Clone)": cmdClass = new TurnCommand(player, _enemy); break;

                // Events

                /*case "OnStart(Clone)":
                 *  lst = new List<Command>();
                 *  player.GetComponent<Player>().OnStart += () => HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name)); break;*/
                case "OnCollisionWithBullet(Clone)":
                    lst = new List <Command>();
                    player.GetComponent <Player>().OnCollisionWithBullet += () => HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name)); break;

                case "OnCollisionWithPlayer(Clone)":
                    lst = new List <Command>();
                    player.GetComponent <Player>().OnCollisionWithPlayer += () => HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name)); break;

                case "OnSuccessfulHit(Clone)":
                    lst = new List <Command>();
                    _enemy.GetComponent <Player>().OnCollisionWithBullet += () => HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name)); break;

                case "OnTimer(Clone)":
                    lst = new List <Command>();
                    player.GetComponent <Player>().OnTimer += () =>
                    {
                        if (player.GetComponent <Player>().secondsAlive % Convert.ToInt32(headCmd.GetArgs()[1]) == 0)
                        {
                            HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name));
                        }
                    }; break;

                case "OnChangeHP(Clone)":
                    lst = new List <Command>();
                    player.GetComponent <Player>().OnChangeHP += () =>
                    {
                        if (player.GetComponent <Player>().HP == Convert.ToInt32(headCmd.GetArgs()[1]))
                        {
                            HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name));
                        }
                    }; break;

                case "OnCollisionWithBounds(Clone)":
                    lst = new List <Command>();
                    player.GetComponent <Bounds>().OnCollisionWithBounds += () => HandleEvent(player, new Thread(this, lst, false, Convert.ToInt32(headCmd.GetArgs()[0]), headCmd.name)); break;
                }
                if (lst == null)
                {
                    list.Add(cmdClass);
                }
                else if (cmdClass != null)
                {
                    lst.Add(cmdClass);
                }
                Transform next = cmdObj.Next();
                if (next == null)
                {
                    break;
                }
                else
                {
                    cmdObj = next;
                }
            }
        }
        return(list);
    }
示例#18
0
 protected virtual void HandleCommand(ShootCommand shootCmnd)
 {
 }
 public AttackState(EnemyController owner)
 {
     this.owner   = owner;
     shootCommand = new FastShootCommand(owner.SpawnLocation, owner.ShootForce);
 }
示例#20
0
        public void UserInput()
        {
            // Clear the previous command
            UserCommand = null;

            if (Console.KeyAvailable)
            {
                // Catch key event but don't display it
                var key = Console.ReadKey(intercept: true).Key;

                // Hold key fix
                while (Console.KeyAvailable)
                {
                    Console.ReadKey(intercept: true);
                }

                // Keys for lanes
                var laneKeys = new List <ConsoleKey>()
                {
                    ConsoleKey.D1,
                    ConsoleKey.D2,
                    ConsoleKey.D3,
                    ConsoleKey.D4,
                    ConsoleKey.D5,
                    ConsoleKey.D6,
                    ConsoleKey.D7,
                    ConsoleKey.D8,
                    ConsoleKey.D9,
                    ConsoleKey.D0,
                };

                var laneIndex = laneKeys.IndexOf(key);

                IUserCommand command = null;

                if (0 <= laneIndex && laneIndex < Level.Lanes.Count)
                {
                    if (!Level.Menu.IsMenuLocked)
                    {
                        var replacementBullet = RandomBullet();
                        var bullet            =
                            Level.Menu.UseBullet(
                                replacementBullet);

                        command = new ShootCommand(
                            laneIndex, bullet);
                    }
                }
                else
                {
                    // Handle the other keys
                    switch (key)
                    {
                    case ConsoleKey.Spacebar:
                        var replacementBullet =
                            RandomBullet();
                        command =
                            new DiscardBulletCommand(
                                replacementBullet);
                        break;

                    default:
                        break;
                    }
                }

                // Set the new command,
                // null if no command
                UserCommand = command;
            }
        }
示例#21
0
 // Start is called before the first frame update
 protected virtual void Start()
 {
     shootCommand = new ShootCommand(transform, shootForce);
 }
示例#22
0
        public List <Entity> Simulate(List <PlayerCommand> input)
        {
            // handle user ticks here
            foreach (var cmd in input)
            {
                var targetIndex = entities.FindIndex(q => q.name == cmd.targetID);

                if (targetIndex != -1)
                {
                    Ship target = (Ship)entities[targetIndex];

                    if (cmd is MoveCommand)
                    {
                        MoveCommand parsedCmd = (MoveCommand)cmd;
                        target.Velocity += parsedCmd.Force;
                    }
                    if (cmd is ShootCommand)
                    {
                        ShootCommand parsedCmd = (ShootCommand)cmd;
                        var          bullet    = new Bullet();

                        string uniqueBulletName = target.name + "_bullet_";

                        var bulletsfromsameship = entities
                                                  .Where(q => q is Bullet)
                                                  .Select(q => q as Bullet)
                                                  .Where(q => q.origin == target.name)
                                                  .Select(q => q.name)
                                                  .ToList();

                        int indexer = 0;
                        while (bulletsfromsameship.Contains(uniqueBulletName + indexer.ToString()))
                        {
                            indexer++;
                        }

                        bullet.name = uniqueBulletName + indexer.ToString();

                        bullet.origin   = target.name;
                        bullet.Velocity = target.Velocity + (parsedCmd.Direction * parsedCmd.Power);
                        bullet.pos      = target.pos;
                        entities.Add(bullet);
                    }
                    if (cmd is ShieldCommand)
                    {
                        throw new NotImplementedException();
                    }
                }
            }

            var Movables = entities
                           .Where(q => q is MovingEntity)
                           .Select(q => q as MovingEntity)
                           .ToList();

            foreach (var item in Movables)
            {
                ApplyWorldForces(item);
            }

            foreach (var item in Movables)
            {
                MoveFromVelocity(item);
            }

            return(entities);
        }