~ruther/NosSmooth

ref: 286b8d11d72777baee365a4069f3aacaae7ab2e3 NosSmooth/Core/NosSmooth.Game/Helpers/EntityHelpers.cs -rw-r--r-- 1.4 KiB
286b8d11 — Rutherther fix(packets): make mltobj packet list a list index 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
//
//  EntityHelpers.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 NosSmooth.Game.Data.Entities;
using NosSmooth.Packets.Enums.Entities;

namespace NosSmooth.Game.Helpers;

/// <summary>
/// Helper methods for various operations with entities.
/// </summary>
public static class EntityHelpers
{
    /// <summary>
    /// Create an entity from the given type and id.
    /// </summary>
    /// <param name="type">The entity type.</param>
    /// <param name="entityId">The entity id.</param>
    /// <returns>The entity.</returns>
    public static IEntity CreateEntity(EntityType type, long entityId)
    {
        switch (type)
        {
            case EntityType.Npc:
                return new Npc
                {
                    Id = entityId
                };
            case EntityType.Monster:
                return new Monster
                {
                    Id = entityId
                };
            case EntityType.Player:
                return new Player
                {
                    Id = entityId
                };
            case EntityType.Object:
                return new GroundItem
                {
                    Id = entityId
                };
        }

        throw new Exception("Unknown entity type.");
    }
}
Do not follow this link