ModernUO/Projects/Server/Guild.cs
Kamron Batman 9c7cb5d778
fix: Fixes dupe property copying. Adds IgnoreDupe (#1811)
## Summary

### Changes
- Adds `[IgnoreDupe]` and `[SerializedIgnoreDupe]`
- Updates all _known_ classes that need the attribute. Some might be missing, please helps us find them!
- Adds `Item.Dupe()` command and encapsulates `CopyProperties` and `OnAfterDuped`. This is also overridable.
- Updates Dupe command to use the new logic.
- Fixes duping multiple kinds of objects that used to be outright broken.

### Bug Fixes
- Fixes issue with durability after duping
- Fixes issue with hue after duping

> [!Note]
> **Developer Note**
> Customizing how duping an item works now requires two steps:
> 1. Add `[IgnoreDupe]` or `[SerializedIgnoreDupe]` to the property/field
> 2. Add custom logic in an `OnAfterDuped` override
>
> When do you need to do this?
> *When the property being copied is not a primitive, and you need to manually deep-clone the contents of the property such as with Lists, Dictionaries, or sub classes.*
2024-06-02 15:04:54 -07:00

122 lines
3.3 KiB
C#

/*************************************************************************
* ModernUO *
* Copyright 2019-2023 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Guild.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System;
using System.Collections.Generic;
namespace Server.Guilds;
public enum GuildType
{
Regular,
Chaos,
Order
}
public abstract class BaseGuild : ISerializable
{
protected BaseGuild()
{
Serial = World.NewGuild;
World.AddGuild(this);
}
protected BaseGuild(Serial serial) => Serial = serial;
public abstract string Abbreviation { get; set; }
public abstract string Name { get; set; }
public abstract GuildType Type { get; set; }
public abstract bool Disbanded { get; }
public abstract void Delete();
public bool Deleted => Disbanded;
[IgnoreDupe]
[CommandProperty(AccessLevel.Counselor)]
public Serial Serial { get; }
[IgnoreDupe]
[CommandProperty(AccessLevel.GameMaster, readOnly: true)]
public DateTime Created { get; set; } = Core.Now;
[IgnoreDupe]
public long SavePosition { get; set; } = -1;
[IgnoreDupe]
public BufferWriter SaveBuffer { get; set; }
public abstract void Serialize(IGenericWriter writer);
public abstract void Deserialize(IGenericReader reader);
public abstract void OnDelete(Mobile mob);
public static BaseGuild FindByName(string name)
{
foreach (var g in World.Guilds.Values)
{
if (g.Name.InsensitiveEquals(name))
{
return g;
}
}
return null;
}
public static BaseGuild FindByAbbrev(string abbr)
{
foreach (var g in World.Guilds.Values)
{
if (g.Abbreviation.InsensitiveEquals(abbr))
{
return g;
}
}
return null;
}
public static HashSet<BaseGuild> Search(string find)
{
var words = find.ToLower().Split(' ');
var results = new HashSet<BaseGuild>();
foreach (var g in World.Guilds.Values)
{
var name = g.Name;
bool all = true;
foreach (var t in words)
{
if (name.InsensitiveIndexOf(t) == -1)
{
all = false;
break;
}
}
if (all)
{
results.Add(g);
}
}
return results;
}
public override string ToString() => $"{Serial} \"{Name} [{Abbreviation}]\"";
}