示例#1
0
        public void Equip(NewItem itm, Inventory inv)
        {
            int firstEquip         = -1;
            int firstFreeEquip     = -1;
            GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>();

            //Look for thew first open slot and unequip all future slots
            for (int i = 0; i < attr.PossibleSlots.Length; i++)
            {
                if (attr.PossibleSlots[i])
                {
                    if (firstEquip == -1)
                    {
                        firstEquip = i;
                    }
                    if (items[i] == null && firstFreeEquip == -1)
                    {
                        firstFreeEquip = i;
                    }
                }
            }

            int slot = firstFreeEquip == -1 ? firstEquip : firstFreeEquip;

            Equip(itm, slot, inv);
        }
示例#2
0
        void Paste(object obj)
        {
            int               i    = (int)obj;
            NewItem           itm  = ItemEditor.CopiedItem;
            GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>();

            if (attr == null)
            {
                Debug.LogWarning("This Item lack GearSlot Attribute and cannot be added to the Gear slot");
            }
            else
            {
                WeaponAttribute weaponAttr   = itm.GetAttribute <WeaponAttribute>();
                bool            weaponCancel = false;
                if (weaponAttr)
                {
                    if (!stats.CanEquipWeapons.Contains((int)weaponAttr.WeaponType))
                    {
                        weaponCancel = true;
                    }
                }
                //Add to a slot
                if (attr.PossibleSlots[i] && !weaponCancel)
                {
                    Undo.RecordObject(UndoObj, "Modify Stats");
                    stats.Gear.Equip(itm, i, null);
                }
                else
                {
                    Debug.LogWarning("This items GearSlot attribute does not allow this slot!");
                }
            }
            RefreshDictionary();
        }
示例#3
0
        private void OpenMiniMenuStats(IntMessage msg)
        {
            NewItem itm = gear.items[msg.i];

            if (itm)
            {
                onCancelActions.Remove(DropDownMenu.Hide);
                onCancelActions.Add(DropDownMenu.Hide);

                ButtonArgument Argument = new ButtonArgument("Unequip");
                Argument.onClickCallback.Add(() => DropDownMenu.Hide());
                Argument.onClickCallback.Add(() => gear.Unequip(msg.i, inventory));
                Argument.onClickCallback.Add(() => GenerateUI());
                Argument.onClickCallback.Add(() => UpdateStatLabels());

                DropDownMenu.Initialize(new List <ButtonArgument>()
                {
                    Argument
                }, null);
            }
            else
            {
                Debug.Log("No Item : " + msg.i.ToString());
            }
        }
示例#4
0
        private void OpenMiniMenuInventory(NewItem itm)
        {
            List <ButtonArgument> buttonArguments = new List <ButtonArgument>();

            onCancelActions.Remove(DropDownMenu.Hide);
            onCancelActions.Add(DropDownMenu.Hide);
            if (itm.GetAttribute <UseAttribute>() != null)
            {
                ButtonArgument UseArgument = new ButtonArgument("Use");


                UseArgument.onClickCallback.Add(() => DropDownMenu.Hide());
                UseArgument.onClickCallback.Add(() => itm.GetAttribute <UseAttribute>().Use(TurnManager.currentCharacter));

                if (itm.GetAttribute <UseAttribute>().destoryOnUse)
                {
                    UseArgument.onClickCallback.Add(() => inventory.DepleteItem(itm));
                }

                UseArgument.onClickCallback.Add(() => GenerateUI());
                UseArgument.onClickCallback.Add(() => UpdateStatLabels());


                buttonArguments.Add(UseArgument);
            }

            if (itm.GetAttribute <GearSlotAttribute>() != null)
            {
                ButtonArgument GearArgument = new ButtonArgument("Equip");

                WeaponAttribute weaponAttr = itm.GetAttribute <WeaponAttribute>();
                if (weaponAttr)
                {
                    GearArgument.Interactable = TurnManager.currentCharacter.stats.CanEquipWeapons.Contains((int)weaponAttr.WeaponType) ? true : false;
                }

                GearArgument.onClickCallback.Add(() => DropDownMenu.Hide());
                GearArgument.onClickCallback.Add(() => gear.Equip(itm, inventory));
                GearArgument.onClickCallback.Add(() => UpdateStatLabels());
                GearArgument.onClickCallback.Add(() => GenerateUI());

                buttonArguments.Add(GearArgument);
            }


            ButtonArgument DropArgument = new ButtonArgument("Drop");

            DropArgument.onClickCallback.Add(() => DropDownMenu.Hide());
            DropArgument.onClickCallback.Add(() => inventory.DepleteItem(itm));
            DropArgument.onClickCallback.Add(() => GenerateUI());

            buttonArguments.Add(DropArgument);


            DropDownMenu.Initialize(buttonArguments, null);
        }
