Esempio n. 1
0
    public void SpawnNewFormation(Vector3 spawnLocation = new Vector3())
    {
        formation = currentArea.battleFormations.GetRandom();

        int level = Game.Instance.PlayerParty.Level - formation.levelLowerThanPlayer;

        if (level <= 0)
        {
            level = 1;
        }
        enemyParty.ForceLevel(level);

        for (int i = 0; i < formation.enemies.Count; i++)
        {
            if (formation.enemies[i].minimumPlayerCharacters > Game.Instance.PlayerParty.characters.Count)
            {
                continue;
            }

            GameObject    go = ObjectPooler.Instance.SpawnFromPool(formation.enemies[i].enemy.tag, enemyParty.transform, spawnLocation, Quaternion.identity);
            CharacterBase cb = go.GetComponent <CharacterBase>();
            cb.Lane       = formation.enemies[i].lane;
            cb.IsDead     = false;
            cb.IsBlocking = false;
            go.GetComponent <Transform>().localScale = Vector3.one;
            go.name = formation.enemies[i].enemy.prefab.GetComponent <CharacterBase>().stats.characterName + " " + letters[i];
        }
    }
Esempio n. 2
0
    //解析战前阵型信息
    private BattleFormationCard[] parseBattleFormation(ErlArray arr)
    {
        //只有是自己阵型才可以为空
        if (arr == null || arr.Value.Length < 1)
        {
            if (flag)
            {
                return(null);
            }
            return(parseMyCards(null));
        }
        int max = arr.Value.Length;

        BattleFormation[] bfs = new BattleFormation[max];
        for (int i = 0; i < max; i++)
        {
            ErlArray erlArr = arr.Value [i] as ErlArray;

            bfs [i]       = new BattleFormation();
            bfs [i].id    = erlArr.Value [0].getValueString();
            bfs [i].hp    = StringKit.toInt(erlArr.Value [1].getValueString());
            bfs [i].maxHp = StringKit.toInt(erlArr.Value [2].getValueString());
        }
        return(parseMyCards(bfs));
    }
Esempio n. 3
0
    public void init(string id)
    {
        taskId = id;


        if (taskId == "random")
        {
            Dictionary <string, TaskItem> requireDic = BattleFormation.getRanTaskFishList();
            foreach (string key in requireDic.Keys)
            {
                TaskItem item = requireDic[key];
                requireList.Add(item.item_id, item);
            }
        }
        else
        {
            TaskItemSpec spec = getTaskSpec();

            List <OwnedItem> specrequireList = spec.getRequireList();
            foreach (OwnedItem item in specrequireList)
            {
                TaskItem item1 = new TaskItem();
                item1.item_id  = item.item_id;
                item1.finished = 0;
                item1.total    = item.count;

                requireList.Add(item.item_id, item1);
            }
        }
        creatRewards();
        setSaveData();
    }
Esempio n. 4
0
        /* isp ActivateFormation()
         *
         * Input variables:
         * battleFormation =
         * battleFormationType =
         *
         * State variables:
         *
         *
         */
        public void ActivateFormation(BattleFormation battleFormation, BattleFormationType battleFormationType)
        {
            if (battleFormation is null)
            {
                throw new ArgumentNullException(nameof(BattleFormation));
            }
            if (battleFormation.GeneralInCharge == null)
            {
                var article = battleFormationType == BattleFormationType.Offensive ? "an" : "a";
                throw new InvalidOperationException($"A general must be assigned in charge of {battleFormation.Name} formation in your '{Name}' planet to activate it as {article} {battleFormationType.ToString().ToLower()} formation");
            }
            var formation = Formations.SingleOrDefault(f => f.Equals(battleFormation));

            if (formation == null)
            {
                throw new ArgumentException("Formation does not exist");
            }
            if (battleFormationType == BattleFormationType.Offensive)
            {
                battleFormation.SetStatus(true);
                ActiveOffensiveFormation = battleFormation;
            }

            if (battleFormationType == BattleFormationType.Defensive)
            {
                battleFormation.SetStatus(true);
                ActiveDefensiveFormation = battleFormation;
            }
        }
