private void PrepareEnemyUnits()
    {
        enemyTeamGO = GameObject.FindGameObjectWithTag("Enemy");
        enemyTeam   = enemyTeamGO.GetComponent <UnitTeam>();

        enemyUnit1GO = enemyTeam.GetUnit1GO();
        enemyUnit2GO = enemyTeam.GetUnit2GO();
        enemyUnit3GO = enemyTeam.GetUnit3GO();

        enemyUnit1 = enemyUnit1GO.GetComponent <Unit>();
        enemyUnit2 = enemyUnit2GO.GetComponent <Unit>();
        enemyUnit3 = enemyUnit3GO.GetComponent <Unit>();

        //Ensure that the sprite renderer is enabled
        enemyUnit1GO.GetComponent <SpriteRenderer>().enabled = true;
        enemyUnit2GO.GetComponent <SpriteRenderer>().enabled = true;
        enemyUnit3GO.GetComponent <SpriteRenderer>().enabled = true;

        enemyUnit1GO.GetComponent <Transform>().localScale = enemyUnit1.GetScale();
        enemyUnit2GO.GetComponent <Transform>().localScale = enemyUnit2.GetScale();
        enemyUnit3GO.GetComponent <Transform>().localScale = enemyUnit3.GetScale();

        enemyUnit1GO.GetComponent <Transform>().localPosition = enemyUnit1.GetPosition();
        enemyUnit2GO.GetComponent <Transform>().localPosition = enemyUnit2.GetPosition();
        enemyUnit3GO.GetComponent <Transform>().localPosition = enemyUnit3.GetPosition();
    }
 public UnitViewModel(double _minHealth
                      , double _minAttack
                      , double _minArmor
                      , double _maxHealth
                      , double _maxAttack
                      , double _maxArmor
                      , int _maxAttackSpeed
                      , UnitType _unityType
                      , UnitTeam _team
                      , int _points)
 {
     _timer                 = new DispatcherTimer();
     MinHealth              = Health = _minHealth;
     MinAttack              = Attack = _minAttack;
     MinArmor               = Armor = _minArmor;
     MaxHealth              = _maxHealth;
     MaxAttack              = _maxAttack;
     MaxArmor               = _maxArmor;
     MaxAttackSpeed         = _maxAttackSpeed;
     UnitType               = _unityType;
     Team                   = _team;
     Points                 = _points;
     AttackSpeed            = 0;
     PropertyChanged       += Unity_PropertyChanged;
     AddHealthPoint         = new RelayCommand(OnAddHealthPoint);
     RemoveHealthPoint      = new RelayCommand(OnRemoveHealthPoint);
     AddAttackPoint         = new RelayCommand(OnAddAttackPoint);
     RemoveAttackPoint      = new RelayCommand(OnRemoveAttackPoint);
     AddArmorPoint          = new RelayCommand(OnAddArmorPoint);
     RemoveArmorPoint       = new RelayCommand(OnRemoveArmorPoint);
     AddAttackSpeedPoint    = new RelayCommand(OnAddAttackSpeedPoint);
     RemoveAttackSpeedPoint = new RelayCommand(OnRemoveAttackSpeedPoint);
 }
Exemple #3
0
        internal static UnitEntity GetUnitForTeam(UnitTeam team)
        {
            UnitEntity ue = new UnitEntity();

            ue.TeamID = team;
            return(ue);
        }
Exemple #4
0
 public void Die()
 {
     UnitTeam.MoveUnit(this, 4);
     SetSprite(character.GetSpriteHeader() + "_Hurt");
     fade = true;
     TurnOffUIElemenets();
 }
Exemple #5
0
 public void LoadResourcesToBase()
 {
     if (carriedResource.type == ResourceType.None)
     {
         return;
     }
     UnitTeam.AddResource(carriedResource);
     DropResources();
 }
Exemple #6
0
    public void Setup(UnitManager unitManager, UnitTeam team)
    {
        UnitManager = unitManager;
        Team        = team;

        if (graphics)
        {
            graphics.SetColor(team.UnitColor);
        }
    }
