Example #1
0
            internal void AddItem(ItemPlacement placement, Item item)
            {
                switch (placement)
                {
                case ItemPlacement.PlayerBracers: Bracers = item; break;

                case ItemPlacement.PlayerFeet: Feet = item; break;

                case ItemPlacement.PlayerHands: Hands = item; break;

                case ItemPlacement.PlayerHead: Head = item; break;

                case ItemPlacement.PlayerLeftFinger: LeftFinger = item; break;

                case ItemPlacement.PlayerLeftHand: LeftHand = item; break;

                case ItemPlacement.PlayerLegs: Legs = item; break;

                case ItemPlacement.PlayerNeck: Neck = item; break;

                case ItemPlacement.PlayerRightFinger: RightFinger = item; break;

                case ItemPlacement.PlayerRightHand: RightHand = item; break;

                case ItemPlacement.PlayerShoulders: Shoulders = item; break;

                case ItemPlacement.PlayerTorso: Torso = item; break;

                case ItemPlacement.PlayerWaist: Waist = item; break;

                default:
                    throw new Exception("Unrecognized attachment position " + placement);
                }
            }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="mode">
        /// The mode settings.
        /// </param>
        /// <param name="expectedValue">
        /// The expected item placement value.
        /// </param>
        public ItemPlacementRequirement(IMode mode, ItemPlacement expectedValue)
        {
            _mode          = mode;
            _expectedValue = expectedValue;

            _mode.PropertyChanged += OnModeChanged;

            UpdateValue();
        }
 private void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
 {
     if (entity == null || info == null)
     {
         ItemPlacement placement = entity.GetComponent <ItemPlacement>();
         if (placement != null)
         {
             placement.OnPlayerDeath();
         }
     }
 }
        private async void GoToButton_Click(object sender, RoutedEventArgs e)
        {
            int.TryParse(GoToIntex.Text, out int goToIntex);
            ItemPlacement itemPlacement    = (ItemPlacement)ItemPlacementComboBox.SelectedItem;
            bool          disableAnimation = DisableAnimationToggleSwitch.IsOn;
            bool          scrollIfVisibile = ScrollIfVisibileToggleSwitch.IsOn;

            int.TryParse(AdditionalHorizontalOffsetTextBox.Text, out int additionalHorizontalOffset);
            int.TryParse(AdditionalHorizontalOffsetTextBox.Text, out int additionalVerticalOffset);

            await MyGridView.SmoothScrollIntoViewWithIndex(goToIntex, itemPlacement, disableAnimation, scrollIfVisibile, additionalHorizontalOffset, additionalVerticalOffset);
        }
Example #5
0
        public GameObject Place(ItemPlacement placement, ProgressBar progress)
        {
            using (new Timing("Placing"))
                try {
                    progress.Increment(string.Format("(ID {1}) {0}", placement.ItemName, placement.DefinitionID));

                    var definition = IdeCollection[placement.DefinitionID];
                    var obj        = definition.GetObject(false);

                    obj.transform.position = placement.Position;
                    obj.transform.rotation = placement.Rotation;
                    //obj.transform.localScale = plac.Scale; Unnecessary?

                    if (IplCollection.GetLodVersion(placement, out placement))
                    {
                        if (!obj.GetComponent <LODGroup>())
                        {
                            var lodObj     = Place(placement, progress);
                            var lodGroupGO = new GameObject(obj.name + " (LOD Group)");
                            var lodGroup   = lodGroupGO.AddComponent <LODGroup>();

                            obj.transform.SetParent(lodGroupGO.transform);
                            lodObj.transform.SetParent(lodGroupGO.transform);
                            lodGroupGO.layer = Layer.LODGroup;

                            foreach (var child in obj.GetComponentsInChildren <Transform>())
                            {
                                child.gameObject.layer = Layer.LODGroup;
                            }
                            foreach (var child in lodObj.GetComponentsInChildren <Transform>())
                            {
                                child.gameObject.layer = Layer.LODGroup;
                            }

                            lodGroup.SetLODs(new LOD[] {
                                new LOD(0.5f, obj.GetComponentsInChildren <Renderer>()),
                                new LOD(0f, lodObj.GetComponentsInChildren <Renderer>())
                            });
                        }
                    }

                    return(obj);
                }
                catch (Exception e) {
                    Log.Error("Failed to place object \"{0}\" (ID {1}): {2}", placement.ItemName, placement.DefinitionID, e);
                    return(null);
                }
        }
Example #6
0
        PanePosition GetDockState(ItemPlacement p_dockState)
        {
            switch (p_dockState)
            {
            case ItemPlacement.Left:
                return(PanePosition.Left);

            case ItemPlacement.Right:
                return(PanePosition.Right);

            case ItemPlacement.Top:
                return(PanePosition.Top);

            case ItemPlacement.Bottom:
                return(PanePosition.Bottom);
            }
            return(PanePosition.Left);
        }
Example #7
0
    /// <summary>
    /// Called to see if the current pickupable can be used on whats being hovered by the player
    /// </summary>
    /// <returns></returns>
    private bool UseOnInteractactable()
    {
        //Check if the player is hovering over an ItemPlacement object and determine whether the object is able to be used by it
        GameObject itemInView = playerInteract.GetItemInView();

        if (itemInView)
        {
            ItemPlacement itemPlacement = itemInView.GetComponent <ItemPlacement>();
            if (itemPlacement && itemPlacement.OnItemUse(item))
            {
                playerInventory.RemoveFromInventory(item, 1);
                Destroy(gameObject);
                return(true);
            }
        }

        return(false);
    }
