void SkillInventory::AddItem(HudItem* pItem) { // Any free slots? if(!HasFreeSlots()) return; Skill* skill = mPlayer->AddSkill(pItem->GetName()); // Pass on the attributes. // [NOTE] REALLY UGLY [HACK][WARNING]. skill->SetAttributes(pItem->GetAttributes()); skill->SetDescription(pItem->GetDescription()); skill->SetCost(pItem->GetCost()); skill->SetLevel(pItem->GetLevel()); // Send message to server. SendItemAdded(mPlayer->GetPlayer()->GetId(), pItem->GetName(), pItem->GetLevel()); UpdateItems(); }
SkillManager::SkillManager(void) { error_ = false; /* Populate upgrade paths, costs etc*/ TiXmlDocument doc("Skills.xml"); doc.LoadFile(); if(doc.Error()) { Logger::ErrorOut() << "Unable to load skills.xml\n"; Logger::ErrorOut() << "Error: " << doc.ErrorDesc() << "\n"; } TiXmlElement* root = doc.FirstChildElement("Skills"); if(root) { TiXmlElement* skill = root->FirstChildElement("Skill"); while(skill) { std::vector<SkillLevel> upgrades; std::string name; std::string alignment; unsigned int init_cost = 0; error_ |= (skill->QueryValueAttribute("name", &name) != TIXML_SUCCESS); error_ |= (skill->QueryValueAttribute("alignment", &alignment) != TIXML_SUCCESS); TiXmlElement* initialcost = skill->FirstChildElement("InitialCost"); if(initialcost) { std::string init_cost_str = initialcost->GetText(); init_cost = boost::lexical_cast<unsigned int, std::string>(init_cost_str); } else { Logger::ErrorOut() << "No initial cost for skill " << name << "\n"; error_ = true; } //TODO upgrades TiXmlElement* upgrade = skill->FirstChildElement("Upgrade"); while(upgrade) { std::string upgrade_name; upgrade->QueryValueAttribute("name", &upgrade_name); SkillLevel sl(upgrade_name); int ltv_rank = 1; TiXmlElement* level = upgrade->FirstChildElement("Level"); while(level) { int rank = 0; int cost = 0; error_ |= (level->QueryIntAttribute("rank", &rank) != TIXML_SUCCESS); error_ |= (level->QueryIntAttribute("cost", &cost) != TIXML_SUCCESS); error_ |= (rank != ltv_rank + 1); ltv_rank = rank; sl.AddRank(cost); level = level->NextSiblingElement("Level"); } upgrades.push_back(sl); upgrade = upgrade->NextSiblingElement("Upgrade"); } if(error_) break; else { Skill* sk = new Skill(); sk->SetCost(init_cost); sk->SetName(name); for(std::vector<SkillLevel>::iterator it = upgrades.begin(); it != upgrades.end(); ++it) { sk->AddUpgrade(*it); } if(alignment == "good") sk->SetAlignment(SkillAlignment::Good); else if(alignment == "evil") sk->SetAlignment(SkillAlignment::Evil); else if(alignment == "neutral") sk->SetAlignment(SkillAlignment::Neutral); else { Logger::ErrorOut() << "Skill alignment can only be 'good', 'evil' or 'neutral'\n"; error_ = true; break; } if(cheat_) sk->SetUnlocked(true); skills_.push_back(sk); } skill = skill->NextSiblingElement("Skill"); } } else { Logger::ErrorOut() << "Malformed skills.xml, no root element 'Skills'\n"; error_ = true; } }