mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-12-05 08:09:02 +00:00
补全 Item 转换器的属性;添加装备物品时返回旧的物品
This commit is contained in:
parent
a2efcd8328
commit
d9737f00f1
@ -875,12 +875,15 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为角色装备物品(必须使用此方法而不是自己去给EquipSlot里的物品赋值)
|
||||
/// 为角色装备物品(必须使用此方法而不是自己去给EquipSlot里的物品赋值)<para/>
|
||||
/// 此方法装备到指定栏位,并返回被替换的装备(如果有的话)
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="slot"></param>
|
||||
public bool Equip(Item item, EquipSlotType slot)
|
||||
/// <param name="previous"></param>
|
||||
public bool Equip(Item item, EquipSlotType slot, out Item? previous)
|
||||
{
|
||||
previous = null;
|
||||
bool result = false;
|
||||
double pastHP = HP;
|
||||
double pastMaxHP = MaxHP;
|
||||
@ -891,7 +894,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
case EquipSlotType.MagicCardPack:
|
||||
if (item.ItemType == ItemType.MagicCardPack)
|
||||
{
|
||||
UnEquip(EquipSlotType.MagicCardPack);
|
||||
previous = UnEquip(EquipSlotType.MagicCardPack);
|
||||
EquipSlot.MagicCardPack = item;
|
||||
item.OnItemEquip(this, EquipSlotType.MagicCardPack);
|
||||
result = true;
|
||||
@ -900,7 +903,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
case EquipSlotType.Weapon:
|
||||
if (item.ItemType == ItemType.Weapon)
|
||||
{
|
||||
UnEquip(EquipSlotType.Weapon);
|
||||
previous = UnEquip(EquipSlotType.Weapon);
|
||||
EquipSlot.Weapon = item;
|
||||
item.OnItemEquip(this, EquipSlotType.Weapon);
|
||||
result = true;
|
||||
@ -909,7 +912,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
case EquipSlotType.Armor:
|
||||
if (item.ItemType == ItemType.Armor)
|
||||
{
|
||||
UnEquip(EquipSlotType.Armor);
|
||||
previous = UnEquip(EquipSlotType.Armor);
|
||||
EquipSlot.Armor = item;
|
||||
item.OnItemEquip(this, EquipSlotType.Armor);
|
||||
result = true;
|
||||
@ -918,7 +921,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
case EquipSlotType.Shoes:
|
||||
if (item.ItemType == ItemType.Shoes)
|
||||
{
|
||||
UnEquip(EquipSlotType.Shoes);
|
||||
previous = UnEquip(EquipSlotType.Shoes);
|
||||
EquipSlot.Shoes = item;
|
||||
item.OnItemEquip(this, EquipSlotType.Shoes);
|
||||
result = true;
|
||||
@ -927,7 +930,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
case EquipSlotType.Accessory1:
|
||||
if (item.ItemType == ItemType.Accessory)
|
||||
{
|
||||
UnEquip(EquipSlotType.Accessory1);
|
||||
previous = UnEquip(EquipSlotType.Accessory1);
|
||||
EquipSlot.Accessory1 = item;
|
||||
EquipSlot.LastEquipSlotType = EquipSlotType.Accessory1;
|
||||
item.OnItemEquip(this, EquipSlotType.Accessory1);
|
||||
@ -937,7 +940,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
case EquipSlotType.Accessory2:
|
||||
if (item.ItemType == ItemType.Accessory)
|
||||
{
|
||||
UnEquip(EquipSlotType.Accessory2);
|
||||
previous = UnEquip(EquipSlotType.Accessory2);
|
||||
EquipSlot.Accessory2 = item;
|
||||
EquipSlot.LastEquipSlotType = EquipSlotType.Accessory2;
|
||||
item.OnItemEquip(this, EquipSlotType.Accessory2);
|
||||
@ -963,29 +966,70 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
switch (item.ItemType)
|
||||
{
|
||||
case ItemType.MagicCardPack:
|
||||
return Equip(item, EquipSlotType.MagicCardPack);
|
||||
return Equip(item, EquipSlotType.MagicCardPack, out _);
|
||||
case ItemType.Weapon:
|
||||
return Equip(item, EquipSlotType.Weapon);
|
||||
return Equip(item, EquipSlotType.Weapon, out _);
|
||||
case ItemType.Armor:
|
||||
return Equip(item, EquipSlotType.Armor);
|
||||
return Equip(item, EquipSlotType.Armor, out _);
|
||||
case ItemType.Shoes:
|
||||
return Equip(item, EquipSlotType.Shoes);
|
||||
return Equip(item, EquipSlotType.Shoes, out _);
|
||||
case ItemType.Accessory:
|
||||
if (EquipSlot.Accessory1 is null)
|
||||
{
|
||||
return Equip(item, EquipSlotType.Accessory1);
|
||||
return Equip(item, EquipSlotType.Accessory1, out _);
|
||||
}
|
||||
else if (EquipSlot.Accessory1 != null && EquipSlot.Accessory2 is null)
|
||||
{
|
||||
return Equip(item, EquipSlotType.Accessory2);
|
||||
return Equip(item, EquipSlotType.Accessory2, out _);
|
||||
}
|
||||
else if (EquipSlot.Accessory1 != null && EquipSlot.Accessory2 != null && EquipSlot.LastEquipSlotType == EquipSlotType.Accessory1)
|
||||
{
|
||||
return Equip(item, EquipSlotType.Accessory2);
|
||||
return Equip(item, EquipSlotType.Accessory2, out _);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Equip(item, EquipSlotType.Accessory1);
|
||||
return Equip(item, EquipSlotType.Accessory1, out _);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为角色装备物品(必须使用此方法而不是自己去给EquipSlot里的物品赋值)<para/>
|
||||
/// 此方法为根据物品类型,优先空位自动装备<para/>
|
||||
/// 此方法可返回被替换的装备(如果有的话)
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="previous"></param>
|
||||
public bool Equip(Item item, out Item? previous)
|
||||
{
|
||||
previous = null;
|
||||
switch (item.ItemType)
|
||||
{
|
||||
case ItemType.MagicCardPack:
|
||||
return Equip(item, EquipSlotType.MagicCardPack, out previous);
|
||||
case ItemType.Weapon:
|
||||
return Equip(item, EquipSlotType.Weapon, out previous);
|
||||
case ItemType.Armor:
|
||||
return Equip(item, EquipSlotType.Armor, out previous);
|
||||
case ItemType.Shoes:
|
||||
return Equip(item, EquipSlotType.Shoes, out previous);
|
||||
case ItemType.Accessory:
|
||||
if (EquipSlot.Accessory1 is null)
|
||||
{
|
||||
return Equip(item, EquipSlotType.Accessory1, out previous);
|
||||
}
|
||||
else if (EquipSlot.Accessory1 != null && EquipSlot.Accessory2 is null)
|
||||
{
|
||||
return Equip(item, EquipSlotType.Accessory2, out previous);
|
||||
}
|
||||
else if (EquipSlot.Accessory1 != null && EquipSlot.Accessory2 != null && EquipSlot.LastEquipSlotType == EquipSlotType.Accessory1)
|
||||
{
|
||||
return Equip(item, EquipSlotType.Accessory2, out previous);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Equip(item, EquipSlotType.Accessory1, out previous);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -54,16 +54,16 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许装备
|
||||
/// [ 注意:这个不是用来判断是不是装备类型的,判断装备类型时,请判断他们的 <see cref="ItemType"/> ]
|
||||
/// [ 注意:这个不是用来判断是不是装备类型的,判断装备类型时,请判断他们的 <see cref="IsEquipment"/> ]
|
||||
/// </summary>
|
||||
public bool Equipable { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许取消装备
|
||||
/// [ 注意:这个不是用来判断是不是装备类型的,判断装备类型时,请判断他们的 <see cref="ItemType"/> ]
|
||||
/// [ 注意:这个不是用来判断是不是装备类型的,判断装备类型时,使用 <see cref="IsEquipment"/> ]
|
||||
/// </summary>
|
||||
public bool Unequipable { get; set; } = true;
|
||||
|
||||
@ -310,7 +310,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// <summary>
|
||||
/// 局外(库存)使用物品触发
|
||||
/// </summary>
|
||||
public void UseItem(/*Inventory inventory*/)
|
||||
public void UseItem()
|
||||
{
|
||||
if (User != null) OnItemUsed(User, this);
|
||||
}
|
||||
@ -322,7 +322,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancel"></param>
|
||||
/// <param name="used"></param>
|
||||
public virtual void OnItemUsed(Character character, Item item, bool cancel, bool used)
|
||||
protected virtual void OnItemUsed(Character character, Item item, bool cancel, bool used)
|
||||
{
|
||||
|
||||
}
|
||||
@ -332,7 +332,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="item"></param>
|
||||
public virtual void OnItemUsed(User user, Item item)
|
||||
protected virtual void OnItemUsed(User user, Item item)
|
||||
{
|
||||
|
||||
}
|
||||
@ -343,7 +343,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// <param name="character"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="type"></param>
|
||||
public virtual void OnItemEquipped(Character character, Item item, EquipSlotType type)
|
||||
protected virtual void OnItemEquipped(Character character, Item item, EquipSlotType type)
|
||||
{
|
||||
|
||||
}
|
||||
@ -354,7 +354,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// <param name="character"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="type"></param>
|
||||
public virtual void OnItemUnEquipped(Character character, Item item, EquipSlotType type)
|
||||
protected virtual void OnItemUnEquipped(Character character, Item item, EquipSlotType type)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -59,6 +59,12 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
case nameof(Item.Equipable):
|
||||
result.Equipable = reader.GetBoolean();
|
||||
break;
|
||||
case nameof(Item.Unequipable):
|
||||
result.Unequipable = reader.GetBoolean();
|
||||
break;
|
||||
case nameof(Item.RemainUseTimes):
|
||||
result.RemainUseTimes = reader.GetInt32();
|
||||
break;
|
||||
case nameof(Item.IsPurchasable):
|
||||
result.IsPurchasable = reader.GetBoolean();
|
||||
break;
|
||||
@ -128,6 +134,8 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
||||
writer.WriteNumber(nameof(Item.RankType), (int)value.RankType);
|
||||
writer.WriteBoolean(nameof(Item.IsInGameItem), value.IsInGameItem);
|
||||
writer.WriteBoolean(nameof(Item.Equipable), value.Equipable);
|
||||
writer.WriteBoolean(nameof(Item.Unequipable), value.Unequipable);
|
||||
writer.WriteNumber(nameof(Item.RemainUseTimes), value.RemainUseTimes);
|
||||
writer.WriteBoolean(nameof(Item.IsPurchasable), value.IsPurchasable);
|
||||
writer.WriteNumber(nameof(Item.Price), value.Price);
|
||||
if (!value.IsSellable)
|
||||
|
||||
@ -1987,31 +1987,34 @@ namespace Milimoe.FunGame.Core.Model
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 装备物品到指定栏位
|
||||
/// 装备物品到指定栏位,并返回被替换的装备(如果有的话)
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="item"></param>
|
||||
public void Equip(Character character, EquipSlotType type, Item item)
|
||||
/// <param name="previous"></param>
|
||||
public void Equip(Character character, EquipSlotType type, Item item, out Item? previous)
|
||||
{
|
||||
if (character.Equip(item, type))
|
||||
if (character.Equip(item, type, out previous))
|
||||
{
|
||||
WriteLine($"[ {character} ] 装备了 [ {item.Name} ]。({ItemSet.GetEquipSlotTypeName(type)} 栏位)");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消装备
|
||||
/// 取消装备,并返回被替换的装备(如果有的话)
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
/// <param name="type"></param>
|
||||
public void UnEquip(Character character, EquipSlotType type)
|
||||
/// <returns></returns>
|
||||
public Item? UnEquip(Character character, EquipSlotType type)
|
||||
{
|
||||
Item? item = character.UnEquip(type);
|
||||
if (item != null)
|
||||
{
|
||||
WriteLine($"[ {character} ] 取消装备了 [ {item.Name} ]。({ItemSet.GetEquipSlotTypeName(type)} 栏位)");
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user