-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCastable.cs
More file actions
125 lines (103 loc) · 4.09 KB
/
Copy pathCastable.cs
File metadata and controls
125 lines (103 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// This file is part of Project Hybrasyl.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the Affero General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but
// without ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the Affero General Public License
// for more details.
//
// You should have received a copy of the Affero General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
//
// (C) 2020-2023 ERISCO, LLC
//
// For contributors and individual authors please refer to CONTRIBUTORS.MD.
using System;
using System.Collections.Generic;
using System.Linq;
using Hybrasyl.Xml.Interfaces;
namespace Hybrasyl.Xml.Objects;
public partial class Castable : ILoadOnStart<Castable>, ICategorizable
{
public int Id
{
get
{
unchecked
{
return 31 * (Name.GetHashCode() + 1);
}
}
}
// Helper functions to deal with xml vagaries
public List<AddStatus> AddStatuses => Effects.Statuses?.Add ?? new List<AddStatus>();
public List<RemoveStatus> RemoveStatuses => Effects.Statuses?.Remove ?? new List<RemoveStatus>();
public List<CastableReactor> Reactors => Effects?.Reactors ?? new List<CastableReactor>();
public byte CastableLevel { get; set; }
public ElementType Element
{
get
{
return Elements.Count switch
{
1 => Elements.First(),
> 1 => Elements.PickRandom(),
_ => ElementType.None
};
}
}
public DateTime LastCast { get; set; }
public bool IsSkill => Book is Book.PrimarySkill or Book.SecondarySkill or Book.UtilitySkill;
public bool IsSpell => Book is Book.PrimarySpell or Book.SecondarySpell or Book.UtilitySpell;
public bool OnCooldown => Cooldown > 0 && (DateTime.Now - LastCast).TotalSeconds < Cooldown;
public override string PrimaryKey => Id.ToString();
public override List<string> SecondaryKeys =>
Name == null ? new List<string>() : new List<string> { Name, Name.ToLower() };
public List<string> CategoryList
{
get
{
return Categories.Count > 0
? Categories.Select(selector: x => x.Value.ToLower()).ToList()
: new List<string>();
}
}
public new static void LoadAll(IWorldDataManager manager, string path) =>
HybrasylEntity<Castable>.LoadAll(manager, path);
public byte GetMaxLevelByClass(Class castableClass)
{
var maxLevelProperty = MaxLevel.GetType().GetProperty(castableClass.ToString());
return (byte) (maxLevelProperty != null ? maxLevelProperty.GetValue(MaxLevel, null) : 0);
}
public bool TryGetMotion(Class castClass, out CastableMotion motion)
{
motion = null;
if (Effects?.Animations?.OnCast?.Player == null) return false;
var m = Effects.Animations.OnCast.Player.Where(predicate: e => e.Class.Contains(castClass));
if (!m.Any())
m = Effects.Animations.OnCast.Player.Where(predicate: e => e.Class.Count == 0);
if (!m.Any())
return false;
motion = m.First();
return true;
}
public bool IsCategory(string category) => CategoryList.Contains(category.Normalize().ToLower());
}
public class CastableComparer : IEqualityComparer<Castable>
{
public bool Equals(Castable c1, Castable c2)
{
if (c1 == null && c2 == null) return true;
if (c1 == null || c2 == null) return false;
return string.Equals(c1.Name.Trim(), c2.Name.Trim(), StringComparison.CurrentCultureIgnoreCase) &&
c1.Book == c2.Book;
}
public int GetHashCode(Castable c)
{
var hCode = $"{c.Name.Trim().ToLower()}-{c.Book}";
return hCode.GetHashCode();
}
}