00001 /* 00002 * The Mana World 00003 * Copyright (C) 2004 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #include "resources/iteminfo.h" 00023 00024 #include "resources/itemdb.h" 00025 00026 const std::string &ItemInfo::getSprite(Gender gender) const 00027 { 00028 if (mView) 00029 { 00030 // Forward the request to the item defining how to view this item 00031 return ItemDB::get(mView).getSprite(gender); 00032 } 00033 else 00034 { 00035 static const std::string empty = ""; 00036 std::map<int, std::string>::const_iterator i = 00037 mAnimationFiles.find(gender); 00038 00039 return (i != mAnimationFiles.end()) ? i->second : empty; 00040 } 00041 } 00042 00043 void ItemInfo::setWeaponType(int type) 00044 { 00045 // See server item.hpp file for type values. 00046 switch (type) 00047 { 00048 case WPNTYPE_NONE: 00049 mAttackType = ACTION_DEFAULT; 00050 break; 00051 case WPNTYPE_KNIFE: 00052 case WPNTYPE_SWORD: 00053 mAttackType = ACTION_ATTACK_STAB; 00054 break; 00055 case WPNTYPE_THROWN: 00056 mAttackType = ACTION_ATTACK_THROW; 00057 break; 00058 case WPNTYPE_BOW: 00059 mAttackType = ACTION_ATTACK_BOW; 00060 break; 00061 case WPNTYPE_POLEARM: 00062 mAttackType = ACTION_ATTACK_SWING; 00063 break; 00064 default: 00065 mAttackType = ACTION_ATTACK; 00066 } 00067 } 00068 00069 void ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename) 00070 { 00071 mSounds[event].push_back("sfx/" + filename); 00072 } 00073 00074 const std::string &ItemInfo::getSound(EquipmentSoundEvent event) const 00075 { 00076 static const std::string empty; 00077 std::map< EquipmentSoundEvent, std::vector<std::string> >::const_iterator i; 00078 i = mSounds.find(event); 00079 00080 return i == mSounds.end() ? empty : i->second[rand() % i->second.size()]; 00081 }