コード例 #1
0
        void OnGoButtonClicked(UISoldierChoiceMultiple control, List <int> indexes)
        {
            control.HiddenEvent          -= OnControlHidden;
            control.GoButtonClickedEvent -= OnGoButtonClicked;

            if (targetTower != null && targetTower.OccupiedByEnemy)
            {
                var soldiers = building.RemoveSoldiers(indexes);
                for (int i = 0; i < soldiers.Count; i++)
                {
                    soldiers[indexes[i]].FreedOccupiedTower(targetTower.GetComponent <OccupiedByEnemy>());
                }
            }
            else if (targetBuilding != null)
            {
                var soldiers = building.RemoveSoldiers(indexes);
                targetBuilding.AddSoldiers(soldiers);
            }
            else if (targetWizard != null)
            {
                var soldiers = building.UnloadSoldiers(indexes);
                for (int i = 0; i < soldiers.Count; i++)
                {
                    soldiers[indexes[i]].AttackWizard(targetWizard);
                }
            }
            else if (targetFood != null)
            {
                var soldiers = building.UnloadSoldiers(indexes);
                for (int i = 0; i < soldiers.Count; i++)
                {
                    soldiers[indexes[i]].TakeFood(targetFood);
                }
            }
        }
コード例 #2
0
        void EnterTower()
        {
            ArrivedDestinationEvent -= EnterTower;

            if (DefendingTower.OccupiedByEnemy)
            {
                DefendingTower.GetComponent <OccupiedByEnemy>().ReturnMob(this);
            }
            else
            {
                _moveByPath.AssignToClosestWaypoint();
            }
        }
コード例 #3
0
        public void OnDragEnded(Vector2 point)
        {
            if (_dragArrow != null)
            {
                int hits = Physics2D.RaycastNonAlloc(Camera.main.ScreenToWorldPoint(point),
                                                     Vector2.zero, results, Mathf.Infinity, dragEndFilter);

                if (hits > 0)
                {
                    var target = results[hits - 1].transform.gameObject;
                    if (target != null && target.GetInstanceID() != gameObject.GetInstanceID())
                    {
                        building = GetComponent <Building>();

                        targetTower = target.GetComponent <Tower>();
                        if (targetTower != null)
                        {
                            if (targetTower.OccupiedByEnemy)
                            {
                                if (building.SoldiersCount == 1)
                                {
                                    building.RemoveLastSoldier().FreedOccupiedTower(targetTower.GetComponent <OccupiedByEnemy>());
                                }
                                else
                                {
                                    var control = UILevelControlsManager.Instance.GetControl <UISoldierChoiceMultiple>(
                                        UILevelControlsManager.LevelControl.SoldierChoiceMultiple);
                                    control.Show(building);
                                    control.GoButtonClickedEvent += OnGoButtonClicked;
                                    control.HiddenEvent          += OnControlHidden;
                                }
                                _dragArrow.End();
                                _dragArrow = null;
                                return;
                            }
                        }

                        targetBuilding = target.GetComponent <Building>();
                        if (targetBuilding != null)
                        {
                            if (targetBuilding.SoldiersCount >= targetBuilding.MaxSoldiersCount)
                            {
                                _dragArrow.End();
                                _dragArrow = null;
                                return;
                            }

                            if (building.SoldiersCount == 1)
                            {
                                targetBuilding.AddSoldier(building.RemoveLastSoldier());
                            }
                            else
                            {
                                var control = UILevelControlsManager.Instance.GetControl <UISoldierChoiceMultiple>(UILevelControlsManager.LevelControl.SoldierChoiceMultiple);
                                control.Show(building, targetBuilding);
                                control.GoButtonClickedEvent += OnGoButtonClicked;
                                control.HiddenEvent          += OnControlHidden;
                            }
                        }

                        targetWizard = target.GetComponent <Wizard>();
                        if (targetWizard != null)
                        {
                            if (building.SoldiersCount == 1)
                            {
                                building.UnloadLastSoldier().AttackWizard(targetWizard);
                            }
                            else
                            {
                                var control = UILevelControlsManager.Instance.GetControl <UISoldierChoiceMultiple>(UILevelControlsManager.LevelControl.SoldierChoiceMultiple);
                                control.Show(building);
                                control.GoButtonClickedEvent += OnGoButtonClicked;
                                control.HiddenEvent          += OnControlHidden;
                            }
                        }

                        targetFood = target.GetComponent <Food>();
                        if (targetFood != null && !targetFood.SoldierAssigned)
                        {
                            if (building.SoldiersCount == 1)
                            {
                                building.UnloadLastSoldier().TakeFood(targetFood);
                            }
                            else
                            {
                                var control = UILevelControlsManager.Instance.GetControl <UISoldierChoiceMultiple>(
                                    UILevelControlsManager.LevelControl.SoldierChoiceMultiple);
                                control.Show(building);
                                control.GoButtonClickedEvent += OnGoButtonClicked;
                                control.HiddenEvent          += OnControlHidden;
                            }
                        }

                        targetTrapPlace = target.GetComponent <TrapPlace>();
                        if (targetTrapPlace != null && !targetTrapPlace.IsBusy)
                        {
                            var control = UILevelControlsManager.Instance.GetControl <UITrapChoiceClouds>(
                                UILevelControlsManager.LevelControl.TrapChoice);
                            control.Show(point, targetTrapPlace);
                            control.TrapChosenEvent += OnTrapChosen;
                            control.HiddenEvent     += OnControlHidden;
                        }
                    }
                }

                _dragArrow.End();
                _dragArrow = null;
            }
        }