#W# Added Knives TownHouses. Also wrote my own static house system that is configured with a cfg file.

This commit is contained in:
WarrentyExpired 2026-08-24 19:15:14 -04:00
parent 3132211847
commit dc5e0577fd
31 changed files with 7009 additions and 11 deletions

View file

@ -0,0 +1,36 @@
using System;
using Server;
namespace Knives.TownHouses
{
public delegate void TownHouseCommandHandler(CommandInfo info);
public class CommandInfo
{
private Mobile c_Mobile;
private string c_Command;
private string c_ArgString;
private string[] c_Arguments;
public Mobile Mobile { get { return c_Mobile; } }
public string Command { get { return c_Command; } }
public string ArgString { get { return c_ArgString; } }
public string[] Arguments { get { return c_Arguments; } }
public CommandInfo(Mobile m, string com, string args, string[] arglist)
{
c_Mobile = m;
c_Command = com;
c_ArgString = args;
c_Arguments = arglist;
}
public string GetString(int num)
{
if (c_Arguments.Length > num)
return c_Arguments[num];
return "";
}
}
}

View file

@ -0,0 +1,64 @@
using System;
using Server;
namespace Knives.TownHouses
{
public class DecoreItemInfo
{
private string c_TypeString;
private string c_Name;
private int c_ItemID;
private int c_Hue;
private Point3D c_Location;
private Map c_Map;
public string TypeString{ get{ return c_TypeString; } }
public string Name{ get{ return c_Name; } }
public int ItemID{ get{ return c_ItemID; } }
public int Hue{ get{ return c_Hue; } }
public Point3D Location{ get{ return c_Location; } }
public Map Map{ get{ return c_Map; } }
public DecoreItemInfo()
{
}
public DecoreItemInfo( string typestring, string name, int itemid, int hue, Point3D loc, Map map )
{
c_TypeString = typestring;
c_ItemID = itemid;
c_Location = loc;
c_Map = map;
}
public void Save( GenericWriter writer )
{
writer.Write( (int)1 ); // Version
// Version 1
writer.Write( c_Hue );
writer.Write( c_Name );
writer.Write( c_TypeString );
writer.Write( c_ItemID );
writer.Write( c_Location );
writer.Write( c_Map );
}
public void Load( GenericReader reader )
{
int version = reader.ReadInt();
if ( version >= 1 )
{
c_Hue = reader.ReadInt();
c_Name = reader.ReadString();
}
c_TypeString = reader.ReadString();
c_ItemID = reader.ReadInt();
c_Location = reader.ReadPoint3D();
c_Map = reader.ReadMap();
}
}
}

View file

