添加user参数

This commit is contained in:
milimoe 2025-05-30 19:12:38 +08:00
parent 98e92e0611
commit 22889598ec
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
15 changed files with 109 additions and 63 deletions

View File

@ -32,7 +32,7 @@ namespace Oshima.FunGame.OshimaModules.Effects.ItemEffects
caster.EP += ; caster.EP += ;
} }
public override void OnSkillCasted(List<Character> targets, Dictionary<string, object> others) public override void OnSkillCasted(User user, List<Character> targets, Dictionary<string, object> others)
{ {
foreach (Character target in targets) foreach (Character target in targets)
{ {

View File

@ -32,7 +32,7 @@ namespace Oshima.FunGame.OshimaModules.Effects.ItemEffects
caster.EXP += ; caster.EXP += ;
} }
public override void OnSkillCasted(List<Character> targets, Dictionary<string, object> others) public override void OnSkillCasted(User user, List<Character> targets, Dictionary<string, object> others)
{ {
foreach (Character target in targets) foreach (Character target in targets)
{ {

View File

@ -32,7 +32,7 @@ namespace Oshima.FunGame.OshimaModules.Effects.ItemEffects
HealToTarget(caster, caster, , false); HealToTarget(caster, caster, , false);
} }
public override void OnSkillCasted(List<Character> targets, Dictionary<string, object> others) public override void OnSkillCasted(User user, List<Character> targets, Dictionary<string, object> others)
{ {
foreach (Character target in targets) foreach (Character target in targets)
{ {

View File

@ -33,7 +33,7 @@ namespace Oshima.FunGame.OshimaModules.Effects.ItemEffects
HealToTarget(caster, caster, , false); HealToTarget(caster, caster, , false);
} }
public override void OnSkillCasted(List<Character> targets, Dictionary<string, object> others) public override void OnSkillCasted(User user, List<Character> targets, Dictionary<string, object> others)
{ {
foreach (Character target in targets) foreach (Character target in targets)
{ {

View File

@ -32,7 +32,7 @@ namespace Oshima.FunGame.OshimaModules.Effects.ItemEffects
caster.MP += ; caster.MP += ;
} }
public override void OnSkillCasted(List<Character> targets, Dictionary<string, object> others) public override void OnSkillCasted(User user, List<Character> targets, Dictionary<string, object> others)
{ {
foreach (Character target in targets) foreach (Character target in targets)
{ {

View File

@ -33,7 +33,7 @@ namespace Oshima.FunGame.OshimaModules.Effects.ItemEffects
caster.MP += ; caster.MP += ;
} }
public override void OnSkillCasted(List<Character> targets, Dictionary<string, object> others) public override void OnSkillCasted(User user, List<Character> targets, Dictionary<string, object> others)
{ {
foreach (Character target in targets) foreach (Character target in targets)
{ {

View File

@ -21,11 +21,11 @@ namespace Oshima.FunGame.OshimaModules.Items
item.IsRemoveAfterUse = true; item.IsRemoveAfterUse = true;
} }
public static string UseItem(Item item, Character character) public static string UseItem(User user, Item item, Character character)
{ {
if (item.Skills.Active != null) if (item.Skills.Active != null)
{ {
item.Skills.Active.OnSkillCasted([character]); item.Skills.Active.OnSkillCasted(user, [character]);
string msg = $"对角色 [ {character} ] 使用 [ {item.Name} ] 成功!"; string msg = $"对角色 [ {character} ] 使用 [ {item.Name} ] 成功!";
if (item is HPRecovery hpBook) if (item is HPRecovery hpBook)
{ {
@ -36,7 +36,7 @@ namespace Oshima.FunGame.OshimaModules.Items
return "此物品没有主动技能,无法被使用!"; return "此物品没有主动技能,无法被使用!";
} }
public static bool OnItemUsed(Item item, Dictionary<string, object> args) public static bool OnItemUsed(User user, Item item, Dictionary<string, object> args)
{ {
string msg = ""; string msg = "";
bool result = false; bool result = false;
@ -47,7 +47,7 @@ namespace Oshima.FunGame.OshimaModules.Items
if (temp.Length > 0) if (temp.Length > 0)
{ {
targets = [temp[0]]; targets = [temp[0]];
msg = UseItem(item, temp[0]); msg = UseItem(user, item, temp[0]);
result = true; result = true;
} }
else else
@ -84,9 +84,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, HP, remainUseTimes); .Init(this, HP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }
@ -104,9 +104,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, HP, remainUseTimes); .Init(this, HP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }
@ -124,9 +124,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, HP, remainUseTimes); .Init(this, HP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }

View File

@ -21,11 +21,11 @@ namespace Oshima.FunGame.OshimaModules.Items
item.IsRemoveAfterUse = true; item.IsRemoveAfterUse = true;
} }
public static string UseItem(Item item, Character character) public static string UseItem(User user, Item item, Character character)
{ {
if (item.Skills.Active != null) if (item.Skills.Active != null)
{ {
item.Skills.Active.OnSkillCasted([character]); item.Skills.Active.OnSkillCasted(user, [character]);
string msg = $"对角色 [ {character} ] 使用 [ {item.Name} ] 成功!"; string msg = $"对角色 [ {character} ] 使用 [ {item.Name} ] 成功!";
if (item is EXPBook expBook) if (item is EXPBook expBook)
{ {
@ -36,7 +36,7 @@ namespace Oshima.FunGame.OshimaModules.Items
return "此物品没有主动技能,无法被使用!"; return "此物品没有主动技能,无法被使用!";
} }
public static bool OnItemUsed(Item item, Dictionary<string, object> args) public static bool OnItemUsed(User user, Item item, Dictionary<string, object> args)
{ {
string msg = ""; string msg = "";
bool result = false; bool result = false;
@ -47,7 +47,7 @@ namespace Oshima.FunGame.OshimaModules.Items
if (temp.Length > 0) if (temp.Length > 0)
{ {
targets = [temp[0]]; targets = [temp[0]];
msg = UseItem(item, temp[0]); msg = UseItem(user, item, temp[0]);
result = true; result = true;
} }
else else
@ -84,9 +84,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, EXP, remainUseTimes); .Init(this, EXP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }
@ -104,9 +104,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, EXP, remainUseTimes); .Init(this, EXP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }
@ -124,9 +124,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, EXP, remainUseTimes); .Init(this, EXP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }

View File

@ -21,11 +21,11 @@ namespace Oshima.FunGame.OshimaModules.Items
item.IsRemoveAfterUse = true; item.IsRemoveAfterUse = true;
} }
public static string UseItem(Item item, Character character) public static string UseItem(User user, Item item, Character character)
{ {
if (item.Skills.Active != null) if (item.Skills.Active != null)
{ {
item.Skills.Active.OnSkillCasted([character]); item.Skills.Active.OnSkillCasted(user, [character]);
string msg = $"对角色 [ {character} ] 使用 [ {item.Name} ] 成功!"; string msg = $"对角色 [ {character} ] 使用 [ {item.Name} ] 成功!";
if (item is EPAdd hpBook) if (item is EPAdd hpBook)
{ {
@ -36,7 +36,7 @@ namespace Oshima.FunGame.OshimaModules.Items
return "此物品没有主动技能,无法被使用!"; return "此物品没有主动技能,无法被使用!";
} }
public static bool OnItemUsed(Item item, Dictionary<string, object> args) public static bool OnItemUsed(User user, Item item, Dictionary<string, object> args)
{ {
string msg = ""; string msg = "";
bool result = false; bool result = false;
@ -47,7 +47,7 @@ namespace Oshima.FunGame.OshimaModules.Items
if (temp.Length > 0) if (temp.Length > 0)
{ {
targets = [temp[0]]; targets = [temp[0]];
msg = UseItem(item, temp[0]); msg = UseItem(user, item, temp[0]);
result = true; result = true;
} }
else else
@ -84,9 +84,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, EP, remainUseTimes); .Init(this, EP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }
@ -104,9 +104,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, EP, remainUseTimes); .Init(this, EP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }
@ -124,9 +124,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, EP, remainUseTimes); .Init(this, EP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }

View File

@ -21,11 +21,11 @@ namespace Oshima.FunGame.OshimaModules.Items
item.IsRemoveAfterUse = true; item.IsRemoveAfterUse = true;
} }
public static string UseItem(Item item, Character character) public static string UseItem(User user, Item item, Character character)
{ {
if (item.Skills.Active != null) if (item.Skills.Active != null)
{ {
item.Skills.Active.OnSkillCasted([character]); item.Skills.Active.OnSkillCasted(user, [character]);
string msg = $"对角色 [ {character} ] 使用 [ {item.Name} ] 成功!"; string msg = $"对角色 [ {character} ] 使用 [ {item.Name} ] 成功!";
if (item is MPRecovery hpBook) if (item is MPRecovery hpBook)
{ {
@ -36,7 +36,7 @@ namespace Oshima.FunGame.OshimaModules.Items
return "此物品没有主动技能,无法被使用!"; return "此物品没有主动技能,无法被使用!";
} }
public static bool OnItemUsed(Item item, Dictionary<string, object> args) public static bool OnItemUsed(User user, Item item, Dictionary<string, object> args)
{ {
string msg = ""; string msg = "";
bool result = false; bool result = false;
@ -47,7 +47,7 @@ namespace Oshima.FunGame.OshimaModules.Items
if (temp.Length > 0) if (temp.Length > 0)
{ {
targets = [temp[0]]; targets = [temp[0]];
msg = UseItem(item, temp[0]); msg = UseItem(user, item, temp[0]);
result = true; result = true;
} }
else else
@ -84,9 +84,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, MP, remainUseTimes); .Init(this, MP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }
@ -104,9 +104,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, MP, remainUseTimes); .Init(this, MP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }
@ -124,9 +124,9 @@ namespace Oshima.FunGame.OshimaModules.Items
.Init(this, MP, remainUseTimes); .Init(this, MP, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }

View File

@ -24,7 +24,7 @@ namespace Oshima.FunGame.OshimaModules.Items
item.IsRemoveAfterUse = true; item.IsRemoveAfterUse = true;
} }
public static bool OnItemUsed(Item item, Dictionary<string, object> args) public static bool OnItemUsed(User user, Item item, Dictionary<string, object> args)
{ {
string msg = ""; string msg = "";
if (item is GiftBox box) if (item is GiftBox box)
@ -61,9 +61,9 @@ namespace Oshima.FunGame.OshimaModules.Items
}, remainUseTimes); }, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }
@ -93,9 +93,9 @@ namespace Oshima.FunGame.OshimaModules.Items
}, remainUseTimes); }, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }
@ -124,9 +124,9 @@ namespace Oshima.FunGame.OshimaModules.Items
}, remainUseTimes); }, remainUseTimes);
} }
protected override bool OnItemUsed(Dictionary<string, object> args) protected override bool OnItemUsed(User user, Dictionary<string, object> args)
{ {
return .OnItemUsed(this, args); return .OnItemUsed(user, this, args);
} }
} }

View File

@ -11,14 +11,21 @@ namespace Oshima.FunGame.OshimaModules
public override string Description => OshimaGameModuleConstant.Description; public override string Description => OshimaGameModuleConstant.Description;
public override string Version => OshimaGameModuleConstant.Version; public override string Version => OshimaGameModuleConstant.Version;
public override string Author => OshimaGameModuleConstant.Author; public override string Author => OshimaGameModuleConstant.Author;
public Dictionary<string, Character> KnownCharacters { get; } = [];
public override Dictionary<string, Character> Characters public override Dictionary<string, Character> Characters
{ {
get get
{ {
EntityModuleConfig<Character> config = new(OshimaGameModuleConstant.General, OshimaGameModuleConstant.Character); Dictionary<string, Character> characters = Factory.GetGameModuleInstances<Character>(OshimaGameModuleConstant.General, OshimaGameModuleConstant.Character);
config.LoadConfig(); if (KnownCharacters.Count == 0 && characters.Count > 0)
return config; {
foreach (string key in characters.Keys)
{
KnownCharacters[key] = characters[key];
}
}
return characters;
} }
} }
@ -26,7 +33,7 @@ namespace Oshima.FunGame.OshimaModules
{ {
return (id, name, args) => return (id, name, args) =>
{ {
return id switch Character? character = id switch
{ {
1 => new OshimaShiya(), 1 => new OshimaShiya(),
2 => new XinYin(), 2 => new XinYin(),
@ -42,6 +49,13 @@ namespace Oshima.FunGame.OshimaModules
12 => new Quduoduo(), 12 => new Quduoduo(),
_ => null, _ => null,
}; };
if (character is null && KnownCharacters.Values.FirstOrDefault(i => i.Id == id) is Character known)
{
character = known.Copy();
}
return character;
}; };
} }
} }

View File

@ -11,12 +11,21 @@ namespace Oshima.FunGame.OshimaModules
public override string Description => OshimaGameModuleConstant.Description; public override string Description => OshimaGameModuleConstant.Description;
public override string Version => OshimaGameModuleConstant.Version; public override string Version => OshimaGameModuleConstant.Version;
public override string Author => OshimaGameModuleConstant.Author; public override string Author => OshimaGameModuleConstant.Author;
public Dictionary<string, Item> KnownItems { get; } = [];
public override Dictionary<string, Item> Items public override Dictionary<string, Item> Items
{ {
get get
{ {
return Factory.GetGameModuleInstances<Item>(OshimaGameModuleConstant.General, OshimaGameModuleConstant.Item); Dictionary<string, Item> items = Factory.GetGameModuleInstances<Item>(OshimaGameModuleConstant.General, OshimaGameModuleConstant.Item);
if (KnownItems.Count == 0 && items.Count > 0)
{
foreach (string key in items.Keys)
{
KnownItems[key] = items[key];
}
}
return items;
} }
} }
@ -24,7 +33,7 @@ namespace Oshima.FunGame.OshimaModules
{ {
return (id, name, args) => return (id, name, args) =>
{ {
return id switch Item? item = id switch
{ {
(long)AccessoryID.8 => new 8(), (long)AccessoryID.8 => new 8(),
(long)AccessoryID.20 => new 20(), (long)AccessoryID.20 => new 20(),
@ -55,6 +64,13 @@ namespace Oshima.FunGame.OshimaModules
(long)GiftBoxID. => new (), (long)GiftBoxID. => new (),
_ => null, _ => null,
}; };
if (item is null && KnownItems.Values.FirstOrDefault(i => i.Id == id) is Item known)
{
item = known.Copy();
}
return item;
}; };
} }
} }

