~ruther/NosSmooth

ref: d45c0f088bb74f87198ea0ea38a063a3468ddf37 NosSmooth/Core/NosSmooth.Game/Data/Mates/Mates.cs -rw-r--r-- 2.5 KiB
d45c0f08 — NotKappa Move VNum property to ILivingEntity 2 years ago
                                                                                
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
//
//  Mates.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections;
using System.Collections.Concurrent;
using NosSmooth.Game.Data.Characters;

namespace NosSmooth.Game.Data.Mates;

/// <summary>
/// Game mates state.
/// </summary>
public class Mates : IEnumerable<Mate>
{
    private ConcurrentDictionary<long, Partner> _partners;
    private ConcurrentDictionary<long, Pet> _pets;

    /// <summary>
    /// Initializes a new instance of the <see cref="Mates"/> class.
    /// </summary>
    public Mates()
    {
        _partners = new ConcurrentDictionary<long, Partner>();
        _pets = new ConcurrentDictionary<long, Pet>();
    }

    /// <summary>
    /// Gets all of the partners belonging to the character.
    /// </summary>
    public IEnumerable<Partner> Partners => _partners.Values;

    /// <summary>
    /// Gets all of the pets belonging to the character.
    /// </summary>
    public IEnumerable<Pet> Pets => _pets.Values;

    /// <summary>
    /// Gets the current skill of pet, if there is any.
    /// </summary>
    public Skill? PetSkill { get; internal set; }

    /// <summary>
    /// Get sthe current skills of partner(' sp).
    /// </summary>
    public IReadOnlyList<Skill>? PartnerSkills { get; internal set; }

    /// <summary>
    /// Gets the current pet of the client.
    /// </summary>
    public PartyPet? CurrentPet { get; internal set; }

    /// <summary>
    /// Gets the current partner of the client.
    /// </summary>
    public PartyPartner? CurrentPartner { get; internal set; }

    /// <inheritdoc />
    public IEnumerator<Mate> GetEnumerator()
        => _partners.Values.Cast<Mate>().Concat(_pets.Values.Cast<Mate>()).GetEnumerator();

    /// <inheritdoc/>
    IEnumerator IEnumerable.GetEnumerator()
        => GetEnumerator();

    /// <summary>
    /// Sets pet of the given id.
    /// </summary>
    /// <param name="pet">The pet.</param>
    internal void SetPet(Pet pet)
    {
        _pets[pet.MateId] = pet;
    }

    /// <summary>
    /// Sets partner of the given id.
    /// </summary>
    /// <param name="partner">The partner.</param>
    internal void SetPartner(Partner partner)
    {
        _partners[partner.MateId] = partner;
    }

    /// <summary>
    /// Clears partners and pets.
    /// </summary>
    internal void Clear()
    {
        _partners.Clear();
        _pets.Clear();
    }
}
Do not follow this link