Пример #1
0
 private void Update()
 {
     if (CanClick && Input.GetMouseButtonDown(0) && ParentProduction.IsProductionOverlayActive &&
         !ParentProduction.BuildingClickedProduction.Tile.HasUnit())
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit touchBox;
         if (Physics.Raycast(ray, out touchBox))
         {
             if (touchBox.collider == this.collider)
             {
                 BuildingGameObject buildingToProduceFrom = ParentProduction.BuildingClickedProduction;
                 // Kind of ugly yet could not find better solution. The unit is created before we check if it can be bought.
                 // Set it inactive immediatly and then check for enough Gold. If not then destroy else decrease the Gold and set it active.
                 UnitGameObject unit = CreatorFactoryUnit.CreateUnit(buildingToProduceFrom.Tile,
                                                                     buildingToProduceFrom.index, type);
                 unit.gameObject.SetActive(false);
                 if (lm.CurrentLevel.CurrentPlayer.CanBuy(unit.UnitGame.Cost))
                 {
                     unit.gameObject.SetActive(true);
                     lm.CurrentLevel.CurrentPlayer.DecreaseGoldBy(unit.UnitGame.Cost);
                     CanClick = false;
                     ParentProduction.InitiateMoving(true);
                 }
                 else
                 {
                     Notificator.Notify("Not enough gold!", 1.5f);
                     unit.DestroyUnit();
                 }
             }
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Get called whenever an OnHighlightClick is fired. If it is possible it will attack an enemy unit.
        /// </summary>
        /// <param Name="evt"></param>
        public void BattlePreparation(OnHighlightClick evt)
        {
            if (evt.highlight != null)
            {
                HighlightObject highlightObj = evt.highlight;
                if (highlight.IsHighlightOn && !movement.NeedsMoving &&
                    highlightObj.highlightTypeActive == HighlightTypes.highlight_attack)
                {
                    UnitGameObject attackingUnit = highlight.UnitSelected;
                    UnitGameObject defendingUnit = highlightObj.Tile.unitGameObject;


                    if (!attackingUnit.UnitGame.HasAttacked)
                    {
                        if (!attackingUnit.UnitGame.HasMoved ||
                            (attackingUnit.UnitGame.HasMoved && attackingUnit.UnitGame.CanAttackAfterMove))
                        {
                            if (TileHelper.IsTileWithinRange(attackingUnit.transform.position,
                                                             defendingUnit.transform.position, attackingUnit.UnitGame.AttackRange))
                            {
                                attackingUnit.UnitGame.HasAttacked = true;
                                attackingUnit.UnitGame.HasMoved    = true;
                                attackingUnit.UnitGame.PlaySound(UnitSoundType.Attack);

                                highlight.ClearHighlights();

                                // Check if units are faces the wrong way
                                FacingDirectionUnits(attackingUnit, defendingUnit);

                                // Dispatch the animation fight event. But set the needsanimating to true.
                                OnAnimFight fight = new OnAnimFight();
                                fight.attacker       = attackingUnit;
                                fight.defender       = defendingUnit;
                                fight.needsAnimating = true;
                                EventHandler.dispatch(fight);
                            }
                            else
                            {
                                Notificator.Notify("Move to this unit to attack!", 1f);
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        public void TurnIncrease()
        {
            dayTurnCounter++;
            LevelManager lm          = GameObjectReferences.GetGlobalScriptsGameObject().GetComponent <LevelManager>();
            int          turnsNeeded = lm.CurrentLevel.dayNightTurns[CurrentDayState];
            bool         ended       = dayTurnCounter > turnsNeeded;

            if (ended)
            {
                int newNumber = (int)CurrentDayState + 1;
                int highest   = 0;
                foreach (DayStates day in (DayStates[])Enum.GetValues(typeof(DayStates)))
                {
                    int n = (int)day;

                    if (n > highest)
                    {
                        highest = n;
                    }

                    if (newNumber > highest)
                    {
                        CurrentDayState = DayStates.Morning;
                        dayTurnCounter  = 1;
                    }
                    else if (n == newNumber)
                    {
                        CurrentDayState = day;
                        dayTurnCounter  = 1;
                    }
                }
                StartTime = Time.time;
                Notificator.Notify(CurrentDayState.ToString() + " has arrived", 1.5f);
            }
            else
            {
                int turnsRemaining = (turnsNeeded - dayTurnCounter) + 1;
                Notificator.Notify(turnsRemaining + " turns remaining before new daystate!", 1.1f);
            }

            SetFowOfWar();
        }
Пример #4
0
    public void NotifyEvent(string dest, string event_key)
    {
        dest = dest.ToLower();
        Notificator selectedNot = null;

        if (dest.Equals("osiris"))
        {
            selectedNot = osirisNotificator;
        }
        if (dest.Equals("isis"))
        {
            selectedNot = isisNotificator;
        }
        if (selectedNot != null)
        {
            if (!triggeredEvents[event_key])
            {
                selectedNot.gameObject.SetActive(true);
                selectedNot.Notify(events[event_key]);
                triggeredEvents[event_key] = true;
            }
        }
    }