fix: Codegens vendor contracts (#1000)
This commit is contained in:
parent
dbb75f78a0
commit
4bde9a4c86
4 changed files with 686 additions and 647 deletions
|
|
@ -1,19 +1,32 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using ModernUO.Serialization;
|
||||||
using Server.ContextMenus;
|
using Server.ContextMenus;
|
||||||
using Server.Gumps;
|
using Server.Gumps;
|
||||||
using Server.Mobiles;
|
using Server.Mobiles;
|
||||||
using Server.Multis;
|
using Server.Multis;
|
||||||
using Server.Targeting;
|
using Server.Targeting;
|
||||||
|
|
||||||
namespace Server.Items
|
namespace Server.Items;
|
||||||
{
|
|
||||||
public class VendorRentalContract : Item
|
|
||||||
{
|
|
||||||
private VendorRentalDuration m_Duration;
|
|
||||||
|
|
||||||
private Mobile m_Offeree;
|
[SerializationGenerator(0)]
|
||||||
private Timer m_OfferExpireTimer;
|
public partial class VendorRentalContract : Item
|
||||||
|
{
|
||||||
|
[SerializableField(0, getter: "private", setter: "private")]
|
||||||
|
private int _rentalDurationId; // TODO: Replace this with something more robust
|
||||||
|
|
||||||
|
private VendorRentalDuration _duration;
|
||||||
|
|
||||||
|
private Mobile _offeree;
|
||||||
|
private Timer _offerExpireTimer;
|
||||||
|
|
||||||
|
[SerializableField(1)]
|
||||||
|
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||||
|
private int _price;
|
||||||
|
|
||||||
|
[SerializableField(2)]
|
||||||
|
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||||
|
private bool _landlordRenew;
|
||||||
|
|
||||||
[Constructible]
|
[Constructible]
|
||||||
public VendorRentalContract() : base(0x14F0)
|
public VendorRentalContract() : base(0x14F0)
|
||||||
|
|
@ -21,51 +34,42 @@ namespace Server.Items
|
||||||
Weight = 1.0;
|
Weight = 1.0;
|
||||||
Hue = 0x672;
|
Hue = 0x672;
|
||||||
|
|
||||||
m_Duration = VendorRentalDuration.Instances[0];
|
_duration = VendorRentalDuration.Instances[0];
|
||||||
Price = 1500;
|
Price = 1500;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VendorRentalContract(Serial serial) : base(serial)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int LabelNumber => 1062332; // a vendor rental contract
|
public override int LabelNumber => 1062332; // a vendor rental contract
|
||||||
|
|
||||||
public VendorRentalDuration Duration
|
public VendorRentalDuration Duration
|
||||||
{
|
{
|
||||||
get => m_Duration;
|
get => _duration;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
m_Duration = value;
|
_duration = value;
|
||||||
|
_rentalDurationId = _duration.ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[CommandProperty(AccessLevel.GameMaster)]
|
|
||||||
public int Price { get; set; }
|
|
||||||
|
|
||||||
[CommandProperty(AccessLevel.GameMaster)]
|
|
||||||
public bool LandlordRenew { get; set; }
|
|
||||||
|
|
||||||
public Mobile Offeree
|
public Mobile Offeree
|
||||||
{
|
{
|
||||||
get => m_Offeree;
|
get => _offeree;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (m_OfferExpireTimer != null)
|
if (_offerExpireTimer != null)
|
||||||
{
|
{
|
||||||
m_OfferExpireTimer.Stop();
|
_offerExpireTimer.Stop();
|
||||||
m_OfferExpireTimer = null;
|
_offerExpireTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Offeree = value;
|
_offeree = value;
|
||||||
|
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
m_OfferExpireTimer = new OfferExpireTimer(this);
|
_offerExpireTimer = new OfferExpireTimer(this);
|
||||||
m_OfferExpireTimer.Start();
|
_offerExpireTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
InvalidateProperties();
|
InvalidateProperties();
|
||||||
|
|
@ -211,36 +215,11 @@ namespace Server.Items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Serialize(IGenericWriter writer)
|
[AfterDeserialization]
|
||||||
|
private void AfterDeserialization()
|
||||||
{
|
{
|
||||||
base.Serialize(writer);
|
var index = Math.Clamp(_rentalDurationId, 0, VendorRentalDuration.Instances.Length);
|
||||||
|
_duration = VendorRentalDuration.Instances[index];
|
||||||
writer.WriteEncodedInt(0); // version
|
|
||||||
|
|
||||||
writer.WriteEncodedInt(m_Duration.ID);
|
|
||||||
|
|
||||||
writer.Write(Price);
|
|
||||||
writer.Write(LandlordRenew);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Deserialize(IGenericReader reader)
|
|
||||||
{
|
|
||||||
base.Deserialize(reader);
|
|
||||||
|
|
||||||
var version = reader.ReadEncodedInt();
|
|
||||||
|
|
||||||
var durationID = reader.ReadEncodedInt();
|
|
||||||
if (durationID < VendorRentalDuration.Instances.Length)
|
|
||||||
{
|
|
||||||
m_Duration = VendorRentalDuration.Instances[durationID];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_Duration = VendorRentalDuration.Instances[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
Price = reader.ReadInt();
|
|
||||||
LandlordRenew = reader.ReadBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ContractOptionEntry : ContextMenuEntry
|
private class ContractOptionEntry : ContextMenuEntry
|
||||||
|
|
@ -366,5 +345,4 @@ namespace Server.Items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"version": 0,
|
||||||
|
"type": "Server.Items.VendorRentalContract",
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "RentalDurationId",
|
||||||
|
"type": "int",
|
||||||
|
"rule": "PrimitiveTypeMigrationRule",
|
||||||
|
"ruleArguments": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Price",
|
||||||
|
"type": "int",
|
||||||
|
"rule": "PrimitiveTypeMigrationRule",
|
||||||
|
"ruleArguments": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "LandlordRenew",
|
||||||
|
"type": "bool",
|
||||||
|
"rule": "PrimitiveTypeMigrationRule",
|
||||||
|
"ruleArguments": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
{
|
||||||
|
"version": 0,
|
||||||
|
"type": "Server.Mobiles.RentedVendor",
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "RentalDurationId",
|
||||||
|
"type": "int",
|
||||||
|
"rule": "PrimitiveTypeMigrationRule",
|
||||||
|
"ruleArguments": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "RentalPrice",
|
||||||
|
"type": "int",
|
||||||
|
"rule": "PrimitiveTypeMigrationRule",
|
||||||
|
"ruleArguments": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "LandlordRenew",
|
||||||
|
"type": "bool",
|
||||||
|
"rule": "PrimitiveTypeMigrationRule",
|
||||||
|
"ruleArguments": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "RenterRenew",
|
||||||
|
"type": "bool",
|
||||||
|
"rule": "PrimitiveTypeMigrationRule",
|
||||||
|
"ruleArguments": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "RenewalPrice",
|
||||||
|
"type": "int",
|
||||||
|
"rule": "PrimitiveTypeMigrationRule",
|
||||||
|
"ruleArguments": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "RentalGold",
|
||||||
|
"type": "int",
|
||||||
|
"rule": "PrimitiveTypeMigrationRule",
|
||||||
|
"ruleArguments": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "RentalExpireTime",
|
||||||
|
"type": "System.DateTime",
|
||||||
|
"rule": "PrimitiveTypeMigrationRule",
|
||||||
|
"ruleArguments": [
|
||||||
|
"DeltaTime"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using ModernUO.Serialization;
|
||||||
using Server.ContextMenus;
|
using Server.ContextMenus;
|
||||||
using Server.Gumps;
|
using Server.Gumps;
|
||||||
using Server.Misc;
|
using Server.Misc;
|
||||||
using Server.Multis;
|
using Server.Multis;
|
||||||
using Server.Prompts;
|
using Server.Prompts;
|
||||||
|
|
||||||
namespace Server.Mobiles
|
namespace Server.Mobiles;
|
||||||
|
|
||||||
|
public class VendorRentalDuration
|
||||||
{
|
{
|
||||||
public class VendorRentalDuration
|
|
||||||
{
|
|
||||||
public static readonly VendorRentalDuration[] Instances =
|
public static readonly VendorRentalDuration[] Instances =
|
||||||
{
|
{
|
||||||
new(TimeSpan.FromDays(7.0), 1062361), // 1 Week
|
new(TimeSpan.FromDays(7.0), 1062361), // 1 Week
|
||||||
|
|
@ -43,11 +44,12 @@ namespace Server.Mobiles
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RentedVendor : PlayerVendor
|
[SerializationGenerator(0)]
|
||||||
{
|
public partial class RentedVendor : PlayerVendor
|
||||||
private Timer m_RentalExpireTimer;
|
{
|
||||||
|
private Timer _rentalExpireTimer;
|
||||||
|
|
||||||
public RentedVendor(
|
public RentedVendor(
|
||||||
Mobile owner, BaseHouse house, VendorRentalDuration duration, int rentalPrice,
|
Mobile owner, BaseHouse house, VendorRentalDuration duration, int rentalPrice,
|
||||||
|
|
@ -62,40 +64,46 @@ namespace Server.Mobiles
|
||||||
RentalGold = rentalGold;
|
RentalGold = rentalGold;
|
||||||
|
|
||||||
RentalExpireTime = Core.Now + duration.Duration;
|
RentalExpireTime = Core.Now + duration.Duration;
|
||||||
m_RentalExpireTimer = new RentalExpireTimer(this, duration.Duration);
|
_rentalExpireTimer = new RentalExpireTimer(this, duration.Duration);
|
||||||
m_RentalExpireTimer.Start();
|
_rentalExpireTimer.Start();
|
||||||
}
|
|
||||||
|
|
||||||
public RentedVendor(Serial serial) : base(serial)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public VendorRentalDuration RentalDuration { get; private set; }
|
public VendorRentalDuration RentalDuration { get; private set; }
|
||||||
|
|
||||||
[CommandProperty(AccessLevel.GameMaster)]
|
[SerializableField(0, getter: "private", setter: "private")]
|
||||||
public int RentalPrice { get; set; }
|
private int _rentalDurationId; // TODO: Replace this with something more robust
|
||||||
|
|
||||||
[CommandProperty(AccessLevel.GameMaster)]
|
[SerializableField(1)]
|
||||||
public bool LandlordRenew { get; set; }
|
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||||
|
private int _rentalPrice;
|
||||||
|
|
||||||
[CommandProperty(AccessLevel.GameMaster)]
|
[SerializableField(2)]
|
||||||
public bool RenterRenew { get; set; }
|
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||||
|
private bool _landlordRenew;
|
||||||
|
|
||||||
[CommandProperty(AccessLevel.GameMaster)]
|
[SerializableField(3)]
|
||||||
public bool Renew => LandlordRenew && RenterRenew && House != null && House.DecayType != DecayType.Condemned;
|
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||||
|
private bool _renterRenew;
|
||||||
|
|
||||||
[CommandProperty(AccessLevel.GameMaster)]
|
[SerializableField(4)]
|
||||||
public int RenewalPrice { get; set; }
|
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||||
|
private int _renewalPrice;
|
||||||
|
|
||||||
[CommandProperty(AccessLevel.GameMaster)]
|
[SerializableField(5)]
|
||||||
public int RentalGold { get; set; }
|
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||||
|
private int _rentalGold;
|
||||||
|
|
||||||
[CommandProperty(AccessLevel.GameMaster)]
|
[DeltaDateTime]
|
||||||
public DateTime RentalExpireTime { get; private set; }
|
[SerializableField(6)]
|
||||||
|
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||||
|
private DateTime _rentalExpireTime;
|
||||||
|
|
||||||
[CommandProperty(AccessLevel.GameMaster)]
|
[CommandProperty(AccessLevel.GameMaster)]
|
||||||
public Mobile Landlord => House?.Owner;
|
public Mobile Landlord => House?.Owner;
|
||||||
|
|
||||||
|
[CommandProperty(AccessLevel.GameMaster)]
|
||||||
|
public bool Renew => LandlordRenew && RenterRenew && House != null && House.DecayType != DecayType.Condemned;
|
||||||
|
|
||||||
public override bool IsOwner(Mobile m) => m == Owner || m.AccessLevel >= AccessLevel.GameMaster ||
|
public override bool IsOwner(Mobile m) => m == Owner || m.AccessLevel >= AccessLevel.GameMaster ||
|
||||||
Core.ML && AccountHandler.CheckAccount(m, Owner);
|
Core.ML && AccountHandler.CheckAccount(m, Owner);
|
||||||
|
|
||||||
|
|
@ -131,7 +139,7 @@ namespace Server.Mobiles
|
||||||
{
|
{
|
||||||
base.OnAfterDelete();
|
base.OnAfterDelete();
|
||||||
|
|
||||||
m_RentalExpireTimer.Stop();
|
_rentalExpireTimer.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Destroy(bool toBackpack)
|
public override void Destroy(bool toBackpack)
|
||||||
|
|
@ -170,52 +178,14 @@ namespace Server.Mobiles
|
||||||
base.GetContextMenuEntries(from, list);
|
base.GetContextMenuEntries(from, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Serialize(IGenericWriter writer)
|
[AfterDeserialization]
|
||||||
|
private void AfterDeserialization()
|
||||||
{
|
{
|
||||||
base.Serialize(writer);
|
var index = Math.Clamp(_rentalDurationId, 0, VendorRentalDuration.Instances.Length - 1);
|
||||||
|
RentalDuration = VendorRentalDuration.Instances[index];
|
||||||
|
|
||||||
writer.WriteEncodedInt(0); // version
|
var delay = _rentalExpireTime - Core.Now;
|
||||||
|
_rentalExpireTimer = new RentalExpireTimer(this, delay > TimeSpan.Zero ? delay : TimeSpan.Zero).Start();
|
||||||
writer.WriteEncodedInt(RentalDuration.ID);
|
|
||||||
|
|
||||||
writer.Write(RentalPrice);
|
|
||||||
writer.Write(LandlordRenew);
|
|
||||||
writer.Write(RenterRenew);
|
|
||||||
writer.Write(RenewalPrice);
|
|
||||||
|
|
||||||
writer.Write(RentalGold);
|
|
||||||
|
|
||||||
writer.WriteDeltaTime(RentalExpireTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Deserialize(IGenericReader reader)
|
|
||||||
{
|
|
||||||
base.Deserialize(reader);
|
|
||||||
|
|
||||||
var version = reader.ReadEncodedInt();
|
|
||||||
|
|
||||||
var durationID = reader.ReadEncodedInt();
|
|
||||||
if (durationID < VendorRentalDuration.Instances.Length)
|
|
||||||
{
|
|
||||||
RentalDuration = VendorRentalDuration.Instances[durationID];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RentalDuration = VendorRentalDuration.Instances[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
RentalPrice = reader.ReadInt();
|
|
||||||
LandlordRenew = reader.ReadBool();
|
|
||||||
RenterRenew = reader.ReadBool();
|
|
||||||
RenewalPrice = reader.ReadInt();
|
|
||||||
|
|
||||||
RentalGold = reader.ReadInt();
|
|
||||||
|
|
||||||
RentalExpireTime = reader.ReadDeltaTime();
|
|
||||||
|
|
||||||
var delay = RentalExpireTime - Core.Now;
|
|
||||||
m_RentalExpireTimer = new RentalExpireTimer(this, delay > TimeSpan.Zero ? delay : TimeSpan.Zero);
|
|
||||||
m_RentalExpireTimer.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ContractOptionsEntry : ContextMenuEntry
|
private class ContractOptionsEntry : ContextMenuEntry
|
||||||
|
|
@ -386,5 +356,4 @@ namespace Server.Mobiles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue