예제 #1
0
        /// <summary>
        /// Updates world objects.
        /// </summary>
        /// <param name="elapsed">The number of milliseconds since the previous update.</param>
        private void Update(long elapsed)
        {
            // Note these are based on the characteristics of "Test Ground" in the Unity client
            const float MIN_X = -29.5f, MAX_X = -0.5f;
            const float MIN_Z = 0.5f, MAX_Z = 29.5f;

            // DEBUG: We'll make the monsters dance about for fun every few seconds
            updateTracker += elapsed;
            if (updateTracker > 4000L)
            {
                updateTracker = 0L;
                foreach (Monster monster in this.monsters.Values)
                {
                    float newX = random.Next(-1, 2);
                    float newZ = random.Next(-1, 2);
                    monster.WorldLoc = new Vector3D(
                        (monster.WorldLoc.X + newX).Clamp(MIN_X, MAX_X),
                        0f,
                        (monster.WorldLoc.Z + newZ).Clamp(MIN_Z, MAX_Z)
                        );
                    Msg upd = MsgBuilder.Client()
                              .ClientID(Msg.ALL_CLIENTS)
                              .Command(Msgs.CMD_POS)
                              .Subcommand(Msgs.SCMD_POS_UPDATE)
                              .TargetID(monster.ObjectID)
                              .Vector(monster.WorldLoc)
                              .Build();
                    MessageBroker.Broadcast(upd);
                }
            }
        }