示例#1
0
        public void OnPropertyLoaded(PropertyModel property)
        {
            var daysUntilPay = getDaysUntilNextPayment(property);

            if (daysUntilPay < 0)
            {
                if (property.FinanceData.CurrentInstallmentPayed >= GetPropertyNextPaymentPrice(property)) // reset everything because all stuff was payed on time
                {
                    property.FinanceData.CurrentInstallmentPayed   = 0;
                    property.FinanceData.ConsecutiveMissedPayments = 0;
                    property.FinanceData.LastPaymentDate           = DateTime.Now;

                    MySQL.execute("UPDATE property_finance SET LastPayment = CURRENT_TIMESTAMP WHERE PropertyID = @propid", new Dictionary <string, dynamic>
                    {
                        { "@propid", property.PropertyId },
                    });
                    SaveFinanceInformation(property);

                    return;
                }

                Log.Verbose($"Property {property.Address} ({property.PropertyId}) wasn't payed on time. Increasing ConsecutiveMissedPayments from {property.FinanceData.ConsecutiveMissedPayments} to {property.FinanceData.ConsecutiveMissedPayments + 1}");
                Log.Verbose($"Property {property.Address} ({property.PropertyId}) wasn't payed on time. Increasing TotalMissedPayments from {property.FinanceData.TotalMissedPayments} to {property.FinanceData.TotalMissedPayments + 1}");
                property.FinanceData.ConsecutiveMissedPayments += 1;
                property.FinanceData.TotalMissedPayments       += 1;

                if (property.FinanceData.ConsecutiveMissedPayments >= Settings.PropertyMaxAllowedConsecutiveMissedPayments || property.FinanceData.TotalMissedPayments >= Settings.PropertyMaxAllowedMissedPayments && property.OwnerCharacterId != -1)
                {
                    Log.Info($"Property {property.Address} ({property.PropertyId}) Is being foreclosed due to either the consecutive missed payments or total missed payments exceding their max values");
                    Log.Verbose($"Property {property.Address} ({property.PropertyId}) ConsecutiveMissedPayments: {property.FinanceData.ConsecutiveMissedPayments}");
                    Log.Verbose($"Property {property.Address} ({property.PropertyId}) TotalMissedPayments: {property.FinanceData.TotalMissedPayments}");

                    property.DesyncProperty();
                    property.OwnerCharacterId = -1;
                    foreach (var tenant in property.PropertyCharacterAccess)
                    {
                        Server.Get <PropertyManager>().RemovePropertyTenant(property, tenant);
                    }

                    foreach (var guest in property.TemporaryCharacterAccess)
                    {
                        Server.Get <PropertyManager>().RemovePropertyTenant(property, guest);
                    }

                    MySQL.execute("UPDATE vehicle_data SET Garage = 'Public1' WHERE Garage = ?", new List <string> {
                        $"home-{property.PropertyId}"
                    }, new Action <dynamic>(data =>
                    {
                        Log.Verbose($"Reset garages for vehicles in property {property.PropertyId} to Public1 due to the property being foreclosed");
                    }));
                }

                SaveFinanceInformation(property);
            }
        }
示例#2
0
        public void DeleteProperty(PropertyModel property)
        {
            Log.Verbose($"Deleting property {property.PropertyId}");
            property.DesyncProperty();
            property.OwnerCharacterId = -1;
            property.PropertyCharacterAccess.Clear();
            property.TemporaryCharacterAccess.Clear();

            MySQL.execute("DELETE FROM property_data WHERE PropertyID = ?", new List <string> {
                property.PropertyId
            }, new Action <dynamic>(data =>
            {
                Log.Verbose($"Removed property {property.PropertyId} from property_data");
            }));

            MySQL.execute("DELETE FROM property_finance WHERE PropertyID = ?", new List <string> {
                property.PropertyId
            }, new Action <dynamic>(data =>
            {
                Log.Verbose($"Removed property {property.PropertyId} from property_finance");
            }));

            MySQL.execute("DELETE FROM property_tenants WHERE PropertyID = ?", new List <string> {
                property.PropertyId
            }, new Action <dynamic>(data =>
            {
                Log.Verbose($"Removed property {property.PropertyId} from property_tenants");
            }));

            MySQL.execute("UPDATE vehicle_data SET Garage = 'Public1' WHERE Garage = ?", new List <string> {
                $"home-{property.PropertyId}"
            }, new Action <dynamic>(data =>
            {
                Log.Verbose($"Reset garages for vehicles in property {property.PropertyId} to Public1 due to the property being deleted");
            }));

            RemoveProperty(property);
        }