Esempio n. 5
0
        public float CalcArrowedDensity(BattleFormation rangers, Rect arrowed, BattleFormation targets, float heightRanger, float heightTarget)
        {
            var shootSquer     = CalcArrowedSquer(rangers, heightRanger, heightTarget);
            var densityOfShoot = rangers.Soldiers * shootSquer.Squer / arrowed.Squer;

            return(densityOfShoot / CalcOverArrowedAmount(arrowed, targets));
        }
    void beginNextWave()
    {
        timer = 0;
        string bgmName = "bgm_1";

        isOuting = false;

        if (BattleMode == BattleFormation.RandomMode)
        {
            BattleMode = BattleFormation.ArrowMode;
            bgmName    = "bgm_4";
        }
        else if (BattleMode == BattleFormation.BossMode)
        {
        }
        else if (BattleMode == BattleFormation.MissionMode)
        {
        }
        else
        {
            BattleMode = BattleFormation.RandomMode;
        }
        wave.SetActive(true);

        fishList = BattleFormation.getFishList(BattleMode);

        Camera.main.GetComponent <AudioSource> ().clip = AudioController.getClip(bgmName);
        Camera.main.GetComponent <AudioSource> ().Play();

        AudioController.PlaySound(AudioController.SOUND_BATTLER);
    }
Esempio n. 7
0
        /* isp AddFormation()
         *
         * Input variables:
         * battleFormation =
         *
         * State variables:
         *
         *
         */

        public void AddFormation(BattleFormation battleFormation)
        {
            if (battleFormation is null)
            {
                throw new ArgumentNullException(nameof(BattleFormation));
            }
            Formations?.Add(battleFormation);
        }
Esempio n. 8
0
 /* isp ExistsFormation()
  *
  * Input variables:
  * battleFormation =
  *
  * State variables:
  *
  *
  */
 public bool ExistsFormation(BattleFormation battleFormation)
 {
     if (battleFormation is null)
     {
         throw new ArgumentNullException(nameof(BattleFormation));
     }
     return(Formations?.SingleOrDefault(f => f.Equals(battleFormation)) != null);
 }
Esempio n. 9
0
    //解析战前阵型信息
    private BattleFormationCard[] parseBattleFormation(ErlArray arr, bool isMine)
    {
        //只有是自己阵型才可以为空
        if (arr.Value.Length < 1)
        {
            if (isMine)
            {
                return(parseMyCards(null));
            }
            else
            {
                return(null);
            }
        }
        BattleFormation[] bfs;
        if (!isMine)
        {
            int max = 15;
            bfs = new BattleFormation[15];
            for (int i = 0; i < max; i++)
            {
                ErlArray erlArr = arr.Value [i] as ErlArray;
                if (erlArr == null || erlArr.Value.Length < 1)
                {
                    continue;
                }
                ErlArray array1 = erlArr.Value [0] as ErlArray;                //主力 如果erlArr 数组长度大于1 则后面的部分是替补

                if (array1 != null || array1.Value.Length < 1)
                {
                    bfs [i]       = new BattleFormation();
                    bfs [i].id    = array1.Value [0].getValueString();
                    bfs [i].hp    = StringKit.toInt(array1.Value [1].getValueString());
                    bfs [i].maxHp = StringKit.toInt(array1.Value [2].getValueString());
                    bfs [i].lv    = StringKit.toInt(array1.Value [3].getValueString());
                }
            }
        }
        else
        {
            int max = arr.Value.Length;
            bfs = new BattleFormation[max];
            for (int i = 0; i < max; i++)
            {
                ErlArray erlArr = arr.Value [i] as ErlArray;

                bfs [i]       = new BattleFormation();
                bfs [i].id    = erlArr.Value [0].getValueString();
                bfs [i].hp    = StringKit.toInt(erlArr.Value [1].getValueString());
                bfs [i].maxHp = StringKit.toInt(erlArr.Value [2].getValueString());
            }
        }
        if (isMine)
        {
            return(parseMyCards(bfs));
        }
        return(parseEnemycards(bfs));
    }
    PetEggData creatNewEgg()
    {
        PetEggData newData = new PetEggData();

        newData.creatTime = GameController.GetInstance().getCurrentSystemNum();
        newData.item_id   = BattleFormation.getRanPetEggId();

        return(newData);
    }
