Exemple #1
0
 protected override void LogAdded(GameUnit actor)
 {
     VisibleLogger.GetInstance().LogDebug(string.Format(
                                              "Unit [{0}] registered",
                                              actor.GetId()
                                              ));
 }
Exemple #2
0
        public void CmdPerfomAttack(string defenderId, Team attackerTeam, float attackPoints)
        {
            GameActor defender = UnitsManager.GetInstance().GetByUniqueNetworkId(defenderId);

            if (defender == null)
            {
                defender = BuildingsManager.GetInstance().GetByUniqueNetworkId(defenderId);
            }

            VisibleLogger.GetInstance().LogDebug(
                string.Format("Damage [{0}] for {1}",
                              defender.GetId()
                              , attackPoints
                              ));

            defender.ActorAttributes.HealthPoints -= attackPoints;

            if (HpLessThanZero(defender) && defender.LifeState == GameActor.UnitLifeState.LIVING)
            {
                VisibleLogger.GetInstance().LogDebug(
                    string.Format("Changing [{0}] state {1} -> {2}",
                                  defender.GetId()
                                  , defender.LifeState,
                                  GameActor.UnitLifeState.WAITING_FOR_DEAD_ACTION
                                  ));

                PlayersManager.GetInstance().Get(attackerTeam).Gold += defender.ActorAttributes.KillReward;

                defender.LifeState = GameActor.UnitLifeState.WAITING_FOR_DEAD_ACTION;
            }
        }
 private void RemoveNetworkid(string networkId)
 {
     if (!_uniqueNetworkIdToGameActorDictionary.Remove(networkId))
     {
         VisibleLogger.GetInstance().LogError(
             string.Format("Missing {0}", networkId)
             );
     }
 }
        public static TargetSelector GetInstance()
        {
            if (_targetSelector == null)
            {
                VisibleLogger.GetInstance().LogDebug("Target selector initialized");
                _targetSelector = new TargetSelector();
            }

            return(_targetSelector);
        }
Exemple #5
0
        public void ExitGame()
        {
            VisibleLogger.GetInstance().LogDebug("Exit button pressed");

#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
#else
            Application.Quit();
#endif
        }
        public override void OnDeadAction()
        {
            VisibleLogger.GetInstance().LogDebug(
                string.Format("OnDeadAction [{0}]", GetId())
                );

            _timeOfDie = Time.time;

            LifeState = UnitLifeState.DEAD;
            CmdChangeLifeStateToDead();
        }
Exemple #7
0
        public new void Start()
        {
            base.Start();

            UnitsManager.GetInstance().Add(this);

            VisibleLogger.GetInstance().LogDebug(
                string.Format("Start [{0}]", GetId())
                );

            name = GetId();
        }
        public override void OnConstructionComplete()
        {
            _timeOfLastSpawn = Time.time;

            VisibleLogger.GetInstance().LogDebug(
                string.Format("OnConstructionComplete [{0}]", GetId())
                );

            // Events that shall occur only one time per object lifetime
            // have to be set locally to prevent multiple invocation
            LifeState = UnitLifeState.LIVING;
            CmdChangeStateToLiving();
        }
        public new void Start()
        {
            base.Start();

            _productionOutput         = Transform.localPosition + Transform.localRotation * new Vector3(8, 0, 0);
            _targetPositionAfterBuild = Transform.localPosition;

            _constructionStartTime = Time.time;

            VisibleLogger.GetInstance().LogDebug(
                string.Format("Start [{0}]", GetId())
                );
        }
Exemple #10
0
        public override void OnDeadAction()
        {
            LifeState = UnitLifeState.DEAD;

            VisibleLogger.GetInstance().LogDebug(
                string.Format("OnDeadAction [{0}]", GetId())
                );

            Animator.SetBool("IsAttacking", false);
            Animator.SetBool("IsDead", true);
            _timeOfDie = Time.time;
            Destroy(GetComponent <NavMeshAgent>());

            CmdChangeToDead();
        }
        public void PerformUpdate()
        {
            foreach (var unit in _registered.Where(
                         u => u.LifeState == GameActor.UnitLifeState.WAITING_FOR_DISPOSAL
                         ))
            {
                try
                {
                    _uniqueNetworkIdToGameActorDictionary.Remove(unit.UniqeNetworkId);

                    try
                    {
                        if (unit.hasAuthority)
                        {
                            NetworkServer.Destroy(unit.gameObject);
                        }
                    }
                    catch (Exception e)
                    {
                        VisibleLogger.GetInstance().LogException(e);
                    }

                    VisibleLogger.GetInstance().LogDebug(
                        string.Format("<color=orange>Destroyed [{0}]</color>", unit.GetId())
                        );
                }
                catch (Exception ex)
                {
                    VisibleLogger.GetInstance().LogException(ex);
                }
            }

            int removedCount = _registered.RemoveAll(
                u => u.LifeState == GameActor.UnitLifeState.WAITING_FOR_DISPOSAL
                );

            if (removedCount > 0)
            {
                VisibleLogger.GetInstance().LogDebug(
                    string.Format("Removed {0} objects", removedCount)
                    );
            }

            UpdateLifecycle();
        }
        public void Start()
        {
            VisibleLogger.GetInstance().LogDebug("Initializing in order");

            UpdateablesManager.Add(UnitsManager.GetInstance());
            UpdateablesManager.Add(BuildingsManager.GetInstance());

            foreach (var preplayBuildingInitializer in GetComponents <PreplayBuildingInitializer>())
            {
                preplayBuildingInitializer.InitInOrder();
                Destroy(preplayBuildingInitializer);
            }

            foreach (var initializableChild in Gui.GetComponentsInChildren <IInOrderInitializable>())
            {
                initializableChild.InitInOrder();
            }

            VisibleLogger.GetInstance().LogDebug("Initializing in order successfully finished");
        }
        public override void UpdateWhenUnderConstruction()
        {
            float totalBuildingTime = Time.time - _constructionStartTime;

            Transform.localPosition = (
                _targetPositionAfterBuild + new Vector3(
                    0
                    , (1 - ((totalBuildingTime) / BuildingAttributes.ConstructionTime)) * -10
                    , 0
                    )
                );

            if (totalBuildingTime >= BuildingAttributes.ConstructionTime)
            {
                VisibleLogger.GetInstance().LogDebug(
                    string.Format("Constucted [{0}]", GetId())
                    );

                CmdChangeStateToWaitingForOnConstructed();
            }
        }
Exemple #14
0
        public void Add(IUpdateable actor)
        {
            VisibleLogger.GetInstance().LogDebug("Updateable added to updateable manager");

            _registered.Add(actor);
        }