public bool ProcessDrag(Item item, float x, float y) { return(MapLogic.Instance.IsLoaded && SelectedObject != null && SelectedObject is IPlayerPawn && ((IPlayerPawn)SelectedObject).GetPlayer() == MapLogic.Instance.ConsolePlayer && SelectedObject.GetObjectType() == MapObjectType.Human && ((MapHuman)SelectedObject).IsHero); }
public bool ProcessEvent(Event e) { if (!MapLogic.Instance.IsLoaded) { return(false); } if (e.type == EventType.KeyDown) { switch (e.keyCode) { case KeyCode.LeftArrow: if (ScrollDeltaX == 0) { ScrollDeltaX = -1; } return(true); case KeyCode.RightArrow: if (ScrollDeltaX == 0) { ScrollDeltaX = 1; } return(true); case KeyCode.UpArrow: if (ScrollDeltaY == 0) { ScrollDeltaY = -1; } return(true); case KeyCode.DownArrow: if (ScrollDeltaY == 0) { ScrollDeltaY = 1; } return(true); case KeyCode.Plus: case KeyCode.Equals: // + = = case KeyCode.KeypadPlus: { int oldSpeed = MapLogic.Instance.Speed; if (!NetworkManager.IsClient) { MapLogic.Instance.Speed++; } if (oldSpeed != MapLogic.Instance.Speed) { MapViewChat.Instance.AddChatMessage(Player.AllColorsSystem, Locale.Main[108 + MapLogic.Instance.Speed]); } } return(true); case KeyCode.Minus: case KeyCode.KeypadMinus: { int oldSpeed = MapLogic.Instance.Speed; if (!NetworkManager.IsClient) { MapLogic.Instance.Speed--; } if (oldSpeed != MapLogic.Instance.Speed) { MapViewChat.Instance.AddChatMessage(Player.AllColorsSystem, Locale.Main[108 + MapLogic.Instance.Speed]); } } return(true); case KeyCode.F3: //if (NetworkManager.IsClient) { DiplomacyWindow wnd = Utils.CreateObjectWithScript <DiplomacyWindow>(); //Debug.LogFormat("created a window!"); } return(true); case KeyCode.Escape: { // todo: create main menu ExampleWindow wnd = Utils.CreateObjectWithScript <ExampleWindow>(); } return(true); case KeyCode.Space: // check if local unit is dead. // for dead local unit, space sends respawn. // for alive local unit, space toggles both spellbook and inventory. if (MapLogic.Instance.ConsolePlayer != null && !MapLogic.Instance.ConsolePlayer.Avatar.IsAlive) { Client.SendRespawn(); } else { bool cstate = InventoryVisible && SpellbookVisible; InventoryVisible = !cstate; SpellbookVisible = !cstate; Spellbook.Update(); } return(true); case KeyCode.BackQuote: InventoryVisible = !InventoryVisible; Spellbook.Update(); return(true); case KeyCode.Q: SpellbookVisible = !SpellbookVisible; Spellbook.Update(); return(true); } } else if (e.type == EventType.KeyUp) { switch (e.keyCode) { case KeyCode.LeftArrow: if (ScrollDeltaX == -1) { ScrollDeltaX = 0; } return(true); case KeyCode.RightArrow: if (ScrollDeltaX == 1) { ScrollDeltaX = 0; } return(true); case KeyCode.UpArrow: if (ScrollDeltaY == -1) { ScrollDeltaY = 0; } return(true); case KeyCode.DownArrow: if (ScrollDeltaY == 1) { ScrollDeltaY = 0; } return(true); } } else if (e.rawType == EventType.MouseMove) { UpdateInput(); return(true); } else if (e.rawType == EventType.MouseDown && e.button == 0) { // select unit if not selected yet if (HoveredObject != null && (SelectedObject == null || (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move && !Input.GetKey(KeyCode.LeftAlt) && !Input.GetKey(KeyCode.RightAlt)) || (Commandbar.CurrentCommand == 0))) { SelectedObject = HoveredObject; OnObjectSelected(SelectedObject); } else if (SelectedObject != null && SelectedObject is IPlayerPawn && ((IPlayerPawn)SelectedObject).GetPlayer() == MapLogic.Instance.ConsolePlayer) { // todo: handle commands here // try to walk. if (SelectedObject.GetObjectType() == MapObjectType.Monster || SelectedObject.GetObjectType() == MapObjectType.Human) { MapUnit unit = (MapUnit)SelectedObject; if (GetCastSpell() != Spell.Spells.NoneSpell) { if (HoveredObject != null && (HoveredObject.GetObjectType() == MapObjectType.Monster || HoveredObject.GetObjectType() == MapObjectType.Human)) { Client.SendCastToUnit(unit, GetCastSpell(), (MapUnit)HoveredObject); } else { Client.SendCastToArea(unit, GetCastSpell(), MouseCellX, MouseCellY); } } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move) { Client.SendMoveUnit(unit, MouseCellX, MouseCellY); } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Attack && HoveredObject != null && (HoveredObject.GetObjectType() == MapObjectType.Monster || HoveredObject.GetObjectType() == MapObjectType.Human)) { Client.SendAttackUnit(unit, (MapUnit)HoveredObject); } else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Pickup && MapLogic.Instance.GetSackAt(MouseCellX, MouseCellY) != null) { Client.SendPickupUnit(unit, MouseCellX, MouseCellY); // issue sack pickup command by current unit at target coordinates } } } return(true); } else if (e.rawType == EventType.MouseDown && e.button == 1) { SelectedObject = null; // deselect Commandbar.EnabledCommands = 0; return(true); } return(false); }
void Update() { MiniMap.gameObject.SetActive(MapLogic.Instance.IsLoaded); Commandbar.gameObject.SetActive(MapLogic.Instance.IsLoaded); Infowindow.gameObject.SetActive(MapLogic.Instance.IsLoaded); Inventory.gameObject.SetActive(InventoryVisible); Spellbook.gameObject.SetActive(SpellbookVisible); if (!MapLogic.Instance.IsLoaded) { return; } if (GridEnabled) { GridMeshMaterial.color = new Color(1, 0, 0, 0.5f); } else { GridMeshMaterial.color = new Color(0, 0, 0, 0); } // update lighting. Texture2D lightTex = MapLogic.Instance.CheckLightingTexture(); if (lightTex != null) { UpdateLighting(lightTex); } Texture2D fowTex = MapLogic.Instance.CheckFOWTexture(); if (fowTex != null) { UpdateFOW(fowTex); } if (HoveredObject != null && (HoveredObject.GetObjectType() == MapObjectType.Monster || HoveredObject.GetObjectType() == MapObjectType.Human) && (!((MapUnit)HoveredObject).IsAlive || !MapLogic.Instance.Objects.Contains(HoveredObject))) { HoveredObject = null; } if (SelectedObject != null && (SelectedObject.GetObjectType() == MapObjectType.Monster || SelectedObject.GetObjectType() == MapObjectType.Human) && (!((MapUnit)SelectedObject).IsAlive || !MapLogic.Instance.Objects.Contains(SelectedObject))) { SelectedObject = null; } UpdateLogic(); int waterAnimFrameNew = (MapLogic.Instance.LevelTime % 20) / 5; if (WaterAnimFrame != waterAnimFrameNew) { WaterAnimFrame = waterAnimFrameNew; UpdateTiles(WaterAnimFrame); } // update scrolling scrollTimer += Time.unscaledDeltaTime; if (scrollTimer > 0.01) { SetScroll(ScrollX + ScrollDeltaX, ScrollY + ScrollDeltaY); scrollTimer = 0; } }