public static GameObject CreateTroop(TroopData troopData, Vector3 position)
    {
        GameObject  troop       = new GameObject(troopData.name, typeof(Troop), typeof(BoxCollider));
        BoxCollider boxCollider = troop.GetComponent <BoxCollider>();

        boxCollider.center    = new Vector3(0, 1, 0);
        boxCollider.size      = new Vector3(12, 2, 6);
        boxCollider.isTrigger = true;
        troop.GetComponent <Troop>().movementSpeed = troopData.movementSpeed;

        troop.tag = "Allies";                                              //TO DO: MAKE ALLIES NOT COLLIDE WITH OTHER ALLIES
        troop.transform.position = new Vector3(position.x, 1, position.z); //always 1 unit above ground

        float xPos, zPos;

        for (int z = 0; z < troopData.numZ; z++)
        {
            zPos = -(((troopData.numZ - 1) * troopData.spaceBetween) / 2) + (z * troopData.spaceBetween);
            for (int x = 0; x < troopData.numX; x++)
            {
                xPos = -(((troopData.numX - 1) * troopData.spaceBetween) / 2) + (x * troopData.spaceBetween);
                GameObject obj = Object.Instantiate(troopData.troopPrefabs[Random.Range(0, troopData.troopPrefabs.Count)], position + new Vector3(xPos, 0, zPos),
                                                    Quaternion.identity, troop.transform);
                obj.tag = "Allies";
                obj.AddComponent <Unit>().troop = troop.GetComponent <Troop>(); //adds IndividualTroop script for each unit
            }
        }
        return(troop);
    }
