public void OnOk(Character pUsrAccept) { switch (Type) { case RequestBoxType.SYNDICATE_ALLY: { Syndicate pAsk, pAccept; if (ServerKernel.Syndicates.TryGetValue(OwnerIdentity, out pAsk) && ServerKernel.Syndicates.TryGetValue(ObjectIdentity, out pAccept)) { pAsk.AllySyndicate(pAccept); pAsk.Send(string.Format(ServerString.STR_SYN_ALLY1, pAsk.LeaderName, pAccept.Name)); pAccept.Send(string.Format(ServerString.STR_SYN_ALLY0, pAccept.LeaderName, pAsk.Name)); } return; } case RequestBoxType.FAMILY_ALLY: { Family pAsk, pAccept; if (ServerKernel.Families.TryGetValue(OwnerIdentity, out pAsk) && ServerKernel.Families.TryGetValue(ObjectIdentity, out pAccept)) { pAsk.AllyFamily(pAccept); } return; } case RequestBoxType.ADD_APPRENTICE: { // Who accepts is the apprentice // Owner == Mentor // Object == Apprentice Client pMentor, pApprentice; if (ServerKernel.Players.TryGetValue(OwnerIdentity, out pMentor) && ServerKernel.Players.TryGetValue(ObjectIdentity, out pApprentice)) { if (!pMentor.Character.FetchStudentRequest(pMentor.Identity)) { return; } if (pApprentice.Character.IsMentor(pMentor.Character) || pMentor.Character.IsMentor(pApprentice.Character)) { pApprentice.Character.ClearStudentRequest(); return; } if (pMentor.Character.Metempsychosis < pApprentice.Character.Metempsychosis) { pApprentice.Character.ClearStudentRequest(); return; } if (pMentor.Character.Metempsychosis == pApprentice.Character.Metempsychosis && pMentor.Character.Level - pApprentice.Character.Level < 20) { pApprentice.Character.ClearStudentRequest(); return; } Guide pGuide = new Guide(pApprentice.Character); if (!pGuide.Create(pMentor.Identity, uint.Parse(DateTime.Now.ToString("yyyymmdd")))) { pApprentice.Character.ClearStudentRequest(); return; } Student pStudent = new Student(pMentor.Character); if (!pStudent.Create(pApprentice.Identity, uint.Parse(DateTime.Now.ToString("yyyymmdd")))) { pApprentice.Character.ClearStudentRequest(); return; } pMentor.Character.Apprentices.TryAdd(pApprentice.Identity, pStudent); pApprentice.Character.Mentor = pGuide; DbMentor dbMentor = new DbMentor { Date = (uint)UnixTimestamp.Timestamp(), GuideIdentity = pMentor.Character.Identity, GuideName = pMentor.Character.Name, StudentIdentity = pApprentice.Character.Identity, StudentName = pApprentice.Character.Name }; new MentorRepository().SaveOrUpdate(dbMentor); pGuide.Send(); pStudent.Send(); pApprentice.Character.ClearStudentRequest(); } break; } case RequestBoxType.ADD_MENTOR: { // Who accepts is the mentor // Owner == Apprentice // Object == Mentor Client pMentor, pApprentice; if (ServerKernel.Players.TryGetValue(OwnerIdentity, out pApprentice) && ServerKernel.Players.TryGetValue(ObjectIdentity, out pMentor)) { if (!pApprentice.Character.FetchGuideRequest(pMentor.Identity)) { return; } if (pApprentice.Character.IsMentor(pMentor.Character) || pMentor.Character.IsMentor(pApprentice.Character)) { pApprentice.Character.ClearGuideRequest(); return; } if (pMentor.Character.Metempsychosis < pApprentice.Character.Metempsychosis) { pApprentice.Character.ClearGuideRequest(); return; } if (pMentor.Character.Metempsychosis == pApprentice.Character.Metempsychosis && pMentor.Character.Level - pApprentice.Character.Level < 20) { pApprentice.Character.ClearGuideRequest(); return; } Guide pGuide = new Guide(pApprentice.Character); if (!pGuide.Create(pMentor.Identity, uint.Parse(DateTime.Now.ToString("yyyymmdd")))) { pApprentice.Character.ClearGuideRequest(); return; } Student pStudent = new Student(pMentor.Character); if (!pStudent.Create(pApprentice.Identity, uint.Parse(DateTime.Now.ToString("yyyymmdd")))) { pApprentice.Character.ClearGuideRequest(); return; } pMentor.Character.Apprentices.TryAdd(pApprentice.Identity, pStudent); pApprentice.Character.Mentor = pGuide; DbMentor dbMentor = new DbMentor { Date = (uint)UnixTimestamp.Timestamp(), GuideIdentity = pMentor.Character.Identity, GuideName = pMentor.Character.Name, StudentIdentity = pApprentice.Character.Identity, StudentName = pApprentice.Character.Name }; new MentorRepository().SaveOrUpdate(dbMentor); pGuide.Send(); pStudent.Send(); pApprentice.Character.ClearGuideRequest(); } break; } } }
public static void HandleGuideRequest(Character pRole, MsgGuide pMsg) { switch (pMsg.Type) { #region Request Mentor case MentorRequest.REQUEST_MENTOR: { if (pRole.Mentor == null) { Client pUser; if (pRole.Mentor == null && ServerKernel.Players.TryGetValue(pMsg.Param, out pUser)) { if (pUser.Character == null) { return; } Character pTargetRole = pUser.Character; if (pTargetRole.Level < pRole.Level || (pTargetRole.Level - pRole.Level < 20 && pTargetRole.Metempsychosis <= pRole.Metempsychosis)) { pRole.Send(ServerString.STR_GUIDE_TUTOR_LOW_LEVEL1); return; } if (pTargetRole.Metempsychosis < pRole.Metempsychosis) { pRole.Send(ServerString.STR_GUIDE_TUTOR_LOW_LEVEL1); return; } DbMentorType maxStud = ServerKernel.MentorTypes.FirstOrDefault( x => pTargetRole.Level >= x.UserMinLevel && pTargetRole.Level <= x.UserMaxLevel); if (maxStud == null) { return; } if (pRole.IsApprentice(pTargetRole) || pTargetRole.IsApprentice(pRole)) { return; } if (pTargetRole.Apprentices.Count >= maxStud.StudentNum) { pRole.Send(ServerString.STR_GUIDE_TOO_MANY_STUDENTS1); return; } pRole.SetGuideRequest(pMsg.Param); //pRole.SetGuideRequest(pMsg.Param); //pTargetRole.SetStudentRequest(pRole.Identity); pTargetRole.RequestBox = new RequestBox { OwnerIdentity = pRole.Identity, OwnerName = pRole.Name, ObjectIdentity = pTargetRole.Identity, ObjectName = pTargetRole.Name, Message = string.Format("{0} wants to be your apprentice. Do you accept?", pRole.Name), Type = RequestBoxType.ADD_MENTOR }; pTargetRole.RequestBox.Send(pTargetRole); } } break; } #endregion #region Request Apprentice case MentorRequest.REQUEST_APPRENTICE: { Client pClient; if (ServerKernel.Players.TryGetValue(pMsg.Param, out pClient)) { Character pTarget = pClient.Character; if (pTarget.Level > pRole.Level || pRole.Level - pTarget.Level < 20) { pRole.Send(ServerString.STR_GUIDE_TUTOR_LOW_LEVEL1); return; } if (pTarget.Metempsychosis > pRole.Metempsychosis) { pRole.Send(ServerString.STR_GUIDE_TUTOR_LOW_LEVEL1); return; } DbMentorType maxStud = ServerKernel.MentorTypes.FirstOrDefault( x => pRole.Level >= x.UserMinLevel && pRole.Level <= x.UserMaxLevel); if (maxStud == null) { return; } if (pRole.Apprentices.Count >= maxStud.StudentNum) { pRole.Send(ServerString.STR_GUIDE_TOO_MANY_STUDENTS1); return; } if (pRole.IsApprentice(pTarget) || pTarget.IsApprentice(pRole)) { return; } pRole.SetStudentRequest(pMsg.Param); //pTarget.SetGuideRequest(pRole.Identity); pTarget.RequestBox = new RequestBox { OwnerIdentity = pRole.Identity, OwnerName = pRole.Name, ObjectIdentity = pTarget.Identity, ObjectName = pTarget.Name, Message = string.Format("{0} wants to be your mentor.", pRole.Name), Type = RequestBoxType.ADD_APPRENTICE }; pTarget.RequestBox.Send(pTarget); pRole.Send(string.Format(ServerString.STR_GUIDE_SENDTUTOR, pTarget.Name)); } break; } #endregion #region Leave Mentor case MentorRequest.LEAVE_MENTOR: { if (pRole.Mentor == null) { return; } var repo = new MentorRepository(); var dbobj = repo.FetchMentor(pRole.Identity); if (dbobj == null) { return; } if (dbobj.BetrayalFlag > 0) { System.DateTime date = UnixTimestamp.ToDateTime((uint)dbobj.BetrayalFlag); pRole.Send("You still need to wait until " + date.ToString("M") + " to leave your mentor."); return; } if (!pRole.ReduceMoney(50000, true)) { return; } dbobj.BetrayalFlag = UnixTimestamp.Timestamp() + 60 * 60 * 24 * 3; repo.Delete(dbobj); pRole.Mentor.SendExpell(); pRole.Mentor = null; break; } #endregion #region Leave Apprentice case MentorRequest.EXPELL_APPRENTICE: { if (pRole.Apprentices.Count <= 0) { return; } var repo = new MentorRepository(); var apprentices = repo.FetchApprentices(pRole.Identity); DbMentor pAppr = null; foreach (var appr in apprentices) { if (appr.StudentIdentity == pMsg.Identity) { pAppr = appr; break; } } if (pAppr == null) { return; } Student pUserAppr; if (!pRole.Apprentices.TryRemove(pAppr.StudentIdentity, out pUserAppr)) { return; } repo.Delete(pAppr); pUserAppr.SendExpell(); break; } #endregion } }