Esempio n. 11
0
        public static void Main(string[] args)
        {
            //var battleship = Battleship.CreateBattleShip("Raven");

            var factory = new ShipFactory <Battleship>();

            var raven    = factory.CreateShip(Battleships.Raven);
            var dominix  = factory.CreateShip(Battleships.Dominix);
            var rokh     = factory.CreateShip(Battleships.Rokh);
            var scorpion = factory.CreateShip(Battleships.Scorpion);

            var canon      = new Weapon(Weapons.Cannon, WeaponGrades.Large);
            var projectile = new Weapon(Weapons.Projectile, WeaponGrades.Large);
            var laser      = new Weapon(Weapons.Laser, WeaponGrades.Large);
            var missile    = new Weapon(Weapons.Missile, WeaponGrades.Large);

            raven.InstallWeapon(canon, 1);
            dominix.InstallWeapon(projectile, 1);
            rokh.InstallWeapon(laser, 1);
            scorpion.InstallWeapon(missile, 1);

            var attackingPlanetOffensiveFormation = new BattleFormation("ap of");
            var attackingPlanetDefensiveFormation = new BattleFormation("ap df");
            var defensivePlanetOffensiveFormation = new BattleFormation("dp of");
            var defensivePlanetDefensiveFormation = new BattleFormation("dp df");

            attackingPlanetOffensiveFormation.SetFormationRow(raven, 100, 1);
            attackingPlanetDefensiveFormation.SetFormationRow(dominix, 100, 1);
            defensivePlanetOffensiveFormation.SetFormationRow(raven, 100, 1);
            defensivePlanetDefensiveFormation.SetFormationRow(raven, 100, 1);


            var attackingPlanetOffensiveFormationGeneral = new General();
            var attackingPlanetDefensiveFormationGeneral = new General();
            var defensivePlanetOffensiveFormationGeneral = new General();
            var defensivePlanetDefensiveFormationGeneral = new General();

            attackingPlanetOffensiveFormation.SetGeneral(attackingPlanetOffensiveFormationGeneral);
            attackingPlanetDefensiveFormation.SetGeneral(attackingPlanetDefensiveFormationGeneral);
            defensivePlanetDefensiveFormation.SetGeneral(defensivePlanetDefensiveFormationGeneral);
            defensivePlanetOffensiveFormation.SetGeneral(defensivePlanetOffensiveFormationGeneral);

            var attackingPlanet = new Planet(Planets.Pandora);
            var defensivePlanet = new Planet(Planets.Desert);

            attackingPlanet.AddFormation(attackingPlanetOffensiveFormation);
            attackingPlanet.AddFormation(attackingPlanetDefensiveFormation);
            defensivePlanet.AddFormation(defensivePlanetOffensiveFormation);
            defensivePlanet.AddFormation(defensivePlanetDefensiveFormation);

            attackingPlanet.ActivateFormation(attackingPlanetOffensiveFormation, BattleFormationType.Offensive);
            attackingPlanet.ActivateFormation(attackingPlanetDefensiveFormation, BattleFormationType.Defensive);
            defensivePlanet.ActivateFormation(defensivePlanetOffensiveFormation, BattleFormationType.Offensive);
            defensivePlanet.ActivateFormation(defensivePlanetDefensiveFormation, BattleFormationType.Defensive);

            BattleSimulator.CalculateBattleResult(attackingPlanet, defensivePlanet);
        }
