コード例 #1
0
 public void TriggerExitEntity(BaseGameEntity networkEntity)
 {
     if (networkEntity != null)
     {
         triggerEntities.Remove(networkEntity);
     }
 }
コード例 #2
0
        /// <summary>
        /// This will be called from `BasePlayerCharacterController` class
        /// To set selected target entity UIs
        /// </summary>
        /// <param name="entity"></param>
        public void SetTargetEntity(BaseGameEntity entity)
        {
            if (entity == null)
            {
                SetTargetCharacter(null);
                SetTargetNpc(null);
                SetTargetItemDrop(null);
                SetTargetBuilding(null);
                SetTargetHarvestable(null);
                return;
            }

            if (entity is BaseCharacterEntity)
            {
                SetTargetCharacter(entity as BaseCharacterEntity);
            }
            if (entity is NpcEntity)
            {
                SetTargetNpc(entity as NpcEntity);
            }
            if (entity is ItemDropEntity)
            {
                SetTargetItemDrop(entity as ItemDropEntity);
            }
            if (entity is BuildingEntity)
            {
                SetTargetBuilding(entity as BuildingEntity);
            }
            if (entity is HarvestableEntity)
            {
                SetTargetHarvestable(entity as HarvestableEntity);
            }
        }
コード例 #3
0
 public void TriggerEnterEntity(BaseGameEntity networkEntity)
 {
     if (networkEntity != null && !triggerEntities.Contains(networkEntity))
     {
         triggerEntities.Add(networkEntity);
     }
 }
コード例 #4
0
        /// <summary>
        /// SetTargetEntity is overriden to show loot item target UI instead of building target UI
        /// when entity is loot bag, and to hide the loot bag items dialog when target entity disappears.
        /// </summary>
        public override void SetTargetEntity(BaseGameEntity entity)
        {
            base.SetTargetEntity(entity);

            if (entity != null && entity is LootBagEntity)
            {
                GameInstance.Singleton.targetLootBagEntity = entity as LootBagEntity;

                if (uiTargetItemDrop == null)
                {
                    return;
                }

                if (uiTargetBuilding != null)
                {
                    uiTargetBuilding.Hide();
                }

                uiTargetItemDrop.Data = entity;
                uiTargetItemDrop.Show();
            }
            else
            {
                GameInstance.Singleton.targetLootBagEntity = null;
            }

            if (uiLootBagItems != null && uiLootBagItems.IsVisible() && !uiTargetItemDrop.IsVisible())
            {
                uiLootBagItems.Hide();
            }
        }
 protected override void SetTarget(BaseGameEntity entity)
 {
     targetPosition = entity.CacheTransform.position;
     targetEntity   = entity;
     PlayerCharacterEntity.SetTargetEntity(entity);
     SelectedEntity = entity;
 }
 protected override void SetTarget(BaseGameEntity entity, TargetActionType targetActionType, bool checkControllerMode = true)
 {
     this.targetActionType = targetActionType;
     destination           = null;
     TargetEntity          = entity;
     PlayerCharacterEntity.SetTargetEntity(entity);
 }
コード例 #7
0
 public override void SetTargetEntity(BaseGameEntity entity)
 {
     if (IsOwnerClient && !IsServer && targetEntity != entity)
     {
         CallNetFunction(NetFuncSetTargetEntity, FunctionReceivers.Server, new PackedUInt(entity == null ? 0 : entity.ObjectId));
     }
     base.SetTargetEntity(entity);
 }
        public void SetSubTarget(BaseGameEntity entity)
        {
            if (entity == null)
            {
                subTargetEntityId.Value = 0;
                return;
            }

            subTargetEntityId.Value = entity.ObjectId;
            subTargetEntityId.UpdateImmediately();
        }
コード例 #9
0
        protected void UpdateTargetEntityPosition(BaseGameEntity entity)
        {
            if (entity == null)
            {
                return;
            }

            var targetPosition = entity.CacheTransform.position;

            PlayerCharacterEntity.PointClickMovement(targetPosition);
        }
コード例 #10
0
        protected void UpdateTargetEntityPosition(BaseGameEntity entity)
        {
            if (entity == null)
            {
                return;
            }
            Vector3 targetPosition = entity.CacheTransform.position;

            PlayerCharacterEntity.PointClickMovement(targetPosition);
            targetLookDirection = (targetPosition - PlayerCharacterEntity.CacheTransform.position).normalized;
        }
        public void SetCastingTarget(BaseGameEntity entity)
        {
            if (entity == null)
            {
                castingTargetEntityId.Value = 0;
                return;
            }

            castingTargetEntityId.Value = entity.ObjectId;
            castingTargetEntityId.UpdateImmediately();
        }