Example #8
0
        /// <summary>
        /// Parsing IPL files<para/>
        /// Разбор файлов IPL
        /// </summary>
        public static void ReadPlacements()
        {
            List <ItemPlacement> pl = new List <ItemPlacement>();

            foreach (string IPL in FileManager.PlacementFiles)
            {
                TextFile f = new TextFile(PathManager.GetAbsolute(IPL), true, true);
                foreach (TextFile.Line p in f.Lines)
                {
                    switch (p.Section.ToLower())
                    {
                    // Object installation
                    // Расстановка объектов
                    case "inst":
                        ItemPlacement g = new ItemPlacement();

                        g = new ItemPlacement()
                        {
                            ID         = p.Text[0].ToInt(),
                            ModelName  = p.Text[1],
                            InteriorID = ItemPlacement.Interior.World,
                            Position   = new Vector3(p.Text[p.Text.Length - 10].ToFloat(), p.Text[p.Text.Length - 8].ToFloat(), p.Text[p.Text.Length - 9].ToFloat()),
                            Scale      = new Vector3(p.Text[p.Text.Length - 7].ToFloat(), p.Text[p.Text.Length - 5].ToFloat(), p.Text[p.Text.Length - 6].ToFloat()),
                            Angle      = new Quaternion(-p.Text[p.Text.Length - 4].ToFloat(), -p.Text[p.Text.Length - 2].ToFloat(), -p.Text[p.Text.Length - 3].ToFloat(), -p.Text[p.Text.Length - 1].ToFloat()),
                        };
                        if (p.Text.Length > 12)
                        {
                            g.InteriorID = (ItemPlacement.Interior)p.Text[2].ToInt();
                        }
                        pl.Add(g);
                        break;
                    }
                    // Operation is threadable, so sleep for a while
                    // Операция потоковая, поэтому отдадим времени основному процессу
                    System.Threading.Thread.Sleep(0);
                }
            }
            Placements = pl.ToArray();
            Dev.Console.Log("[ObjectManager] Parsed " + FileManager.PlacementFiles.Length + " placement files (" + pl.Count + " entries)");
        }
Example #9
0
        /// <summary>
        /// 应用GridResizer属性
        /// </summary>
        /// <param name="p_resizer"></param>
        public void Bind(GridResizer p_resizer)
        {
            UIElement parent = p_resizer.Parent as UIElement;

            if (parent != null)
            {
                Matrix matrix = ((MatrixTransform)p_resizer.TransformToVisual(parent)).Matrix;
                _splitterOrigin.X = matrix.OffsetX;
                _splitterOrigin.Y = matrix.OffsetY;

                ItemPlacement direction = p_resizer.Placement ?? ItemPlacement.Left;
                if (p_resizer.Placement == ItemPlacement.Left)
                {
                    Height = parent.RenderSize.Height;
                    Width  = GridResizer.ResizerSize;
                    SetValue(Canvas.LeftProperty, _splitterOrigin.X);
                }
                else if (p_resizer.Placement == ItemPlacement.Right)
                {
                    Height = parent.RenderSize.Height;
                    Width  = GridResizer.ResizerSize;
                    SetValue(Canvas.LeftProperty, _splitterOrigin.X);
                }
                else if (p_resizer.Placement == ItemPlacement.Top)
                {
                    Width  = parent.RenderSize.Width;
                    Height = GridResizer.ResizerSize;
                    SetValue(Canvas.TopProperty, _splitterOrigin.Y);
                }
                else
                {
                    Width  = parent.RenderSize.Width;
                    Height = GridResizer.ResizerSize;
                    SetValue(Canvas.TopProperty, _splitterOrigin.Y);
                }
            }
        }
Example #10
0
 void Start() {
     _input = ConfigurableInput.GetInstance();
     _placement = ItemPlacement.GetInstance();
 }
