summaryrefslogtreecommitdiff
path: root/src/being.cpp
blob: ae339ad84bfebc8333d1c3d95a99838dddf5b861 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 *  The Mana World Server
 *  Copyright 2004 The Mana World Development Team
 *
 *  This file is part of The Mana World.
 *
 *  The Mana World  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; either version 2 of the License, or any later version.
 *
 *  The Mana  World 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 The Mana  World; if not, write to the  Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *  $Id$
 */


#include "being.h"

/**
 * Update the internal status.
 */
void Player::update()
{
    // computed stats.
    setStat(STAT_HEA, 20 + (20 * mRawStats.stats[STAT_VIT]));
    setStat(STAT_ATT, 10 + mRawStats.stats[STAT_STR]);
    setStat(STAT_DEF, 10 + mRawStats.stats[STAT_STR]);
    setStat(STAT_MAG, 10 + mRawStats.stats[STAT_INT]);
    setStat(STAT_ACC, 50 + mRawStats.stats[STAT_DEX]);
    setStat(STAT_SPD, mRawStats.stats[STAT_DEX]);

    mNeedUpdate = false;
}

void Player::setInventory(const std::vector<unsigned int> &inven)
{
    inventory = inven;
}

bool Player::addInventory(unsigned int itemId)
{
    // If required weight could be tallied to see if player can pick up more.
    inventory.push_back(itemId);
    return true;
}

bool Player::delInventory(unsigned int itemId)
{
    for (std::vector<unsigned int>::iterator i = inventory.begin();
         i != inventory.end(); i++) {
        if (*i == itemId) {
            inventory.erase(i);
            return true;
        }
    }
    return false;
}

bool Player::hasItem(unsigned int itemId)
{
    for (std::vector<unsigned int>::iterator i = inventory.begin();
         i != inventory.end(); i++)
    {
        if (*i == itemId)
            return true;
    }
    return false;
}

bool Player::equip(unsigned int itemId, unsigned char slot)
{
    // currently this is too simplistic and doesn't check enough
    // but until further functionality is implemented in the
    // server it will suffice
    if (slot < MAX_EQUIP_SLOTS) {
        equipment[slot] = itemId;
        return true;
    } else
        return false;
}

bool Player::unequip(unsigned char slot)
{
    // NOTE: 0 will be invalid item id (or we could use key/value pairs)
    equipment[slot] = 0;
    return true;
}