コード例 #12
0
 protected void SetTarget(BaseGameEntity entity)
 {
     targetPosition = null;
     if (pointClickSetTargetImmediately || selectedTarget == entity)
     {
         targetPosition = entity.CacheTransform.position;
         targetEntity   = entity;
         PlayerCharacterEntity.SetTargetEntity(entity);
     }
     selectedTarget = entity;
 }
 private void UseSkillOn(BaseGameEntity target)
 {
     Targeting.CastingTarget = target.gameObject;
     if (Targeting.SelectedTarget == null)
     {
         Targeting.Target(Targeting.CastingTarget);
     }
     Targeting.UnHighlightPotentialTarget();
     TabTargetUpdateTarget();
     TurnCharacterToPosition(target.transform.position);
     RequestUsePendingSkill();
 }
コード例 #14
0
 protected virtual void SetTarget(BaseGameEntity entity)
 {
     targetPosition = null;
     if (pointClickSetTargetImmediately ||
         (entity != null && SelectedEntity == entity) ||
         (entity != null && entity is ItemDropEntity))
     {
         targetPosition = entity.CacheTransform.position;
         targetEntity   = entity;
         PlayerCharacterEntity.SetTargetEntity(entity);
     }
     SelectedEntity = entity;
 }
コード例 #15
0
        protected override void UpdateUI()
        {
            if (!ValidateToUpdateUI())
            {
                CacheCanvas.enabled = false;
                return;
            }

            Profiler.BeginSample("UIBaseGameEntity - Update UI");
            tempOwningCharacter = BasePlayerCharacterController.OwningCharacter;
            if (tempOwningCharacter == Data)
            {
                // Always show the UI when character is owning character
                CacheCanvas.enabled = true;
            }
            else
            {
                switch (visibility)
                {
                case Visibility.VisibleWhenSelected:
                    tempTargetEntity    = BasePlayerCharacterController.Singleton.SelectedEntity;
                    CacheCanvas.enabled = tempTargetEntity != null &&
                                          tempTargetEntity.ObjectId == Data.ObjectId &&
                                          Vector3.Distance(tempOwningCharacter.CacheTransform.position, Data.CacheTransform.position) <= visibleDistance;
                    break;

                case Visibility.VisibleWhenNearby:
                    CacheCanvas.enabled = Vector3.Distance(tempOwningCharacter.CacheTransform.position, Data.CacheTransform.position) <= visibleDistance;
                    break;

                case Visibility.AlwaysVisible:
                    CacheCanvas.enabled = true;
                    break;
                }
            }
            Profiler.EndSample();
        }
コード例 #16
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);
        }
コード例 #17
0
        public static ItemDropEntity DropItem(BaseGameEntity dropper, int itemDataId, short level, short amount, IEnumerable <uint> looters)
        {
            var gameInstance = GameInstance.Singleton;

            if (gameInstance.itemDropEntityPrefab == null)
            {
                return(null);
            }

            var dropPosition = dropper.CacheTransform.position;
            var dropRotation = Quaternion.identity;

            switch (gameInstance.itemDropEntityPrefab.dimensionType)
            {
            case DimensionType.Dimension3D:
                // Random drop position around character
                dropPosition = dropper.CacheTransform.position + new Vector3(Random.Range(-1f, 1f) * gameInstance.dropDistance, 0, Random.Range(-1f, 1f) * gameInstance.dropDistance);
                // Raycast to find hit floor
                Vector3?   aboveHitPoint    = null;
                Vector3?   underHitPoint    = null;
                var        raycastLayerMask = gameInstance.GetItemDropGroundDetectionLayerMask();
                RaycastHit tempHit;
                if (Physics.Raycast(dropPosition, Vector3.up, out tempHit, GROUND_DETECTION_DISTANCE, raycastLayerMask))
                {
                    aboveHitPoint = tempHit.point;
                }
                if (Physics.Raycast(dropPosition, Vector3.down, out tempHit, GROUND_DETECTION_DISTANCE, raycastLayerMask))
                {
                    underHitPoint = tempHit.point;
                }
                // Set drop position to nearest hit point
                if (aboveHitPoint.HasValue && underHitPoint.HasValue)
                {
                    if (Vector3.Distance(dropPosition, aboveHitPoint.Value) < Vector3.Distance(dropPosition, underHitPoint.Value))
                    {
                        dropPosition = aboveHitPoint.Value;
                    }
                    else
                    {
                        dropPosition = underHitPoint.Value;
                    }
                }
                else if (aboveHitPoint.HasValue)
                {
                    dropPosition = aboveHitPoint.Value;
                }
                else if (underHitPoint.HasValue)
                {
                    dropPosition = underHitPoint.Value;
                }
                // Random rotation
                dropRotation = Quaternion.Euler(Vector3.up * Random.Range(0, 360));
                break;

            case DimensionType.Dimension2D:
                dropPosition = dropper.CacheTransform.position + new Vector3(Random.Range(-1f, 1f) * gameInstance.dropDistance, Random.Range(-1f, 1f) * gameInstance.dropDistance);
                break;
            }
            var identity       = dropper.Manager.Assets.NetworkSpawn(gameInstance.itemDropEntityPrefab.Identity, dropPosition, dropRotation);
            var itemDropEntity = identity.GetComponent <ItemDropEntity>();
            var dropData       = CharacterItem.Create(itemDataId, level, amount);

            itemDropEntity.dropData = dropData;
            itemDropEntity.looters  = new HashSet <uint>(looters);
            return(itemDropEntity);
        }