示例#5
0
        public static void CreateAttribute(object attribute, NewItem itm)
        {
            var newAttribute = CreateInstance((System.Type)attribute) as ItemAttribute;

            newAttribute.hideFlags = HideFlags.HideInHierarchy;
            AssetDatabase.AddObjectToAsset(newAttribute, itm);
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newAttribute));

            (itm).Add(newAttribute);
        }
示例#6
0
        private void GenerateUI()
        {
            DestroyChildren(buttonContainer.transform);

            int _i = 0;

            for (int i = 0; i < inventory.Items.Count; i++)
            {
                _i = i;
                Inventory_ItemList_Button btn       = GameObject.Instantiate <Inventory_ItemList_Button>(InventorybuttonPrefab);
                RectTransform             transform = btn.GetComponent <RectTransform>();
                btn.transform.SetParent(buttonContainer.transform, false);
                btn.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
                btn.onClick.RemoveAllListeners();

                ButtonArgument equipArgument = new ButtonArgument("Equip");
                NewItem        itm           = inventory.Items[_i].item;
                equipArgument.onClickCallback.Add(() => OpenMiniMenuInventory(itm));
                btn.SetData(inventory.Items[_i], equipArgument);
            }


            for (int q = 0; q < gear.items.Length; q++)
            {
                int _q = q;
                gearInfo.buttons[q].onClick.RemoveAllListeners();
                if (gear.items[q])
                {
                    gearInfo.buttons[q].interactable = true;
                    ButtonArgument unequipArgument = new ButtonArgument("Unequip");
                    unequipArgument.onClickCallback.Add(() => OpenMiniMenuStats(new IntMessage(_q)));
                    NewItem itm = gear.items[q];

                    gearInfo.buttons[q].SetData(itm, unequipArgument);
                }
                else
                {
                    gearInfo.buttons[q].Clear();
                    gearInfo.buttons[q].interactable = false;

                    if (gear.Names[q])
                    {
                        if (gear.Names[q].GetAttribute <CommonAttributes>())
                        {
                            gearInfo.buttons[q].InventorySprite.sprite = gear.Names[q].GetAttribute <CommonAttributes>().GetSprite();
                        }
                    }
                    else
                    {
                        gearInfo.buttons[q].InventorySprite.sprite = null;
                    }
                }
            }
        }
示例#7
0
        public void Equip(NewItem itm, int slot, Inventory inv)
        {
            GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>();

            if (attr)
            {
                //Unequip item slots
                for (int i = 0; i < attr.UnequipLots.Length; i++)
                {
                    if (attr.UnequipLots[i])
                    {
                        if (gear[i])
                        {
                            Unequip(i, inv);
                        }
                    }
                }
            }

            //Unequip item that is currently in the slot
            if (gear[slot])
            {
                NewItem           lastItem = gear[slot];
                GearSlotAttribute attrLast = lastItem.GetAttribute <GearSlotAttribute>();
                for (int q = 0; q < attrLast.UnequipLots.Length; q++)
                {
                    if (attr.UnequipLots[q])
                    {
                        gear[q]      = null;
                        gearNames[q] = null;
                    }
                }

                gear[slot] = null;
            }

            gear[slot] = itm;

            //Fill other slots
            for (int i = 0; i < attr.UnequipLots.Length; i++)
            {
                if (attr.UnequipLots[i])
                {
                    gearNames[i] = itm;
                }
            }

            if (Application.isPlaying && inv != null)
            {
                inv.DepleteItem(itm);
            }
        }
示例#8
0
        public void DepleteItem(NewItem itm)
        {
            int index = Items.FindIndex(a => a.item == itm);

            if (index != -1)
            {
                items[index].amount--;
            }
            if (items[index].amount <= 0)
            {
                items.RemoveAt(index);
            }
        }
示例#9
0
        public void AddItem(NewItem i)
        {
            int index = Items.FindIndex(a => a.item == i);

            if (index == -1)
            {
                Items.Add(new ItemStack(i));
                valueOverrides.Add(i.Value);
            }

            else
            {
                Items[index].amount++;
            }
        }
示例#10
0
        public void SetData(NewItem stack, ButtonArgument arg = null)
        {
            this.stack = stack;
            onPointerEvent.RemoveAllListeners();
            CommonAttributes atr = stack.GetAttribute <CommonAttributes>();

            if (atr)
            {
                this.image.sprite = atr.GetSprite();
            }


            if (arg != null)
            {
                foreach (UnityAction argument in arg.onClickCallback)
                {
                    onPointerEvent.AddListener(argument);
                }
            }
        }
