Skip to content

Commit 6bf3d5e

Browse files
Fix some systems in the guild
Fix the management of guild member applications, as well as the management functions of guild permissions and positions
1 parent c62e56d commit 6bf3d5e

8 files changed

Lines changed: 389 additions & 19 deletions

File tree

Maple2.Database/Storage/Game/GameStorage.Guild.cs

Lines changed: 141 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Maple2.Model.Enum;
33
using Maple2.Model.Game;
44
using Maple2.Tools.Extensions;
5+
using Microsoft.EntityFrameworkCore;
56
using Z.EntityFramework.Plus;
67

78
namespace Maple2.Database.Storage;
@@ -42,6 +43,140 @@ public IList<GuildMember> GetGuildMembers(IPlayerInfoProvider provider, long gui
4243
.ToList();
4344
}
4445

46+
47+
public IList<Guild> SearchGuilds(IPlayerInfoProvider provider, string guildName = "", GuildFocus? focus = null, int limit = 50) {
48+
IQueryable<Model.Guild> query = Context.Guild;
49+
if (!string.IsNullOrWhiteSpace(guildName)) {
50+
query = query.Where(guild => EF.Functions.Like(guild.Name, $"%{guildName}%"));
51+
}
52+
if (focus.HasValue && (int) focus.Value != 0) {
53+
query = query.Where(guild => guild.Focus == focus.Value);
54+
}
55+
56+
List<long> guildIds = query.OrderBy(guild => guild.Name)
57+
.Take(limit)
58+
.Select(guild => guild.Id)
59+
.ToList();
60+
61+
var result = new List<Guild>();
62+
foreach (long id in guildIds) {
63+
Guild? guild = LoadGuild(id, string.Empty);
64+
if (guild == null) {
65+
continue;
66+
}
67+
68+
foreach (GuildMember member in GetGuildMembers(provider, id)) {
69+
guild.Members.TryAdd(member.CharacterId, member);
70+
guild.AchievementInfo += member.Info.AchievementInfo;
71+
}
72+
result.Add(guild);
73+
}
74+
75+
return result;
76+
}
77+
78+
public GuildApplication? CreateGuildApplication(IPlayerInfoProvider provider, long guildId, long applicantId) {
79+
Guild? guild = LoadGuild(guildId, string.Empty);
80+
PlayerInfo? applicant = provider.GetPlayerInfo(applicantId);
81+
if (guild == null || applicant == null) {
82+
return null;
83+
}
84+
85+
if (Context.GuildApplication.Any(app => app.GuildId == guildId && app.ApplicantId == applicantId)) {
86+
Model.GuildApplication existing = Context.GuildApplication.First(app => app.GuildId == guildId && app.ApplicantId == applicantId);
87+
return new GuildApplication {
88+
Id = existing.Id,
89+
Guild = guild,
90+
Applicant = applicant,
91+
CreationTime = existing.CreationTime.ToEpochSeconds(),
92+
};
93+
}
94+
95+
var app = new Model.GuildApplication {
96+
GuildId = guildId,
97+
ApplicantId = applicantId,
98+
};
99+
Context.GuildApplication.Add(app);
100+
if (!SaveChanges()) {
101+
return null;
102+
}
103+
104+
return new GuildApplication {
105+
Id = app.Id,
106+
Guild = guild,
107+
Applicant = applicant,
108+
CreationTime = app.CreationTime.ToEpochSeconds(),
109+
};
110+
}
111+
112+
public GuildApplication? GetGuildApplication(IPlayerInfoProvider provider, long applicationId) {
113+
Model.GuildApplication? app = Context.GuildApplication.FirstOrDefault(app => app.Id == applicationId);
114+
if (app == null) {
115+
return null;
116+
}
117+
118+
Guild? guild = LoadGuild(app.GuildId, string.Empty);
119+
PlayerInfo? applicant = provider.GetPlayerInfo(app.ApplicantId);
120+
if (guild == null || applicant == null) {
121+
return null;
122+
}
123+
124+
return new GuildApplication {
125+
Id = app.Id,
126+
Guild = guild,
127+
Applicant = applicant,
128+
CreationTime = app.CreationTime.ToEpochSeconds(),
129+
};
130+
}
131+
132+
public IList<GuildApplication> GetGuildApplications(IPlayerInfoProvider provider, long guildId) {
133+
List<Model.GuildApplication> applications = Context.GuildApplication.Where(app => app.GuildId == guildId)
134+
.OrderByDescending(app => app.CreationTime)
135+
.ToList();
136+
137+
return applications
138+
.Select(app => {
139+
Guild? guild = LoadGuild(app.GuildId, string.Empty);
140+
PlayerInfo? applicant = provider.GetPlayerInfo(app.ApplicantId);
141+
if (guild == null || applicant == null) {
142+
return null;
143+
}
144+
145+
return new GuildApplication {
146+
Id = app.Id,
147+
Guild = guild,
148+
Applicant = applicant,
149+
CreationTime = app.CreationTime.ToEpochSeconds(),
150+
};
151+
})
152+
.WhereNotNull()
153+
.ToList();
154+
}
155+
156+
public IList<GuildApplication> GetGuildApplicationsByApplicant(IPlayerInfoProvider provider, long applicantId) {
157+
List<Model.GuildApplication> applications = Context.GuildApplication.Where(app => app.ApplicantId == applicantId)
158+
.OrderByDescending(app => app.CreationTime)
159+
.ToList();
160+
161+
return applications
162+
.Select(app => {
163+
Guild? guild = LoadGuild(app.GuildId, string.Empty);
164+
PlayerInfo? applicant = provider.GetPlayerInfo(app.ApplicantId);
165+
if (guild == null || applicant == null) {
166+
return null;
167+
}
168+
169+
return new GuildApplication {
170+
Id = app.Id,
171+
Guild = guild,
172+
Applicant = applicant,
173+
CreationTime = app.CreationTime.ToEpochSeconds(),
174+
};
175+
})
176+
.WhereNotNull()
177+
.ToList();
178+
}
179+
45180
public Guild? CreateGuild(string name, long leaderId) {
46181
BeginTransaction();
47182

@@ -155,20 +290,18 @@ public bool DeleteGuildApplications(long characterId) {
155290
public bool SaveGuildMembers(long guildId, ICollection<GuildMember> members) {
156291
Dictionary<long, GuildMember> saveMembers = members
157292
.ToDictionary(member => member.CharacterId, member => member);
158-
IEnumerable<Model.GuildMember> existingMembers = Context.GuildMember
293+
HashSet<long> existingMembers = Context.GuildMember
159294
.Where(member => member.GuildId == guildId)
160-
.Select(member => new Model.GuildMember {
161-
CharacterId = member.CharacterId,
162-
});
295+
.Select(member => member.CharacterId)
296+
.ToHashSet();
163297

164-
foreach (Model.GuildMember member in existingMembers) {
165-
if (saveMembers.Remove(member.CharacterId, out GuildMember? gameMember)) {
298+
foreach ((long characterId, GuildMember gameMember) in saveMembers) {
299+
if (existingMembers.Contains(characterId)) {
166300
Context.GuildMember.Update(gameMember);
167301
} else {
168-
Context.GuildMember.Remove(member);
302+
Context.GuildMember.Add(gameMember);
169303
}
170304
}
171-
Context.GuildMember.AddRange(saveMembers.Values.Select<GuildMember, Model.GuildMember>(member => member));
172305

173306
return SaveChanges();
174307
}

Maple2.Server.Game/Model/Field/Actor/Actor.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ public virtual void ApplyDamage(IActor caster, DamageRecord damage, SkillMetadat
152152
Stats.Values[BasicAttribute.Health].Add(damageAmount);
153153
Field.Broadcast(StatsPacket.Update(this, BasicAttribute.Health));
154154
OnDamageReceived(caster, positiveDamage);
155+
156+
if (caster is FieldPlayer casterPlayer && casterPlayer.Session.Dungeon.UserRecord != null) {
157+
casterPlayer.Session.Dungeon.UserRecord.AccumulationRecords[DungeonAccumulationRecordType.TotalDamage] += (int) positiveDamage;
158+
casterPlayer.Session.Dungeon.UserRecord.AccumulationRecords[DungeonAccumulationRecordType.TotalHitCount] += targetRecord.Damage.Count(x => x.Amount > 0 && x.Type is DamageType.Normal or DamageType.Critical);
159+
casterPlayer.Session.Dungeon.UserRecord.AccumulationRecords[DungeonAccumulationRecordType.TotalCriticalDamage] += (int) targetRecord.Damage.Where(x => x.Type == DamageType.Critical).Sum(x => x.Amount);
160+
}
161+
if (this is FieldPlayer targetPlayer && targetPlayer.Session.Dungeon.UserRecord != null) {
162+
targetPlayer.Session.Dungeon.UserRecord.AccumulationRecords[DungeonAccumulationRecordType.IncomingDamage] += (int) positiveDamage;
163+
}
155164
}
156165

157166
foreach ((DamageType damageType, long amount) in targetRecord.Damage) {

Maple2.Server.Game/Model/Field/Buff.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ private void ApplyRecovery() {
211211
if (updated.Count > 0) {
212212
Field.Broadcast(StatsPacket.Update(Owner, updated.ToArray()));
213213
}
214+
if (Caster is FieldPlayer casterPlayer && casterPlayer.Session.Dungeon.UserRecord != null && record.HpAmount > 0) {
215+
casterPlayer.Session.Dungeon.UserRecord.AccumulationRecords[DungeonAccumulationRecordType.TotalHealing] += record.HpAmount;
216+
}
214217
Field.Broadcast(SkillDamagePacket.Heal(record));
215218
}
216219

0 commit comments

Comments
 (0)