Exemple #7
0
    private BoardCell GetRandomCellToSpawnUnitAt(UnitTeam forTeam)
    {
        BoardGenerator boardGenerator = GameBoard.Instance.Generator;
        int            columns        = boardGenerator.BoardSize.x;

        int startIndex = forTeam.Side == TeamSide.Left ? 0 : columns - forTeam.SpawnColumns;
        int endIndex   = startIndex + forTeam.SpawnColumns - 1;

        return(boardGenerator.GetRandomEmptyCellInColumnRange(startIndex, endIndex));
    }
            public static IEnumerable <Obj_AI_Minion> Get(
                EntityType type,
                UnitTeam minionTeam    = UnitTeam.Enemy,
                Vector3?sourcePosition = null,
                float radius           = float.MaxValue,
                bool addBoundingRadius = true)
            {
                // Filter the entity team and type
                IEnumerable <Obj_AI_Minion> entities;

                switch (type)
                {
                case EntityType.Minion:

                    switch (minionTeam)
                    {
                    case UnitTeam.Ally:

                        entities = AlliedMinions;
                        break;

                    case UnitTeam.Enemy:

                        entities = EnemyMinions;
                        break;

                    default:

                        entities = Minions;
                        break;
                    }
                    break;

                case EntityType.Monster:

                    entities = Monsters;
                    break;

                default:

                    entities = CombinedAttackable;
                    break;
                }

                if (entities == null)
                {
                    return(new List <Obj_AI_Minion>());
                }

                // Remove all invalid targets
                entities = entities.Where(o => (sourcePosition ?? Player.Instance.ServerPosition).IsInRange(o, radius + (addBoundingRadius ? o.BoundingRadius : 0)));

                // Sort the list decending by max health and return
                return(entities.OrderByDescending(o => o.MaxHealth).ToList());
            }
Exemple #9
0
 private void OnGameEnded(UnitTeam winnerTeam)
 {
     if (winnerTeam == null)
     {
         winText.text = "DRAW!";
     }
     else
     {
         winText.text = $"{winnerTeam.TeamName.ToUpper()} TEAM WON!";
     }
 }
Exemple #10
0
    private void SpawnUnitAt(BoardCell cell, UnitTeam team)
    {
        Unit unit = Instantiate(team.UnitPrefab, transform);

        unit.Setup(UnitManager, team);
        unit.SpawnAt(cell);

        unit.OnDone.AddListener(() => UnitManager.OnUnitDone(unit));

        UnitManager.Units.Add(unit);
    }
        /// <summary>
        /// Starts the given team's turn, ending the current turn if needed
        /// </summary>
        /// <param name="team"></param>
        public void StartTurn(UnitTeam team)
        {
            if (teamTurn != team)
            {
                EndTurn(teamTurn);
                teamTurn = team;
            }

            foreach (UnitEntity ue in UnitBook.GetRoster(team).GetAllUnits())
            {
                ue.HasActed = false;
            }
        }
Exemple #12
0
    private void SpawnUnitsForTeam(UnitTeam team)
    {
        int unitCount = Random.Range(team.UnitSpawnCountRange.min, team.UnitSpawnCountRange.max + 1);

        for (int unitIdx = 0; unitIdx < unitCount; unitIdx++)
        {
            BoardCell randomCell = GetRandomCellToSpawnUnitAt(team);

            if (randomCell)
            {
                SpawnUnitAt(randomCell, team);
            }
        }
    }
 /// <summary>
 /// Goes through all units for the active player and sets "HasActed" to true. This will end the turn for this team.
 /// </summary>
 /// <param name="team"></param>
 public void EndTurn(UnitTeam team)
 {
     if (teamTurn == UnitTeam.none)
     {
         return;
     }
     if (teamTurn != team)
     {
         throw new TurnOrderException("Not the player's turn");
     }
     foreach (UnitEntity ue in UnitBook.GetRoster(team).GetAllUnits())
     {
         ue.HasActed = true;
     }
 }