Esempio n. 12
0
 public void UpdateFormation(BattleFormation formation)
 {
     unitData.Clear();
     for (int i = 0; i < formation.party.Units.Count; i++)
     {
         var newFormationUnitData = new FormationUnitSaveData();
         newFormationUnitData.UpdateFromUnit(formation.party.Units[i]);
         unitData.Add(newFormationUnitData);
     }
 }
 public void UpdateFormation(BattleFormation formation)
 {
     UnitData.Clear();
     foreach (FormationUnit unit in formation.Party.Units)
     {
         var newFormationUnitData = new FormationUnitSaveData();
         newFormationUnitData.UpdateFromUnit(unit);
         UnitData.Add(newFormationUnitData);
     }
 }
 public void SetupFormations()
 {
     using (var mock = AutoMock.GetLoose())
     {
         var formationMock = mock.Mock <BattleFormation>();
         formationMock.Setup(f => f.GeneralInCharge).Returns(_General);
         formationMock.Setup(s => s.SetGeneral(_General)).Callback(() => { });
         _FormationMock = mock.Create <BattleFormation>();
     }
 }
Esempio n. 15
0
    //private float[] engage_probabities;

    private BattleState()
    {
        engageMode      = EngageMode.PARALLEL;
        battleFormation = BattleFormation.LINE_AHEAD;

        //解耦合,具体实现在Mono中做
        //engage_probabities= new float[4];
        //engage_probabities[0] = 0.45f;
        //engage_probabities[1] = 0.30f;
        //engage_probabities[2] = 0.15f;
        //engage_probabities[3] = 0.10f;
    }
Esempio n. 16
0
        /* Моделирование обстрела. */

        /// <summary>
        /// Получить площадь, на которую будут падать стрелы. Зависит от дальнобойности оружия и степени усталости стрелков.
        /// </summary>
        /// <param name="rangers">Полк стрелков</param>
        /// <returns>Площадь, осыпаемая стрелами.</returns>
        public Rect CalcArrowedSquer(BattleFormation rangers, float heightRanger, float heightTarget)
        {
            var ranDist = rangers.DistanceToCenter;
            var view    = (float)(rangers.V.Direction);
            var near    = view * rangers.Range.Near;
            var far     = view * rangers.Side.Class.GetRangeLimit(heightRanger - heightTarget, rangers.Energy);

            return(new Rect(
                       0, ranDist - view * rangers.Length + near,
                       0 + rangers.Width, ranDist + far
                       ));
        }
Esempio n. 17
0
    //world FISH
    public void creatTrappedFish(HomeObject obj, int creatTime)
    {
        string id = BattleFormation.getRanFishId();

        obj.trappedId = "10029";
        Vector2 p   = UnityEngine.Random.insideUnitCircle * 3;
        Vector2 pos = p.normalized * (2.5f + p.magnitude);

        obj.trappedPosx = pos.x * 50;
        obj.trappedPosy = pos.y * 50;
        obj.trappedTime = creatTime;
        PlayerData.updateHomeObject(obj);
    }
