コード例 #1
0
        protected virtual void NetFuncNpcActivate(PackedUInt objectId)
        {
            if (!CanDoActions())
            {
                return;
            }

            NpcEntity npcEntity = null;

            if (!TryGetEntityByObjectId(objectId, out npcEntity))
            {
                return;
            }

            if (Vector3.Distance(CacheTransform.position, npcEntity.CacheTransform.position) > gameInstance.conversationDistance + 5f)
            {
                return;
            }

            currentNpcDialog = npcEntity.StartDialog;
            if (currentNpcDialog != null)
            {
                RequestShowNpcDialog(currentNpcDialog.DataId);
            }
        }
コード例 #2
0
 private void Awake()
 {
     if (npcEntity == null)
     {
         npcEntity = GetComponentInParent <NpcEntity>();
     }
 }
コード例 #3
0
        private bool RemoveEntity(GameObject other)
        {
            BasePlayerCharacterEntity  player  = null;
            BaseMonsterCharacterEntity monster = null;
            NpcEntity      npc      = null;
            ItemDropEntity itemDrop = null;
            BuildingEntity building = null;

            FindEntity(other, out player, out monster, out npc, out itemDrop, out building, false);

            if (player != null)
            {
                return(characters.Remove(player) && players.Remove(player));
            }
            if (monster != null)
            {
                return(characters.Remove(monster) && monsters.Remove(monster));
            }
            if (npc != null)
            {
                return(npcs.Remove(npc));
            }
            if (itemDrop != null)
            {
                return(itemDrops.Remove(itemDrop));
            }
            if (building != null)
            {
                return(buildings.Remove(building));
            }
            return(false);
        }
コード例 #4
0
        private bool AddEntity(GameObject other)
        {
            BasePlayerCharacterEntity  player  = null;
            BaseMonsterCharacterEntity monster = null;
            NpcEntity      npc      = null;
            ItemDropEntity itemDrop = null;
            BuildingEntity building = null;

            FindEntity(other, out player, out monster, out npc, out itemDrop, out building);

            if (player != null)
            {
                if (!characters.Contains(player))
                {
                    characters.Add(player);
                }
                if (!players.Contains(player))
                {
                    players.Add(player);
                }
                return(true);
            }
            if (monster != null)
            {
                if (!characters.Contains(monster))
                {
                    characters.Add(monster);
                }
                if (!monsters.Contains(monster))
                {
                    monsters.Add(monster);
                }
                return(true);
            }
            if (npc != null)
            {
                if (!npcs.Contains(npc))
                {
                    npcs.Add(npc);
                }
                return(true);
            }
            if (building != null)
            {
                if (!buildings.Contains(building))
                {
                    buildings.Add(building);
                }
                return(true);
            }
            if (itemDrop != null)
            {
                if (!itemDrops.Contains(itemDrop))
                {
                    itemDrops.Add(itemDrop);
                }
                return(true);
            }
            return(false);
        }
