protected void InitPlayerCharacter() { InitMovementComponent(); Player = this; ContextualUI = GetComponentInChildren <UIPlayerComponent>(); SpriteRender = GetComponentInChildren <SpriteRenderer>(); InitialSortingOrder = SpriteRender.sortingOrder; InitialZPosition = transform.position.z; image = ContextualUI.GetComponentInChildren <Image>(); Inventory = GetComponent <InventoryComponent>(); Inventory.AddItem(Item.EType.Mask); Inventory.AddItem(Item.EType.Newspaper); Inventory.AddItem(Item.EType.Grandma); }
public override State OnReachedTarget() { GridActor[] actors = GridActorMap.GetGridActors(this.request.PositionToMoveTo); foreach (GridActor actor in actors) { if (actor.Guid.Equals(this.request.TargetGuid)) { logger.Log("Found my target GridActor, giving it my item"); InventoryComponent inventory = actor.GetComponent <InventoryComponent>(); if (inventory) { inventory.AddItem(item); MoveItemRequestPool.Instance.FinishRequest(request); } else { MoveItemRequestPool.Instance.CancelRequest(request); logger.Log("My target GridActor did not have an inventory", LogLevel.Error); } TerminateMachine(); return(StateMachine.NoTransition()); } } logger.Log("Did not find my target GridActor at the target, dropping my item"); DroppedItemManager.PutItem(this.request.PositionToMoveTo, item); return(OnPathFindFail()); }
public void Animator_ToEat() { if (_animatorVariables.PlantSpotComponent == null) // => Is used by drag { _stomachComponent.AddFood(new ItemDTO() { Item = _animatorVariables.Flower.Item, Amount = 1 }); } else { ItemDTO flower = _animatorVariables.PlantSpotComponent.TakeFlower(); _stomachComponent.AddFood(new ItemDTO() { Item = flower.Item, Amount = 1 }); flower.Amount--; _animatorVariables.PlantSpotComponent.ResetPlantSpot(); if (flower.Amount <= 0) { this.RemoveInteractableState(); _isEating = false; return; } if (_inventoryComponent.InventoryIsFull()) { GameObject itemDropGameObject = Instantiate(_itemDropPrefab, this.gameObject.transform.position, Quaternion.identity); itemDropGameObject.GetComponentInChildren <ItemDropComponent>().SetCurrentItem(flower); } else { _inventoryComponent.AddItem(flower); } } _animatorVariables.ResetAuxiliarObjects(); this.RemoveInteractableState(); _isEating = false; }
public SeekerPistolEntity() : base() { Name = "SeekerPistol"; AddComponent(new PositionComponent(this)); AddComponent(new DrawableSfmlComponent(this, Enums.EnumSfmlSprites.SeekerPistol)); AddComponent(new CollisionComponent(this)); AddComponent(new AiComponent(this, new AiGuard(this))); var inventory = new InventoryComponent(this); inventory.AddItem(new Item(EnumItemTypes.Pistol)); AddComponent(inventory); }
/// <summary> /// Interact with entity on tile /// Returns false if it blocks the entity actor's movement /// </summary> /// <param name="interactor"></param> /// <param name="nextTile"></param> /// <returns></returns> private bool InteractTileEntities(Entity interactor, MapTile nextTile) { Entity activeTileEntity = nextTile.entities[0]; if (nextTile.entities.Count > 1) { // figure this out... for (int i = 0; i < nextTile.entities.Count; i++) { if (nextTile.entities[i].entityType == EntityType.Unit) { activeTileEntity = nextTile.entities[i]; break; } } } if (activeTileEntity.entityType == EntityType.Unit) { if (activeTileEntity.faction == interactor.faction) { return(false); } FighterComponent attacker = (FighterComponent)interactor.GetEntityComponent(ComponentID.Fighter); FighterComponent defender = (FighterComponent)activeTileEntity.GetEntityComponent(ComponentID.Fighter); return(DoCombat(attacker, defender)); } else if (activeTileEntity.entityType == EntityType.Item) { Debug.Log("ON AN ITEM TILE!!"); // do item pick up EntityComponent comp = interactor.GetEntityComponent(ComponentID.Inventory); if (comp == null) { return(true); } ItemComponent item = (ItemComponent)activeTileEntity.GetEntityComponent(ComponentID.Item); InventoryComponent inventory = (InventoryComponent)comp; if (inventory.AddItem(item) == true) { item.PickUp(); } return(true); } return(true); }
private void OnTriggerEnter(Collider other) { if (!other.CompareTag("Player")) { return; } if (this.gameObject.tag == "AK47") { //ItemInstance.UseItem(other.GetComponent<PlayerController>()); if (!other.CompareTag("Player")) { return; } Debug.Log($"{PickUpItem.Name} - Pickup Up"); InventoryComponent playerInventory = other.GetComponent <InventoryComponent>(); if (playerInventory) { playerInventory.AddItem(ItemInstance, Amount); } } else { if (!other.CompareTag("Player")) { return; } Debug.Log($"{PickUpItem.Name} - Pickup Up"); InventoryComponent playerInventory = other.GetComponent <InventoryComponent>(); if (playerInventory) { playerInventory.AddItem(ItemInstance, Amount); } } //if (!other.CompareTag("Player")) return; //Debug.Log($"{PickUpItem.Name} - Pickup Up"); //InventoryComponent playerInventory = other.GetComponent<InventoryComponent>(); //if (playerInventory) playerInventory.AddItem(ItemInstance, Amount); //ItemInstance.UseItem(other.GetComponent<PlayerController>()); Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { if (!other.CompareTag("Player")) { return; } Debug.Log($"{ PickUpItem.name} - Picked Up"); InventoryComponent inventoryComponent = other.GetComponent <InventoryComponent>(); if (inventoryComponent) { inventoryComponent.AddItem(ItemInstance, Amount); } Destroy(gameObject); }
public static void PutItem(Vector3Int pos, Item itemToAdd) { if (itemToAdd == null) { return; } Debug.Log("GridMap, Adding item to " + pos); GridActor[] actors = GridActorMap.GetGridActors(pos); DroppedItemComponent itemCont = null; foreach (GridActor actor in actors) { DroppedItemComponent tmpCont = actor.GetComponent <DroppedItemComponent>(); if (tmpCont != null) { itemCont = tmpCont; break; } } if (itemCont == null) { itemCont = DroppedItemComponent.InstantiateNew(pos); Debug.Log("GridMap, Spawned new DroppedItemComponent"); } InventoryComponent inv = itemCont.gameObject.GetComponent <InventoryComponent>(); if (inv) { inv.AddItem(itemToAdd); } else { Debug.LogWarning("GridMap, No inventory to drop item in"); } }