Example #11
0
        /// <summary>
        /// Smooth scrolling the list to bring the specified index into view
        /// </summary>
        /// <param name="listViewBase">List to scroll</param>
        /// <param name="index">The intex to bring into view</param>
        /// <param name="itemPlacement">Set the item placement after scrolling</param>
        /// <param name="disableAnimation">Set true to disable animation</param>
        /// <param name="scrollIfVisibile">Set true to disable scrolling when the corresponding item is in view</param>
        /// <param name="additionalHorizontalOffset">Adds additional horizontal offset</param>
        /// <param name="additionalVerticalOffset">Adds additional vertical offset</param>
        /// <returns>Note: Even though this return <see cref="Task"/>, it will not wait until the scrolling completes</returns>
        public static async Task SmoothScrollIntoViewWithIndex(this Windows.UI.Xaml.Controls.ListViewBase listViewBase, int index, ItemPlacement itemPlacement = ItemPlacement.Default, bool disableAnimation = false, bool scrollIfVisibile = true, int additionalHorizontalOffset = 0, int additionalVerticalOffset = 0)
        {
            if (Math.Abs(index) > listViewBase.Items.Count)
            {
                throw new IndexOutOfRangeException("Index can't be greater than number of items in " + listViewBase.GetType().Name);
            }

            index = (index < 0) ? (index + listViewBase.Items.Count) : index;

            bool   isVirtualizing = default(bool);
            double previousXOffset = default(double), previousYOffset = default(double);

            var scrollViewer = listViewBase.FindDescendant <ScrollViewer>();
            var selectorItem = listViewBase.ContainerFromIndex(index) as SelectorItem;

            if (selectorItem == null)
            {
                isVirtualizing = true;

                previousXOffset = scrollViewer.HorizontalOffset;
                previousYOffset = scrollViewer.VerticalOffset;

                var tcs = new TaskCompletionSource <object>();

                void viewChanged(object s, ScrollViewerViewChangedEventArgs e) => tcs.TrySetResult(null);

                try
                {
                    scrollViewer.ViewChanged += viewChanged;
                    listViewBase.ScrollIntoView(listViewBase.Items[index], ScrollIntoViewAlignment.Leading);
                    await tcs.Task;
                }
                finally
                {
                    scrollViewer.ViewChanged -= viewChanged;
                }

                selectorItem = (SelectorItem)listViewBase.ContainerFromIndex(index);
            }

            var transform = selectorItem.TransformToVisual((UIElement)scrollViewer.Content);
            var position  = transform.TransformPoint(new Point(0, 0));

            if (isVirtualizing)
            {
                var tcs = new TaskCompletionSource <object>();

                void viewChanged(object s, ScrollViewerViewChangedEventArgs e) => tcs.TrySetResult(null);

                try
                {
                    scrollViewer.ViewChanged += viewChanged;
                    scrollViewer.ChangeView(previousXOffset, previousYOffset, null, true);
                    await tcs.Task;
                }
                finally
                {
                    scrollViewer.ViewChanged -= viewChanged;
                }
            }

            var listViewBaseWidth  = listViewBase.ActualWidth;
            var selectorItemWidth  = selectorItem.ActualWidth;
            var listViewBaseHeight = listViewBase.ActualHeight;
            var selectorItemHeight = selectorItem.ActualHeight;

            previousXOffset = scrollViewer.HorizontalOffset;
            previousYOffset = scrollViewer.VerticalOffset;

            var minXPosition = position.X - listViewBaseWidth + selectorItemWidth;
            var minYPosition = position.Y - listViewBaseHeight + selectorItemHeight;

            var maxXPosition = position.X;
            var maxYPosition = position.Y;

            double finalXPosition, finalYPosition;

            if (!scrollIfVisibile && (previousXOffset <= maxXPosition && previousXOffset >= minXPosition) && (previousYOffset <= maxYPosition && previousYOffset >= minYPosition))
            {
                finalXPosition = previousXOffset;
                finalYPosition = previousYOffset;
            }
            else
            {
                switch (itemPlacement)
                {
                case ItemPlacement.Default:
                    if (previousXOffset <= maxXPosition && previousXOffset >= minXPosition)
                    {
                        finalXPosition = previousXOffset + additionalHorizontalOffset;
                    }
                    else if (Math.Abs(previousXOffset - minXPosition) < Math.Abs(previousXOffset - maxXPosition))
                    {
                        finalXPosition = minXPosition + additionalHorizontalOffset;
                    }
                    else
                    {
                        finalXPosition = maxXPosition + additionalHorizontalOffset;
                    }

                    if (previousYOffset <= maxYPosition && previousYOffset >= minYPosition)
                    {
                        finalYPosition = previousYOffset + additionalVerticalOffset;
                    }
                    else if (Math.Abs(previousYOffset - minYPosition) < Math.Abs(previousYOffset - maxYPosition))
                    {
                        finalYPosition = minYPosition + additionalVerticalOffset;
                    }
                    else
                    {
                        finalYPosition = maxYPosition + additionalVerticalOffset;
                    }

                    break;

                case ItemPlacement.Left:
                    finalXPosition = maxXPosition + additionalHorizontalOffset;
                    finalYPosition = previousYOffset + additionalVerticalOffset;
                    break;

                case ItemPlacement.Top:
                    finalXPosition = previousXOffset + additionalHorizontalOffset;
                    finalYPosition = maxYPosition + additionalVerticalOffset;
                    break;

                case ItemPlacement.Centre:
                    var centreX = (listViewBaseWidth - selectorItemWidth) / 2.0;
                    var centreY = (listViewBaseHeight - selectorItemHeight) / 2.0;
                    finalXPosition = maxXPosition - centreX + additionalHorizontalOffset;
                    finalYPosition = maxYPosition - centreY + additionalVerticalOffset;
                    break;

                case ItemPlacement.Right:
                    finalXPosition = minXPosition + additionalHorizontalOffset;
                    finalYPosition = previousYOffset + additionalVerticalOffset;
                    break;

                case ItemPlacement.Bottom:
                    finalXPosition = previousXOffset + additionalHorizontalOffset;
                    finalYPosition = minYPosition + additionalVerticalOffset;
                    break;

                default:
                    finalXPosition = previousXOffset + additionalHorizontalOffset;
                    finalYPosition = previousYOffset + additionalVerticalOffset;
                    break;
                }
            }

            scrollViewer.ChangeView(finalXPosition, finalYPosition, null, disableAnimation);
        }
