装备和物品分离

This commit is contained in:
milimoe 2024-09-21 19:14:05 +08:00
parent 78d6f78c56
commit 6a7e5460b0
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
2 changed files with 121 additions and 24 deletions

View File

@ -21,6 +21,101 @@ namespace Milimoe.FunGame.Testing.Desktop.Solutions
CharacterManager.Load();
SkillManager.Load();
ItemManager.Load();
foreach (Character character in CharacterManager.LoadedCharacters.Values)
{
Skill[] skills = [.. character.Skills];
for (int i = 0; i < skills.Length; i++)
{
Skill skill = skills[i];
character.Skills.Remove(skill);
Skill? s = (skill.Id, skill.Name, skill.SkillType);
if (s != null)
{
skill = s.Copy();
skill.Character = character;
}
character.Skills.Add(skill);
}
if (character.EquipSlot.MagicCardPack != null)
{
Item item = character.EquipSlot.MagicCardPack;
Item? i = (item.Id, item.Name, item.ItemType);
if (i != null)
{
item.SetPropertyToItemModuleNew(i);
item = i.Copy();
character.Equip(item);
}
}
if (character.EquipSlot.Weapon != null)
{
Item item = character.EquipSlot.Weapon;
Item? i = (item.Id, item.Name, item.ItemType);
if (i != null)
{
item.SetPropertyToItemModuleNew(i);
item = i.Copy();
character.Equip(item);
}
}
if (character.EquipSlot.Armor != null)
{
Item item = character.EquipSlot.Armor;
Item? i = (item.Id, item.Name, item.ItemType);
if (i != null)
{
item.SetPropertyToItemModuleNew(i);
item = i.Copy();
character.Equip(item);
}
}
if (character.EquipSlot.Shoes != null)
{
Item item = character.EquipSlot.Shoes;
Item? i = (item.Id, item.Name, item.ItemType);
if (i != null)
{
item.SetPropertyToItemModuleNew(i);
item = i.Copy();
character.Equip(item);
}
}
if (character.EquipSlot.Accessory1 != null)
{
Item item = character.EquipSlot.Accessory1;
Item? i = (item.Id, item.Name, item.ItemType);
if (i != null)
{
item.SetPropertyToItemModuleNew(i);
item = i.Copy();
character.Equip(item);
}
}
if (character.EquipSlot.Accessory2 != null)
{
Item item = character.EquipSlot.Accessory2;
Item? i = (item.Id, item.Name, item.ItemType);
if (i != null)
{
item.SetPropertyToItemModuleNew(i);
item = i.Copy();
character.Equip(item);
}
}
Item[] items = [.. character.Items];
for (int j = 0; j < items.Length; j++)
{
Item item = items[j];
character.Items.Remove(item);
Item? i = (item.Id, item.Name, item.ItemType);
if (i != null)
{
item.SetPropertyToItemModuleNew(i);
item = i.Copy();
item.Character = character;
}
}
}
();
();
();
@ -222,6 +317,8 @@ namespace Milimoe.FunGame.Testing.Desktop.Solutions
Character? c = CharacterManager.LoadedCharacters.Values.Where(c => c.ToString() == .Items[.SelectedIndex].ToString()).FirstOrDefault();
Item? i = ItemManager.LoadedItems.Where(kv => GetItemDisplayName(ItemManager, kv.Key) == selected).Select(kv => kv.Value).FirstOrDefault();
if (c != null && i != null)
{
if (i.Equipable)
{
Item? i2 = (i.Id, i.Name, i.ItemType);
if (i2 != null)
@ -229,7 +326,10 @@ namespace Milimoe.FunGame.Testing.Desktop.Solutions
i.SetPropertyToItemModuleNew(i2);
i = i2;
}
c.Equip(i);
if (i.Equipable) c.Equip(i);
else c.Items.Add(i);
}
else c.Items.Add(i);
}
}
else
@ -264,7 +364,7 @@ namespace Milimoe.FunGame.Testing.Desktop.Solutions
Character? c = CharacterManager.LoadedCharacters.Values.Where(c => c.ToString() == .Items[.SelectedIndex].ToString()).FirstOrDefault();
if (c != null)
{
if (c.Items.Count != 0)
if (c.Items.Count != 0 || c.EquipSlot.Any())
{
ShowList l = new();
l.AddListItem(c.Items.Select(s => s.GetIdName()).ToArray());
@ -273,7 +373,8 @@ namespace Milimoe.FunGame.Testing.Desktop.Solutions
Item? i = c.Items.Where(i => i.GetIdName() == selected).FirstOrDefault();
if (i != null)
{
c.UnEquip(c.EquipSlot.GetEquipItemToSlot(i));
if (i.Equipable) c.UnEquip(c.EquipSlot.GetEquipItemToSlot(i));
else c.Items.Remove(i);
}
}
else
@ -415,16 +516,6 @@ namespace Milimoe.FunGame.Testing.Desktop.Solutions
return "";
}
private static ItemType SelectItemType()
{
ShowList l = new();
l.AddListItem([ItemType.MagicCardPack, ItemType.Weapon, ItemType.Armor, ItemType.Shoes, ItemType.Accessory,
ItemType.Consumable, ItemType.MagicCard, ItemType.Collectible, ItemType.SpecialItem, ItemType.QuestItem, ItemType.GiftBox, ItemType.Others]);
l.Text = "选择一个物品类型";
l.ShowDialog();
return Enum.TryParse(l.SelectItem, out ItemType type) ? type : ItemType.Others;
}
private static GameModuleLoader LoadModules()
{
PluginLoader plugins = PluginLoader.LoadPlugins([]);

View File

@ -86,6 +86,8 @@ namespace Milimoe.FunGame.Testing.Desktop.Solutions
string selected = l.SelectItem;
Item? i = ItemManager.LoadedItems.Where(kv => EntityEditor.GetItemDisplayName(ItemManager, kv.Key) == selected).Select(kv => kv.Value).FirstOrDefault();
if (c != null && i != null)
{
if (i.Equipable)
{
Item? i2 = EntityEditor.(i.Id, i.Name, i.ItemType);
if (i2 != null)
@ -93,7 +95,10 @@ namespace Milimoe.FunGame.Testing.Desktop.Solutions
i.SetPropertyToItemModuleNew(i2);
i = i2;
}
c.Equip(i);
if (i.Equipable) c.Equip(i);
else c.Items.Add(i);
}
else c.Items.Add(i);
.Text = c.GetInfo();
}
}
@ -144,7 +149,7 @@ namespace Milimoe.FunGame.Testing.Desktop.Solutions
{
if (c != null)
{
if (c.Items.Count != 0)
if (c.Items.Count != 0 || c.EquipSlot.Any())
{
ShowList l = new();
l.AddListItem(c.Items.OrderBy(i => i.Id).Select(i => i.GetIdName()).ToArray());
@ -153,7 +158,8 @@ namespace Milimoe.FunGame.Testing.Desktop.Solutions
Item? i = c.Items.Where(i => i.GetIdName() == selected).FirstOrDefault();
if (i != null)
{
c.UnEquip(c.EquipSlot.GetEquipItemToSlot(i));
if (i.Equipable) c.UnEquip(c.EquipSlot.GetEquipItemToSlot(i));
else c.Items.Remove(i);
.Text = c.GetInfo();
}
}