/*
 * drmessage.h by Matze Braun <MatzeBraun@gmx.de>
 *
 * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org) 
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation (version 2 of the License)
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
#ifndef __DRMESSAGE_H__
#define __DRMESSAGE_H__

#include <csutil/databuf.h>
#include "net/messages.h"
#include "../../server/bulkobjects/pscharacter.h"
#include "rpgrules/vitals.h"

class psStatDRMessage : public psMessageCracker
{
public:

    psStatDRMessage(uint32_t clientnum, PS_ID eid, psCharacter* psChar, int flags) 
    {
        msg = new MsgEntry(sizeof(PS_ID) + 200 + sizeof(uint32_t), PRIORITY_LOW); //200 is enough to accomodate any statDRMessage

        msg->clientnum = clientnum;
        msg->SetType(MSGTYPE_STATDRUPDATE);

        msg->Add((uint32_t)eid);
        useful = psChar->GetStatDRData(msg,flags);
        msg->ClipToCurrentSize();

        valid=!(msg->overrun);
    }

    /** Send a request to the server for a full stat update.
      */
    psStatDRMessage()
    {
        msg = new MsgEntry(PRIORITY_HIGH);

        msg->clientnum = 0;
        msg->SetType(MSGTYPE_STATDRUPDATE);
        valid=!(msg->overrun);    
    }
    
    
    psStatDRMessage(MsgEntry* me)
    {
        /* We handle PS_ID as a uint32 - which it is at this time.  If it ever changes we 
         *  will need to adjust.
         */
        CS_ASSERT(sizeof(PS_ID) == sizeof(uint32_t));

        entityid=me->GetUInt32();
        statsDirty = me->GetUInt32();

        if (statsDirty & DIRTY_VITAL_HP)       
            hp = me->GetFloat();
            
        if (statsDirty & DIRTY_VITAL_HP_RATE)
            hp_rate = me->GetFloat();
            
        if (statsDirty & DIRTY_VITAL_MANA)
            mana = me->GetFloat();
            
        if (statsDirty & DIRTY_VITAL_MANA_RATE)
            mana_rate = me->GetFloat();

        if (statsDirty & DIRTY_VITAL_PYSSTAMINA)
            pstam = me->GetFloat();

        if (statsDirty & DIRTY_VITAL_PYSSTAMINA_RATE)
            pstam_rate = me->GetFloat();

        if (statsDirty & DIRTY_VITAL_MENSTAMINA)
            mstam = me->GetFloat();

        if (statsDirty & DIRTY_VITAL_MENSTAMINA_RATE)
            mstam_rate = me->GetFloat();

        if (statsDirty & DIRTY_VITAL_EXPERIENCE)
            exp = me->GetInt32();
            
        if (statsDirty & DIRTY_VITAL_PROGRESSION)
            prog = me->GetInt32();

        counter = me->GetUInt8();

        valid=!(me->overrun);
    }

    virtual ~psStatDRMessage()
    {
        
    }

    PSF_DECLARE_MSG_FACTORY();

    /**
     * Convert the message into human readable string.
     *
     * @param access_ptrs A struct to a number of access pointers.
     * @return Return a human readable string for the message.
     */
    virtual csString ToString(AccessPointers * access_ptrs);
    
    bool useful;
    PS_ID entityid;
    uint32_t statsDirty;
    uint8_t counter;

    float hp,hp_rate,mana,mana_rate,pstam,pstam_rate;
    float mstam,mstam_rate,exp,prog;
};

#endif