Example #12
0
 /// <summary>
 /// Smooth scrolling the list to bring the specified data item into view
 /// </summary>
 /// <param name="listViewBase">List to scroll</param>
 /// <param name="index">The data item to bring into view</param>
 /// <param name="itemPlacement">Set the item placement after scrolling</param>
 /// <param name="disableAnimation">Set true to disable animation</param>
 /// <param name="ScrollIfVisibile">Set true to disable scrolling when the corresponding item is in view</param>
 /// <param name="additionalHorizontalOffset">Adds additional horizontal offset</param>
 /// <param name="additionalVerticalOffset">Adds additional vertical offset</param>
 /// <returns>Note: Even though this return <see cref="Task"/>, it will not wait until the scrolling completes</returns>
 public static async Task SmoothScrollIntoViewWithItem(this Windows.UI.Xaml.Controls.ListViewBase listViewBase, object item, ItemPlacement itemPlacement = ItemPlacement.Default, bool disableAnimation = false, bool scrollIfVisibile = true, int additionalHorizontalOffset = 0, int additionalVerticalOffset = 0)
 {
     await SmoothScrollIntoViewWithIndex(listViewBase, listViewBase.Items.IndexOf(item), itemPlacement, disableAnimation, scrollIfVisibile, additionalHorizontalOffset, additionalVerticalOffset);
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="itemPlacement">
 /// The new item placement setting.
 /// </param>
 public ChangeItemPlacement(ItemPlacement itemPlacement)
 {
     _itemPlacement = itemPlacement;
 }
 /// <summary>
 /// Returns a new change item placement action.
 /// </summary>
 /// <param name="itemPlacement">
 /// The new item placement value.
 /// </param>
 /// <returns>
 /// A new change item placement action.
 /// </returns>
 public IUndoable GetChangeItemPlacement(ItemPlacement itemPlacement)
 {
     return(_changeItemPlacementFactory(itemPlacement));
 }
        private object OnItemPickup(Item item, BasePlayer player)
        {
            if (item != null && player != null)
            {
                ItemPlacement placement = player.GetComponent <ItemPlacement>();
                if (placement != null)
                {
                    return(false);
                }
                else
                {
                    DroppedItem droppedItem = item.GetWorldEntity()?.GetComponent <DroppedItem>();

                    if (droppedItem == null)
                    {
                        return(null);
                    }

                    List <DroppedItem> skulls;

                    if (spearRegisteredSkulls.TryGetValue(droppedItem, out skulls))
                    {
                        if (skulls?.Count == 0)
                        {
                            if (!CanRemove(player, "Error.NoBuildingAuthSpear"))
                            {
                                return(false);
                            }

                            Pool.FreeList(ref skulls);

                            spearRegisteredSkulls.Remove(droppedItem);
                        }
                        else
                        {
                            SendReply(player, msg("Error.SkullsOnSpear", player.userID));
                            return(false);
                        }
                    }

                    if (droppedItem.item.info.itemid == SKULL_ITEM_ID)
                    {
                        Signage signage = droppedItem.GetComponentInParent <Signage>();

                        if (signage != null && signRegisteredSkulls.ContainsKey(signage))
                        {
                            if (!CanRemove(player, "Error.NoBuildingAuthSkull"))
                            {
                                return(false);
                            }

                            signRegisteredSkulls.Remove(signage);

                            if (signage.HasFlag(BaseEntity.Flags.Locked))
                            {
                                signage.SetFlag(BaseEntity.Flags.Locked, false);
                            }

                            UpdateSignImage(signage, "", true);
                        }
                        else
                        {
                            if (droppedItem.HasParent())
                            {
                                DroppedItem spear = droppedItem.GetParentEntity().GetComponent <DroppedItem>();
                                if (spear == null)
                                {
                                    return(null);
                                }

                                if (spearRegisteredSkulls.TryGetValue(spear, out skulls) && skulls.Contains(droppedItem))
                                {
                                    if (!CanRemove(player, "Error.NoBuildingAuthSkull"))
                                    {
                                        return(false);
                                    }

                                    spearRegisteredSkulls[spear].Remove(droppedItem);
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="mode">
 /// The mode settings.
 /// </param>
 /// <param name="itemPlacement">
 /// The new item placement setting.
 /// </param>
 public ChangeItemPlacement(IMode mode, ItemPlacement itemPlacement)
 {
     _mode          = mode;
     _itemPlacement = itemPlacement;
 }
Example #17
0
 /// <summary>
 /// Executes the action.
 /// </summary>
 public void Execute()
 {
     _previousWorldState      = Mode.Instance.WorldState;
     _previousItemPlacement   = Mode.Instance.ItemPlacement;
     Mode.Instance.WorldState = _worldState;
 }
 /// <summary>
 /// Executes the action.
 /// </summary>
 public void Execute()
 {
     _previousItemPlacement      = Mode.Instance.ItemPlacement;
     Mode.Instance.ItemPlacement = _itemPlacement;
 }
Example #19
0
        /// <summary>
        /// Draws the custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            var item = target as Item;

            if (item == null || serializedObject == null)
            {
                return; // How'd this happen?
            }
            base.OnInspectorGUI();

            // Show all of the fields.
            serializedObject.Update();
            EditorGUI.BeginChangeCheck();

            // Allow the user to assign the item if it isn't already assigned
            if (item.transform.parent == null)
            {
                m_AssignTo = EditorGUILayout.ObjectField("Assign To", m_AssignTo, typeof(GameObject), true) as GameObject;
                var enableGUI = m_AssignTo != null && m_AssignTo.GetComponent <Animator>() != null;
                if (enableGUI)
                {
                    if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(m_AssignTo)))
                    {
                        EditorGUILayout.HelpBox("The character must be located within the scene.", MessageType.Error);
                        enableGUI = false;
                    }
                    else
                    {
                        if (m_AssignTo.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.LeftHand) == null)
                        {
                            // The ItemPlacement component must be specified for generic models.
                            m_ItemPlacement = EditorGUILayout.ObjectField("Item Placement", m_ItemPlacement, typeof(ItemPlacement), true) as ItemPlacement;
                            if (m_ItemPlacement == null)
                            {
                                EditorGUILayout.HelpBox("The ItemPlacement GameObject must be specified for Generic models.", MessageType.Error);
                                enableGUI = false;
                            }
                        }
                        else
                        {
                            m_HandAssignment = (HandAssignment)EditorGUILayout.EnumPopup("Hand", m_HandAssignment);
                        }
                    }
                }

                GUI.enabled = enableGUI;
                if (GUILayout.Button("Assign"))
                {
                    Transform itemPlacement = null;
                    if (m_AssignTo.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.LeftHand) == null)
                    {
                        itemPlacement = m_ItemPlacement.transform;
                    }
                    else
                    {
                        var handTransform = m_AssignTo.GetComponent <Animator>().GetBoneTransform(m_HandAssignment == HandAssignment.Left ? HumanBodyBones.LeftHand : HumanBodyBones.RightHand);
                        itemPlacement = handTransform.GetComponentInChildren <ItemPlacement>().transform;
                    }
                    AssignItem(item.gameObject, itemPlacement);
                }
                GUI.enabled = true;
            }

            var itemTypeProperty = PropertyFromName(serializedObject, "m_ItemType");

            EditorGUILayout.PropertyField(itemTypeProperty);
            if (itemTypeProperty.objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("This field is required. The Inventory uses the Item Type to determine the type of item.", MessageType.Error);
            }

            var itemName = PropertyFromName(serializedObject, "m_ItemName");

            EditorGUILayout.PropertyField(itemName);
            if (string.IsNullOrEmpty(itemName.stringValue))
            {
                EditorGUILayout.HelpBox("The Item Name specifies the name of the Animator substate machine. It should not be empty unless you only have one item type.", MessageType.Warning);
            }

            if ((m_CharacterAnimatorFoldout = EditorGUILayout.Foldout(m_CharacterAnimatorFoldout, "Character Animator Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                var canAim = PropertyFromName(serializedObject, "m_CanAim");
                EditorGUILayout.PropertyField(canAim);
                if (canAim.boolValue)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RequireAim"));
                }
                DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_DefaultStates"));
                if (canAim.boolValue)
                {
                    DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_AimStates"));
                }
                if (target is IUseableItem)
                {
                    DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_UseStates"));
                }
                if (target is IReloadableItem)
                {
                    DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_ReloadStates"));
                }
                if (target is MeleeWeapon || target is Shield)
                {
                    DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_RecoilStates"));
                }
                DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_EquipStates"));
                DrawAnimatorStateSet(item, m_ReorderableListMap, m_ReordableLists, OnListSelectInternal, OnListAddInternal, OnListRemoveInternal, PropertyFromName(serializedObject, "m_UnequipStates"));
                EditorGUI.indentLevel--;
            }

            if ((m_UIFoldout = EditorGUILayout.Foldout(m_UIFoldout, "UI Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ItemSprite"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RightItemSprite"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CrosshairsSprite"), true);
                EditorGUI.indentLevel--;
            }

            if ((m_InputFoldout = EditorGUILayout.Foldout(m_InputFoldout, "Input Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                if (item is IUseableItem)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_UseInputName"));
                    if (serializedObject.FindProperty("m_DualWieldUseInputName") != null)
                    {
                        EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DualWieldUseInputName"));
                    }
                }
                if (item is IReloadableItem)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ReloadInputName"));
                }
                if (item is IFlashlightUseable)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ToggleFlashlightInputName"));
                }
                if (item is ILaserSightUseable)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ToggleLaserSightInputName"));
                }
                EditorGUI.indentLevel--;
            }

            if ((m_GeneralFoldout = EditorGUILayout.Foldout(m_GeneralFoldout, "General Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_TwoHandedItem"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_NonDominantHandPosition"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_HolsterTarget"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ItemPickup"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AimCameraState"));
                EditorGUI.indentLevel--;
            }

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(item, "Inspector");
                serializedObject.ApplyModifiedProperties();
                InspectorUtility.SetObjectDirty(item);
            }
        }
 /// <summary>
 /// Executes the action.
 /// </summary>
 public void ExecuteDo()
 {
     _previousWorldState    = _mode.WorldState;
     _previousItemPlacement = _mode.ItemPlacement;
     _mode.WorldState       = _worldState;
 }
