173 lines
7.0 KiB
C#
173 lines
7.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using DataServer.Data;
|
|
using DataServer.Data.Entities;
|
|
using DataServer.Data.Enums;
|
|
|
|
namespace GameServices.Admin.Pages.Abilities;
|
|
|
|
public class EditModel : AdminPageModel
|
|
{
|
|
private readonly GameDbContext _db;
|
|
|
|
public EditModel(GameDbContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
[BindProperty]
|
|
public MobAbilityDefinition Ability { get; set; } = new();
|
|
|
|
public List<DamageResistanceType> DamageTypes { get; set; } = new();
|
|
public List<DungeonMobDefinition> SummonableMobs { get; set; } = new();
|
|
public int AssignmentCount { get; set; }
|
|
|
|
public string? Message { get; set; }
|
|
public bool IsError { get; set; }
|
|
|
|
public async Task OnGetAsync(int? id)
|
|
{
|
|
await LoadLookups();
|
|
|
|
if (id.HasValue)
|
|
{
|
|
var ability = await _db.MobAbilityDefinitions.FindAsync(id.Value);
|
|
if (ability != null)
|
|
{
|
|
Ability = ability;
|
|
AssignmentCount = await _db.MobAbilityAssignments.CountAsync(a => a.AbilityDefinitionId == id.Value);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Ability = new MobAbilityDefinition
|
|
{
|
|
Key = "new_ability_" + DateTime.UtcNow.Ticks % 10000,
|
|
IsEnabled = true
|
|
};
|
|
}
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAsync(string? action)
|
|
{
|
|
await LoadLookups();
|
|
|
|
try
|
|
{
|
|
if (action == "duplicate" && Ability.Id > 0)
|
|
{
|
|
var newAbility = new MobAbilityDefinition
|
|
{
|
|
Name = Ability.Name + " (Copy)",
|
|
Key = Ability.Key + "_copy",
|
|
Description = Ability.Description,
|
|
AbilityType = Ability.AbilityType,
|
|
Targeting = Ability.Targeting,
|
|
BaseDamage = Ability.BaseDamage,
|
|
DamagePerTier = Ability.DamagePerTier,
|
|
DamageTypeKey = Ability.DamageTypeKey,
|
|
Range = Ability.Range,
|
|
AoeRadius = Ability.AoeRadius,
|
|
ConeAngle = Ability.ConeAngle,
|
|
Cooldown = Ability.Cooldown,
|
|
CastTime = Ability.CastTime,
|
|
AnimationDuration = Ability.AnimationDuration,
|
|
ProjectileSpeed = Ability.ProjectileSpeed,
|
|
ProjectileSprite = Ability.ProjectileSprite,
|
|
EffectDuration = Ability.EffectDuration,
|
|
DotDamagePerTick = Ability.DotDamagePerTick,
|
|
DotTickInterval = Ability.DotTickInterval,
|
|
SpeedModifier = Ability.SpeedModifier,
|
|
DisplacementDistance = Ability.DisplacementDistance,
|
|
SummonMobId = Ability.SummonMobId,
|
|
SummonCount = Ability.SummonCount,
|
|
StatModifier = Ability.StatModifier,
|
|
AffectedStat = Ability.AffectedStat,
|
|
Priority = Ability.Priority,
|
|
ManaCost = Ability.ManaCost,
|
|
AnimationKey = Ability.AnimationKey,
|
|
SoundEffectKey = Ability.SoundEffectKey,
|
|
VisualEffectKey = Ability.VisualEffectKey,
|
|
IsEnabled = true
|
|
};
|
|
_db.MobAbilityDefinitions.Add(newAbility);
|
|
await _db.SaveChangesAsync();
|
|
return RedirectToPage(new { id = newAbility.Id });
|
|
}
|
|
|
|
if (Ability.Id == 0)
|
|
{
|
|
Ability.CreatedAt = DateTime.UtcNow;
|
|
Ability.UpdatedAt = DateTime.UtcNow;
|
|
_db.MobAbilityDefinitions.Add(Ability);
|
|
await _db.SaveChangesAsync();
|
|
Message = $"Ability '{Ability.Name}' created.";
|
|
return RedirectToPage(new { id = Ability.Id });
|
|
}
|
|
else
|
|
{
|
|
var existing = await _db.MobAbilityDefinitions.FindAsync(Ability.Id);
|
|
if (existing == null)
|
|
{
|
|
Message = "Ability not found.";
|
|
IsError = true;
|
|
return Page();
|
|
}
|
|
|
|
existing.Name = Ability.Name;
|
|
existing.Key = Ability.Key;
|
|
existing.Description = Ability.Description;
|
|
existing.AbilityType = Ability.AbilityType;
|
|
existing.Targeting = Ability.Targeting;
|
|
existing.BaseDamage = Ability.BaseDamage;
|
|
existing.DamagePerTier = Ability.DamagePerTier;
|
|
existing.DamageTypeKey = Ability.DamageTypeKey;
|
|
existing.Range = Ability.Range;
|
|
existing.AoeRadius = Ability.AoeRadius;
|
|
existing.ConeAngle = Ability.ConeAngle;
|
|
existing.Cooldown = Ability.Cooldown;
|
|
existing.CastTime = Ability.CastTime;
|
|
existing.AnimationDuration = Ability.AnimationDuration;
|
|
existing.ProjectileSpeed = Ability.ProjectileSpeed;
|
|
existing.ProjectileSprite = Ability.ProjectileSprite;
|
|
existing.EffectDuration = Ability.EffectDuration;
|
|
existing.DotDamagePerTick = Ability.DotDamagePerTick;
|
|
existing.DotTickInterval = Ability.DotTickInterval;
|
|
existing.SpeedModifier = Ability.SpeedModifier;
|
|
existing.DisplacementDistance = Ability.DisplacementDistance;
|
|
existing.SummonMobId = Ability.SummonMobId;
|
|
existing.SummonCount = Ability.SummonCount;
|
|
existing.StatModifier = Ability.StatModifier;
|
|
existing.AffectedStat = Ability.AffectedStat;
|
|
existing.HpThresholdBelow = Ability.HpThresholdBelow;
|
|
existing.HpThresholdAbove = Ability.HpThresholdAbove;
|
|
existing.MinTargetsInRange = Ability.MinTargetsInRange;
|
|
existing.Priority = Ability.Priority;
|
|
existing.ManaCost = Ability.ManaCost;
|
|
existing.AnimationKey = Ability.AnimationKey;
|
|
existing.SoundEffectKey = Ability.SoundEffectKey;
|
|
existing.VisualEffectKey = Ability.VisualEffectKey;
|
|
existing.IsEnabled = Ability.IsEnabled;
|
|
existing.UpdatedAt = DateTime.UtcNow;
|
|
|
|
await _db.SaveChangesAsync();
|
|
Message = "Ability updated.";
|
|
AssignmentCount = await _db.MobAbilityAssignments.CountAsync(a => a.AbilityDefinitionId == Ability.Id);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Message = $"Error: {ex.Message}";
|
|
IsError = true;
|
|
}
|
|
|
|
return Page();
|
|
}
|
|
|
|
private async Task LoadLookups()
|
|
{
|
|
DamageTypes = await _db.DamageResistanceTypes.OrderBy(d => d.DisplayName).ToListAsync();
|
|
SummonableMobs = await _db.DungeonMobDefinitions.Where(m => m.IsEnabled).OrderBy(m => m.Name).ToListAsync();
|
|
}
|
|
}
|