Example #1
0
        public void Serialize(LittleEndianWriter writer)
        {
            writer.WriteUInt(TargetNetId);
            writer.WriteUInt(NetAssignedNetId);
            writer.WriteUInt(CasterNetId);

            writer.WriteUInt(BindNetId);

            writer.WriteUInt(KeywordNetId);


            writer.WriteShort(PositionX);
            writer.WriteFloat(PositionY);
            writer.WriteShort(PositionZ);
            writer.WriteShort(TargetPositionX);
            writer.WriteFloat(TargetPositionY);
            writer.WriteShort(TargetPositionZ);
            writer.WriteShort(OwnerPositionX);
            writer.WriteFloat(OwnerPositionY);
            writer.WriteShort(OwnerPositionZ);

            OrientationVector.Serialize(writer);
            writer.WriteFloat(TimeSpent);
            writer.WriteFloat(ScriptScale);
        }
Example #2
0
        private void InstantRefresh()
        {
            var bot = _gameState[_botId];

            transform.position    = _gameState.ArenaToWorldPosition(bot.X, bot.Y);
            transform.eulerAngles = OrientationVector.CreateFrom(bot.Orientation);
            _lastAnimation        = null;
        }
 public void InstantRefresh()
 {
     if (_bot != null)
     {
         transform.position    = _arenaController.ArenaToWorldPosition(_bot.X, _bot.Y);
         transform.eulerAngles = OrientationVector.CreateFrom(_bot.Orientation);
         _lastAnimation        = null;
     }
 }
Example #4
0
 public void instantRefresh()
 {
     if (_bot != null)
     {
         transform.position    = GridController.Instance.gridToWorldPosition(_bot.Location.X, _bot.Location.Y);
         transform.eulerAngles = OrientationVector.createFrom(_bot.Orientation);
         lastPlayedAnim        = null;
     }
 }
        void Update()
        {
            // If the bot is not available.
            if (_bot == null || _died)
            {
                return;
            }

            // If the robot is confused.
            if (_bot.Move == PossibleMoves.ScriptError)
            {
                RunAnimationOnce(Animations.Defend);
                if (_errorGameObject == null)
                {
                    _errorGameObject = Instantiate(ErrorPrefab);
                    _errorGameObject.transform.SetParent(Head);
                    _errorGameObject.transform.localPosition = new Vector3(0, 0, 0);
                    _errorGameObject.transform.position      = new Vector3(_errorGameObject.transform.position.x, 2.5f, _errorGameObject.transform.position.z);
                }
                return;
            }

            if (_errorGameObject != null)
            {
                Destroy(_errorGameObject);
                _errorGameObject = null;
            }

            float   step = Math.Abs(_bot.X - _bot.FromX) > 1 || Math.Abs(_bot.Y - _bot.FromY) > 1 ? 100 : MovementSpeed * Time.deltaTime;
            Vector3 targetWorldPosition = _arenaController.ArenaToWorldPosition(_bot.X, _bot.Y);
            Vector3 newPos = Vector3.MoveTowards(transform.position, targetWorldPosition, step);

            if ((newPos - transform.position).magnitude > 0.01)
            {
                RunAnimation(Animations.Walk);
                transform.position = newPos;
                return;
            }

            Vector3 targetOrientation = OrientationVector.CreateFrom(_bot.Orientation);
            float   rotationStep      = RotationSpeed * Time.deltaTime;
            Vector3 newDir            = Vector3.RotateTowards(transform.forward, targetOrientation, rotationStep, 0.0F);

            if (targetOrientation != newDir)
            {
                transform.rotation = Quaternion.LookRotation(newDir);
            }

            if ((targetOrientation - newDir).magnitude > 0.01)
            {
                RunAnimation(Animations.Turn);
                return;
            }

            // If the robot has died.
            if (_bot.CurrentHealth <= 0 && _bot.Move != PossibleMoves.SelfDestruct)
            {
                _died = true;
                RunAnimationOnce(Animations.Death);
                _nameTagController.Destroy();
                _healthTagController.Destroy();
                _staminaTagController.Destroy();
                return;
            }

            // If the robot performs a melee attack.
            if (_bot.Move == PossibleMoves.MeleeAttack)
            {
                RunAnimationOnce(Animations.MeleeAttack);
                return;
            }

            // If the robot performs a ranged attack.
            if (_bot.Move == PossibleMoves.RangedAttack)
            {
                if (!_rangeAttackExecuted)
                {
                    _rangeAttackExecuted    = true;
                    _rangedAttackGameObject = Instantiate(RangedAttackPrefab);
                    _rangedAttackGameObject.transform.SetParent(transform);
                    var     rangedAttackController = _rangedAttackGameObject.GetComponent <RangedAttackController>();
                    Vector3 startPos  = _arenaController.ArenaToWorldPosition(_bot.X, _bot.Y);
                    Vector3 targetPos = _arenaController.ArenaToWorldPosition(_bot.LastAttackX, _bot.LastAttackY);
                    rangedAttackController.Fire(startPos, targetPos);
                    RunAnimation(Animations.RangedAttack);
                }
                return;
            }

            // If the robot is self destructing.
            if (_bot.Move == PossibleMoves.SelfDestruct)
            {
                GetComponent <ExplosionController>().Explode();
                RunAnimationOnce(Animations.Death);
                return;
            }

            RunAnimation(Animations.Idle);
        }