Example #21
0
        public static void RunStats(MT19337 rng,
                                    IItemPlacementFlags flags,
                                    IncentiveData incentivesData,
                                    ItemShopSlot caravanItemLocation,
                                    OverworldMap overworldMap)
        {
            Dictionary <MapLocation, Tuple <List <MapChange>, AccessRequirement> > fullLocationRequirements = overworldMap.FullLocationRequirements;
            var placedItems  = new List <IRewardSource>();
            var treasurePool = ItemLocations.AllTreasures.Where(x => !x.IsUnused).Select(x => x.Item)
                               .Concat(ItemLists.AllNonTreasureChestItems).ToList();
            var requirementChecks = ItemLists.AllQuestItems.ToDictionary(x => x, x => 0);

            requirementChecks[Item.Ribbon] = 0;
            var requirementsToCheck = new List <Item> {
                Item.Crown, Item.Crystal, Item.Herb, Item.Tnt,
                Item.Adamant, Item.Slab, Item.Ruby, Item.Bottle,
                Item.Floater, Item.Ship, Item.Bridge, Item.Canal
            };
            const int maxIterations      = 255;
            var       forcedIceCount     = 0;
            var       itemPlacementStats = ItemLists.AllQuestItems.ToDictionary(x => x, x => new List <int>());

            itemPlacementStats[Item.Ribbon] = new List <int>();
            var itemPlacementZones = ItemLists.AllQuestItems.ToDictionary(x => x, x => new List <string>());

            itemPlacementZones[Item.Ribbon] = new List <string>();
            long iterations  = 0;
            var  timeElapsed = new Stopwatch();

            while (iterations < maxIterations)
            {
                iterations++;
                // When Enemy Status Shuffle is turned on Coneria is reduced to 11% chance with other shops spliting the remaining 89%
                var shopTownSelected = ItemShops.PickRandom(rng);
                var itemShopItem     = new ItemShopSlot(ItemLocations.CaravanItemShop1.Address,
                                                        $"{Enum.GetName(typeof(MapLocation), shopTownSelected)}Shop",
                                                        shopTownSelected,
                                                        Item.Bottle);
                timeElapsed.Start();
                placedItems = ItemPlacement.PlaceSaneItems(rng,
                                                           flags,
                                                           incentivesData,
                                                           treasurePool,
                                                           itemShopItem,
                                                           overworldMap);
                timeElapsed.Stop();

                var outputIndexes = placedItems.ToLookup(x => x.Item, x => x);
                foreach (Item item in itemPlacementStats.Keys)
                {
                    itemPlacementStats[item].AddRange(outputIndexes[item].Select(x => x.Address).ToList());
                }
                var outputZones =
                    placedItems
                    .ToLookup(x => x.Item,
                              x => Enum.GetName(typeof(MapLocation), x.MapLocation));
                foreach (Item item in itemPlacementZones.Keys)
                {
                    if (!outputZones[item].Any())
                    {
                        continue;
                    }
                    itemPlacementZones[item].AddRange(outputZones[item]);
                }
                var matoyaShip     = placedItems.Any(x => x.Address == ItemLocations.Matoya.Address && x.Item == Item.Ship);
                var crystalIceCave = placedItems.Any(x => x.Item == Item.Crystal &&
                                                     x.Address >= ItemLocations.IceCave1.Address &&
                                                     x.Address <= ItemLocations.IceCaveMajor.Address);
                var keyIceCave = placedItems.Any(x => x.Item == Item.Key &&
                                                 x.Address >= ItemLocations.IceCave1.Address &&
                                                 x.Address <= ItemLocations.IceCaveMajor.Address);
                var keyLockedCrystal = placedItems.Any(x => x.Item == Item.Crystal &&
                                                       x.AccessRequirement.HasFlag(AccessRequirement.Key));
                var keyLockedShip = placedItems.Any(x => x.Item == Item.Ship &&
                                                    x.AccessRequirement.HasFlag(AccessRequirement.Key));
                if ((keyLockedShip && keyIceCave) ||
                    (matoyaShip && crystalIceCave) ||
                    (matoyaShip && keyLockedCrystal && keyIceCave))
                {
                    forcedIceCount++;
                }

                foreach (Item item in requirementsToCheck)
                {
                    if (!ItemPlacement.CheckSanity(placedItems.Where(x => x.Item != item).ToList(), fullLocationRequirements, new Flags {
                        OnlyRequireGameIsBeatable = true
                    }))
                    {
                        requirementChecks[item]++;
                    }
                }
            }

            if (iterations > 10)
            {
                Debug.WriteLine(PrintStats(maxIterations, itemPlacementStats, itemPlacementZones, requirementChecks));
                Debug.WriteLine($"Forced Early Ice Cave for Ship: {forcedIceCount} out of {maxIterations}");
                Debug.WriteLine($"Time per iteration: {1.0 * timeElapsed.ElapsedMilliseconds / iterations}");
            }
        }