@ -0,0 +1,217 @@
// Check PackUpHouse() for that crash on item delete. It causes a crash in RemoveMulti (Core)
using System;
using System.Collections;
using Server;
using Server.Multis;
namespace Knives.TownHouses
{
public class General
{
public static string Version{ get { return "2.01"; } }
// This setting determines the suggested gold value for a single square of a home
// which then derives price, lockdowns and secures.
public static int SuggestionFactor { get{ return 600; } }
// This setting determines if players need License in order to rent out their property
public static bool RequireRenterLicense{ get{ return false; } }
public static void Configure()
{
EventSink.WorldSave += new WorldSaveEventHandler( OnSave );
}
public static void Initialize()
{
EventSink.Login += new LoginEventHandler( OnLogin );
EventSink.Speech += new SpeechEventHandler( HandleSpeech );
EventSink.ServerStarted += new ServerStartedEventHandler( OnStarted );
}
private static void OnStarted()
{
foreach (TownHouse house in TownHouse.AllTownHouses)
{
house.InitSectorDefinition();
RUOVersion.UpdateRegion(house.ForSaleSign);
}
}
public static void OnSave( WorldSaveEventArgs e )
{
foreach( TownHouseSign sign in new ArrayList( TownHouseSign.AllSigns ) )
sign.ValidateOwnership();
foreach( TownHouse house in new ArrayList( TownHouse.AllTownHouses ) )
if ( house.Deleted )
{
TownHouse.AllTownHouses.Remove( house );
continue;
}
}
private static void OnLogin( LoginEventArgs e )
{
foreach( BaseHouse house in BaseHouse.GetHouses( e.Mobile ) )
if ( house is TownHouse )
((TownHouse)house).ForSaleSign.CheckDemolishTimer();
}
private static void HandleSpeech( SpeechEventArgs e )
{
ArrayList houses = new ArrayList(BaseHouse.GetHouses( e.Mobile ));
if ( houses == null )
return;
foreach( BaseHouse house in houses )
{
if (!RUOVersion.RegionContains(house.Region, e.Mobile))
continue;
if ( house is TownHouse )
house.OnSpeech( e );
if ( house.Owner == e.Mobile
&& e.Speech.ToLower() == "create rental contract"
&& CanRent( e.Mobile, house, true ) )
{
e.Mobile.AddToBackpack( new RentalContract() );
e.Mobile.SendMessage( "A rental contract has been placed in your bag." );
}
if ( house.Owner == e.Mobile
&& e.Speech.ToLower() == "check storage" )
{
int count = 0;
e.Mobile.SendMessage( "You have {0} lockdowns and {1} secures available.", RemainingSecures( house ), RemainingLocks( house ) );
if ( (count = AllRentalLocks( house )) != 0 )
e.Mobile.SendMessage( "Current rentals are using {0} of your lockdowns.", count );
if ( (count = AllRentalSecures( house )) != 0 )
e.Mobile.SendMessage( "Current rentals are using {0} of your secures.", count );
}
}
}
private static bool CanRent( Mobile m, BaseHouse house, bool say )
{
if ( house is TownHouse && ((TownHouse)house).ForSaleSign.PriceType != "Sale" )
{
if ( say )
m.SendMessage( "You must own your property to rent it." );
return false;
}
if ( RequireRenterLicense )
{
RentalLicense lic = m.Backpack.FindItemByType( typeof( RentalLicense ) ) as RentalLicense;
if ( lic != null && lic.Owner == null )
lic.Owner = m;
if ( lic == null || lic.Owner != m )
{
if ( say )
m.SendMessage( "You must have a renter's license to rent your property." );
return false;
}
}
if ( EntireHouseContracted( house ) )
{
if ( say )
m.SendMessage( "This entire house already has a rental contract." );
return false;
}
if ( RemainingSecures( house ) < 0 || RemainingLocks( house ) < 0 )
{
if ( say )
m.SendMessage( "You don't have the storage available to rent property." );
return false;
}
return true;
}
#region Rental Info
public static bool EntireHouseContracted( BaseHouse house )
{
foreach( Item item in TownHouseSign.AllSigns )
if ( item is RentalContract && house == ((RentalContract)item).ParentHouse )
if ( ((RentalContract)item).EntireHouse )
return true;
return false;
}
public static bool HasContract( BaseHouse house )
{
foreach( Item item in TownHouseSign.AllSigns )
if ( item is RentalContract && house == ((RentalContract)item).ParentHouse )
return true;
return false;
}
public static bool HasOtherContract( BaseHouse house, RentalContract contract )
{
foreach( Item item in TownHouseSign.AllSigns )
if ( item is RentalContract && item != contract && house == ((RentalContract)item).ParentHouse )
return true;
return false;
}
public static int RemainingSecures( BaseHouse house )
{
if ( house == null )
return 0;
int a, b, c, d;
return (Core.AOS ? house.GetAosMaxSecures() - house.GetAosCurSecures( out a, out b, out c, out d ) : house.MaxSecures - house.SecureCount) - AllRentalSecures( house );
}
public static int RemainingLocks( BaseHouse house )
{
if ( house == null )
return 0;
return (Core.AOS ? house.GetAosMaxLockdowns() - house.GetAosCurLockdowns() : house.MaxLockDowns - house.LockDownCount) - AllRentalLocks( house );
}
public static int AllRentalSecures( BaseHouse house )
{
int count = 0;
foreach( TownHouseSign sign in TownHouseSign.AllSigns )
if ( sign is RentalContract && ((RentalContract)sign).ParentHouse == house )
count+=sign.Secures;
return count;
}
public static int AllRentalLocks( BaseHouse house )
{
int count = 0;
foreach( TownHouseSign sign in TownHouseSign.AllSigns )
if ( sign is RentalContract && ((RentalContract)sign).ParentHouse == house )
count+=sign.Locks;
return count;
}
#endregion
}
}