示例#11
0
        public void BuildUI(NewItem item)
        {
            DestroyChildren();
            if (item == null)
            {
                return;
            }
            if (GearHelper)
            {
                GearHelper.SetActive(false);
            }
            NameField.text       = item.GameName;
            ValueField.text      = item.Value.ToString();
            coinSprite.enabled   = true;
            SpriteField.sprite   = item.Sprite;
            SpriteField.enabled  = true;
            DecriptionField.text = item.Description;
            HorizontalLayoutGroup g = BuildLine(Content.gameObject, 5);

            if (item.GetAttribute <WeaponAttribute>())
            {
                BuildWeaponUI(Content.gameObject, item.GetAttribute <WeaponAttribute>());
                g = BuildLine(Content.gameObject, 5);
            }
            if (item.GetAttribute <StatsAttribute>())
            {
                BuildStatAttributeUI(Content.gameObject, item.GetAttribute <StatsAttribute>());
            }
            if (item.GetAttribute <GearSlotAttribute>())
            {
                BuildArmorSlotAttributeUI(Content.gameObject, item.GetAttribute <GearSlotAttribute>());
            }
            if (item.GetAttribute <UseAttribute>())
            {
                UseAttribute atr = item.GetAttribute <UseAttribute>();
                if (atr.GetType() == typeof(Use_RecoverAttribute))
                {
                    BuildRecoveryItemUI(Content.gameObject, atr as Use_RecoverAttribute);
                }
            }
        }
示例#12
0
        public static NewItem CreateItemWithAttributes(ItemDatabase database, object arributeArray)
        {
            var Item = NewItem.CreateInstance <NewItem>();

            Item.hideFlags = HideFlags.HideInHierarchy;
            AssetDatabase.AddObjectToAsset(Item, database);
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(Item));


            object[] arr = arributeArray as object[];
            foreach (object obj in arr)
            {
                CreateAttribute(obj, Item);
            }
            database.AddItem(Item);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            return(Item);
        }
示例#13
0
        private void CacheEditors()
        {
            if (target == null)
            {
                return;
            }


            foreach (var editor in cachedEditors.Values)
            {
                Editor.DestroyImmediate(editor);
            }

            cachedEditors.Clear();
            NewItem _target = (NewItem)target;

            for (int i = 0; i < ((NewItem)target).attributes.Count; i++)
            {
                cachedEditors.Add(_target.attributes[i], AttributeEditor.CreateEditor(_target.attributes[i]) as AttributeEditor);
            }
        }
示例#14
0
        public void AddItem(NewItem itm)
        {
            CommonAttributes attr = itm.GetAttribute <CommonAttributes>();

            if (attr && attr.isStackable)
            {
                int index = Items.FindIndex(a => a.item == itm);
                if (index != -1)
                {
                    items[index].amount++;
                }
                if (items[index].amount <= 0)
                {
                    items.Add(new ItemStack(itm));
                }
            }
            else
            {
                items.Add(new ItemStack(itm));
            }
        }
示例#15
0
        public void Unequip(int slot, Inventory inv)
        {
            NewItem           lastItem = items[slot];
            GearSlotAttribute attrLast = lastItem.GetAttribute <GearSlotAttribute>();

            for (int q = 0; q < attrLast.UnequipLots.Length; q++)
            {
                if (attrLast.UnequipLots[q])
                {
                    gearNames[q] = null;
                }
            }

            if (Application.isPlaying && inv != null)
            {
                inv.AddItem(lastItem);
            }


            gear[slot] = null;
        }
示例#16
0
 public ItemStack(NewItem itm)
 {
     item   = itm;
     amount = 1;
 }