View File

@ -15,12 +15,21 @@ namespace Oshima.FunGame.OshimaModules
public override string Description => OshimaGameModuleConstant.Description; public override string Description => OshimaGameModuleConstant.Description;
public override string Version => OshimaGameModuleConstant.Version; public override string Version => OshimaGameModuleConstant.Version;
public override string Author => OshimaGameModuleConstant.Author; public override string Author => OshimaGameModuleConstant.Author;
public Dictionary<string, Skill> KnownSkills { get; } = [];
public override Dictionary<string, Skill> Skills public override Dictionary<string, Skill> Skills
{ {
get get
{ {
return Factory.GetGameModuleInstances<Skill>(OshimaGameModuleConstant.General, OshimaGameModuleConstant.Skill); Dictionary<string, Skill> skills = Factory.GetGameModuleInstances<Skill>(OshimaGameModuleConstant.General, OshimaGameModuleConstant.Skill);
if (KnownSkills.Count == 0 && skills.Count > 0)
{
foreach (string key in skills.Keys)
{
KnownSkills[key] = skills[key];
}
}
return skills;
} }
} }
@ -33,7 +42,7 @@ namespace Oshima.FunGame.OshimaModules
{ {
return (id, name, args) => return (id, name, args) =>
{ {
return id switch Skill? skill = id switch
{ {
(long)MagicID. => new (), (long)MagicID. => new (),
(long)MagicID. => new (), (long)MagicID. => new (),
@ -90,6 +99,13 @@ namespace Oshima.FunGame.OshimaModules
(long)ItemActiveID. => new (), (long)ItemActiveID. => new (),
_ => null _ => null
}; };
if (skill is null && KnownSkills.Values.FirstOrDefault(i => i.Id == id) is Skill known)
{
skill = known.Copy();
}
return skill;
}; };
} }

View File

@ -999,7 +999,7 @@ namespace Oshima.FunGame.OshimaServers.Service
{ {
{ "targets", targets.ToArray() } { "targets", targets.ToArray() }
}; };
bool result = item.UseItem(args); bool result = item.UseItem(user, args);
if (item.EntityState == EntityState.Deleted) if (item.EntityState == EntityState.Deleted)
{ {
user.Inventory.Items.Remove(item); user.Inventory.Items.Remove(item);
@ -1037,7 +1037,7 @@ namespace Oshima.FunGame.OshimaServers.Service
msgs.Add($"{item.Name} 的剩余使用次数为 0无法使用"); msgs.Add($"{item.Name} 的剩余使用次数为 0无法使用");
result = false; result = false;
} }
bool tempResult = item.UseItem(args); bool tempResult = item.UseItem(user, args);
if (item.EntityState == EntityState.Deleted) if (item.EntityState == EntityState.Deleted)
{ {
user.Inventory.Items.Remove(item); user.Inventory.Items.Remove(item);