private void OnObjectMultiUseHandlerUse(Vector3Int _, Core.Appearances.ObjectInstance @object, int __) { _activeActionPanel.toggleComponent.isOn = true; Core.Game.ObjectMultiUseHandler.onUse = null; if (!@object) { Open(); return; } var objectId = @object.Id; if (objectId < 100) { return; } var objectAction = GetHotkeyActionForPanel <HotkeyObjectAction>(_activeActionPanel); bool firstAdd = objectAction == null; if (firstAdd) { objectAction = new HotkeyObjectAction(@object.Type, UseActionTarget.CrossHair); SetHotketActionForPanel(_activeActionPanel, objectAction); _useWithCrosshairsToggle.toggle.isOn = true; _hotkeyTextInputField.interactable = false; _autoSendCheckboxWrapper.DisableComponent(); } else { objectAction.AppearanceType = @object.Type; if (@object.Type.IsMultiUse && objectAction.ActionTarget == UseActionTarget.Auto) { objectAction.ActionTarget = UseActionTarget.CrossHair; } else if ([email protected] && objectAction.ActionTarget != UseActionTarget.Auto) { objectAction.ActionTarget = UseActionTarget.Auto; } } if (objectAction.ActionTarget != UseActionTarget.Auto) { EnableObjectToggles(); } else { DisableObjectToggles(); } UpdateHotkeyPanelWithAction(_activeActionPanel, objectAction); if (!_objectInstance || _objectInstance.Id != objectAction.AppearanceType.Id) { _objectInstance = new Core.Appearances.ObjectInstance(objectAction.AppearanceType.Id, objectAction.AppearanceType, 0); } Open(); }
public HotkeyObjectAction(Core.Appearances.ObjectInstance @object, UseActionTarget actionTarget) { if (!@object) { throw new System.ArgumentNullException("HotkeyObjectAction.HotkeyObjectAction: invalid object"); } AppearanceType = @object.Type; ActionTarget = actionTarget; }
private void OnHotkeyActionToggleValueChanged(HotkeyActionPanel actionPanel, bool value) { if (!value) { return; } m_ChangingSelectedAction = true; var action = GetHotkeyActionForPanel <IHotkeyAction>(actionPanel); bool isObjectAction = action is HotkeyObjectAction; if (isObjectAction) { m_AutoSendCheckboxWrapper.DisableComponent(); } else { m_AutoSendCheckboxWrapper.EnableComponent(); } m_HotkeyTextInputField.interactable = !isObjectAction; m_ObjectImage.enabled = isObjectAction; if (action is HotkeyTextAction textAction) { m_HotkeyTextInputField.text = textAction.Text; m_AutoSendCheckboxWrapper.checkbox.Checked = textAction.AutoSend; } else { m_HotkeyTextInputField.text = string.Empty; m_AutoSendCheckboxWrapper.checkbox.Checked = false; } if (action is HotkeyObjectAction objectAction) { EnableObjectToggles(); SelectObjectToggle(objectAction.ActionTarget); if (!m_ObjectInstance || m_ObjectInstance.ID != objectAction.AppearanceType.ID) { m_ObjectInstance = new Core.Appearances.ObjectInstance(objectAction.AppearanceType.ID, objectAction.AppearanceType, 0); } } else { DisableObjectToggles(); } m_ActiveActionPanel = actionPanel; m_ChangingSelectedAction = false; }
public void Apply() { var absolutePosition = new UnityEngine.Vector3Int(65535, 0, 0); if (ActionTarget == UseActionTarget.CrossHair) { var @object = new Core.Appearances.ObjectInstance(AppearanceType._id, AppearanceType, 0); Core.Game.ObjectMultiUseHandler.Activate(absolutePosition, @object, 0); return; } // this is guaranteed to only be "self/target" // if the item is not multiuse (i.e a rune that can only be used on yourself, it will be only used) Core.Input.GameAction.GameActionFactory.CreateUseAction(absolutePosition, AppearanceType, 0, UnityEngine.Vector3Int.zero, null, 0, ActionTarget).Perform(); }
private void OnObjectMultiUseHandlerUse(Vector3Int _, Core.Appearances.ObjectInstance @object, int __) { Core.Game.ObjectMultiUseHandler.onUse = null; if (!@object) { OpenWindow(); return; } var objectID = @object.ID; if (objectID < 100) { return; } var objectAction = GetHotkeyActionForPanel <HotkeyObjectAction>(m_ActiveActionPanel); if (objectAction == null) { objectAction = new HotkeyObjectAction(@object.Type, UseActionTarget.CrossHair); SetHotketActionForPanel(m_ActiveActionPanel, objectAction); EnableObjectToggles(); m_ActiveActionPanel.textComponent.text = string.Format(TextUseWithCrosshairs, m_ActiveActionPanel.BaseText); m_UseWithCrosshairsToggle.toggle.isOn = true; m_HotkeyTextInputField.interactable = false; m_AutoSendCheckboxWrapper.DisableComponent(); } else { objectAction.AppearanceType = @object.Type; } if (!m_ObjectInstance || m_ObjectInstance.ID != objectAction.AppearanceType.ID) { m_ObjectInstance = new Core.Appearances.ObjectInstance(objectAction.AppearanceType.ID, objectAction.AppearanceType, 0); } OpenWindow(); }
private void OnHotkeyActionToggleValueChanged(HotkeyActionPanel actionPanel, bool value) { if (_changingVisibility || !value) { return; } _changingSelectedAction = true; var action = GetHotkeyActionForPanel <HotkeyAction>(actionPanel); bool isObjectAction = action is HotkeyObjectAction; if (isObjectAction) { _autoSendCheckboxWrapper.DisableComponent(); } else { _autoSendCheckboxWrapper.EnableComponent(); } _hotkeyTextInputField.interactable = !isObjectAction; _objectImage.enabled = isObjectAction; if (action is HotkeyTextAction textAction) { _hotkeyTextInputField.text = textAction.Text; _autoSendCheckboxWrapper.checkbox.Checked = textAction.AutoSend; } else { _hotkeyTextInputField.text = string.Empty; _autoSendCheckboxWrapper.checkbox.Checked = false; } if (action is HotkeyObjectAction objectAction) { if (objectAction.ActionTarget != UseActionTarget.Auto) { EnableObjectToggles(); SelectObjectToggle(objectAction.ActionTarget); } else { DisableObjectToggles(); } if (!_objectInstance || _objectInstance.Id != objectAction.AppearanceType.Id) { _objectInstance = new Core.Appearances.ObjectInstance(objectAction.AppearanceType.Id, objectAction.AppearanceType, 0); } } else { OpenTibiaUnity.GameManager.InvokeOnMainThread(() => { if (action == null || action is HotkeyTextAction) { _hotkeyTextInputField.ActivateInputField(); _hotkeyTextInputField.MoveTextEnd(false); } }); DisableObjectToggles(); if (action == null || action is HotkeyTextAction) { OpenTibiaUnity.GameManager.InvokeOnMainThread(() => { _hotkeyTextInputField.ActivateInputField(); _hotkeyTextInputField.MoveTextEnd(false); }); } } _activeActionPanel = actionPanel; _changingSelectedAction = false; }
public AppearanceActions DetermineAction(Vector2 point, bool applyAction = false, bool updateCursor = false, bool updateHighlight = false) { var mouseBinding = DetermineBinding(); if (!mouseBinding.HasValue) { return(AppearanceActions.None); } var worldMapRenderer = OpenTibiaUnity.WorldMapRenderer; var worldMapStorage = OpenTibiaUnity.WorldMapStorage; var creatureStorage = OpenTibiaUnity.CreatureStorage; var player = OpenTibiaUnity.Player; var action = mouseBinding.Value.Action; var oldAction = AppearanceActions.None; var mapPosition = worldMapRenderer.PointToMap(point); Core.Creatures.Creature creature = null; Core.Appearances.ObjectInstance foundObject = null; Core.Appearances.ObjectInstance topLookObject = null; Core.Appearances.ObjectInstance topUseObject = null; if (mapPosition.HasValue && mapPosition.Value.z == worldMapStorage.PlayerZPlane) { if (action != AppearanceActions.SmartClick && action != AppearanceActions.AutoWalk) { var tmpCreature = worldMapRenderer.PointToCreature(point, true); if (!!tmpCreature && worldMapStorage.GetCreatureObjectForCreature(creature, out foundObject) > -1) { creature = tmpCreature; } if (!foundObject) { worldMapStorage.GetTopLookObject(mapPosition.Value, out topLookObject); } else { topLookObject = foundObject; } worldMapStorage.GetTopUseObject(mapPosition.Value, out topUseObject); oldAction = action; if (!!creature && creature != player) { action = Core.InputManagment.MouseActionHelper.ResolveActionForAppearanceOrCreature(action, creature); topUseObject = null; } else if (!!topUseObject && topUseObject.Type.IsUsable) { action = Core.InputManagment.MouseActionHelper.ResolveActionForAppearanceOrCreature(action, topUseObject); } else if (!!topLookObject) { action = Core.InputManagment.MouseActionHelper.ResolveActionForAppearanceOrCreature(action, topLookObject); } } else { action = AppearanceActions.AutoWalk; } if (!!topUseObject && (topUseObject.Type.DefaultAction == (int)AppearanceActions.None) && oldAction != action && action == AppearanceActions.Look && worldMapStorage.GetEnterPossibleFlag(mapPosition.Value.x, mapPosition.Value.y, worldMapStorage.PlayerZPlane, true) != Constants.FieldEnterNotPossible) { action = AppearanceActions.AutoWalk; } } else { action = AppearanceActions.None; } if (updateCursor) { // TODO: Update Cursor } if (updateHighlight) { // TODO: update highlighted tile } if (applyAction) { switch (action) { case AppearanceActions.None: break; case AppearanceActions.Attack: if (!!creature && creature != player) { creatureStorage.ToggleAttackTarget(creature, true); } break; case AppearanceActions.AutoWalk: case AppearanceActions.AutoWalkHighlight: var cost = OpenTibiaUnity.MiniMapStorage.GetFieldCost(worldMapStorage.ToAbsolute(mapPosition.Value)); player.StartAutowalk(worldMapStorage.ToAbsolute(mapPosition.Value), false, true); break; case AppearanceActions.ContextMenu: // TODO: Open Context menu (position alligned to player) break; case AppearanceActions.Look: if (!!topLookObject) { // TODO: look action Vector3Int absolutePosition; if (foundObject == topLookObject) { absolutePosition = creature.Position; } else { absolutePosition = worldMapStorage.ToAbsolute(mapPosition.Value); } new Core.InputManagment.GameAction.LookActionImpl(absolutePosition, topLookObject, topLookObject.MapData).Perform(); } break; case AppearanceActions.Use: case AppearanceActions.Open: if (topUseObject != null) { var absolutePosition = worldMapStorage.ToAbsolute(mapPosition.Value); new Core.InputManagment.GameAction.UseActionImpl(absolutePosition, topUseObject.Type, topUseObject.MapData, UseActionTarget.Auto).Perform(); } break; case AppearanceActions.Talk: // TODO: Greet action break; case AppearanceActions.Unset: break; } } return(action); }
public HotkeyObjectAction(Core.Appearances.ObjectInstance @object, UseActionTarget actionTarget) : this(@object?.Type, actionTarget) { }