Exemple #14
0
        public UnitRoster(UnitEntity[] unit, UnitTeam teamID)
        {
            TeamID = teamID;

            this.units = new HashSet <UnitEntity>();

            if (unit == null)
            {
                return;
            }

            foreach (UnitEntity mu in unit)
            {
                AddUnit(mu);
            }
        }
    private void CheckForGameEnd()
    {
        int countOfAliveTeams = UnitManager.Units.Select(x => x.Team).Distinct().Count();

        if (countOfAliveTeams <= 1)
        {
            UnitTeam winnerTeam = null;

            if (countOfAliveTeams == 1)
            {
                winnerTeam = UnitManager.Units.First().Team;
            }

            OnGameEnded(winnerTeam);
        }
    }
    /// <summary>
    /// Sets the players team level to the same level as the player.
    /// </summary>
    private void SetPetLevelsToPlayerLevel()
    {
        UnitTeam playerTeam = player.GetComponent <UnitTeam>();

        if (playerTeam.unit1 != null)
        {
            playerTeam.unit1.GetComponent <Unit>().unitLevel = level;
        }
        if (playerTeam.unit2 != null)
        {
            playerTeam.unit2.GetComponent <Unit>().unitLevel = level;
        }
        if (playerTeam.unit3 != null)
        {
            playerTeam.unit3.GetComponent <Unit>().unitLevel = level;
        }
    }
        /// <summary>
        /// When a unit dies, the MainViewModel unsubscribes the unit events, restores unit points to the
        /// total of the team points and remove it from the field of battle.
        /// </summary>
        /// <param name="sender">The dead unit</param>
        /// <param name="Team">The team of the dead unit</param>
        private void Unit_UnitDied(object sender, UnitTeam Team)
        {
            var unit = sender as UnitViewModel;

            unit.UnitAttack -= Unit_UnitAttack;
            unit.UnitDied   -= Unit_UnitDied;
            if (Team == UnitTeam.Red)
            {
                ListRedUnits.Remove(unit);
                ObserverHelper <MainViewModel, int> .NotifyObservers(unit, RedPoints + unit.UsedPoints);
            }
            else
            {
                ListBlueUnits.Remove(unit);
                ObserverHelper <MainViewModel, int> .NotifyObservers(unit, BluePoints + unit.UsedPoints);
            }
        }
Exemple #18
0
 public virtual void OnPointerEnter(PointerEventData p)
 {
     if (tooltip.currentAbility != null && showUI)
     {
         if (tooltip.currentAbility.isAOE)
         {
             foreach (Unit u in UnitTeam.GetUnits())
             {
                 u.SetChangeIndicators(true);
                 u.SetToolTipActive(true);
             }
         }
         else
         {
             SetChangeIndicators(true);
             tooltip.gameObject.SetActive(true);
         }
     }
 }
Exemple #19
0
 public virtual void OnPointerExit(PointerEventData p)
 {
     if (tooltip.currentAbility == null)
     {
         return;
     }
     if (tooltip.currentAbility.isAOE)
     {
         foreach (Unit u in UnitTeam.GetUnits())
         {
             u.SetChangeIndicators(false);
             u.SetToolTipActive(false);
         }
     }
     else
     {
         SetChangeIndicators(false);
         tooltip.gameObject.SetActive(false);
     }
 }
