Exemplo n.º 1
0
 protected override void LogAdded(GameUnit actor)
 {
     VisibleLogger.GetInstance().LogDebug(string.Format(
                                              "Unit [{0}] registered",
                                              actor.GetId()
                                              ));
 }
Exemplo n.º 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;
            }
        }
Exemplo n.º 3
0
 private void RemoveNetworkid(string networkId)
 {
     if (!_uniqueNetworkIdToGameActorDictionary.Remove(networkId))
     {
         VisibleLogger.GetInstance().LogError(
             string.Format("Missing {0}", networkId)
             );
     }
 }
Exemplo n.º 4
0
        public static TargetSelector GetInstance()
        {
            if (_targetSelector == null)
            {
                VisibleLogger.GetInstance().LogDebug("Target selector initialized");
                _targetSelector = new TargetSelector();
            }

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

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

            _timeOfDie = Time.time;

            LifeState = UnitLifeState.DEAD;
            CmdChangeLifeStateToDead();
        }
Exemplo n.º 7
0
        public new void Start()
        {
            base.Start();

            UnitsManager.GetInstance().Add(this);

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

            name = GetId();
        }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
        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())
                );
        }
Exemplo n.º 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();
        }
Exemplo n.º 11
0
        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();
        }
Exemplo n.º 12
0
        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");
        }
Exemplo n.º 13
0
        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();
            }
        }
Exemplo n.º 14
0
        public void Add(IUpdateable actor)
        {
            VisibleLogger.GetInstance().LogDebug("Updateable added to updateable manager");

            _registered.Add(actor);
        }