public static int DecayAllTownshipWalls() { int deleted = 0; try { List <BaseFortificationWall> listcopy = new List <BaseFortificationWall>(); foreach (BaseFortificationWall wall in TownshipWallList) { listcopy.Add(wall); } foreach (BaseFortificationWall wall in listcopy) { wall.Hits -= TownshipSettings.WallHitsDecay; TownshipRegion tr = TownshipRegion.GetTownshipAt(wall.Location, wall.Map); if (tr == null || wall.Hits < 0) { deleted++; wall.Delete(); } } } catch (Exception e) { Server.Commands.LogHelper.LogException(e); } return(deleted); }
public bool CanChange(Mobile from) { bool bReturn = false; if (from.AccessLevel >= AccessLevel.GameMaster) { return(true); } CustomRegion cr = CustomRegion.FindDRDTRegion(from.Map, this.Location); if (cr is TownshipRegion) { TownshipRegion tsr = cr as TownshipRegion; if (tsr != null && tsr.TStone != null && tsr.TStone.Guild != null && tsr.TStone.Guild == from.Guild) { bReturn = true; } else { from.SendMessage("You must be a member of this township to modify this wall."); bReturn = false; } } else { from.SendMessage("You must be within the township to modify this wall."); bReturn = false; } return(bReturn); }
public override bool Place(Mobile from) { try { if (((TownshipStone)m_Guild.TownshipStone).ActivityLevel >= Township.ActivityLevel.MEDIUM) { TownshipRegion tr = TownshipRegion.FindDRDTRegion(from.Map, from.Location) as TownshipRegion; if (tr != null) { if (tr.TStone != null) { CanExtendResult cer = tr.TStone.CanExtendRegion(from); if (cer == CanExtendResult.CanExtend) { tr.TStone.ExtendRegion(); TSTownCrier tsm = new TSTownCrier(); SetupTownshipNPC(tsm, from); return(true); } else { from.SendMessage("Can't extend Region."); switch (cer) { case CanExtendResult.ConflictingRegion: from.SendMessage("Extended area would conflict with another special area."); break; case CanExtendResult.HousingPercentage: from.SendMessage("Guild doens't own enough of the housing in the extended area."); break; default: from.SendMessage("Unknown reason - inform an administrator."); break; } } } else { from.SendMessage("Can't find Township Stone."); } } else { from.SendMessage("Can't find Township."); } } else { from.SendMessage("Your township must have a higher activity level to place this NPC."); } } catch (Exception e) { Server.Commands.LogHelper.LogException(e); } return(false); }
public static bool IsEnemyOfTownship(Mobile vendor, Mobile b) { if (b == null || vendor == null || !(b is PlayerMobile)) { return(true); } TownshipRegion tr = TownshipRegion.GetTownshipAt(vendor); if (tr != null) { if (tr.TStone != null) { return(tr.TStone.IsEnemy(b as PlayerMobile)); } } return(true); //if we can't find the township, don't interact with anyone }
public void NotifyOfDamager(Mobile damager) { if (damager == null) { return; //safety } Point3D targetPoint = this.Location; CustomRegion cr = CustomRegion.FindDRDTRegion(damager.Map, targetPoint); if (cr is TownshipRegion) { TownshipRegion tsr = cr as TownshipRegion; if (tsr != null && tsr.TStone != null && tsr.TStone.Guild != null && tsr.TStone.Guild != damager.Guild) { // every 10 minutes we will get a message unless the damager changes. // also, township members can type .status from within the township to dump the spam queue string text = string.Format("{0} at {1} is damaging your township's wall.", damager.Name, damager.Location.ToString()); if (tsr.IsSpam(damager, text) == false) { tsr.QueueSpam(damager, text); tsr.TStone.Guild.GuildMessage(text); try { string allytext = "[" + TownshipStone.GetTownshipSizeDesc(tsr.TStone.ActivityLevel) + " of the " + tsr.TStone.GuildName + "]: " + text; foreach (Server.Guilds.Guild g in tsr.TStone.Guild.Allies) { g.GuildMessage(allytext); } } catch (Exception exc) { Server.Commands.LogHelper.LogException(exc); } } else { tsr.QueueSpam(damager, text); } } } }
public static bool IsTownshipNPCOwner(Mobile a, Mobile vendor) { if (a != null) { BaseHouse house = BaseHouse.FindHouseAt(vendor); if (house != null) { TownshipRegion tr = TownshipRegion.GetTownshipAt(vendor); if (tr != null && tr.TStone != null) { if (house.IsOwner(a) && a.Guild != null && tr.TStone.Guild != null && a.Guild == tr.TStone.Guild) { return(true); } } } } return(false); }
public void NotifyOfDamager(Mobile damager) { if (damager == null) { return; //safety } Point3D targetPoint = this.Location; CustomRegion cr = CustomRegion.FindDRDTRegion(damager.Map, targetPoint); if (cr is TownshipRegion) { TownshipRegion tsr = cr as TownshipRegion; if (tsr != null && tsr.TStone != null && tsr.TStone.Guild != null && tsr.TStone.Guild != damager.Guild) { tsr.TStone.Guild.GuildMessage( string.Format("{0} at {1} is damaging your township's wall.", damager.Name, damager.Location.ToString())); } } }
public static bool TryPlace(Mobile from, int boardsRequired, int ingotsRequired, Item tool) { bool bReturn = false; if (tool.IsChildOf(from.Backpack) || tool.Parent == from) { PlayerMobile pm = from as PlayerMobile; if (pm != null) { Point3D targetPoint = from.Location; CustomRegion cr = CustomRegion.FindDRDTRegion(from.Map, targetPoint); if (cr is TownshipRegion) { TownshipRegion tsr = cr as TownshipRegion; if (tsr != null && tsr.TStone != null && tsr.TStone.Guild != null && tsr.TStone.Guild == from.Guild) { //for Adam, check for 100% ownership if (1.0 == TownshipDeed.GetPercentageOfGuildedHousesInArea(tsr.TStone.TownshipCenter, tsr.TStone.Map, tsr.TStone.Extended ? TownshipStone.EXTENDED_RADIUS : TownshipStone.INITIAL_RADIUS, tsr.TStone.Guild, false)) { //make sure we're not in a house, or right beside it BaseHouse house = null; bool bHouseRestriction = false; //find all the houses within 5 tiles of this location int radius = 5; Dictionary <BaseHouse, int> houseDict = new Dictionary <BaseHouse, int>(); for (int i = radius * -1; i <= radius && house == null; i++) { for (int j = radius * -1; j <= radius && house == null; j++) { Point3D currentCheck = new Point3D(targetPoint.X + i, targetPoint.Y + j, targetPoint.Z); //skip point-in-township test if we're checking a point right next to where we want to place if (!((i <= 1 && i >= -1) && (j <= 1 && j >= -1))) { //ensure that the point we're checking is actually in the township if (!tsr.IsPointInTownship(currentCheck)) { continue; } } house = BaseHouse.FindHouseAt(currentCheck, from.Map, 16); if (house != null) { int distance = (int)Math.Sqrt(sqr(currentCheck.X - targetPoint.X) + sqr(currentCheck.Y - targetPoint.Y)); if (houseDict.ContainsKey(house)) { int saveddistance = houseDict[house]; if (saveddistance > distance) { houseDict[house] = distance; } } else { houseDict.Add(house, distance); } } } } //now we have a list of all houses within the radius from the point where the wall is to be built and their distance from the point foreach (BaseHouse h in houseDict.Keys) { if (h.Owner != null) { if (tsr.TStone.Guild.IsMember(h.Owner) == false && houseDict[h] <= 5.0) { bHouseRestriction = true; break; } // else if (houseDict[h] <= 1.0) // { // bHouseRestriction = true; // break; // } } } if (bHouseRestriction == false) { //next check for teleporters bool bTeleporterRestriction = false; int iTeleporterDistanceRange = TownshipSettings.WallTeleporterDistance; IPooledEnumerable itemlist = from.Map.GetItemsInRange(targetPoint, iTeleporterDistanceRange); foreach (Item item in itemlist) { if (item is Teleporter) { bTeleporterRestriction = true; break; } } itemlist.Free(); if (bTeleporterRestriction == false) { bool hasResources = false; Item[] boards = from.Backpack.FindItemsByType(typeof(Board), true); Item[] ingots = from.Backpack.FindItemsByType(typeof(IronIngot), true); int boardCount = 0; int ingotCount = 0; for (int i = 0; i < boards.Length; i++) { boardCount += boards[i].Amount; } for (int i = 0; i < ingots.Length; i++) { ingotCount += ingots[i].Amount; } hasResources = (boardCount >= boardsRequired) && (ingotCount >= ingotsRequired); if (hasResources) { from.Backpack.ConsumeTotal(typeof(Board), boardsRequired); from.Backpack.ConsumeTotal(typeof(IronIngot), ingotsRequired); //from.SendMessage("You place the wall."); bReturn = true; } else { from.SendMessage("You don't have the resources to build this wall."); from.SendMessage("You need {0} boards and {1} iron ingots.", boardsRequired, ingotsRequired); } } else { from.SendMessage("You can't place this here."); from.SendMessage("Certain areas are restricted from placement because they would block normal transportation and entrances/exits."); } } else { from.SendMessage("You can't place this in or by a house."); from.SendMessage("You can place outside of one tile from a house that the township owns,"); from.SendMessage("but not within 6 tiles of a house that the township doesn't own."); } } else { from.SendMessage("Your guild must own all houses in this township to build fortifications.."); } } else { from.SendMessage("You must place this within the township that your guild owns."); } } else { from.SendMessage("You must place this within the township that your guild owns."); } } } else { from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it. } return(bReturn); }
public static bool DoesTownshipRegionConflict(Point3D centerLocation, Map map, int radius, TownshipRegion ignoreThisRegion) { bool bReturn = false; int x = centerLocation.X; int y = centerLocation.Y; int z = centerLocation.Z; int x_start = x - radius; int y_start = y - radius; int x_end = x + radius; int y_end = y + radius; for (int i = x_start; i < x_end; i++) { for (int j = y_start; j < y_end; j++) { Region r = Region.Find(new Point3D(i, j, z), map); if (r is TownshipRegion || r is GuardedRegion || r is CustomRegion) { if (ignoreThisRegion != null && r == ignoreThisRegion) { } else { bReturn = true; break; } } } if (bReturn) { break; } } return(bReturn); }
public override void OnDoubleClick(Mobile from) { BaseHouse house = BaseHouse.FindHouseAt(from); TownshipRegion tr = TownshipRegion.GetTownshipAt(from); if (house == null) { from.SendMessage("You must be in a house to place this vendor."); } else if (tr == null) { from.SendMessage("You must be in a township to place this vendor."); } else if (!house.IsCoOwner(from)) { from.SendMessage("You must be a coowner of the house to place this vendor."); } else if (!tr.CanBuildHouseInTownship(from)) { from.SendMessage("You must be a guildmate to place this vendor."); } else if (!tr.CanBuildHouseInTownship(house.Owner)) { from.SendMessage("The house must be owned by a guildmember to place this vendor."); } else if (!house.Public) { from.SendMessage("This vendor must be placed in a public house."); } else if (tr.TStone.Guild.Abbreviation != this.m_GuildAbbr) { from.SendMessage("This vendor must be placed in your guild's town."); } else { bool bCanPlace = true; int playervendorCount = 0; int tsnpcCount = 0; foreach (Mobile mx in house.Region.Mobiles.Values) { if (mx is PlayerVendor) { playervendorCount++; } Type type = mx.GetType(); TownshipNPCAttribute[] attributearray = (TownshipNPCAttribute[])type.GetCustomAttributes(typeof(TownshipNPCAttribute), false); if (attributearray.Length > 0) { tsnpcCount++; //it's a townshipNPC if (TownshipHelper.IsRestrictedTownshipNPC(mx)) { bCanPlace = false; } } } if ( (playervendorCount > 0 || tsnpcCount > 0) && (TownshipHelper.IsRestrictedTownshipNPCDeed(this)) ) { bCanPlace = false; } if (!bCanPlace) { from.SendMessage("You cannot place this vendor in a house with the other vendors that are present."); } else { //now check that the total TownshipNPC count is under what the house can hold. if (house.MaxSecures <= tsnpcCount) { from.SendMessage("You can't have any more Township NPCs in this house"); } else { if (this.Place(from)) { this.Delete(); } else { from.SendMessage("Placement failed"); } } } } }