/// <summary> /// Crafts an item from the added ingredients /// </summary> /// <returns>true if item was succesfully created</returns> public bool CraftItem() { if (items.Count < 2) { UISystem.Message("You need to put in at least two items!"); ResetCrafting(); return(false); } ExtractSubstances(); // TODO: other crafting than alchemy int newItem = Alchemy(); if (newItem == 0) { // something went wrong before and // should have already been handled ResetCrafting(); return(false); } UISystem.Message("You just crafted something!"); substances.Clear(); foreach (var itemID in items) { ItemSystem.TryDeleteItem(itemID); } items.Clear(); //var description = EntityManager.GetComponent<DescriptionComponent>(newItem); //description.Name = "Crafted " + description.Name; ItemAddedEvent?.Invoke(Util.PlayerID, newItem); string info = DescriptionSystem.GetDebugInfoEntity(newItem); Log.Message("Crafting successful:"); Log.Data(info); Util.TurnOver(Util.PlayerID); return(true); }
public bool HandleInteraction(int actor, int other) { var interactable = EntityManager.GetComponent <InteractableComponent>(other); if (interactable == null) { Log.Error("HandleInteraction called on non-interactable object!"); Log.Data(DescriptionSystem.GetDebugInfoEntity(other)); return(false); } //Log.Message("Interaction between " + DescriptionSystem.GetNameWithID(actor) + " and " + DescriptionSystem.GetNameWithID(other)); //Log.Data(DescriptionSystem.GetDebugInfoEntity(other)); if (interactable.ChangeSolidity) { var collider = EntityManager.GetComponent <ColliderComponent>(other); if (collider == null) { Log.Warning("Interactable has ChangeSolidity set but has no collider attached! " + DescriptionSystem.GetNameWithID(other)); Log.Data(DescriptionSystem.GetDebugInfoEntity(other)); } else if (collider.Solid == false) { //TODO: make it solid again? ( ._.)? } else { collider.Solid = false; } } if (interactable.ChangeTexture) { var renderable = EntityManager.GetComponent <RenderableSpriteComponent>(other); if (renderable == null) { Log.Error("Interactable has ChangeTexture set but does not have RenderableSprite attached! " + DescriptionSystem.GetNameWithID(other)); Log.Data(DescriptionSystem.GetDebugInfoEntity(other)); return(false); } if (interactable.AlternateTexture == "") { Log.Warning("Interactable has ChangeTexture set but does not define AlternateTexture! " + DescriptionSystem.GetNameWithID(other)); Log.Data(DescriptionSystem.GetDebugInfoEntity(other)); renderable.Texture = "square"; // placholder; something's not right } else { renderable.Texture = interactable.AlternateTexture; } } if (interactable.GrantsItems) { if (interactable.Items == null) { Log.Warning("Interactable has GrantItems set but does not define Items! " + DescriptionSystem.GetNameWithID(other)); Log.Data(DescriptionSystem.GetDebugInfoEntity(other)); } else if (interactable.Items.Count == 0) { UISystem.Message("Nothing here to be picked up!"); return(false); } else { var inventory = EntityManager.GetComponent <InventoryComponent>(actor); if (inventory == null) { Log.Warning("Pick up failed. Character has no inventory! " + DescriptionSystem.GetNameWithID(actor)); return(false); } else { if (ItemAddedEvent == null) { Log.Error("InteractionSystem->ItemAddedEvent is null!"); return(false); } bool success = ItemAddedEvent.Invoke(actor, interactable.Items[0]); if (success) { interactable.Items.RemoveAt(0); } else { // Failed to add to inventory (should already be handled) return(false); } } } } Util.TurnOver(actor); return(true); }
/// <summary> /// checks if moving onto newPos is possible /// and triggers any interaction otherwise /// </summary> /// <param name="entity">ID of entity to move</param> /// <param name="newPos">new Position to move to</param> /// <returns>wether movement is possible</returns> private bool TryMove(int entity, Position newPos) { var floor = Util.CurrentFloor; if (floor.IsOutOfBounds(newPos)) { return(false); } int otherCharacter = floor.GetCharacter(newPos); //check if someone's already there if (otherCharacter != 0 && otherCharacter != entity) { // check if collidable if (EntityManager.GetComponent <ColliderComponent>(otherCharacter) != null) { //TODO: talk to npcs? RaiseBasicAttackEvent(entity, otherCharacter); return(false); } else { Log.Warning("Character without collider:"); Log.Data(DescriptionSystem.GetDebugInfoEntity(otherCharacter)); UISystem.Message("Something seems to be there..."); return(false); } } int structure = floor.GetStructure(newPos); if (structure != 0 && EntityManager.GetComponent <ColliderComponent>(structure) != null) { bool solid = RaiseCollisionEvent(entity, structure); // check if interactable var interactable = EntityManager.GetComponent <InteractableComponent>(structure); // only interact with structures right away if they're solid ("bumping" into them) if (solid) { if (interactable != null) { RaiseInteractionEvent(entity, structure); } return(false); } } int terrain = floor.GetTerrain(newPos); // check if collidable with if (terrain != 0 && EntityManager.GetComponent <ColliderComponent>(terrain) != null) { // check if terrain is solid before possible interaction // this is because solidity might be changed by interaction (e.g. door gets opened) bool solid = RaiseCollisionEvent(entity, terrain); // check if interactable var interactable = EntityManager.GetComponent <InteractableComponent>(terrain); if (interactable != null) { RaiseInteractionEvent(entity, terrain); } // check if terrain is solid if (solid) { return(false); } } //trigger special Message on step on if (entity == Util.PlayerID && terrain != 0) { string message = (DescriptionSystem.GetSpecialMessage(terrain, DescriptionComponent.MessageType.StepOn)); if (message.Length > 0) { UISystem.Message(message); } } return(true); }