Example #22
0
        /// <summary>
        /// Shows the initial Item options.
        /// </summary>
        private bool ShowIntroGUI()
        {
            var canContinue = true;

            m_ItemType = EditorGUILayout.ObjectField("Item Type", m_ItemType, typeof(ItemType), false) as ItemType;
            if (canContinue && m_ItemType == null)
            {
                EditorGUILayout.HelpBox("This field is required. The Inventory uses the Item Type to determine the type of weapon ", MessageType.Error);
                canContinue = false;
            }

            m_Base = EditorGUILayout.ObjectField("Base", m_Base, typeof(GameObject), true) as GameObject;
            if (canContinue && m_Base == null)
            {
                EditorGUILayout.HelpBox("This field is required. If the item uses a model then that model should be the base object. If an item does not use a model (such as a grenade), " +
                                        "then an empty GameObject can be used.", MessageType.Error);
                canContinue = false;
            }
            else if (canContinue && PrefabUtility.GetPrefabType(m_Base) == PrefabType.Prefab)
            {
                EditorGUILayout.HelpBox("Please drag your item into the scene. The Item Builder cannot add components to prefabs.",
                                        MessageType.Error);
                canContinue = false;
            }

            m_ItemName = EditorGUILayout.TextField("Item Name", m_ItemName);
            if (string.IsNullOrEmpty(m_ItemName))
            {
                EditorGUILayout.HelpBox("The Item Name specifies the name of the Animator substate machine. It should not be empty unless you only have one item type.", MessageType.Warning);
            }

            m_AssignTo = EditorGUILayout.ObjectField("Assign To", m_AssignTo, typeof(GameObject), true) as GameObject;
            if (m_AssignTo == null)
            {
                EditorGUILayout.HelpBox("When the Item is built it can be assigned to an existing character. If this value is not specified the Item can be later assigned.", MessageType.Info);
            }
            else
            {
                if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(m_AssignTo)))
                {
                    EditorGUILayout.HelpBox("The character must be located within the scene.", MessageType.Error);
                    canContinue = false;
                }
                else
                {
                    EditorGUI.indentLevel++;
                    if (m_AssignTo.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.LeftHand) == null)
                    {
                        // The ItemPlacement component must be specified for generic models.
                        m_ItemPlacement = EditorGUILayout.ObjectField("Item Placement", m_ItemPlacement, typeof(ItemPlacement), true) as ItemPlacement;
                        if (m_ItemPlacement == null)
                        {
                            EditorGUILayout.HelpBox("The ItemPlacement GameObject must be specified for Generic models.", MessageType.Error);
                            canContinue = false;
                        }
                    }
                    else
                    {
                        m_HandAssignment = (ThirdPersonController.ItemBuilder.HandAssignment)EditorGUILayout.EnumPopup("Hand", m_HandAssignment);
                    }
                    m_AddToDefaultLoadout = EditorGUILayout.Toggle("Add to Default Loadout", m_AddToDefaultLoadout);
                    EditorGUI.indentLevel--;
                }
            }
            m_Type = (ThirdPersonController.ItemBuilder.ItemTypes)EditorGUILayout.EnumPopup("Type", m_Type);

            return(canContinue);
        }
 /// <summary>
 /// Executes the action.
 /// </summary>
 public void ExecuteDo()
 {
     _previousItemPlacement = _mode.ItemPlacement;
     _mode.ItemPlacement    = _itemPlacement;
 }
