// dynamic features public override TCODConsole GetUpdatedConsole() { base.GetUpdatedConsole(); const int left = 2; int hoveredItemY = -1; Entity hoveredItem = null; int width = console.getWidth() - (left + 3); Vector2 mLoc = ScreenToConsoleCoord(engine.mouseData.CellX, engine.mouseData.CellY); InitializeConsole(); // devider line is a horizontal line that can be drawn across the console string deviderLine = CharConstants.E_TJOINT + ""; for (int i = 1; i < console.getWidth() - 1; i++) { deviderLine += CharConstants.HORZ_LINE; } deviderLine += CharConstants.W_TJOINT; // inventory weight: TODO DrawText(left, 2, " weight: X/X", Constants.COL_FRIENDLY); // equipped area ------------------------------------------------------------- int equiptopY = equipSection.starty; DrawText(0, equiptopY, deviderLine, TCODColor.white); DrawText(left, equiptopY, " equipped ", Constants.COL_NORMAL); if (equipment.weapon != null) { EGetScreenName getName = (EGetScreenName)equipment.weapon.FireEvent(new EGetScreenName()); string weaponName = getName.text; // the weapon is being hovered over if (mLoc.y == equiptopY + 3 && mLoc.x >= left && mLoc.x < weaponName.Length + 1 + left) { DrawRect(left, equiptopY + 3, width, Constants.COL_FRIENDLY); hoveredItem = equipment.weapon; hoveredItemY = equiptopY + 3; // was clicked, start dragging it if (engine.mouseData.LeftButtonPressed) { parent.SetDragDrop(weaponName, equipment.weapon, OnDragDroppedEquippedItem); parent.rangeIndicator.range = CombatEngine.GetThrowRange(player, equipment.weapon); draggingItem = true; } } DrawText(left, equiptopY + 2, "weapon: ", Constants.COL_NORMAL); DrawText(left, equiptopY + 3, " " + weaponName, TCODColor.white); } // pack adrea (general unequipped items) ------------------------------------- int packtopY = invSection.starty; DrawText(0, packtopY, deviderLine, TCODColor.white); DrawText(left, packtopY, " pack ", Constants.COL_NORMAL); int line = 1; foreach (Entity item in inventory.items) { // get the screen name dynamically: TODO: maybe cache this? EGetScreenName getName = (EGetScreenName)item.FireEvent(new EGetScreenName()); string screenName = getName.text; // check if the mouse is hovering on this item row if (mLoc.y == packtopY + line && mLoc.x >= left && mLoc.x < screenName.Length + 1 + left) { hoveredItem = item; hoveredItemY = packtopY + line; // highlight the item that is hovered on DrawRect(left, packtopY + line, width, Constants.COL_FRIENDLY); // check for clicks on this item, and start dragging it if (engine.mouseData.LeftButtonPressed) { parent.SetDragDrop(screenName, item, OnDragDroppedInvItem); // set the range indicator based on how far the dragged item can be thrown, in case the player dicides to throw its parent.rangeIndicator.range = CombatEngine.GetThrowRange(player, item); draggingItem = true; } } DrawText(left, packtopY + line, screenName, TCODColor.white); DrawText(left - 1, packtopY + line, ">", Constants.COL_ATTENTION); line += 1; } // if there is a hovered item, open the item details window if (hoveredItem != null && (!itemInfoWindow.isVisible || hoveredItem != itemInfoWindow.targetItem)) { // move the window to the correct position, and open it for the new item itemInfoWindow.origin.y = hoveredItemY; itemInfoWindow.origin.x = origin.x - itemInfoWindow.console.getWidth(); itemInfoWindow.OpenForItem(hoveredItem); } else if (hoveredItem == null && itemInfoWindow.isVisible) { itemInfoWindow.Close(); } // tell the parent to draw the range indicator if the user is looking like they will drop the dragged item if (draggingItem) { if (!ScreenCoordInConsole(new Vector2(engine.mouseData.CellX, engine.mouseData.CellY))) { parent.rangeIndicator.active = true; } else { parent.rangeIndicator.active = false; } } return(console); }
public bool Event_ThrowItem(ComponentEvent e) { AreaMap map = Engine.instance.world.currentMap; var throwEvent = ((EThrowItem)e); string itemType = throwEvent.itemName; // try to find the item on the entity to throw it var consumeItemEvent = (EConsumeItem)owner.FireEvent(new EConsumeItem() { itemName = itemType }); if (!consumeItemEvent.hasItem) { return(true); } // This enttiy did have the item to throw Entity projectile = consumeItemEvent.consumedItem; // Get the thrwoer strength and item weight, in order to calc both damage and max throw distance var getStrength = (EGetAttributeLevel)owner.FireEvent(new EGetAttributeLevel() { target = "strength" }); int strength = getStrength.level; float strRatio = (strength / 100.0f); var getWeight = (EGetWeight)owner.FireEvent(new EGetWeight()); int thrownWeight = getWeight.weight; float maxDistance = CombatEngine.GetThrowRange(owner, projectile); int throwDamage = (int)(strRatio * thrownWeight); // if the target position is farther than the max distance, select the nearest point in that direction Vector2 targetLoc = throwEvent.targetLocation; Vector2 toTarget = targetLoc - owner.position; if (toTarget.Magnitude() > maxDistance) { Vector2 dir = toTarget.Normalized(); targetLoc = owner.position + (dir * maxDistance); } // check where the item hits, if there is something in the way Vector2 hitNormal; Vector2 endPosition = map.CollisionPointFromTo(owner.position, targetLoc, out hitNormal); // find the target to hit, and apply some damage and knock them back Entity[] targets = map.GetAllObjectsAt(endPosition.X, endPosition.Y); foreach (Entity hit in targets) { CombatInstance combat = new CombatInstance(owner, hit) { { "damage", throwDamage }, { "weapon", projectile } }; CombatEngine.ProcessCombat(combat); } // the thrown item ends up next to the target location, or the nearest valid location toTarget = Vector2.OrthoNormal(toTarget); endPosition = endPosition - toTarget; endPosition = map.GetNearestValidMove(endPosition); Engine.instance.world.SpawnExisting(projectile, endPosition); return(true); }