Exemplo n.º 1
0
//==============================================================================
void GameServer::GenMonsters_()
{
  int monsterCounter = 0;
  for (int i = 0; i < levelMap_.GetRowCount(); i++)
  {
    for (int j = 0; j < levelMap_.GetColumnCount(); j++)
    {
      if (levelMap_.GetCell(j, i) == '.')
      {
        monsterCounter++;
        if (monsterCounter % 10 == 0)
        {
          Monster* monster = CreateActor_<Monster>();
          monster->SetType(EActorType::MONSTER);
          Monster& m = *monster;
          SetActorPosition_(monster, Vector2(j + 0.5f, i + 0.5f));
          m.SetDirection(static_cast<EActorDirection>(rand() % 4 + 1));
          storage_.GetMonster(monster, monster->GetId() % 32 + 1);
        }
      }
    }
  }
}
Exemplo n.º 2
0
//==============================================================================
void GameServer::HandlePutMob_(const QVariantMap& request, QVariantMap& response)
{
  if (!testingStageActive_)
  {
    WriteResult_(response, EFEMPResult::BAD_ACTION);
    return;
  }

  if (!request["x"].toFloat()
      || !request["y"].toFloat())
  {
    WriteResult_(response, EFEMPResult::BAD_PLACING);
    return;
  }

  float x = request["x"].toFloat();
  float y = request["y"].toFloat();

  Monster* monster = CreateActor_<Monster>();
  SetActorPosition_(monster, Vector2(x, y));

  monster->SetDirection(EActorDirection::SOUTH);

  if (IsPositionWrong(x, y, monster))
  {
    KillActor_(monster);
    WriteResult_(response, EFEMPResult::BAD_PLACING);
    return;
  }

  auto flags = request["flags"].toList();
  for (auto flag: flags)
  {
    if (monster->possibleFlags.lastIndexOf(flag.toString()) == -1)
    {
      WriteResult_(response, EFEMPResult::BAD_FLAG);
      return;
    }
     monster->Flags.push_back(flag.toString());
  }

  monster->SetRace(request["race"].toString());
  if (monster->GetRace() == "NONE")
  {
    WriteResult_(response, EFEMPResult::BAD_RACE);
    return;
  }

  auto stats = request["stats"].toMap();
  for (auto s = stats.begin(); s != stats.end(); s++)
  {
    EStatConst stat = StringToStat[s.key()];
    QVariant val = s.value();
    monster->SetStat(stat, val.toFloat());
  }

  auto inventory = request["inventory"].toList();
  for (auto elem: inventory)
  {
    Item* item = CreateActor_<Item>();
    SetItemDescription(elem.toMap(), item);
    item->SetOnTheGround(false);
    monster->items.push_back(item);
    actors_.erase(std::remove(actors_.begin(), actors_.end(), item)
                , actors_.end()); //???
  }

  QStringList damage;
  damage << request["dealtDamage"].toString().split("d");

  if (damage.size() < 2
      || !damage[0].toInt()
      || !damage[1].toInt())
  {
    WriteResult_(response, EFEMPResult::BAD_DAMAGE);
    return;
  }

  response["id"] = monster->GetId();
}