コード例 #5
0
 public override void OnServerOnlineSceneLoaded()
 {
     base.OnServerOnlineSceneLoaded();
     this.InvokeInstanceDevExtMethods("OnServerOnlineSceneLoaded");
     RegisterEntities();
     // Spawn monsters
     MonsterSpawnArea[] monsterSpawnAreas = FindObjectsOfType <MonsterSpawnArea>();
     foreach (MonsterSpawnArea monsterSpawnArea in monsterSpawnAreas)
     {
         monsterSpawnArea.SpawnAll();
     }
     // Spawn Warp Portals
     if (GameInstance.MapWarpPortals.Count > 0)
     {
         List <WarpPortal> mapWarpPortals;
         if (GameInstance.MapWarpPortals.TryGetValue(CurrentMapInfo.Id, out mapWarpPortals))
         {
             foreach (WarpPortal warpPortal in mapWarpPortals)
             {
                 WarpPortalEntity warpPortalPrefab = warpPortal.entityPrefab != null ? warpPortal.entityPrefab : gameInstance.warpPortalEntityPrefab;
                 if (warpPortalPrefab != null)
                 {
                     GameObject       spawnObj         = Instantiate(warpPortalPrefab.gameObject, warpPortal.position, Quaternion.identity);
                     WarpPortalEntity warpPortalEntity = spawnObj.GetComponent <WarpPortalEntity>();
                     warpPortalEntity.type     = warpPortal.warpPortalType;
                     warpPortalEntity.mapInfo  = warpPortal.warpToMapInfo;
                     warpPortalEntity.position = warpPortal.warpToPosition;
                     Assets.NetworkSpawn(spawnObj);
                 }
             }
         }
     }
     // Spawn Npcs
     if (GameInstance.MapNpcs.Count > 0)
     {
         List <Npc> mapNpcs;
         if (GameInstance.MapNpcs.TryGetValue(CurrentMapInfo.Id, out mapNpcs))
         {
             foreach (Npc npc in mapNpcs)
             {
                 NpcEntity npcPrefab = npc.entityPrefab;
                 if (npcPrefab != null)
                 {
                     GameObject spawnObj  = Instantiate(npcPrefab.gameObject, npc.position, Quaternion.Euler(npc.rotation));
                     NpcEntity  npcEntity = spawnObj.GetComponent <NpcEntity>();
                     npcEntity.StartDialog = npc.startDialog;
                     npcEntity.Title       = npc.title;
                     Assets.NetworkSpawn(spawnObj);
                 }
             }
         }
     }
     // If it's server (not host) spawn simple camera controller
     if (!IsClient && GameInstance.Singleton.serverCharacterPrefab != null)
     {
         Instantiate(GameInstance.Singleton.serverCharacterPrefab);
     }
 }
コード例 #6
0
        protected void SetTargetNpc(NpcEntity npc)
        {
            if (uiTargetNpc == null)
            {
                return;
            }

            if (npc == null)
            {
                uiTargetNpc.Hide();
                return;
            }

            uiTargetNpc.Data = npc;
            uiTargetNpc.Show();
        }
コード例 #7
0
        protected void UpdateInput()
        {
            if (GenericUtils.IsFocusInputField())
            {
                return;
            }

            if (PlayerCharacterEntity.IsDead())
            {
                return;
            }

            // If it's building something, don't allow to activate NPC/Warp/Pickup Item
            if (!ConstructingBuildingEntity)
            {
                // Activate nearby npcs / players / activable buildings
                if (InputManager.GetButtonDown("Activate"))
                {
                    targetPlayer = null;
                    if (ActivatableEntityDetector.players.Count > 0)
                    {
                        targetPlayer = ActivatableEntityDetector.players[0];
                    }
                    targetNpc = null;
                    if (ActivatableEntityDetector.npcs.Count > 0)
                    {
                        targetNpc = ActivatableEntityDetector.npcs[0];
                    }
                    targetBuilding = null;
                    if (ActivatableEntityDetector.buildings.Count > 0)
                    {
                        targetBuilding = ActivatableEntityDetector.buildings[0];
                    }
                    targetVehicle = null;
                    if (ActivatableEntityDetector.vehicles.Count > 0)
                    {
                        targetVehicle = ActivatableEntityDetector.vehicles[0];
                    }
                    // Priority Player -> Npc -> Buildings
                    if (targetPlayer && CacheUISceneGameplay)
                    {
                        // Show dealing, invitation menu
                        SelectedEntity = targetPlayer;
                        CacheUISceneGameplay.SetActivePlayerCharacter(targetPlayer);
                    }
                    else if (targetNpc)
                    {
                        // Talk to NPC
                        SelectedEntity = targetNpc;
                        PlayerCharacterEntity.RequestNpcActivate(targetNpc.ObjectId);
                    }
                    else if (targetBuilding)
                    {
                        // Use building
                        SelectedEntity = targetBuilding;
                        ActivateBuilding(targetBuilding);
                    }
                    else if (targetVehicle)
                    {
                        // Enter vehicle
                        PlayerCharacterEntity.RequestEnterVehicle(targetVehicle.ObjectId);
                    }
                    else
                    {
                        // Enter warp, For some warp portals that `warpImmediatelyWhenEnter` is FALSE
                        PlayerCharacterEntity.RequestEnterWarp();
                    }
                }
                // Pick up nearby items
                if (InputManager.GetButtonDown("PickUpItem"))
                {
                    targetItemDrop = null;
                    if (ItemDropEntityDetector.itemDrops.Count > 0)
                    {
                        targetItemDrop = ItemDropEntityDetector.itemDrops[0];
                    }
                    if (targetItemDrop != null)
                    {
                        PlayerCharacterEntity.RequestPickupItem(targetItemDrop.ObjectId);
                    }
                }
                // Reload
                if (InputManager.GetButtonDown("Reload"))
                {
                    // Reload ammo when press the button
                    ReloadAmmo();
                }
                if (InputManager.GetButtonDown("ExitVehicle"))
                {
                    // Exit vehicle
                    PlayerCharacterEntity.RequestExitVehicle();
                }
                if (InputManager.GetButtonDown("SwitchEquipWeaponSet"))
                {
                    // Switch equip weapon set
                    PlayerCharacterEntity.RequestSwitchEquipWeaponSet((byte)(PlayerCharacterEntity.EquipWeaponSet + 1));
                }
                if (InputManager.GetButtonDown("Sprint"))
                {
                    // Toggles sprint state
                    isSprinting = !isSprinting;
                }
                // Auto reload
                if (PlayerCharacterEntity.EquipWeapons.rightHand.IsAmmoEmpty() ||
                    PlayerCharacterEntity.EquipWeapons.leftHand.IsAmmoEmpty())
                {
                    // Reload ammo when empty and not press any keys
                    ReloadAmmo();
                }
            }
            // Update inputs
            UpdateLookInput();
            UpdateWASDInput();
            // Set sprinting state
            PlayerCharacterEntity.SetExtraMovement(isSprinting ? ExtraMovementState.IsSprinting : ExtraMovementState.None);
        }