Example #6
0
        void Update()
        {
            if (_bot != null)
            {
                if (_bot.LastAction != LastAction.ScriptError)
                {
                    _exclamationMarkVisible = false;
                    if (exclamationMark != null)
                    {
                        Destroy(exclamationMark);
                    }
                }

                if (_bot.PhysicalHealth.Current <= 0 && _bot.LastAction != LastAction.SelfDestruct)
                {
                    GoAnimOnce(DEATH);
                }
                else
                {
                    Vector3 targetDir    = OrientationVector.createFrom(_bot.Orientation);
                    float   rotationStep = rotationSpeed * Time.deltaTime;
                    Vector3 newDir       = Vector3.RotateTowards(transform.forward, targetDir, rotationStep, 0.0F);
                    if (targetDir != newDir)
                    {
                        transform.rotation = Quaternion.LookRotation(newDir);
                    }

                    float   step = speed * Time.deltaTime;
                    Vector3 targetWorldPosition = GridController.Instance.gridToWorldPosition(_bot.Location.X, _bot.Location.Y);
                    Vector3 newPos = Vector3.MoveTowards(transform.position, targetWorldPosition, step);
                    if ((targetDir - newDir).magnitude > 0.01)
                    {
                        GoAnim(TURN_RIGHT);
                    }
                    else if ((newPos - transform.position).magnitude > 0.01)
                    {
                        GoAnim(WALK);
                    }
                    else
                    {
                        switch (_bot.LastAction)
                        {
                        case LastAction.MeleeAttack:
                            GoAnim(MELEE_ATTACK);
                            break;

                        case LastAction.RangedAttack:
                            if (rangeAttack == null && !_rangeAttackFired)
                            {
                                _rangeAttackFired = true;
                                rangeAttack       = Instantiate(rangeAttackPrefab);
                                //rangeAttack.transform.SetParent(this.transform);
                                RangeAttackController rangeAttackController = rangeAttack.GetComponent <RangeAttackController>();
                                Vector3 startPos  = GridController.Instance.gridToWorldPosition(_bot.Location.X, _bot.Location.Y);
                                Vector3 targetPos = GridController.Instance.gridToWorldPosition(_bot.LastAttackLocation.X, _bot.LastAttackLocation.Y);
                                rangeAttackController.fire(startPos, targetPos, 3f);
                                GoAnim(RANGED_ATTACK);
                            }
                            break;

                        case LastAction.SelfDestruct:
                            GetComponent <ExploderController>().Do(x => x.Explode());
                            GoAnimOnce(DEATH);
                            break;

                        case LastAction.ScriptError:
                            if (!_exclamationMarkVisible)
                            {
                                exclamationMark = Instantiate(exclamationMarkPrefab);
                                exclamationMark.transform.SetParent(head);
                                exclamationMark.transform.localPosition = new Vector3(0, 0, 0);
                                exclamationMark.transform.position      = new Vector3(exclamationMark.transform.position.x, 2.5f, exclamationMark.transform.position.z);
                                _exclamationMarkVisible = true;
                            }
                            break;

                        default:
                            GoAnim(IDLE);
                            break;
                        }
                    }
                    transform.position = newPos;

                    Debug.DrawRay(transform.position, newDir, Color.red);
                }
            }
        }
