private void Read()
 {
     while (true)
     {
         _packet = _peer.Receive();
         while (_packet != null)
         {
             _peer.DeallocatePacket(_packet);
             _packet = _peer.Receive();
         }
         Thread.Sleep(10);
     }
 }
Esempio n. 2
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            byte wt = 0, starthour = 0, startminute = 0, endhour = 0, endminute;

            stream.Read(out wt);
            stream.Read(out starthour);
            stream.Read(out startminute);
            stream.Read(out endhour);
            stream.Read(out endminute);

            sWorld.WeatherType     = wt;
            sWorld.StartRainHour   = starthour;
            sWorld.StartRainMinute = startminute;
            sWorld.EndRainHour     = endhour;
            sWorld.EndRainMinute   = endminute;


            if (!(Program._state is GUC.States.GameState))
            {
                return;
            }

            Process process = Process.ThisProcess();

            if (sWorld.WeatherType != 2)
            {
                oCGame.Game(process).World.SkyControlerOutdoor.SetWeatherType(sWorld.WeatherType);
            }
            oCGame.Game(process).World.SkyControlerOutdoor.setRainTime(sWorld.StartRainHour, sWorld.StartRainMinute, sWorld.EndRainHour, sWorld.EndRainMinute);
            if (sWorld.WeatherType != 2)
            {
                oCGame.Game(process).World.SkyControlerOutdoor.SetWeatherType(wt);
            }

            //oCGame.Game(process).WorldTimer.SetTime(hour, minute);
        }
Esempio n. 3
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            int vobID = 0;

            stream.Read(out vobID);

            if (vobID == 0 || !sWorld.VobDict.ContainsKey(vobID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[vobID];

            if (vob.Address == 0)
            {
                return;
            }

            Process process = Process.ThisProcess();

            oCGame.Game(process).AICamera.SetTarget(new zCVob(process, vob.Address));


            CamToPlayerFront.destroyPlayerVob();
        }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            int      playerID  = 0;
            Vob      playerVob = null;
            NPCProto player    = null;

            stream.Read(out playerID);

            sWorld.VobDict.TryGetValue(playerID, out playerVob);
            if (playerVob == null)
            {
                throw new Exception("Vob was not found: " + playerID);
            }
            if (!(playerVob is NPCProto))
            {
                throw new Exception("Vob was not a NPCProto: " + playerID + " " + playerVob);
            }

            player = (NPCProto)playerVob;

            if (player.Address == 0)
            {
                return;
            }
            Process process = Process.ThisProcess();

            oCNpc npc = new oCNpc(process, player.Address);

            if (player.FocusVob != null && player.FocusVob.Address != 0)
            {
                npc.MagBook.Spell_Setup(npc, new zCVob(process, player.FocusVob.Address), 0);
            }
            npc.MagBook.Spell_Invest();

            zERROR.GetZErr(process).Report(2, 'G', "Invest Spell! ", 0, "Program.cs", 0);
        }