Example #24
0
 internal void AddItem(ItemPlacement placement, Item item)
 {
     switch (placement)
     {
         case ItemPlacement.PlayerBracers: Bracers = item; break;
         case ItemPlacement.PlayerFeet: Feet = item; break;
         case ItemPlacement.PlayerHands: Hands = item; break;
         case ItemPlacement.PlayerHead: Head = item; break;
         case ItemPlacement.PlayerLeftFinger: LeftFinger = item; break;
         case ItemPlacement.PlayerLeftHand: LeftHand = item; break;
         case ItemPlacement.PlayerLegs: Legs = item; break;
         case ItemPlacement.PlayerNeck: Neck = item; break;
         case ItemPlacement.PlayerRightFinger: RightFinger = item; break;
         case ItemPlacement.PlayerRightHand: RightHand = item; break;
         case ItemPlacement.PlayerShoulders: Shoulders = item; break;
         case ItemPlacement.PlayerTorso: Torso = item; break;
         case ItemPlacement.PlayerWaist: Waist = item; break;
         default:
             throw new Exception("Unrecognized attachment position " + placement);
     }
 }
Example #25
0
        public static void RunStats(MT19337 rng, ITreasureShuffleFlags flags, IncentiveData incentivesData)
        {
            var forcedItems = ItemLocations.AllOtherItemLocations.ToList();

            if (!flags.NPCItems)
            {
                forcedItems = ItemLocations.AllNonTreasureItemLocations.ToList();
            }

            var placedItems       = new List <IRewardSource>();
            var treasurePool      = ItemLocations.AllTreasures.Where(x => !x.IsUnused).Select(x => x.Item).ToList();
            var requirementChecks = ItemLists.AllQuestItems.ToDictionary(x => x, x => 0);

            requirementChecks[Item.Ribbon] = 0;
            var requirementsToCheck = new List <Item> {
                Item.Crown, Item.Crystal, Item.Herb, Item.Tnt,
                Item.Adamant, Item.Slab, Item.Ruby, Item.Bottle, Item.Canal
            };
            const int maxIterations      = 10000;
            var       forcedIceCount     = 0;
            var       itemPlacementStats = ItemLists.AllQuestItems.ToDictionary(x => x, x => new List <int>());

            itemPlacementStats[Item.Ribbon] = new List <int>();
            var itemPlacementZones = ItemLists.AllQuestItems.ToDictionary(x => x, x => new List <string>());

            itemPlacementZones[Item.Ribbon] = new List <string>();
            var  mapLocationRequirements = ItemLocations.MapLocationRequirements.ToDictionary(x => x.Key, x => x.Value.ToList());
            long iterations = 0;

            while (iterations < maxIterations)
            {
                iterations++;
                // When Enemy Status Shuffle is turned on Coneria is reduced to 11% chance with other shops spliting the remaining 89%
                var shopTownSelected = ItemShops.PickRandom(rng);
                var itemShopItem     = new ItemShopSlot(ItemLocations.CaravanItemShop1.Address,
                                                        $"{Enum.GetName(typeof(MapLocation), shopTownSelected)}Shop",
                                                        shopTownSelected,
                                                        Item.Bottle);
                placedItems = ItemPlacement.PlaceSaneItems(rng,
                                                           flags,
                                                           incentivesData,
                                                           treasurePool,
                                                           itemShopItem,
                                                           mapLocationRequirements);

                var outputIndexes = placedItems.ToLookup(x => x.Item, x => x);
                foreach (Item item in itemPlacementStats.Keys)
                {
                    itemPlacementStats[item].AddRange(outputIndexes[item].Select(x => x.Address).ToList());
                }
                var outputZones =
                    placedItems
                    .ToLookup(x => x.Item,
                              x => Enum.GetName(typeof(MapLocation), x.MapLocation));
                foreach (Item item in itemPlacementZones.Keys)
                {
                    if (!outputZones[item].Any())
                    {
                        continue;
                    }
                    itemPlacementZones[item].AddRange(outputZones[item]);
                }
                var matoyaShip     = placedItems.Any(x => x.Address == ItemLocations.Matoya.Address && x.Item == Item.Ship);
                var crystalIceCave = placedItems.Any(x => x.Item == Item.Crystal &&
                                                     x.Address >= ItemLocations.IceCave1.Address &&
                                                     x.Address <= ItemLocations.IceCaveMajor.Address);
                var keyIceCave = placedItems.Any(x => x.Item == Item.Key &&
                                                 x.Address >= ItemLocations.IceCave1.Address &&
                                                 x.Address <= ItemLocations.IceCaveMajor.Address);
                var keyLockedCrystal = placedItems.Any(x => x.Item == Item.Crystal &&
                                                       x.AccessRequirement.HasFlag(AccessRequirement.Key));
                var keyLockedShip = placedItems.Any(x => x.Item == Item.Ship &&
                                                    x.AccessRequirement.HasFlag(AccessRequirement.Key));
                if ((keyLockedShip && keyIceCave) ||
                    (matoyaShip && crystalIceCave) ||
                    (matoyaShip && keyLockedCrystal && keyIceCave))
                {
                    forcedIceCount++;
                }

                foreach (Item item in requirementsToCheck)
                {
                    if (!ItemPlacement.CheckSanity(placedItems.Where(x => x.Item != item).ToList(), flags, mapLocationRequirements))
                    {
                        requirementChecks[item]++;
                    }
                }
            }

            if (iterations > 10)
            {
                Debug.WriteLine(PrintStats(maxIterations, itemPlacementStats, itemPlacementZones, requirementChecks));
                Debug.WriteLine($"Forced Early Ice Cave for Ship: {forcedIceCount} out of {maxIterations}");
            }
        }
