fixed several offense calculations
This commit is contained in:
@@ -65,6 +65,7 @@ export function DP2Form() {
|
||||
});
|
||||
|
||||
const onSubmit = (data: FormData) => {
|
||||
console.log('=== FORM SUBMISSION STARTED ===');
|
||||
console.log('Form submitted with data:', data);
|
||||
console.log('CrimeId value:', data.crimeId);
|
||||
|
||||
@@ -73,6 +74,8 @@ export function DP2Form() {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('About to call calculatePunishment...');
|
||||
|
||||
calculatePunishment(
|
||||
{
|
||||
playerName: data.playerName,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { CRIMES, calculateTotalPoints, getPunishmentLevel, generateCommands, generateExplanation, Crime, PunishmentLevel } from '@/lib/dp2-rules';
|
||||
import { CRIMES, ITEM_POINTS, calculateTotalPoints, getPunishmentLevel, generateCommands, generateExplanation, Crime, PunishmentLevel } from '@/lib/dp2-rules';
|
||||
|
||||
export interface PlayerFormData {
|
||||
playerName: string;
|
||||
@@ -36,6 +36,7 @@ export function useDP2Calculator() {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const calculatePunishment = useCallback((playerData: PlayerFormData, offenseData: OffenseFormData) => {
|
||||
console.log('calculatePunishment called with:', { playerData, offenseData });
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
@@ -47,27 +48,61 @@ export function useDP2Calculator() {
|
||||
throw new Error('Invalid crime selected');
|
||||
}
|
||||
|
||||
// Calculate item points if applicable
|
||||
// Calculate item points using ITEM_POINTS mapping
|
||||
let itemPoints = 0;
|
||||
if (offenseData.itemDetails) {
|
||||
itemPoints = offenseData.itemDetails.reduce((total, item) => {
|
||||
return total + (item.quantity || 0);
|
||||
}, 0);
|
||||
for (const item of offenseData.itemDetails) {
|
||||
// Use ITEM_POINTS mapping or default to 1 for unknown items
|
||||
const itemKey = item.type.toLowerCase() as keyof typeof ITEM_POINTS;
|
||||
const pointValue = ITEM_POINTS[itemKey] || ITEM_POINTS['other'] || 1;
|
||||
itemPoints += pointValue * (item.quantity || 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate special item points if applicable
|
||||
// Calculate special item points using ITEM_POINTS mapping
|
||||
let specialItemPoints = 0;
|
||||
if (offenseData.specialItems) {
|
||||
specialItemPoints =
|
||||
(offenseData.specialItems.elytra * 20) +
|
||||
(offenseData.specialItems.netherStar * 20) +
|
||||
(offenseData.specialItems.beacon * 20) +
|
||||
(offenseData.specialItems.netheriteBlock * 10) +
|
||||
(offenseData.specialItems.diamondBlock * 10);
|
||||
specialItemPoints +=
|
||||
(offenseData.specialItems.elytra * (ITEM_POINTS['elytra'] || 20)) +
|
||||
(offenseData.specialItems.netherStar * (ITEM_POINTS['nether_star'] || 20)) +
|
||||
(offenseData.specialItems.beacon * (ITEM_POINTS['beacon'] || 20)) +
|
||||
(offenseData.specialItems.netheriteBlock * (ITEM_POINTS['netherite_block'] || 10)) +
|
||||
(offenseData.specialItems.diamondBlock * (ITEM_POINTS['diamond_block'] || 10));
|
||||
}
|
||||
|
||||
// Calculate base points (including item points and special item points)
|
||||
const basePoints = crime.basePoints + itemPoints + specialItemPoints;
|
||||
// Calculate base points with crime-specific classification logic
|
||||
let basePoints = crime.basePoints;
|
||||
|
||||
// Special handling for theft classification
|
||||
if (crime.id === 'theft') {
|
||||
const totalItemPoints = itemPoints + specialItemPoints;
|
||||
if (totalItemPoints < 50) {
|
||||
basePoints = 1; // Minor theft
|
||||
} else if (totalItemPoints <= 500) {
|
||||
basePoints = 2; // Moderate theft
|
||||
} else {
|
||||
basePoints = 3; // Severe theft
|
||||
}
|
||||
}
|
||||
|
||||
// Special handling for grief classification
|
||||
if (crime.id === 'grief') {
|
||||
const blockCount = offenseData.blockCount || 0;
|
||||
if (blockCount < 100) {
|
||||
basePoints = 3; // Minor grief
|
||||
} else if (blockCount <= 1000) {
|
||||
basePoints = 5; // Moderate grief
|
||||
} else if (blockCount <= 100000) {
|
||||
basePoints = 8; // Large grief
|
||||
} else {
|
||||
basePoints = 25; // Massive grief
|
||||
}
|
||||
}
|
||||
|
||||
// Add any additional points from items (for non-theft crimes)
|
||||
if (crime.id !== 'theft') {
|
||||
basePoints += itemPoints + specialItemPoints;
|
||||
}
|
||||
|
||||
// Calculate total points with decay
|
||||
const totalPoints = calculateTotalPoints(basePoints, playerData.currentPoints, playerData.lastOffenseDate);
|
||||
|
||||
Reference in New Issue
Block a user