示例#17
0
        public override void OnInspectorGUI()
        {
            NewItem _target = (NewItem)target;

            if (target == null)
            {
                return;
            }

            EditorGUILayout.VerticalScope v = new EditorGUILayout.VerticalScope();
            using (v)
            {
                EditorGUI.BeginChangeCheck();
                string name = EditorGUILayout.TextField("Editor name", _target.ItemName);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RegisterCompleteObjectUndo(_target, "Modify Item");
                    _target.ItemName = name;
                    EditorTools.ItemDatabase.RefreshDictionary();
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Attributes", EditorStyles.boldLabel);
                if (GUILayout.Button("+", GUILayout.Width(20)))
                {
                    GenericMenu CreateMenu = new GenericMenu();

                    CreateMenu.AddItem(new GUIContent("Generic"), false, MenuItemCreateAttribute, new object[] { typeof(CommonAttributes) });
                    CreateMenu.AddItem(new GUIContent("Weapons/Stats Attribute"), false, MenuItemCreateAttribute, new object[] { typeof(StatsAttribute) });
                    CreateMenu.AddItem(new GUIContent("Weapons/Weapon Attribute"), false, MenuItemCreateAttribute, new object[] { typeof(WeaponAttribute) });
                    CreateMenu.AddItem(new GUIContent("Weapons/Slot Attribute"), false, MenuItemCreateAttribute, new object[] { typeof(GearSlotAttribute) });
                    CreateMenu.AddItem(new GUIContent("Potion/Recover"), false, MenuItemCreateAttribute, new object[] { typeof(Use_RecoverAttribute) });


                    CreateMenu.ShowAsContext();
                }
                EditorGUILayout.EndHorizontal();

                for (int i = 0; i < _target.attributes.Count; i++)
                {
                    if (!cachedEditors.ContainsKey(_target.attributes[i]))
                    {
                        CacheEditors();
                    }
                }
                EditorGUI.indentLevel++;
                int deleteIndex = -1;
                for (int i = 0; i < _target.attributes.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    cachedEditors[_target.attributes[i]].OnInspectorGUI();

                    EditorGUI.BeginDisabledGroup(!cachedEditors[_target.attributes[i]].CanDelete() && !Debug);
                    if (GUILayout.Button("X", GUILayout.Width(20)))
                    {
                        deleteIndex = i;
                    }
                    EditorGUI.EndDisabledGroup();
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUI.indentLevel--;
                if (deleteIndex != -1)
                {
                    cachedEditors.Remove(_target.attributes[deleteIndex]);
                    _target.Destroy(_target.attributes[deleteIndex]);
                }
            }
            Event e = Event.current;

            if (e.isMouse && e.button == 1 && v.rect.Contains(e.mousePosition))
            {
                GenericMenu CreateMenu = new GenericMenu();
                CreateMenu.AddItem(new GUIContent("Debug Mode"), Debug, ToggleDebug);
                CreateMenu.AddItem(new GUIContent("Copy"), false, Copy, _target);
                CreateMenu.ShowAsContext();
            }
        }
示例#18
0
 private void OpenMiniGear(NewItem itm, int slot)
 {
 }
示例#19
0
 public void Destroy(NewItem itm)
 {
     items.Remove(itm);
     GameObject.DestroyImmediate(itm, true);
     RefreshDictionary();
 }
示例#20
0
 public void Clear()
 {
     stack = null;
 }
示例#21
0
        public void OnGUI()
        {
            if (stats == null || UndoObj == null)
            {
                return;
            }
            EditorGUI.BeginChangeCheck();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Base stats");
            float baseHP    = (int)EditorGUILayout.FloatField("HP", stats.BaseHP);
            float baseMP    = (int)EditorGUILayout.FloatField("MP", stats.BaseMP);
            float baseAtt   = (int)EditorGUILayout.FloatField("Attack", stats.BaseAttack);
            float baseDef   = (int)EditorGUILayout.FloatField("Defence", stats.BaseDef);
            float baseSpeed = (int)EditorGUILayout.FloatField("Speed", stats.BaseSpeed);

            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            stats.CalculateStats();
            EditorGUILayout.LabelField("Calculated stats");
            EditorGUILayout.SelectableLabel(((int)stats.CalculatedHP).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.SelectableLabel(((int)stats.CalculatedMP).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.SelectableLabel(((int)stats.CalculatedAtt).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.SelectableLabel(((int)stats.CalculatedDef).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.SelectableLabel(((int)stats.CalculatedSpeed).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight));

            EditorGUILayout.EndVertical();



            EditorGUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
            {
                if (UndoObj != null)
                {
                    Undo.RegisterCompleteObjectUndo(UndoObj, "Modify Stats");
                }

                stats.BaseHP     = Mathf.Max(1, baseHP);
                stats.BaseMP     = Mathf.Max(0, baseMP);
                stats.BaseAttack = Mathf.Max(1, baseAtt);
                stats.BaseDef    = Mathf.Max(0, baseDef);
                stats.BaseSpeed  = Mathf.Max(0, baseSpeed);;
            }

            for (int i = 0; i < stats.Gear.items.Length; i++)
            {
                if (stats.Gear.items[i] != null)
                {
                    if (!dict.ContainsKey(i))
                    {
                        RefreshDictionary();
                        break;
                    }
                }
            }
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Weapon Types", EditorStyles.boldLabel, GUILayout.Width(120));

            if (GUILayout.Button("+", GUILayout.Width(25)))
            {
                var myEnumMemberCount = Enum.GetNames(typeof(Stats.WeaponType)).Length;

                GenericMenu CreateMenu = new GenericMenu();

                for (int i = 0; i < myEnumMemberCount; i++)
                {
                    if (!stats.CanEquipWeapons.Contains(i))
                    {
                        CreateMenu.AddItem(new GUIContent(((Stats.WeaponType)i).ToString()), false, AddToEquipables, i);
                    }
                }

                CreateMenu.ShowAsContext();
            }
            GUILayout.FlexibleSpace();

            EditorGUILayout.EndHorizontal();

            int deleteIndex1 = -1;

            for (int i = 0; i < stats.CanEquipWeapons.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(((Stats.WeaponType)stats.CanEquipWeapons[i]).ToString(), GUILayout.Width(75));
                if (GUILayout.Button("x", GUILayout.Width(20)))
                {
                    deleteIndex1 = i;
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
            }

            if (deleteIndex1 != -1)
            {
                Undo.RecordObject(UndoObj, "Modify Stats");
                stats.CanEquipWeapons.RemoveAt(deleteIndex1);
            }


            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Gear", EditorStyles.boldLabel);

            int deleteIndex = -1;

            for (int i = 0; i < stats.Gear.items.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(((Stats.GearSlots)i).ToString(), GUILayout.Width(100));
                if (stats.Gear.items[i] != null || stats.Gear.Names[i] != null)
                {
                    EditorGUI.BeginDisabledGroup(stats.Gear.items[i] == null);

                    NewItem item = stats.Gear.items[i] != null ? stats.Gear.items[i] : stats.Gear.Names[i];

                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                    gearFolds[i] = EditorGUILayout.Foldout(gearFolds[i], item.ItemName);
                    if (gearFolds[i])
                    {
                        if (dict.ContainsKey(i))
                        {
                            dict[i].OnInspectorGUI();
                        }
                        else
                        {
                            RefreshDictionary();
                        }
                    }
                    EditorGUILayout.EndVertical();

                    if (GUILayout.Button("X", GUILayout.Width(20)))
                    {
                        deleteIndex = i;
                    }

                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    EditorGUILayout.HorizontalScope v = new EditorGUILayout.HorizontalScope();
                    using (v) {
                        EditorGUILayout.HelpBox("No Gear", MessageType.Info);
                        EditorGUI.BeginChangeCheck();

                        EditorGUILayout.BeginVertical();

                        EditorGUILayout.Space();
                        EditorGUILayout.Space();
                        int select = EditorGUILayout.Popup(0, slotItemStrings[i]);
                        EditorGUILayout.EndVertical();

                        if (EditorGUI.EndChangeCheck())
                        {
                            NewItem           itm  = slotItems[i][slotItemStrings[i][select]];
                            GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>();
                            if (attr == null)
                            {
                                Debug.LogWarning("This Item lack GearSlot Attribute and cannot be added to the Gear slot");
                            }
                            else
                            {
                                WeaponAttribute weaponAttr   = itm.GetAttribute <WeaponAttribute>();
                                bool            weaponCancel = false;
                                if (weaponAttr)
                                {
                                    if (!stats.CanEquipWeapons.Contains((int)weaponAttr.WeaponType))
                                    {
                                        weaponCancel = true;
                                        Debug.LogWarning("This character cannot equip this weapon type");
                                    }
                                }

                                //Add to a slot
                                if (attr.PossibleSlots[i] && !weaponCancel)
                                {
                                    Undo.RecordObject(UndoObj, "Modify Stats");
                                    stats.Gear.Equip(itm, i, null);
                                }
                            }
                            RefreshDictionary();
                        }
                    }
                    Event e = Event.current;
                    if (e.isMouse && e.button == 1 && v.rect.Contains(e.mousePosition))
                    {
                        GenericMenu CreateMenu = new GenericMenu();
                        if (ItemEditor.CopiedItem == null)
                        {
                            CreateMenu.AddDisabledItem(new GUIContent("Paste"));
                        }
                        else
                        {
                            CreateMenu.AddItem(new GUIContent("Paste"), false, Paste, i);
                        }
                        CreateMenu.ShowAsContext();
                    }
                }

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();
            }
            if (deleteIndex != -1)
            {
                Undo.RecordObject(UndoObj, "Modify Stats");
                stats.Gear.Unequip(deleteIndex, null);
                RefreshDictionary();
            }
        }
示例#22
0
 public void AddItem(NewItem itm)
 {
     itm.GenereateNewId();
     items.Add(itm);
     RefreshDictionary();
 }
示例#23
0
 private void Copy(object obj)
 {
     CopiedItem = (NewItem)obj;
 }