View file

@ -0,0 +1,167 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Network;
using Server.Gumps;
namespace Knives.TownHouses
{
public class GumpResponse
{
public static void Initialize()
{
Timer.DelayCall(TimeSpan.Zero, new TimerCallback(AfterInit));
}
private static void AfterInit()
{
PacketHandlers.Register(0xB1, 0, true, new OnPacketReceive(DisplayGumpResponse));
}
public static void DisplayGumpResponse(NetState state, PacketReader pvSrc)
{
int serial = pvSrc.ReadInt32();
int typeID = pvSrc.ReadInt32();
int buttonID = pvSrc.ReadInt32();
/* Fixed for SVN */
//List<Gump> gumps = state.Gumps;
List<Gump> gumps = ((List<Gump>)state.Gumps);
for (int i = 0; i < gumps.Count; ++i)
{
Gump gump = gumps[i];
if (gump.Serial == serial && gump.TypeID == typeID)
{
int switchCount = pvSrc.ReadInt32();
if (switchCount < 0)
{
Console.WriteLine("Client: {0}: Invalid gump response, disconnecting...", state);
state.Dispose();
return;
}
int[] switches = new int[switchCount];
for (int j = 0; j < switches.Length; ++j)
switches[j] = pvSrc.ReadInt32();
int textCount = pvSrc.ReadInt32();
if (textCount < 0)
{
Console.WriteLine("Client: {0}: Invalid gump response, disconnecting...", state);
state.Dispose();
return;
}
TextRelay[] textEntries = new TextRelay[textCount];
for (int j = 0; j < textEntries.Length; ++j)
{
int entryID = pvSrc.ReadUInt16();
int textLength = pvSrc.ReadUInt16();
if (textLength > 239)
return;
string text = pvSrc.ReadUnicodeStringSafe(textLength);
textEntries[j] = new TextRelay(entryID, text);
}
state.RemoveGump(i);
if (!CheckResponse(gump, state.Mobile, buttonID))
return;
gump.OnResponse(state, new RelayInfo(buttonID, switches, textEntries));
return;
}
}
}
private static bool CheckResponse(Gump gump, Mobile m, int id)
{
if (m == null || !m.Player)
return true;
TownHouse th = null;
ArrayList list = new ArrayList();
foreach (Item item in m.GetItemsInRange(20))
if (item is TownHouse)
list.Add(item);
foreach (TownHouse t in list)
if (t.Owner == m)
{
th = t;
break;
}
if (th == null || th.ForSaleSign == null)
return true;
if (gump is HouseGumpAOS)
{
int val = id - 1;
if (val < 0)
return true;
int type = val % 15;
int index = val / 15;
if (th.ForSaleSign.ForcePublic && type == 3 && index == 12 && th.Public)
{
m.SendMessage("This house cannot be private.");
m.SendGump(gump);
return false;
}
if (th.ForSaleSign.ForcePrivate && type == 3 && index == 13 && !th.Public)
{
m.SendMessage("This house cannot be public.");
m.SendGump(gump);
return false;
}
if (th.ForSaleSign.NoTrade && type == 6 && index == 1)
{
m.SendMessage("This house cannot be traded.");
m.SendGump(gump);
return false;
}
}
else if (gump is HouseGump)
{
if (th.ForSaleSign.ForcePublic && id == 17 && th.Public)
{
m.SendMessage("This house cannot be private.");
m.SendGump(gump);
return false;
}
if (th.ForSaleSign.ForcePrivate && id == 17 && !th.Public)
{
m.SendMessage("This house cannot be public.");
m.SendGump(gump);
return false;
}
if (th.ForSaleSign.NoTrade && id == 14)
{
m.SendMessage("This house cannot be traded.");
m.SendGump(gump);
return false;
}
}
return true;
}
}
}