Esempio n. 18
0
        public void BattleFormation_GivenInvalidFormationLength_ThrowException()
        {
            using (var mock = AutoMock.GetLoose())
            {
                var name = "Formation 2";

                //Act
                BattleFormation battleFormation = new BattleFormation(name);

                //Assert

                Assert.AreNotEqual(7, battleFormation.Rows.Length, "Invalid Formation Length");
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Определить, сколько солдат попадают в область обстрела.
        /// </summary>
        /// <param name="arrowed">Зона обстрела</param>
        /// <param name="targets">Дивизия, которую проверяют на попадание в зону обстрела</param>
        /// <returns>Число солдат, в которых хотя бы теоретически могли попасть.</returns>
        public int CalcOverArrowedAmount(Rect arrowed, BattleFormation targets)
        {
            var view         = (float)(targets.V.Direction);
            var ranDist      = targets.DistanceToCenter;
            var between      = Math.Abs(ranDist - targets.DistanceToCenter);
            var targetSquer  = new Rect(0, ranDist, 0 + targets.Width, ranDist + view * targets.Length);
            var firedOverlay = targetSquer.GetOverlay(arrowed);

            if (!firedOverlay.HasValue)
            {
                return(0);
            }
            return((int)Math.Floor(targets.Soldiers * Math.Min(firedOverlay.Value.Squer / targetSquer.Squer, 1)));
        }
Esempio n. 20
0
        public void CreateBattleFormation_CheckInitializationValue_ReturnsCorrectInstance()
        {
            using (var mock = AutoMock.GetLoose())
            {
                var name = "Formation 2";

                //Act
                // battleFormation.SetFormationRow(ship, 2000, 7);
                BattleFormation battleFormation = new BattleFormation(name);

                //Assert
                Assert.AreEqual(name, battleFormation.Name);
                Assert.IsNull(battleFormation.GeneralInCharge);
            }
        }
Esempio n. 21
0
        public void BattleFormation_CheckInTotalFormationLength_ReturnTotalLength()
        {
            using (var mock = AutoMock.GetLoose())
            {
                var name = "Formation 2";


                //Act
                BattleFormation battleFormation = new BattleFormation(name);

                //Assert

                Assert.AreEqual(6, battleFormation.Rows.Length);
            }
        }
Esempio n. 22
0
        public void SetFormationRow_ValidInput_SetShipRowWithSpecifiedQuantity()
        {
            using (var mock = AutoMock.GetLoose())
            {
                //Arrange
                BattleFormation formation = new BattleFormation("formation 1");
                var             ship      = Battleship.CreateBattleship("Reven");
                //var shipMock = mock.Mock<Ship>();
                //var ship = shipMock.Object;
                //Act
                formation.SetFormationRow(ship, 100, 2);

                //Assert
                Assert.AreSame(formation.Rows[2].SelectedShip, ship);
            }
        }
Esempio n. 23
0
        /* isp RemoveFormation()
         *
         * Input variables:
         * battleFormation =
         *
         * State variables:
         *
         *
         */
        public void RemoveFormation(BattleFormation battleFormation)
        {
            if (battleFormation is null)
            {
                throw new ArgumentNullException(nameof(BattleFormation));
            }

            var formations = Formations.Where(f => f.Equals(battleFormation));

            if (formations == null || formations.Count() == 0)
            {
                throw new ArgumentException("Battle formation does not exist");
            }

            Formations.Remove(battleFormation);
        }
Esempio n. 24
0
        /* isp UpdateFormation()
         *
         * Input variables:
         * battleFormation =
         * newFormation =
         *
         * State variables:
         *
         *
         */
        public void UpdateFormation(BattleFormation battleFormation, BattleFormation newFormation)
        {
            if (battleFormation is null)
            {
                throw new ArgumentNullException(nameof(battleFormation), "Invalid source formation");
            }
            if (newFormation is null)
            {
                throw new ArgumentNullException(nameof(battleFormation), "Invalid new formation");
            }
            var existingFormation = Formations?.SingleOrDefault(f => f.Equals(battleFormation));

            if (existingFormation != null)
            {
                existingFormation = newFormation;
            }
        }
Esempio n. 25
0
        public void ActivateFormation_ProvideProperValue_SuccessfullyActivated()
        {
            using (var mock = AutoMock.GetLoose())
            {
                var             name            = "Formation 2";
                BattleFormation battleFormation = new BattleFormation(name);
                var             generalMock     = mock.Create <General>();

                //Act
                battleFormation.ActivateFormation(generalMock);


                //Assert
                Assert.AreEqual(generalMock, battleFormation.GeneralInCharge);
                Assert.IsTrue(battleFormation.IsActive);
            }
        }
Esempio n. 26
0
        public void ActivateFormation_ProvideNullValue_ThrowsException()
        {
            using (var mock = AutoMock.GetLoose())
            {
                //arrange
                var             name            = "Formation 2";
                BattleFormation battleFormation = new BattleFormation(name);
                var             generalMock     = mock.Create <General>();

                //Act

                //Assert

                Assert.Throws <ArgumentNullException>(() => battleFormation.ActivateFormation(null),
                                                      null, "assignedGeneral");
            }
        }
Esempio n. 27
0
        public void SetFormation_InvalidInput_SetsRowWithSpecifiedQuntaty()
        {
            using (var mock = AutoMock.GetLoose())
            {
                //Arrange

                BattleFormation battleFormation = new BattleFormation("Foramtion 1");
                //var raven = Battleship.CreateBattleship("Raven");
                var shipmock = mock.Mock <Ship>();

                var ship = shipmock.Object;
                //Act
                battleFormation.SetFormationRow(ship, 2000, 4);

                //Assert
                Assert.AreSame(battleFormation.Rows[4].SelectedShip, ship);
            }
        }
    /// <summary>
    /// 初始化队伍位置
    /// </summary>
    private void initTeamPos()
    {
        BattleFormation.init();
        BattleRole br;
        int        count = this.myTeam.Count;

        int[]   matrixAry;
        Vector3 startPos = BattleFormation.leftStartPos;
        int     gapH     = BattleFormation.gapH;
        int     gapV     = BattleFormation.gapV;

        for (int i = 0; i < count; ++i)
        {
            br        = this.myTeam[i];
            matrixAry = BattleFormation.leftMatrix[i];
            int     xm  = matrixAry[0];
            int     zm  = matrixAry[1];
            Vector3 pos = new Vector3(startPos.x + (xm - 1) * gapH,
                                      startPos.y,
                                      startPos.z - (zm - 1) * gapV);
            br.setPosition(pos);
            int posX = BattleFormation.leftPosIndex[i][0];
            int posY = BattleFormation.leftPosIndex[i][1];
            br.posIndexVector = new Vector2(posX, posY);
        }

        startPos = BattleFormation.rightStartPos;
        count    = this.targetTeam.Count;
        for (int i = 0; i < count; ++i)
        {
            br        = this.targetTeam[i];
            matrixAry = BattleFormation.rightMatrix[i];
            int     xm  = matrixAry[0];
            int     zm  = matrixAry[1];
            Vector3 pos = new Vector3(startPos.x + (xm - 1) * gapH,
                                      startPos.y,
                                      startPos.z - (zm - 1) * gapV);
            br.setPosition(pos);
            int posX = BattleFormation.rightPosIndex[i][0];
            int posY = BattleFormation.rightPosIndex[i][1];
            br.posIndexVector = new Vector2(posX, posY);
        }
    }
Esempio n. 29
0
        public void SetFormation_GivenInvalidRowPosition_ThrowException()
        {
            using (var mock = AutoMock.GetLoose())
            {
                BattleFormation battleFormation = new BattleFormation("Foramtion 2");
                //var raven = Battleship.CreateBattleship("Raven");
                var shipmock = mock.Mock <Ship>();

                var ship = shipmock.Object;
                //Act
                // battleFormation.SetFormationRow(ship, 2000, 7);

                //Assert
                Assert.Multiple(() =>
                {
                    var ex = Assert.Catch <Exception>(() => battleFormation.SetFormationRow(ship, 200, 7),
                                                      "Expected exception is missing");
                    Assert.AreEqual("Invalid Row Position", ex.Message, "Wrong error message");
                });
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Получить как можно более плотную (маленькую) зону обстрела.
        /// Стрелки стараются обстреливать именно дивизию.
        /// </summary>
        /// <param name="rangers">Полк стрелков</param>
        /// <param name="targets">В какой полк целятся</param>
        /// <param name="heightRanger">Высота положения стрелков</param>
        /// <param name="heightTarget">На какой высоте находятся цели</param>
        /// <returns>Область, в которую стараются попасть</returns>
        public Rect?CalcTargetSquer(BattleFormation rangers, BattleFormation targets, float heightRanger, float heightTarget)
        {
            var arcWide = Math.Max(
                Math.Min(
                    Math.Abs(rangers.DistanceToCenter - targets.DistanceToCenter),
                    rangers.Side.Class.GetRangeLimit(heightRanger - heightTarget, rangers.Energy)
                    ),
                rangers.Range.Near
                );

            if (arcWide < rangers.Range.Near || arcWide > rangers.Range.Far)
            {
                return(null);
            }
            var ranDist = rangers.DistanceToCenter;
            var view    = (float)(rangers.V.Direction);
            var near    = Math.Min(rangers.Range.Near, arcWide);

            return(new Rect(
                       0, ranDist - view * rangers.Length + near,
                       0 + rangers.Width, ranDist + arcWide + 0.1f
                       ));
        }