Exemple #20
0
        /// <summary>
        /// Returns the positions of all units on a given team.
        /// </summary>
        /// <param name="teamID"></param>
        /// <returns></returns>
        private List <Position> GetUnitAllies(UnitTeam teamID)
        {
            List <Position> retPos = new List <Position>();

            int w = unitMap.GetLength(0);             // width
            int h = unitMap.GetLength(1);             // height


            for (int x = 0; x < w; ++x)
            {
                for (int y = 0; y < h; ++y)
                {
                    if (unitMap[x, y] != null && unitMap[x, y].Stats.TeamID == teamID)
                    {
                        retPos.Add(new Position(x, y));
                    }
                }
            }
            return(retPos);
        }
    /// <summary>
    /// When loading this scene from a different scene these two functions will set the
    /// player and enemy units to the correct ones dependent on what enemy was encountered and
    /// how the team of the player was built up
    /// </summary>
    private void PrepareFriendlyUnits()
    {
        friendlyTeamGO = GameObject.FindGameObjectWithTag("Player");
        friendlyTeam   = friendlyTeamGO.GetComponent <UnitTeam>();

        friendlyUnit1GO = friendlyTeam.GetUnit1GO();
        friendlyUnit2GO = friendlyTeam.GetUnit2GO();
        friendlyUnit3GO = friendlyTeam.GetUnit3GO();

        friendlyUnit1 = friendlyUnit1GO.GetComponent <Unit>();
        friendlyUnit2 = friendlyUnit2GO.GetComponent <Unit>();
        friendlyUnit3 = friendlyUnit3GO.GetComponent <Unit>();

        //Ensure that the sprite renderer is enabled
        SetFriendlySprite(true);

        friendlyUnit1GO.GetComponent <Transform>().localScale = friendlyUnit1.GetScale();
        friendlyUnit2GO.GetComponent <Transform>().localScale = friendlyUnit2.GetScale();
        friendlyUnit3GO.GetComponent <Transform>().localScale = friendlyUnit3.GetScale();

        friendlyUnit1GO.GetComponent <Transform>().localPosition = friendlyUnit1.GetPosition();
        friendlyUnit2GO.GetComponent <Transform>().localPosition = friendlyUnit2.GetPosition();
        friendlyUnit3GO.GetComponent <Transform>().localPosition = friendlyUnit3.GetPosition();
    }
Exemple #22
0
 public static IEnumerable <Obj_AI_Minion> GetLaneMinions(UnitTeam minionTeam = UnitTeam.Enemy, Vector3?sourcePosition = null, float radius = float.MaxValue, bool addBoundingRadius = true)
 {
     return(Get(EntityType.Minion, minionTeam, sourcePosition, radius, addBoundingRadius));
 }
Exemple #23
0
        public void Command(ChatParser.Command command)
        {
            if (HitPoints.IsAlive == false)
            {
                return;
            }
            switch (command.commandType)
            {
            case ChatParser.ChatCommands.Gather:
                GatherResource(command.resourceType);
                break;

            case ChatParser.ChatCommands.Build:
                if (CurrentJob.canBuild == false)
                {
                    return;
                }
                unitBehaviour.Build(command.buildingType, command.position, command.direction);
                break;

            case ChatParser.ChatCommands.Job:
                if (command.jobType == CurrentJob.jobType || TryGetJobFromType(command.jobType, out var job) == false || UnitTeam.CheckHasBuilding(job.buildingNeeded) == false)
                {
                    return;
                }
                unitBehaviour.ChangeJob(job);
                break;

            case ChatParser.ChatCommands.Patrol:
                if (CurrentJob.canPatrol == false)
                {
                    return;
                }
                unitBehaviour.Patrol(command.position, command.secondPosition);
                break;

            case ChatParser.ChatCommands.Move:
                unitBehaviour.Move(command.position);
                break;

            case ChatParser.ChatCommands.Kill:
                var  enemyTeam = GameController.Instance.GetEnemyTeam(UnitTeam);
                Unit target    = string.IsNullOrEmpty(command.targetName) == false?enemyTeam.GetUnit(command.targetIndex) : (command.teamTag != UnitTeam.teamTag ? enemyTeam.GetUnit(command.targetIndex) : null);

                if (target == null)
                {
                    return;
                }
                unitBehaviour.AttackTarget(target.HitPoints);
                break;
            }
        }
 private void SetPlayerTeam()
 {
     playerTeam = battleSystem.friendlyTeamGO.GetComponent <UnitTeam>();
 }
