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); }
private TownshipStaffGump(Mobile mobile, Sort sort, int page, List <TownshipStone> list, bool tsdetail, int index) : base(20, 30) { try { mobile.CloseGump(typeof(TownshipStaffGump)); m_Mobile = mobile; m_List = list; m_Page = page; ConfigureGump(); if (m_List == null) { GenerateList(); } if (tsdetail && index >= 0 && index < m_List.Count) { //Show detail about township! TownshipStone thisStone = m_List[index]; double dHousePercentageFull = 0.0; double dHousePercentageWithAlliedIgnored = 0.0; try { dHousePercentageFull = TownshipDeed.GetPercentageOfGuildedHousesInArea(thisStone.TownshipCenter, thisStone.Map, thisStone.Extended ? TownshipStone.EXTENDED_RADIUS : TownshipStone.INITIAL_RADIUS, thisStone.Guild, false); dHousePercentageWithAlliedIgnored = TownshipDeed.GetPercentageOfGuildedHousesInArea(thisStone.TownshipCenter, thisStone.Map, thisStone.Extended ? TownshipStone.EXTENDED_RADIUS : TownshipStone.INITIAL_RADIUS, thisStone.Guild, true); } catch (Exception cpe) { Scripts.Commands.LogHelper.LogException(cpe); } AddHtml(20, 50, 300, 35, string.Format("{0} of {1}", TownshipStone.GetTownshipSizeDesc(thisStone.ActivityLevel), thisStone.GuildName), false, false); AddHtml(20, 80, 300, 35, string.Format("Last Week Total: {0}", thisStone.LastActualWeekNumber), false, false); AddHtml(20, 110, 300, 35, string.Format("Weeks at current level: {0}", thisStone.WeeksAtThisLevel), false, false); AddHtml(20, 140, 300, 35, string.Format("Last 7 days: {0},{1},{2},{3},{4},{5},{6}", thisStone.Visitors0, thisStone.Visitors1, thisStone.Visitors2, thisStone.Visitors3, thisStone.Visitors4, thisStone.Visitors5, thisStone.Visitors6), false, false); AddHtml(20, 170, 300, 35, string.Format("Current day index: {0}", thisStone.VisitorsIndex), false, false); AddHtml(20, 200, 300, 35, string.Format("Stone Location: ({0}, {1}, {2})", thisStone.X, thisStone.Y, thisStone.Z), false, false); AddHtml(20, 230, 300, 35, string.Format("House Ownership Percentage: all: {0:0.00} -- allies ignored: {1:0.00}", dHousePercentageFull, dHousePercentageWithAlliedIgnored), false, false); AddButton(20, 390, 4005, 4007, 997, GumpButtonType.Reply, 0); AddHtml(55, 390, 470, 30, "Back to Main Page", false, false); // EXIT } else { SortList(sort); ShowList(page); int numPages = (m_List.Count / 10) + 1; //need next/back buttons if (page > 0) { AddButton(20, 390, 4005, 4007, 998, GumpButtonType.Reply, 0); AddHtml(55, 390, 470, 30, "Previous", false, false); // EXIT } if (page + 1 < numPages) { AddButton(150, 390, 4005, 4007, 999, GumpButtonType.Reply, 0); AddHtml(185, 390, 470, 30, "Next", false, false); // EXIT } } } catch (Exception e) { Scripts.Commands.LogHelper.LogException(e); } }