コード例 #8
0
        protected override void Update()
        {
            if (PlayerCharacterEntity == null || !PlayerCharacterEntity.IsOwnerClient)
            {
                return;
            }

            base.Update();
            UpdateLookAtTarget();
            tempDeltaTime    = Time.deltaTime;
            turnTimeCounter += tempDeltaTime;

            // Hide construction UI
            if (CurrentBuildingEntity == null)
            {
                if (CacheUISceneGameplay.uiConstructBuilding.IsVisible())
                {
                    CacheUISceneGameplay.uiConstructBuilding.Hide();
                }
            }
            if (ActiveBuildingEntity == null)
            {
                if (CacheUISceneGameplay.uiCurrentBuilding.IsVisible())
                {
                    CacheUISceneGameplay.uiCurrentBuilding.Hide();
                }
            }

            IsBlockController = CacheUISceneGameplay.IsBlockController();
            // Lock cursor when not show UIs
            Cursor.lockState = !IsBlockController ? CursorLockMode.Locked : CursorLockMode.None;
            Cursor.visible   = IsBlockController;

            CacheGameplayCameraControls.updateRotation = !IsBlockController;
            // Clear selected entity
            SelectedEntity = null;

            // Update crosshair (with states from last update)
            if (isDoingAction)
            {
                UpdateCrosshair(currentCrosshairSetting, currentCrosshairSetting.expandPerFrameWhileAttacking);
            }
            else if (movementState.HasFlag(MovementState.Forward) ||
                     movementState.HasFlag(MovementState.Backward) ||
                     movementState.HasFlag(MovementState.Left) ||
                     movementState.HasFlag(MovementState.Right) ||
                     movementState.HasFlag(MovementState.IsJump))
            {
                UpdateCrosshair(currentCrosshairSetting, currentCrosshairSetting.expandPerFrameWhileMoving);
            }
            else
            {
                UpdateCrosshair(currentCrosshairSetting, -currentCrosshairSetting.shrinkPerFrame);
            }

            // Clear controlling states from last update
            isDoingAction = false;
            movementState = MovementState.None;
            UpdateActivatedWeaponAbility(tempDeltaTime);

            if (IsBlockController || GenericUtils.IsFocusInputField())
            {
                mustReleaseFireKey = false;
                PlayerCharacterEntity.KeyMovement(Vector3.zero, MovementState.None);
                DeactivateWeaponAbility();
                return;
            }

            // Find target character
            Ray     ray                = CacheGameplayCameraControls.CacheCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
            Vector3 forward            = CacheGameplayCameraControls.CacheCameraTransform.forward;
            Vector3 right              = CacheGameplayCameraControls.CacheCameraTransform.right;
            float   distanceFromOrigin = Vector3.Distance(ray.origin, PlayerCharacterEntity.CacheTransform.position);
            float   aimDistance        = distanceFromOrigin;

            // Calculating aim distance, also read attack inputs here
            // Attack inputs will be used to calculate attack distance
            if (CurrentBuildingEntity == null)
            {
                // Attack with right hand weapon
                tempPressAttackRight = InputManager.GetButton("Fire1");
                if (weaponAbility == null && leftHandWeapon != null)
                {
                    // Attack with left hand weapon if left hand weapon not empty
                    tempPressAttackLeft = InputManager.GetButton("Fire2");
                }
                else if (weaponAbility != null)
                {
                    // Use weapon ability if it can
                    tempPressWeaponAbility = InputManager.GetButtonDown("Fire2");
                }
                // Is left hand attack when not attacking with right hand
                // So priority is right > left
                isLeftHandAttacking = !tempPressAttackRight && tempPressAttackLeft;

                // Calculate aim distance by skill or weapon
                if (queueSkill != null && queueSkill.IsAttack())
                {
                    // Increase aim distance by skill attack distance
                    aimDistance += PlayerCharacterEntity.GetSkillAttackDistance(queueSkill, isLeftHandAttacking);
                }
                else
                {
                    // Increase aim distance by attack distance
                    aimDistance += PlayerCharacterEntity.GetAttackDistance(isLeftHandAttacking);
                }
            }
            actionLookDirection   = aimPosition = ray.origin + ray.direction * aimDistance;
            actionLookDirection.y = PlayerCharacterEntity.CacheTransform.position.y;
            actionLookDirection   = actionLookDirection - PlayerCharacterEntity.CacheTransform.position;
            actionLookDirection.Normalize();
            // Prepare variables to find nearest raycasted hit point
            float tempDistance;
            float tempNearestDistance = float.MaxValue;

            // Find for enemy character
            if (CurrentBuildingEntity == null)
            {
                int tempCount = Physics.RaycastNonAlloc(ray, raycasts, aimDistance);
                for (int tempCounter = 0; tempCounter < tempCount; ++tempCounter)
                {
                    tempHitInfo = raycasts[tempCounter];

                    tempEntity = tempHitInfo.collider.GetComponent <BaseGameEntity>();
                    // Find building entity from building material
                    if (tempEntity == null)
                    {
                        tempBuildingMaterial = tempHitInfo.collider.GetComponent <BuildingMaterial>();
                        if (tempBuildingMaterial != null)
                        {
                            tempEntity = tempBuildingMaterial.buildingEntity;
                        }
                    }
                    if (tempEntity == null || tempEntity == PlayerCharacterEntity)
                    {
                        continue;
                    }
                    // Target must be alive
                    if (tempEntity is IDamageableEntity && (tempEntity as IDamageableEntity).IsDead())
                    {
                        continue;
                    }
                    // Target must be in front of player character
                    if (!PlayerCharacterEntity.IsPositionInFov(15f, tempEntity.CacheTransform.position, forward))
                    {
                        continue;
                    }
                    // Set aim position and found target
                    tempDistance = Vector3.Distance(CacheGameplayCameraControls.CacheCameraTransform.position, tempHitInfo.point);
                    if (tempDistance < tempNearestDistance)
                    {
                        tempNearestDistance = tempDistance;
                        aimPosition         = tempHitInfo.point;
                        if (tempEntity != null)
                        {
                            SelectedEntity = tempEntity;
                        }
                    }
                }
                // Show target hp/mp
                CacheUISceneGameplay.SetTargetEntity(SelectedEntity);
            }
            else
            {
                // Clear area before next find
                CurrentBuildingEntity.buildingArea = null;
                // Find for position to construction building
                bool         foundSnapBuildPosition = false;
                int          tempCount    = Physics.RaycastNonAlloc(ray, raycasts, gameInstance.buildDistance);
                BuildingArea buildingArea = null;
                for (int tempCounter = 0; tempCounter < tempCount; ++tempCounter)
                {
                    tempHitInfo = raycasts[tempCounter];
                    tempEntity  = tempHitInfo.collider.GetComponentInParent <BuildingEntity>();
                    if (tempEntity == null || tempEntity == CurrentBuildingEntity)
                    {
                        continue;
                    }

                    buildingArea = tempHitInfo.transform.GetComponent <BuildingArea>();
                    if (buildingArea == null ||
                        (buildingArea.buildingEntity != null && buildingArea.buildingEntity == CurrentBuildingEntity) ||
                        !CurrentBuildingEntity.buildingType.Equals(buildingArea.buildingType))
                    {
                        continue;
                    }

                    // Set aim position
                    tempDistance = Vector3.Distance(CacheGameplayCameraControls.CacheCameraTransform.position, tempHitInfo.point);
                    if (tempDistance < tempNearestDistance)
                    {
                        aimPosition = tempHitInfo.point;
                        CurrentBuildingEntity.buildingArea = buildingArea;
                        if (buildingArea.snapBuildingObject)
                        {
                            foundSnapBuildPosition = true;
                            break;
                        }
                    }
                }
                // Update building position
                if (!foundSnapBuildPosition)
                {
                    CurrentBuildingEntity.CacheTransform.position = aimPosition;
                    // Rotate to camera
                    Vector3 direction = (aimPosition - CacheGameplayCameraControls.CacheCameraTransform.position).normalized;
                    direction.y = 0;
                    CurrentBuildingEntity.transform.rotation = Quaternion.LookRotation(direction);
                }
            }

            // If mobile platforms, don't receive input raw to make it smooth
            bool    raw           = !InputManager.useMobileInputOnNonMobile && !Application.isMobilePlatform;
            Vector3 moveDirection = Vector3.zero;

            forward.y = 0f;
            right.y   = 0f;
            forward.Normalize();
            right.Normalize();
            float inputV = InputManager.GetAxis("Vertical", raw);
            float inputH = InputManager.GetAxis("Horizontal", raw);

            moveDirection += forward * inputV;
            moveDirection += right * inputH;
            // Set movement state by inputs
            switch (mode)
            {
            case Mode.Adventure:
                if (inputV > 0.5f || inputV < -0.5f || inputH > 0.5f || inputH < -0.5f)
                {
                    movementState = MovementState.Forward;
                }
                moveLookDirection = moveDirection;
                break;

            case Mode.Combat:
                moveDirection += forward * inputV;
                moveDirection += right * inputH;
                if (inputV > 0.5f)
                {
                    movementState |= MovementState.Forward;
                }
                else if (inputV < -0.5f)
                {
                    movementState |= MovementState.Backward;
                }
                if (inputH > 0.5f)
                {
                    movementState |= MovementState.Right;
                }
                else if (inputH < -0.5f)
                {
                    movementState |= MovementState.Left;
                }
                moveLookDirection = actionLookDirection;
                break;
            }

            // normalize input if it exceeds 1 in combined length:
            if (moveDirection.sqrMagnitude > 1)
            {
                moveDirection.Normalize();
            }

            if (CurrentBuildingEntity != null)
            {
                mustReleaseFireKey = false;
                // Building
                tempPressAttackRight = InputManager.GetButtonUp("Fire1");
                if (tempPressAttackRight)
                {
                    if (showConfirmConstructionUI)
                    {
                        // Show confirm UI
                        if (!CacheUISceneGameplay.uiConstructBuilding.IsVisible())
                        {
                            CacheUISceneGameplay.uiConstructBuilding.Show();
                        }
                    }
                    else
                    {
                        // Build when click
                        ConfirmBuild();
                    }
                }
                else
                {
                    // Update move direction
                    if (moveDirection.magnitude != 0f)
                    {
                        targetLookDirection = moveLookDirection;
                    }
                }
            }
            else
            {
                // Have to release fire key, then check press fire key later on next frame
                if (mustReleaseFireKey)
                {
                    tempPressAttackRight = false;
                    tempPressAttackLeft  = false;
                    if (!isLeftHandAttacking &&
                        (InputManager.GetButtonUp("Fire1") ||
                         !InputManager.GetButton("Fire1")))
                    {
                        mustReleaseFireKey = false;
                    }
                    if (isLeftHandAttacking &&
                        (InputManager.GetButtonUp("Fire2") ||
                         !InputManager.GetButton("Fire2")))
                    {
                        mustReleaseFireKey = false;
                    }
                }
                // Not building so it is attacking
                tempPressActivate   = InputManager.GetButtonDown("Activate");
                tempPressPickupItem = InputManager.GetButtonDown("PickUpItem");
                tempPressReload     = InputManager.GetButtonDown("Reload");
                if (queueSkill != null || tempPressAttackRight || tempPressAttackLeft || tempPressActivate || PlayerCharacterEntity.IsPlayingActionAnimation())
                {
                    // Find forward character / npc / building / warp entity from camera center
                    targetPlayer   = null;
                    targetNpc      = null;
                    targetBuilding = null;
                    if (tempPressActivate && !tempPressAttackRight && !tempPressAttackLeft)
                    {
                        if (SelectedEntity is BasePlayerCharacterEntity)
                        {
                            targetPlayer = SelectedEntity as BasePlayerCharacterEntity;
                        }
                        if (SelectedEntity is NpcEntity)
                        {
                            targetNpc = SelectedEntity as NpcEntity;
                        }
                        if (SelectedEntity is BuildingEntity)
                        {
                            targetBuilding = SelectedEntity as BuildingEntity;
                        }
                    }
                    // While attacking turn to camera forward
                    tempCalculateAngle = Vector3.Angle(PlayerCharacterEntity.CacheTransform.forward, actionLookDirection);
                    if (tempCalculateAngle > 15f)
                    {
                        if (queueSkill != null && queueSkill.IsAttack())
                        {
                            turningState = TurningState.UseSkill;
                        }
                        else if (tempPressAttackRight || tempPressAttackLeft)
                        {
                            turningState = TurningState.Attack;
                        }
                        else if (tempPressActivate)
                        {
                            turningState = TurningState.Activate;
                        }
                        turnTimeCounter     = ((180f - tempCalculateAngle) / 180f) * turnToTargetDuration;
                        targetLookDirection = actionLookDirection;
                        // Set movement state by inputs
                        if (inputV > 0.5f)
                        {
                            movementState |= MovementState.Forward;
                        }
                        else if (inputV < -0.5f)
                        {
                            movementState |= MovementState.Backward;
                        }
                        if (inputH > 0.5f)
                        {
                            movementState |= MovementState.Right;
                        }
                        else if (inputH < -0.5f)
                        {
                            movementState |= MovementState.Left;
                        }
                    }
                    else
                    {
                        // Attack immediately if character already look at target
                        if (queueSkill != null && queueSkill.IsAttack())
                        {
                            UseSkill(isLeftHandAttacking, aimPosition);
                            isDoingAction = true;
                        }
                        else if (tempPressAttackRight || tempPressAttackLeft)
                        {
                            Attack(isLeftHandAttacking);
                            isDoingAction = true;
                        }
                        else if (tempPressActivate)
                        {
                            Activate();
                        }
                    }
                    // If skill is not attack skill, use it immediately
                    if (queueSkill != null && !queueSkill.IsAttack())
                    {
                        UseSkill(false);
                    }
                    queueSkill = null;
                }
                else if (tempPressWeaponAbility)
                {
                    switch (weaponAbilityState)
                    {
                    case WeaponAbilityState.Activated:
                    case WeaponAbilityState.Activating:
                        DeactivateWeaponAbility();
                        break;

                    case WeaponAbilityState.Deactivated:
                    case WeaponAbilityState.Deactivating:
                        ActivateWeaponAbility();
                        break;
                    }
                }
                else if (tempPressPickupItem)
                {
                    // Find for item to pick up
                    if (SelectedEntity != null)
                    {
                        PlayerCharacterEntity.RequestPickupItem((SelectedEntity as ItemDropEntity).ObjectId);
                    }
                }
                else if (tempPressReload)
                {
                    // Reload ammo when press the button
                    ReloadAmmo();
                }
                else
                {
                    // Update move direction
                    if (moveDirection.magnitude != 0f)
                    {
                        targetLookDirection = moveLookDirection;
                    }
                }
                // Setup releasing state
                if (tempPressAttackRight && rightHandWeapon != null && rightHandWeapon.fireType == FireType.SingleFire)
                {
                    // The weapon's fire mode is single fire, so player have to release fire key for next fire
                    mustReleaseFireKey = true;
                }
                else if (tempPressAttackLeft && leftHandWeapon != null && leftHandWeapon.fireType == FireType.SingleFire)
                {
                    // The weapon's fire mode is single fire, so player have to release fire key for next fire
                    mustReleaseFireKey = true;
                }
                // Auto reload
                if (!tempPressAttackRight && !tempPressAttackLeft && !tempPressReload &&
                    (PlayerCharacterEntity.EquipWeapons.rightHand.IsAmmoEmpty() ||
                     PlayerCharacterEntity.EquipWeapons.leftHand.IsAmmoEmpty()))
                {
                    // Reload ammo when empty and not press any keys
                    ReloadAmmo();
                }
            }
            SetAimPosition(aimPosition);

            // Hide Npc UIs when move
            if (moveDirection.magnitude != 0f)
            {
                HideNpcDialogs();
                PlayerCharacterEntity.StopMove();
                PlayerCharacterEntity.SetTargetEntity(null);
            }
            // If jumping add jump state
            if (InputManager.GetButtonDown("Jump"))
            {
                movementState |= MovementState.IsJump;
            }

            PlayerCharacterEntity.KeyMovement(moveDirection, movementState);
        }