Exemple #25
0
 public IEnumerable <MapUnit> Units(UnitTeam team)
 {
     return(Units(x => x.team == team));
 }
 /// <summary>
 /// Simple factory to generate new units.
 /// </summary>
 /// <param name="_team">The team of the new unit</param>
 /// <param name="_points">The team points avaliable</param>
 /// <returns>A new instance of UnitViewModel</returns>
 public static UnitViewModel GetNewInfantry(UnitTeam _team, int _points)
 {
     return(new UnitViewModel(50, 15, 20, 100, 30, 50, 200, UnitType.Infantry, _team, _points));
 }
 public static UnitViewModel GetNewRanged(UnitTeam _team, int _points)
 {
     return(new UnitViewModel(30, 35, 10, 100, 40, 50, 500, UnitType.Ranged, _team, _points));
 }
 public static UnitViewModel GetNewCavalry(UnitTeam _team, int _points)
 {
     return(new UnitViewModel(60, 20, 10, 150, 50, 30, 100, UnitType.Cavalary, _team, _points));
 }
        /// <summary>
        /// When a unit attacks, a random unit from the opposite team is chosen to be the target.
        /// Both unit types are compared to see if a +50% attack bonus can be applied.
        /// The final attack value is defined by : (sender.attack + bonus) - target.armor
        /// </summary>
        /// <param name="sender">The attacking unit</param>
        /// <param name="AttackPower">The attack power of the attacking unit</param>
        /// <param name="UnityType">The type of the attacking unit</param>
        /// <param name="Team">The team of the attacking unit</param>
        private void Unit_UnitAttack(object sender, double AttackPower, UnitType UnityType, UnitTeam Team)
        {
            var targetTeam = Team == UnitTeam.Red ? ListBlueUnits : ListRedUnits;

            if (targetTeam.Any())
            {
                var index      = _rand.Next(0, targetTeam.Count() - 1);
                var target     = targetTeam.ElementAt(index);
                var realAttack = GetAttackBonus(AttackPower, UnityType, target.UnitType);
                realAttack     = ((100 - target.Armor) * realAttack) / 100;
                target.Health -= realAttack;
            }
        }
        ///// <summary>
        ///// Returns a list of actions available to the given unit, were it at the given position (presumably already
        ///// calculated to be a viable movement target)
        ///// </summary>
        ///// <param name="unit"></param>
        ///// <param name="newPosition"></param>
        ///// <returns></returns>
        //public List<MapActionCommand> GetMapActionsForUnit(UnitEntity unit, Position newPosition)
        //{
        //	List<MapActionCommand> retList = new List<MapActionCommand>();
        //	//retList.Add(MapActionCommand.Wait); //wait always available.

        //	////get attack range, and check team relationship in relevant tiles
        //	//foreach (Position range in unit.AllAttackRanges())
        //	//{
        //	//	Position targ = newPosition + range;
        //	//	UnitTeam targTeam = GetTile(targ.xPos, targ.yPos);
        //	//	if (targ.xPos == unit.xPos && targ.yPos == unit.yPos) continue; //can't attack yourself

        //	//	if (targTeam != UnitTeam.none && targTeam != UnitTeam.playerTeam)
        //	//	{
        //	//		retList.Add(MapActionCommand.Attack);
        //	//		break;
        //	//	}
        //	//}

        //	////get utility range, and check team relationship in relevant tiles
        //	//foreach (Position range in unit.AllUtilityRanges())
        //	//{
        //	//	Position targ = newPosition + range;
        //	//	UnitTeam targTeam = GetTile(targ.xPos, targ.yPos);
        //	//	if (targ.xPos == unit.xPos && targ.yPos == unit.yPos) continue; //can't utility yourself

        //	//	if (targTeam != UnitTeam.none && targTeam == UnitTeam.playerTeam)
        //	//	{
        //	//		retList.Add(MapActionCommand.Heal);
        //	//		break;
        //	//	}
        //	//}

        //	return retList;
        //}



        /// <summary>
        /// Returns a UnitRoster of all Units in the Session for the given team
        /// </summary>
        /// <param name="team"></param>
        /// <returns></returns>
        public UnitRoster GetUnits(UnitTeam team)
        {
            return(UnitBook.GetRoster(team));
        }