public static void HandlePetitionRename(IRealmClient client, RealmPacketIn packet) { var petitionGuid = packet.ReadEntityId(); var newName = packet.ReadCString().Trim(); var charter = client.ActiveCharacter.Inventory.GetItem(petitionGuid) as PetitionCharter; var chr = client.ActiveCharacter; if (charter.Petition.Type == PetitionType.Guild) { if (!GuildMgr.IsValidGuildName(newName)) { GuildHandler.SendResult(chr, GuildCommandId.CREATE, newName, GuildResult.NAME_INVALID); return; } else if (GuildMgr.DoesGuildExist(newName)) { GuildHandler.SendResult(chr, GuildCommandId.CREATE, newName, GuildResult.NAME_EXISTS); return; } } else { if (!ArenaMgr.IsValidArenaTeamName(newName)) { ArenaTeamHandler.SendResult(chr, ArenaTeamCommandId.CREATE, newName, string.Empty, ArenaTeamResult.NAME_INVALID); return; } else if (ArenaMgr.DoesArenaTeamExist(newName)) { ArenaTeamHandler.SendResult(chr, ArenaTeamCommandId.CREATE, newName, string.Empty, ArenaTeamResult.NAME_EXISTS); return; } } charter.Petition.Name = newName; charter.Petition.Update(); SendPetitionRename(client, charter); }
public static void HandlePetitionTurnIn(IRealmClient client, RealmPacketIn packet) { var petitionGuid = packet.ReadEntityId(); var petition = client.ActiveCharacter.Inventory.GetItem(petitionGuid) as PetitionCharter; if (petition == null) { return; } var name = petition.Petition.Name; var type = petition.Petition.Type; if (petition.Petition.SignedIds.Count < ((uint)type - 1)) { SendPetitionTurnInResults(client, PetitionTurns.NEED_MORE_SIGNATURES); return; } if (type == PetitionType.Guild && client.ActiveCharacter.IsInGuild) { SendPetitionTurnInResults(client, PetitionTurns.ALREADY_IN_GUILD); return; } else if (client.ActiveCharacter.ArenaTeamMember[(uint)ArenaMgr.GetSlotByType((uint)type)] != null) { ArenaTeamHandler.SendResult(client, ArenaTeamCommandId.CREATE, name, string.Empty, ArenaTeamResult.ALREADY_IN_ARENA_TEAM); return; } else if (type == PetitionType.Guild && GuildMgr.DoesGuildExist(name)) { GuildHandler.SendResult(client, GuildCommandId.CREATE, name, GuildResult.NAME_EXISTS); return; } else if (ArenaMgr.DoesArenaTeamExist(name)) { ArenaTeamHandler.SendResult(client, ArenaTeamCommandId.CREATE, name, string.Empty, ArenaTeamResult.NAME_EXISTS); return; } else { petition.Destroy(); if (type == PetitionType.Guild) { var guild = new Guild(client.ActiveCharacter.Record, name); foreach (var chr in petition.Petition.SignedIds) { if (chr == 0) { continue; } else { var character = World.GetCharacter(chr); guild.AddMember(character); } } } else { var team = new ArenaTeam(client.ActiveCharacter.Record, name, (uint)type); foreach (var chr in petition.Petition.SignedIds) { if (chr == 0) { continue; } else { var character = World.GetCharacter(chr); team.AddMember(character); } } } SendPetitionTurnInResults(client, PetitionTurns.OK); } }
public static void HandlePetitionBuy(IRealmClient client, RealmPacketIn packet) { var chr = client.ActiveCharacter; var petitionerId = packet.ReadEntityId(); var petitioner = chr.Map.GetObject(petitionerId) as NPC; //var petitionId = packet.ReadInt32(); //var petitionCreator = packet.ReadEntityId(); //packet.SkipBytes(4 + 8); packet.Position += 4 + 8; var name = packet.ReadCString().Trim(); //var bodytext = packet.ReadCString().Trim(); //var minSignatures = packet.ReadInt32(); //var maxSignatures = packet.ReadInt32(); //var deadline = packet.ReadInt32(); //var issueDate = packet.ReadInt32(); //var allowedGuildId = packet.ReadInt32(); //var allowedClassMask = packet.ReadInt32(); //var allowedRaceMask = packet.ReadInt32(); //var allowedGender = packet.ReadInt32(); // wow is sexist... :( //var allowedMinLevel = packet.ReadInt32(); //var allowedMaxLevel = packet.ReadInt32(); //packet.SkipBytes(4 * 10); //packet.Position += (7 * 8) + 2 + 1 + 8; packet.Position += 4 * 10; var choice = packet.ReadInt32(); //var petitionType = packet.ReadInt32(); //packet.SkipBytes(4); packet.Position += 4; if (petitioner != null && petitioner.IsPetitioner && petitioner.CheckVendorInteraction(chr)) { ItemId itemId = 0; uint cost = 0; PetitionType type = PetitionType.None; if (petitioner.IsGuildPetitioner) { if (chr.IsInGuild) { GuildHandler.SendResult(chr, GuildCommandId.CREATE, name, GuildResult.ALREADY_IN_GUILD); return; } if (!GuildMgr.IsValidGuildName(name)) { GuildHandler.SendResult(chr, GuildCommandId.CREATE, name, GuildResult.NAME_INVALID); return; } else if (GuildMgr.DoesGuildExist(name)) { GuildHandler.SendResult(chr, GuildCommandId.CREATE, name, GuildResult.NAME_EXISTS); return; } itemId = PetitionerEntry.GuildPetitionEntry.ItemId; cost = GuildMgr.GuildCharterCost; type = PetitionType.Guild; } else if (petitioner.IsArenaPetitioner) { switch (choice) { case 1: itemId = PetitionerEntry.ArenaPetition2v2Entry.ItemId; cost = PetitionerEntry.ArenaPetition2v2Entry.Cost; type = PetitionType.Arena2vs2; break; case 2: itemId = PetitionerEntry.ArenaPetition3v3Entry.ItemId; cost = PetitionerEntry.ArenaPetition3v3Entry.Cost; type = PetitionType.Arena3vs3; break; case 3: itemId = PetitionerEntry.ArenaPetition5v5Entry.ItemId; cost = PetitionerEntry.ArenaPetition5v5Entry.Cost; type = PetitionType.Arena5vs5; break; default: return; } if (!ArenaMgr.IsValidArenaTeamName(name)) { ArenaTeamHandler.SendResult(chr, ArenaTeamCommandId.CREATE, name, string.Empty, ArenaTeamResult.NAME_INVALID); return; } else if (ArenaMgr.DoesArenaTeamExist(name)) { ArenaTeamHandler.SendResult(chr, ArenaTeamCommandId.CREATE, name, string.Empty, ArenaTeamResult.NAME_EXISTS); return; } } if (itemId != 0 && cost != 0 && type != PetitionType.None) { var templ = ItemMgr.GetTemplate(itemId); if (templ == null) { SendBuyError(chr, petitioner, itemId, BuyItemError.CantFindItem); } else if (chr.Money < cost) { SendBuyError(chr, petitioner, itemId, BuyItemError.NotEnoughMoney); } else if (!PetitionRecord.CanBuyPetition(chr.EntityId.Low)) { chr.SendSystemMessage("You can't buy another petition !"); } else { var slotId = chr.Inventory.FindFreeSlot(templ, 1); if (slotId.Container == null) { SendBuyError(chr, petitioner, itemId, BuyItemError.CantCarryAnymore); } else { var item = slotId.Container.AddUnchecked(slotId.Slot, templ, 1, true) as PetitionCharter; item.Petition = new PetitionRecord(name, chr.EntityId.Low, item.EntityId.Low, type); item.Petition.Create(); chr.Money -= cost; item.SetEnchantId(EnchantSlot.Permanent, item.EntityId.Low); } } } } }