Ejemplo n.º 1
0
        CString setProps(CString pProps, int clientVersion)
        {
            CString ret = new CString();
            int len = 0;
            while (pProps.BytesLeft > 0)
            {
                char propId = pProps.readGUChar();
                CString oldProp = getProp(propId, clientVersion);
                //printf( "propId: %d\n", propId );
                switch ((NPCPROP)propId)
                {
                    case NPCPROP.IMAGE:
                        image = pProps.readChars(pProps.readGUChar());
                        if (image.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(image).isEmpty())
                        image += new CString() + ".gif";
                        break;

                    case NPCPROP.SCRIPT:
                        clientScript = pProps.readChars(pProps.readGUShort());
                        break;

                    case NPCPROP.X:
                        if (blockPositionUpdates)
                        {
                            pProps.readGChar();
                            continue;
                        }
                        x = (float)(pProps.readGChar()) / 2.0f;
                        x2 = (int)(x * 16);
                        break;

                    case NPCPROP.Y:
                        if (blockPositionUpdates)
                        {
                            pProps.readGChar();
                            continue;
                        }
                        y = (float)(pProps.readGChar()) / 2.0f;
                        y2 = (int)(y * 16);
                        break;

                    case NPCPROP.POWER:
                        power = pProps.readGUChar();
                        break;

                    case NPCPROP.RUPEES:
                        rupees = (int)pProps.readGUInt();
                        break;

                    case NPCPROP.ARROWS:
                        darts = pProps.readGUChar();
                        break;

                    case NPCPROP.BOMBS:
                        bombs = pProps.readGUChar();
                        break;

                    case NPCPROP.GLOVEPOWER:
                        glovePower = pProps.readGUChar();
                        break;

                    case NPCPROP.BOMBPOWER:
                        bombPower = pProps.readGUChar();
                        break;

                    case NPCPROP.SWORDIMAGE:
                        {
                            int sp = pProps.readGUChar();
                            if (sp <= 4)
                                swordImage = new CString() + "sword" + new CString(sp.ToString()) + ".png";
                            else
                            {
                                sp -= 30;
                                len = pProps.readGUChar();
                                if (len > 0)
                                {
                                    swordImage = pProps.readChars(len);
                                    if (swordImage.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(swordImage).isEmpty())
                                    swordImage += new CString() + ".gif";
                                }
                                else
                                    swordImage = new CString() + "";
                                //swordPower = clip(sp, ((settings->getBool("healswords", false) == true) ? -(settings->getInt("swordlimit", 3)) : 0), settings->getInt("swordlimit", 3));
                            }
                            swordPower = (char)sp;
                        }
                        break;

                    case NPCPROP.SHIELDIMAGE:
                        {
                            int sp = pProps.readGUChar();
                            if (sp <= 3)
                                shieldImage = new CString() + "shield" + new CString(sp.ToString()) + ".png";
                            else
                            {
                                sp -= 10;
                                len = pProps.readGUChar();
                                if (len > 0)
                                {
                                    shieldImage = pProps.readChars(len);
                                    if (shieldImage.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(shieldImage).isEmpty())
                                    shieldImage += new CString() + ".gif";
                                }
                                else
                                    shieldImage = new CString() + "";
                            }
                            shieldPower = (char)sp;
                        }
                        break;

                    case NPCPROP.GANI:
                    /*
                if (clientVersion < CLVER_2_1)
                {
                    // Older clients don't use ganis.  This is the bow power and image instead.
                    int sp = pProps.readGUChar();
                    if (sp < 10)
                        bowImage = CString() + (char)sp;
                    else
                    {
                        sp -= 10;
                        if (sp < 0) break;
                        bowImage = pProps.readChars(sp);
                        if (!bowImage.isEmpty() && clientVersion < CLVER_2_1 && getExtension(bowImage).isEmpty())
                            bowImage + ".gif";
                        bowImage = CString() + (char)(10 + bowImage.Length) + bowImage;
                    }
                    break;
                }
                    */
                        gani = pProps.readChars(pProps.readGUChar());
                        break;

                    case NPCPROP.VISFLAGS:
                        visFlags = pProps.readGUChar();
                        break;

                    case NPCPROP.BLOCKFLAGS:
                        blockFlags = pProps.readGUChar();
                        break;

                    case NPCPROP.MESSAGE:
                        chatMsg = pProps.readChars(pProps.readGUChar());
                        break;

                    case NPCPROP.HURTDXDY:
                        hurtX = ((float)(pProps.readGUChar() - 32)) / 32;
                        hurtY = ((float)(pProps.readGUChar() - 32)) / 32;
                        break;

                    case NPCPROP.ID:
                        pProps.readGUInt();
                        break;

                    case NPCPROP.SPRITE:
                        sprite = pProps.readGUChar();
                        break;

                    case NPCPROP.COLORS:
                        for (int i = 0; i < 5; i++)
                            colors[i] = pProps.readGUChar();
                        break;

                    case NPCPROP.NICKNAME:
                        nickName = pProps.readChars(pProps.readGUChar());
                        break;

                    case NPCPROP.HORSEIMAGE:
                        horseImage = pProps.readChars(pProps.readGUChar());
                        if (horseImage.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(horseImage).isEmpty())
                        horseImage += new CString() + ".gif";
                        break;

                    case NPCPROP.HEADIMAGE:
                        len = pProps.readGUChar();
                        if (len < 100)
                            headImage = new CString() + "head" + new CString(len.ToString()) + ".png";
                        else
                        {
                            headImage = pProps.readChars(len - 100);
                            if (headImage.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(headImage).isEmpty())
                            headImage += new CString() + ".gif";
                        }
                        break;

                    case NPCPROP.ALIGNMENT:
                        ap = pProps.readGUChar();
                        if (ap < 0)
                            ap = (char)0;
                        else if (ap > 100)
                            ap = (char)100;
                //ap = clip(ap, 0, 100);
                        break;

                    case NPCPROP.IMAGEPART:
                        imagePart = pProps.readChars(6);
                        break;

                    case NPCPROP.BODYIMAGE:
                        bodyImage = pProps.readChars(pProps.readGUChar());
                        break;

                    case NPCPROP.GMAPLEVELX:
                        gmaplevelx = pProps.readGUChar();
                        break;

                    case NPCPROP.GMAPLEVELY:
                        gmaplevely = pProps.readGUChar();
                        break;

                    case NPCPROP.CLASS:
                        pProps.readChars(pProps.readGShort());
                        break;

                // Location, in pixels, of the npc on the level in 2.3+ clients.
                // Bit 0x0001 controls if it is negative or not.
                // Bits 0xFFFE are the actual value.
                    case NPCPROP.X2:
                        if (blockPositionUpdates)
                        {
                            pProps.readGUShort();
                            continue;
                        }

                        x2 = len = pProps.readGUShort();

                // If the first bit is 1, our position is negative.
                        x2 += 1;
                        if (((short)len & 0x0001) != 0)
                            x2 = -x2;

                // Let pre-2.3+ clients see 2.3+ movement.
                        x = (float)x2 / 16.0f;
                        break;

                    case NPCPROP.Y2:
                        if (blockPositionUpdates)
                        {
                            pProps.readGUShort();
                            continue;
                        }

                        y2 = len = pProps.readGUShort();

                // If the first bit is 1, our position is negative.
                        y2 += 1;
                        if (((short)len & 0x0001) != 0)
                            y2 = -y2;

                // Let pre-2.3+ clients see 2.3+ movement.
                        y = (float)y2 / 16.0f;
                        break;

                    case NPCPROP.SAVE0:
                        saves[0] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE1:
                        saves[1] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE2:
                        saves[2] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE3:
                        saves[3] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE4:
                        saves[4] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE5:
                        saves[5] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE6:
                        saves[6] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE7:
                        saves[7] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE8:
                        saves[8] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE9:
                        saves[9] = pProps.readGUChar();
                        break;

                    case NPCPROP.GATTRIB1:
                        gAttribs[0] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB2:
                        gAttribs[1] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB3:
                        gAttribs[2] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB4:
                        gAttribs[3] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB5:
                        gAttribs[4] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB6:
                        gAttribs[5] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB7:
                        gAttribs[6] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB8:
                        gAttribs[7] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB9:
                        gAttribs[8] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB10:
                        gAttribs[9] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB11:
                        gAttribs[10] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB12:
                        gAttribs[11] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB13:
                        gAttribs[12] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB14:
                        gAttribs[13] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB15:
                        gAttribs[14] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB16:
                        gAttribs[15] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB17:
                        gAttribs[16] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB18:
                        gAttribs[17] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB19:
                        gAttribs[18] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB20:
                        gAttribs[19] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB21:
                        gAttribs[20] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB22:
                        gAttribs[21] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB23:
                        gAttribs[22] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB24:
                        gAttribs[23] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB25:
                        gAttribs[24] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB26:
                        gAttribs[25] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB27:
                        gAttribs[26] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB28:
                        gAttribs[27] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB29:
                        gAttribs[28] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB30:
                        gAttribs[29] = pProps.readChars(pProps.readGUChar());
                        break;

                    default:
                        {
                            Console.Write("NPC %d (%.2f, %.2f): ", id, x, y);
                            Console.Write("Unknown prop: %ud, readPos: %d\n", propId, pProps.ReadCount);
                            for (int i = 0; i < pProps.Length; ++i)
                                Console.Write("%02x ", (char)pProps[i]);
                            Console.Write("\n");
                        }
                        return ret;
                }

                // If a prop changed, adjust its mod time.
                if (propId < (int)NPCPROP.COUNT)
                {
                    if (oldProp != getProp(propId, clientVersion))
                        modTime[propId] = new DateTime();
                }

                // Add to ret.
                ret += new CString() + (char)propId + getProp(propId, clientVersion);
            }
            return ret;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set Properties
        /// </summary>
        /// <param name="Packet"></param>
        public void SetProps(CString Packet)
        {
            while (Packet.BytesLeft > 0)
            {
                Int32 PropId = Packet.readGUChar();
                //Console.Write("[prop]: " + PropId.ToString());
                switch ((Properties)PropId)
                {
                    case Properties.IMAGE: // 0
                        this.Image = Packet.readChars(Packet.readGUChar()).ToString();
                        break;

                    case Properties.SCRIPT: // 1
                        int length;
                        if (!this.npcserver)
                            length = Packet.readGUShort();
                        else
                            length = (int)Packet.ReadGUByte5();
                        this.Script = Packet.readChars(length).ToString();
                        this.Script = this.Script.Replace("\xa7", "\n");
                        this.Script = this.Script.Replace("�", "\n");
                        this.Script = this.Script.Replace("�", "\n");

                        //if (this.Script.IndexOf("void") > 0 || this.Script.IndexOf("join(") > 0)
                        this.CompileScript = true;

                        break;

                    case Properties.NPCX: // 2 - obsolete
                    //Packet.ReadGByte1 ();
                        this.OldX = (float)(Packet.readGChar()) / 2.0f;
                        this.PixelX = (int)(this.OldX * 16);
                        break;

                    case Properties.NPCY: // 3 - obsolete
                    //Packet.ReadGByte1 ();
                        this.OldY = (float)(Packet.readGChar()) / 2.0f;
                        this.PixelY = (int)(this.OldY * 16);
                        break;

                    case Properties.NPCPOWER: // 4
                        Packet.readGUChar();
                        break;

                    case Properties.NPCRUPEES: // 5
                        this.Gralats = (int)Packet.readGUInt();
                        break;

                    case Properties.ARROWS: // 6
                        this.Arrows = Packet.readGUChar();
                        break;

                    case Properties.BOMBS: // 7
                        this.Bombs = Packet.readGUChar();
                        break;

                    case Properties.GLOVEPOWER: // 8
                        Packet.readGUChar();
                        break;

                    case Properties.BOMBPOWER: // 9
                        Packet.readGUChar();
                        break;
                    case Properties.SWORDIMG: // 10
                        {
                            int sp = Packet.readGUChar();
                            if (sp <= 4)
                                _swordImage = "sword" + sp.ToString() + ".png";
                            else
                            {
                                sp -= 30;
                                int len = Packet.readGUChar();
                                if (len > 0)
                                {
                                    _swordImage = Packet.readChars(len).ToString();
                                    if (_swordImage.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(swordImage).isEmpty())
                                    _swordImage += ".gif";
                                }
                                else
                                    _swordImage = "";
                                //swordPower = clip(sp, ((settings->getBool("healswords", false) == true) ? -(settings->getInt("swordlimit", 3)) : 0), settings->getInt("swordlimit", 3));
                            }
                            //_swordPower = (char)sp;
                        }
                        break;
                    case Properties.SHIELDIMG: // 11
                        {
                            int sp = Packet.readGUChar();
                            CString shieldImage = new CString();
                            int len;
                            if (sp <= 3)
                            {
                                shieldImage = new CString() + "shield" + new CString(sp.ToString()) + ".png";
                            }
                            else
                            {
                                sp -= 10;
                                len = Packet.readGUChar();
                                if (len > 0)
                                {
                                    shieldImage = Packet.readChars(len);
                                    if (shieldImage.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(shieldImage).isEmpty())
                                    shieldImage += new CString() + ".gif";
                                }
                                else
                                    shieldImage = new CString() + "";
                            }
                            //shieldPower = (char)sp;
                            _shieldImage = shieldImage.ToString();
                        }
                        break;
                    case Properties.GANI: // 12
                        this.Animation = Packet.readChars(Packet.readGUChar()).ToString();
                        break;

                    case Properties.VISFLAGS: // 13
                        this.VisFlags = (sbyte)Packet.readGUChar();
                        break;

                    case Properties.BLOCKFLAGS: // 14
                        this.BlockFlags = (sbyte)Packet.readGUChar();
                        break;

                    case Properties.MESSAGE: // 15
                        this.Chat = Packet.readChars(Packet.readGUChar()).ToString();
                        break;
                    case Properties.HURTDXDY: // 16
                        float hurtX = ((float)(Packet.readGUChar() - 32)) / 32;
                        float hurtY = ((float)(Packet.readGUChar() - 32)) / 32;
                        break;
                    case Properties.NPCID: // 17
                        this.Id = (int)Packet.readGUInt();
                        break;

                    case Properties.SPRITE: // 18
                        this.Dir = Packet.readGUChar();
                        break;

                    case Properties.COLORS: // 19
                        for (int i = 0; i < 5; i++)
                            Packet.readGUChar();
                        break;

                    case Properties.NICKNAME: // 20
                        this.Nickname = Packet.readChars(Packet.readGUChar()).ToString();
                        break;

                    case Properties.HORSEIMG: // 21
                        Packet.readChars(Packet.readGUChar());
                        break;

                    case Properties.HEADIMG: // 22
                        {
                            Int32 len = Packet.readGUChar();
                            this.HeadImage = (len < 100 ? "head" + len + ".png" : Packet.readChars(len - 100).ToString());
                            break;
                        }

                    case Properties.SAVE0: // 23
                        this.Save[0] = (byte)Packet.readGUChar();
                        break;

                    case Properties.SAVE1: // 24
                        this.Save[1] = (byte)Packet.readGUChar();
                        break;

                    case Properties.SAVE2: // 25
                        this.Save[2] = (byte)Packet.readGUChar();
                        break;

                    case Properties.SAVE3: // 26
                        this.Save[3] = (byte)Packet.readGUChar();
                        break;

                    case Properties.SAVE4: // 27
                        this.Save[4] = (byte)Packet.readGUChar();
                        break;

                    case Properties.SAVE5: // 28
                        this.Save[5] = (byte)Packet.readGUChar();
                        break;

                    case Properties.SAVE6: // 29
                        this.Save[6] = (byte)Packet.readGUChar();
                        break;

                    case Properties.SAVE7: // 30
                        this.Save[7] = (byte)Packet.readGUChar();
                        break;

                    case Properties.SAVE8: // 31
                        this.Save[8] = (byte)Packet.readGUChar();
                        break;

                    case Properties.SAVE9: // 32
                        this.Save[9] = (byte)Packet.readGUChar();
                        break;

                    case Properties.ALIGNMENT: // 33
                        Packet.readGUChar();
                        break;

                    case Properties.IMAGEPART: // 34
                        this.ImagePart = Packet.readChars(6);
                        break;

                    case Properties.BODYIMG: // 35
                        this.BodyImage = Packet.readChars(Packet.readGUChar()).ToString();
                        break;

                    case Properties.GMAPLVLX: // 41
                        this.GMapX = (byte)Packet.readGUChar();
                        break;

                    case Properties.GMAPLVLY: // 42
                        this.GMapY = (byte)Packet.readGUChar();
                        break;
                    case Properties.GATTRIB6: // 44
                    case Properties.GATTRIB7: // 45
                    case Properties.GATTRIB8: // 46
                    case Properties.GATTRIB9: // 47
                    case Properties.GATTRIB10: // 53,
                    case Properties.GATTRIB11: // 54,
                    case Properties.GATTRIB12: // 55,
                    case Properties.GATTRIB13: // 56,
                    case Properties.GATTRIB14: // 57,
                    case Properties.GATTRIB15: // 58,
                    case Properties.GATTRIB16: // 59,
                    case Properties.GATTRIB17: // 60,
                    case Properties.GATTRIB18: // 61,
                    case Properties.GATTRIB19: // 62,
                    case Properties.GATTRIB20: // 63,
                    case Properties.GATTRIB21: // 64,
                    case Properties.GATTRIB22: // 65,
                    case Properties.GATTRIB23: // 66,
                    case Properties.GATTRIB24: // 67,
                    case Properties.GATTRIB25: // 68,
                    case Properties.GATTRIB26: // 69,
                    case Properties.GATTRIB27: // 70,
                    case Properties.GATTRIB28: // 71,
                    case Properties.GATTRIB29: // 72,
                    case Properties.GATTRIB30: // 73,
                        Packet.readChars(Packet.readGUChar());
                        break;

                    case Properties.CLASS: // 74
                        Packet.readChars(Packet.readGShort());
                        break;

                    case Properties.PIXELX: // 75
                        {
                            int tmp = this.PixelX = Packet.readGUShort();

                            // If the first bit is 1, our position is negative.
                            this.PixelX >>= 1;
                            if ((tmp & 0x0001) != 0)
                                this.PixelX = -this.PixelX;
                            break;
                        }

                    case Properties.PIXELY: // 76
                        {
                            int tmp = this.PixelY = Packet.readGUShort();

                            // If the first bit is 1, our position is negative.
                            this.PixelY >>= 1;
                            if ((tmp & 0x0001) != 0)
                                this.PixelY = -this.PixelY;
                            break;
                        }

                    default:
                        System.Console.WriteLine("Unknown NPC Prop: " + PropId + " Data: " + Packet.ReadString());
                    //Packet.ReadGUByte1 ();
                        return;

                }

                //Console.WriteLine(": " + this.GetProp((Properties)PropId).ToString());
            }

            // Compile script if script changed.
            //if (CompileScript)
            //	Server.Compiler.CompileAdd(this);
        }