301 Days

A year of gamedev experiments.

Day 15 - Moar Live Info!

| Comments

We need to supply more live info about the NPCs, so we can do more cool stuff.


Need Input

Seeing NPCs suddenly be dead isn’t very interesting; we want to see them take damage, know who they’re fighting, etc. So I made a quick laundry list of NPC details we should be able to track:

"DragonsSpine/SQL Scripts/LiveNPC.sql"link
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
CREATE TABLE [dbo].[LiveNPC](
    [uniqueId] [int] NOT NULL,
    [name] [nvarchar](255) NOT NULL,
    [facet] [smallint] NOT NULL,
    [land] [smallint] NOT NULL,
    [map] [smallint] NOT NULL,
    [xCord] [smallint] NOT NULL,
    [yCord] [smallint] NOT NULL,
    [zCord] [int] NOT NULL,
    [level] [int] NOT NULL,
    [hits] [int] NOT NULL,
    [fullHits] [int] NOT NULL,
    [mana] [int] NOT NULL,
    [fullMana] [int] NOT NULL,
    [lastCommand] [nvarchar](255) NOT NULL,
    [lastActiveRound] [int] NOT NULL,
    [firstActiveRound] [int] NOT NULL,
    [isDead] [bit] NOT NULL  DEFAULT (0),
    [mostHatedId] [int] NULL,
    [hateCenterX] [smallint] NULL,
    [hateCenterY] [smallint] NULL,
    [loveCenterX] [smallint] NULL,
    [loveCenterY] [smallint] NULL,
    [fearLove] [int] NULL,
    [NpcTypeCode] [int] NULL ,
    [BaseTypeCode] [int] NULL ,
    [CharacterClassCode] [int] NULL ,
    [AlignCode] [int] NULL ,
    [numAttackers] [int] NULL,
    [lairLocationX] [smallint] NULL,
    [lairLocationY] [smallint] NULL,
    [lairLocationZ] [int] NULL,
    [priorityCode] [int] NULL,
    [effects] [nvarchar](255) NULL

So out with the NPCLocation table, in with the LiveNPC table. I replaced the necessary logic, pulling what I needed from the NPC and Character classes. Lots of cut-paste-edit, with a couple of interesting bits:

DragonsSpine/SQL Scripts/prApp_LiveNPC_Update.sqllink
93
94
95
    IF @@ROWCOUNT=0
        INSERT INTO LiveNPC (
            uniqueId,

DragonsSpine/SQL Scripts/prApp_LiveNPC_Update.sqllink
108
109
110
111
            lastCommand,
            lastActiveRound,
            firstActiveRound,
            isDead,

DragonsSpine/SQL Scripts/prApp_LiveNPC_Update.sqllink
143
144
145
146
            @lastCommand,
            @lastActiveRound,
            @lastActiveRound,
            @isDead,

firstActiveRound isn’t a concept inside of the server code, but we can track it this way: in the SQL, when a new NPC needs to be inserted, save the firstActiveRound as the same as the lastActiveRound (which will be the current round); for updates, don’t touch it.

DragonsSpine/GameObjects/GameLiving/NPC/NPC.cslink
1857
1858
1859
                // Save live NPC data
                if (Character.NPCList.Contains(ch))
                    DAL.DBNPC.SaveLiveNpc(npc);

I wanted to track dead NPCs, as long as they were still in the world, to see if there are any cases where they stick around while dead. So rather than checking IsDead, I have to see if they’ve been removed from the global NPC list yet.

Very Interesting


Matching Client

Of course, now that we’ve changed where the live NPC data is going, the client side will have to read from there. An easy change:

Assets/DragonsSpine/DAL/DBNPC.cslink
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
        public static List<NPC> GetAllNpcs()
        {
            List<NPC> npclist = new List<NPC>();

            using (SqlConnection tempConnection = DataAccess.GetSQLConnection())
            using (SqlStoredProcedure sp = new SqlStoredProcedure("prApp_LiveNPC_by_MapID", tempConnection)) {
                sp.AddParameter("@facet", SqlDbType.Int, 4, ParameterDirection.Input, 0);
                sp.AddParameter("@land", SqlDbType.Int, 4, ParameterDirection.Input, 0);
                sp.AddParameter("@map", SqlDbType.Int, 4, ParameterDirection.Input, 0);
                DataTable dtNPCs = sp.ExecuteDataTable();
                foreach (DataRow dr in dtNPCs.Rows)
                {
                    NPC npc = new NPC();
                    npc.worldNpcID = Convert.ToInt32(dr["uniqueId"]);
                    npc.lastActiveRound = Convert.ToInt32(dr["lastActiveRound"]);
                    npc.Name = dr["name"].ToString();
                    npc.X = Convert.ToInt16(dr["xCord"]);
                    npc.Y = Convert.ToInt16(dr["yCord"]);
                    npc.Z = Convert.ToInt16(dr["zCord"]);
                    npclist.Add(npc);
                }
            }
            return npclist;
        }

Not pulling in any of the new info until we have a use for it, but at least that brings things back to normal:


This is my new jam

Day 15 code - server
Day 15 code - client

Comments