Pastebin

New pastes are no longer accepted · Stats

Latest Pastes

Fearless's Statskill Fuxed up


/* $Id: StatSkill.cpp 168 2009-10-23 14:58:32Z sausage $
 * EOSERV is released under the zlib license.
 * See LICENSE.txt for more info.
 */

#include "handlers.h"

CLIENT_F_FUNC(StatSkill)
{
	PacketBuilder reply;

	switch (action)
	{
		case PACKET_OPEN: // Talked to a skill master NPC
		{
           if (this->state < EOClient::Playing) return false;
            CLIENT_QUEUE_ACTION(0.0)

            short id = reader.GetShort();

            UTIL_PTR_VECTOR_FOREACH(this->player->character->map->npcs, NPC, npc)
            {
                if (npc->index == id && (npc->spell_shop.size() > 0 || npc->spell_shop.size() > 0))
                {

                    this->player->character->npc = *npc;
                    this->player->character->npc_type = ENF::Skills;

                    reply.SetID(PACKET_STATSKILL, PACKET_OPEN);
                    reply.AddShort(npc->id);
                    reply.AddBreakString(npc->skill_name.c_str());

                    UTIL_PTR_VECTOR_FOREACH(npc->spell_shop, NPC_Spell_Trade, spell)
                    {
                        reply.AddShort(spell->id);
                        reply.AddShort(spell->level);
                        reply.AddInt(spell->gold);
                        reply.AddShort(spell->spell1);
                        reply.AddShort(spell->spell2);
                        reply.AddShort(spell->spell3);
                        reply.AddShort(spell->spell4);
                        reply.AddShort(spell->str);
                        reply.AddShort(spell->wis);
                        reply.AddShort(spell->intt);
                        reply.AddShort(spell->agi);
                        reply.AddShort(spell->con);
                        reply.AddShort(spell->cha);
                    }
                    CLIENT_SEND(reply);
                }
            }
        }
        break;

        case PACKET_TAKE:
        {

            int amount = reader.GetInt();
            int spell = reader.GetShort();

            if (this->player->character->npc_type == ENF::Skills)
            {
                UTIL_PTR_VECTOR_FOREACH(this->player->character->npc->spell_shop, NPC_Spell_Trade, checkspell)
                {
                    if (checkspell->id == spell && this->player->character->HasItem(1) >= checkspell->gold)
                    {
                        this->player->character->DelItem(1, checkspell->gold);
                        this->player->character->AddSpell(spell, 0);

                        PacketBuilder builder(PACKET_STATSKILL, PACKET_TAKE);
                        builder.AddShort(spell);
                        builder.AddInt(this->player->character->HasItem(1));
                        CLIENT_SEND(builder);
                        break;
                    }
                }
            }
        }
        break;

        case PACKET_REMOVE:
        {

            int data1 = reader.GetInt();
            int spellid = reader.GetShort();
            int data3 = reader.GetChar();

            if(this->player->character->HasSpell(spellid))
            {
                UTIL_PTR_LIST_FOREACH(this->player->character->spells, Character_Spell, spl)
                {
                    if(spellid == spl->id)
                    {
                        this->player->character->skillpoints += spl->level;
                        this->player->character->DelSpell(spellid);

                        reply.SetID(PACKET_STATSKILL, PACKET_REMOVE);
                        reply.AddShort(spellid);

                        CLIENT_SEND(reply);

                        break;
                    }
                }
            }
        }
        break;

		case PACKET_REPLY: // (unsure) Error message from the skill master
		{

		}
		break;

		case PACKET_ADD: // Spending a stat point on a skill
		{
			if (this->state < EOClient::PlayingModal) return false;

			unsigned short *stat;
			/*int action = */reader.GetChar();
			int stat_id = reader.GetShort();

			if (this->player->character->statpoints <= 0)
			{
				return false;
			}

			switch (stat_id)
			{
				case 1: stat = &this->player->character->str; break;
				case 2: stat = &this->player->character->intl; break;
				case 3: stat = &this->player->character->wis; break;
				case 4: stat = &this->player->character->agi; break;
				case 5: stat = &this->player->character->con; break;
				case 6: stat = &this->player->character->cha; break;
				default: return false;
			}

			++(*stat);
			--this->player->character->statpoints;

			this->player->character->CalculateStats();

			reply.SetID(PACKET_STATSKILL, PACKET_PLAYER);
			reply.AddShort(this->player->character->statpoints);
			reply.AddShort(this->player->character->str);
			reply.AddShort(this->player->character->intl);
			reply.AddShort(this->player->character->wis);
			reply.AddShort(this->player->character->agi);
			reply.AddShort(this->player->character->con);
			reply.AddShort(this->player->character->cha);
			reply.AddShort(this->player->character->maxhp);
			reply.AddShort(this->player->character->maxtp);
			reply.AddShort(this->player->character->maxsp);
			reply.AddShort(this->player->character->maxweight);
			reply.AddShort(this->player->character->mindam);
			reply.AddShort(this->player->character->maxdam);
			reply.AddShort(this->player->character->accuracy);
			reply.AddShort(this->player->character->evade);
			reply.AddShort(this->player->character->armor);

			CLIENT_SEND(reply);
		}
		break;

		default:
			return false;
	}

	return true;
}