Esempio n. 5
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int plID = 0;

            stream.Read(out plID);

            byte keyCounts = 0;

            stream.Read(out keyCounts);
            Dictionary <byte, byte> keys = new Dictionary <byte, byte>();

            for (int i = 0; i < keyCounts; i++)
            {
                byte key   = 0;
                byte value = 0;
                stream.Read(out key);
                stream.Read(out value);

                keys.Add(key, value);
            }

            if (plID == 0 || !sWorld.VobDict.ContainsKey(plID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[plID];

            if (!(vob is Player))
            {
                throw new Exception("Vob is not a Player!");
            }

            Player proto = (Player)vob;

            Scripting.Objects.Character.Player.sOnPlayerKey((Scripting.Objects.Character.Player)proto.ScriptingNPC, keys);
        }
Esempio n. 6
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            String name = "";
            int    plID = 0;

            stream.Read(out plID);
            stream.Read(out name);

            if (plID == 0 || !sWorld.VobDict.ContainsKey(plID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[plID];

            if (!(vob is NPCProto))
            {
                throw new Exception("Vob is not an NPC!");
            }
            ((NPCProto)vob).Name = name;

            if (vob.Address == 0)
            {
                return;
            }
            Process process = Process.ThisProcess();
            oCNpc   pl      = new oCNpc(process, vob.Address);

            if (((NPCProto)vob).hideName)
            {
                pl.Name.Set("");
            }
            else
            {
                pl.Name.Set(name);
            }
        }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            String animation = "";
            byte   start     = 0;
            int    plID      = 0;

            stream.Read(out plID);
            stream.Read(out animation);
            stream.Read(out start);

            if (plID == 0 || !sWorld.VobDict.ContainsKey(plID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[plID];

            if (!(vob is NPCProto))
            {
                throw new Exception("Vob is not a NPC!");
            }

            NPCProto npcProto = (NPCProto)vob;

            if (start == 1 && !npcProto.AnimationList.Contains(animation))
            {
                npcProto.AnimationList.Add(animation);
            }
            else if (start == 0 && npcProto.AnimationList.Contains(animation))
            {
                npcProto.AnimationList.Remove(animation);
            }
            else if (start == 2)
            {
                npcProto.Overlays.Add(animation);
            }
            else if (start == 3)
            {
                npcProto.Overlays.Remove(animation);
            }
            else if (start == 4)
            {
                npcProto.Overlays.Clear();
            }
            else if (start == 5 && vob.Address == 0)
            {
                npcProto.AnimationList.Clear();
            }


            if (vob.Address == 0)
            {
                return;
            }

            Process process = Process.ThisProcess();
            oCNpc   npc     = new oCNpc(process, vob.Address);


            zString str = zString.Create(process, animation);

            if (start == 1)
            {
                npc.GetModel().StartAnimation(str);
            }
            else if (start == 0)
            {
                npc.GetModel().StopAnimation(str);
            }
            else if (start == 2)
            {
                npc.ApplyOverlay(str);
            }
            else if (start == 3)
            {
                npc.RemoveOverlay(str);
            }
            else if (start == 4)
            {
                zCArray <zString> overlays = npc.ActiveOverlays;
                int size = overlays.Size;
                for (int i = size - 1; i >= 0; i--)
                {
                    npc.RemoveOverlay(overlays.get(i));
                }
            }
            else if (start == 5)
            {
                foreach (String iAnim in npcProto.AnimationList)
                {
                    zString iStr = zString.Create(process, iAnim);
                    npc.GetModel().StopAnimation(iStr);
                    iStr.Dispose();
                }
                npcProto.AnimationList.Clear();
            }
            str.Dispose();
        }
Esempio n. 8
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            String visual = "", BodyMesh = "", HeadMesh = "";
            int    plID = 0, bodyTex = 0, skinColor = 0, headTex = 0, teethTex = 0;



            stream.Read(out plID);

            if (plID == 0 || !sWorld.VobDict.ContainsKey(plID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[plID];

            if (vob is NPCProto)
            {
                NPCProto npcP = (NPCProto)vob;
                stream.Read(out visual);
                stream.Read(out BodyMesh);
                stream.Read(out bodyTex);
                stream.Read(out skinColor);
                stream.Read(out HeadMesh);
                stream.Read(out headTex);
                stream.Read(out teethTex);



                npcP.SetVisual(visual, BodyMesh, HeadMesh, bodyTex, skinColor, headTex, teethTex);



                //bool visualSame = false;
                //if (vob.Visual.ToUpper().Trim() == visual.ToUpper().Trim())
                //    visualSame = true;
                //vob.Visual = visual;

                //npcP.BodyMesh = BodyMesh;
                //npcP.BodyTex = bodyTex;
                //npcP.SkinColor = skinColor;
                //npcP.HeadMesh = HeadMesh;
                //npcP.HeadTex = headTex;
                //npcP.TeethTex = teethTex;

                //if (!visualSame && visual.ToUpper().Trim() != "HUMANS.MDS")
                //    npcP.setWeaponMode(1);

                //if (vob.Address == 0)
                //    return;

                //if (!visualSame)
                //{
                //    int oldAdress = npcP.Address;
                //    npcP.Despawn();
                //    npcP.Spawn(npcP.Map, npcP.Position, npcP.Direction);
                //    if (Player.Hero == npcP)
                //    {
                //        new oCNpc(Process.ThisProcess(), npcP.Address).SetAsPlayer();

                //        if (oldAdress != 0)
                //        {
                //            new oCNpc(Process.ThisProcess(), oldAdress).Disable();
                //        }
                //    }
                //    npcP.Enable(npcP.Position);



                //    return;
                //}



                //Process process = Process.ThisProcess();
                //zCVob zVob = new zCVob(Process.ThisProcess(), vob.Address);

                //oCNpc npc = new oCNpc(process, vob.Address);

                //npc.SetAdditionalVisuals(BodyMesh, bodyTex, skinColor, HeadMesh, headTex, teethTex, -1);
            }
        }
Esempio n. 9
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            int  vobID = 0, playerID = 0;
            byte mobInterTypeInt = 0;
            char mobInterKey     = '0';

            short startChangeState0 = 0, startChangeState1 = 1;

            stream.Read(out mobInterTypeInt);
            stream.Read(out playerID);
            stream.Read(out vobID);

            MobInterNetwork mobInterFlags = (MobInterNetwork)mobInterTypeInt;

            if (mobInterFlags.HasFlag(MobInterNetwork.PickLock))
            {
                stream.Read(out mobInterKey);
            }

            if (mobInterFlags.HasFlag(MobInterNetwork.StartStateChange))
            {
                stream.Read(out startChangeState0);
                stream.Read(out startChangeState1);
            }

            if (playerID == 0 || !sWorld.VobDict.ContainsKey(playerID))
            {
                throw new Exception("Player not found!");
            }
            Vob plVob = sWorld.VobDict[playerID];

            if (!(plVob is NPCProto))
            {
                throw new Exception("PlayerVob was not from type Player: " + plVob);
            }
            NPCProto player = (NPCProto)plVob;

            if (vobID == 0 || !sWorld.VobDict.ContainsKey(vobID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[vobID];

            if (!(vob is MobInter))
            {
                throw new Exception("Vob was not from type MobInter: " + vob);
            }


            MobInter mob     = (MobInter)vob;
            Process  process = Process.ThisProcess();

            if (mobInterFlags == MobInterNetwork.PickLock)
            {
                if (!(vob is MobLockable))
                {
                    throw new Exception("Vob was not from type MobLockable: " + vob);
                }
            }
            else if (mobInterFlags == MobInterNetwork.OnTrigger)
            {
                mob.State = 1;
                if (mob.Address != 0)
                {
                    oCMobInter mI = new oCMobInter(process, mob.Address);

                    //mI.GetModel().StartAnimation("T_S0_2_S1");

                    mI.OnTrigger(new zCVob(process, mI.Address), new zCVob(process, player.Address));
                    //mI.State = 1;


                    //mI.StateAniID = mI.GetModel().GetAniIDFromAniName("S_S1");
                }
            }
            else if (mobInterFlags == MobInterNetwork.OnUnTrigger)
            {
                mob.State = 0;
                if (mob.Address != 0)
                {
                    oCMobInter mI = new oCMobInter(process, mob.Address);
                    //mI.GetModel().StartAnimation("T_S1_2_S0");
                    mI.OnUnTrigger(new zCVob(process, mI.Address), new zCVob(process, player.Address));
                    //mI.State = 0;


                    //mI.StateAniID = mI.GetModel().GetAniIDFromAniName("S_S0");
                    //mI.StateAniID = mI.GetModel().
                }
            }
            else if (mobInterFlags == MobInterNetwork.StartInteraction)
            {
                if (mob.Address != 0)
                {
                    new oCMobInter(process, mob.Address).StartInteraction(new oCNpc(process, player.Address));
                }
            }
            else if (mobInterFlags == MobInterNetwork.StopInteraction)
            {
                if (mob.Address != 0)
                {
                    new oCMobInter(process, mob.Address).StopInteraction(new oCNpc(process, player.Address));
                }
            }
            else if (mobInterFlags == MobInterNetwork.StartStateChange)
            {
                if (mob.Address != 0)
                {
                    oCMobInter mI = new oCMobInter(process, mob.Address);
                    mI.StartStateChange(new oCNpc(process, player.Address), startChangeState0, startChangeState1);
                }
            }
        }
Esempio n. 10
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            byte type = 0;

            stream.Read(out type);
            GuiMessageType gmT = (GuiMessageType)type;

            int viewID = 0;

            if (gmT == GuiMessageType.Show)
            {
                stream.Read(out viewID);
                View v = getViewFromList(viewID);

                v.show();
            }
            else if (gmT == GuiMessageType.Hide)
            {
                stream.Read(out viewID);
                View v = getViewFromList(viewID);

                v.hide();
            }
            else if (gmT == GuiMessageType.SetPosition)
            {
                Vec2i position;
                stream.Read(out viewID);
                stream.Read(out position);
                View v = getViewFromList(viewID);

                v.setPosition(position);
            }
            else if (gmT == GuiMessageType.Destroy)
            {
                stream.Read(out viewID);
                View v = getViewFromList(viewID);

                v.Destroy();
            }//Creation:
            else if (gmT == GuiMessageType.CreateTexture)
            {
                Vec2i  position, size;
                string texture;
                int    parentID  = 0;
                int    guiEvents = 0;

                stream.Read(out viewID);
                stream.Read(out position);
                stream.Read(out size);
                stream.Read(out texture);
                stream.Read(out parentID);
                stream.Read(out guiEvents);

                Texture tex = new Texture(viewID, texture, position, size, getTextureParentFromList(parentID), (GUIEvents)guiEvents);
                viewList.Add(viewID, tex);
            }
            else if (gmT == GuiMessageType.CreateText)
            {
                Vec2i     position;
                string    text, font;
                ColorRGBA color;
                int       parentID = 0;

                stream.Read(out viewID);
                stream.Read(out position);
                stream.Read(out text);
                stream.Read(out font);
                stream.Read(out color);
                stream.Read(out parentID);

                Text textView = new Text(viewID, text, font, position, getTextureParentFromList(parentID), color);
                viewList.Add(viewID, textView);
            }
            else if (gmT == GuiMessageType.CreateTextBox)
            {
                Vec2i     position;
                string    text, font;
                ColorRGBA color;
                int       parentID = 0, sendKey, startWriteKey, resetKey;

                stream.Read(out viewID);
                stream.Read(out position);
                stream.Read(out text);
                stream.Read(out font);
                stream.Read(out color);
                stream.Read(out sendKey);
                stream.Read(out startWriteKey);
                stream.Read(out resetKey);
                stream.Read(out parentID);

                TextBox textView = new TextBox(viewID, text, font, position, getTextureParentFromList(parentID), color, resetKey, startWriteKey, sendKey);
                viewList.Add(viewID, textView);
            }
            else if (gmT == GuiMessageType.CreateTextArea)
            {
                Vec2i     position, size;
                string    text, font;
                ColorRGBA color;
                int       parentID = 0, sendKey, startWriteKey, resetKey;

                stream.Read(out viewID);
                stream.Read(out position);
                stream.Read(out size);
                stream.Read(out text);
                stream.Read(out font);
                stream.Read(out color);
                stream.Read(out sendKey);
                stream.Read(out startWriteKey);
                stream.Read(out resetKey);
                stream.Read(out parentID);

                TextArea textView = new TextArea(viewID, text, font, position, size, getTextureParentFromList(parentID), color, resetKey, startWriteKey, sendKey);
                viewList.Add(viewID, textView);
            }
            else if (gmT == GuiMessageType.CreateMessageBox)
            {
                Vec2i  position;
                int    parentID = 0;
                String font;
                byte   lines;

                stream.Read(out viewID);
                stream.Read(out position);
                stream.Read(out parentID);
                stream.Read(out font);
                stream.Read(out lines);

                MessageBox messageBox = new MessageBox(viewID, lines, font, position, getTextureParentFromList(parentID));
                viewList.Add(viewID, messageBox);
            }
            else if (gmT == GuiMessageType.CreateCursor)
            {
                Vec2i  position, size;
                string texture;
                int    parentID = 0;

                stream.Read(out viewID);
                stream.Read(out position);
                stream.Read(out size);
                stream.Read(out texture);
                stream.Read(out parentID);



                Cursor tex = new Cursor(viewID, texture, position, size);
                viewList.Add(viewID, tex);
            }
            else if (gmT == GuiMessageType.CreateButton)
            {
                Vec2i     position, size;
                string    texture, text, font;
                int       parentID = 0;
                ColorRGBA color;
                int       guiEvents = 0;

                stream.Read(out viewID);
                stream.Read(out position);
                stream.Read(out size);
                stream.Read(out text);
                stream.Read(out texture);
                stream.Read(out font);
                stream.Read(out color);


                stream.Read(out parentID);
                stream.Read(out guiEvents);


                Button tex = new Button(viewID, text, texture, font, color, position, size, getTextureParentFromList(parentID), (GUIEvents)guiEvents);
                viewList.Add(viewID, tex);
            }
            else if (gmT == GuiMessageType.CreateList)
            {
                Vec2i  position, size;
                string texture, font;
                int    parentID  = 0;
                int    guiEvents = 0;
                byte   lines     = 0;


                stream.Read(out viewID);
                stream.Read(out position);
                stream.Read(out size);
                stream.Read(out texture);
                stream.Read(out parentID);
                //stream.Read(out guiEvents);
                stream.Read(out lines);
                stream.Read(out font);

                GUI.GuiList.List tex = new GUI.GuiList.List(viewID, lines, font, position, size, texture, getTextureParentFromList(parentID), (GUIEvents)guiEvents);
                viewList.Add(viewID, tex);
            }
            else if (gmT == GuiMessageType.CreateListText)
            {
                String    text = "";
                int       parentID = 0;
                ColorRGBA activeColor, inactiveColor;


                stream.Read(out viewID);
                stream.Read(out text);
                stream.Read(out parentID);
                stream.Read(out activeColor);
                stream.Read(out inactiveColor);


                GUI.GuiList.List     list        = getListParentFromList(parentID);
                GUI.GuiList.ListText listelement = new GUI.GuiList.ListText(viewID, text, list, activeColor, inactiveColor);
                list.addRow(listelement);
                viewList.Add(viewID, listelement);
            }
            else if (gmT == GuiMessageType.CreateListButton)
            {
                String    text = "";
                int       parentID = 0;
                ColorRGBA activeColor, inactiveColor;

                stream.Read(out viewID);
                stream.Read(out text);
                stream.Read(out parentID);

                stream.Read(out activeColor);
                stream.Read(out inactiveColor);


                GUI.GuiList.List       list        = getListParentFromList(parentID);
                GUI.GuiList.ListButton listelement = new GUI.GuiList.ListButton(viewID, text, list, activeColor, inactiveColor);
                list.addRow(listelement);
                viewList.Add(viewID, listelement);
            }
            else if (gmT == GuiMessageType.CreateListTextBox)
            {
                String    text = "";
                String    hardText = "";
                int       parentID = 0;
                ColorRGBA activeColor, inactiveColor;


                stream.Read(out viewID);

                stream.Read(out hardText);
                stream.Read(out text);

                stream.Read(out parentID);

                stream.Read(out activeColor);
                stream.Read(out inactiveColor);


                GUI.GuiList.List        list        = getListParentFromList(parentID);
                GUI.GuiList.ListTextBox listelement = new GUI.GuiList.ListTextBox(viewID, hardText, text, list, activeColor, inactiveColor);
                list.addRow(listelement);
                viewList.Add(viewID, listelement);
            }
            else if (gmT == GuiMessageType.CreateText3D)
            {
                Vec3f  position;
                float  maxDistance;
                int    parentID = 0;
                String world    = "";

                stream.Read(out viewID);
                stream.Read(out position);
                stream.Read(out world);
                stream.Read(out maxDistance);
                stream.Read(out parentID);

                int rowCount = 0;
                stream.Read(out rowCount);

                Text3D textView = new Text3D(viewID, world, maxDistance, position);
                for (int i = 0; i < rowCount; i++)
                {
                    String    text = "";
                    ColorRGBA color = ColorRGBA.White;
                    long      time = 0, blendTime;

                    stream.Read(out text);
                    stream.Read(out color);
                    stream.Read(out time);
                    stream.Read(out blendTime);

                    textView.addRow(new Text3D.Text3DRow()
                    {
                        Text = text, Color = color, Time = time, BlendTime = blendTime
                    });
                }


                viewList.Add(viewID, textView);
            }
            else if (gmT == GuiMessageType.CreateTextPlayer)
            {
                int   playerID = 0;
                float maxDistance;
                int   parentID = 0;


                stream.Read(out viewID);
                stream.Read(out playerID);
                stream.Read(out maxDistance);
                stream.Read(out parentID);

                int rowCount = 0;
                stream.Read(out rowCount);

                Vob vob = null;
                if (!sWorld.VobDict.TryGetValue(playerID, out vob))
                {
                    throw new Exception("Player id:" + playerID + " was not found!");
                }
                if (!(vob is Player))
                {
                    throw new Exception("Vob is not a Player: " + playerID + " " + vob);
                }

                PlayerText textView = new PlayerText(viewID, (Player)vob, maxDistance);
                for (int i = 0; i < rowCount; i++)
                {
                    String    text = "";
                    ColorRGBA color = ColorRGBA.White;
                    long      time = 0, blendTime;

                    stream.Read(out text);
                    stream.Read(out color);
                    stream.Read(out time);
                    stream.Read(out blendTime);

                    textView.addRow(new Text3D.Text3DRow()
                    {
                        Text = text, Color = color, Time = time, BlendTime = blendTime
                    });
                }


                viewList.Add(viewID, textView);
            }
            else if (gmT == GuiMessageType.Text3DAddRow)
            {
                String    text = "";
                ColorRGBA color = ColorRGBA.White;
                long      time = 0, blendTime = 0;

                stream.Read(out viewID);
                stream.Read(out text);
                stream.Read(out color);
                stream.Read(out time);
                stream.Read(out blendTime);

                View v = getViewFromList(viewID);

                if (!(v is Text3D))
                {
                    throw new Exception("Text3DAddRow works only with a Text3D!: " + v);
                }

                Text3D t3d = (Text3D)v;
                t3d.addRow(new Text3D.Text3DRow()
                {
                    Text = text, Color = color, Time = time, BlendTime = blendTime
                });
            }
            else if (gmT == GuiMessageType.Text3DClear)
            {
                stream.Read(out viewID);
                View v = getViewFromList(viewID);

                if (!(v is Text3D))
                {
                    throw new Exception("Text3DAddRow works only with a Text3D!: " + v);
                }

                Text3D t3d = (Text3D)v;
                t3d.Clear();
            }
            else if (gmT == GuiMessageType.Text3DPosition)
            {
                Vec3f position = new Vec3f();
                stream.Read(out viewID);
                stream.Read(out position);
                View v = getViewFromList(viewID);

                if (!(v is Text3D))
                {
                    throw new Exception("Text3DAddRow works only with a Text3D!: " + v);
                }

                Text3D t3d = (Text3D)v;
                t3d.setPosition(position);
            }
            //Texture:
            else if (gmT == GuiMessageType.SetTexture)
            {
                String texture = "";

                stream.Read(out viewID);
                stream.Read(out texture);
                View v = getViewFromList(viewID);

                if (!(v is Texture) && !(v is Button))
                {
                    throw new Exception("SetTexture works only with a texture or buttons!: " + v);
                }
                Texture tex = (Texture)v;
                tex.setTexture(texture);
            }
            else if (gmT == GuiMessageType.SetSize)
            {
                Vec2i position;

                stream.Read(out viewID);
                stream.Read(out position);
                View v = getViewFromList(viewID);

                if (!(v is Texture) && !(v is Button))
                {
                    throw new Exception("SetSize works only with a texture or buttons!: " + v);
                }
                Texture tex = (Texture)v;
                tex.setSize(position);
            }//Text&TextBox:
            else if (gmT == GuiMessageType.SetText)
            {
                String text = "";

                stream.Read(out viewID);
                stream.Read(out text);
                View v = getViewFromList(viewID);

                if (!(v is Text) && !(v is TextBox) && !(v is TextArea) && !(v is Button))
                {
                    throw new Exception("SetText works only with a text and textbox!: " + v);
                }

                if (v is Text)
                {
                    Text tex = (Text)v;
                    tex.setText(text);
                }
                else if (v is TextBox)
                {
                    TextBox tex = (TextBox)v;
                    tex.setText(text);
                }
                else if (v is TextArea)
                {
                    TextArea tex = (TextArea)v;
                    tex.setText(text);
                }
                else if (v is Button)
                {
                    Button button = (Button)v;
                    button.setText(text);
                }
            }
            else if (gmT == GuiMessageType.SetTextFont)
            {
                String font = "";

                stream.Read(out viewID);
                stream.Read(out font);
                View v = getViewFromList(viewID);

                if (!(v is Text) && !(v is TextBox))
                {
                    throw new Exception("SetFont works only with a text and textbox!: " + v);
                }

                if (v is Text)
                {
                    Text tex = (Text)v;
                    tex.setFont(font);
                }
                else if (v is TextBox)
                {
                    TextBox tex = (TextBox)v;
                    tex.setFont(font);
                }
            }
            else if (gmT == GuiMessageType.SetTextColor)
            {
                ColorRGBA color;

                stream.Read(out viewID);
                stream.Read(out color);
                View v = getViewFromList(viewID);

                if (!(v is Text) && !(v is TextBox) && !(v is TextArea))
                {
                    throw new Exception("SetColor works only with a text and textbox!: " + v);
                }

                if (v is Text)
                {
                    Text tex = (Text)v;
                    tex.setColor(color);
                }
                else if (v is TextBox)
                {
                    TextBox tex = (TextBox)v;
                    tex.setColor(color);
                }
                else if (v is TextArea)
                {
                    TextArea tex = (TextArea)v;
                    tex.setColor(color);
                }
            }//TextBox!
            else if (gmT == GuiMessageType.TextBoxStartWriting)
            {
                stream.Read(out viewID);
                View v = getViewFromList(viewID);

                if (!(v is TextBox) && !(v is TextArea))
                {
                    throw new Exception("TextBoxStartWriting works only with a textbox!: " + v);
                }

                if (v is TextBox)
                {
                    TextBox tex = (TextBox)v;
                    tex.startWriting();
                }
                else if (v is TextArea)
                {
                    TextArea tex = (TextArea)v;
                    tex.startWriting();
                }
            }
            else if (gmT == GuiMessageType.TextBoxStopWriting)
            {
                stream.Read(out viewID);
                View v = getViewFromList(viewID);

                if (!(v is TextBox) && !(v is TextArea))
                {
                    throw new Exception("TextBoxStartWriting works only with a textbox!: " + v);
                }

                if (v is TextBox)
                {
                    TextBox tex = (TextBox)v;
                    tex.stopWriting();
                }
                else if (v is TextArea)
                {
                    TextArea tex = (TextArea)v;
                    tex.stopWriting();
                }
            }
            else if (gmT == GuiMessageType.TextBoxCallSend)
            {
                stream.Read(out viewID);
                View v = getViewFromList(viewID);

                if (!(v is TextBox) && !(v is TextArea))
                {
                    throw new Exception("TextBoxStartWriting works only with a textbox!: " + v);
                }

                if (v is TextBox)
                {
                    TextBox tex = (TextBox)v;
                    tex.callSendText();
                }
                else if (v is TextArea)
                {
                    TextArea tex = (TextArea)v;
                    tex.callSendText();
                }
            }
            else if (gmT == GuiMessageType.TextBoxSetStartWritingKey)
            {
                int key = 0;
                stream.Read(out viewID);
                stream.Read(out key);
                View v = getViewFromList(viewID);

                if (!(v is TextBox) && !(v is TextArea))
                {
                    throw new Exception("TextBoxStartWriting works only with a textbox!: " + v);
                }

                if (v is TextBox)
                {
                    TextBox tex = (TextBox)v;
                    tex.setEnableKey(key);
                }
                else if (v is TextArea)
                {
                    TextArea tex = (TextArea)v;
                    tex.setEnableKey(key);
                }
            }
            else if (gmT == GuiMessageType.TextBoxSetSendKey)
            {
                int key = 0;
                stream.Read(out viewID);
                stream.Read(out key);
                View v = getViewFromList(viewID);

                if (!(v is TextBox) && !(v is TextArea))
                {
                    throw new Exception("TextBoxStartWriting works only with a textbox!: " + v);
                }

                if (v is TextBox)
                {
                    TextBox tex = (TextBox)v;
                    tex.setSendKey(key);
                }
                else if (v is TextArea)
                {
                    TextArea tex = (TextArea)v;
                    tex.setSendKey(key);
                }
            }
            else if (gmT == GuiMessageType.TextBoxSetResetKey)
            {
                int key = 0;
                stream.Read(out viewID);
                stream.Read(out key);
                View v = getViewFromList(viewID);

                if (!(v is TextBox) && !(v is TextArea))
                {
                    throw new Exception("TextBoxStartWriting works only with a textbox!: " + v);
                }


                if (v is TextBox)
                {
                    TextBox tex = (TextBox)v;
                    tex.setResetKey(key);
                }
                else if (v is TextArea)
                {
                    TextArea tex = (TextArea)v;
                    tex.setResetKey(key);
                }
            }//MessageBox:
            else if (gmT == GuiMessageType.MessageBoxAddLine)
            {
                String    message;
                ColorRGBA color;
                stream.Read(out viewID);
                stream.Read(out color);
                stream.Read(out message);
                View v = getViewFromList(viewID);

                if (!(v is MessageBox))
                {
                    throw new Exception("TextBoxStartWriting works only with a textbox!: " + v);
                }

                MessageBox tex = (MessageBox)v;
                tex.addMessage(message, color);
            }
        }
 public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
 {
 }
Esempio n. 12
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            byte type = 0;
            int  itemID = 0, playerID = 0, mobContainerID, amount = 0;

            stream.Read(out type);
            stream.Read(out playerID);
            stream.Read(out mobContainerID);
            stream.Read(out itemID);

            if (!sWorld.VobDict.ContainsKey(playerID))
            {
                throw new Exception("Player ID was not found: " + playerID);
            }
            NPCProto npc = (NPCProto)sWorld.VobDict[playerID];

            if (!sWorld.VobDict.ContainsKey(mobContainerID))
            {
                throw new Exception("MobContainer ID was not found: " + mobContainerID);
            }
            IContainer mobContainer = (IContainer)sWorld.VobDict[mobContainerID];


            ContainerItemChanged cic = (ContainerItemChanged)type;


            if (cic == ContainerItemChanged.itemRemoved)
            {
                stream.Read(out amount);
                if (!sWorld.VobDict.ContainsKey(itemID))
                {
                    throw new Exception("Item ID was not found: " + itemID);
                }

                Item item = (Item)sWorld.VobDict[itemID];


                if (item.ItemInstance.Flags.HasFlag(Flags.ITEM_MULTI))
                {
                    if (item.Amount - amount <= 0)
                    {
                        Item itemInInventory = npc.getItemByInstance(item.ItemInstance);
                        if (itemInInventory == null)
                        {
                            itemInInventory = item;
                            item.ScriptingProto.toContainer(npc.ScriptingNPC);
                        }
                        else
                        {
                            itemInInventory.ScriptingProto.Amount += amount;
                            item.ScriptingProto.Amount             = 0;
                        }

                        UpdateMobContainer(amount, npc, mobContainer, itemInInventory);
                    }
                    else
                    {
                        Item itemInInventory = npc.HasItem(item.ItemInstance.ID);
                        if (itemInInventory == null)
                        {
                            itemInInventory             = npc.ScriptingNPC.addItem(item.ItemInstance.ScriptingProto, amount).ProtoItem;
                            item.ScriptingProto.Amount -= amount;
                        }
                        else
                        {
                            itemInInventory.ScriptingProto.Amount += amount;
                            item.ScriptingProto.Amount            -= amount;
                        }

                        UpdateMobContainer(amount, npc, mobContainer, itemInInventory);
                    }
                }
                else
                {
                    item.ScriptingProto.toContainer(npc.ScriptingNPC);

                    UpdateMobContainer(item.Amount, npc, mobContainer, item);
                }
            }
            else if (cic == ContainerItemChanged.itemInsertedOld)
            {
                if (!sWorld.VobDict.ContainsKey(itemID))
                {
                    throw new Exception("Item ID was not found: " + itemID);
                }
                Item item = (Item)sWorld.VobDict[itemID];

                if (item.ItemInstance.Flags.HasFlag(Flags.ITEM_MULTI))
                {
                    Item        gI     = null;
                    List <Item> imList = null;
                    if (mobContainer is MobContainer)
                    {
                        imList = ((MobContainer)mobContainer).itemList;
                    }
                    else
                    {
                        imList = ((NPCProto)mobContainer).ItemList;
                    }
                    foreach (Item i in imList)
                    {
                        if (i.ItemInstance == item.ItemInstance)
                        {
                            gI = i;
                            break;
                        }
                    }
                    if (gI == null)
                    {
                        if (mobContainer is MobContainer)
                        {
                            item.ScriptingProto.toContainer((Scripting.Objects.Mob.MobContainer)((MobContainer)mobContainer).ScriptingVob);
                        }
                        else if (mobContainer is NPCProto)
                        {
                            item.ScriptingProto.toContainer(((NPCProto)mobContainer).ScriptingNPC);
                        }

                        UpdateMobContainer(item.Amount, npc, mobContainer, item);
                    }
                    else
                    {
                        int _amount = item.Amount;
                        gI.ScriptingProto.Amount  += item.Amount;
                        item.ScriptingProto.Amount = 0;

                        UpdateMobContainer(_amount, npc, mobContainer, gI);
                    }
                }
                else
                {
                    if (mobContainer is MobContainer)
                    {
                        item.ScriptingProto.toContainer((Scripting.Objects.Mob.MobContainer)((MobContainer)mobContainer).ScriptingVob);
                    }
                    else if (mobContainer is NPCProto)
                    {
                        item.ScriptingProto.toContainer(((NPCProto)mobContainer).ScriptingNPC);
                    }

                    UpdateMobContainer(item.Amount, npc, mobContainer, item);
                }
            }
            else if (cic == ContainerItemChanged.itemInsertedNew)
            {
                if (!ItemInstance.ItemInstanceDict.ContainsKey(itemID))
                {
                    throw new Exception("Iteminstance ID was not found: " + itemID);
                }
                ItemInstance item = (ItemInstance)ItemInstance.ItemInstanceDict[itemID];

                Item newItem = null;
                if (mobContainer is MobContainer)
                {
                    newItem = ((Scripting.Objects.Mob.MobContainer)((MobContainer)mobContainer).ScriptingVob).addItem(item.ScriptingProto, 1).ProtoItem;
                }
                else if (mobContainer is NPCProto)
                {
                    newItem = (((NPCProto)mobContainer).ScriptingNPC).addItem(item.ScriptingProto, 1).ProtoItem;
                }

                Item i = npc.getItemByInstance(item);
                if (i == null)
                {
                    throw new Exception("NPC has not the item: " + item.ID);
                }
                i.ScriptingProto.Amount -= 1;

                UpdateMobContainer(1, npc, mobContainer, newItem);
            }
        }
Esempio n. 13
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int  playerID = 0;
            byte type     = 0;

            stream.Read(out type);
            stream.Read(out playerID);

            Player pl = (Player)sWorld.VobDict[playerID];

            GuiMessageType gmT    = (GuiMessageType)type;
            int            viewID = 0;

            if (gmT == GuiMessageType.TextBoxCallSend)
            {
                String message;
                stream.Read(out viewID);
                stream.Read(out message);

                View v = getViewFromList(viewID);
                if (!(v is TextBox))
                {
                    throw new Exception("TextBoxCallSend needs a TextBox " + v);
                }
                TextBox tex = (TextBox)v;
                TextBox.OnTextSends(tex, (Scripting.Objects.Character.Player)pl.ScriptingNPC, message);
            }
            else if (gmT == GuiMessageType.ButtonPressed)
            {
                stream.Read(out viewID);

                View v = getViewFromList(viewID);
                if (!(v is Button))
                {
                    throw new Exception("ButtonPressed needs a Button " + v);
                }
                Button button = (Button)v;
                Button.OnButtonPress(button, (Scripting.Objects.Character.Player)pl.ScriptingNPC);
            }
            else if (gmT == GuiMessageType.GuiEvent)
            {
                int guiEvent = 0;
                stream.Read(out viewID);
                stream.Read(out guiEvent);

                GUIEvents evt = (GUIEvents)guiEvent;

                View v = getViewFromList(viewID);


                if (evt.HasFlag(GUIEvents.LeftClicked))
                {
                    if ((v is Button))
                    {
                        Button button = (Button)v;
                        Button.OnButtonPress(button, (Scripting.Objects.Character.Player)pl.ScriptingNPC);
                    }
                    Texture tex = (Texture)v;
                    Texture.isOnLeftClick(tex, (Scripting.Objects.Character.Player)pl.ScriptingNPC);
                }
                else if (evt.HasFlag(GUIEvents.RightClicked))
                {
                    Texture.isOnRightClick((Texture)v, (Scripting.Objects.Character.Player)pl.ScriptingNPC);
                }
                else if (evt.HasFlag(GUIEvents.Hover))
                {
                    bool hover = false;
                    stream.Read(out hover);
                    Texture.isOnHover((Texture)v, (Scripting.Objects.Character.Player)pl.ScriptingNPC, hover);
                }
                else if (evt.HasFlag(GUIEvents.ListButtonClicked))
                {
                    Scripting.GUI.GuiList.ListButton.isOnClick((Scripting.GUI.GuiList.ListButton)v, (Scripting.Objects.Character.Player)pl.ScriptingNPC);
                    //Texture.isOnHover((Texture)v, (Scripting.Objects.Character.Player)pl.ScriptingNPC, hover);
                }
                else if (evt.HasFlag(GUIEvents.ListTextBoxSend))
                {
                    String text = "";
                    stream.Read(out text);
                    Scripting.GUI.GuiList.ListTextBox.isOnTextSend((Scripting.GUI.GuiList.ListTextBox)v, (Scripting.Objects.Character.Player)pl.ScriptingNPC, text);
                    //Texture.isOnHover((Texture)v, (Scripting.Objects.Character.Player)pl.ScriptingNPC, hover);
                }
            }
        }
 public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
 {
     CGameManager.ExitGameFunc(Process.ThisProcess());
 }