Example #26
0
        public override void FillPage(PrintPageEventArgs e, System.Collections.ArrayList items, System.Collections.ArrayList coords)
        {
            // Getting page parameters, filling queue of elements for placement
            InitializePage(e);
            int i, itemCount = FillQueue(e);

            if (itemCount == 0)
            {
                return;
            }

            // Preparing stack
            SearchStackFrame[] stack = new SearchStackFrame[_queuedItems.Count + 1];
            for (i = 0; i < stack.Length; i++)
            {
                stack[i] = new SearchStackFrame();
            }

            // Adding fake rectangle with first position
            ItemRectangle fakeRect = new ItemRectangle();

            fakeRect.Location = new Point(-100000, -100000);
            fakeRect.HostedPositions.Add(new Position(_pageLeft, _pageTop));
            stack[0].PlacedRectangles.Add(fakeRect);

            // Go! - there we will emulate recursion in plain loop. Deep is restricted by s_intMaxBranchingDepth,
            // after this level - just going straight forward without recursive search.
            ItemPlacement[] bestPlacement = new ItemPlacement[_queuedItems.Count];       // best reached result
            ArrayList       positions     = new ArrayList(256);                          // search positions for current level

            int bestSquare      = -1,
                framePointer    = 0,
                placedItemCount = 0;

            while (true)
            {
                // if the dip is over
                if (framePointer < 0)
                {
                    break;
                }

                // extracting and cleaning current level of the stack
                SearchStackFrame stackFrame = stack[framePointer];
                if (stackFrame.Item != null)
                {
                    stackFrame.Item.Locked = false;
                    stackFrame.Item        = null;
                }
                stackFrame.ActualQueueIndex = stackFrame.InitialQueueIndex;

                // searching at this level
                if (stackFrame.ProcessState < 2)
                {
                    positions.Clear();
                    foreach (ItemRectangle tmp1 in stackFrame.PlacedRectangles)
                    {
                        foreach (Position tmp2 in tmp1.HostedPositions)
                        {
                            tmp2.Close(framePointer, false);
                            if (!tmp2.Closed(framePointer))
                            {
                                positions.Add(tmp2);
                            }
                        }
                    }

                    bool placed = false;
                    while (!placed)
                    {
                        int maxCoverage = -1;
                        int coverage;

                        Position resPosition;

                        stackFrame.Item = GetQueuedItemAt(ref stackFrame.ActualQueueIndex);
                        if (stackFrame.Item == null)
                        {
                            break;
                        }

                        // Original item orientation
                        stackFrame.Rotate = stackFrame.Item.Rotated = (stackFrame.ProcessState == 1);
                        for (i = 0; i < positions.Count; i++)
                        {
                            Position position = (Position)positions[i];
                            if (TryToPlaceRectangle(framePointer, stackFrame.PlacedRectangles, position, stackFrame.Item, out coverage, out resPosition) && coverage > maxCoverage)
                            {
                                stackFrame.ItemPosition = resPosition;
                                maxCoverage             = coverage;
                                placed = true;
                            }
                        }

                        // Rotated orientation (performed if we cannot use full-search on current level)
                        if (_printOptions.PlaceholderAutoRotate && framePointer > MaxBranchingDeep)
                        {
                            stackFrame.Item.Rotated = true;
                            for (i = 0; i < positions.Count; i++)
                            {
                                Position position = (Position)positions[i];
                                if (position.Closed(framePointer))
                                {
                                    continue;
                                }

                                if (TryToPlaceRectangle(framePointer, stackFrame.PlacedRectangles, position, stackFrame.Item, out coverage, out resPosition) && coverage > maxCoverage)
                                {
                                    stackFrame.ItemPosition = resPosition;
                                    maxCoverage             = coverage;
                                    stackFrame.Rotate       = true;
                                    placed = true;
                                }
                            }
                        }

                        if (placed)
                        {
                            // Goto next level
                            if (framePointer <= MaxBranchingDeep && _printOptions.PlaceholderAutoRotate)
                            {
                                stackFrame.ProcessState++;
                            }
                            else
                            {
                                stackFrame.ProcessState = 2;
                            }

                            int nextFrame = framePointer + 1;
                            stack[nextFrame].ProcessState      = 0;
                            stack[nextFrame].Item              = null;
                            stack[nextFrame].Coverage          = stackFrame.Coverage + maxCoverage;
                            stack[nextFrame].Square            = stackFrame.Square + stackFrame.Item.Square;
                            stack[nextFrame].InitialQueueIndex = stackFrame.ActualQueueIndex + 1;
                            stack[nextFrame].PlacedRectangles.AddRange(stackFrame.PlacedRectangles);

                            stackFrame.Item.Rotated = stackFrame.Rotate;
                            PlaceRectangle(framePointer, stackFrame.ItemPosition, stackFrame.Item, stack[nextFrame].PlacedRectangles);
                            stackFrame.Item.Neighbours.Clear();

                            framePointer++;
                        }
                        else
                        {
                            stackFrame.Item.Locked = false;
                            stackFrame.Item        = null;
                            stackFrame.ActualQueueIndex++;
                        }
                    }

                    if (!placed)
                    {
                        if (stackFrame.Square > bestSquare)
                        {
                            placedItemCount = framePointer;
                            bestSquare      = stackFrame.Square;

                            for (i = 0; i < framePointer; i++)
                            {
                                bestPlacement[i].QueueIndex   = stack[i].ActualQueueIndex;
                                bestPlacement[i].ItemPosition = stack[i].ItemPosition;
                                bestPlacement[i].Rotate       = stack[i].Rotate;
                                bestPlacement[i].Item         = stack[i].Item;
                            }
                        }

                        framePointer--;
                    }
                }
                else
                {
                    framePointer--;
                }
            }

            // Returning best result to caller
            if (bestSquare > 0)
            {
                for (i = 0; i < placedItemCount; i++)
                {
                    ItemPlacement element = bestPlacement[i];

                    GetQueuedItemAt(ref element.QueueIndex);
                    element.Item.Rotated = element.Rotate;

                    coords.Add(ItemRectangle.GetItemLeftTopCorner(element.ItemPosition));
                    items.Add(element.Item.Detach());
                }
            }

            FlushQueueNonPlaced();
            e.HasMorePages = HasMorePages();
        }