public override void Tick(float deltaTime) { for (int i = 0; i < filters.Length; i++) { // cache variables Filter filter = filters[i]; InventoryComponent inventoryComp = filter.inventoryComponent; InputComponent inputComp = filter.inputComponent; InteractorComponent interactComp = filter.interactorComponent; // ----- logic ----- if (inputComp.GetKeyDown(KeyCode.E) || inputComp.GetButtonDown("Fire1")) { isGathering = true; } else if (inputComp.GetKeyUp(KeyCode.E) || inputComp.GetButtonUp("Fire1") || isGathering == false) { //stop gather interactedTime = 0f; isGathering = false; player.uiComponent.gatheringPrompt.ProgressFill(0); } if (isGathering) { AttemptWorldInteract(interactComp, player.inventoryComponent, inputComp.worldInteractMask); interactComp.SetInteractMode(InteractMode.Object); } } }
private void AttemptWorldInteract(InteractorComponent interactorComp, InventoryComponent inventoryComp, LayerMask mask) { Transform t = interactorComp.GetOwnerGO().transform; Vector3 position = t.position + t.forward; RaycastHit[] hits; hits = Physics.BoxCastAll(position, Vector3.one, t.forward, Quaternion.identity, 1f, mask); for (int i = 0; i < hits.Length; i++) { CartComponent tc = hits[i].transform.GetComponentInParent <CartComponent>(); if (tc) { interactorComp.currentInteractable = tc; tc.isTraveling = false; interactorComp.SetInteractMode(InteractMode.Object); } // BaseResource treeComp = hits[i].transform.gameObject.GetComponentInParent<CollectibleComponent>().baseCollectible; // if (treeComp != null) // { // GatherResource(treeComp, inventoryComp); // } } }
public override void Initialize(Transform[] objects) { // list because I don't know size here List <Filter> tmpFilters = new List <Filter>(); int index = 0; for (int i = 0; i < objects.Length; i++) { // check performance InventoryComponent invC = objects[i].GetComponent <InventoryComponent>(); InputComponent inpC = objects[i].GetComponent <InputComponent>(); InteractorComponent intC = objects[i].GetComponent <InteractorComponent>(); MovementComponent movC = objects[i].GetComponent <MovementComponent>(); if (invC && inpC && intC && movC) { tmpFilters.Add(new Filter(index, objects[i].gameObject, invC, inpC, intC, movC)); } } filters = tmpFilters.ToArray(); environmentComponent = GetComponentInChildren <EnvironmentComponent>(); transportableComponent = GetComponentInChildren <CartComponent>(); cartInteractable = transportableComponent.GetComponent <InteractableComponent>(); lightComponent = GetComponentInChildren <LightComponent>(); //villagerComponent = GetComponentInChildren<VillagerComponent>(); travelComponent = GetComponentInChildren <TravelComponent>(); treeComponents = GetComponentsInChildren <CollectibleComponent>(); goapSystem = GetComponent <GOAPSystem>(); navMeshComponent = playerGO.GetComponent <NavMeshComponent>(); }
private void InteractWithWorldObject(RaycastHit hit, InteractorComponent interactorComp, InventoryComponent inventoryComp) { switch (hit.transform.gameObject.GetComponentInParent <CollectibleComponent>().baseCollectible) { case BaseResource t: // GatherResource(t, inventoryComp); break; default: break; } BaseResource resourceComp = hit.transform.gameObject.GetComponentInParent <CollectibleComponent>().baseCollectible; if (resourceComp != null) { // GatherResource(resourceComp, inventoryComp); } CartComponent transComp = hit.transform.GetComponent <CartComponent>(); if (transComp != null) { interactorComp.interactMode = InteractMode.Object; interactorComp.isInteracting = true; interactorComp.currentInteractable = transComp; //if(player.go.GetComponent<InventoryComponent>().InventoryBag.Count > 0) //{ // transComp.gameObject.GetComponent<InventoryComponent>().TransferItemsFromTo( // player.go.GetComponent<InventoryComponent>(), // transComp.gameObject.GetComponent<InventoryComponent>(), true); //} } }
private void AttemptWorldInteract(InteractorComponent interactorComp, InventoryComponent inventoryComp, LayerMask mask) { Transform t = interactorComp.GetOwnerGO().transform; Vector3 position = t.position + t.forward; RaycastHit[] hits; hits = Physics.BoxCastAll(position, Vector3.one, t.forward, Quaternion.identity, 1f, mask); for (int i = 0; i < hits.Length; i++) { CartComponent tc = hits[i].transform.GetComponentInParent <CartComponent>(); if (tc) { interactorComp.currentInteractable = tc; tc.isTraveling = false; interactorComp.SetInteractMode(InteractMode.Object); /* bool tempTest = false; * for (int y = 0; y < player.inventoryComponent.InventoryBag.Count; y++) * { * if (player.inventoryComponent.InventoryBag[y] != player.inventoryComponent.tempColl) * { * tempTest = true; * break; * } * } * * if(tempTest) * player.inventoryComponent.TransferItemsFromTo(player.inventoryComponent, tc.gameObject.GetComponent<InventoryComponent>(), true);*/ break; } } }
public Filter( int id, GameObject go, InventoryComponent ic, InputComponent inc, InteractorComponent iac ) { this.id = id; gameObject = go; inventoryComponent = ic; inputComponent = inc; interactorComponent = iac; }
public Filter(int id, GameObject go, InventoryComponent invC, InputComponent ic, InteractorComponent intC, MovementComponent movC ) { this.id = go.GetInstanceID(); gameObject = go; inventoryComponent = invC; inputComponent = ic; interactorComponent = intC; movementComponent = movC; }
public void Initialize() { if (!initialized) { return; } Transform[] worldObjects = GetComponentsInChildren <Transform>(); inputSystem.Initialize(worldObjects); InputComponent inpC = playerObject.GetComponent <InputComponent>(); HealthComponent healthC = playerObject.GetComponent <HealthComponent>(); InteractorComponent intC = playerObject.GetComponent <InteractorComponent>(); MovementComponent moveC = playerObject.GetComponent <MovementComponent>(); InventoryComponent invC = playerObject.GetComponent <InventoryComponent>(); GameManagerComponent gmC = playerObject.GetComponent <GameManagerComponent>(); AnimationComponent animC = playerObject.GetComponent <AnimationComponent>(); PlayerStoryComponent storyBeatC = playerObject.GetComponent <PlayerStoryComponent>(); PlayerEventComponent eventC = playerObject.GetComponent <PlayerEventComponent>(); GatheringComponent gatC = playerObject.GetComponent <GatheringComponent>(); UIComponent uiC = playerObject.GetComponent <UIComponent>(); NavMeshComponent nmC = playerObject.GetComponent <NavMeshComponent>(); LightComponent lC = playerObject.GetComponent <LightComponent>(); VFXComponent vfxC = playerObject.GetComponent <VFXComponent>(); CombatComponent cC = playerObject.GetComponent <CombatComponent>(); AudioComponent aC = playerObject.GetComponent <AudioComponent>(); ConditionsComponent conC = playerObject.GetComponent <ConditionsComponent>(); PlayerFilter pf = new PlayerFilter( playerObject, inpC, healthC, intC, moveC, invC, gmC, animC, storyBeatC, eventC, gatC, uiC, nmC, lC, vfxC, cC, aC, conC); sbs = GetComponent <StoryBeatSystem>(); for (int i = 0; i < systems.Length; i++) { systems[i].player = pf; systems[i].Initialize(worldObjects); systems[i].SetupInputComponent(inputSystem.inputComponent); } }
public override void Tick(float deltaTime) { for (int i = 0; i < filters.Length; i++) { // cache variables Filter filter = filters[i]; InventoryComponent inventoryComp = filter.inventoryComponent; InputComponent inputComp = filter.inputComponent; InteractorComponent interactComp = filter.interactorComponent; CartComponent cartComp = filter.cartComponent; // ----- logic ----- if (inputComp.GetKeyDown(KeyCode.E) || inputComp.GetButtonDown("Fire1")) { //if (invComp.treeResources > 0) //{ // //craftingSystem?.CraftPotion1(); // //craftGO.SetActive(!craftGO.activeSelf); //} AttemptWorldInteract(interactComp, player.inventoryComponent, inputComp.worldInteractMask); interactComp.SetInteractMode(InteractMode.Object); } if (inputComp.upDPad) { DropItem(0); } else if (inputComp.rightDPad) { DropItem(1); } else if (inputComp.downDPad) { DropItem(2); } else if (inputComp.leftDPad) { DropItem(3); } } }
public override void Initialize(Transform[] objects) { // list because I don't know size here List <Filter> tmpFilters = new List <Filter>(); int index = 0; for (int i = 0; i < objects.Length; i++) { // check performance InventoryComponent ic = objects[i].GetComponent <InventoryComponent>(); InteractorComponent iac = objects[i].GetComponent <InteractorComponent>(); InputComponent inc = objects[i].GetComponent <InputComponent>(); if (ic && iac && inc) { tmpFilters.Add(new Filter(index, objects[i].gameObject, ic, inc, iac)); } } filters = tmpFilters.ToArray(); }
public PlayerFilter( GameObject go, InputComponent inputC, HealthComponent healthC, InteractorComponent interactC, MovementComponent moveC, InventoryComponent inventoryC, GameManagerComponent gmc, AnimationComponent animC, PlayerStoryComponent psC, PlayerEventComponent peC, GatheringComponent gC, UIComponent uiC, NavMeshComponent nmC, LightComponent lC, VFXComponent vfxC, CombatComponent cC, AudioComponent aC, ConditionsComponent conC) { this.go = go; inputComponent = inputC; healthComponent = healthC; interactorComponent = interactC; movementComponent = moveC; inventoryComponent = inventoryC; gameManagerComponent = gmc; animationComponent = animC; playerStoryComponent = psC; eventComponent = peC; gatheringComponent = gC; uiComponent = uiC; navMeshComponent = nmC; lightComponent = lC; vfxComponent = vfxC; combatComponent = cC; audioComponent = aC; conditionsComponent = conC; }
public override void Initialize(Transform[] objects) { // list because I don't know size here List <Filter> tmpFilters = new List <Filter>(); int index = 0; for (int i = 0; i < objects.Length; i++) { // check performance InventoryComponent ic = objects[i].GetComponent <InventoryComponent>(); InteractorComponent iac = objects[i].GetComponent <InteractorComponent>(); InputComponent inc = objects[i].GetComponent <InputComponent>(); CartComponent cart = objects[i].GetComponent <CartComponent>(); if (ic && iac && inc) { tmpFilters.Add(new Filter(index, objects[i].gameObject, ic, inc, iac, cart)); } } // OnStart(); //player.go.GetComponent<InventoryComponent>().invUI = tempUIfix.GetComponent<UseInventorySystem>();//*/GameObject.FindObjectOfType<UseInventorySystem>(); filters = tmpFilters.ToArray(); }
private void AttemptWorldInteract(InteractorComponent interactorComp, InventoryComponent inventoryComp, LayerMask mask) { bool DontRemoveItemIfFull = false; if (player.gatheringComponent.nearbyCollectibles.Count != 0) { for (int i = 0; i < player.gatheringComponent.nearbyCollectibles.Count; i++) { if (player.gatheringComponent.nearbyCollectibles[i].isGatherable) { CollectibleComponent c = player.gatheringComponent.nearbyCollectibles[i]; // if several items, interact with one most in front of player if (interactedTime >= c.baseCollectible.interactionTime && c.isGatherable) { for (int y = 0; y < player.inventoryComponent.InventoryBag.Count; y++) { if (c.baseCollectible == player.inventoryComponent.InventoryBag[y].itemType.baseCollectible || player.inventoryComponent.InventoryBag[y].itemType.baseCollectible == player.inventoryComponent.tempColl.itemType.baseCollectible) { DontRemoveItemIfFull = true; break; } else { continue; } } //c.baseCollectible.PerformCollectibleEvent(player); if (!c.baseCollectible.PerformCollectibleEvent(player)) { if (DontRemoveItemIfFull) { if (c.TypeofCollectible != CollectibleComponent.CollectibleType.UTILITY) { GatherResource(c, inventoryComp); } player.animationComponent.OnPlayGatherAnimation(); interactedTime = 0f; } } else { /*Light l = c.GetComponentInChildren<Light>(); * * if (l) * { * Debug.Log(l); * if (player.lightComponent.nearbyLights.Contains(l)) * { * player.lightComponent.nearbyLights.Remove(l); * } * }*/ player.eventComponent.OnHidePreviousGatherPrompt(); interactedTime = 0f; } if (DontRemoveItemIfFull) { if (c.baseCollectible.destroyObjectOnPickup) { c.gameObject.SetActive(false); interactedTime = 0f; } player.gatheringComponent.nearbyCollectibles.Remove(c); } interactedTime = 0f; DontRemoveItemIfFull = false; } else if (interactedTime <= c.baseCollectible.interactionTime && c.isGatherable) { interactedTime += Time.deltaTime; player.uiComponent.gatheringPrompt.ProgressFill(interactedTime / c.baseCollectible.interactionTime); } if (!c.isGatherable) { isGathering = false; } } } } }
public override void Tick(float deltaTime) { for (int i = 0; i < filters.Length; i++) { // cache variables Filter filter = filters[i]; InventoryComponent invComp = filter.inventoryComponent; InputComponent inputComp = filter.inputComponent; InteractorComponent interactorComp = filter.interactorComponent; MovementComponent movComp = filter.movementComponent; // ----- logic ----- CheckDistanceToInteractable(filter); FindVisibleTargets(); // no longer used--------------------------- InteractMode previous = interactorComp.interactMode; if (inputComp.GetKeyDown(KeyCode.Alpha1)) { // move set none if previous was new to SetInteractMode interactorComp.SetInteractMode(InteractMode.PlacingPlanks); if (previous == InteractMode.PlacingPlanks) { interactorComp.SetInteractMode(InteractMode.None); } } else if (inputComp.GetKeyDown(KeyCode.Alpha2)) { interactorComp.SetInteractMode(InteractMode.Combat); if (previous == InteractMode.Combat) { interactorComp.SetInteractMode(InteractMode.None); } } //-------------------------------------------------- if (inputComp.GetKeyDown(KeyCode.E) || inputComp.GetButtonDown("Fire1")) { //AttemptWorldInteract(interactorComp, player.inventoryComponent, inputComp.worldInteractMask); //interactorComp.SetInteractMode(InteractMode.Object); } else if (inputComp.GetKeyDown(KeyCode.Escape)) { interactorComp.interactMode = InteractMode.None; CartComponent tc = (CartComponent)interactorComp.currentInteractable; if (tc) { tc.isTraveling = true; } } if (Vector3.Distance(filter.gameObject.transform.position, transportableComponent.transform.position) < 6f || Vector3.Distance(filter.gameObject.transform.position, travelComponent.transform.position) < 6f && lightComponent.IsLightEnabled()) { goapSystem?.SetLightState(true); } else { goapSystem?.SetLightState(false); } if (Vector3.Distance(filter.gameObject.transform.position, transportableComponent.transform.position) < 3f) { if (inputComp.GetKeyDown(KeyCode.B) || inputComp.GetButtonDown("Fire3")) { //bookGO.SetActive(!bookGO.activeSelf); movComp.alive = false; } else { movComp.alive = true; } if (inputComp.GetKeyDown(KeyCode.M) || inputComp.GetButtonDown("Fire2")) { //mapGO.SetActive(!mapGO.activeSelf); } if (inputComp.GetKeyDown(KeyCode.E) || inputComp.GetButtonDown("Fire1")) { //if (invComp.treeResources > 0) //{ // //craftingSystem?.CraftPotion1(); // //craftGO.SetActive(!craftGO.activeSelf); //} } } else { /*toggleMapGO.SetActive(false); * toggleBookGO.SetActive(false); * craftGO.SetActive(false);*/ } isCombat = interactorComp.interactMode == InteractMode.Combat; actorLocation = interactorComp.gameObject.transform.position; if (interactorComp.interactMode == InteractMode.PlacingPlanks) { isPlacingPlanks = true; if (isPlacingPlanks) { // Don't LogWarning this unity I'm sure you have your reasons but I don't like them. } // TODO remaing at last possible location if impossible position plankPlaceLocation = inputComp.GetMouseHoverTransformPosition(inputComp.objectPlaceMask); plankPlaceLocation.y = 0f; //if (inputComp.GetMouseButtonDown(0)) //{ // PlacePlank(invComp); //} } else { isPlacingPlanks = false; if (inputComp.GetMouseButtonDown(0)) { inputComp.GetMouseWorldLocation(out RaycastHit hit); } } } if (Vector3.Distance(lightComponent.transform.position, transportableComponent.transform.position) < 7 && !lightComponent.IsLightEnabled()) //Magic number. Remove this { //lightComponent.currentFuel = lightComponent.maxFuel; } }
public void Interact(InteractorComponent interactor) { OnInteracted.Invoke(); timer = 0.1f; timerRunning = true; }