Exemplo n.º 2
0
        public override bool ExternalCondition(BTreeTemplateData input)
        {
            var _input     = (BTreeInputData)input;
            var troop      = _input.troop;
            var battleData = _input.battleData;

            if (troop.targetKey != 0)
            {
                TroopData tarTroop = battleData.mAllTroopDic[troop.targetKey];
                if (tarTroop == null)
                {
                    return(false);
                }
                uint atkDis   = TroopHelper.GetTroopAtkDis(troop.type);
                uint myRange  = TroopHelper.GetTroopRange(troop.type);
                uint tarRange = TroopHelper.GetTroopRange(tarTroop.type);
                int  dis      = MathHelper.TroopDistanceV2(troop, tarTroop);
                if (dis > atkDis + myRange + tarRange)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public override Enum Enter(ref FSMInputData _input)
        {
            var troop = _input.m_Troop;

            if (troop.targetKey != 0)
            {
                TroopData tarTroop = dataMgr.m_BattleData.mAllTroopDic[troop.targetKey];
                if (tarTroop == null)
                {
                    Debugger.LogError("AttackState 未找到目标");
                }
                uint atkDis   = TroopHelper.GetTroopAtkDis(troop.type);
                uint myRange  = TroopHelper.GetTroopRange(troop.type);
                uint tarRange = TroopHelper.GetTroopRange(tarTroop.type);
                int  dis      = MathHelper.TroopDistanceV2(troop, tarTroop);
                if (dis > atkDis + myRange + tarRange)
                {
                    return(TroopFSMState.Move);
                }
                else
                {
                    return(Excute(ref _input));
                }
            }
            return(TroopFSMState.End);
        }
Exemplo n.º 4
0
    public void UpdateInfoWindow(int index)
    {
        TroopData data = GameStats.Instance.TroopBaseData[currentShop[index]];

        //Debug.Log(data.TroopName);
        InfoWindow.UpdateInfoStatic(data);
    }
    public static void SetUpData()   //TO DO: Make this more generic so that files can be used for knight data
    {
        TroopData knightData = new TroopData {
            troopPrefabs = new List <GameObject>()
            {
                (GameObject)Resources.Load("Character_Knight_Black"),
                (GameObject)Resources.Load("Character_Knight_White"),
                (GameObject)Resources.Load("Character_Knight_Brown")
            },
            troopId       = 1,
            name          = "Knights",
            movementSpeed = 5,
            numX          = 5,
            numZ          = 3,
            spaceBetween  = 2.5f
        };

        troopDatas = new List <TroopData>()
        {
            knightData
        };
        if (troopDatas[0].troopPrefabs[0] == null)
        {
            Debug.Log("null");
        }
    }
Exemplo n.º 6
0
 public void AddTestData()
 {
     troopData = new TroopData();
     //troopData.AddTestData();
     battleRound = new BattleRound();
     battleRound.AddTestData();
     isPlayed = false;
     isWin    = true;
 }
Exemplo n.º 7
0
    public void SetData(TroopData newData)
    {
        if (data != null)
        {
            return;
        }

        data = newData;
    }
Exemplo n.º 8
0
        private Enum MoveToTarget(ref FSMInputData _input, TroopData target)
        {
            var troop = _input.m_Troop;

            mTar_X      = target.x;
            mTar_Y      = target.y;
            troop.dir_x = mTar_X;
            troop.dir_y = mTar_Y;
            return(Excute(ref _input));
        }
    public static AttackEvaluation Attack(TroopData troop, PlayerData oldOwner, PlayerData newOwner, int shipsOnPlanetAfterEvent, int lostShipsByOwner, int lostShipsByAttacker, int lostShipsByLanding)
    {
        AttackEvaluation evaluation = new AttackEvaluation();
        if (troop.Owner == null || troop.Owner.IsHumanPlayer) { // null-check for debugging purposes: if a ship has been sent from a neutral planet
            evaluation.Type = EvaluationType.AttackedPlanet;
            evaluation.LostShips = lostShipsByAttacker + lostShipsByLanding;
            if (newOwner == troop.Owner) {                   // Captured
                if (lostShipsByLanding > 0) {
                    evaluation.Outcome = EvaluationOutcome.Neutral;     // Bitterer Beigeschmack
                } else {
                    evaluation.Outcome = EvaluationOutcome.Success;
                }
                evaluation.Importance = 80;
            } else {
                evaluation.Outcome = EvaluationOutcome.Lost;
                evaluation.Importance = 75;
            }
        } else if (oldOwner != null && oldOwner.IsHumanPlayer) {
            evaluation.Type = EvaluationType.GotAttacked;
            evaluation.LostShips = lostShipsByOwner;
            if (newOwner == troop.Owner) {                   // Captured
                evaluation.Outcome = EvaluationOutcome.Lost;
                evaluation.Importance = 80;
            } else {
                evaluation.Outcome = EvaluationOutcome.Success;
                evaluation.Importance = 60;
            }
        } else {
            if (oldOwner != newOwner) {
                evaluation.Type = EvaluationType.CaptureViewer;
                evaluation.Importance = 15;
            } else {
                evaluation.Type = EvaluationType.AttackViewer;
                evaluation.Importance = 5;
            }
            evaluation.LostShips = lostShipsByOwner + lostShipsByAttacker + lostShipsByLanding;     // A viewer is only intersted in the total number of ships destroyed
            evaluation.Outcome = EvaluationOutcome.Neutral;
        }

        evaluation.ShipOwner = troop.Owner;
        evaluation.PlanetOwner = newOwner;
        evaluation.IncomingShips = troop.ShipCount;
        evaluation.ShipsOnPlanetAfterEvent = shipsOnPlanetAfterEvent;

        evaluation.Planet = troop.TargetPlanet;
        evaluation.OriginalOwner = oldOwner;

        Debug.Log("An attack of " + evaluation.IncomingShips
            + " ships reached planet " + evaluation.Planet.Name
            + " - Losses:  owner = " + lostShipsByOwner
            + ", attacker = " + (lostShipsByAttacker + lostShipsByLanding)
            + "; New owner: " + (newOwner == null ? "neutral" : newOwner.Name)
            + "");
        return evaluation;
    }
Exemplo n.º 10
0
    void LoadPlayerData()
    {
        if (File.Exists(Application.persistentDataPath + "/PlayerData.json"))
        {
            Loader.LoadAll();
            int SlvNum = 0;
            foreach (GameObject slv in PlayInv.SlavePlace)
            {
                if (slv != null)
                {
                    slv.transform.SetParent(SlavesContainer.transform);
                    slv.transform.position = SlavesFields.transform.GetChild(SlvNum).gameObject.transform.position + new Vector3(0, 0, -0.1f);
                    slv.GetComponent <SlaveProperties>().Goal = EnemiesFields.transform.GetChild(5).gameObject;
                    this.GetComponent <WORK_Battle>().Slaves.Add(slv);
                }
                SlvNum++;
            }
        }

        if (File.Exists(Application.persistentDataPath + "/BanditTroop.json"))
        {
            string    GetEnemyData = File.ReadAllText(Application.persistentDataPath + "/BanditTroop.json");
            TroopData GetTroop     = new TroopData();
            GetTroop     = JsonUtility.FromJson <TroopData>(GetEnemyData);
            NumberOfArea = GetTroop.NumberOfArea;
            Count        = GetTroop.TroopCount;
            Battle.Clan  = GetTroop.Band;

            for (int e = 0; e < GetTroop.TroopCount; e++)
            {
                GameObject E = Instantiate(Resources.Load("EnemyDoll")) as GameObject;
                E.name = "Enm" + e;
                E.GetComponent <EnemyProperties>().FullHealth = GetTroop.Enemies[e].FullHealth;
                E.GetComponent <EnemyProperties>().Health     = GetTroop.Enemies[e].Health;
                E.GetComponent <EnemyProperties>().Damage     = GetTroop.Enemies[e].Damage;
                E.GetComponent <EnemyProperties>().Accuracy   = GetTroop.Enemies[e].Accuracy;
                E.GetComponent <EnemyProperties>().Level      = GetTroop.Enemies[e].Level;
                E.GetComponent <EnemyProperties>().Skin       = GetTroop.Enemies[e].Skin;
                E.transform.SetParent(EnemiesContainer.transform);
                this.GetComponent <WORK_Battle>().Enemies.Add(E);
            }

            int GetEnemy = 0;
            PanoramaCoef = -0.1f;
            for (int i = 0; i < GetTroop.Places.Length; i++)
            {
                if (GetTroop.Places[i] == true)
                {
                    EnemiesContainer.transform.GetChild(GetEnemy).transform.position = EnemiesFields.transform.GetChild(i).transform.position + new Vector3(0, 0, PanoramaCoef);
                    GetEnemy     += 1;
                    PanoramaCoef -= 0.1f;
                }
            }
        }
    }
Exemplo n.º 11
0
    public void Init(int currentDay, TroopData troop)
    {
        troopData = troop;
        this.transform.localScale = new Vector3(15, 15, 1);
        this.transform.localPosition = troop.StartPlanet.Position;

        UpdatePosition(currentDay);   // sets the target progress
        this.name = GetNameForTroopGameObject(troopData);

        shipcountText.text = "" + troop.ShipCount;
        spaceshipTextureTransform.rotation = Quaternion.FromToRotation(Vector3.up, troop.TargetPlanet.Position - troop.StartPlanet.Position);

        textBackgroundRenderer.color = troop.Owner.Color;
    }
Exemplo n.º 12
0
 private void RefreshTroop()
 {
     for (int i = 0; i < m_AtkTroopList.Count; i++)
     {
         TroopData _atkTroop = m_AtkTroopList[i];
         float     x         = _atkTroop.x;
         float     y         = _atkTroop.y;
         CorrectPos(ref x, ref y);
         float dir_x = _atkTroop.dir_x;
         float dir_y = _atkTroop.dir_y;
         CorrectPos(ref dir_x, ref dir_y);
         if (m_AtkSoldierGroup.ContainsKey(_atkTroop.key))
         {
             m_AtkSoldierGroup[_atkTroop.key].Doing(x, y, dir_x, dir_y, _atkTroop);
         }
         else
         {
             SoldierGroup soldierGroup = MainBattleManager.Instance.CreateSoldierGroup(x, y, dir_x, dir_y, _atkTroop);
             m_AtkSoldierGroup[_atkTroop.key] = soldierGroup;
         }
         _atkTroop.addTroop = false;
     }
     for (int i = 0; i < m_DefTroopList.Count; i++)
     {
         TroopData _defTroop = m_DefTroopList[i];
         float     x         = _defTroop.x;
         float     y         = _defTroop.y;
         CorrectPos(ref x, ref y);
         float dir_x = _defTroop.dir_x;
         float dir_y = _defTroop.dir_y;
         CorrectPos(ref dir_x, ref dir_y);
         if (m_DefSoldierGroup.ContainsKey(_defTroop.key))
         {
             m_DefSoldierGroup[_defTroop.key].Doing(x, y, dir_x, dir_y, _defTroop);
         }
         else
         {
             SoldierGroup soldierGroup = MainBattleManager.Instance.CreateSoldierGroup(x, y, dir_x, dir_y, _defTroop);
             m_DefSoldierGroup[_defTroop.key] = soldierGroup;
         }
         _defTroop.addTroop = false;
     }
 }
Exemplo n.º 13
0
 public void Init(float x, float y, float dir_x, float dir_y, TroopData data)
 {
     base.Init(data);
     m_Type         = data.type;
     m_IsAttacker   = data.isAtkTroop;
     m_Line         = data.line;
     m_Row          = data.row;
     m_Scale        = 1f;
     m_LineInterval = 1f;
     m_RowInterval  = 1f;
     //初始化坐标
     InitPosition(x, y);
     m_BaseCount = data.count;
     if (data.count > 0)
     {
         //float deg = CalcRad(dir_x, dir_y);
         InitAllSoldiers(data.count, (TroopAnimState)data.state);
     }
 }
Exemplo n.º 14
0
        public override Enum Excute(ref FSMInputData _input)
        {
            var       troop    = _input.m_Troop;
            TroopData tarTroop = dataMgr.m_BattleData.mAllTroopDic[troop.targetKey];

            if (tarTroop == null)
            {
                Debugger.LogError("AttackState 未找到目标");
            }
            if (troop.norAtkCD == 0)
            {
                troop.state     = (int)TroopAnimState.Attack;
                troop.dir_x     = tarTroop.x;
                troop.dir_y     = tarTroop.y;
                troop.inPrepose = true;
                troop.preTime   = TroopHelper.GetTroopAtkPrepareTime(troop.type);
                troop.isAtk     = true;
                troop.norAtkCD  = TroopHelper.GetTroopAtkCDTime(troop.type);
            }
            return(TroopFSMState.End);
        }
Exemplo n.º 15
0
 // Use this for initialization
 void Start()
 {
     data = GameObject.Find ("Troop Numbers").GetComponent<TroopData> ();
 }
Exemplo n.º 16
0
 private void InitGraphicalTroopMovement(int currentDay, TroopData troopData)
 {
     GameObject troopObject = troopPool.Get();
     Troop troop = troopObject.GetComponent<Troop>();
     if (troop == null) {
         throw new MissingComponentException("A pooled Troop-GameObect doesn't have a Troop-Component. Each Troop-GO should have a Troop Script attached.");
     }
     troop.Init(currentDay, troopData);
     troopObject.transform.SetParent(space.transform,false);
     if(fogOfWar == 0) {
         troopObject.SetActive(true);
         troop.SetSprite();
     } else if (troopData.Owner != null && troopData.Owner.IsHumanPlayer) {     // Belongs to human
         troopObject.SetActive(true);
         troop.SetSprite();
     } else if (troopData.TargetPlanet.Owner != null && troopData.TargetPlanet.Owner.IsHumanPlayer) { // Attacks human
         if (troopData.TravelTime <= fogOfWar) {                          // Can already be seen
             troopObject.SetActive(true);
             troop.SetSprite();
         }
     }
     troops.Add(troopObject);
 }
 // Use this for initialization
 void Start()
 {
     console = GameObject.Find ("Console");
     dev = console.GetComponent<DevOptions>();
     resourceData = resourceValues.GetComponent<ResourceData> ();
     troopData = troopNumbers.GetComponent<TroopData> ();
     windowManager = window.GetComponent<WindowManager> ();
     var repo = ConsoleCommandsRepository.Instance;
     repo.RegisterCommand ("changetroops", ChangeTroops);
     repo.RegisterCommand ("closewindow", CloseWindow);
     repo.RegisterCommand ("debug", DebugOn);
     repo.RegisterCommand ("exit", Exit);
     repo.RegisterCommand ("foodrate", FoodRate);
     repo.RegisterCommand("help", Help);
     repo.RegisterCommand("load", Load);
     repo.RegisterCommand ("metalrate", MetalRate);
     repo.RegisterCommand ("openwindow", OpenWindow);
     repo.RegisterCommand ("stonerate", StoneRate);
     repo.RegisterCommand ("woodrate", WoodRate);
 }
Exemplo n.º 18
0
 public void SetData(BTreeInputData _input)
 {
     troop = _input.troop;
 }
Exemplo n.º 19
0
    // Supply ships from other planet
    private AttackEvaluation EvaluateIncommingSupply(TroopData troop)
    {
        Debug.Assert(troop.Owner == Owner, "Invalid call");

        int remainingSpace = HangarSize - Ships;  //Remaining space
        if (remainingSpace < 0) { remainingSpace = 0; }

        int lostShips = 0;

        if (remainingSpace < troop.ShipCount) {          //Some ships will get lost
            Ships += remainingSpace;
            lostShips = Mathf.RoundToInt((troop.ShipCount - remainingSpace) * 0.5f);     //All other ships will get a 50% penality
            Ships += troop.ShipCount - remainingSpace - lostShips;
        } else {
            Ships += troop.ShipCount;
        }

        AttackEvaluation evaluation = AttackEvaluation.Supply(troop, Ships, lostShips);
        return evaluation;
    }
Exemplo n.º 20
0
 public void AddTroopMovement(TroopData troopData)
 {
     //Debug.Assert(troopData.ArrivalTime > CurrentDay);
     airTraffic.Add(troopData);
 }
Exemplo n.º 21
0
 private string GetNameForTroopGameObject(TroopData troopData)
 {
     try
     {
         return troopData.Owner.Name + " (" + troopData.ShipCount + "): " + troopData.StartPlanet.Name + " > " + troopData.TargetPlanet.Name;
     }
     catch (NullReferenceException)
     {
         return "Troop of " + troopData.ShipCount + " ships";
     }
 }
Exemplo n.º 22
0
 public static void UpdateInfoStatic(TroopData data)
 {
     instance.UpdateInfo(new TroopPlaceholder(data));
 }
Exemplo n.º 23
0
        public void Doing(float x, float y, float dir_x, float dir_y, TroopData data)
        {
            m_CurrentState = (TroopAnimState)data.state;
            //士兵已死
            if (m_BaseCount == 0 && data.count == 0)
            {
                return;
            }
            //复活(从出生点)
            if (m_BaseCount == 0)
            {
                InitPosition(x, y);
            }
            //初始化显示
            if (!m_IsInit)
            {
                Show(true);
            }
            float deg = CalcRad(dir_x, dir_y);

            //有其他玩家加入,士兵刷新
            if (data.addTroop && data.count > 0)
            {
                InitAllSoldiers(data.count, (TroopAnimState)data.state, deg);
                //不影响移动
                if (m_CurrentState == TroopAnimState.Move)
                {
                    SetTweenPosition(x, y);
                }
                return;
            }
            //判断死亡数
            uint allObject        = data.row * data.line;
            int  remainIndexCount = soldierIndexList == null ? 0 : soldierIndexList.Count;
            int  loseCount        = (int)((m_BaseCount - data.count) * allObject / m_BaseCount + remainIndexCount - allObject);

            for (int i = 0; i < loseCount; i++)
            {
                DieOne(deg);
            }

            for (int i = 0; i < soldierArray.GetLength(0); i++)
            {
                for (int j = 0; j < soldierArray.GetLength(1); j++)
                {
                    if (soldierArray[i, j] != null)
                    {
                        soldierArray[i, j].SetState(m_CurrentState);
                    }
                }
            }
            if (m_CurrentState == TroopAnimState.Move)
            {
                //如果状态是移动则播放
                SetTweenPosition(x, y);
            }
            SetSoldierLocalRotation(deg);
            if (data.count == 0)
            {
                m_BaseCount = 0;
                //ShowUI(false);
            }
        }
Exemplo n.º 24
0
    public AttackEvaluation EvaluateIncomingTroop(TroopData troop)
    {
        if (troop.TargetPlanet != this) {
            throw new ArgumentException("Unable to evaluate incoming troop: The troop is not arriving at this planet. Me: " + Name + ", Troop: " + troop.ToString());
        }

        if (troop.Owner == Owner && troop.Owner.IsHumanPlayer) {
            return EvaluateIncommingSupply(troop);
        }

        return EvaluateIncommingAttack(troop);
    }
Exemplo n.º 25
0
    // Attacking ships from other planet
    private AttackEvaluation EvaluateIncommingAttack(TroopData troop)
    {
        if(troop.TargetPlanet != this) {
            Debug.LogError("Invalid Call!");
        }

        bool gotCaptured = (Ships <= troop.ShipCount);
        if(Owner == troop.Owner) {  // Supply
            gotCaptured = false;
        }
        if (Owner == null && Ships == troop.ShipCount) { // Planet was neutral and stayed neutral. But there are no more ships on this planet anymore.
            gotCaptured = false;
        }

        PlayerData oldOwner = Owner;
        PlayerData newOwner = (gotCaptured ? troop.Owner : oldOwner);
        if(Ships == troop.ShipCount) {
            newOwner = null;
        }

        int lostShipsByOwner = 0;
        int lostShipsByAttacker = 0;
        int lostShipsByLanding = 0;

        if (Ships <= troop.ShipCount) { // planet is lost
            lostShipsByOwner = Ships;
            lostShipsByAttacker = Ships;
            // check for landing - maybe the attacker won, but not all ships have space to land:
            lostShipsByLanding = Math.Max((int)(Mathf.RoundToInt((troop.ShipCount - Ships - HangarSize) * 0.5f)), 0);     //50% of all ships that hadn't enough space lost
        } else {
            lostShipsByOwner = troop.ShipCount;
            lostShipsByAttacker = troop.ShipCount;
        }

        // Perform actions:
        if (gotCaptured) {
            SetOwner(newOwner);
            Ships = troop.ShipCount - lostShipsByAttacker - lostShipsByLanding;
        } else {
            Ships -= lostShipsByOwner;
        }

        Debug.Assert(lostShipsByAttacker + lostShipsByLanding <= troop.ShipCount);
        AttackEvaluation evaluation = AttackEvaluation.Attack(troop, oldOwner, newOwner, Ships, lostShipsByOwner, lostShipsByAttacker, lostShipsByLanding);
        return evaluation;
    }
Exemplo n.º 26
0
 public void SetTroop(TroopData _troop)
 {
     m_Troop = _troop;
 }
 public static AttackEvaluation Supply(TroopData troop, int shipsOnPlanetAfterEvent, int lostShips)
 {
     AttackEvaluation evaluation = new AttackEvaluation();
     evaluation.Type = EvaluationType.Supply;
     if (lostShips > 0) {
         evaluation.Outcome = EvaluationOutcome.Lost;
         evaluation.Importance = Mathf.Lerp(50, 100, Mathf.Min(1, lostShips / 500));
     } else {
         evaluation.Outcome = EvaluationOutcome.Neutral;
         evaluation.Importance = 40;
     }
     evaluation.ShipOwner = troop.Owner;
     evaluation.PlanetOwner = troop.Owner;
     evaluation.IncomingShips = troop.ShipCount;
     evaluation.ShipsOnPlanetAfterEvent = shipsOnPlanetAfterEvent;
     evaluation.LostShips = lostShips;
     evaluation.Planet = troop.TargetPlanet;
     evaluation.OriginalOwner = troop.Owner;
     Debug.Log("A supply of "
         + evaluation.IncomingShips
         + " reached planet "
         + evaluation.Planet.Name + " - " + lostShips
         + " ships were lost due to full hangar");
     return evaluation;
 }
Exemplo n.º 28
0
 public static int TroopDistanceV2(TroopData a1, TroopData a2)
 {
     return(DistanceV2(a1.x, a1.y, a2.x, a2.y));
 }
Exemplo n.º 29
0
 public TroopPlaceholder(TroopData data)
 {
     this.data = data;
 }
Exemplo n.º 30
0
    //================================= Генерация врагов ===================================
    public void GenerateBanditTroop()
    {
        string GetBandTroopData;

        //if (File.Exists(Application.persistentDataPath + "/BanditTroop.json")) {
        //    GetBandTroopData = File.ReadAllText(Application.persistentDataPath + "/BanditTroop.json");
        //} else {
        //    File.Create(Application.persistentDataPath + "/BanditTroop.json");
        //}

        TroopData NewTroop = new TroopData();

        GameObject GetTouch = Player.GetComponent <PlayerChip>().TouchObject;

        if (GetTouch != null && GetTouch.gameObject.GetComponent <BanditsDoll>() != null)
        {
            BanditsDoll Band = GetTouch.gameObject.GetComponent <BanditsDoll>();
            NewTroop.Band         = Band.Clan;
            NewTroop.NumberOfArea = Band.Number;
            if (Band.Attacks == 0)
            {
                NewTroop.TroopCount = Random.Range(1, 3);
                if (NewTroop.TroopCount > Band.Population)
                {
                    NewTroop.TroopCount = Band.Population;
                }
                newFieldCover = new int[NewTroop.TroopCount];
                for (NumOfField = 0; NumOfField < newFieldCover.Length; NumOfField++)
                {
                    RandomRepeat();
                }

                for (int d = 0; d < newFieldCover.Length; d++)
                {
                    NewTroop.Places[newFieldCover[d]] = true;
                }

                for (int b = 0; b < NewTroop.TroopCount; b++)
                {
                    EnemyData NewEnemy = new EnemyData();
                    NewEnemy.Skin = Random.Range(1, 4);

                    int healthCoof   = Random.Range(1, 9);
                    int damageCoof   = Random.Range(1, 10 - healthCoof);
                    int accuracyCoof = 10 - (healthCoof + damageCoof);

                    NewEnemy.FullHealth = 15 * healthCoof;
                    NewEnemy.Health     = 15 * healthCoof;
                    NewEnemy.Damage     = 15 * damageCoof;
                    NewEnemy.Accuracy   = 15 * accuracyCoof;

                    //NewEnemy.Weapon = Random.Range(1, 6);

                    NewEnemy.Level = Random.Range(1, 3);
                    NewTroop.Enemies.Add(NewEnemy);
                }
            }
            else if (Band.Attacks == 1)
            {
                NewTroop.TroopCount = Random.Range(3, 6);
                if (NewTroop.TroopCount > Band.Population)
                {
                    NewTroop.TroopCount = Band.Population;
                }
                newFieldCover = new int[NewTroop.TroopCount];
                for (NumOfField = 0; NumOfField < newFieldCover.Length; NumOfField++)
                {
                    RandomRepeat();
                }

                for (int d = 0; d < newFieldCover.Length; d++)
                {
                    NewTroop.Places[newFieldCover[d]] = true;
                }

                for (int b = 0; b < NewTroop.TroopCount; b++)
                {
                    EnemyData NewEnemy = new EnemyData();
                    NewEnemy.Skin = Random.Range(1, 6);

                    int healthCoof   = Random.Range(1, 9);
                    int damageCoof   = Random.Range(1, 10 - healthCoof);
                    int accuracyCoof = 10 - (healthCoof + damageCoof);

                    NewEnemy.FullHealth = 15 * healthCoof;
                    NewEnemy.Health     = 15 * healthCoof;
                    NewEnemy.Damage     = 15 * damageCoof;
                    NewEnemy.Accuracy   = 15 * accuracyCoof;

                    //NewEnemy.Weapon = Random.Range(1, 6);

                    NewEnemy.Level = Random.Range(2, 5);
                    NewTroop.Enemies.Add(NewEnemy);
                }
            }
            else if (Band.Attacks >= 2)
            {
                NewTroop.TroopCount = Random.Range(6, 10);
                if (NewTroop.TroopCount > Band.Population)
                {
                    NewTroop.TroopCount = Band.Population;
                }
                newFieldCover = new int[NewTroop.TroopCount];
                for (NumOfField = 0; NumOfField < newFieldCover.Length; NumOfField++)
                {
                    RandomRepeat();
                }

                for (int d = 0; d < newFieldCover.Length; d++)
                {
                    NewTroop.Places[newFieldCover[d]] = true;
                }

                for (int b = 0; b < NewTroop.TroopCount; b++)
                {
                    EnemyData NewEnemy = new EnemyData();
                    NewEnemy.Skin = Random.Range(1, 6);

                    int healthCoof   = Random.Range(1, 9);
                    int damageCoof   = Random.Range(1, 10 - healthCoof);
                    int accuracyCoof = 10 - (healthCoof + damageCoof);

                    NewEnemy.FullHealth = 15 * healthCoof;
                    NewEnemy.Health     = 15 * healthCoof;
                    NewEnemy.Damage     = 15 * damageCoof;
                    NewEnemy.Accuracy   = 15 * accuracyCoof;

                    //NewEnemy.Weapon = Random.Range(1, 6);

                    NewEnemy.Level = Random.Range(4, 10);
                    NewTroop.Enemies.Add(NewEnemy);
                }
            }
        }
        else
        {
            NewTroop.Band       = "Unknown";
            NewTroop.TroopCount = Random.Range(1, 7);

            newFieldCover = new int[NewTroop.TroopCount];
            for (NumOfField = 0; NumOfField < newFieldCover.Length; NumOfField++)
            {
                RandomRepeat();
            }

            for (int d = 0; d < newFieldCover.Length; d++)
            {
                NewTroop.Places[newFieldCover[d]] = true;
            }

            for (int b = 0; b < NewTroop.TroopCount; b++)
            {
                EnemyData NewEnemy = new EnemyData();
                NewEnemy.Skin = Random.Range(1, 6);

                int healthCoof   = Random.Range(1, 9);
                int damageCoof   = Random.Range(1, 10 - healthCoof);
                int accuracyCoof = 10 - (healthCoof + damageCoof);

                NewEnemy.FullHealth = 15 * healthCoof;
                NewEnemy.Health     = 15 * healthCoof;
                NewEnemy.Damage     = 15 * damageCoof;
                NewEnemy.Accuracy   = 15 * accuracyCoof;

                NewEnemy.Level = Random.Range(1, 5);
                NewTroop.Enemies.Add(NewEnemy);
            }
        }


        string       NewEnemyData   = JsonUtility.ToJson(NewTroop);
        StreamWriter WriteEnemyData = new StreamWriter(Application.persistentDataPath + "/BanditTroop.json");

        WriteEnemyData.Write(NewEnemyData);
        WriteEnemyData.Close();
    }
    public SoldierGroup CreateSoldierGroup(float x, float y, float dir_x, float dir_y, TroopData data)
    {
        SoldierGroup group = m_BattleResManager.m_SoldierGroupPool.Create(m_BattleViewRoot);

        group.Init(x, y, dir_x, dir_y, data);
        return(group);
    }
Exemplo n.º 32
0
 public void SetData(TroopData _troop, BattleData _battleData)
 {
     troop      = _troop;
     battleData = _battleData;
 }