示例#1
0
        private static void QuestInteract(ConnectionType type, int index, byte[] data)
        {
            ByteBuffer.ByteBuffer buffer = new ByteBuffer.ByteBuffer();
            buffer.WriteBytes(data);
            ReadHeader(ref buffer);
            int Character_ID = buffer.ReadInteger();
            int NPC_ID       = buffer.ReadInteger();

            if (MathF.Distance(World.instance.players[Character_ID], World.instance.GetNPCByEntityID(NPC_ID)) <= World.InteractionDistance)
            {
                World.instance.UpdateQuestLog(Character_ID);
                bool        Create = false;
                QuestReturn qr     = World.instance.GetQuestContentByNPCEntityID(Character_ID, NPC_ID, out Create);
                Quest_Log   ql     = null;
                ql = World.instance.GetQuestLog(Character_ID, qr.Quest_ID);
                if (qr.Null != true && ql != null)
                {
                    switch (qr.Status)
                    {
                    case QuestStatus.None:
                        break;

                    case QuestStatus.InProgress:
                        if (ql.ObjectiveProgress >= qr.Target)
                        {
                            World.instance.GetQuestLog(Character_ID, qr.Quest_ID).Status = QuestStatus.Finished;
                            qr = World.instance.GetQuestContentByNPCEntityID(Character_ID, NPC_ID, out Create);
                            SendData.QuestInteractConfirm(index, true, ql.Status, qr.NPC_ID, ql.Quest_ID);
                            SendData.UpdateQuestLog(ql);
                        }
                        else
                        {
                            SendData.QuestInteractConfirm(index, false);
                        }
                        break;

                    case QuestStatus.Complete:
                        SendData.QuestInteractConfirm(index, false);
                        break;

                    case QuestStatus.Finished:
                        World.instance.GetQuestLog(Character_ID, qr.Quest_ID).Status = QuestStatus.Complete;
                        qr = World.instance.GetQuestContentByNPCEntityID(Character_ID, NPC_ID, out Create);
                        SendData.QuestInteractConfirm(index, true, ql.Status, qr.NPC_ID, ql.Quest_ID);
                        SendData.UpdateQuestLog(ql);
                        if (World.instance.players.ContainsKey(Character_ID))
                        {
                            World.instance.players[Character_ID].experience += World.instance.quests[ql.Quest_ID].Experience;
                        }
                        // Get the next quest in the series
                        List <Quest> q = World.instance.GetAvailableQuests(Character_ID);
                        if (q != null && q.Count > 0)
                        {
                            foreach (Quest qu in q)
                            {
                                // Create a new quest log for it
                                Quest_Log newql = new Quest_Log(-1, Character_ID, qu.ID, QuestStatus.Available, 0);
                                // Update the synchronization server
                                SendData.CreateQuestLog(newql);
                                // Notify the client that a new quest is available
                                SendData.UpdateQuestLog(index, qu.ID, newql.Quest_Log_ID, World.instance.GetNPCEntityID(qu.NPC_Start_ID), newql.Status, newql.ObjectiveProgress, qu.Objective_Target);
                            }
                        }
                        break;

                    case QuestStatus.Available:
                        if (qr.Target == -1)
                        {
                            World.instance.GetQuestLog(Character_ID, qr.Quest_ID).Status = QuestStatus.Finished;
                            qr = World.instance.GetQuestContentByNPCEntityID(Character_ID, NPC_ID, out Create);
                            World.instance.UpdateQuestLog(Character_ID);
                        }
                        else
                        {
                            World.instance.GetQuestLog(Character_ID, qr.Quest_ID).Status = QuestStatus.InProgress;
                            qr = World.instance.GetQuestContentByNPCEntityID(Character_ID, NPC_ID, out Create);
                            World.instance.UpdateQuestLog(Character_ID);
                        }
                        SendData.QuestInteractConfirm(index, true, ql.Status, qr.NPC_ID, ql.Quest_ID);
                        SendData.UpdateQuestLog(ql);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    SendData.QuestInteractConfirm(index, false);
                }
            }
            else
            {
                SendData.QuestInteractConfirm(index, false);
            }
            World.instance.UpdateQuestLog(Character_ID);
        }
示例#2
0
        private static void Update(ConnectionType type, int index, byte[] data)
        {
            ByteBuffer.ByteBuffer buffer = new ByteBuffer.ByteBuffer();
            if (data.Length == 105)
            {
                buffer.WriteBytes(data);
                ReadHeader(ref buffer);
                // Connectivity Statistics
                Client client = Network.instance.Clients[index];
                client.TCP_Throughput = buffer.ReadFloat();
                client.TCP_SetLatency(buffer.ReadFloat());
                client.TCP_PacketsReceived = buffer.ReadInteger();
                client.UDP_Throughput      = buffer.ReadFloat();
                client.UDP_SetLatency(buffer.ReadFloat());
                client.UDP_PacketsReceived = buffer.ReadInteger();

                // ID
                int Character_ID = buffer.ReadInteger();
                // Position
                float X = buffer.ReadFloat();
                float Y = buffer.ReadFloat();
                float Z = buffer.ReadFloat();
                float R = buffer.ReadFloat();
                // Velocity
                float vx = buffer.ReadFloat();
                float vy = buffer.ReadFloat();
                float vz = buffer.ReadFloat();
                // Camera Position
                float cX = buffer.ReadFloat();
                float cY = buffer.ReadFloat();
                float cZ = buffer.ReadFloat();
                float cR = buffer.ReadFloat();
                // Animation State
                float Forward   = buffer.ReadFloat();
                float Turn      = buffer.ReadFloat();
                float Jump      = buffer.ReadFloat();
                float JumpLeg   = buffer.ReadFloat();
                byte  bools     = buffer.ReadByte();
                bool  Crouch    = false;
                bool  OnGround  = false;
                bool  Attacking = false;
                bool  Dead      = false;
                bool  Attacked  = false;
                bool  Cast      = false;
                bool  b6        = false; // Unused
                bool  b7        = false; // Unused
                BitwiseRefinement.ByteToBools(bools, out Crouch, out OnGround, out Attacking, out Dead, out Attacked, out Cast, out b6, out b7);
                // Target
                EntityType TargetType = (EntityType)buffer.ReadInteger();
                int        TargetID   = buffer.ReadInteger();

                if (World.instance.players.ContainsKey(Character_ID))
                {
                    Player player = World.instance.players[Character_ID];
                    // Position
                    player.position.x = X;
                    player.position.y = Y;
                    player.position.z = Z;
                    player.r          = R;
                    // Velocity
                    player.vx = vx;
                    player.vy = vy;
                    player.vz = vz;
                    // Camera Position and Rotation
                    player.Camera_Pos_X      = cX;
                    player.Camera_Pos_Y      = cY;
                    player.Camera_Pos_Z      = cZ;
                    player.Camera_Rotation_Y = cR;
                    // Animations
                    player.AnimState.Forward   = Forward;
                    player.AnimState.Turn      = Turn;
                    player.AnimState.Jump      = Jump;
                    player.AnimState.JumpLeg   = JumpLeg;
                    player.AnimState.Crouch    = Crouch;
                    player.AnimState.OnGround  = OnGround;
                    player.AnimState.Attacking = Attacking;
                    player.AnimState.Dead      = Dead;
                    player.AnimState.Attacked  = Attacked;
                    player.AnimState.Cast      = Cast;
                    // Target
                    player.TargetType = TargetType;
                    player.TargetID   = TargetID;
                    SendData.UpdatePlayerData(player);
                }
            }
        }