コード例 #9
0
        private void FindEntity(GameObject other,
                                out BasePlayerCharacterEntity player,
                                out BaseMonsterCharacterEntity monster,
                                out NpcEntity npc,
                                out ItemDropEntity itemDrop,
                                out BuildingEntity building,
                                bool findWithAdvanceOptions = true)
        {
            player = null;
            if (findPlayer)
            {
                player = other.GetComponent <BasePlayerCharacterEntity>();
                if (player == BasePlayerCharacterController.OwningCharacter)
                {
                    player = null;
                }
                if (findWithAdvanceOptions)
                {
                    if (findOnlyAlivePlayers && player != null && player.IsDead())
                    {
                        player = null;
                    }
                    if (findPlayerToAttack && player != null && player.IsAlly(BasePlayerCharacterController.OwningCharacter))
                    {
                        player = null;
                    }
                }
            }

            monster = null;
            if (findMonster)
            {
                monster = other.GetComponent <BaseMonsterCharacterEntity>();
                if (findWithAdvanceOptions)
                {
                    if (findOnlyAliveMonsters && monster != null && monster.IsDead())
                    {
                        monster = null;
                    }
                    if (findMonsterToAttack && monster != null && monster.IsAlly(BasePlayerCharacterController.OwningCharacter))
                    {
                        monster = null;
                    }
                }
            }

            npc = null;
            if (findNpc)
            {
                npc = other.GetComponent <NpcEntity>();
            }

            itemDrop = null;
            if (findItemDrop)
            {
                itemDrop = other.GetComponent <ItemDropEntity>();
            }

            building = null;
            if (findBuilding)
            {
                BuildingMaterial buildingMaterial = other.GetComponent <BuildingMaterial>();
                if (buildingMaterial != null)
                {
                    building = buildingMaterial.buildingEntity;
                }
                if (findWithAdvanceOptions)
                {
                    if (findOnlyAliveBuildings && building != null && building.IsDead())
                    {
                        building = null;
                    }
                    if (findOnlyActivatableBuildings && building != null && !building.Activatable)
                    {
                        building = null;
                    }
                }
            }
        }