コード例 #18
0
        public static ItemDropEntity DropItem(BaseGameEntity dropper, CharacterItem dropData, IEnumerable <uint> looters)
        {
            GameInstance gameInstance = GameInstance.Singleton;

            if (gameInstance.itemDropEntityPrefab == null)
            {
                return(null);
            }

            Vector3    dropPosition = dropper.CacheTransform.position;
            Quaternion dropRotation = Quaternion.identity;

            if (gameInstance.DimensionType == DimensionType.Dimension2D)
            {
                // If 2d, just random position around character
                dropPosition = dropper.CacheTransform.position + new Vector3(Random.Range(-1f, 1f) * gameInstance.dropDistance, Random.Range(-1f, 1f) * gameInstance.dropDistance);
            }
            else
            {
                // Random drop position around character
                dropPosition = dropper.CacheTransform.position + new Vector3(Random.Range(-1f, 1f) * gameInstance.dropDistance, 0, Random.Range(-1f, 1f) * gameInstance.dropDistance);
                // Raycast to find hit floor
                Vector3?   aboveHitPoint    = null;
                Vector3?   underHitPoint    = null;
                int        raycastLayerMask = gameInstance.GetItemDropGroundDetectionLayerMask();
                RaycastHit tempHit;
                if (Physics.Raycast(dropPosition, Vector3.up, out tempHit, GROUND_DETECTION_DISTANCE, raycastLayerMask))
                {
                    aboveHitPoint = tempHit.point;
                }
                if (Physics.Raycast(dropPosition, Vector3.down, out tempHit, GROUND_DETECTION_DISTANCE, raycastLayerMask))
                {
                    underHitPoint = tempHit.point;
                }
                // Set drop position to nearest hit point
                if (aboveHitPoint.HasValue && underHitPoint.HasValue)
                {
                    if (Vector3.Distance(dropPosition, aboveHitPoint.Value) < Vector3.Distance(dropPosition, underHitPoint.Value))
                    {
                        dropPosition = aboveHitPoint.Value;
                    }
                    else
                    {
                        dropPosition = underHitPoint.Value;
                    }
                }
                else if (aboveHitPoint.HasValue)
                {
                    dropPosition = aboveHitPoint.Value;
                }
                else if (underHitPoint.HasValue)
                {
                    dropPosition = underHitPoint.Value;
                }
                // Random rotation
                dropRotation = Quaternion.Euler(Vector3.up * Random.Range(0, 360));
            }
            GameObject     spawnObj       = Instantiate(gameInstance.itemDropEntityPrefab.gameObject, dropPosition, dropRotation);
            ItemDropEntity itemDropEntity = spawnObj.GetComponent <ItemDropEntity>();

            itemDropEntity.dropData = dropData;
            itemDropEntity.looters  = new HashSet <uint>(looters);
            BaseGameNetworkManager.Singleton.Assets.NetworkSpawn(spawnObj);
            return(itemDropEntity);
        }