protected void UpdateBuilding() { // Current building UI UICurrentBuilding uiCurrentBuilding = CacheUISceneGameplay.uiCurrentBuilding; if (uiCurrentBuilding != null) { if (uiCurrentBuilding.IsVisible() && ActiveBuildingEntity == null) { uiCurrentBuilding.Hide(); } } // Construct building UI UIConstructBuilding uiConstructBuilding = CacheUISceneGameplay.uiConstructBuilding; if (uiConstructBuilding != null) { if (uiConstructBuilding.IsVisible() && CurrentBuildingEntity == null) { uiConstructBuilding.Hide(); } if (!uiConstructBuilding.IsVisible() && CurrentBuildingEntity != null) { uiConstructBuilding.Show(); } } if (CurrentBuildingEntity == null) { return; } bool isPointerOverUI = CacheUISceneGameplay != null && CacheUISceneGameplay.IsPointerOverUIObject(); if (Input.GetMouseButton(0) && !isPointerOverUI) { mouseDownTime = Time.unscaledTime; mouseDownPosition = Input.mousePosition; FindAndSetBuildingAreaFromMousePosition(); } }
protected void UpdateFollowTarget() { // Temp variables if (TryGetAttackingCharacter(out targetEnemy)) { if (targetEnemy.IsDead()) { queueUsingSkill = null; PlayerCharacterEntity.StopMove(); ClearTarget(); return; } // Find attack distance and fov, from weapon or skill float attackDistance = 0f; float attackFov = 0f; if (!GetAttackDataOrUseNonAttackSkill(isLeftHandAttacking, out attackDistance, out attackFov)) { return; } float actDistance = attackDistance; actDistance -= actDistance * 0.1f; actDistance -= StoppingDistance; if (FindTarget(targetEnemy.gameObject, actDistance, gameInstance.characterLayer.Mask)) { // Stop movement to attack PlayerCharacterEntity.StopMove(); // Turn character to target targetLookDirection = (targetEnemy.CacheTransform.position - PlayerCharacterEntity.CacheTransform.position).normalized; if (PlayerCharacterEntity.IsPositionInFov(attackFov, targetEnemy.CacheTransform.position)) { // If has queue using skill, attack by the skill if (queueUsingSkill.HasValue && RequestUsePendingSkill(isLeftHandAttacking, targetEnemy.OpponentAimTransform.position)) { isLeftHandAttacking = !isLeftHandAttacking; } else if (PlayerCharacterEntity.RequestAttack(isLeftHandAttacking, targetEnemy.OpponentAimTransform.position)) { isLeftHandAttacking = !isLeftHandAttacking; } } } else { UpdateTargetEntityPosition(targetEnemy); } } else if (PlayerCharacterEntity.TryGetTargetEntity(out targetPlayer)) { if (targetPlayer.IsDead()) { queueUsingSkill = null; PlayerCharacterEntity.StopMove(); ClearTarget(); return; } float actDistance = gameInstance.conversationDistance - StoppingDistance; if (Vector3.Distance(CharacterTransform.position, targetPlayer.CacheTransform.position) <= actDistance) { PlayerCharacterEntity.StopMove(); // TODO: do something } else { UpdateTargetEntityPosition(targetPlayer); } } else if (PlayerCharacterEntity.TryGetTargetEntity(out targetMonster)) { if (targetMonster.IsDead()) { queueUsingSkill = null; PlayerCharacterEntity.StopMove(); ClearTarget(); return; } float actDistance = gameInstance.conversationDistance - StoppingDistance; if (Vector3.Distance(CharacterTransform.position, targetMonster.CacheTransform.position) <= actDistance) { PlayerCharacterEntity.StopMove(); // TODO: do something } else { UpdateTargetEntityPosition(targetMonster); } } else if (PlayerCharacterEntity.TryGetTargetEntity(out targetNpc)) { float actDistance = gameInstance.conversationDistance - StoppingDistance; if (Vector3.Distance(CharacterTransform.position, targetNpc.CacheTransform.position) <= actDistance) { if (lastNpcObjectId != targetNpc.ObjectId) { PlayerCharacterEntity.RequestNpcActivate(targetNpc.ObjectId); lastNpcObjectId = targetNpc.ObjectId; } PlayerCharacterEntity.StopMove(); } else { UpdateTargetEntityPosition(targetNpc); } } else if (PlayerCharacterEntity.TryGetTargetEntity(out targetItemDrop)) { float actDistance = gameInstance.pickUpItemDistance - StoppingDistance; if (Vector3.Distance(CharacterTransform.position, targetItemDrop.CacheTransform.position) <= actDistance) { PlayerCharacterEntity.RequestPickupItem(targetItemDrop.ObjectId); PlayerCharacterEntity.StopMove(); ClearTarget(); } else { UpdateTargetEntityPosition(targetItemDrop); } } else if (PlayerCharacterEntity.TryGetTargetEntity(out targetBuilding)) { UICurrentBuilding uiCurrentBuilding = null; if (CacheUISceneGameplay != null) { uiCurrentBuilding = CacheUISceneGameplay.uiCurrentBuilding; } float actDistance = gameInstance.conversationDistance - StoppingDistance; if (Vector3.Distance(CharacterTransform.position, targetBuilding.CacheTransform.position) <= actDistance) { PlayerCharacterEntity.StopMove(); if (IsEditingBuilding) { // If it's build mode, show destroy menu if (uiCurrentBuilding != null && !uiCurrentBuilding.IsVisible()) { uiCurrentBuilding.Show(); } } else { // If it's not build mode, try to activate it ActivateBuilding(targetBuilding); ClearTarget(); } } else { UpdateTargetEntityPosition(targetBuilding); if (uiCurrentBuilding != null && uiCurrentBuilding.IsVisible()) { uiCurrentBuilding.Hide(); } } } else if (PlayerCharacterEntity.TryGetTargetEntity(out targetHarvestable)) { if (targetHarvestable.IsDead()) { queueUsingSkill = null; PlayerCharacterEntity.StopMove(); ClearTarget(); return; } float attackDistance = 0f; float attackFov = 0f; if (!GetAttackDataOrUseNonAttackSkill(isLeftHandAttacking, out attackDistance, out attackFov)) { return; } float actDistance = attackDistance; actDistance -= actDistance * 0.1f; actDistance -= StoppingDistance; if (FindTarget(targetHarvestable.gameObject, actDistance, gameInstance.harvestableLayer.Mask)) { // Stop movement to attack PlayerCharacterEntity.StopMove(); // Turn character to target targetLookDirection = (targetHarvestable.CacheTransform.position - PlayerCharacterEntity.CacheTransform.position).normalized; if (PlayerCharacterEntity.IsPositionInFov(attackFov, targetHarvestable.CacheTransform.position)) { if (PlayerCharacterEntity.RequestAttack(isLeftHandAttacking, targetHarvestable.OpponentAimTransform.position)) { isLeftHandAttacking = !isLeftHandAttacking; } } } else { UpdateTargetEntityPosition(targetHarvestable); } } }