Example #1
0
        // start the walk
        private void StartWalk(Vector3 dir)
        {
            CharacterTargetingComponent character = player.GetComponent <CharacterTargetingComponent>();

            if (null != character)
            {
                const float MoveOffset = 2f;
                character.SetMovementTarget(player.transform.position + dir * MoveOffset);
            }
        }
Example #2
0
    void Awake()
    {
        if (_stateHandlers == null)
        {
            _stateHandlers = new Dictionary <eCampaignCharacterState, System.Type>();

            //ToDo:���÷��䵼��������ù�ϵ���ײ鿴
            //Assembly assembly = Assembly.GetAssembly(typeof(CharacterStateHandler));
            //foreach (System.Type t in assembly.GetTypes())
            //{
            //	if (!t.IsAbstract && t.IsSubclassOf(typeof(CharacterStateHandler)))
            //	{
            //		CharacterStateHandlerAttribute attr = (CharacterStateHandlerAttribute)t.GetCustomAttributes(typeof(CharacterStateHandlerAttribute), false)[0];
            //		_stateHandlers.Add(attr.handledState, t);
            //	}
            //}

            var type = typeof(AttackTargetStateHandler);
            _stateHandlers.Add(((CharacterStateHandlerAttribute)type.GetCustomAttributes(typeof(CharacterStateHandlerAttribute), false)[0]).handledState, type);
            type = typeof(ChaseTargetStateHandler);
            _stateHandlers.Add(((CharacterStateHandlerAttribute)type.GetCustomAttributes(typeof(CharacterStateHandlerAttribute), false)[0]).handledState, type);
            type = typeof(IdleStateHandler);
            _stateHandlers.Add(((CharacterStateHandlerAttribute)type.GetCustomAttributes(typeof(CharacterStateHandlerAttribute), false)[0]).handledState, type);
            type = typeof(InteractStateHandler);
            _stateHandlers.Add(((CharacterStateHandlerAttribute)type.GetCustomAttributes(typeof(CharacterStateHandlerAttribute), false)[0]).handledState, type);
            type = typeof(MoveStateHandler);
            _stateHandlers.Add(((CharacterStateHandlerAttribute)type.GetCustomAttributes(typeof(CharacterStateHandlerAttribute), false)[0]).handledState, type);
        }

        _animator = GetComponentInChildren <Animator>();

        _controller = GetComponent <Controller>();
        if (_controller is EnemyController)
        {
            ((EnemyController)_controller).onDestroy += OnEnemyKilled;
        }

        _combatController = GetComponent <CombatController>();
        _viewRPC          = FindReplicationViewForComponent <CharacterComponent>();

        //_effectReceiver = new EffectReceiver(gameObject);

        _conditionComponent = GetComponent <ConditionComponent>();
        _targetingComponent = GetComponent <CharacterTargetingComponent>();
        //_animationController = GetComponent<AnimationController>();

        _moveController = GetComponent <CampaignMoveController>();

        _locomotionComponent = (ILocomotionComponent)GetComponent(typeof(ILocomotionComponent));
        if (_locomotionComponent != null)
        {
            _locomotionComponent.Initialize();
        }
        //_network = GetComponent<NetworkOwnershipComponent>();
    }
Example #3
0
    // see which player is best suited to own this enemy
    private static PlayerController CalculateBestOwner(EnemyController enemy, NetworkOwnershipComponent netOwner)
    {
        CharacterTargetingComponent enemyTargeting = enemy.gameObject.GetComponent <CharacterTargetingComponent>();

        PlayerController closestPlayer          = null;
        float            distToClosestPlayerSqr = float.MaxValue;

        for (int controller = 0; controller < PlayerManager.sPlayerControllers.Count; ++controller)
        {
            PlayerController pc = PlayerManager.sPlayerControllers[controller];
            if (pc.gameObject.GetComponent <CharacterTargetingComponent>().AttackTarget == enemy.gameObject)            // if this enemy is this player's attack target, then we should be owned by this player
            {
                return(pc);
            }

            float distToPlayerSqr = GameUtils.GetDistSqXZ(pc.transform.position, enemy.transform.position);
            if (distToPlayerSqr < distToClosestPlayerSqr)
            {
                distToClosestPlayerSqr = distToPlayerSqr;
                closestPlayer          = pc;
            }
        }

        if (null != enemyTargeting.AttackTarget && PlayerManager.IsPlayer(enemyTargeting.AttackTarget))
        {
            return(enemyTargeting.AttackTarget.GetComponent <PlayerController>());           // if this player is this enemies attack target, then we should be owned by this player
        }

        if (!netOwner.IsOwner(closestPlayer.ReplicationPlayer))         // if the closest player is not our current owner, we may want to change owners
        {
            EB.Sparx.Player sparxPlayer = netOwner.GetOwner();
            if (sparxPlayer == null)
            {
                return(closestPlayer);
            }

            PlayerController currentOwner            = PlayerManager.GetPlayerController(sparxPlayer);
            float            distFromCurrentOwnerSqr = GameUtils.GetDistSqXZ(currentOwner.transform.position, enemy.transform.position);

            // these distances are arbitrary, but are designed so that dithering between different owners should not occur
            const float RequiredDistFromCurrentOwnerSqr = 12f * 12f;
            const float RequiredDistToNewOwnerSqr       = 5f * 5f;

            if (distFromCurrentOwnerSqr > RequiredDistFromCurrentOwnerSqr &&        // if we are far enough away from our current owner
                distToClosestPlayerSqr < RequiredDistToNewOwnerSqr)                 // we are close enough to our potential new owner
            {
                return(closestPlayer);
            }
        }
        return(null);
    }
Example #4
0
    public static void LocalPlayerDisableNavigation()
    {
        PlayerController controller = PlayerManager.LocalPlayerController();

        if (null != controller)
        {
            CharacterTargetingComponent characterTargetingComp = controller.gameObject.GetComponent <CharacterTargetingComponent>();
            if (null != characterTargetingComp)
            {
                characterTargetingComp.SetMovementTarget(Vector3.zero, true);
            }

            SelectionLogic selection = controller.GetComponent <SelectionLogic>();
            if (null != selection)
            {
                selection.DisablePlayerSelectionControls();
            }
        }
    }
Example #5
0
    private GameObject GetCurrentTarget()
    {
        CharacterTargetingComponent targeting = GetComponent <CharacterTargetingComponent>();

        return(targeting == null ? null : targeting.AttackTarget);
    }
Example #6
0
 public void Start(PlayerController controller)
 {
     _playerController = controller;
     _targeting        = controller.GetComponent <CharacterTargetingComponent>();
     BeginCharging();
 }
Example #7
0
 protected void Awake()
 {
     _characterComponent = GetComponent <CharacterComponent>();
     _viewRPC            = FindReplicationViewForComponent <Controller>();
     _targetingComponent = GetComponent <CharacterTargetingComponent>();
 }