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 EnemyComponent ec = objects[i].GetComponent <EnemyComponent>(); CombatComponent cc = objects[i].GetComponent <CombatComponent>(); HealthComponent hc = objects[i].GetComponent <HealthComponent>(); if (cc && hc) { tmpFilters.Add(new Filter(index, objects[i].gameObject, ec, cc, hc)); } } filters = tmpFilters.ToArray(); environmentComponent = GetComponentInChildren <EnvironmentComponent>(); transportableComponent = GetComponentInChildren <CartComponent>(); inputComponent = GetComponentInChildren <InputComponent>(); }
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 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 GameManagerComponent gmc = objects[i].GetComponent <GameManagerComponent>(); if (gmc) { tmpFilters.Add(new Filter(index, objects[i].gameObject, gmc)); gmc.OnRestart += Restart; gmc.OnVictory += VictoryScreen; //gmc.OnDeath += RestartFromDeath; gmc.OnStartGameTick += StartGameTick; gmc.OnStopGameTick += StopGameTick; } } filters = tmpFilters.ToArray(); travelComponent = GetComponentInChildren <TravelComponent>(); transportableComponent = GetComponentInChildren <CartComponent>(); goapSystem = GetComponent <GOAPSystem>(); }
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); // } } }
IEnumerator InitializeCartComponent(CartComponent cartComponent) { var entityComponent = cartComponent.GetComponent <EntityComponent>(); var entityHandler = EntityComponentToEntityHandler[entityComponent]; var spriteRenderer = entityHandler.GetComponent <SpriteRenderer>(); spriteRenderer.color = new Color(0.5f, 0.35f, 0.35f); yield break; }
public Filter(int id, GameObject go, CartComponent tc, CombatComponent cc ) { this.id = id; gameObject = go; transportableComponent = tc; combatComponent = cc; }
void RegisterCart(CartComponent cart) { this.Log($"ProductionAgent initializing cart {cart}"); var cartAgent = cart.gameObject.AddComponent <CartAgentComponent>(); var logtype = this.GetLogLevel(); cartAgent.SetLogLevel(logtype); CartToAgent.Add(cart, cartAgent); }
public void AddToCart() { List <Product> productList = new List <Product>(); List <Promotion> promotionList = new List <Promotion>(); productList.Add(new Product { SKUID = 'A', Price = 50 }); productList.Add(new Product { SKUID = 'B', Price = 30 }); productList.Add(new Product { SKUID = 'C', Price = 20 }); productList.Add(new Product { SKUID = 'D', Price = 15 }); promotionList.Add(new Promotion { SKUID = 'A', Quantity = 3, Price = 130 }); promotionList.Add(new Promotion { SKUID = 'B', Quantity = 2, Price = 45 }); promotionList.Add(new Promotion { SKUID = 'C', Quantity = 1, Price = 30 }); promotionList.Add(new Promotion { SKUID = 'D', Quantity = 1, Price = 30 }); CartComponent cart = new CartComponent(); Assert.AreEqual(true, cart.AddCart('A', 1, productList, promotionList)); Assert.AreEqual(true, cart.AddCart('B', 1, productList, promotionList)); Assert.AreEqual(true, cart.AddCart('C', 1, productList, promotionList)); Assert.AreEqual(100, cart.GetCartTotal(productList, promotionList)); cart = new CartComponent(); Assert.AreEqual(true, cart.AddCart('A', 5, productList, promotionList)); Assert.AreEqual(true, cart.AddCart('B', 5, productList, promotionList)); Assert.AreEqual(true, cart.AddCart('C', 1, productList, promotionList)); Assert.AreEqual(370, cart.GetCartTotal(productList, promotionList)); cart = new CartComponent(); Assert.AreEqual(true, cart.AddCart('A', 3, productList, promotionList)); Assert.AreEqual(true, cart.AddCart('B', 5, productList, promotionList)); Assert.AreEqual(true, cart.AddCart('C', 1, productList, promotionList)); Assert.AreEqual(true, cart.AddCart('D', 1, productList, promotionList)); Assert.AreEqual(280, cart.GetCartTotal(productList, promotionList)); }
public Filter( int id, GameObject go, InventoryComponent ic, InputComponent inc, InteractorComponent iac, CartComponent cart ) { this.id = id; gameObject = go; inventoryComponent = ic; inputComponent = inc; interactorComponent = iac; cartComponent = cart; }
public override void Tick(float deltaTime) { for (int i = 0; i < filters.Length; i++) { // cache variables Filter filter = filters[i]; CartComponent transComp = filter.transportableComponent; CombatComponent combComp = filter.combatComponent; // ----- logic ----- /*if (transComp.isTraveling) * { * transComp.ConsumeFuel(deltaTime); * transComp.agent.Move(transComp.GetOwnerGO().transform.TransformDirection(transform.forward) * transComp.travelSpeed * deltaTime); * }*/ } }
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>(); if (ic) { tmpFilters.Add(new Filter(index, objects[i].gameObject, ic)); } } filters = tmpFilters.ToArray(); cartComponent = GetComponentInChildren <CartComponent>(); }
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 CartComponent tc = objects[i].GetComponent <CartComponent>(); CombatComponent cc = objects[i].GetComponent <CombatComponent>(); if (tc) { tmpFilters.Add(new Filter(index, objects[i].gameObject, tc, cc)); } } filters = tmpFilters.ToArray(); }
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>(); 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(); }
/// <summary> /// Initializes a new instance of the <see cref = "CartLeftEventArgs">CartLeftEventArgs</see> class. /// </summary> /// <param name="cart">The <see cref = "CartComponent">Cart</see> which has left the company.</param> public CartLeftEventArgs(CartComponent cart) { Cart = cart; }
/// <summary> /// Gets wether a given cart is employed by the company. /// </summary> /// <param name="cart">The cart in question.</param> /// <returns></returns> public bool IsEmployed(CartComponent cart) => Carts.Contains(cart);
/// <summary> /// Gets whether a give cart is at the company. /// </summary> /// <param name="cart">The cart in question.</param> /// <returns></returns> public bool IsAvailable(CartComponent cart) => Location.EntityRegistry.IsRegistered(cart.Entity);
/// <summary> /// Initializes a new instance of the <see cref = "CartArrivedEventArgs">CartArrivedEventArgs</see> class. /// </summary> /// <param name="cart">The <see cref = "CartComponent">Cart</see> which has arrived at the company.</param> public CartArrivedEventArgs(CartComponent cart) { Cart = cart; }
/// <summary> /// Initializes a new instance of the <see cref = "CartHiredEventArgs">CartHiredEventArgs</see> class. /// </summary> /// <param name="cart">The hired <see cref = "CartComponent">Cart</see>.</param> /// <param name="cost">The cost of hiring the cart.</param> public CartHiredEventArgs(CartComponent cart, int cost) { Cart = cart; Cost = cost; }
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; } }