Example #7
0
 public void SwapOrientation(OrientationVector newX, OrientationVector newY, OrientationVector newZ)
 {
     // Swap the orientation of the STL (So that the system is ambiguous of which way is z)
 }
        void Update()
        {
            if (BotIsNotAvailable())
            {
                return;
            }

            if (RobotIsConfused())
            {
                RunAnimationOnce(Animations.Defend);
                if (_errorGameObject == null)
                {
                    _errorGameObject = Instantiate(ErrorPrefab);
                    _errorGameObject.transform.SetParent(Head);
                    _errorGameObject.transform.localPosition = new Vector3(0, 0, 0);
                    _errorGameObject.transform.position      = new Vector3(_errorGameObject.transform.position.x, 2.5f, _errorGameObject.transform.position.z);
                }
                return;
            }

            if (_errorGameObject != null)
            {
                Destroy(_errorGameObject);
                _errorGameObject = null;
            }

            Single  step = Math.Abs(_bot.X - _bot.FromX) > 1 || Math.Abs(_bot.Y - _bot.FromY) > 1 ? 100 : Speed * Time.deltaTime;
            Vector3 targetWorldPosition = _arenaController.ArenaToWorldPosition(_bot.X, _bot.Y);
            Vector3 newPos = Vector3.MoveTowards(transform.position, targetWorldPosition, step);

            if ((newPos - transform.position).magnitude > 0.01)
            {
                RunAnimation(Animations.Walk);
                transform.position = newPos;
                return;
            }

            Vector3 targetOrientation = OrientationVector.CreateFrom(_bot.Orientation);
            Single  rotationStep      = RotationSpeed * Time.deltaTime;
            Vector3 newDir            = Vector3.RotateTowards(transform.forward, targetOrientation, rotationStep, 0.0F);

            if (targetOrientation != newDir)
            {
                transform.rotation = Quaternion.LookRotation(newDir);
            }

            if ((targetOrientation - newDir).magnitude > 0.01)
            {
                RunAnimation(Animations.TurnRight);
                return;
            }

            if (RobotHasDied())
            {
                _died = true;
                RunAnimationOnce(Animations.Death);
                _nameTagController.Destroy();
                _healthTagController.Destroy();
                _staminaTagController.Destroy();
                return;
            }

            if (RobotIsAttackingUsingMelee())
            {
                RunAnimationOnce(Animations.MeleeAttack);
                return;
            }

            if (RobotIsAttackingUsingRanged())
            {
                if (!_rangeAttackExecuted)
                {
                    _rangeAttackExecuted    = true;
                    _rangedAttackGameObject = Instantiate(RangedAttackPrefab);
                    _rangedAttackGameObject.transform.SetParent(transform);
                    var     rangedAttackController = _rangedAttackGameObject.GetComponent <RangedAttackController>();
                    Vector3 startPos  = _arenaController.ArenaToWorldPosition(_bot.X, _bot.Y);
                    Vector3 targetPos = _arenaController.ArenaToWorldPosition(_bot.LastAttackX, _bot.LastAttackY);
                    rangedAttackController.Fire(startPos, targetPos);
                    RunAnimation(Animations.RangedAttack);
                }
                return;
            }

            if (RobotIsSelfDestructing())
            {
                GetComponent <ExplosionController>().Explode();
                RunAnimationOnce(Animations.Death);
                return;
            }

            RunAnimation(Animations.Idle);
        }