Ejemplo n.º 1
0
        public void AddArmyFromBorderBattle(VisualArmy armyPrefab, Army army)
        {
            Armies.Add(army);
            SupportOnly = Armies.All(x => x.Type == ArmyType.Support);

            if (!Territories.Contains(army.TargetTerritory))
            {
                Territories.Add(army.TargetTerritory);
            }
            if (!Players.Contains(army.SourcePlayer))
            {
                Players.Add(army.SourcePlayer);
            }
            if (!Players.Contains(army.TargetPlayer))
            {
                Players.Add(army.TargetPlayer);
            }


            // Visual
            List <Vector2> walkPath = new List <Vector2>();

            if (army.IsWaterArmy)
            {
                WaterConnection wc = army.SourceTerritory.Region.GetWaterConnectionTo(army.TargetTerritory.Region);
                System.Tuple <Vector2, float> center = new System.Tuple <Vector2, float>(wc.Center, wc.FromRegion == army.SourceTerritory.Region ? wc.Angle - 90 : wc.Angle + 90);
                Vector2 borderCenter     = center.Item1;
                float   targetAngle      = center.Item2 + 180;
                float   approachDistance = wc.Length / 2f;
                float   xTarget          = Mathf.Sin(Mathf.Deg2Rad * targetAngle) * approachDistance;
                float   yTarget          = Mathf.Cos(Mathf.Deg2Rad * targetAngle) * approachDistance;
                Vector2 coastPos         = borderCenter + new Vector2(xTarget, yTarget);
                walkPath.Add(borderCenter);
                walkPath.Add(coastPos);
            }
            else
            {
                System.Tuple <Vector2, float> center = army.SourceTerritory.Region.GetBorderCenterPositionTo(army.TargetTerritory.Region);
                Vector2 borderCenter = center.Item1;
                walkPath.Add(borderCenter);
            }
            Vector2 targetPos = army.TargetTerritory.Region.CenterPoi;

            walkPath.Add(targetPos);

            VisualArmy visualArmy = GameObject.Instantiate(armyPrefab);

            visualArmy.Init(army, walkPath, ParriskGame.ArmyApproachTime);
        }