示例#1
0
bool DesignStore::addDesign(Design::Ptr d){
  d->setDesignId(next_designid++);

  //check components all come from this category
  IdMap cl = d->getComponents();
  Player::Ptr player = Game::getGame()->getPlayerManager()->getPlayer(d->getOwner());
  PlayerView::Ptr playerview = player->getPlayerView();
  for(IdMap::iterator itcurr = cl.begin(); 
      itcurr != cl.end(); ++itcurr){
    if(!(playerview->isUsableComponent(itcurr->first)))
      return false;
    std::map<uint32_t, Component::Ptr>::iterator itcomp = components.find(itcurr->first);
    if(itcomp == components.end())
      return false;
    getComponent(itcurr->first)->setInUse();
  }
  d->eval();
  designs[d->getId()] = d;
  getCategory(d->getCategoryId())->doAddDesign(d);

  if(d->isValid()){
    playerview->addUsableDesign(d->getId());
  }else{
    playerview->addVisibleDesign( DesignView::Ptr( new DesignView( d->getId(), true )) );
  }

  Game::getGame()->getPlayerManager()->updatePlayer(player->getID());
  Game::getGame()->getPersistence()->saveDesign(d);
  return true;
}
示例#2
0
bool DesignStore::modifyDesign(Design::Ptr d){
  Design::Ptr current = designs[d->getId()];
  if(!current || current->getOwner() != d->getOwner() || current->getNumExist() != 0 || current->getInUse() != 0)
    return false;
  Player::Ptr player = Game::getGame()->getPlayerManager()->getPlayer(d->getOwner());
  PlayerView::Ptr playerview = player->getPlayerView();
  playerview->removeUsableDesign(d->getId());

  IdMap cl = current->getComponents();
  for(IdMap::iterator itcurr = cl.begin(); itcurr != cl.end(); ++itcurr){
    components[itcurr->first]->setInUse(false);
  }
  for(IdMap::iterator itcurr = cl.begin(); itcurr != cl.end(); ++itcurr){
    if(!(playerview->isUsableComponent(itcurr->first)))
      return false;
    std::map<uint32_t, Component::Ptr>::iterator itcomp = components.find(itcurr->first);
    if(itcomp == components.end())
      return false;
    itcomp->second->setInUse();
  }

  d->eval();
  bool rtv;
  if(getCategory(d->getCategoryId())->doModifyDesign(d)){
    designs[d->getId()] = d;
    rtv = true;
  }else{
    d = current;
    rtv = false;
  }
  if(d->isValid()){
    playerview->addUsableDesign(d->getId());
  }
  Game::getGame()->getPlayerManager()->updatePlayer(player->getID());
  Game::getGame()->getPersistence()->updateDesign(d);
  return rtv;
}